three.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. /**
  55. * Copyright (c) 2014-present, Facebook, Inc.
  56. *
  57. * This source code is licensed under the MIT license found in the
  58. * LICENSE file in the root directory of this source tree.
  59. */
  60. var runtime = function (exports) {
  61. var Op = Object.prototype;
  62. var hasOwn = Op.hasOwnProperty;
  63. var undefined$1; // More compressible than void 0.
  64. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  65. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  66. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  67. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  68. function define(obj, key, value) {
  69. Object.defineProperty(obj, key, {
  70. value: value,
  71. enumerable: true,
  72. configurable: true,
  73. writable: true
  74. });
  75. return obj[key];
  76. }
  77. try {
  78. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  79. define({}, "");
  80. } catch (err) {
  81. define = function define(obj, key, value) {
  82. return obj[key] = value;
  83. };
  84. }
  85. function wrap(innerFn, outerFn, self, tryLocsList) {
  86. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  87. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  88. var generator = Object.create(protoGenerator.prototype);
  89. var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
  90. // .throw, and .return methods.
  91. generator._invoke = makeInvokeMethod(innerFn, self, context);
  92. return generator;
  93. }
  94. exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
  95. // record like context.tryEntries[i].completion. This interface could
  96. // have been (and was previously) designed to take a closure to be
  97. // invoked without arguments, but in all the cases we care about we
  98. // already have an existing method we want to call, so there's no need
  99. // to create a new function object. We can even get away with assuming
  100. // the method takes exactly one argument, since that happens to be true
  101. // in every case, so we don't have to touch the arguments object. The
  102. // only additional allocation required is the completion record, which
  103. // has a stable shape and so hopefully should be cheap to allocate.
  104. function tryCatch(fn, obj, arg) {
  105. try {
  106. return {
  107. type: "normal",
  108. arg: fn.call(obj, arg)
  109. };
  110. } catch (err) {
  111. return {
  112. type: "throw",
  113. arg: err
  114. };
  115. }
  116. }
  117. var GenStateSuspendedStart = "suspendedStart";
  118. var GenStateSuspendedYield = "suspendedYield";
  119. var GenStateExecuting = "executing";
  120. var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
  121. // breaking out of the dispatch switch statement.
  122. var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
  123. // .constructor.prototype properties for functions that return Generator
  124. // objects. For full spec compliance, you may wish to configure your
  125. // minifier not to mangle the names of these two functions.
  126. function Generator() {}
  127. function GeneratorFunction() {}
  128. function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
  129. // don't natively support it.
  130. var IteratorPrototype = {};
  131. IteratorPrototype[iteratorSymbol] = function () {
  132. return this;
  133. };
  134. var getProto = Object.getPrototypeOf;
  135. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  136. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  137. // This environment has a native %IteratorPrototype%; use it instead
  138. // of the polyfill.
  139. IteratorPrototype = NativeIteratorPrototype;
  140. }
  141. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  142. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  143. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  144. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
  145. // Iterator interface in terms of a single ._invoke method.
  146. function defineIteratorMethods(prototype) {
  147. ["next", "throw", "return"].forEach(function (method) {
  148. define(prototype, method, function (arg) {
  149. return this._invoke(method, arg);
  150. });
  151. });
  152. }
  153. exports.isGeneratorFunction = function (genFun) {
  154. var ctor = typeof genFun === "function" && genFun.constructor;
  155. return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
  156. // do is to check its .name property.
  157. (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  158. };
  159. exports.mark = function (genFun) {
  160. if (Object.setPrototypeOf) {
  161. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  162. } else {
  163. genFun.__proto__ = GeneratorFunctionPrototype;
  164. define(genFun, toStringTagSymbol, "GeneratorFunction");
  165. }
  166. genFun.prototype = Object.create(Gp);
  167. return genFun;
  168. }; // Within the body of any async function, `await x` is transformed to
  169. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  170. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  171. // meant to be awaited.
  172. exports.awrap = function (arg) {
  173. return {
  174. __await: arg
  175. };
  176. };
  177. function AsyncIterator(generator, PromiseImpl) {
  178. function invoke(method, arg, resolve, reject) {
  179. var record = tryCatch(generator[method], generator, arg);
  180. if (record.type === "throw") {
  181. reject(record.arg);
  182. } else {
  183. var result = record.arg;
  184. var value = result.value;
  185. if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
  186. return PromiseImpl.resolve(value.__await).then(function (value) {
  187. invoke("next", value, resolve, reject);
  188. }, function (err) {
  189. invoke("throw", err, resolve, reject);
  190. });
  191. }
  192. return PromiseImpl.resolve(value).then(function (unwrapped) {
  193. // When a yielded Promise is resolved, its final value becomes
  194. // the .value of the Promise<{value,done}> result for the
  195. // current iteration.
  196. result.value = unwrapped;
  197. resolve(result);
  198. }, function (error) {
  199. // If a rejected Promise was yielded, throw the rejection back
  200. // into the async generator function so it can be handled there.
  201. return invoke("throw", error, resolve, reject);
  202. });
  203. }
  204. }
  205. var previousPromise;
  206. function enqueue(method, arg) {
  207. function callInvokeWithMethodAndArg() {
  208. return new PromiseImpl(function (resolve, reject) {
  209. invoke(method, arg, resolve, reject);
  210. });
  211. }
  212. return previousPromise = // If enqueue has been called before, then we want to wait until
  213. // all previous Promises have been resolved before calling invoke,
  214. // so that results are always delivered in the correct order. If
  215. // enqueue has not been called before, then it is important to
  216. // call invoke immediately, without waiting on a callback to fire,
  217. // so that the async generator function has the opportunity to do
  218. // any necessary setup in a predictable way. This predictability
  219. // is why the Promise constructor synchronously invokes its
  220. // executor callback, and why async functions synchronously
  221. // execute code before the first await. Since we implement simple
  222. // async functions in terms of async generators, it is especially
  223. // important to get this right, even though it requires care.
  224. previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
  225. // invocations of the iterator.
  226. callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  227. } // Define the unified helper method that is used to implement .next,
  228. // .throw, and .return (see defineIteratorMethods).
  229. this._invoke = enqueue;
  230. }
  231. defineIteratorMethods(AsyncIterator.prototype);
  232. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  233. return this;
  234. };
  235. exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
  236. // AsyncIterator objects; they just return a Promise for the value of
  237. // the final result produced by the iterator.
  238. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  239. if (PromiseImpl === void 0) PromiseImpl = Promise;
  240. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  241. return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
  242. : iter.next().then(function (result) {
  243. return result.done ? result.value : iter.next();
  244. });
  245. };
  246. function makeInvokeMethod(innerFn, self, context) {
  247. var state = GenStateSuspendedStart;
  248. return function invoke(method, arg) {
  249. if (state === GenStateExecuting) {
  250. throw new Error("Generator is already running");
  251. }
  252. if (state === GenStateCompleted) {
  253. if (method === "throw") {
  254. throw arg;
  255. } // Be forgiving, per 25.3.3.3.3 of the spec:
  256. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  257. return doneResult();
  258. }
  259. context.method = method;
  260. context.arg = arg;
  261. while (true) {
  262. var delegate = context.delegate;
  263. if (delegate) {
  264. var delegateResult = maybeInvokeDelegate(delegate, context);
  265. if (delegateResult) {
  266. if (delegateResult === ContinueSentinel) continue;
  267. return delegateResult;
  268. }
  269. }
  270. if (context.method === "next") {
  271. // Setting context._sent for legacy support of Babel's
  272. // function.sent implementation.
  273. context.sent = context._sent = context.arg;
  274. } else if (context.method === "throw") {
  275. if (state === GenStateSuspendedStart) {
  276. state = GenStateCompleted;
  277. throw context.arg;
  278. }
  279. context.dispatchException(context.arg);
  280. } else if (context.method === "return") {
  281. context.abrupt("return", context.arg);
  282. }
  283. state = GenStateExecuting;
  284. var record = tryCatch(innerFn, self, context);
  285. if (record.type === "normal") {
  286. // If an exception is thrown from innerFn, we leave state ===
  287. // GenStateExecuting and loop back for another invocation.
  288. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  289. if (record.arg === ContinueSentinel) {
  290. continue;
  291. }
  292. return {
  293. value: record.arg,
  294. done: context.done
  295. };
  296. } else if (record.type === "throw") {
  297. state = GenStateCompleted; // Dispatch the exception by looping back around to the
  298. // context.dispatchException(context.arg) call above.
  299. context.method = "throw";
  300. context.arg = record.arg;
  301. }
  302. }
  303. };
  304. } // Call delegate.iterator[context.method](context.arg) and handle the
  305. // result, either by returning a { value, done } result from the
  306. // delegate iterator, or by modifying context.method and context.arg,
  307. // setting context.delegate to null, and returning the ContinueSentinel.
  308. function maybeInvokeDelegate(delegate, context) {
  309. var method = delegate.iterator[context.method];
  310. if (method === undefined$1) {
  311. // A .throw or .return when the delegate iterator has no .throw
  312. // method always terminates the yield* loop.
  313. context.delegate = null;
  314. if (context.method === "throw") {
  315. // Note: ["return"] must be used for ES3 parsing compatibility.
  316. if (delegate.iterator["return"]) {
  317. // If the delegate iterator has a return method, give it a
  318. // chance to clean up.
  319. context.method = "return";
  320. context.arg = undefined$1;
  321. maybeInvokeDelegate(delegate, context);
  322. if (context.method === "throw") {
  323. // If maybeInvokeDelegate(context) changed context.method from
  324. // "return" to "throw", let that override the TypeError below.
  325. return ContinueSentinel;
  326. }
  327. }
  328. context.method = "throw";
  329. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  330. }
  331. return ContinueSentinel;
  332. }
  333. var record = tryCatch(method, delegate.iterator, context.arg);
  334. if (record.type === "throw") {
  335. context.method = "throw";
  336. context.arg = record.arg;
  337. context.delegate = null;
  338. return ContinueSentinel;
  339. }
  340. var info = record.arg;
  341. if (!info) {
  342. context.method = "throw";
  343. context.arg = new TypeError("iterator result is not an object");
  344. context.delegate = null;
  345. return ContinueSentinel;
  346. }
  347. if (info.done) {
  348. // Assign the result of the finished delegate to the temporary
  349. // variable specified by delegate.resultName (see delegateYield).
  350. context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
  351. context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
  352. // exception, let the outer generator proceed normally. If
  353. // context.method was "next", forget context.arg since it has been
  354. // "consumed" by the delegate iterator. If context.method was
  355. // "return", allow the original .return call to continue in the
  356. // outer generator.
  357. if (context.method !== "return") {
  358. context.method = "next";
  359. context.arg = undefined$1;
  360. }
  361. } else {
  362. // Re-yield the result returned by the delegate method.
  363. return info;
  364. } // The delegate iterator is finished, so forget it and continue with
  365. // the outer generator.
  366. context.delegate = null;
  367. return ContinueSentinel;
  368. } // Define Generator.prototype.{next,throw,return} in terms of the
  369. // unified ._invoke helper method.
  370. defineIteratorMethods(Gp);
  371. define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
  372. // @@iterator function is called on it. Some browsers' implementations of the
  373. // iterator prototype chain incorrectly implement this, causing the Generator
  374. // object to not be returned from this call. This ensures that doesn't happen.
  375. // See https://github.com/facebook/regenerator/issues/274 for more details.
  376. Gp[iteratorSymbol] = function () {
  377. return this;
  378. };
  379. Gp.toString = function () {
  380. return "[object Generator]";
  381. };
  382. function pushTryEntry(locs) {
  383. var entry = {
  384. tryLoc: locs[0]
  385. };
  386. if (1 in locs) {
  387. entry.catchLoc = locs[1];
  388. }
  389. if (2 in locs) {
  390. entry.finallyLoc = locs[2];
  391. entry.afterLoc = locs[3];
  392. }
  393. this.tryEntries.push(entry);
  394. }
  395. function resetTryEntry(entry) {
  396. var record = entry.completion || {};
  397. record.type = "normal";
  398. delete record.arg;
  399. entry.completion = record;
  400. }
  401. function Context(tryLocsList) {
  402. // The root entry object (effectively a try statement without a catch
  403. // or a finally block) gives us a place to store values thrown from
  404. // locations where there is no enclosing try statement.
  405. this.tryEntries = [{
  406. tryLoc: "root"
  407. }];
  408. tryLocsList.forEach(pushTryEntry, this);
  409. this.reset(true);
  410. }
  411. exports.keys = function (object) {
  412. var keys = [];
  413. for (var key in object) {
  414. keys.push(key);
  415. }
  416. keys.reverse(); // Rather than returning an object with a next method, we keep
  417. // things simple and return the next function itself.
  418. return function next() {
  419. while (keys.length) {
  420. var key = keys.pop();
  421. if (key in object) {
  422. next.value = key;
  423. next.done = false;
  424. return next;
  425. }
  426. } // To avoid creating an additional object, we just hang the .value
  427. // and .done properties off the next function object itself. This
  428. // also ensures that the minifier will not anonymize the function.
  429. next.done = true;
  430. return next;
  431. };
  432. };
  433. function values(iterable) {
  434. if (iterable) {
  435. var iteratorMethod = iterable[iteratorSymbol];
  436. if (iteratorMethod) {
  437. return iteratorMethod.call(iterable);
  438. }
  439. if (typeof iterable.next === "function") {
  440. return iterable;
  441. }
  442. if (!isNaN(iterable.length)) {
  443. var i = -1,
  444. next = function next() {
  445. while (++i < iterable.length) {
  446. if (hasOwn.call(iterable, i)) {
  447. next.value = iterable[i];
  448. next.done = false;
  449. return next;
  450. }
  451. }
  452. next.value = undefined$1;
  453. next.done = true;
  454. return next;
  455. };
  456. return next.next = next;
  457. }
  458. } // Return an iterator with no values.
  459. return {
  460. next: doneResult
  461. };
  462. }
  463. exports.values = values;
  464. function doneResult() {
  465. return {
  466. value: undefined$1,
  467. done: true
  468. };
  469. }
  470. Context.prototype = {
  471. constructor: Context,
  472. reset: function reset(skipTempReset) {
  473. this.prev = 0;
  474. this.next = 0; // Resetting context._sent for legacy support of Babel's
  475. // function.sent implementation.
  476. this.sent = this._sent = undefined$1;
  477. this.done = false;
  478. this.delegate = null;
  479. this.method = "next";
  480. this.arg = undefined$1;
  481. this.tryEntries.forEach(resetTryEntry);
  482. if (!skipTempReset) {
  483. for (var name in this) {
  484. // Not sure about the optimal order of these conditions:
  485. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  486. this[name] = undefined$1;
  487. }
  488. }
  489. }
  490. },
  491. stop: function stop() {
  492. this.done = true;
  493. var rootEntry = this.tryEntries[0];
  494. var rootRecord = rootEntry.completion;
  495. if (rootRecord.type === "throw") {
  496. throw rootRecord.arg;
  497. }
  498. return this.rval;
  499. },
  500. dispatchException: function dispatchException(exception) {
  501. if (this.done) {
  502. throw exception;
  503. }
  504. var context = this;
  505. function handle(loc, caught) {
  506. record.type = "throw";
  507. record.arg = exception;
  508. context.next = loc;
  509. if (caught) {
  510. // If the dispatched exception was caught by a catch block,
  511. // then let that catch block handle the exception normally.
  512. context.method = "next";
  513. context.arg = undefined$1;
  514. }
  515. return !!caught;
  516. }
  517. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  518. var entry = this.tryEntries[i];
  519. var record = entry.completion;
  520. if (entry.tryLoc === "root") {
  521. // Exception thrown outside of any try block that could handle
  522. // it, so set the completion value of the entire function to
  523. // throw the exception.
  524. return handle("end");
  525. }
  526. if (entry.tryLoc <= this.prev) {
  527. var hasCatch = hasOwn.call(entry, "catchLoc");
  528. var hasFinally = hasOwn.call(entry, "finallyLoc");
  529. if (hasCatch && hasFinally) {
  530. if (this.prev < entry.catchLoc) {
  531. return handle(entry.catchLoc, true);
  532. } else if (this.prev < entry.finallyLoc) {
  533. return handle(entry.finallyLoc);
  534. }
  535. } else if (hasCatch) {
  536. if (this.prev < entry.catchLoc) {
  537. return handle(entry.catchLoc, true);
  538. }
  539. } else if (hasFinally) {
  540. if (this.prev < entry.finallyLoc) {
  541. return handle(entry.finallyLoc);
  542. }
  543. } else {
  544. throw new Error("try statement without catch or finally");
  545. }
  546. }
  547. }
  548. },
  549. abrupt: function abrupt(type, arg) {
  550. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  551. var entry = this.tryEntries[i];
  552. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  553. var finallyEntry = entry;
  554. break;
  555. }
  556. }
  557. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  558. // Ignore the finally entry if control is not jumping to a
  559. // location outside the try/catch block.
  560. finallyEntry = null;
  561. }
  562. var record = finallyEntry ? finallyEntry.completion : {};
  563. record.type = type;
  564. record.arg = arg;
  565. if (finallyEntry) {
  566. this.method = "next";
  567. this.next = finallyEntry.finallyLoc;
  568. return ContinueSentinel;
  569. }
  570. return this.complete(record);
  571. },
  572. complete: function complete(record, afterLoc) {
  573. if (record.type === "throw") {
  574. throw record.arg;
  575. }
  576. if (record.type === "break" || record.type === "continue") {
  577. this.next = record.arg;
  578. } else if (record.type === "return") {
  579. this.rval = this.arg = record.arg;
  580. this.method = "return";
  581. this.next = "end";
  582. } else if (record.type === "normal" && afterLoc) {
  583. this.next = afterLoc;
  584. }
  585. return ContinueSentinel;
  586. },
  587. finish: function finish(finallyLoc) {
  588. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  589. var entry = this.tryEntries[i];
  590. if (entry.finallyLoc === finallyLoc) {
  591. this.complete(entry.completion, entry.afterLoc);
  592. resetTryEntry(entry);
  593. return ContinueSentinel;
  594. }
  595. }
  596. },
  597. "catch": function _catch(tryLoc) {
  598. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  599. var entry = this.tryEntries[i];
  600. if (entry.tryLoc === tryLoc) {
  601. var record = entry.completion;
  602. if (record.type === "throw") {
  603. var thrown = record.arg;
  604. resetTryEntry(entry);
  605. }
  606. return thrown;
  607. }
  608. } // The context.catch method must only be called with a location
  609. // argument that corresponds to a known catch block.
  610. throw new Error("illegal catch attempt");
  611. },
  612. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  613. this.delegate = {
  614. iterator: values(iterable),
  615. resultName: resultName,
  616. nextLoc: nextLoc
  617. };
  618. if (this.method === "next") {
  619. // Deliberately forget the last sent value so that we don't
  620. // accidentally pass it on to the delegate.
  621. this.arg = undefined$1;
  622. }
  623. return ContinueSentinel;
  624. }
  625. }; // Regardless of whether this script is executing as a CommonJS module
  626. // or not, return the runtime object so that we can declare the variable
  627. // regeneratorRuntime in the outer scope, which allows this module to be
  628. // injected easily by `bin/regenerator --include-runtime script.js`.
  629. return exports;
  630. }( // If this script is executing as a CommonJS module, use module.exports
  631. // as the regeneratorRuntime namespace. Otherwise create a new empty
  632. // object. Either way, the resulting object will be used to initialize
  633. // the regeneratorRuntime variable at the top of this file.
  634. typeof module === "object" ? module.exports : {});
  635. try {
  636. regeneratorRuntime = runtime;
  637. } catch (accidentalStrictMode) {
  638. // This module should not be running in strict mode, so the above
  639. // assignment should always work unless something is misconfigured. Just
  640. // in case runtime.js accidentally runs in strict mode, we can escape
  641. // strict mode using a global Function call. This could conceivably fail
  642. // if a Content Security Policy forbids using Function, but in that case
  643. // the proper solution is to fix the accidental strict mode problem. If
  644. // you've misconfigured your bundler to force strict mode and applied a
  645. // CSP to forbid Function, and you're not willing to fix either of those
  646. // problems, please detail your unique predicament in a GitHub issue.
  647. Function("r", "regeneratorRuntime = r")(runtime);
  648. }
  649. var REVISION = '126dev';
  650. var MOUSE = {
  651. LEFT: 0,
  652. MIDDLE: 1,
  653. RIGHT: 2,
  654. ROTATE: 0,
  655. DOLLY: 1,
  656. PAN: 2
  657. };
  658. var TOUCH = {
  659. ROTATE: 0,
  660. PAN: 1,
  661. DOLLY_PAN: 2,
  662. DOLLY_ROTATE: 3
  663. };
  664. var CullFaceNone = 0;
  665. var CullFaceBack = 1;
  666. var CullFaceFront = 2;
  667. var CullFaceFrontBack = 3;
  668. var BasicShadowMap = 0;
  669. var PCFShadowMap = 1;
  670. var PCFSoftShadowMap = 2;
  671. var VSMShadowMap = 3;
  672. var FrontSide = 0;
  673. var BackSide = 1;
  674. var DoubleSide = 2;
  675. var FlatShading = 1;
  676. var SmoothShading = 2;
  677. var NoBlending = 0;
  678. var NormalBlending = 1;
  679. var AdditiveBlending = 2;
  680. var SubtractiveBlending = 3;
  681. var MultiplyBlending = 4;
  682. var CustomBlending = 5;
  683. var AddEquation = 100;
  684. var SubtractEquation = 101;
  685. var ReverseSubtractEquation = 102;
  686. var MinEquation = 103;
  687. var MaxEquation = 104;
  688. var ZeroFactor = 200;
  689. var OneFactor = 201;
  690. var SrcColorFactor = 202;
  691. var OneMinusSrcColorFactor = 203;
  692. var SrcAlphaFactor = 204;
  693. var OneMinusSrcAlphaFactor = 205;
  694. var DstAlphaFactor = 206;
  695. var OneMinusDstAlphaFactor = 207;
  696. var DstColorFactor = 208;
  697. var OneMinusDstColorFactor = 209;
  698. var SrcAlphaSaturateFactor = 210;
  699. var NeverDepth = 0;
  700. var AlwaysDepth = 1;
  701. var LessDepth = 2;
  702. var LessEqualDepth = 3;
  703. var EqualDepth = 4;
  704. var GreaterEqualDepth = 5;
  705. var GreaterDepth = 6;
  706. var NotEqualDepth = 7;
  707. var MultiplyOperation = 0;
  708. var MixOperation = 1;
  709. var AddOperation = 2;
  710. var NoToneMapping = 0;
  711. var LinearToneMapping = 1;
  712. var ReinhardToneMapping = 2;
  713. var CineonToneMapping = 3;
  714. var ACESFilmicToneMapping = 4;
  715. var CustomToneMapping = 5;
  716. var UVMapping = 300;
  717. var CubeReflectionMapping = 301;
  718. var CubeRefractionMapping = 302;
  719. var EquirectangularReflectionMapping = 303;
  720. var EquirectangularRefractionMapping = 304;
  721. var CubeUVReflectionMapping = 306;
  722. var CubeUVRefractionMapping = 307;
  723. var RepeatWrapping = 1000;
  724. var ClampToEdgeWrapping = 1001;
  725. var MirroredRepeatWrapping = 1002;
  726. var NearestFilter = 1003;
  727. var NearestMipmapNearestFilter = 1004;
  728. var NearestMipMapNearestFilter = 1004;
  729. var NearestMipmapLinearFilter = 1005;
  730. var NearestMipMapLinearFilter = 1005;
  731. var LinearFilter = 1006;
  732. var LinearMipmapNearestFilter = 1007;
  733. var LinearMipMapNearestFilter = 1007;
  734. var LinearMipmapLinearFilter = 1008;
  735. var LinearMipMapLinearFilter = 1008;
  736. var UnsignedByteType = 1009;
  737. var ByteType = 1010;
  738. var ShortType = 1011;
  739. var UnsignedShortType = 1012;
  740. var IntType = 1013;
  741. var UnsignedIntType = 1014;
  742. var FloatType = 1015;
  743. var HalfFloatType = 1016;
  744. var UnsignedShort4444Type = 1017;
  745. var UnsignedShort5551Type = 1018;
  746. var UnsignedShort565Type = 1019;
  747. var UnsignedInt248Type = 1020;
  748. var AlphaFormat = 1021;
  749. var RGBFormat = 1022;
  750. var RGBAFormat = 1023;
  751. var LuminanceFormat = 1024;
  752. var LuminanceAlphaFormat = 1025;
  753. var RGBEFormat = RGBAFormat;
  754. var DepthFormat = 1026;
  755. var DepthStencilFormat = 1027;
  756. var RedFormat = 1028;
  757. var RedIntegerFormat = 1029;
  758. var RGFormat = 1030;
  759. var RGIntegerFormat = 1031;
  760. var RGBIntegerFormat = 1032;
  761. var RGBAIntegerFormat = 1033;
  762. var RGB_S3TC_DXT1_Format = 33776;
  763. var RGBA_S3TC_DXT1_Format = 33777;
  764. var RGBA_S3TC_DXT3_Format = 33778;
  765. var RGBA_S3TC_DXT5_Format = 33779;
  766. var RGB_PVRTC_4BPPV1_Format = 35840;
  767. var RGB_PVRTC_2BPPV1_Format = 35841;
  768. var RGBA_PVRTC_4BPPV1_Format = 35842;
  769. var RGBA_PVRTC_2BPPV1_Format = 35843;
  770. var RGB_ETC1_Format = 36196;
  771. var RGB_ETC2_Format = 37492;
  772. var RGBA_ETC2_EAC_Format = 37496;
  773. var RGBA_ASTC_4x4_Format = 37808;
  774. var RGBA_ASTC_5x4_Format = 37809;
  775. var RGBA_ASTC_5x5_Format = 37810;
  776. var RGBA_ASTC_6x5_Format = 37811;
  777. var RGBA_ASTC_6x6_Format = 37812;
  778. var RGBA_ASTC_8x5_Format = 37813;
  779. var RGBA_ASTC_8x6_Format = 37814;
  780. var RGBA_ASTC_8x8_Format = 37815;
  781. var RGBA_ASTC_10x5_Format = 37816;
  782. var RGBA_ASTC_10x6_Format = 37817;
  783. var RGBA_ASTC_10x8_Format = 37818;
  784. var RGBA_ASTC_10x10_Format = 37819;
  785. var RGBA_ASTC_12x10_Format = 37820;
  786. var RGBA_ASTC_12x12_Format = 37821;
  787. var RGBA_BPTC_Format = 36492;
  788. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  789. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  790. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  791. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  792. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  793. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  794. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  795. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  796. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  797. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  798. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  799. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  800. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  801. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  802. var LoopOnce = 2200;
  803. var LoopRepeat = 2201;
  804. var LoopPingPong = 2202;
  805. var InterpolateDiscrete = 2300;
  806. var InterpolateLinear = 2301;
  807. var InterpolateSmooth = 2302;
  808. var ZeroCurvatureEnding = 2400;
  809. var ZeroSlopeEnding = 2401;
  810. var WrapAroundEnding = 2402;
  811. var NormalAnimationBlendMode = 2500;
  812. var AdditiveAnimationBlendMode = 2501;
  813. var TrianglesDrawMode = 0;
  814. var TriangleStripDrawMode = 1;
  815. var TriangleFanDrawMode = 2;
  816. var LinearEncoding = 3000;
  817. var sRGBEncoding = 3001;
  818. var GammaEncoding = 3007;
  819. var RGBEEncoding = 3002;
  820. var LogLuvEncoding = 3003;
  821. var RGBM7Encoding = 3004;
  822. var RGBM16Encoding = 3005;
  823. var RGBDEncoding = 3006;
  824. var BasicDepthPacking = 3200;
  825. var RGBADepthPacking = 3201;
  826. var TangentSpaceNormalMap = 0;
  827. var ObjectSpaceNormalMap = 1;
  828. var ZeroStencilOp = 0;
  829. var KeepStencilOp = 7680;
  830. var ReplaceStencilOp = 7681;
  831. var IncrementStencilOp = 7682;
  832. var DecrementStencilOp = 7683;
  833. var IncrementWrapStencilOp = 34055;
  834. var DecrementWrapStencilOp = 34056;
  835. var InvertStencilOp = 5386;
  836. var NeverStencilFunc = 512;
  837. var LessStencilFunc = 513;
  838. var EqualStencilFunc = 514;
  839. var LessEqualStencilFunc = 515;
  840. var GreaterStencilFunc = 516;
  841. var NotEqualStencilFunc = 517;
  842. var GreaterEqualStencilFunc = 518;
  843. var AlwaysStencilFunc = 519;
  844. var StaticDrawUsage = 35044;
  845. var DynamicDrawUsage = 35048;
  846. var StreamDrawUsage = 35040;
  847. var StaticReadUsage = 35045;
  848. var DynamicReadUsage = 35049;
  849. var StreamReadUsage = 35041;
  850. var StaticCopyUsage = 35046;
  851. var DynamicCopyUsage = 35050;
  852. var StreamCopyUsage = 35042;
  853. var GLSL1 = '100';
  854. var GLSL3 = '300 es';
  855. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  856. try {
  857. var info = gen[key](arg);
  858. var value = info.value;
  859. } catch (error) {
  860. reject(error);
  861. return;
  862. }
  863. if (info.done) {
  864. resolve(value);
  865. } else {
  866. Promise.resolve(value).then(_next, _throw);
  867. }
  868. }
  869. function _asyncToGenerator(fn) {
  870. return function () {
  871. var self = this,
  872. args = arguments;
  873. return new Promise(function (resolve, reject) {
  874. var gen = fn.apply(self, args);
  875. function _next(value) {
  876. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  877. }
  878. function _throw(err) {
  879. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  880. }
  881. _next(undefined);
  882. });
  883. };
  884. }
  885. function _defineProperties(target, props) {
  886. for (var i = 0; i < props.length; i++) {
  887. var descriptor = props[i];
  888. descriptor.enumerable = descriptor.enumerable || false;
  889. descriptor.configurable = true;
  890. if ("value" in descriptor) descriptor.writable = true;
  891. Object.defineProperty(target, descriptor.key, descriptor);
  892. }
  893. }
  894. function _createClass(Constructor, protoProps, staticProps) {
  895. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  896. if (staticProps) _defineProperties(Constructor, staticProps);
  897. return Constructor;
  898. }
  899. function _inheritsLoose(subClass, superClass) {
  900. subClass.prototype = Object.create(superClass.prototype);
  901. subClass.prototype.constructor = subClass;
  902. _setPrototypeOf(subClass, superClass);
  903. }
  904. function _setPrototypeOf(o, p) {
  905. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  906. o.__proto__ = p;
  907. return o;
  908. };
  909. return _setPrototypeOf(o, p);
  910. }
  911. function _assertThisInitialized(self) {
  912. if (self === void 0) {
  913. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  914. }
  915. return self;
  916. }
  917. function _unsupportedIterableToArray(o, minLen) {
  918. if (!o) return;
  919. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  920. var n = Object.prototype.toString.call(o).slice(8, -1);
  921. if (n === "Object" && o.constructor) n = o.constructor.name;
  922. if (n === "Map" || n === "Set") return Array.from(o);
  923. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  924. }
  925. function _arrayLikeToArray(arr, len) {
  926. if (len == null || len > arr.length) len = arr.length;
  927. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  928. return arr2;
  929. }
  930. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  931. var it;
  932. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  933. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  934. if (it) o = it;
  935. var i = 0;
  936. return function () {
  937. if (i >= o.length) return {
  938. done: true
  939. };
  940. return {
  941. done: false,
  942. value: o[i++]
  943. };
  944. };
  945. }
  946. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  947. }
  948. it = o[Symbol.iterator]();
  949. return it.next.bind(it);
  950. }
  951. /**
  952. * https://github.com/mrdoob/eventdispatcher.js/
  953. */
  954. function EventDispatcher() {}
  955. Object.assign(EventDispatcher.prototype, {
  956. addEventListener: function addEventListener(type, listener) {
  957. if (this._listeners === undefined) this._listeners = {};
  958. var listeners = this._listeners;
  959. if (listeners[type] === undefined) {
  960. listeners[type] = [];
  961. }
  962. if (listeners[type].indexOf(listener) === -1) {
  963. listeners[type].push(listener);
  964. }
  965. },
  966. hasEventListener: function hasEventListener(type, listener) {
  967. if (this._listeners === undefined) return false;
  968. var listeners = this._listeners;
  969. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  970. },
  971. removeEventListener: function removeEventListener(type, listener) {
  972. if (this._listeners === undefined) return;
  973. var listeners = this._listeners;
  974. var listenerArray = listeners[type];
  975. if (listenerArray !== undefined) {
  976. var index = listenerArray.indexOf(listener);
  977. if (index !== -1) {
  978. listenerArray.splice(index, 1);
  979. }
  980. }
  981. },
  982. dispatchEvent: function dispatchEvent(event) {
  983. if (this._listeners === undefined) return;
  984. var listeners = this._listeners;
  985. var listenerArray = listeners[event.type];
  986. if (listenerArray !== undefined) {
  987. event.target = this; // Make a copy, in case listeners are removed while iterating.
  988. var array = listenerArray.slice(0);
  989. for (var i = 0, l = array.length; i < l; i++) {
  990. array[i].call(this, event);
  991. }
  992. }
  993. }
  994. });
  995. var _lut = [];
  996. for (var i = 0; i < 256; i++) {
  997. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  998. }
  999. var _seed = 1234567;
  1000. var MathUtils = {
  1001. DEG2RAD: Math.PI / 180,
  1002. RAD2DEG: 180 / Math.PI,
  1003. generateUUID: function generateUUID() {
  1004. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  1005. var d0 = Math.random() * 0xffffffff | 0;
  1006. var d1 = Math.random() * 0xffffffff | 0;
  1007. var d2 = Math.random() * 0xffffffff | 0;
  1008. var d3 = Math.random() * 0xffffffff | 0;
  1009. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  1010. return uuid.toUpperCase();
  1011. },
  1012. clamp: function clamp(value, min, max) {
  1013. return Math.max(min, Math.min(max, value));
  1014. },
  1015. // compute euclidian modulo of m % n
  1016. // https://en.wikipedia.org/wiki/Modulo_operation
  1017. euclideanModulo: function euclideanModulo(n, m) {
  1018. return (n % m + m) % m;
  1019. },
  1020. // Linear mapping from range <a1, a2> to range <b1, b2>
  1021. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  1022. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  1023. },
  1024. // https://en.wikipedia.org/wiki/Linear_interpolation
  1025. lerp: function lerp(x, y, t) {
  1026. return (1 - t) * x + t * y;
  1027. },
  1028. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  1029. damp: function damp(x, y, lambda, dt) {
  1030. return MathUtils.lerp(x, y, 1 - Math.exp(-lambda * dt));
  1031. },
  1032. // https://www.desmos.com/calculator/vcsjnyz7x4
  1033. pingpong: function pingpong(x, length) {
  1034. if (length === void 0) {
  1035. length = 1;
  1036. }
  1037. return length - Math.abs(MathUtils.euclideanModulo(x, length * 2) - length);
  1038. },
  1039. // http://en.wikipedia.org/wiki/Smoothstep
  1040. smoothstep: function smoothstep(x, min, max) {
  1041. if (x <= min) return 0;
  1042. if (x >= max) return 1;
  1043. x = (x - min) / (max - min);
  1044. return x * x * (3 - 2 * x);
  1045. },
  1046. smootherstep: function smootherstep(x, min, max) {
  1047. if (x <= min) return 0;
  1048. if (x >= max) return 1;
  1049. x = (x - min) / (max - min);
  1050. return x * x * x * (x * (x * 6 - 15) + 10);
  1051. },
  1052. // Random integer from <low, high> interval
  1053. randInt: function randInt(low, high) {
  1054. return low + Math.floor(Math.random() * (high - low + 1));
  1055. },
  1056. // Random float from <low, high> interval
  1057. randFloat: function randFloat(low, high) {
  1058. return low + Math.random() * (high - low);
  1059. },
  1060. // Random float from <-range/2, range/2> interval
  1061. randFloatSpread: function randFloatSpread(range) {
  1062. return range * (0.5 - Math.random());
  1063. },
  1064. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  1065. seededRandom: function seededRandom(s) {
  1066. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  1067. _seed = _seed * 16807 % 2147483647;
  1068. return (_seed - 1) / 2147483646;
  1069. },
  1070. degToRad: function degToRad(degrees) {
  1071. return degrees * MathUtils.DEG2RAD;
  1072. },
  1073. radToDeg: function radToDeg(radians) {
  1074. return radians * MathUtils.RAD2DEG;
  1075. },
  1076. isPowerOfTwo: function isPowerOfTwo(value) {
  1077. return (value & value - 1) === 0 && value !== 0;
  1078. },
  1079. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  1080. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  1081. },
  1082. floorPowerOfTwo: function floorPowerOfTwo(value) {
  1083. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  1084. },
  1085. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  1086. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  1087. // rotations are applied to the axes in the order specified by 'order'
  1088. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  1089. // angles are in radians
  1090. var cos = Math.cos;
  1091. var sin = Math.sin;
  1092. var c2 = cos(b / 2);
  1093. var s2 = sin(b / 2);
  1094. var c13 = cos((a + c) / 2);
  1095. var s13 = sin((a + c) / 2);
  1096. var c1_3 = cos((a - c) / 2);
  1097. var s1_3 = sin((a - c) / 2);
  1098. var c3_1 = cos((c - a) / 2);
  1099. var s3_1 = sin((c - a) / 2);
  1100. switch (order) {
  1101. case 'XYX':
  1102. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  1103. break;
  1104. case 'YZY':
  1105. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  1106. break;
  1107. case 'ZXZ':
  1108. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  1109. break;
  1110. case 'XZX':
  1111. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  1112. break;
  1113. case 'YXY':
  1114. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  1115. break;
  1116. case 'ZYZ':
  1117. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  1118. break;
  1119. default:
  1120. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  1121. }
  1122. }
  1123. };
  1124. var Vector2 = /*#__PURE__*/function () {
  1125. function Vector2(x, y) {
  1126. if (x === void 0) {
  1127. x = 0;
  1128. }
  1129. if (y === void 0) {
  1130. y = 0;
  1131. }
  1132. this.x = x;
  1133. this.y = y;
  1134. }
  1135. var _proto = Vector2.prototype;
  1136. _proto.set = function set(x, y) {
  1137. this.x = x;
  1138. this.y = y;
  1139. return this;
  1140. };
  1141. _proto.setScalar = function setScalar(scalar) {
  1142. this.x = scalar;
  1143. this.y = scalar;
  1144. return this;
  1145. };
  1146. _proto.setX = function setX(x) {
  1147. this.x = x;
  1148. return this;
  1149. };
  1150. _proto.setY = function setY(y) {
  1151. this.y = y;
  1152. return this;
  1153. };
  1154. _proto.setComponent = function setComponent(index, value) {
  1155. switch (index) {
  1156. case 0:
  1157. this.x = value;
  1158. break;
  1159. case 1:
  1160. this.y = value;
  1161. break;
  1162. default:
  1163. throw new Error('index is out of range: ' + index);
  1164. }
  1165. return this;
  1166. };
  1167. _proto.getComponent = function getComponent(index) {
  1168. switch (index) {
  1169. case 0:
  1170. return this.x;
  1171. case 1:
  1172. return this.y;
  1173. default:
  1174. throw new Error('index is out of range: ' + index);
  1175. }
  1176. };
  1177. _proto.clone = function clone() {
  1178. return new this.constructor(this.x, this.y);
  1179. };
  1180. _proto.copy = function copy(v) {
  1181. this.x = v.x;
  1182. this.y = v.y;
  1183. return this;
  1184. };
  1185. _proto.add = function add(v, w) {
  1186. if (w !== undefined) {
  1187. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1188. return this.addVectors(v, w);
  1189. }
  1190. this.x += v.x;
  1191. this.y += v.y;
  1192. return this;
  1193. };
  1194. _proto.addScalar = function addScalar(s) {
  1195. this.x += s;
  1196. this.y += s;
  1197. return this;
  1198. };
  1199. _proto.addVectors = function addVectors(a, b) {
  1200. this.x = a.x + b.x;
  1201. this.y = a.y + b.y;
  1202. return this;
  1203. };
  1204. _proto.addScaledVector = function addScaledVector(v, s) {
  1205. this.x += v.x * s;
  1206. this.y += v.y * s;
  1207. return this;
  1208. };
  1209. _proto.sub = function sub(v, w) {
  1210. if (w !== undefined) {
  1211. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1212. return this.subVectors(v, w);
  1213. }
  1214. this.x -= v.x;
  1215. this.y -= v.y;
  1216. return this;
  1217. };
  1218. _proto.subScalar = function subScalar(s) {
  1219. this.x -= s;
  1220. this.y -= s;
  1221. return this;
  1222. };
  1223. _proto.subVectors = function subVectors(a, b) {
  1224. this.x = a.x - b.x;
  1225. this.y = a.y - b.y;
  1226. return this;
  1227. };
  1228. _proto.multiply = function multiply(v) {
  1229. this.x *= v.x;
  1230. this.y *= v.y;
  1231. return this;
  1232. };
  1233. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1234. this.x *= scalar;
  1235. this.y *= scalar;
  1236. return this;
  1237. };
  1238. _proto.divide = function divide(v) {
  1239. this.x /= v.x;
  1240. this.y /= v.y;
  1241. return this;
  1242. };
  1243. _proto.divideScalar = function divideScalar(scalar) {
  1244. return this.multiplyScalar(1 / scalar);
  1245. };
  1246. _proto.applyMatrix3 = function applyMatrix3(m) {
  1247. var x = this.x,
  1248. y = this.y;
  1249. var e = m.elements;
  1250. this.x = e[0] * x + e[3] * y + e[6];
  1251. this.y = e[1] * x + e[4] * y + e[7];
  1252. return this;
  1253. };
  1254. _proto.min = function min(v) {
  1255. this.x = Math.min(this.x, v.x);
  1256. this.y = Math.min(this.y, v.y);
  1257. return this;
  1258. };
  1259. _proto.max = function max(v) {
  1260. this.x = Math.max(this.x, v.x);
  1261. this.y = Math.max(this.y, v.y);
  1262. return this;
  1263. };
  1264. _proto.clamp = function clamp(min, max) {
  1265. // assumes min < max, componentwise
  1266. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1267. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1268. return this;
  1269. };
  1270. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1271. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1272. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1273. return this;
  1274. };
  1275. _proto.clampLength = function clampLength(min, max) {
  1276. var length = this.length();
  1277. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1278. };
  1279. _proto.floor = function floor() {
  1280. this.x = Math.floor(this.x);
  1281. this.y = Math.floor(this.y);
  1282. return this;
  1283. };
  1284. _proto.ceil = function ceil() {
  1285. this.x = Math.ceil(this.x);
  1286. this.y = Math.ceil(this.y);
  1287. return this;
  1288. };
  1289. _proto.round = function round() {
  1290. this.x = Math.round(this.x);
  1291. this.y = Math.round(this.y);
  1292. return this;
  1293. };
  1294. _proto.roundToZero = function roundToZero() {
  1295. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1296. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1297. return this;
  1298. };
  1299. _proto.negate = function negate() {
  1300. this.x = -this.x;
  1301. this.y = -this.y;
  1302. return this;
  1303. };
  1304. _proto.dot = function dot(v) {
  1305. return this.x * v.x + this.y * v.y;
  1306. };
  1307. _proto.cross = function cross(v) {
  1308. return this.x * v.y - this.y * v.x;
  1309. };
  1310. _proto.lengthSq = function lengthSq() {
  1311. return this.x * this.x + this.y * this.y;
  1312. };
  1313. _proto.length = function length() {
  1314. return Math.sqrt(this.x * this.x + this.y * this.y);
  1315. };
  1316. _proto.manhattanLength = function manhattanLength() {
  1317. return Math.abs(this.x) + Math.abs(this.y);
  1318. };
  1319. _proto.normalize = function normalize() {
  1320. return this.divideScalar(this.length() || 1);
  1321. };
  1322. _proto.angle = function angle() {
  1323. // computes the angle in radians with respect to the positive x-axis
  1324. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  1325. return angle;
  1326. };
  1327. _proto.distanceTo = function distanceTo(v) {
  1328. return Math.sqrt(this.distanceToSquared(v));
  1329. };
  1330. _proto.distanceToSquared = function distanceToSquared(v) {
  1331. var dx = this.x - v.x,
  1332. dy = this.y - v.y;
  1333. return dx * dx + dy * dy;
  1334. };
  1335. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  1336. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  1337. };
  1338. _proto.setLength = function setLength(length) {
  1339. return this.normalize().multiplyScalar(length);
  1340. };
  1341. _proto.lerp = function lerp(v, alpha) {
  1342. this.x += (v.x - this.x) * alpha;
  1343. this.y += (v.y - this.y) * alpha;
  1344. return this;
  1345. };
  1346. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1347. this.x = v1.x + (v2.x - v1.x) * alpha;
  1348. this.y = v1.y + (v2.y - v1.y) * alpha;
  1349. return this;
  1350. };
  1351. _proto.equals = function equals(v) {
  1352. return v.x === this.x && v.y === this.y;
  1353. };
  1354. _proto.fromArray = function fromArray(array, offset) {
  1355. if (offset === void 0) {
  1356. offset = 0;
  1357. }
  1358. this.x = array[offset];
  1359. this.y = array[offset + 1];
  1360. return this;
  1361. };
  1362. _proto.toArray = function toArray(array, offset) {
  1363. if (array === void 0) {
  1364. array = [];
  1365. }
  1366. if (offset === void 0) {
  1367. offset = 0;
  1368. }
  1369. array[offset] = this.x;
  1370. array[offset + 1] = this.y;
  1371. return array;
  1372. };
  1373. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1374. if (offset !== undefined) {
  1375. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  1376. }
  1377. this.x = attribute.getX(index);
  1378. this.y = attribute.getY(index);
  1379. return this;
  1380. };
  1381. _proto.rotateAround = function rotateAround(center, angle) {
  1382. var c = Math.cos(angle),
  1383. s = Math.sin(angle);
  1384. var x = this.x - center.x;
  1385. var y = this.y - center.y;
  1386. this.x = x * c - y * s + center.x;
  1387. this.y = x * s + y * c + center.y;
  1388. return this;
  1389. };
  1390. _proto.random = function random() {
  1391. this.x = Math.random();
  1392. this.y = Math.random();
  1393. return this;
  1394. };
  1395. _createClass(Vector2, [{
  1396. key: "width",
  1397. get: function get() {
  1398. return this.x;
  1399. },
  1400. set: function set(value) {
  1401. this.x = value;
  1402. }
  1403. }, {
  1404. key: "height",
  1405. get: function get() {
  1406. return this.y;
  1407. },
  1408. set: function set(value) {
  1409. this.y = value;
  1410. }
  1411. }]);
  1412. return Vector2;
  1413. }();
  1414. Vector2.prototype.isVector2 = true;
  1415. var Matrix3 = /*#__PURE__*/function () {
  1416. function Matrix3() {
  1417. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  1418. if (arguments.length > 0) {
  1419. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  1420. }
  1421. }
  1422. var _proto = Matrix3.prototype;
  1423. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  1424. var te = this.elements;
  1425. te[0] = n11;
  1426. te[1] = n21;
  1427. te[2] = n31;
  1428. te[3] = n12;
  1429. te[4] = n22;
  1430. te[5] = n32;
  1431. te[6] = n13;
  1432. te[7] = n23;
  1433. te[8] = n33;
  1434. return this;
  1435. };
  1436. _proto.identity = function identity() {
  1437. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  1438. return this;
  1439. };
  1440. _proto.copy = function copy(m) {
  1441. var te = this.elements;
  1442. var me = m.elements;
  1443. te[0] = me[0];
  1444. te[1] = me[1];
  1445. te[2] = me[2];
  1446. te[3] = me[3];
  1447. te[4] = me[4];
  1448. te[5] = me[5];
  1449. te[6] = me[6];
  1450. te[7] = me[7];
  1451. te[8] = me[8];
  1452. return this;
  1453. };
  1454. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  1455. xAxis.setFromMatrix3Column(this, 0);
  1456. yAxis.setFromMatrix3Column(this, 1);
  1457. zAxis.setFromMatrix3Column(this, 2);
  1458. return this;
  1459. };
  1460. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  1461. var me = m.elements;
  1462. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  1463. return this;
  1464. };
  1465. _proto.multiply = function multiply(m) {
  1466. return this.multiplyMatrices(this, m);
  1467. };
  1468. _proto.premultiply = function premultiply(m) {
  1469. return this.multiplyMatrices(m, this);
  1470. };
  1471. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  1472. var ae = a.elements;
  1473. var be = b.elements;
  1474. var te = this.elements;
  1475. var a11 = ae[0],
  1476. a12 = ae[3],
  1477. a13 = ae[6];
  1478. var a21 = ae[1],
  1479. a22 = ae[4],
  1480. a23 = ae[7];
  1481. var a31 = ae[2],
  1482. a32 = ae[5],
  1483. a33 = ae[8];
  1484. var b11 = be[0],
  1485. b12 = be[3],
  1486. b13 = be[6];
  1487. var b21 = be[1],
  1488. b22 = be[4],
  1489. b23 = be[7];
  1490. var b31 = be[2],
  1491. b32 = be[5],
  1492. b33 = be[8];
  1493. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  1494. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  1495. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  1496. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  1497. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  1498. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  1499. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  1500. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  1501. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  1502. return this;
  1503. };
  1504. _proto.multiplyScalar = function multiplyScalar(s) {
  1505. var te = this.elements;
  1506. te[0] *= s;
  1507. te[3] *= s;
  1508. te[6] *= s;
  1509. te[1] *= s;
  1510. te[4] *= s;
  1511. te[7] *= s;
  1512. te[2] *= s;
  1513. te[5] *= s;
  1514. te[8] *= s;
  1515. return this;
  1516. };
  1517. _proto.determinant = function determinant() {
  1518. var te = this.elements;
  1519. var a = te[0],
  1520. b = te[1],
  1521. c = te[2],
  1522. d = te[3],
  1523. e = te[4],
  1524. f = te[5],
  1525. g = te[6],
  1526. h = te[7],
  1527. i = te[8];
  1528. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1529. };
  1530. _proto.invert = function invert() {
  1531. var te = this.elements,
  1532. n11 = te[0],
  1533. n21 = te[1],
  1534. n31 = te[2],
  1535. n12 = te[3],
  1536. n22 = te[4],
  1537. n32 = te[5],
  1538. n13 = te[6],
  1539. n23 = te[7],
  1540. n33 = te[8],
  1541. t11 = n33 * n22 - n32 * n23,
  1542. t12 = n32 * n13 - n33 * n12,
  1543. t13 = n23 * n12 - n22 * n13,
  1544. det = n11 * t11 + n21 * t12 + n31 * t13;
  1545. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  1546. var detInv = 1 / det;
  1547. te[0] = t11 * detInv;
  1548. te[1] = (n31 * n23 - n33 * n21) * detInv;
  1549. te[2] = (n32 * n21 - n31 * n22) * detInv;
  1550. te[3] = t12 * detInv;
  1551. te[4] = (n33 * n11 - n31 * n13) * detInv;
  1552. te[5] = (n31 * n12 - n32 * n11) * detInv;
  1553. te[6] = t13 * detInv;
  1554. te[7] = (n21 * n13 - n23 * n11) * detInv;
  1555. te[8] = (n22 * n11 - n21 * n12) * detInv;
  1556. return this;
  1557. };
  1558. _proto.transpose = function transpose() {
  1559. var tmp;
  1560. var m = this.elements;
  1561. tmp = m[1];
  1562. m[1] = m[3];
  1563. m[3] = tmp;
  1564. tmp = m[2];
  1565. m[2] = m[6];
  1566. m[6] = tmp;
  1567. tmp = m[5];
  1568. m[5] = m[7];
  1569. m[7] = tmp;
  1570. return this;
  1571. };
  1572. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  1573. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  1574. };
  1575. _proto.transposeIntoArray = function transposeIntoArray(r) {
  1576. var m = this.elements;
  1577. r[0] = m[0];
  1578. r[1] = m[3];
  1579. r[2] = m[6];
  1580. r[3] = m[1];
  1581. r[4] = m[4];
  1582. r[5] = m[7];
  1583. r[6] = m[2];
  1584. r[7] = m[5];
  1585. r[8] = m[8];
  1586. return this;
  1587. };
  1588. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  1589. var c = Math.cos(rotation);
  1590. var s = Math.sin(rotation);
  1591. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  1592. return this;
  1593. };
  1594. _proto.scale = function scale(sx, sy) {
  1595. var te = this.elements;
  1596. te[0] *= sx;
  1597. te[3] *= sx;
  1598. te[6] *= sx;
  1599. te[1] *= sy;
  1600. te[4] *= sy;
  1601. te[7] *= sy;
  1602. return this;
  1603. };
  1604. _proto.rotate = function rotate(theta) {
  1605. var c = Math.cos(theta);
  1606. var s = Math.sin(theta);
  1607. var te = this.elements;
  1608. var a11 = te[0],
  1609. a12 = te[3],
  1610. a13 = te[6];
  1611. var a21 = te[1],
  1612. a22 = te[4],
  1613. a23 = te[7];
  1614. te[0] = c * a11 + s * a21;
  1615. te[3] = c * a12 + s * a22;
  1616. te[6] = c * a13 + s * a23;
  1617. te[1] = -s * a11 + c * a21;
  1618. te[4] = -s * a12 + c * a22;
  1619. te[7] = -s * a13 + c * a23;
  1620. return this;
  1621. };
  1622. _proto.translate = function translate(tx, ty) {
  1623. var te = this.elements;
  1624. te[0] += tx * te[2];
  1625. te[3] += tx * te[5];
  1626. te[6] += tx * te[8];
  1627. te[1] += ty * te[2];
  1628. te[4] += ty * te[5];
  1629. te[7] += ty * te[8];
  1630. return this;
  1631. };
  1632. _proto.equals = function equals(matrix) {
  1633. var te = this.elements;
  1634. var me = matrix.elements;
  1635. for (var i = 0; i < 9; i++) {
  1636. if (te[i] !== me[i]) return false;
  1637. }
  1638. return true;
  1639. };
  1640. _proto.fromArray = function fromArray(array, offset) {
  1641. if (offset === void 0) {
  1642. offset = 0;
  1643. }
  1644. for (var i = 0; i < 9; i++) {
  1645. this.elements[i] = array[i + offset];
  1646. }
  1647. return this;
  1648. };
  1649. _proto.toArray = function toArray(array, offset) {
  1650. if (array === void 0) {
  1651. array = [];
  1652. }
  1653. if (offset === void 0) {
  1654. offset = 0;
  1655. }
  1656. var te = this.elements;
  1657. array[offset] = te[0];
  1658. array[offset + 1] = te[1];
  1659. array[offset + 2] = te[2];
  1660. array[offset + 3] = te[3];
  1661. array[offset + 4] = te[4];
  1662. array[offset + 5] = te[5];
  1663. array[offset + 6] = te[6];
  1664. array[offset + 7] = te[7];
  1665. array[offset + 8] = te[8];
  1666. return array;
  1667. };
  1668. _proto.clone = function clone() {
  1669. return new this.constructor().fromArray(this.elements);
  1670. };
  1671. return Matrix3;
  1672. }();
  1673. Matrix3.prototype.isMatrix3 = true;
  1674. var _canvas;
  1675. var ImageUtils = {
  1676. getDataURL: function getDataURL(image) {
  1677. if (/^data:/i.test(image.src)) {
  1678. return image.src;
  1679. }
  1680. if (typeof HTMLCanvasElement == 'undefined') {
  1681. return image.src;
  1682. }
  1683. var canvas;
  1684. if (image instanceof HTMLCanvasElement) {
  1685. canvas = image;
  1686. } else {
  1687. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1688. _canvas.width = image.width;
  1689. _canvas.height = image.height;
  1690. var context = _canvas.getContext('2d');
  1691. if (image instanceof ImageData) {
  1692. context.putImageData(image, 0, 0);
  1693. } else {
  1694. context.drawImage(image, 0, 0, image.width, image.height);
  1695. }
  1696. canvas = _canvas;
  1697. }
  1698. if (canvas.width > 2048 || canvas.height > 2048) {
  1699. return canvas.toDataURL('image/jpeg', 0.6);
  1700. } else {
  1701. return canvas.toDataURL('image/png');
  1702. }
  1703. }
  1704. };
  1705. var textureId = 0;
  1706. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1707. if (image === void 0) {
  1708. image = Texture.DEFAULT_IMAGE;
  1709. }
  1710. if (mapping === void 0) {
  1711. mapping = Texture.DEFAULT_MAPPING;
  1712. }
  1713. if (wrapS === void 0) {
  1714. wrapS = ClampToEdgeWrapping;
  1715. }
  1716. if (wrapT === void 0) {
  1717. wrapT = ClampToEdgeWrapping;
  1718. }
  1719. if (magFilter === void 0) {
  1720. magFilter = LinearFilter;
  1721. }
  1722. if (minFilter === void 0) {
  1723. minFilter = LinearMipmapLinearFilter;
  1724. }
  1725. if (format === void 0) {
  1726. format = RGBAFormat;
  1727. }
  1728. if (type === void 0) {
  1729. type = UnsignedByteType;
  1730. }
  1731. if (anisotropy === void 0) {
  1732. anisotropy = 1;
  1733. }
  1734. if (encoding === void 0) {
  1735. encoding = LinearEncoding;
  1736. }
  1737. Object.defineProperty(this, 'id', {
  1738. value: textureId++
  1739. });
  1740. this.uuid = MathUtils.generateUUID();
  1741. this.name = '';
  1742. this.image = image;
  1743. this.mipmaps = [];
  1744. this.mapping = mapping;
  1745. this.wrapS = wrapS;
  1746. this.wrapT = wrapT;
  1747. this.magFilter = magFilter;
  1748. this.minFilter = minFilter;
  1749. this.anisotropy = anisotropy;
  1750. this.format = format;
  1751. this.internalFormat = null;
  1752. this.type = type;
  1753. this.offset = new Vector2(0, 0);
  1754. this.repeat = new Vector2(1, 1);
  1755. this.center = new Vector2(0, 0);
  1756. this.rotation = 0;
  1757. this.matrixAutoUpdate = true;
  1758. this.matrix = new Matrix3();
  1759. this.generateMipmaps = true;
  1760. this.premultiplyAlpha = false;
  1761. this.flipY = true;
  1762. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1763. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1764. //
  1765. // Also changing the encoding after already used by a Material will not automatically make the Material
  1766. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1767. this.encoding = encoding;
  1768. this.version = 0;
  1769. this.onUpdate = null;
  1770. }
  1771. Texture.DEFAULT_IMAGE = undefined;
  1772. Texture.DEFAULT_MAPPING = UVMapping;
  1773. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1774. constructor: Texture,
  1775. isTexture: true,
  1776. updateMatrix: function updateMatrix() {
  1777. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1778. },
  1779. clone: function clone() {
  1780. return new this.constructor().copy(this);
  1781. },
  1782. copy: function copy(source) {
  1783. this.name = source.name;
  1784. this.image = source.image;
  1785. this.mipmaps = source.mipmaps.slice(0);
  1786. this.mapping = source.mapping;
  1787. this.wrapS = source.wrapS;
  1788. this.wrapT = source.wrapT;
  1789. this.magFilter = source.magFilter;
  1790. this.minFilter = source.minFilter;
  1791. this.anisotropy = source.anisotropy;
  1792. this.format = source.format;
  1793. this.internalFormat = source.internalFormat;
  1794. this.type = source.type;
  1795. this.offset.copy(source.offset);
  1796. this.repeat.copy(source.repeat);
  1797. this.center.copy(source.center);
  1798. this.rotation = source.rotation;
  1799. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1800. this.matrix.copy(source.matrix);
  1801. this.generateMipmaps = source.generateMipmaps;
  1802. this.premultiplyAlpha = source.premultiplyAlpha;
  1803. this.flipY = source.flipY;
  1804. this.unpackAlignment = source.unpackAlignment;
  1805. this.encoding = source.encoding;
  1806. return this;
  1807. },
  1808. toJSON: function toJSON(meta) {
  1809. var isRootObject = meta === undefined || typeof meta === 'string';
  1810. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1811. return meta.textures[this.uuid];
  1812. }
  1813. var output = {
  1814. metadata: {
  1815. version: 4.5,
  1816. type: 'Texture',
  1817. generator: 'Texture.toJSON'
  1818. },
  1819. uuid: this.uuid,
  1820. name: this.name,
  1821. mapping: this.mapping,
  1822. repeat: [this.repeat.x, this.repeat.y],
  1823. offset: [this.offset.x, this.offset.y],
  1824. center: [this.center.x, this.center.y],
  1825. rotation: this.rotation,
  1826. wrap: [this.wrapS, this.wrapT],
  1827. format: this.format,
  1828. type: this.type,
  1829. encoding: this.encoding,
  1830. minFilter: this.minFilter,
  1831. magFilter: this.magFilter,
  1832. anisotropy: this.anisotropy,
  1833. flipY: this.flipY,
  1834. premultiplyAlpha: this.premultiplyAlpha,
  1835. unpackAlignment: this.unpackAlignment
  1836. };
  1837. if (this.image !== undefined) {
  1838. // TODO: Move to THREE.Image
  1839. var image = this.image;
  1840. if (image.uuid === undefined) {
  1841. image.uuid = MathUtils.generateUUID(); // UGH
  1842. }
  1843. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1844. var url;
  1845. if (Array.isArray(image)) {
  1846. // process array of images e.g. CubeTexture
  1847. url = [];
  1848. for (var i = 0, l = image.length; i < l; i++) {
  1849. // check cube texture with data textures
  1850. if (image[i].isDataTexture) {
  1851. url.push(serializeImage(image[i].image));
  1852. } else {
  1853. url.push(serializeImage(image[i]));
  1854. }
  1855. }
  1856. } else {
  1857. // process single image
  1858. url = serializeImage(image);
  1859. }
  1860. meta.images[image.uuid] = {
  1861. uuid: image.uuid,
  1862. url: url
  1863. };
  1864. }
  1865. output.image = image.uuid;
  1866. }
  1867. if (!isRootObject) {
  1868. meta.textures[this.uuid] = output;
  1869. }
  1870. return output;
  1871. },
  1872. dispose: function dispose() {
  1873. this.dispatchEvent({
  1874. type: 'dispose'
  1875. });
  1876. },
  1877. transformUv: function transformUv(uv) {
  1878. if (this.mapping !== UVMapping) return uv;
  1879. uv.applyMatrix3(this.matrix);
  1880. if (uv.x < 0 || uv.x > 1) {
  1881. switch (this.wrapS) {
  1882. case RepeatWrapping:
  1883. uv.x = uv.x - Math.floor(uv.x);
  1884. break;
  1885. case ClampToEdgeWrapping:
  1886. uv.x = uv.x < 0 ? 0 : 1;
  1887. break;
  1888. case MirroredRepeatWrapping:
  1889. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1890. uv.x = Math.ceil(uv.x) - uv.x;
  1891. } else {
  1892. uv.x = uv.x - Math.floor(uv.x);
  1893. }
  1894. break;
  1895. }
  1896. }
  1897. if (uv.y < 0 || uv.y > 1) {
  1898. switch (this.wrapT) {
  1899. case RepeatWrapping:
  1900. uv.y = uv.y - Math.floor(uv.y);
  1901. break;
  1902. case ClampToEdgeWrapping:
  1903. uv.y = uv.y < 0 ? 0 : 1;
  1904. break;
  1905. case MirroredRepeatWrapping:
  1906. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1907. uv.y = Math.ceil(uv.y) - uv.y;
  1908. } else {
  1909. uv.y = uv.y - Math.floor(uv.y);
  1910. }
  1911. break;
  1912. }
  1913. }
  1914. if (this.flipY) {
  1915. uv.y = 1 - uv.y;
  1916. }
  1917. return uv;
  1918. }
  1919. });
  1920. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1921. set: function set(value) {
  1922. if (value === true) this.version++;
  1923. }
  1924. });
  1925. function serializeImage(image) {
  1926. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1927. // default images
  1928. return ImageUtils.getDataURL(image);
  1929. } else {
  1930. if (image.data) {
  1931. // images of DataTexture
  1932. return {
  1933. data: Array.prototype.slice.call(image.data),
  1934. width: image.width,
  1935. height: image.height,
  1936. type: image.data.constructor.name
  1937. };
  1938. } else {
  1939. console.warn('THREE.Texture: Unable to serialize Texture.');
  1940. return {};
  1941. }
  1942. }
  1943. }
  1944. var Vector4 = /*#__PURE__*/function () {
  1945. function Vector4(x, y, z, w) {
  1946. if (x === void 0) {
  1947. x = 0;
  1948. }
  1949. if (y === void 0) {
  1950. y = 0;
  1951. }
  1952. if (z === void 0) {
  1953. z = 0;
  1954. }
  1955. if (w === void 0) {
  1956. w = 1;
  1957. }
  1958. this.x = x;
  1959. this.y = y;
  1960. this.z = z;
  1961. this.w = w;
  1962. }
  1963. var _proto = Vector4.prototype;
  1964. _proto.set = function set(x, y, z, w) {
  1965. this.x = x;
  1966. this.y = y;
  1967. this.z = z;
  1968. this.w = w;
  1969. return this;
  1970. };
  1971. _proto.setScalar = function setScalar(scalar) {
  1972. this.x = scalar;
  1973. this.y = scalar;
  1974. this.z = scalar;
  1975. this.w = scalar;
  1976. return this;
  1977. };
  1978. _proto.setX = function setX(x) {
  1979. this.x = x;
  1980. return this;
  1981. };
  1982. _proto.setY = function setY(y) {
  1983. this.y = y;
  1984. return this;
  1985. };
  1986. _proto.setZ = function setZ(z) {
  1987. this.z = z;
  1988. return this;
  1989. };
  1990. _proto.setW = function setW(w) {
  1991. this.w = w;
  1992. return this;
  1993. };
  1994. _proto.setComponent = function setComponent(index, value) {
  1995. switch (index) {
  1996. case 0:
  1997. this.x = value;
  1998. break;
  1999. case 1:
  2000. this.y = value;
  2001. break;
  2002. case 2:
  2003. this.z = value;
  2004. break;
  2005. case 3:
  2006. this.w = value;
  2007. break;
  2008. default:
  2009. throw new Error('index is out of range: ' + index);
  2010. }
  2011. return this;
  2012. };
  2013. _proto.getComponent = function getComponent(index) {
  2014. switch (index) {
  2015. case 0:
  2016. return this.x;
  2017. case 1:
  2018. return this.y;
  2019. case 2:
  2020. return this.z;
  2021. case 3:
  2022. return this.w;
  2023. default:
  2024. throw new Error('index is out of range: ' + index);
  2025. }
  2026. };
  2027. _proto.clone = function clone() {
  2028. return new this.constructor(this.x, this.y, this.z, this.w);
  2029. };
  2030. _proto.copy = function copy(v) {
  2031. this.x = v.x;
  2032. this.y = v.y;
  2033. this.z = v.z;
  2034. this.w = v.w !== undefined ? v.w : 1;
  2035. return this;
  2036. };
  2037. _proto.add = function add(v, w) {
  2038. if (w !== undefined) {
  2039. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2040. return this.addVectors(v, w);
  2041. }
  2042. this.x += v.x;
  2043. this.y += v.y;
  2044. this.z += v.z;
  2045. this.w += v.w;
  2046. return this;
  2047. };
  2048. _proto.addScalar = function addScalar(s) {
  2049. this.x += s;
  2050. this.y += s;
  2051. this.z += s;
  2052. this.w += s;
  2053. return this;
  2054. };
  2055. _proto.addVectors = function addVectors(a, b) {
  2056. this.x = a.x + b.x;
  2057. this.y = a.y + b.y;
  2058. this.z = a.z + b.z;
  2059. this.w = a.w + b.w;
  2060. return this;
  2061. };
  2062. _proto.addScaledVector = function addScaledVector(v, s) {
  2063. this.x += v.x * s;
  2064. this.y += v.y * s;
  2065. this.z += v.z * s;
  2066. this.w += v.w * s;
  2067. return this;
  2068. };
  2069. _proto.sub = function sub(v, w) {
  2070. if (w !== undefined) {
  2071. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2072. return this.subVectors(v, w);
  2073. }
  2074. this.x -= v.x;
  2075. this.y -= v.y;
  2076. this.z -= v.z;
  2077. this.w -= v.w;
  2078. return this;
  2079. };
  2080. _proto.subScalar = function subScalar(s) {
  2081. this.x -= s;
  2082. this.y -= s;
  2083. this.z -= s;
  2084. this.w -= s;
  2085. return this;
  2086. };
  2087. _proto.subVectors = function subVectors(a, b) {
  2088. this.x = a.x - b.x;
  2089. this.y = a.y - b.y;
  2090. this.z = a.z - b.z;
  2091. this.w = a.w - b.w;
  2092. return this;
  2093. };
  2094. _proto.multiply = function multiply(v) {
  2095. this.x *= v.x;
  2096. this.y *= v.y;
  2097. this.z *= v.z;
  2098. this.w *= v.w;
  2099. return this;
  2100. };
  2101. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2102. this.x *= scalar;
  2103. this.y *= scalar;
  2104. this.z *= scalar;
  2105. this.w *= scalar;
  2106. return this;
  2107. };
  2108. _proto.applyMatrix4 = function applyMatrix4(m) {
  2109. var x = this.x,
  2110. y = this.y,
  2111. z = this.z,
  2112. w = this.w;
  2113. var e = m.elements;
  2114. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  2115. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  2116. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  2117. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  2118. return this;
  2119. };
  2120. _proto.divideScalar = function divideScalar(scalar) {
  2121. return this.multiplyScalar(1 / scalar);
  2122. };
  2123. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  2124. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2125. // q is assumed to be normalized
  2126. this.w = 2 * Math.acos(q.w);
  2127. var s = Math.sqrt(1 - q.w * q.w);
  2128. if (s < 0.0001) {
  2129. this.x = 1;
  2130. this.y = 0;
  2131. this.z = 0;
  2132. } else {
  2133. this.x = q.x / s;
  2134. this.y = q.y / s;
  2135. this.z = q.z / s;
  2136. }
  2137. return this;
  2138. };
  2139. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  2140. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2141. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2142. var angle, x, y, z; // variables for result
  2143. var epsilon = 0.01,
  2144. // margin to allow for rounding errors
  2145. epsilon2 = 0.1,
  2146. // margin to distinguish between 0 and 180 degrees
  2147. te = m.elements,
  2148. m11 = te[0],
  2149. m12 = te[4],
  2150. m13 = te[8],
  2151. m21 = te[1],
  2152. m22 = te[5],
  2153. m23 = te[9],
  2154. m31 = te[2],
  2155. m32 = te[6],
  2156. m33 = te[10];
  2157. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  2158. // singularity found
  2159. // first check for identity matrix which must have +1 for all terms
  2160. // in leading diagonal and zero in other terms
  2161. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  2162. // this singularity is identity matrix so angle = 0
  2163. this.set(1, 0, 0, 0);
  2164. return this; // zero angle, arbitrary axis
  2165. } // otherwise this singularity is angle = 180
  2166. angle = Math.PI;
  2167. var xx = (m11 + 1) / 2;
  2168. var yy = (m22 + 1) / 2;
  2169. var zz = (m33 + 1) / 2;
  2170. var xy = (m12 + m21) / 4;
  2171. var xz = (m13 + m31) / 4;
  2172. var yz = (m23 + m32) / 4;
  2173. if (xx > yy && xx > zz) {
  2174. // m11 is the largest diagonal term
  2175. if (xx < epsilon) {
  2176. x = 0;
  2177. y = 0.707106781;
  2178. z = 0.707106781;
  2179. } else {
  2180. x = Math.sqrt(xx);
  2181. y = xy / x;
  2182. z = xz / x;
  2183. }
  2184. } else if (yy > zz) {
  2185. // m22 is the largest diagonal term
  2186. if (yy < epsilon) {
  2187. x = 0.707106781;
  2188. y = 0;
  2189. z = 0.707106781;
  2190. } else {
  2191. y = Math.sqrt(yy);
  2192. x = xy / y;
  2193. z = yz / y;
  2194. }
  2195. } else {
  2196. // m33 is the largest diagonal term so base result on this
  2197. if (zz < epsilon) {
  2198. x = 0.707106781;
  2199. y = 0.707106781;
  2200. z = 0;
  2201. } else {
  2202. z = Math.sqrt(zz);
  2203. x = xz / z;
  2204. y = yz / z;
  2205. }
  2206. }
  2207. this.set(x, y, z, angle);
  2208. return this; // return 180 deg rotation
  2209. } // as we have reached here there are no singularities so we can handle normally
  2210. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  2211. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2212. // caught by singularity test above, but I've left it in just in case
  2213. this.x = (m32 - m23) / s;
  2214. this.y = (m13 - m31) / s;
  2215. this.z = (m21 - m12) / s;
  2216. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  2217. return this;
  2218. };
  2219. _proto.min = function min(v) {
  2220. this.x = Math.min(this.x, v.x);
  2221. this.y = Math.min(this.y, v.y);
  2222. this.z = Math.min(this.z, v.z);
  2223. this.w = Math.min(this.w, v.w);
  2224. return this;
  2225. };
  2226. _proto.max = function max(v) {
  2227. this.x = Math.max(this.x, v.x);
  2228. this.y = Math.max(this.y, v.y);
  2229. this.z = Math.max(this.z, v.z);
  2230. this.w = Math.max(this.w, v.w);
  2231. return this;
  2232. };
  2233. _proto.clamp = function clamp(min, max) {
  2234. // assumes min < max, componentwise
  2235. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2236. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2237. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2238. this.w = Math.max(min.w, Math.min(max.w, this.w));
  2239. return this;
  2240. };
  2241. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2242. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2243. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2244. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2245. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  2246. return this;
  2247. };
  2248. _proto.clampLength = function clampLength(min, max) {
  2249. var length = this.length();
  2250. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2251. };
  2252. _proto.floor = function floor() {
  2253. this.x = Math.floor(this.x);
  2254. this.y = Math.floor(this.y);
  2255. this.z = Math.floor(this.z);
  2256. this.w = Math.floor(this.w);
  2257. return this;
  2258. };
  2259. _proto.ceil = function ceil() {
  2260. this.x = Math.ceil(this.x);
  2261. this.y = Math.ceil(this.y);
  2262. this.z = Math.ceil(this.z);
  2263. this.w = Math.ceil(this.w);
  2264. return this;
  2265. };
  2266. _proto.round = function round() {
  2267. this.x = Math.round(this.x);
  2268. this.y = Math.round(this.y);
  2269. this.z = Math.round(this.z);
  2270. this.w = Math.round(this.w);
  2271. return this;
  2272. };
  2273. _proto.roundToZero = function roundToZero() {
  2274. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2275. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2276. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2277. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  2278. return this;
  2279. };
  2280. _proto.negate = function negate() {
  2281. this.x = -this.x;
  2282. this.y = -this.y;
  2283. this.z = -this.z;
  2284. this.w = -this.w;
  2285. return this;
  2286. };
  2287. _proto.dot = function dot(v) {
  2288. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2289. };
  2290. _proto.lengthSq = function lengthSq() {
  2291. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2292. };
  2293. _proto.length = function length() {
  2294. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  2295. };
  2296. _proto.manhattanLength = function manhattanLength() {
  2297. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  2298. };
  2299. _proto.normalize = function normalize() {
  2300. return this.divideScalar(this.length() || 1);
  2301. };
  2302. _proto.setLength = function setLength(length) {
  2303. return this.normalize().multiplyScalar(length);
  2304. };
  2305. _proto.lerp = function lerp(v, alpha) {
  2306. this.x += (v.x - this.x) * alpha;
  2307. this.y += (v.y - this.y) * alpha;
  2308. this.z += (v.z - this.z) * alpha;
  2309. this.w += (v.w - this.w) * alpha;
  2310. return this;
  2311. };
  2312. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2313. this.x = v1.x + (v2.x - v1.x) * alpha;
  2314. this.y = v1.y + (v2.y - v1.y) * alpha;
  2315. this.z = v1.z + (v2.z - v1.z) * alpha;
  2316. this.w = v1.w + (v2.w - v1.w) * alpha;
  2317. return this;
  2318. };
  2319. _proto.equals = function equals(v) {
  2320. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  2321. };
  2322. _proto.fromArray = function fromArray(array, offset) {
  2323. if (offset === void 0) {
  2324. offset = 0;
  2325. }
  2326. this.x = array[offset];
  2327. this.y = array[offset + 1];
  2328. this.z = array[offset + 2];
  2329. this.w = array[offset + 3];
  2330. return this;
  2331. };
  2332. _proto.toArray = function toArray(array, offset) {
  2333. if (array === void 0) {
  2334. array = [];
  2335. }
  2336. if (offset === void 0) {
  2337. offset = 0;
  2338. }
  2339. array[offset] = this.x;
  2340. array[offset + 1] = this.y;
  2341. array[offset + 2] = this.z;
  2342. array[offset + 3] = this.w;
  2343. return array;
  2344. };
  2345. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2346. if (offset !== undefined) {
  2347. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  2348. }
  2349. this.x = attribute.getX(index);
  2350. this.y = attribute.getY(index);
  2351. this.z = attribute.getZ(index);
  2352. this.w = attribute.getW(index);
  2353. return this;
  2354. };
  2355. _proto.random = function random() {
  2356. this.x = Math.random();
  2357. this.y = Math.random();
  2358. this.z = Math.random();
  2359. this.w = Math.random();
  2360. return this;
  2361. };
  2362. _createClass(Vector4, [{
  2363. key: "width",
  2364. get: function get() {
  2365. return this.z;
  2366. },
  2367. set: function set(value) {
  2368. this.z = value;
  2369. }
  2370. }, {
  2371. key: "height",
  2372. get: function get() {
  2373. return this.w;
  2374. },
  2375. set: function set(value) {
  2376. this.w = value;
  2377. }
  2378. }]);
  2379. return Vector4;
  2380. }();
  2381. Vector4.prototype.isVector4 = true;
  2382. /*
  2383. In options, we can specify:
  2384. * Texture parameters for an auto-generated target texture
  2385. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2386. */
  2387. var WebGLRenderTarget = /*#__PURE__*/function (_EventDispatcher) {
  2388. _inheritsLoose(WebGLRenderTarget, _EventDispatcher);
  2389. function WebGLRenderTarget(width, height, options) {
  2390. var _this;
  2391. _this = _EventDispatcher.call(this) || this;
  2392. _this.width = width;
  2393. _this.height = height;
  2394. _this.depth = 1;
  2395. _this.scissor = new Vector4(0, 0, width, height);
  2396. _this.scissorTest = false;
  2397. _this.viewport = new Vector4(0, 0, width, height);
  2398. options = options || {};
  2399. _this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  2400. _this.texture.image = {};
  2401. _this.texture.image.width = width;
  2402. _this.texture.image.height = height;
  2403. _this.texture.image.depth = 1;
  2404. _this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2405. _this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2406. _this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2407. _this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  2408. _this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2409. return _this;
  2410. }
  2411. var _proto = WebGLRenderTarget.prototype;
  2412. _proto.setTexture = function setTexture(texture) {
  2413. texture.image = {
  2414. width: this.width,
  2415. height: this.height,
  2416. depth: this.depth
  2417. };
  2418. this.texture = texture;
  2419. };
  2420. _proto.setSize = function setSize(width, height, depth) {
  2421. if (depth === void 0) {
  2422. depth = 1;
  2423. }
  2424. if (this.width !== width || this.height !== height || this.depth !== depth) {
  2425. this.width = width;
  2426. this.height = height;
  2427. this.depth = depth;
  2428. this.texture.image.width = width;
  2429. this.texture.image.height = height;
  2430. this.texture.image.depth = depth;
  2431. this.dispose();
  2432. }
  2433. this.viewport.set(0, 0, width, height);
  2434. this.scissor.set(0, 0, width, height);
  2435. };
  2436. _proto.clone = function clone() {
  2437. return new this.constructor().copy(this);
  2438. };
  2439. _proto.copy = function copy(source) {
  2440. this.width = source.width;
  2441. this.height = source.height;
  2442. this.depth = source.depth;
  2443. this.viewport.copy(source.viewport);
  2444. this.texture = source.texture.clone();
  2445. this.depthBuffer = source.depthBuffer;
  2446. this.stencilBuffer = source.stencilBuffer;
  2447. this.depthTexture = source.depthTexture;
  2448. return this;
  2449. };
  2450. _proto.dispose = function dispose() {
  2451. this.dispatchEvent({
  2452. type: 'dispose'
  2453. });
  2454. };
  2455. return WebGLRenderTarget;
  2456. }(EventDispatcher);
  2457. WebGLRenderTarget.prototype.isWebGLRenderTarget = true;
  2458. var WebGLMultisampleRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  2459. _inheritsLoose(WebGLMultisampleRenderTarget, _WebGLRenderTarget);
  2460. function WebGLMultisampleRenderTarget(width, height, options) {
  2461. var _this;
  2462. _this = _WebGLRenderTarget.call(this, width, height, options) || this;
  2463. _this.samples = 4;
  2464. return _this;
  2465. }
  2466. var _proto = WebGLMultisampleRenderTarget.prototype;
  2467. _proto.copy = function copy(source) {
  2468. _WebGLRenderTarget.prototype.copy.call(this, source);
  2469. this.samples = source.samples;
  2470. return this;
  2471. };
  2472. return WebGLMultisampleRenderTarget;
  2473. }(WebGLRenderTarget);
  2474. WebGLMultisampleRenderTarget.prototype.isWebGLMultisampleRenderTarget = true;
  2475. var Quaternion = /*#__PURE__*/function () {
  2476. function Quaternion(x, y, z, w) {
  2477. if (x === void 0) {
  2478. x = 0;
  2479. }
  2480. if (y === void 0) {
  2481. y = 0;
  2482. }
  2483. if (z === void 0) {
  2484. z = 0;
  2485. }
  2486. if (w === void 0) {
  2487. w = 1;
  2488. }
  2489. this._x = x;
  2490. this._y = y;
  2491. this._z = z;
  2492. this._w = w;
  2493. }
  2494. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  2495. return qm.copy(qa).slerp(qb, t);
  2496. };
  2497. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  2498. // fuzz-free, array-based Quaternion SLERP operation
  2499. var x0 = src0[srcOffset0 + 0],
  2500. y0 = src0[srcOffset0 + 1],
  2501. z0 = src0[srcOffset0 + 2],
  2502. w0 = src0[srcOffset0 + 3];
  2503. var x1 = src1[srcOffset1 + 0],
  2504. y1 = src1[srcOffset1 + 1],
  2505. z1 = src1[srcOffset1 + 2],
  2506. w1 = src1[srcOffset1 + 3];
  2507. if (t === 0) {
  2508. dst[dstOffset + 0] = x0;
  2509. dst[dstOffset + 1] = y0;
  2510. dst[dstOffset + 2] = z0;
  2511. dst[dstOffset + 3] = w0;
  2512. return;
  2513. }
  2514. if (t === 1) {
  2515. dst[dstOffset + 0] = x1;
  2516. dst[dstOffset + 1] = y1;
  2517. dst[dstOffset + 2] = z1;
  2518. dst[dstOffset + 3] = w1;
  2519. return;
  2520. }
  2521. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  2522. var s = 1 - t;
  2523. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2524. dir = cos >= 0 ? 1 : -1,
  2525. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  2526. if (sqrSin > Number.EPSILON) {
  2527. var sin = Math.sqrt(sqrSin),
  2528. len = Math.atan2(sin, cos * dir);
  2529. s = Math.sin(s * len) / sin;
  2530. t = Math.sin(t * len) / sin;
  2531. }
  2532. var tDir = t * dir;
  2533. x0 = x0 * s + x1 * tDir;
  2534. y0 = y0 * s + y1 * tDir;
  2535. z0 = z0 * s + z1 * tDir;
  2536. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  2537. if (s === 1 - t) {
  2538. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  2539. x0 *= f;
  2540. y0 *= f;
  2541. z0 *= f;
  2542. w0 *= f;
  2543. }
  2544. }
  2545. dst[dstOffset] = x0;
  2546. dst[dstOffset + 1] = y0;
  2547. dst[dstOffset + 2] = z0;
  2548. dst[dstOffset + 3] = w0;
  2549. };
  2550. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  2551. var x0 = src0[srcOffset0];
  2552. var y0 = src0[srcOffset0 + 1];
  2553. var z0 = src0[srcOffset0 + 2];
  2554. var w0 = src0[srcOffset0 + 3];
  2555. var x1 = src1[srcOffset1];
  2556. var y1 = src1[srcOffset1 + 1];
  2557. var z1 = src1[srcOffset1 + 2];
  2558. var w1 = src1[srcOffset1 + 3];
  2559. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2560. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2561. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2562. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2563. return dst;
  2564. };
  2565. var _proto = Quaternion.prototype;
  2566. _proto.set = function set(x, y, z, w) {
  2567. this._x = x;
  2568. this._y = y;
  2569. this._z = z;
  2570. this._w = w;
  2571. this._onChangeCallback();
  2572. return this;
  2573. };
  2574. _proto.clone = function clone() {
  2575. return new this.constructor(this._x, this._y, this._z, this._w);
  2576. };
  2577. _proto.copy = function copy(quaternion) {
  2578. this._x = quaternion.x;
  2579. this._y = quaternion.y;
  2580. this._z = quaternion.z;
  2581. this._w = quaternion.w;
  2582. this._onChangeCallback();
  2583. return this;
  2584. };
  2585. _proto.setFromEuler = function setFromEuler(euler, update) {
  2586. if (!(euler && euler.isEuler)) {
  2587. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2588. }
  2589. var x = euler._x,
  2590. y = euler._y,
  2591. z = euler._z,
  2592. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  2593. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2594. // content/SpinCalc.m
  2595. var cos = Math.cos;
  2596. var sin = Math.sin;
  2597. var c1 = cos(x / 2);
  2598. var c2 = cos(y / 2);
  2599. var c3 = cos(z / 2);
  2600. var s1 = sin(x / 2);
  2601. var s2 = sin(y / 2);
  2602. var s3 = sin(z / 2);
  2603. switch (order) {
  2604. case 'XYZ':
  2605. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2606. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2607. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2608. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2609. break;
  2610. case 'YXZ':
  2611. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2612. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2613. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2614. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2615. break;
  2616. case 'ZXY':
  2617. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2618. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2619. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2620. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2621. break;
  2622. case 'ZYX':
  2623. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2624. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2625. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2626. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2627. break;
  2628. case 'YZX':
  2629. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2630. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2631. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2632. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2633. break;
  2634. case 'XZY':
  2635. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2636. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2637. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2638. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2639. break;
  2640. default:
  2641. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  2642. }
  2643. if (update !== false) this._onChangeCallback();
  2644. return this;
  2645. };
  2646. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  2647. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2648. // assumes axis is normalized
  2649. var halfAngle = angle / 2,
  2650. s = Math.sin(halfAngle);
  2651. this._x = axis.x * s;
  2652. this._y = axis.y * s;
  2653. this._z = axis.z * s;
  2654. this._w = Math.cos(halfAngle);
  2655. this._onChangeCallback();
  2656. return this;
  2657. };
  2658. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  2659. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2660. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2661. var te = m.elements,
  2662. m11 = te[0],
  2663. m12 = te[4],
  2664. m13 = te[8],
  2665. m21 = te[1],
  2666. m22 = te[5],
  2667. m23 = te[9],
  2668. m31 = te[2],
  2669. m32 = te[6],
  2670. m33 = te[10],
  2671. trace = m11 + m22 + m33;
  2672. if (trace > 0) {
  2673. var s = 0.5 / Math.sqrt(trace + 1.0);
  2674. this._w = 0.25 / s;
  2675. this._x = (m32 - m23) * s;
  2676. this._y = (m13 - m31) * s;
  2677. this._z = (m21 - m12) * s;
  2678. } else if (m11 > m22 && m11 > m33) {
  2679. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  2680. this._w = (m32 - m23) / _s;
  2681. this._x = 0.25 * _s;
  2682. this._y = (m12 + m21) / _s;
  2683. this._z = (m13 + m31) / _s;
  2684. } else if (m22 > m33) {
  2685. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  2686. this._w = (m13 - m31) / _s2;
  2687. this._x = (m12 + m21) / _s2;
  2688. this._y = 0.25 * _s2;
  2689. this._z = (m23 + m32) / _s2;
  2690. } else {
  2691. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  2692. this._w = (m21 - m12) / _s3;
  2693. this._x = (m13 + m31) / _s3;
  2694. this._y = (m23 + m32) / _s3;
  2695. this._z = 0.25 * _s3;
  2696. }
  2697. this._onChangeCallback();
  2698. return this;
  2699. };
  2700. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  2701. // assumes direction vectors vFrom and vTo are normalized
  2702. var EPS = 0.000001;
  2703. var r = vFrom.dot(vTo) + 1;
  2704. if (r < EPS) {
  2705. r = 0;
  2706. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  2707. this._x = -vFrom.y;
  2708. this._y = vFrom.x;
  2709. this._z = 0;
  2710. this._w = r;
  2711. } else {
  2712. this._x = 0;
  2713. this._y = -vFrom.z;
  2714. this._z = vFrom.y;
  2715. this._w = r;
  2716. }
  2717. } else {
  2718. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2719. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2720. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2721. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2722. this._w = r;
  2723. }
  2724. return this.normalize();
  2725. };
  2726. _proto.angleTo = function angleTo(q) {
  2727. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2728. };
  2729. _proto.rotateTowards = function rotateTowards(q, step) {
  2730. var angle = this.angleTo(q);
  2731. if (angle === 0) return this;
  2732. var t = Math.min(1, step / angle);
  2733. this.slerp(q, t);
  2734. return this;
  2735. };
  2736. _proto.identity = function identity() {
  2737. return this.set(0, 0, 0, 1);
  2738. };
  2739. _proto.invert = function invert() {
  2740. // quaternion is assumed to have unit length
  2741. return this.conjugate();
  2742. };
  2743. _proto.conjugate = function conjugate() {
  2744. this._x *= -1;
  2745. this._y *= -1;
  2746. this._z *= -1;
  2747. this._onChangeCallback();
  2748. return this;
  2749. };
  2750. _proto.dot = function dot(v) {
  2751. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2752. };
  2753. _proto.lengthSq = function lengthSq() {
  2754. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2755. };
  2756. _proto.length = function length() {
  2757. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2758. };
  2759. _proto.normalize = function normalize() {
  2760. var l = this.length();
  2761. if (l === 0) {
  2762. this._x = 0;
  2763. this._y = 0;
  2764. this._z = 0;
  2765. this._w = 1;
  2766. } else {
  2767. l = 1 / l;
  2768. this._x = this._x * l;
  2769. this._y = this._y * l;
  2770. this._z = this._z * l;
  2771. this._w = this._w * l;
  2772. }
  2773. this._onChangeCallback();
  2774. return this;
  2775. };
  2776. _proto.multiply = function multiply(q, p) {
  2777. if (p !== undefined) {
  2778. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2779. return this.multiplyQuaternions(q, p);
  2780. }
  2781. return this.multiplyQuaternions(this, q);
  2782. };
  2783. _proto.premultiply = function premultiply(q) {
  2784. return this.multiplyQuaternions(q, this);
  2785. };
  2786. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2787. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2788. var qax = a._x,
  2789. qay = a._y,
  2790. qaz = a._z,
  2791. qaw = a._w;
  2792. var qbx = b._x,
  2793. qby = b._y,
  2794. qbz = b._z,
  2795. qbw = b._w;
  2796. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2797. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2798. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2799. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2800. this._onChangeCallback();
  2801. return this;
  2802. };
  2803. _proto.slerp = function slerp(qb, t) {
  2804. if (t === 0) return this;
  2805. if (t === 1) return this.copy(qb);
  2806. var x = this._x,
  2807. y = this._y,
  2808. z = this._z,
  2809. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2810. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2811. if (cosHalfTheta < 0) {
  2812. this._w = -qb._w;
  2813. this._x = -qb._x;
  2814. this._y = -qb._y;
  2815. this._z = -qb._z;
  2816. cosHalfTheta = -cosHalfTheta;
  2817. } else {
  2818. this.copy(qb);
  2819. }
  2820. if (cosHalfTheta >= 1.0) {
  2821. this._w = w;
  2822. this._x = x;
  2823. this._y = y;
  2824. this._z = z;
  2825. return this;
  2826. }
  2827. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2828. if (sqrSinHalfTheta <= Number.EPSILON) {
  2829. var s = 1 - t;
  2830. this._w = s * w + t * this._w;
  2831. this._x = s * x + t * this._x;
  2832. this._y = s * y + t * this._y;
  2833. this._z = s * z + t * this._z;
  2834. this.normalize();
  2835. this._onChangeCallback();
  2836. return this;
  2837. }
  2838. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2839. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2840. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2841. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2842. this._w = w * ratioA + this._w * ratioB;
  2843. this._x = x * ratioA + this._x * ratioB;
  2844. this._y = y * ratioA + this._y * ratioB;
  2845. this._z = z * ratioA + this._z * ratioB;
  2846. this._onChangeCallback();
  2847. return this;
  2848. };
  2849. _proto.equals = function equals(quaternion) {
  2850. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2851. };
  2852. _proto.fromArray = function fromArray(array, offset) {
  2853. if (offset === void 0) {
  2854. offset = 0;
  2855. }
  2856. this._x = array[offset];
  2857. this._y = array[offset + 1];
  2858. this._z = array[offset + 2];
  2859. this._w = array[offset + 3];
  2860. this._onChangeCallback();
  2861. return this;
  2862. };
  2863. _proto.toArray = function toArray(array, offset) {
  2864. if (array === void 0) {
  2865. array = [];
  2866. }
  2867. if (offset === void 0) {
  2868. offset = 0;
  2869. }
  2870. array[offset] = this._x;
  2871. array[offset + 1] = this._y;
  2872. array[offset + 2] = this._z;
  2873. array[offset + 3] = this._w;
  2874. return array;
  2875. };
  2876. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2877. this._x = attribute.getX(index);
  2878. this._y = attribute.getY(index);
  2879. this._z = attribute.getZ(index);
  2880. this._w = attribute.getW(index);
  2881. return this;
  2882. };
  2883. _proto._onChange = function _onChange(callback) {
  2884. this._onChangeCallback = callback;
  2885. return this;
  2886. };
  2887. _proto._onChangeCallback = function _onChangeCallback() {};
  2888. _createClass(Quaternion, [{
  2889. key: "x",
  2890. get: function get() {
  2891. return this._x;
  2892. },
  2893. set: function set(value) {
  2894. this._x = value;
  2895. this._onChangeCallback();
  2896. }
  2897. }, {
  2898. key: "y",
  2899. get: function get() {
  2900. return this._y;
  2901. },
  2902. set: function set(value) {
  2903. this._y = value;
  2904. this._onChangeCallback();
  2905. }
  2906. }, {
  2907. key: "z",
  2908. get: function get() {
  2909. return this._z;
  2910. },
  2911. set: function set(value) {
  2912. this._z = value;
  2913. this._onChangeCallback();
  2914. }
  2915. }, {
  2916. key: "w",
  2917. get: function get() {
  2918. return this._w;
  2919. },
  2920. set: function set(value) {
  2921. this._w = value;
  2922. this._onChangeCallback();
  2923. }
  2924. }]);
  2925. return Quaternion;
  2926. }();
  2927. Quaternion.prototype.isQuaternion = true;
  2928. var Vector3 = /*#__PURE__*/function () {
  2929. function Vector3(x, y, z) {
  2930. if (x === void 0) {
  2931. x = 0;
  2932. }
  2933. if (y === void 0) {
  2934. y = 0;
  2935. }
  2936. if (z === void 0) {
  2937. z = 0;
  2938. }
  2939. this.x = x;
  2940. this.y = y;
  2941. this.z = z;
  2942. }
  2943. var _proto = Vector3.prototype;
  2944. _proto.set = function set(x, y, z) {
  2945. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2946. this.x = x;
  2947. this.y = y;
  2948. this.z = z;
  2949. return this;
  2950. };
  2951. _proto.setScalar = function setScalar(scalar) {
  2952. this.x = scalar;
  2953. this.y = scalar;
  2954. this.z = scalar;
  2955. return this;
  2956. };
  2957. _proto.setX = function setX(x) {
  2958. this.x = x;
  2959. return this;
  2960. };
  2961. _proto.setY = function setY(y) {
  2962. this.y = y;
  2963. return this;
  2964. };
  2965. _proto.setZ = function setZ(z) {
  2966. this.z = z;
  2967. return this;
  2968. };
  2969. _proto.setComponent = function setComponent(index, value) {
  2970. switch (index) {
  2971. case 0:
  2972. this.x = value;
  2973. break;
  2974. case 1:
  2975. this.y = value;
  2976. break;
  2977. case 2:
  2978. this.z = value;
  2979. break;
  2980. default:
  2981. throw new Error('index is out of range: ' + index);
  2982. }
  2983. return this;
  2984. };
  2985. _proto.getComponent = function getComponent(index) {
  2986. switch (index) {
  2987. case 0:
  2988. return this.x;
  2989. case 1:
  2990. return this.y;
  2991. case 2:
  2992. return this.z;
  2993. default:
  2994. throw new Error('index is out of range: ' + index);
  2995. }
  2996. };
  2997. _proto.clone = function clone() {
  2998. return new this.constructor(this.x, this.y, this.z);
  2999. };
  3000. _proto.copy = function copy(v) {
  3001. this.x = v.x;
  3002. this.y = v.y;
  3003. this.z = v.z;
  3004. return this;
  3005. };
  3006. _proto.add = function add(v, w) {
  3007. if (w !== undefined) {
  3008. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  3009. return this.addVectors(v, w);
  3010. }
  3011. this.x += v.x;
  3012. this.y += v.y;
  3013. this.z += v.z;
  3014. return this;
  3015. };
  3016. _proto.addScalar = function addScalar(s) {
  3017. this.x += s;
  3018. this.y += s;
  3019. this.z += s;
  3020. return this;
  3021. };
  3022. _proto.addVectors = function addVectors(a, b) {
  3023. this.x = a.x + b.x;
  3024. this.y = a.y + b.y;
  3025. this.z = a.z + b.z;
  3026. return this;
  3027. };
  3028. _proto.addScaledVector = function addScaledVector(v, s) {
  3029. this.x += v.x * s;
  3030. this.y += v.y * s;
  3031. this.z += v.z * s;
  3032. return this;
  3033. };
  3034. _proto.sub = function sub(v, w) {
  3035. if (w !== undefined) {
  3036. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  3037. return this.subVectors(v, w);
  3038. }
  3039. this.x -= v.x;
  3040. this.y -= v.y;
  3041. this.z -= v.z;
  3042. return this;
  3043. };
  3044. _proto.subScalar = function subScalar(s) {
  3045. this.x -= s;
  3046. this.y -= s;
  3047. this.z -= s;
  3048. return this;
  3049. };
  3050. _proto.subVectors = function subVectors(a, b) {
  3051. this.x = a.x - b.x;
  3052. this.y = a.y - b.y;
  3053. this.z = a.z - b.z;
  3054. return this;
  3055. };
  3056. _proto.multiply = function multiply(v, w) {
  3057. if (w !== undefined) {
  3058. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  3059. return this.multiplyVectors(v, w);
  3060. }
  3061. this.x *= v.x;
  3062. this.y *= v.y;
  3063. this.z *= v.z;
  3064. return this;
  3065. };
  3066. _proto.multiplyScalar = function multiplyScalar(scalar) {
  3067. this.x *= scalar;
  3068. this.y *= scalar;
  3069. this.z *= scalar;
  3070. return this;
  3071. };
  3072. _proto.multiplyVectors = function multiplyVectors(a, b) {
  3073. this.x = a.x * b.x;
  3074. this.y = a.y * b.y;
  3075. this.z = a.z * b.z;
  3076. return this;
  3077. };
  3078. _proto.applyEuler = function applyEuler(euler) {
  3079. if (!(euler && euler.isEuler)) {
  3080. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  3081. }
  3082. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  3083. };
  3084. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  3085. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  3086. };
  3087. _proto.applyMatrix3 = function applyMatrix3(m) {
  3088. var x = this.x,
  3089. y = this.y,
  3090. z = this.z;
  3091. var e = m.elements;
  3092. this.x = e[0] * x + e[3] * y + e[6] * z;
  3093. this.y = e[1] * x + e[4] * y + e[7] * z;
  3094. this.z = e[2] * x + e[5] * y + e[8] * z;
  3095. return this;
  3096. };
  3097. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  3098. return this.applyMatrix3(m).normalize();
  3099. };
  3100. _proto.applyMatrix4 = function applyMatrix4(m) {
  3101. var x = this.x,
  3102. y = this.y,
  3103. z = this.z;
  3104. var e = m.elements;
  3105. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  3106. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  3107. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  3108. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  3109. return this;
  3110. };
  3111. _proto.applyQuaternion = function applyQuaternion(q) {
  3112. var x = this.x,
  3113. y = this.y,
  3114. z = this.z;
  3115. var qx = q.x,
  3116. qy = q.y,
  3117. qz = q.z,
  3118. qw = q.w; // calculate quat * vector
  3119. var ix = qw * x + qy * z - qz * y;
  3120. var iy = qw * y + qz * x - qx * z;
  3121. var iz = qw * z + qx * y - qy * x;
  3122. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  3123. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3124. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3125. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3126. return this;
  3127. };
  3128. _proto.project = function project(camera) {
  3129. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  3130. };
  3131. _proto.unproject = function unproject(camera) {
  3132. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  3133. };
  3134. _proto.transformDirection = function transformDirection(m) {
  3135. // input: THREE.Matrix4 affine matrix
  3136. // vector interpreted as a direction
  3137. var x = this.x,
  3138. y = this.y,
  3139. z = this.z;
  3140. var e = m.elements;
  3141. this.x = e[0] * x + e[4] * y + e[8] * z;
  3142. this.y = e[1] * x + e[5] * y + e[9] * z;
  3143. this.z = e[2] * x + e[6] * y + e[10] * z;
  3144. return this.normalize();
  3145. };
  3146. _proto.divide = function divide(v) {
  3147. this.x /= v.x;
  3148. this.y /= v.y;
  3149. this.z /= v.z;
  3150. return this;
  3151. };
  3152. _proto.divideScalar = function divideScalar(scalar) {
  3153. return this.multiplyScalar(1 / scalar);
  3154. };
  3155. _proto.min = function min(v) {
  3156. this.x = Math.min(this.x, v.x);
  3157. this.y = Math.min(this.y, v.y);
  3158. this.z = Math.min(this.z, v.z);
  3159. return this;
  3160. };
  3161. _proto.max = function max(v) {
  3162. this.x = Math.max(this.x, v.x);
  3163. this.y = Math.max(this.y, v.y);
  3164. this.z = Math.max(this.z, v.z);
  3165. return this;
  3166. };
  3167. _proto.clamp = function clamp(min, max) {
  3168. // assumes min < max, componentwise
  3169. this.x = Math.max(min.x, Math.min(max.x, this.x));
  3170. this.y = Math.max(min.y, Math.min(max.y, this.y));
  3171. this.z = Math.max(min.z, Math.min(max.z, this.z));
  3172. return this;
  3173. };
  3174. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  3175. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  3176. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  3177. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  3178. return this;
  3179. };
  3180. _proto.clampLength = function clampLength(min, max) {
  3181. var length = this.length();
  3182. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  3183. };
  3184. _proto.floor = function floor() {
  3185. this.x = Math.floor(this.x);
  3186. this.y = Math.floor(this.y);
  3187. this.z = Math.floor(this.z);
  3188. return this;
  3189. };
  3190. _proto.ceil = function ceil() {
  3191. this.x = Math.ceil(this.x);
  3192. this.y = Math.ceil(this.y);
  3193. this.z = Math.ceil(this.z);
  3194. return this;
  3195. };
  3196. _proto.round = function round() {
  3197. this.x = Math.round(this.x);
  3198. this.y = Math.round(this.y);
  3199. this.z = Math.round(this.z);
  3200. return this;
  3201. };
  3202. _proto.roundToZero = function roundToZero() {
  3203. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  3204. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  3205. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  3206. return this;
  3207. };
  3208. _proto.negate = function negate() {
  3209. this.x = -this.x;
  3210. this.y = -this.y;
  3211. this.z = -this.z;
  3212. return this;
  3213. };
  3214. _proto.dot = function dot(v) {
  3215. return this.x * v.x + this.y * v.y + this.z * v.z;
  3216. } // TODO lengthSquared?
  3217. ;
  3218. _proto.lengthSq = function lengthSq() {
  3219. return this.x * this.x + this.y * this.y + this.z * this.z;
  3220. };
  3221. _proto.length = function length() {
  3222. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3223. };
  3224. _proto.manhattanLength = function manhattanLength() {
  3225. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  3226. };
  3227. _proto.normalize = function normalize() {
  3228. return this.divideScalar(this.length() || 1);
  3229. };
  3230. _proto.setLength = function setLength(length) {
  3231. return this.normalize().multiplyScalar(length);
  3232. };
  3233. _proto.lerp = function lerp(v, alpha) {
  3234. this.x += (v.x - this.x) * alpha;
  3235. this.y += (v.y - this.y) * alpha;
  3236. this.z += (v.z - this.z) * alpha;
  3237. return this;
  3238. };
  3239. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  3240. this.x = v1.x + (v2.x - v1.x) * alpha;
  3241. this.y = v1.y + (v2.y - v1.y) * alpha;
  3242. this.z = v1.z + (v2.z - v1.z) * alpha;
  3243. return this;
  3244. };
  3245. _proto.cross = function cross(v, w) {
  3246. if (w !== undefined) {
  3247. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  3248. return this.crossVectors(v, w);
  3249. }
  3250. return this.crossVectors(this, v);
  3251. };
  3252. _proto.crossVectors = function crossVectors(a, b) {
  3253. var ax = a.x,
  3254. ay = a.y,
  3255. az = a.z;
  3256. var bx = b.x,
  3257. by = b.y,
  3258. bz = b.z;
  3259. this.x = ay * bz - az * by;
  3260. this.y = az * bx - ax * bz;
  3261. this.z = ax * by - ay * bx;
  3262. return this;
  3263. };
  3264. _proto.projectOnVector = function projectOnVector(v) {
  3265. var denominator = v.lengthSq();
  3266. if (denominator === 0) return this.set(0, 0, 0);
  3267. var scalar = v.dot(this) / denominator;
  3268. return this.copy(v).multiplyScalar(scalar);
  3269. };
  3270. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  3271. _vector.copy(this).projectOnVector(planeNormal);
  3272. return this.sub(_vector);
  3273. };
  3274. _proto.reflect = function reflect(normal) {
  3275. // reflect incident vector off plane orthogonal to normal
  3276. // normal is assumed to have unit length
  3277. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  3278. };
  3279. _proto.angleTo = function angleTo(v) {
  3280. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  3281. if (denominator === 0) return Math.PI / 2;
  3282. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  3283. return Math.acos(MathUtils.clamp(theta, -1, 1));
  3284. };
  3285. _proto.distanceTo = function distanceTo(v) {
  3286. return Math.sqrt(this.distanceToSquared(v));
  3287. };
  3288. _proto.distanceToSquared = function distanceToSquared(v) {
  3289. var dx = this.x - v.x,
  3290. dy = this.y - v.y,
  3291. dz = this.z - v.z;
  3292. return dx * dx + dy * dy + dz * dz;
  3293. };
  3294. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  3295. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  3296. };
  3297. _proto.setFromSpherical = function setFromSpherical(s) {
  3298. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  3299. };
  3300. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  3301. var sinPhiRadius = Math.sin(phi) * radius;
  3302. this.x = sinPhiRadius * Math.sin(theta);
  3303. this.y = Math.cos(phi) * radius;
  3304. this.z = sinPhiRadius * Math.cos(theta);
  3305. return this;
  3306. };
  3307. _proto.setFromCylindrical = function setFromCylindrical(c) {
  3308. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  3309. };
  3310. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  3311. this.x = radius * Math.sin(theta);
  3312. this.y = y;
  3313. this.z = radius * Math.cos(theta);
  3314. return this;
  3315. };
  3316. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  3317. var e = m.elements;
  3318. this.x = e[12];
  3319. this.y = e[13];
  3320. this.z = e[14];
  3321. return this;
  3322. };
  3323. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  3324. var sx = this.setFromMatrixColumn(m, 0).length();
  3325. var sy = this.setFromMatrixColumn(m, 1).length();
  3326. var sz = this.setFromMatrixColumn(m, 2).length();
  3327. this.x = sx;
  3328. this.y = sy;
  3329. this.z = sz;
  3330. return this;
  3331. };
  3332. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  3333. return this.fromArray(m.elements, index * 4);
  3334. };
  3335. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  3336. return this.fromArray(m.elements, index * 3);
  3337. };
  3338. _proto.equals = function equals(v) {
  3339. return v.x === this.x && v.y === this.y && v.z === this.z;
  3340. };
  3341. _proto.fromArray = function fromArray(array, offset) {
  3342. if (offset === void 0) {
  3343. offset = 0;
  3344. }
  3345. this.x = array[offset];
  3346. this.y = array[offset + 1];
  3347. this.z = array[offset + 2];
  3348. return this;
  3349. };
  3350. _proto.toArray = function toArray(array, offset) {
  3351. if (array === void 0) {
  3352. array = [];
  3353. }
  3354. if (offset === void 0) {
  3355. offset = 0;
  3356. }
  3357. array[offset] = this.x;
  3358. array[offset + 1] = this.y;
  3359. array[offset + 2] = this.z;
  3360. return array;
  3361. };
  3362. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  3363. if (offset !== undefined) {
  3364. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  3365. }
  3366. this.x = attribute.getX(index);
  3367. this.y = attribute.getY(index);
  3368. this.z = attribute.getZ(index);
  3369. return this;
  3370. };
  3371. _proto.random = function random() {
  3372. this.x = Math.random();
  3373. this.y = Math.random();
  3374. this.z = Math.random();
  3375. return this;
  3376. };
  3377. return Vector3;
  3378. }();
  3379. Vector3.prototype.isVector3 = true;
  3380. var _vector = /*@__PURE__*/new Vector3();
  3381. var _quaternion = /*@__PURE__*/new Quaternion();
  3382. var Box3 = /*#__PURE__*/function () {
  3383. function Box3(min, max) {
  3384. if (min === void 0) {
  3385. min = new Vector3(+Infinity, +Infinity, +Infinity);
  3386. }
  3387. if (max === void 0) {
  3388. max = new Vector3(-Infinity, -Infinity, -Infinity);
  3389. }
  3390. this.min = min;
  3391. this.max = max;
  3392. }
  3393. var _proto = Box3.prototype;
  3394. _proto.set = function set(min, max) {
  3395. this.min.copy(min);
  3396. this.max.copy(max);
  3397. return this;
  3398. };
  3399. _proto.setFromArray = function setFromArray(array) {
  3400. var minX = +Infinity;
  3401. var minY = +Infinity;
  3402. var minZ = +Infinity;
  3403. var maxX = -Infinity;
  3404. var maxY = -Infinity;
  3405. var maxZ = -Infinity;
  3406. for (var i = 0, l = array.length; i < l; i += 3) {
  3407. var x = array[i];
  3408. var y = array[i + 1];
  3409. var z = array[i + 2];
  3410. if (x < minX) minX = x;
  3411. if (y < minY) minY = y;
  3412. if (z < minZ) minZ = z;
  3413. if (x > maxX) maxX = x;
  3414. if (y > maxY) maxY = y;
  3415. if (z > maxZ) maxZ = z;
  3416. }
  3417. this.min.set(minX, minY, minZ);
  3418. this.max.set(maxX, maxY, maxZ);
  3419. return this;
  3420. };
  3421. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  3422. var minX = +Infinity;
  3423. var minY = +Infinity;
  3424. var minZ = +Infinity;
  3425. var maxX = -Infinity;
  3426. var maxY = -Infinity;
  3427. var maxZ = -Infinity;
  3428. for (var i = 0, l = attribute.count; i < l; i++) {
  3429. var x = attribute.getX(i);
  3430. var y = attribute.getY(i);
  3431. var z = attribute.getZ(i);
  3432. if (x < minX) minX = x;
  3433. if (y < minY) minY = y;
  3434. if (z < minZ) minZ = z;
  3435. if (x > maxX) maxX = x;
  3436. if (y > maxY) maxY = y;
  3437. if (z > maxZ) maxZ = z;
  3438. }
  3439. this.min.set(minX, minY, minZ);
  3440. this.max.set(maxX, maxY, maxZ);
  3441. return this;
  3442. };
  3443. _proto.setFromPoints = function setFromPoints(points) {
  3444. this.makeEmpty();
  3445. for (var i = 0, il = points.length; i < il; i++) {
  3446. this.expandByPoint(points[i]);
  3447. }
  3448. return this;
  3449. };
  3450. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  3451. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  3452. this.min.copy(center).sub(halfSize);
  3453. this.max.copy(center).add(halfSize);
  3454. return this;
  3455. };
  3456. _proto.setFromObject = function setFromObject(object) {
  3457. this.makeEmpty();
  3458. return this.expandByObject(object);
  3459. };
  3460. _proto.clone = function clone() {
  3461. return new this.constructor().copy(this);
  3462. };
  3463. _proto.copy = function copy(box) {
  3464. this.min.copy(box.min);
  3465. this.max.copy(box.max);
  3466. return this;
  3467. };
  3468. _proto.makeEmpty = function makeEmpty() {
  3469. this.min.x = this.min.y = this.min.z = +Infinity;
  3470. this.max.x = this.max.y = this.max.z = -Infinity;
  3471. return this;
  3472. };
  3473. _proto.isEmpty = function isEmpty() {
  3474. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3475. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  3476. };
  3477. _proto.getCenter = function getCenter(target) {
  3478. if (target === undefined) {
  3479. console.warn('THREE.Box3: .getCenter() target is now required');
  3480. target = new Vector3();
  3481. }
  3482. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  3483. };
  3484. _proto.getSize = function getSize(target) {
  3485. if (target === undefined) {
  3486. console.warn('THREE.Box3: .getSize() target is now required');
  3487. target = new Vector3();
  3488. }
  3489. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  3490. };
  3491. _proto.expandByPoint = function expandByPoint(point) {
  3492. this.min.min(point);
  3493. this.max.max(point);
  3494. return this;
  3495. };
  3496. _proto.expandByVector = function expandByVector(vector) {
  3497. this.min.sub(vector);
  3498. this.max.add(vector);
  3499. return this;
  3500. };
  3501. _proto.expandByScalar = function expandByScalar(scalar) {
  3502. this.min.addScalar(-scalar);
  3503. this.max.addScalar(scalar);
  3504. return this;
  3505. };
  3506. _proto.expandByObject = function expandByObject(object) {
  3507. // Computes the world-axis-aligned bounding box of an object (including its children),
  3508. // accounting for both the object's, and children's, world transforms
  3509. object.updateWorldMatrix(false, false);
  3510. var geometry = object.geometry;
  3511. if (geometry !== undefined) {
  3512. if (geometry.boundingBox === null) {
  3513. geometry.computeBoundingBox();
  3514. }
  3515. _box.copy(geometry.boundingBox);
  3516. _box.applyMatrix4(object.matrixWorld);
  3517. this.union(_box);
  3518. }
  3519. var children = object.children;
  3520. for (var i = 0, l = children.length; i < l; i++) {
  3521. this.expandByObject(children[i]);
  3522. }
  3523. return this;
  3524. };
  3525. _proto.containsPoint = function containsPoint(point) {
  3526. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true;
  3527. };
  3528. _proto.containsBox = function containsBox(box) {
  3529. return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z;
  3530. };
  3531. _proto.getParameter = function getParameter(point, target) {
  3532. // This can potentially have a divide by zero if the box
  3533. // has a size dimension of 0.
  3534. if (target === undefined) {
  3535. console.warn('THREE.Box3: .getParameter() target is now required');
  3536. target = new Vector3();
  3537. }
  3538. return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
  3539. };
  3540. _proto.intersectsBox = function intersectsBox(box) {
  3541. // using 6 splitting planes to rule out intersections.
  3542. return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3543. };
  3544. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3545. // Find the point on the AABB closest to the sphere center.
  3546. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  3547. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  3548. };
  3549. _proto.intersectsPlane = function intersectsPlane(plane) {
  3550. // We compute the minimum and maximum dot product values. If those values
  3551. // are on the same side (back or front) of the plane, then there is no intersection.
  3552. var min, max;
  3553. if (plane.normal.x > 0) {
  3554. min = plane.normal.x * this.min.x;
  3555. max = plane.normal.x * this.max.x;
  3556. } else {
  3557. min = plane.normal.x * this.max.x;
  3558. max = plane.normal.x * this.min.x;
  3559. }
  3560. if (plane.normal.y > 0) {
  3561. min += plane.normal.y * this.min.y;
  3562. max += plane.normal.y * this.max.y;
  3563. } else {
  3564. min += plane.normal.y * this.max.y;
  3565. max += plane.normal.y * this.min.y;
  3566. }
  3567. if (plane.normal.z > 0) {
  3568. min += plane.normal.z * this.min.z;
  3569. max += plane.normal.z * this.max.z;
  3570. } else {
  3571. min += plane.normal.z * this.max.z;
  3572. max += plane.normal.z * this.min.z;
  3573. }
  3574. return min <= -plane.constant && max >= -plane.constant;
  3575. };
  3576. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  3577. if (this.isEmpty()) {
  3578. return false;
  3579. } // compute box center and extents
  3580. this.getCenter(_center);
  3581. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  3582. _v0.subVectors(triangle.a, _center);
  3583. _v1.subVectors(triangle.b, _center);
  3584. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  3585. _f0.subVectors(_v1, _v0);
  3586. _f1.subVectors(_v2, _v1);
  3587. _f2.subVectors(_v0, _v2); // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3588. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  3589. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3590. var axes = [0, -_f0.z, _f0.y, 0, -_f1.z, _f1.y, 0, -_f2.z, _f2.y, _f0.z, 0, -_f0.x, _f1.z, 0, -_f1.x, _f2.z, 0, -_f2.x, -_f0.y, _f0.x, 0, -_f1.y, _f1.x, 0, -_f2.y, _f2.x, 0];
  3591. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3592. return false;
  3593. } // test 3 face normals from the aabb
  3594. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  3595. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3596. return false;
  3597. } // finally testing the face normal of the triangle
  3598. // use already existing triangle edge vectors here
  3599. _triangleNormal.crossVectors(_f0, _f1);
  3600. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  3601. return satForAxes(axes, _v0, _v1, _v2, _extents);
  3602. };
  3603. _proto.clampPoint = function clampPoint(point, target) {
  3604. if (target === undefined) {
  3605. console.warn('THREE.Box3: .clampPoint() target is now required');
  3606. target = new Vector3();
  3607. }
  3608. return target.copy(point).clamp(this.min, this.max);
  3609. };
  3610. _proto.distanceToPoint = function distanceToPoint(point) {
  3611. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  3612. return clampedPoint.sub(point).length();
  3613. };
  3614. _proto.getBoundingSphere = function getBoundingSphere(target) {
  3615. if (target === undefined) {
  3616. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  3617. }
  3618. this.getCenter(target.center);
  3619. target.radius = this.getSize(_vector$1).length() * 0.5;
  3620. return target;
  3621. };
  3622. _proto.intersect = function intersect(box) {
  3623. this.min.max(box.min);
  3624. this.max.min(box.max); // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  3625. if (this.isEmpty()) this.makeEmpty();
  3626. return this;
  3627. };
  3628. _proto.union = function union(box) {
  3629. this.min.min(box.min);
  3630. this.max.max(box.max);
  3631. return this;
  3632. };
  3633. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3634. // transform of empty box is an empty box.
  3635. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3636. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  3637. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  3638. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  3639. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  3640. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  3641. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  3642. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  3643. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  3644. this.setFromPoints(_points);
  3645. return this;
  3646. };
  3647. _proto.translate = function translate(offset) {
  3648. this.min.add(offset);
  3649. this.max.add(offset);
  3650. return this;
  3651. };
  3652. _proto.equals = function equals(box) {
  3653. return box.min.equals(this.min) && box.max.equals(this.max);
  3654. };
  3655. return Box3;
  3656. }();
  3657. Box3.prototype.isBox3 = true;
  3658. var _points = [/*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3()];
  3659. var _vector$1 = /*@__PURE__*/new Vector3();
  3660. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  3661. var _v0 = /*@__PURE__*/new Vector3();
  3662. var _v1 = /*@__PURE__*/new Vector3();
  3663. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  3664. var _f0 = /*@__PURE__*/new Vector3();
  3665. var _f1 = /*@__PURE__*/new Vector3();
  3666. var _f2 = /*@__PURE__*/new Vector3();
  3667. var _center = /*@__PURE__*/new Vector3();
  3668. var _extents = /*@__PURE__*/new Vector3();
  3669. var _triangleNormal = /*@__PURE__*/new Vector3();
  3670. var _testAxis = /*@__PURE__*/new Vector3();
  3671. function satForAxes(axes, v0, v1, v2, extents) {
  3672. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  3673. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  3674. var r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z); // project all 3 vertices of the triangle onto the seperating axis
  3675. var p0 = v0.dot(_testAxis);
  3676. var p1 = v1.dot(_testAxis);
  3677. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  3678. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  3679. // points of the projected triangle are outside the projected half-length of the aabb
  3680. // the axis is seperating and we can exit
  3681. return false;
  3682. }
  3683. }
  3684. return true;
  3685. }
  3686. var _box$1 = /*@__PURE__*/new Box3();
  3687. var Sphere = /*#__PURE__*/function () {
  3688. function Sphere(center, radius) {
  3689. if (center === void 0) {
  3690. center = new Vector3();
  3691. }
  3692. if (radius === void 0) {
  3693. radius = -1;
  3694. }
  3695. this.center = center;
  3696. this.radius = radius;
  3697. }
  3698. var _proto = Sphere.prototype;
  3699. _proto.set = function set(center, radius) {
  3700. this.center.copy(center);
  3701. this.radius = radius;
  3702. return this;
  3703. };
  3704. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  3705. var center = this.center;
  3706. if (optionalCenter !== undefined) {
  3707. center.copy(optionalCenter);
  3708. } else {
  3709. _box$1.setFromPoints(points).getCenter(center);
  3710. }
  3711. var maxRadiusSq = 0;
  3712. for (var i = 0, il = points.length; i < il; i++) {
  3713. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  3714. }
  3715. this.radius = Math.sqrt(maxRadiusSq);
  3716. return this;
  3717. };
  3718. _proto.copy = function copy(sphere) {
  3719. this.center.copy(sphere.center);
  3720. this.radius = sphere.radius;
  3721. return this;
  3722. };
  3723. _proto.isEmpty = function isEmpty() {
  3724. return this.radius < 0;
  3725. };
  3726. _proto.makeEmpty = function makeEmpty() {
  3727. this.center.set(0, 0, 0);
  3728. this.radius = -1;
  3729. return this;
  3730. };
  3731. _proto.containsPoint = function containsPoint(point) {
  3732. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3733. };
  3734. _proto.distanceToPoint = function distanceToPoint(point) {
  3735. return point.distanceTo(this.center) - this.radius;
  3736. };
  3737. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3738. var radiusSum = this.radius + sphere.radius;
  3739. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3740. };
  3741. _proto.intersectsBox = function intersectsBox(box) {
  3742. return box.intersectsSphere(this);
  3743. };
  3744. _proto.intersectsPlane = function intersectsPlane(plane) {
  3745. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3746. };
  3747. _proto.clampPoint = function clampPoint(point, target) {
  3748. var deltaLengthSq = this.center.distanceToSquared(point);
  3749. if (target === undefined) {
  3750. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3751. target = new Vector3();
  3752. }
  3753. target.copy(point);
  3754. if (deltaLengthSq > this.radius * this.radius) {
  3755. target.sub(this.center).normalize();
  3756. target.multiplyScalar(this.radius).add(this.center);
  3757. }
  3758. return target;
  3759. };
  3760. _proto.getBoundingBox = function getBoundingBox(target) {
  3761. if (target === undefined) {
  3762. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3763. target = new Box3();
  3764. }
  3765. if (this.isEmpty()) {
  3766. // Empty sphere produces empty bounding box
  3767. target.makeEmpty();
  3768. return target;
  3769. }
  3770. target.set(this.center, this.center);
  3771. target.expandByScalar(this.radius);
  3772. return target;
  3773. };
  3774. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3775. this.center.applyMatrix4(matrix);
  3776. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3777. return this;
  3778. };
  3779. _proto.translate = function translate(offset) {
  3780. this.center.add(offset);
  3781. return this;
  3782. };
  3783. _proto.equals = function equals(sphere) {
  3784. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3785. };
  3786. _proto.clone = function clone() {
  3787. return new this.constructor().copy(this);
  3788. };
  3789. return Sphere;
  3790. }();
  3791. var _vector$2 = /*@__PURE__*/new Vector3();
  3792. var _segCenter = /*@__PURE__*/new Vector3();
  3793. var _segDir = /*@__PURE__*/new Vector3();
  3794. var _diff = /*@__PURE__*/new Vector3();
  3795. var _edge1 = /*@__PURE__*/new Vector3();
  3796. var _edge2 = /*@__PURE__*/new Vector3();
  3797. var _normal = /*@__PURE__*/new Vector3();
  3798. var Ray = /*#__PURE__*/function () {
  3799. function Ray(origin, direction) {
  3800. if (origin === void 0) {
  3801. origin = new Vector3();
  3802. }
  3803. if (direction === void 0) {
  3804. direction = new Vector3(0, 0, -1);
  3805. }
  3806. this.origin = origin;
  3807. this.direction = direction;
  3808. }
  3809. var _proto = Ray.prototype;
  3810. _proto.set = function set(origin, direction) {
  3811. this.origin.copy(origin);
  3812. this.direction.copy(direction);
  3813. return this;
  3814. };
  3815. _proto.copy = function copy(ray) {
  3816. this.origin.copy(ray.origin);
  3817. this.direction.copy(ray.direction);
  3818. return this;
  3819. };
  3820. _proto.at = function at(t, target) {
  3821. if (target === undefined) {
  3822. console.warn('THREE.Ray: .at() target is now required');
  3823. target = new Vector3();
  3824. }
  3825. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3826. };
  3827. _proto.lookAt = function lookAt(v) {
  3828. this.direction.copy(v).sub(this.origin).normalize();
  3829. return this;
  3830. };
  3831. _proto.recast = function recast(t) {
  3832. this.origin.copy(this.at(t, _vector$2));
  3833. return this;
  3834. };
  3835. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3836. if (target === undefined) {
  3837. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3838. target = new Vector3();
  3839. }
  3840. target.subVectors(point, this.origin);
  3841. var directionDistance = target.dot(this.direction);
  3842. if (directionDistance < 0) {
  3843. return target.copy(this.origin);
  3844. }
  3845. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3846. };
  3847. _proto.distanceToPoint = function distanceToPoint(point) {
  3848. return Math.sqrt(this.distanceSqToPoint(point));
  3849. };
  3850. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3851. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3852. if (directionDistance < 0) {
  3853. return this.origin.distanceToSquared(point);
  3854. }
  3855. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3856. return _vector$2.distanceToSquared(point);
  3857. };
  3858. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3859. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3860. // It returns the min distance between the ray and the segment
  3861. // defined by v0 and v1
  3862. // It can also set two optional targets :
  3863. // - The closest point on the ray
  3864. // - The closest point on the segment
  3865. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3866. _segDir.copy(v1).sub(v0).normalize();
  3867. _diff.copy(this.origin).sub(_segCenter);
  3868. var segExtent = v0.distanceTo(v1) * 0.5;
  3869. var a01 = -this.direction.dot(_segDir);
  3870. var b0 = _diff.dot(this.direction);
  3871. var b1 = -_diff.dot(_segDir);
  3872. var c = _diff.lengthSq();
  3873. var det = Math.abs(1 - a01 * a01);
  3874. var s0, s1, sqrDist, extDet;
  3875. if (det > 0) {
  3876. // The ray and segment are not parallel.
  3877. s0 = a01 * b1 - b0;
  3878. s1 = a01 * b0 - b1;
  3879. extDet = segExtent * det;
  3880. if (s0 >= 0) {
  3881. if (s1 >= -extDet) {
  3882. if (s1 <= extDet) {
  3883. // region 0
  3884. // Minimum at interior points of ray and segment.
  3885. var invDet = 1 / det;
  3886. s0 *= invDet;
  3887. s1 *= invDet;
  3888. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3889. } else {
  3890. // region 1
  3891. s1 = segExtent;
  3892. s0 = Math.max(0, -(a01 * s1 + b0));
  3893. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3894. }
  3895. } else {
  3896. // region 5
  3897. s1 = -segExtent;
  3898. s0 = Math.max(0, -(a01 * s1 + b0));
  3899. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3900. }
  3901. } else {
  3902. if (s1 <= -extDet) {
  3903. // region 4
  3904. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3905. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3906. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3907. } else if (s1 <= extDet) {
  3908. // region 3
  3909. s0 = 0;
  3910. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3911. sqrDist = s1 * (s1 + 2 * b1) + c;
  3912. } else {
  3913. // region 2
  3914. s0 = Math.max(0, -(a01 * segExtent + b0));
  3915. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3916. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3917. }
  3918. }
  3919. } else {
  3920. // Ray and segment are parallel.
  3921. s1 = a01 > 0 ? -segExtent : segExtent;
  3922. s0 = Math.max(0, -(a01 * s1 + b0));
  3923. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3924. }
  3925. if (optionalPointOnRay) {
  3926. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3927. }
  3928. if (optionalPointOnSegment) {
  3929. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3930. }
  3931. return sqrDist;
  3932. };
  3933. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3934. _vector$2.subVectors(sphere.center, this.origin);
  3935. var tca = _vector$2.dot(this.direction);
  3936. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3937. var radius2 = sphere.radius * sphere.radius;
  3938. if (d2 > radius2) return null;
  3939. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3940. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3941. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3942. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3943. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3944. // in order to always return an intersect point that is in front of the ray.
  3945. if (t0 < 0) return this.at(t1, target); // else t0 is in front of the ray, so return the first collision point scaled by t0
  3946. return this.at(t0, target);
  3947. };
  3948. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3949. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3950. };
  3951. _proto.distanceToPlane = function distanceToPlane(plane) {
  3952. var denominator = plane.normal.dot(this.direction);
  3953. if (denominator === 0) {
  3954. // line is coplanar, return origin
  3955. if (plane.distanceToPoint(this.origin) === 0) {
  3956. return 0;
  3957. } // Null is preferable to undefined since undefined means.... it is undefined
  3958. return null;
  3959. }
  3960. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3961. return t >= 0 ? t : null;
  3962. };
  3963. _proto.intersectPlane = function intersectPlane(plane, target) {
  3964. var t = this.distanceToPlane(plane);
  3965. if (t === null) {
  3966. return null;
  3967. }
  3968. return this.at(t, target);
  3969. };
  3970. _proto.intersectsPlane = function intersectsPlane(plane) {
  3971. // check if the ray lies on the plane first
  3972. var distToPoint = plane.distanceToPoint(this.origin);
  3973. if (distToPoint === 0) {
  3974. return true;
  3975. }
  3976. var denominator = plane.normal.dot(this.direction);
  3977. if (denominator * distToPoint < 0) {
  3978. return true;
  3979. } // ray origin is behind the plane (and is pointing behind it)
  3980. return false;
  3981. };
  3982. _proto.intersectBox = function intersectBox(box, target) {
  3983. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3984. var invdirx = 1 / this.direction.x,
  3985. invdiry = 1 / this.direction.y,
  3986. invdirz = 1 / this.direction.z;
  3987. var origin = this.origin;
  3988. if (invdirx >= 0) {
  3989. tmin = (box.min.x - origin.x) * invdirx;
  3990. tmax = (box.max.x - origin.x) * invdirx;
  3991. } else {
  3992. tmin = (box.max.x - origin.x) * invdirx;
  3993. tmax = (box.min.x - origin.x) * invdirx;
  3994. }
  3995. if (invdiry >= 0) {
  3996. tymin = (box.min.y - origin.y) * invdiry;
  3997. tymax = (box.max.y - origin.y) * invdiry;
  3998. } else {
  3999. tymin = (box.max.y - origin.y) * invdiry;
  4000. tymax = (box.min.y - origin.y) * invdiry;
  4001. }
  4002. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  4003. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4004. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  4005. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  4006. if (invdirz >= 0) {
  4007. tzmin = (box.min.z - origin.z) * invdirz;
  4008. tzmax = (box.max.z - origin.z) * invdirz;
  4009. } else {
  4010. tzmin = (box.max.z - origin.z) * invdirz;
  4011. tzmax = (box.min.z - origin.z) * invdirz;
  4012. }
  4013. if (tmin > tzmax || tzmin > tmax) return null;
  4014. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  4015. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  4016. if (tmax < 0) return null;
  4017. return this.at(tmin >= 0 ? tmin : tmax, target);
  4018. };
  4019. _proto.intersectsBox = function intersectsBox(box) {
  4020. return this.intersectBox(box, _vector$2) !== null;
  4021. };
  4022. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  4023. // Compute the offset origin, edges, and normal.
  4024. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4025. _edge1.subVectors(b, a);
  4026. _edge2.subVectors(c, a);
  4027. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4028. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4029. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4030. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4031. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4032. var DdN = this.direction.dot(_normal);
  4033. var sign;
  4034. if (DdN > 0) {
  4035. if (backfaceCulling) return null;
  4036. sign = 1;
  4037. } else if (DdN < 0) {
  4038. sign = -1;
  4039. DdN = -DdN;
  4040. } else {
  4041. return null;
  4042. }
  4043. _diff.subVectors(this.origin, a);
  4044. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  4045. if (DdQxE2 < 0) {
  4046. return null;
  4047. }
  4048. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  4049. if (DdE1xQ < 0) {
  4050. return null;
  4051. } // b1+b2 > 1, no intersection
  4052. if (DdQxE2 + DdE1xQ > DdN) {
  4053. return null;
  4054. } // Line intersects triangle, check if ray does.
  4055. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  4056. if (QdN < 0) {
  4057. return null;
  4058. } // Ray intersects triangle.
  4059. return this.at(QdN / DdN, target);
  4060. };
  4061. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  4062. this.origin.applyMatrix4(matrix4);
  4063. this.direction.transformDirection(matrix4);
  4064. return this;
  4065. };
  4066. _proto.equals = function equals(ray) {
  4067. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  4068. };
  4069. _proto.clone = function clone() {
  4070. return new this.constructor().copy(this);
  4071. };
  4072. return Ray;
  4073. }();
  4074. var Matrix4 = /*#__PURE__*/function () {
  4075. function Matrix4() {
  4076. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  4077. if (arguments.length > 0) {
  4078. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  4079. }
  4080. }
  4081. var _proto = Matrix4.prototype;
  4082. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  4083. var te = this.elements;
  4084. te[0] = n11;
  4085. te[4] = n12;
  4086. te[8] = n13;
  4087. te[12] = n14;
  4088. te[1] = n21;
  4089. te[5] = n22;
  4090. te[9] = n23;
  4091. te[13] = n24;
  4092. te[2] = n31;
  4093. te[6] = n32;
  4094. te[10] = n33;
  4095. te[14] = n34;
  4096. te[3] = n41;
  4097. te[7] = n42;
  4098. te[11] = n43;
  4099. te[15] = n44;
  4100. return this;
  4101. };
  4102. _proto.identity = function identity() {
  4103. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4104. return this;
  4105. };
  4106. _proto.clone = function clone() {
  4107. return new Matrix4().fromArray(this.elements);
  4108. };
  4109. _proto.copy = function copy(m) {
  4110. var te = this.elements;
  4111. var me = m.elements;
  4112. te[0] = me[0];
  4113. te[1] = me[1];
  4114. te[2] = me[2];
  4115. te[3] = me[3];
  4116. te[4] = me[4];
  4117. te[5] = me[5];
  4118. te[6] = me[6];
  4119. te[7] = me[7];
  4120. te[8] = me[8];
  4121. te[9] = me[9];
  4122. te[10] = me[10];
  4123. te[11] = me[11];
  4124. te[12] = me[12];
  4125. te[13] = me[13];
  4126. te[14] = me[14];
  4127. te[15] = me[15];
  4128. return this;
  4129. };
  4130. _proto.copyPosition = function copyPosition(m) {
  4131. var te = this.elements,
  4132. me = m.elements;
  4133. te[12] = me[12];
  4134. te[13] = me[13];
  4135. te[14] = me[14];
  4136. return this;
  4137. };
  4138. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  4139. var me = m.elements;
  4140. this.set(me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1);
  4141. return this;
  4142. };
  4143. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  4144. xAxis.setFromMatrixColumn(this, 0);
  4145. yAxis.setFromMatrixColumn(this, 1);
  4146. zAxis.setFromMatrixColumn(this, 2);
  4147. return this;
  4148. };
  4149. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  4150. this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
  4151. return this;
  4152. };
  4153. _proto.extractRotation = function extractRotation(m) {
  4154. // this method does not support reflection matrices
  4155. var te = this.elements;
  4156. var me = m.elements;
  4157. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  4158. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  4159. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  4160. te[0] = me[0] * scaleX;
  4161. te[1] = me[1] * scaleX;
  4162. te[2] = me[2] * scaleX;
  4163. te[3] = 0;
  4164. te[4] = me[4] * scaleY;
  4165. te[5] = me[5] * scaleY;
  4166. te[6] = me[6] * scaleY;
  4167. te[7] = 0;
  4168. te[8] = me[8] * scaleZ;
  4169. te[9] = me[9] * scaleZ;
  4170. te[10] = me[10] * scaleZ;
  4171. te[11] = 0;
  4172. te[12] = 0;
  4173. te[13] = 0;
  4174. te[14] = 0;
  4175. te[15] = 1;
  4176. return this;
  4177. };
  4178. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  4179. if (!(euler && euler.isEuler)) {
  4180. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  4181. }
  4182. var te = this.elements;
  4183. var x = euler.x,
  4184. y = euler.y,
  4185. z = euler.z;
  4186. var a = Math.cos(x),
  4187. b = Math.sin(x);
  4188. var c = Math.cos(y),
  4189. d = Math.sin(y);
  4190. var e = Math.cos(z),
  4191. f = Math.sin(z);
  4192. if (euler.order === 'XYZ') {
  4193. var ae = a * e,
  4194. af = a * f,
  4195. be = b * e,
  4196. bf = b * f;
  4197. te[0] = c * e;
  4198. te[4] = -c * f;
  4199. te[8] = d;
  4200. te[1] = af + be * d;
  4201. te[5] = ae - bf * d;
  4202. te[9] = -b * c;
  4203. te[2] = bf - ae * d;
  4204. te[6] = be + af * d;
  4205. te[10] = a * c;
  4206. } else if (euler.order === 'YXZ') {
  4207. var ce = c * e,
  4208. cf = c * f,
  4209. de = d * e,
  4210. df = d * f;
  4211. te[0] = ce + df * b;
  4212. te[4] = de * b - cf;
  4213. te[8] = a * d;
  4214. te[1] = a * f;
  4215. te[5] = a * e;
  4216. te[9] = -b;
  4217. te[2] = cf * b - de;
  4218. te[6] = df + ce * b;
  4219. te[10] = a * c;
  4220. } else if (euler.order === 'ZXY') {
  4221. var _ce = c * e,
  4222. _cf = c * f,
  4223. _de = d * e,
  4224. _df = d * f;
  4225. te[0] = _ce - _df * b;
  4226. te[4] = -a * f;
  4227. te[8] = _de + _cf * b;
  4228. te[1] = _cf + _de * b;
  4229. te[5] = a * e;
  4230. te[9] = _df - _ce * b;
  4231. te[2] = -a * d;
  4232. te[6] = b;
  4233. te[10] = a * c;
  4234. } else if (euler.order === 'ZYX') {
  4235. var _ae = a * e,
  4236. _af = a * f,
  4237. _be = b * e,
  4238. _bf = b * f;
  4239. te[0] = c * e;
  4240. te[4] = _be * d - _af;
  4241. te[8] = _ae * d + _bf;
  4242. te[1] = c * f;
  4243. te[5] = _bf * d + _ae;
  4244. te[9] = _af * d - _be;
  4245. te[2] = -d;
  4246. te[6] = b * c;
  4247. te[10] = a * c;
  4248. } else if (euler.order === 'YZX') {
  4249. var ac = a * c,
  4250. ad = a * d,
  4251. bc = b * c,
  4252. bd = b * d;
  4253. te[0] = c * e;
  4254. te[4] = bd - ac * f;
  4255. te[8] = bc * f + ad;
  4256. te[1] = f;
  4257. te[5] = a * e;
  4258. te[9] = -b * e;
  4259. te[2] = -d * e;
  4260. te[6] = ad * f + bc;
  4261. te[10] = ac - bd * f;
  4262. } else if (euler.order === 'XZY') {
  4263. var _ac = a * c,
  4264. _ad = a * d,
  4265. _bc = b * c,
  4266. _bd = b * d;
  4267. te[0] = c * e;
  4268. te[4] = -f;
  4269. te[8] = d * e;
  4270. te[1] = _ac * f + _bd;
  4271. te[5] = a * e;
  4272. te[9] = _ad * f - _bc;
  4273. te[2] = _bc * f - _ad;
  4274. te[6] = b * e;
  4275. te[10] = _bd * f + _ac;
  4276. } // bottom row
  4277. te[3] = 0;
  4278. te[7] = 0;
  4279. te[11] = 0; // last column
  4280. te[12] = 0;
  4281. te[13] = 0;
  4282. te[14] = 0;
  4283. te[15] = 1;
  4284. return this;
  4285. };
  4286. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  4287. return this.compose(_zero, q, _one);
  4288. };
  4289. _proto.lookAt = function lookAt(eye, target, up) {
  4290. var te = this.elements;
  4291. _z.subVectors(eye, target);
  4292. if (_z.lengthSq() === 0) {
  4293. // eye and target are in the same position
  4294. _z.z = 1;
  4295. }
  4296. _z.normalize();
  4297. _x.crossVectors(up, _z);
  4298. if (_x.lengthSq() === 0) {
  4299. // up and z are parallel
  4300. if (Math.abs(up.z) === 1) {
  4301. _z.x += 0.0001;
  4302. } else {
  4303. _z.z += 0.0001;
  4304. }
  4305. _z.normalize();
  4306. _x.crossVectors(up, _z);
  4307. }
  4308. _x.normalize();
  4309. _y.crossVectors(_z, _x);
  4310. te[0] = _x.x;
  4311. te[4] = _y.x;
  4312. te[8] = _z.x;
  4313. te[1] = _x.y;
  4314. te[5] = _y.y;
  4315. te[9] = _z.y;
  4316. te[2] = _x.z;
  4317. te[6] = _y.z;
  4318. te[10] = _z.z;
  4319. return this;
  4320. };
  4321. _proto.multiply = function multiply(m, n) {
  4322. if (n !== undefined) {
  4323. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  4324. return this.multiplyMatrices(m, n);
  4325. }
  4326. return this.multiplyMatrices(this, m);
  4327. };
  4328. _proto.premultiply = function premultiply(m) {
  4329. return this.multiplyMatrices(m, this);
  4330. };
  4331. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  4332. var ae = a.elements;
  4333. var be = b.elements;
  4334. var te = this.elements;
  4335. var a11 = ae[0],
  4336. a12 = ae[4],
  4337. a13 = ae[8],
  4338. a14 = ae[12];
  4339. var a21 = ae[1],
  4340. a22 = ae[5],
  4341. a23 = ae[9],
  4342. a24 = ae[13];
  4343. var a31 = ae[2],
  4344. a32 = ae[6],
  4345. a33 = ae[10],
  4346. a34 = ae[14];
  4347. var a41 = ae[3],
  4348. a42 = ae[7],
  4349. a43 = ae[11],
  4350. a44 = ae[15];
  4351. var b11 = be[0],
  4352. b12 = be[4],
  4353. b13 = be[8],
  4354. b14 = be[12];
  4355. var b21 = be[1],
  4356. b22 = be[5],
  4357. b23 = be[9],
  4358. b24 = be[13];
  4359. var b31 = be[2],
  4360. b32 = be[6],
  4361. b33 = be[10],
  4362. b34 = be[14];
  4363. var b41 = be[3],
  4364. b42 = be[7],
  4365. b43 = be[11],
  4366. b44 = be[15];
  4367. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  4368. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  4369. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  4370. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  4371. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  4372. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  4373. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  4374. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  4375. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  4376. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  4377. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  4378. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  4379. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  4380. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  4381. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  4382. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  4383. return this;
  4384. };
  4385. _proto.multiplyScalar = function multiplyScalar(s) {
  4386. var te = this.elements;
  4387. te[0] *= s;
  4388. te[4] *= s;
  4389. te[8] *= s;
  4390. te[12] *= s;
  4391. te[1] *= s;
  4392. te[5] *= s;
  4393. te[9] *= s;
  4394. te[13] *= s;
  4395. te[2] *= s;
  4396. te[6] *= s;
  4397. te[10] *= s;
  4398. te[14] *= s;
  4399. te[3] *= s;
  4400. te[7] *= s;
  4401. te[11] *= s;
  4402. te[15] *= s;
  4403. return this;
  4404. };
  4405. _proto.determinant = function determinant() {
  4406. var te = this.elements;
  4407. var n11 = te[0],
  4408. n12 = te[4],
  4409. n13 = te[8],
  4410. n14 = te[12];
  4411. var n21 = te[1],
  4412. n22 = te[5],
  4413. n23 = te[9],
  4414. n24 = te[13];
  4415. var n31 = te[2],
  4416. n32 = te[6],
  4417. n33 = te[10],
  4418. n34 = te[14];
  4419. var n41 = te[3],
  4420. n42 = te[7],
  4421. n43 = te[11],
  4422. n44 = te[15]; //TODO: make this more efficient
  4423. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  4424. return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31);
  4425. };
  4426. _proto.transpose = function transpose() {
  4427. var te = this.elements;
  4428. var tmp;
  4429. tmp = te[1];
  4430. te[1] = te[4];
  4431. te[4] = tmp;
  4432. tmp = te[2];
  4433. te[2] = te[8];
  4434. te[8] = tmp;
  4435. tmp = te[6];
  4436. te[6] = te[9];
  4437. te[9] = tmp;
  4438. tmp = te[3];
  4439. te[3] = te[12];
  4440. te[12] = tmp;
  4441. tmp = te[7];
  4442. te[7] = te[13];
  4443. te[13] = tmp;
  4444. tmp = te[11];
  4445. te[11] = te[14];
  4446. te[14] = tmp;
  4447. return this;
  4448. };
  4449. _proto.setPosition = function setPosition(x, y, z) {
  4450. var te = this.elements;
  4451. if (x.isVector3) {
  4452. te[12] = x.x;
  4453. te[13] = x.y;
  4454. te[14] = x.z;
  4455. } else {
  4456. te[12] = x;
  4457. te[13] = y;
  4458. te[14] = z;
  4459. }
  4460. return this;
  4461. };
  4462. _proto.invert = function invert() {
  4463. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  4464. var te = this.elements,
  4465. n11 = te[0],
  4466. n21 = te[1],
  4467. n31 = te[2],
  4468. n41 = te[3],
  4469. n12 = te[4],
  4470. n22 = te[5],
  4471. n32 = te[6],
  4472. n42 = te[7],
  4473. n13 = te[8],
  4474. n23 = te[9],
  4475. n33 = te[10],
  4476. n43 = te[11],
  4477. n14 = te[12],
  4478. n24 = te[13],
  4479. n34 = te[14],
  4480. n44 = te[15],
  4481. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  4482. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  4483. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  4484. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  4485. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  4486. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  4487. var detInv = 1 / det;
  4488. te[0] = t11 * detInv;
  4489. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  4490. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  4491. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  4492. te[4] = t12 * detInv;
  4493. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  4494. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  4495. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  4496. te[8] = t13 * detInv;
  4497. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  4498. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  4499. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  4500. te[12] = t14 * detInv;
  4501. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  4502. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  4503. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  4504. return this;
  4505. };
  4506. _proto.scale = function scale(v) {
  4507. var te = this.elements;
  4508. var x = v.x,
  4509. y = v.y,
  4510. z = v.z;
  4511. te[0] *= x;
  4512. te[4] *= y;
  4513. te[8] *= z;
  4514. te[1] *= x;
  4515. te[5] *= y;
  4516. te[9] *= z;
  4517. te[2] *= x;
  4518. te[6] *= y;
  4519. te[10] *= z;
  4520. te[3] *= x;
  4521. te[7] *= y;
  4522. te[11] *= z;
  4523. return this;
  4524. };
  4525. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  4526. var te = this.elements;
  4527. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  4528. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  4529. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  4530. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  4531. };
  4532. _proto.makeTranslation = function makeTranslation(x, y, z) {
  4533. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  4534. return this;
  4535. };
  4536. _proto.makeRotationX = function makeRotationX(theta) {
  4537. var c = Math.cos(theta),
  4538. s = Math.sin(theta);
  4539. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  4540. return this;
  4541. };
  4542. _proto.makeRotationY = function makeRotationY(theta) {
  4543. var c = Math.cos(theta),
  4544. s = Math.sin(theta);
  4545. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  4546. return this;
  4547. };
  4548. _proto.makeRotationZ = function makeRotationZ(theta) {
  4549. var c = Math.cos(theta),
  4550. s = Math.sin(theta);
  4551. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4552. return this;
  4553. };
  4554. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  4555. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4556. var c = Math.cos(angle);
  4557. var s = Math.sin(angle);
  4558. var t = 1 - c;
  4559. var x = axis.x,
  4560. y = axis.y,
  4561. z = axis.z;
  4562. var tx = t * x,
  4563. ty = t * y;
  4564. this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
  4565. return this;
  4566. };
  4567. _proto.makeScale = function makeScale(x, y, z) {
  4568. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  4569. return this;
  4570. };
  4571. _proto.makeShear = function makeShear(x, y, z) {
  4572. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  4573. return this;
  4574. };
  4575. _proto.compose = function compose(position, quaternion, scale) {
  4576. var te = this.elements;
  4577. var x = quaternion._x,
  4578. y = quaternion._y,
  4579. z = quaternion._z,
  4580. w = quaternion._w;
  4581. var x2 = x + x,
  4582. y2 = y + y,
  4583. z2 = z + z;
  4584. var xx = x * x2,
  4585. xy = x * y2,
  4586. xz = x * z2;
  4587. var yy = y * y2,
  4588. yz = y * z2,
  4589. zz = z * z2;
  4590. var wx = w * x2,
  4591. wy = w * y2,
  4592. wz = w * z2;
  4593. var sx = scale.x,
  4594. sy = scale.y,
  4595. sz = scale.z;
  4596. te[0] = (1 - (yy + zz)) * sx;
  4597. te[1] = (xy + wz) * sx;
  4598. te[2] = (xz - wy) * sx;
  4599. te[3] = 0;
  4600. te[4] = (xy - wz) * sy;
  4601. te[5] = (1 - (xx + zz)) * sy;
  4602. te[6] = (yz + wx) * sy;
  4603. te[7] = 0;
  4604. te[8] = (xz + wy) * sz;
  4605. te[9] = (yz - wx) * sz;
  4606. te[10] = (1 - (xx + yy)) * sz;
  4607. te[11] = 0;
  4608. te[12] = position.x;
  4609. te[13] = position.y;
  4610. te[14] = position.z;
  4611. te[15] = 1;
  4612. return this;
  4613. };
  4614. _proto.decompose = function decompose(position, quaternion, scale) {
  4615. var te = this.elements;
  4616. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  4617. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  4618. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  4619. var det = this.determinant();
  4620. if (det < 0) sx = -sx;
  4621. position.x = te[12];
  4622. position.y = te[13];
  4623. position.z = te[14]; // scale the rotation part
  4624. _m1.copy(this);
  4625. var invSX = 1 / sx;
  4626. var invSY = 1 / sy;
  4627. var invSZ = 1 / sz;
  4628. _m1.elements[0] *= invSX;
  4629. _m1.elements[1] *= invSX;
  4630. _m1.elements[2] *= invSX;
  4631. _m1.elements[4] *= invSY;
  4632. _m1.elements[5] *= invSY;
  4633. _m1.elements[6] *= invSY;
  4634. _m1.elements[8] *= invSZ;
  4635. _m1.elements[9] *= invSZ;
  4636. _m1.elements[10] *= invSZ;
  4637. quaternion.setFromRotationMatrix(_m1);
  4638. scale.x = sx;
  4639. scale.y = sy;
  4640. scale.z = sz;
  4641. return this;
  4642. };
  4643. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  4644. if (far === undefined) {
  4645. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  4646. }
  4647. var te = this.elements;
  4648. var x = 2 * near / (right - left);
  4649. var y = 2 * near / (top - bottom);
  4650. var a = (right + left) / (right - left);
  4651. var b = (top + bottom) / (top - bottom);
  4652. var c = -(far + near) / (far - near);
  4653. var d = -2 * far * near / (far - near);
  4654. te[0] = x;
  4655. te[4] = 0;
  4656. te[8] = a;
  4657. te[12] = 0;
  4658. te[1] = 0;
  4659. te[5] = y;
  4660. te[9] = b;
  4661. te[13] = 0;
  4662. te[2] = 0;
  4663. te[6] = 0;
  4664. te[10] = c;
  4665. te[14] = d;
  4666. te[3] = 0;
  4667. te[7] = 0;
  4668. te[11] = -1;
  4669. te[15] = 0;
  4670. return this;
  4671. };
  4672. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  4673. var te = this.elements;
  4674. var w = 1.0 / (right - left);
  4675. var h = 1.0 / (top - bottom);
  4676. var p = 1.0 / (far - near);
  4677. var x = (right + left) * w;
  4678. var y = (top + bottom) * h;
  4679. var z = (far + near) * p;
  4680. te[0] = 2 * w;
  4681. te[4] = 0;
  4682. te[8] = 0;
  4683. te[12] = -x;
  4684. te[1] = 0;
  4685. te[5] = 2 * h;
  4686. te[9] = 0;
  4687. te[13] = -y;
  4688. te[2] = 0;
  4689. te[6] = 0;
  4690. te[10] = -2 * p;
  4691. te[14] = -z;
  4692. te[3] = 0;
  4693. te[7] = 0;
  4694. te[11] = 0;
  4695. te[15] = 1;
  4696. return this;
  4697. };
  4698. _proto.equals = function equals(matrix) {
  4699. var te = this.elements;
  4700. var me = matrix.elements;
  4701. for (var i = 0; i < 16; i++) {
  4702. if (te[i] !== me[i]) return false;
  4703. }
  4704. return true;
  4705. };
  4706. _proto.fromArray = function fromArray(array, offset) {
  4707. if (offset === void 0) {
  4708. offset = 0;
  4709. }
  4710. for (var i = 0; i < 16; i++) {
  4711. this.elements[i] = array[i + offset];
  4712. }
  4713. return this;
  4714. };
  4715. _proto.toArray = function toArray(array, offset) {
  4716. if (array === void 0) {
  4717. array = [];
  4718. }
  4719. if (offset === void 0) {
  4720. offset = 0;
  4721. }
  4722. var te = this.elements;
  4723. array[offset] = te[0];
  4724. array[offset + 1] = te[1];
  4725. array[offset + 2] = te[2];
  4726. array[offset + 3] = te[3];
  4727. array[offset + 4] = te[4];
  4728. array[offset + 5] = te[5];
  4729. array[offset + 6] = te[6];
  4730. array[offset + 7] = te[7];
  4731. array[offset + 8] = te[8];
  4732. array[offset + 9] = te[9];
  4733. array[offset + 10] = te[10];
  4734. array[offset + 11] = te[11];
  4735. array[offset + 12] = te[12];
  4736. array[offset + 13] = te[13];
  4737. array[offset + 14] = te[14];
  4738. array[offset + 15] = te[15];
  4739. return array;
  4740. };
  4741. return Matrix4;
  4742. }();
  4743. Matrix4.prototype.isMatrix4 = true;
  4744. var _v1$1 = /*@__PURE__*/new Vector3();
  4745. var _m1 = /*@__PURE__*/new Matrix4();
  4746. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4747. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4748. var _x = /*@__PURE__*/new Vector3();
  4749. var _y = /*@__PURE__*/new Vector3();
  4750. var _z = /*@__PURE__*/new Vector3();
  4751. var _matrix = /*@__PURE__*/new Matrix4();
  4752. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4753. var Euler = /*#__PURE__*/function () {
  4754. function Euler(x, y, z, order) {
  4755. if (x === void 0) {
  4756. x = 0;
  4757. }
  4758. if (y === void 0) {
  4759. y = 0;
  4760. }
  4761. if (z === void 0) {
  4762. z = 0;
  4763. }
  4764. if (order === void 0) {
  4765. order = Euler.DefaultOrder;
  4766. }
  4767. this._x = x;
  4768. this._y = y;
  4769. this._z = z;
  4770. this._order = order;
  4771. }
  4772. var _proto = Euler.prototype;
  4773. _proto.set = function set(x, y, z, order) {
  4774. this._x = x;
  4775. this._y = y;
  4776. this._z = z;
  4777. this._order = order || this._order;
  4778. this._onChangeCallback();
  4779. return this;
  4780. };
  4781. _proto.clone = function clone() {
  4782. return new this.constructor(this._x, this._y, this._z, this._order);
  4783. };
  4784. _proto.copy = function copy(euler) {
  4785. this._x = euler._x;
  4786. this._y = euler._y;
  4787. this._z = euler._z;
  4788. this._order = euler._order;
  4789. this._onChangeCallback();
  4790. return this;
  4791. };
  4792. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4793. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4794. var te = m.elements;
  4795. var m11 = te[0],
  4796. m12 = te[4],
  4797. m13 = te[8];
  4798. var m21 = te[1],
  4799. m22 = te[5],
  4800. m23 = te[9];
  4801. var m31 = te[2],
  4802. m32 = te[6],
  4803. m33 = te[10];
  4804. order = order || this._order;
  4805. switch (order) {
  4806. case 'XYZ':
  4807. this._y = Math.asin(clamp(m13, -1, 1));
  4808. if (Math.abs(m13) < 0.9999999) {
  4809. this._x = Math.atan2(-m23, m33);
  4810. this._z = Math.atan2(-m12, m11);
  4811. } else {
  4812. this._x = Math.atan2(m32, m22);
  4813. this._z = 0;
  4814. }
  4815. break;
  4816. case 'YXZ':
  4817. this._x = Math.asin(-clamp(m23, -1, 1));
  4818. if (Math.abs(m23) < 0.9999999) {
  4819. this._y = Math.atan2(m13, m33);
  4820. this._z = Math.atan2(m21, m22);
  4821. } else {
  4822. this._y = Math.atan2(-m31, m11);
  4823. this._z = 0;
  4824. }
  4825. break;
  4826. case 'ZXY':
  4827. this._x = Math.asin(clamp(m32, -1, 1));
  4828. if (Math.abs(m32) < 0.9999999) {
  4829. this._y = Math.atan2(-m31, m33);
  4830. this._z = Math.atan2(-m12, m22);
  4831. } else {
  4832. this._y = 0;
  4833. this._z = Math.atan2(m21, m11);
  4834. }
  4835. break;
  4836. case 'ZYX':
  4837. this._y = Math.asin(-clamp(m31, -1, 1));
  4838. if (Math.abs(m31) < 0.9999999) {
  4839. this._x = Math.atan2(m32, m33);
  4840. this._z = Math.atan2(m21, m11);
  4841. } else {
  4842. this._x = 0;
  4843. this._z = Math.atan2(-m12, m22);
  4844. }
  4845. break;
  4846. case 'YZX':
  4847. this._z = Math.asin(clamp(m21, -1, 1));
  4848. if (Math.abs(m21) < 0.9999999) {
  4849. this._x = Math.atan2(-m23, m22);
  4850. this._y = Math.atan2(-m31, m11);
  4851. } else {
  4852. this._x = 0;
  4853. this._y = Math.atan2(m13, m33);
  4854. }
  4855. break;
  4856. case 'XZY':
  4857. this._z = Math.asin(-clamp(m12, -1, 1));
  4858. if (Math.abs(m12) < 0.9999999) {
  4859. this._x = Math.atan2(m32, m22);
  4860. this._y = Math.atan2(m13, m11);
  4861. } else {
  4862. this._x = Math.atan2(-m23, m33);
  4863. this._y = 0;
  4864. }
  4865. break;
  4866. default:
  4867. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4868. }
  4869. this._order = order;
  4870. if (update !== false) this._onChangeCallback();
  4871. return this;
  4872. };
  4873. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4874. _matrix.makeRotationFromQuaternion(q);
  4875. return this.setFromRotationMatrix(_matrix, order, update);
  4876. };
  4877. _proto.setFromVector3 = function setFromVector3(v, order) {
  4878. return this.set(v.x, v.y, v.z, order || this._order);
  4879. };
  4880. _proto.reorder = function reorder(newOrder) {
  4881. // WARNING: this discards revolution information -bhouston
  4882. _quaternion$1.setFromEuler(this);
  4883. return this.setFromQuaternion(_quaternion$1, newOrder);
  4884. };
  4885. _proto.equals = function equals(euler) {
  4886. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4887. };
  4888. _proto.fromArray = function fromArray(array) {
  4889. this._x = array[0];
  4890. this._y = array[1];
  4891. this._z = array[2];
  4892. if (array[3] !== undefined) this._order = array[3];
  4893. this._onChangeCallback();
  4894. return this;
  4895. };
  4896. _proto.toArray = function toArray(array, offset) {
  4897. if (array === void 0) {
  4898. array = [];
  4899. }
  4900. if (offset === void 0) {
  4901. offset = 0;
  4902. }
  4903. array[offset] = this._x;
  4904. array[offset + 1] = this._y;
  4905. array[offset + 2] = this._z;
  4906. array[offset + 3] = this._order;
  4907. return array;
  4908. };
  4909. _proto.toVector3 = function toVector3(optionalResult) {
  4910. if (optionalResult) {
  4911. return optionalResult.set(this._x, this._y, this._z);
  4912. } else {
  4913. return new Vector3(this._x, this._y, this._z);
  4914. }
  4915. };
  4916. _proto._onChange = function _onChange(callback) {
  4917. this._onChangeCallback = callback;
  4918. return this;
  4919. };
  4920. _proto._onChangeCallback = function _onChangeCallback() {};
  4921. _createClass(Euler, [{
  4922. key: "x",
  4923. get: function get() {
  4924. return this._x;
  4925. },
  4926. set: function set(value) {
  4927. this._x = value;
  4928. this._onChangeCallback();
  4929. }
  4930. }, {
  4931. key: "y",
  4932. get: function get() {
  4933. return this._y;
  4934. },
  4935. set: function set(value) {
  4936. this._y = value;
  4937. this._onChangeCallback();
  4938. }
  4939. }, {
  4940. key: "z",
  4941. get: function get() {
  4942. return this._z;
  4943. },
  4944. set: function set(value) {
  4945. this._z = value;
  4946. this._onChangeCallback();
  4947. }
  4948. }, {
  4949. key: "order",
  4950. get: function get() {
  4951. return this._order;
  4952. },
  4953. set: function set(value) {
  4954. this._order = value;
  4955. this._onChangeCallback();
  4956. }
  4957. }]);
  4958. return Euler;
  4959. }();
  4960. Euler.prototype.isEuler = true;
  4961. Euler.DefaultOrder = 'XYZ';
  4962. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4963. var Layers = /*#__PURE__*/function () {
  4964. function Layers() {
  4965. this.mask = 1 | 0;
  4966. }
  4967. var _proto = Layers.prototype;
  4968. _proto.set = function set(channel) {
  4969. this.mask = 1 << channel | 0;
  4970. };
  4971. _proto.enable = function enable(channel) {
  4972. this.mask |= 1 << channel | 0;
  4973. };
  4974. _proto.enableAll = function enableAll() {
  4975. this.mask = 0xffffffff | 0;
  4976. };
  4977. _proto.toggle = function toggle(channel) {
  4978. this.mask ^= 1 << channel | 0;
  4979. };
  4980. _proto.disable = function disable(channel) {
  4981. this.mask &= ~(1 << channel | 0);
  4982. };
  4983. _proto.disableAll = function disableAll() {
  4984. this.mask = 0;
  4985. };
  4986. _proto.test = function test(layers) {
  4987. return (this.mask & layers.mask) !== 0;
  4988. };
  4989. return Layers;
  4990. }();
  4991. var _object3DId = 0;
  4992. var _v1$2 = new Vector3();
  4993. var _q1 = new Quaternion();
  4994. var _m1$1 = new Matrix4();
  4995. var _target = new Vector3();
  4996. var _position = new Vector3();
  4997. var _scale = new Vector3();
  4998. var _quaternion$2 = new Quaternion();
  4999. var _xAxis = new Vector3(1, 0, 0);
  5000. var _yAxis = new Vector3(0, 1, 0);
  5001. var _zAxis = new Vector3(0, 0, 1);
  5002. var _addedEvent = {
  5003. type: 'added'
  5004. };
  5005. var _removedEvent = {
  5006. type: 'removed'
  5007. };
  5008. function Object3D() {
  5009. Object.defineProperty(this, 'id', {
  5010. value: _object3DId++
  5011. });
  5012. this.uuid = MathUtils.generateUUID();
  5013. this.name = '';
  5014. this.type = 'Object3D';
  5015. this.parent = null;
  5016. this.children = [];
  5017. this.up = Object3D.DefaultUp.clone();
  5018. var position = new Vector3();
  5019. var rotation = new Euler();
  5020. var quaternion = new Quaternion();
  5021. var scale = new Vector3(1, 1, 1);
  5022. function onRotationChange() {
  5023. quaternion.setFromEuler(rotation, false);
  5024. }
  5025. function onQuaternionChange() {
  5026. rotation.setFromQuaternion(quaternion, undefined, false);
  5027. }
  5028. rotation._onChange(onRotationChange);
  5029. quaternion._onChange(onQuaternionChange);
  5030. Object.defineProperties(this, {
  5031. position: {
  5032. configurable: true,
  5033. enumerable: true,
  5034. value: position
  5035. },
  5036. rotation: {
  5037. configurable: true,
  5038. enumerable: true,
  5039. value: rotation
  5040. },
  5041. quaternion: {
  5042. configurable: true,
  5043. enumerable: true,
  5044. value: quaternion
  5045. },
  5046. scale: {
  5047. configurable: true,
  5048. enumerable: true,
  5049. value: scale
  5050. },
  5051. modelViewMatrix: {
  5052. value: new Matrix4()
  5053. },
  5054. normalMatrix: {
  5055. value: new Matrix3()
  5056. }
  5057. });
  5058. this.matrix = new Matrix4();
  5059. this.matrixWorld = new Matrix4();
  5060. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5061. this.matrixWorldNeedsUpdate = false;
  5062. this.layers = new Layers();
  5063. this.visible = true;
  5064. this.castShadow = false;
  5065. this.receiveShadow = false;
  5066. this.frustumCulled = true;
  5067. this.renderOrder = 0;
  5068. this.animations = [];
  5069. this.userData = {};
  5070. }
  5071. Object3D.DefaultUp = new Vector3(0, 1, 0);
  5072. Object3D.DefaultMatrixAutoUpdate = true;
  5073. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5074. constructor: Object3D,
  5075. isObject3D: true,
  5076. onBeforeRender: function onBeforeRender() {},
  5077. onAfterRender: function onAfterRender() {},
  5078. applyMatrix4: function applyMatrix4(matrix) {
  5079. if (this.matrixAutoUpdate) this.updateMatrix();
  5080. this.matrix.premultiply(matrix);
  5081. this.matrix.decompose(this.position, this.quaternion, this.scale);
  5082. },
  5083. applyQuaternion: function applyQuaternion(q) {
  5084. this.quaternion.premultiply(q);
  5085. return this;
  5086. },
  5087. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  5088. // assumes axis is normalized
  5089. this.quaternion.setFromAxisAngle(axis, angle);
  5090. },
  5091. setRotationFromEuler: function setRotationFromEuler(euler) {
  5092. this.quaternion.setFromEuler(euler, true);
  5093. },
  5094. setRotationFromMatrix: function setRotationFromMatrix(m) {
  5095. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5096. this.quaternion.setFromRotationMatrix(m);
  5097. },
  5098. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  5099. // assumes q is normalized
  5100. this.quaternion.copy(q);
  5101. },
  5102. rotateOnAxis: function rotateOnAxis(axis, angle) {
  5103. // rotate object on axis in object space
  5104. // axis is assumed to be normalized
  5105. _q1.setFromAxisAngle(axis, angle);
  5106. this.quaternion.multiply(_q1);
  5107. return this;
  5108. },
  5109. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  5110. // rotate object on axis in world space
  5111. // axis is assumed to be normalized
  5112. // method assumes no rotated parent
  5113. _q1.setFromAxisAngle(axis, angle);
  5114. this.quaternion.premultiply(_q1);
  5115. return this;
  5116. },
  5117. rotateX: function rotateX(angle) {
  5118. return this.rotateOnAxis(_xAxis, angle);
  5119. },
  5120. rotateY: function rotateY(angle) {
  5121. return this.rotateOnAxis(_yAxis, angle);
  5122. },
  5123. rotateZ: function rotateZ(angle) {
  5124. return this.rotateOnAxis(_zAxis, angle);
  5125. },
  5126. translateOnAxis: function translateOnAxis(axis, distance) {
  5127. // translate object by distance along axis in object space
  5128. // axis is assumed to be normalized
  5129. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  5130. this.position.add(_v1$2.multiplyScalar(distance));
  5131. return this;
  5132. },
  5133. translateX: function translateX(distance) {
  5134. return this.translateOnAxis(_xAxis, distance);
  5135. },
  5136. translateY: function translateY(distance) {
  5137. return this.translateOnAxis(_yAxis, distance);
  5138. },
  5139. translateZ: function translateZ(distance) {
  5140. return this.translateOnAxis(_zAxis, distance);
  5141. },
  5142. localToWorld: function localToWorld(vector) {
  5143. return vector.applyMatrix4(this.matrixWorld);
  5144. },
  5145. worldToLocal: function worldToLocal(vector) {
  5146. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  5147. },
  5148. lookAt: function lookAt(x, y, z) {
  5149. // This method does not support objects having non-uniformly-scaled parent(s)
  5150. if (x.isVector3) {
  5151. _target.copy(x);
  5152. } else {
  5153. _target.set(x, y, z);
  5154. }
  5155. var parent = this.parent;
  5156. this.updateWorldMatrix(true, false);
  5157. _position.setFromMatrixPosition(this.matrixWorld);
  5158. if (this.isCamera || this.isLight) {
  5159. _m1$1.lookAt(_position, _target, this.up);
  5160. } else {
  5161. _m1$1.lookAt(_target, _position, this.up);
  5162. }
  5163. this.quaternion.setFromRotationMatrix(_m1$1);
  5164. if (parent) {
  5165. _m1$1.extractRotation(parent.matrixWorld);
  5166. _q1.setFromRotationMatrix(_m1$1);
  5167. this.quaternion.premultiply(_q1.invert());
  5168. }
  5169. },
  5170. add: function add(object) {
  5171. if (arguments.length > 1) {
  5172. for (var i = 0; i < arguments.length; i++) {
  5173. this.add(arguments[i]);
  5174. }
  5175. return this;
  5176. }
  5177. if (object === this) {
  5178. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  5179. return this;
  5180. }
  5181. if (object && object.isObject3D) {
  5182. if (object.parent !== null) {
  5183. object.parent.remove(object);
  5184. }
  5185. object.parent = this;
  5186. this.children.push(object);
  5187. object.dispatchEvent(_addedEvent);
  5188. } else {
  5189. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  5190. }
  5191. return this;
  5192. },
  5193. remove: function remove(object) {
  5194. if (arguments.length > 1) {
  5195. for (var i = 0; i < arguments.length; i++) {
  5196. this.remove(arguments[i]);
  5197. }
  5198. return this;
  5199. }
  5200. var index = this.children.indexOf(object);
  5201. if (index !== -1) {
  5202. object.parent = null;
  5203. this.children.splice(index, 1);
  5204. object.dispatchEvent(_removedEvent);
  5205. }
  5206. return this;
  5207. },
  5208. clear: function clear() {
  5209. for (var i = 0; i < this.children.length; i++) {
  5210. var object = this.children[i];
  5211. object.parent = null;
  5212. object.dispatchEvent(_removedEvent);
  5213. }
  5214. this.children.length = 0;
  5215. return this;
  5216. },
  5217. attach: function attach(object) {
  5218. // adds object as a child of this, while maintaining the object's world transform
  5219. this.updateWorldMatrix(true, false);
  5220. _m1$1.copy(this.matrixWorld).invert();
  5221. if (object.parent !== null) {
  5222. object.parent.updateWorldMatrix(true, false);
  5223. _m1$1.multiply(object.parent.matrixWorld);
  5224. }
  5225. object.applyMatrix4(_m1$1);
  5226. this.add(object);
  5227. object.updateWorldMatrix(false, true);
  5228. return this;
  5229. },
  5230. getObjectById: function getObjectById(id) {
  5231. return this.getObjectByProperty('id', id);
  5232. },
  5233. getObjectByName: function getObjectByName(name) {
  5234. return this.getObjectByProperty('name', name);
  5235. },
  5236. getObjectByProperty: function getObjectByProperty(name, value) {
  5237. if (this[name] === value) return this;
  5238. for (var i = 0, l = this.children.length; i < l; i++) {
  5239. var child = this.children[i];
  5240. var object = child.getObjectByProperty(name, value);
  5241. if (object !== undefined) {
  5242. return object;
  5243. }
  5244. }
  5245. return undefined;
  5246. },
  5247. getWorldPosition: function getWorldPosition(target) {
  5248. if (target === undefined) {
  5249. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  5250. target = new Vector3();
  5251. }
  5252. this.updateWorldMatrix(true, false);
  5253. return target.setFromMatrixPosition(this.matrixWorld);
  5254. },
  5255. getWorldQuaternion: function getWorldQuaternion(target) {
  5256. if (target === undefined) {
  5257. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  5258. target = new Quaternion();
  5259. }
  5260. this.updateWorldMatrix(true, false);
  5261. this.matrixWorld.decompose(_position, target, _scale);
  5262. return target;
  5263. },
  5264. getWorldScale: function getWorldScale(target) {
  5265. if (target === undefined) {
  5266. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  5267. target = new Vector3();
  5268. }
  5269. this.updateWorldMatrix(true, false);
  5270. this.matrixWorld.decompose(_position, _quaternion$2, target);
  5271. return target;
  5272. },
  5273. getWorldDirection: function getWorldDirection(target) {
  5274. if (target === undefined) {
  5275. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  5276. target = new Vector3();
  5277. }
  5278. this.updateWorldMatrix(true, false);
  5279. var e = this.matrixWorld.elements;
  5280. return target.set(e[8], e[9], e[10]).normalize();
  5281. },
  5282. raycast: function raycast() {},
  5283. traverse: function traverse(callback) {
  5284. callback(this);
  5285. var children = this.children;
  5286. for (var i = 0, l = children.length; i < l; i++) {
  5287. children[i].traverse(callback);
  5288. }
  5289. },
  5290. traverseVisible: function traverseVisible(callback) {
  5291. if (this.visible === false) return;
  5292. callback(this);
  5293. var children = this.children;
  5294. for (var i = 0, l = children.length; i < l; i++) {
  5295. children[i].traverseVisible(callback);
  5296. }
  5297. },
  5298. traverseAncestors: function traverseAncestors(callback) {
  5299. var parent = this.parent;
  5300. if (parent !== null) {
  5301. callback(parent);
  5302. parent.traverseAncestors(callback);
  5303. }
  5304. },
  5305. updateMatrix: function updateMatrix() {
  5306. this.matrix.compose(this.position, this.quaternion, this.scale);
  5307. this.matrixWorldNeedsUpdate = true;
  5308. },
  5309. updateMatrixWorld: function updateMatrixWorld(force) {
  5310. if (this.matrixAutoUpdate) this.updateMatrix();
  5311. if (this.matrixWorldNeedsUpdate || force) {
  5312. if (this.parent === null) {
  5313. this.matrixWorld.copy(this.matrix);
  5314. } else {
  5315. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5316. }
  5317. this.matrixWorldNeedsUpdate = false;
  5318. force = true;
  5319. } // update children
  5320. var children = this.children;
  5321. for (var i = 0, l = children.length; i < l; i++) {
  5322. children[i].updateMatrixWorld(force);
  5323. }
  5324. },
  5325. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  5326. var parent = this.parent;
  5327. if (updateParents === true && parent !== null) {
  5328. parent.updateWorldMatrix(true, false);
  5329. }
  5330. if (this.matrixAutoUpdate) this.updateMatrix();
  5331. if (this.parent === null) {
  5332. this.matrixWorld.copy(this.matrix);
  5333. } else {
  5334. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5335. } // update children
  5336. if (updateChildren === true) {
  5337. var children = this.children;
  5338. for (var i = 0, l = children.length; i < l; i++) {
  5339. children[i].updateWorldMatrix(false, true);
  5340. }
  5341. }
  5342. },
  5343. toJSON: function toJSON(meta) {
  5344. // meta is a string when called from JSON.stringify
  5345. var isRootObject = meta === undefined || typeof meta === 'string';
  5346. var output = {}; // meta is a hash used to collect geometries, materials.
  5347. // not providing it implies that this is the root object
  5348. // being serialized.
  5349. if (isRootObject) {
  5350. // initialize meta obj
  5351. meta = {
  5352. geometries: {},
  5353. materials: {},
  5354. textures: {},
  5355. images: {},
  5356. shapes: {},
  5357. skeletons: {},
  5358. animations: {}
  5359. };
  5360. output.metadata = {
  5361. version: 4.5,
  5362. type: 'Object',
  5363. generator: 'Object3D.toJSON'
  5364. };
  5365. } // standard Object3D serialization
  5366. var object = {};
  5367. object.uuid = this.uuid;
  5368. object.type = this.type;
  5369. if (this.name !== '') object.name = this.name;
  5370. if (this.castShadow === true) object.castShadow = true;
  5371. if (this.receiveShadow === true) object.receiveShadow = true;
  5372. if (this.visible === false) object.visible = false;
  5373. if (this.frustumCulled === false) object.frustumCulled = false;
  5374. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  5375. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  5376. object.layers = this.layers.mask;
  5377. object.matrix = this.matrix.toArray();
  5378. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  5379. if (this.isInstancedMesh) {
  5380. object.type = 'InstancedMesh';
  5381. object.count = this.count;
  5382. object.instanceMatrix = this.instanceMatrix.toJSON();
  5383. } //
  5384. function serialize(library, element) {
  5385. if (library[element.uuid] === undefined) {
  5386. library[element.uuid] = element.toJSON(meta);
  5387. }
  5388. return element.uuid;
  5389. }
  5390. if (this.isMesh || this.isLine || this.isPoints) {
  5391. object.geometry = serialize(meta.geometries, this.geometry);
  5392. var parameters = this.geometry.parameters;
  5393. if (parameters !== undefined && parameters.shapes !== undefined) {
  5394. var shapes = parameters.shapes;
  5395. if (Array.isArray(shapes)) {
  5396. for (var i = 0, l = shapes.length; i < l; i++) {
  5397. var shape = shapes[i];
  5398. serialize(meta.shapes, shape);
  5399. }
  5400. } else {
  5401. serialize(meta.shapes, shapes);
  5402. }
  5403. }
  5404. }
  5405. if (this.isSkinnedMesh) {
  5406. object.bindMode = this.bindMode;
  5407. object.bindMatrix = this.bindMatrix.toArray();
  5408. if (this.skeleton !== undefined) {
  5409. serialize(meta.skeletons, this.skeleton);
  5410. object.skeleton = this.skeleton.uuid;
  5411. }
  5412. }
  5413. if (this.material !== undefined) {
  5414. if (Array.isArray(this.material)) {
  5415. var uuids = [];
  5416. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  5417. uuids.push(serialize(meta.materials, this.material[_i]));
  5418. }
  5419. object.material = uuids;
  5420. } else {
  5421. object.material = serialize(meta.materials, this.material);
  5422. }
  5423. } //
  5424. if (this.children.length > 0) {
  5425. object.children = [];
  5426. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  5427. object.children.push(this.children[_i2].toJSON(meta).object);
  5428. }
  5429. } //
  5430. if (this.animations.length > 0) {
  5431. object.animations = [];
  5432. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  5433. var animation = this.animations[_i3];
  5434. object.animations.push(serialize(meta.animations, animation));
  5435. }
  5436. }
  5437. if (isRootObject) {
  5438. var geometries = extractFromCache(meta.geometries);
  5439. var materials = extractFromCache(meta.materials);
  5440. var textures = extractFromCache(meta.textures);
  5441. var images = extractFromCache(meta.images);
  5442. var _shapes = extractFromCache(meta.shapes);
  5443. var skeletons = extractFromCache(meta.skeletons);
  5444. var animations = extractFromCache(meta.animations);
  5445. if (geometries.length > 0) output.geometries = geometries;
  5446. if (materials.length > 0) output.materials = materials;
  5447. if (textures.length > 0) output.textures = textures;
  5448. if (images.length > 0) output.images = images;
  5449. if (_shapes.length > 0) output.shapes = _shapes;
  5450. if (skeletons.length > 0) output.skeletons = skeletons;
  5451. if (animations.length > 0) output.animations = animations;
  5452. }
  5453. output.object = object;
  5454. return output; // extract data from the cache hash
  5455. // remove metadata on each item
  5456. // and return as array
  5457. function extractFromCache(cache) {
  5458. var values = [];
  5459. for (var key in cache) {
  5460. var data = cache[key];
  5461. delete data.metadata;
  5462. values.push(data);
  5463. }
  5464. return values;
  5465. }
  5466. },
  5467. clone: function clone(recursive) {
  5468. return new this.constructor().copy(this, recursive);
  5469. },
  5470. copy: function copy(source, recursive) {
  5471. if (recursive === void 0) {
  5472. recursive = true;
  5473. }
  5474. this.name = source.name;
  5475. this.up.copy(source.up);
  5476. this.position.copy(source.position);
  5477. this.rotation.order = source.rotation.order;
  5478. this.quaternion.copy(source.quaternion);
  5479. this.scale.copy(source.scale);
  5480. this.matrix.copy(source.matrix);
  5481. this.matrixWorld.copy(source.matrixWorld);
  5482. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5483. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5484. this.layers.mask = source.layers.mask;
  5485. this.visible = source.visible;
  5486. this.castShadow = source.castShadow;
  5487. this.receiveShadow = source.receiveShadow;
  5488. this.frustumCulled = source.frustumCulled;
  5489. this.renderOrder = source.renderOrder;
  5490. this.userData = JSON.parse(JSON.stringify(source.userData));
  5491. if (recursive === true) {
  5492. for (var i = 0; i < source.children.length; i++) {
  5493. var child = source.children[i];
  5494. this.add(child.clone());
  5495. }
  5496. }
  5497. return this;
  5498. }
  5499. });
  5500. var _vector1 = /*@__PURE__*/new Vector3();
  5501. var _vector2 = /*@__PURE__*/new Vector3();
  5502. var _normalMatrix = /*@__PURE__*/new Matrix3();
  5503. var Plane = /*#__PURE__*/function () {
  5504. function Plane(normal, constant) {
  5505. if (normal === void 0) {
  5506. normal = new Vector3(1, 0, 0);
  5507. }
  5508. if (constant === void 0) {
  5509. constant = 0;
  5510. }
  5511. // normal is assumed to be normalized
  5512. this.normal = normal;
  5513. this.constant = constant;
  5514. }
  5515. var _proto = Plane.prototype;
  5516. _proto.set = function set(normal, constant) {
  5517. this.normal.copy(normal);
  5518. this.constant = constant;
  5519. return this;
  5520. };
  5521. _proto.setComponents = function setComponents(x, y, z, w) {
  5522. this.normal.set(x, y, z);
  5523. this.constant = w;
  5524. return this;
  5525. };
  5526. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  5527. this.normal.copy(normal);
  5528. this.constant = -point.dot(this.normal);
  5529. return this;
  5530. };
  5531. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  5532. var normal = _vector1.subVectors(c, b).cross(_vector2.subVectors(a, b)).normalize(); // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  5533. this.setFromNormalAndCoplanarPoint(normal, a);
  5534. return this;
  5535. };
  5536. _proto.copy = function copy(plane) {
  5537. this.normal.copy(plane.normal);
  5538. this.constant = plane.constant;
  5539. return this;
  5540. };
  5541. _proto.normalize = function normalize() {
  5542. // Note: will lead to a divide by zero if the plane is invalid.
  5543. var inverseNormalLength = 1.0 / this.normal.length();
  5544. this.normal.multiplyScalar(inverseNormalLength);
  5545. this.constant *= inverseNormalLength;
  5546. return this;
  5547. };
  5548. _proto.negate = function negate() {
  5549. this.constant *= -1;
  5550. this.normal.negate();
  5551. return this;
  5552. };
  5553. _proto.distanceToPoint = function distanceToPoint(point) {
  5554. return this.normal.dot(point) + this.constant;
  5555. };
  5556. _proto.distanceToSphere = function distanceToSphere(sphere) {
  5557. return this.distanceToPoint(sphere.center) - sphere.radius;
  5558. };
  5559. _proto.projectPoint = function projectPoint(point, target) {
  5560. if (target === undefined) {
  5561. console.warn('THREE.Plane: .projectPoint() target is now required');
  5562. target = new Vector3();
  5563. }
  5564. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  5565. };
  5566. _proto.intersectLine = function intersectLine(line, target) {
  5567. if (target === undefined) {
  5568. console.warn('THREE.Plane: .intersectLine() target is now required');
  5569. target = new Vector3();
  5570. }
  5571. var direction = line.delta(_vector1);
  5572. var denominator = this.normal.dot(direction);
  5573. if (denominator === 0) {
  5574. // line is coplanar, return origin
  5575. if (this.distanceToPoint(line.start) === 0) {
  5576. return target.copy(line.start);
  5577. } // Unsure if this is the correct method to handle this case.
  5578. return undefined;
  5579. }
  5580. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  5581. if (t < 0 || t > 1) {
  5582. return undefined;
  5583. }
  5584. return target.copy(direction).multiplyScalar(t).add(line.start);
  5585. };
  5586. _proto.intersectsLine = function intersectsLine(line) {
  5587. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5588. var startSign = this.distanceToPoint(line.start);
  5589. var endSign = this.distanceToPoint(line.end);
  5590. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  5591. };
  5592. _proto.intersectsBox = function intersectsBox(box) {
  5593. return box.intersectsPlane(this);
  5594. };
  5595. _proto.intersectsSphere = function intersectsSphere(sphere) {
  5596. return sphere.intersectsPlane(this);
  5597. };
  5598. _proto.coplanarPoint = function coplanarPoint(target) {
  5599. if (target === undefined) {
  5600. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  5601. target = new Vector3();
  5602. }
  5603. return target.copy(this.normal).multiplyScalar(-this.constant);
  5604. };
  5605. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  5606. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  5607. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  5608. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  5609. this.constant = -referencePoint.dot(normal);
  5610. return this;
  5611. };
  5612. _proto.translate = function translate(offset) {
  5613. this.constant -= offset.dot(this.normal);
  5614. return this;
  5615. };
  5616. _proto.equals = function equals(plane) {
  5617. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  5618. };
  5619. _proto.clone = function clone() {
  5620. return new this.constructor().copy(this);
  5621. };
  5622. return Plane;
  5623. }();
  5624. Plane.prototype.isPlane = true;
  5625. var _v0$1 = /*@__PURE__*/new Vector3();
  5626. var _v1$3 = /*@__PURE__*/new Vector3();
  5627. var _v2$1 = /*@__PURE__*/new Vector3();
  5628. var _v3 = /*@__PURE__*/new Vector3();
  5629. var _vab = /*@__PURE__*/new Vector3();
  5630. var _vac = /*@__PURE__*/new Vector3();
  5631. var _vbc = /*@__PURE__*/new Vector3();
  5632. var _vap = /*@__PURE__*/new Vector3();
  5633. var _vbp = /*@__PURE__*/new Vector3();
  5634. var _vcp = /*@__PURE__*/new Vector3();
  5635. var Triangle = /*#__PURE__*/function () {
  5636. function Triangle(a, b, c) {
  5637. if (a === void 0) {
  5638. a = new Vector3();
  5639. }
  5640. if (b === void 0) {
  5641. b = new Vector3();
  5642. }
  5643. if (c === void 0) {
  5644. c = new Vector3();
  5645. }
  5646. this.a = a;
  5647. this.b = b;
  5648. this.c = c;
  5649. }
  5650. Triangle.getNormal = function getNormal(a, b, c, target) {
  5651. if (target === undefined) {
  5652. console.warn('THREE.Triangle: .getNormal() target is now required');
  5653. target = new Vector3();
  5654. }
  5655. target.subVectors(c, b);
  5656. _v0$1.subVectors(a, b);
  5657. target.cross(_v0$1);
  5658. var targetLengthSq = target.lengthSq();
  5659. if (targetLengthSq > 0) {
  5660. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  5661. }
  5662. return target.set(0, 0, 0);
  5663. } // static/instance method to calculate barycentric coordinates
  5664. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  5665. ;
  5666. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  5667. _v0$1.subVectors(c, a);
  5668. _v1$3.subVectors(b, a);
  5669. _v2$1.subVectors(point, a);
  5670. var dot00 = _v0$1.dot(_v0$1);
  5671. var dot01 = _v0$1.dot(_v1$3);
  5672. var dot02 = _v0$1.dot(_v2$1);
  5673. var dot11 = _v1$3.dot(_v1$3);
  5674. var dot12 = _v1$3.dot(_v2$1);
  5675. var denom = dot00 * dot11 - dot01 * dot01;
  5676. if (target === undefined) {
  5677. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  5678. target = new Vector3();
  5679. } // collinear or singular triangle
  5680. if (denom === 0) {
  5681. // arbitrary location outside of triangle?
  5682. // not sure if this is the best idea, maybe should be returning undefined
  5683. return target.set(-2, -1, -1);
  5684. }
  5685. var invDenom = 1 / denom;
  5686. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  5687. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  5688. return target.set(1 - u - v, v, u);
  5689. };
  5690. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  5691. this.getBarycoord(point, a, b, c, _v3);
  5692. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  5693. };
  5694. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  5695. this.getBarycoord(point, p1, p2, p3, _v3);
  5696. target.set(0, 0);
  5697. target.addScaledVector(uv1, _v3.x);
  5698. target.addScaledVector(uv2, _v3.y);
  5699. target.addScaledVector(uv3, _v3.z);
  5700. return target;
  5701. };
  5702. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  5703. _v0$1.subVectors(c, b);
  5704. _v1$3.subVectors(a, b); // strictly front facing
  5705. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  5706. };
  5707. var _proto = Triangle.prototype;
  5708. _proto.set = function set(a, b, c) {
  5709. this.a.copy(a);
  5710. this.b.copy(b);
  5711. this.c.copy(c);
  5712. return this;
  5713. };
  5714. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  5715. this.a.copy(points[i0]);
  5716. this.b.copy(points[i1]);
  5717. this.c.copy(points[i2]);
  5718. return this;
  5719. };
  5720. _proto.clone = function clone() {
  5721. return new this.constructor().copy(this);
  5722. };
  5723. _proto.copy = function copy(triangle) {
  5724. this.a.copy(triangle.a);
  5725. this.b.copy(triangle.b);
  5726. this.c.copy(triangle.c);
  5727. return this;
  5728. };
  5729. _proto.getArea = function getArea() {
  5730. _v0$1.subVectors(this.c, this.b);
  5731. _v1$3.subVectors(this.a, this.b);
  5732. return _v0$1.cross(_v1$3).length() * 0.5;
  5733. };
  5734. _proto.getMidpoint = function getMidpoint(target) {
  5735. if (target === undefined) {
  5736. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  5737. target = new Vector3();
  5738. }
  5739. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5740. };
  5741. _proto.getNormal = function getNormal(target) {
  5742. return Triangle.getNormal(this.a, this.b, this.c, target);
  5743. };
  5744. _proto.getPlane = function getPlane(target) {
  5745. if (target === undefined) {
  5746. console.warn('THREE.Triangle: .getPlane() target is now required');
  5747. target = new Plane();
  5748. }
  5749. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5750. };
  5751. _proto.getBarycoord = function getBarycoord(point, target) {
  5752. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5753. };
  5754. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5755. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5756. };
  5757. _proto.containsPoint = function containsPoint(point) {
  5758. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5759. };
  5760. _proto.isFrontFacing = function isFrontFacing(direction) {
  5761. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5762. };
  5763. _proto.intersectsBox = function intersectsBox(box) {
  5764. return box.intersectsTriangle(this);
  5765. };
  5766. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5767. if (target === undefined) {
  5768. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5769. target = new Vector3();
  5770. }
  5771. var a = this.a,
  5772. b = this.b,
  5773. c = this.c;
  5774. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5775. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5776. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5777. // basically, we're distinguishing which of the voronoi regions of the triangle
  5778. // the point lies in with the minimum amount of redundant computation.
  5779. _vab.subVectors(b, a);
  5780. _vac.subVectors(c, a);
  5781. _vap.subVectors(p, a);
  5782. var d1 = _vab.dot(_vap);
  5783. var d2 = _vac.dot(_vap);
  5784. if (d1 <= 0 && d2 <= 0) {
  5785. // vertex region of A; barycentric coords (1, 0, 0)
  5786. return target.copy(a);
  5787. }
  5788. _vbp.subVectors(p, b);
  5789. var d3 = _vab.dot(_vbp);
  5790. var d4 = _vac.dot(_vbp);
  5791. if (d3 >= 0 && d4 <= d3) {
  5792. // vertex region of B; barycentric coords (0, 1, 0)
  5793. return target.copy(b);
  5794. }
  5795. var vc = d1 * d4 - d3 * d2;
  5796. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5797. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5798. return target.copy(a).addScaledVector(_vab, v);
  5799. }
  5800. _vcp.subVectors(p, c);
  5801. var d5 = _vab.dot(_vcp);
  5802. var d6 = _vac.dot(_vcp);
  5803. if (d6 >= 0 && d5 <= d6) {
  5804. // vertex region of C; barycentric coords (0, 0, 1)
  5805. return target.copy(c);
  5806. }
  5807. var vb = d5 * d2 - d1 * d6;
  5808. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5809. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5810. return target.copy(a).addScaledVector(_vac, w);
  5811. }
  5812. var va = d3 * d6 - d5 * d4;
  5813. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5814. _vbc.subVectors(c, b);
  5815. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5816. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5817. } // face region
  5818. var denom = 1 / (va + vb + vc); // u = va * denom
  5819. v = vb * denom;
  5820. w = vc * denom;
  5821. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5822. };
  5823. _proto.equals = function equals(triangle) {
  5824. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5825. };
  5826. return Triangle;
  5827. }();
  5828. var materialId = 0;
  5829. function Material() {
  5830. Object.defineProperty(this, 'id', {
  5831. value: materialId++
  5832. });
  5833. this.uuid = MathUtils.generateUUID();
  5834. this.name = '';
  5835. this.type = 'Material';
  5836. this.fog = true;
  5837. this.blending = NormalBlending;
  5838. this.side = FrontSide;
  5839. this.vertexColors = false;
  5840. this.opacity = 1;
  5841. this.transparent = false;
  5842. this.blendSrc = SrcAlphaFactor;
  5843. this.blendDst = OneMinusSrcAlphaFactor;
  5844. this.blendEquation = AddEquation;
  5845. this.blendSrcAlpha = null;
  5846. this.blendDstAlpha = null;
  5847. this.blendEquationAlpha = null;
  5848. this.depthFunc = LessEqualDepth;
  5849. this.depthTest = true;
  5850. this.depthWrite = true;
  5851. this.stencilWriteMask = 0xff;
  5852. this.stencilFunc = AlwaysStencilFunc;
  5853. this.stencilRef = 0;
  5854. this.stencilFuncMask = 0xff;
  5855. this.stencilFail = KeepStencilOp;
  5856. this.stencilZFail = KeepStencilOp;
  5857. this.stencilZPass = KeepStencilOp;
  5858. this.stencilWrite = false;
  5859. this.clippingPlanes = null;
  5860. this.clipIntersection = false;
  5861. this.clipShadows = false;
  5862. this.shadowSide = null;
  5863. this.colorWrite = true;
  5864. this.precision = null; // override the renderer's default precision for this material
  5865. this.polygonOffset = false;
  5866. this.polygonOffsetFactor = 0;
  5867. this.polygonOffsetUnits = 0;
  5868. this.dithering = false;
  5869. this.alphaTest = 0;
  5870. this.premultipliedAlpha = false;
  5871. this.visible = true;
  5872. this.toneMapped = true;
  5873. this.userData = {};
  5874. this.version = 0;
  5875. }
  5876. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5877. constructor: Material,
  5878. isMaterial: true,
  5879. onBeforeCompile: function onBeforeCompile()
  5880. /* shaderobject, renderer */
  5881. {},
  5882. customProgramCacheKey: function customProgramCacheKey() {
  5883. return this.onBeforeCompile.toString();
  5884. },
  5885. setValues: function setValues(values) {
  5886. if (values === undefined) return;
  5887. for (var key in values) {
  5888. var newValue = values[key];
  5889. if (newValue === undefined) {
  5890. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  5891. continue;
  5892. } // for backward compatability if shading is set in the constructor
  5893. if (key === 'shading') {
  5894. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5895. this.flatShading = newValue === FlatShading ? true : false;
  5896. continue;
  5897. }
  5898. var currentValue = this[key];
  5899. if (currentValue === undefined) {
  5900. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  5901. continue;
  5902. }
  5903. if (currentValue && currentValue.isColor) {
  5904. currentValue.set(newValue);
  5905. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5906. currentValue.copy(newValue);
  5907. } else {
  5908. this[key] = newValue;
  5909. }
  5910. }
  5911. },
  5912. toJSON: function toJSON(meta) {
  5913. var isRoot = meta === undefined || typeof meta === 'string';
  5914. if (isRoot) {
  5915. meta = {
  5916. textures: {},
  5917. images: {}
  5918. };
  5919. }
  5920. var data = {
  5921. metadata: {
  5922. version: 4.5,
  5923. type: 'Material',
  5924. generator: 'Material.toJSON'
  5925. }
  5926. }; // standard Material serialization
  5927. data.uuid = this.uuid;
  5928. data.type = this.type;
  5929. if (this.name !== '') data.name = this.name;
  5930. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5931. if (this.roughness !== undefined) data.roughness = this.roughness;
  5932. if (this.metalness !== undefined) data.metalness = this.metalness;
  5933. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5934. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5935. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5936. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5937. if (this.shininess !== undefined) data.shininess = this.shininess;
  5938. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5939. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5940. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5941. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5942. }
  5943. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5944. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5945. }
  5946. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5947. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5948. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5949. }
  5950. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5951. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5952. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5953. if (this.lightMap && this.lightMap.isTexture) {
  5954. data.lightMap = this.lightMap.toJSON(meta).uuid;
  5955. data.lightMapIntensity = this.lightMapIntensity;
  5956. }
  5957. if (this.aoMap && this.aoMap.isTexture) {
  5958. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5959. data.aoMapIntensity = this.aoMapIntensity;
  5960. }
  5961. if (this.bumpMap && this.bumpMap.isTexture) {
  5962. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5963. data.bumpScale = this.bumpScale;
  5964. }
  5965. if (this.normalMap && this.normalMap.isTexture) {
  5966. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5967. data.normalMapType = this.normalMapType;
  5968. data.normalScale = this.normalScale.toArray();
  5969. }
  5970. if (this.displacementMap && this.displacementMap.isTexture) {
  5971. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5972. data.displacementScale = this.displacementScale;
  5973. data.displacementBias = this.displacementBias;
  5974. }
  5975. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5976. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5977. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5978. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5979. if (this.envMap && this.envMap.isTexture) {
  5980. data.envMap = this.envMap.toJSON(meta).uuid;
  5981. data.reflectivity = this.reflectivity; // Scale behind envMap
  5982. data.refractionRatio = this.refractionRatio;
  5983. if (this.combine !== undefined) data.combine = this.combine;
  5984. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5985. }
  5986. if (this.gradientMap && this.gradientMap.isTexture) {
  5987. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5988. }
  5989. if (this.size !== undefined) data.size = this.size;
  5990. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5991. if (this.blending !== NormalBlending) data.blending = this.blending;
  5992. if (this.side !== FrontSide) data.side = this.side;
  5993. if (this.vertexColors) data.vertexColors = true;
  5994. if (this.opacity < 1) data.opacity = this.opacity;
  5995. if (this.transparent === true) data.transparent = this.transparent;
  5996. data.depthFunc = this.depthFunc;
  5997. data.depthTest = this.depthTest;
  5998. data.depthWrite = this.depthWrite;
  5999. data.stencilWrite = this.stencilWrite;
  6000. data.stencilWriteMask = this.stencilWriteMask;
  6001. data.stencilFunc = this.stencilFunc;
  6002. data.stencilRef = this.stencilRef;
  6003. data.stencilFuncMask = this.stencilFuncMask;
  6004. data.stencilFail = this.stencilFail;
  6005. data.stencilZFail = this.stencilZFail;
  6006. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  6007. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  6008. if (this.polygonOffset === true) data.polygonOffset = true;
  6009. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  6010. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  6011. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  6012. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  6013. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  6014. if (this.scale !== undefined) data.scale = this.scale;
  6015. if (this.dithering === true) data.dithering = true;
  6016. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  6017. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  6018. if (this.wireframe === true) data.wireframe = this.wireframe;
  6019. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  6020. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  6021. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  6022. if (this.morphTargets === true) data.morphTargets = true;
  6023. if (this.morphNormals === true) data.morphNormals = true;
  6024. if (this.skinning === true) data.skinning = true;
  6025. if (this.flatShading === true) data.flatShading = this.flatShading;
  6026. if (this.visible === false) data.visible = false;
  6027. if (this.toneMapped === false) data.toneMapped = false;
  6028. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  6029. function extractFromCache(cache) {
  6030. var values = [];
  6031. for (var key in cache) {
  6032. var _data = cache[key];
  6033. delete _data.metadata;
  6034. values.push(_data);
  6035. }
  6036. return values;
  6037. }
  6038. if (isRoot) {
  6039. var textures = extractFromCache(meta.textures);
  6040. var images = extractFromCache(meta.images);
  6041. if (textures.length > 0) data.textures = textures;
  6042. if (images.length > 0) data.images = images;
  6043. }
  6044. return data;
  6045. },
  6046. clone: function clone() {
  6047. return new this.constructor().copy(this);
  6048. },
  6049. copy: function copy(source) {
  6050. this.name = source.name;
  6051. this.fog = source.fog;
  6052. this.blending = source.blending;
  6053. this.side = source.side;
  6054. this.vertexColors = source.vertexColors;
  6055. this.opacity = source.opacity;
  6056. this.transparent = source.transparent;
  6057. this.blendSrc = source.blendSrc;
  6058. this.blendDst = source.blendDst;
  6059. this.blendEquation = source.blendEquation;
  6060. this.blendSrcAlpha = source.blendSrcAlpha;
  6061. this.blendDstAlpha = source.blendDstAlpha;
  6062. this.blendEquationAlpha = source.blendEquationAlpha;
  6063. this.depthFunc = source.depthFunc;
  6064. this.depthTest = source.depthTest;
  6065. this.depthWrite = source.depthWrite;
  6066. this.stencilWriteMask = source.stencilWriteMask;
  6067. this.stencilFunc = source.stencilFunc;
  6068. this.stencilRef = source.stencilRef;
  6069. this.stencilFuncMask = source.stencilFuncMask;
  6070. this.stencilFail = source.stencilFail;
  6071. this.stencilZFail = source.stencilZFail;
  6072. this.stencilZPass = source.stencilZPass;
  6073. this.stencilWrite = source.stencilWrite;
  6074. var srcPlanes = source.clippingPlanes;
  6075. var dstPlanes = null;
  6076. if (srcPlanes !== null) {
  6077. var n = srcPlanes.length;
  6078. dstPlanes = new Array(n);
  6079. for (var i = 0; i !== n; ++i) {
  6080. dstPlanes[i] = srcPlanes[i].clone();
  6081. }
  6082. }
  6083. this.clippingPlanes = dstPlanes;
  6084. this.clipIntersection = source.clipIntersection;
  6085. this.clipShadows = source.clipShadows;
  6086. this.shadowSide = source.shadowSide;
  6087. this.colorWrite = source.colorWrite;
  6088. this.precision = source.precision;
  6089. this.polygonOffset = source.polygonOffset;
  6090. this.polygonOffsetFactor = source.polygonOffsetFactor;
  6091. this.polygonOffsetUnits = source.polygonOffsetUnits;
  6092. this.dithering = source.dithering;
  6093. this.alphaTest = source.alphaTest;
  6094. this.premultipliedAlpha = source.premultipliedAlpha;
  6095. this.visible = source.visible;
  6096. this.toneMapped = source.toneMapped;
  6097. this.userData = JSON.parse(JSON.stringify(source.userData));
  6098. return this;
  6099. },
  6100. dispose: function dispose() {
  6101. this.dispatchEvent({
  6102. type: 'dispose'
  6103. });
  6104. }
  6105. });
  6106. Object.defineProperty(Material.prototype, 'needsUpdate', {
  6107. set: function set(value) {
  6108. if (value === true) this.version++;
  6109. }
  6110. });
  6111. var _colorKeywords = {
  6112. 'aliceblue': 0xF0F8FF,
  6113. 'antiquewhite': 0xFAEBD7,
  6114. 'aqua': 0x00FFFF,
  6115. 'aquamarine': 0x7FFFD4,
  6116. 'azure': 0xF0FFFF,
  6117. 'beige': 0xF5F5DC,
  6118. 'bisque': 0xFFE4C4,
  6119. 'black': 0x000000,
  6120. 'blanchedalmond': 0xFFEBCD,
  6121. 'blue': 0x0000FF,
  6122. 'blueviolet': 0x8A2BE2,
  6123. 'brown': 0xA52A2A,
  6124. 'burlywood': 0xDEB887,
  6125. 'cadetblue': 0x5F9EA0,
  6126. 'chartreuse': 0x7FFF00,
  6127. 'chocolate': 0xD2691E,
  6128. 'coral': 0xFF7F50,
  6129. 'cornflowerblue': 0x6495ED,
  6130. 'cornsilk': 0xFFF8DC,
  6131. 'crimson': 0xDC143C,
  6132. 'cyan': 0x00FFFF,
  6133. 'darkblue': 0x00008B,
  6134. 'darkcyan': 0x008B8B,
  6135. 'darkgoldenrod': 0xB8860B,
  6136. 'darkgray': 0xA9A9A9,
  6137. 'darkgreen': 0x006400,
  6138. 'darkgrey': 0xA9A9A9,
  6139. 'darkkhaki': 0xBDB76B,
  6140. 'darkmagenta': 0x8B008B,
  6141. 'darkolivegreen': 0x556B2F,
  6142. 'darkorange': 0xFF8C00,
  6143. 'darkorchid': 0x9932CC,
  6144. 'darkred': 0x8B0000,
  6145. 'darksalmon': 0xE9967A,
  6146. 'darkseagreen': 0x8FBC8F,
  6147. 'darkslateblue': 0x483D8B,
  6148. 'darkslategray': 0x2F4F4F,
  6149. 'darkslategrey': 0x2F4F4F,
  6150. 'darkturquoise': 0x00CED1,
  6151. 'darkviolet': 0x9400D3,
  6152. 'deeppink': 0xFF1493,
  6153. 'deepskyblue': 0x00BFFF,
  6154. 'dimgray': 0x696969,
  6155. 'dimgrey': 0x696969,
  6156. 'dodgerblue': 0x1E90FF,
  6157. 'firebrick': 0xB22222,
  6158. 'floralwhite': 0xFFFAF0,
  6159. 'forestgreen': 0x228B22,
  6160. 'fuchsia': 0xFF00FF,
  6161. 'gainsboro': 0xDCDCDC,
  6162. 'ghostwhite': 0xF8F8FF,
  6163. 'gold': 0xFFD700,
  6164. 'goldenrod': 0xDAA520,
  6165. 'gray': 0x808080,
  6166. 'green': 0x008000,
  6167. 'greenyellow': 0xADFF2F,
  6168. 'grey': 0x808080,
  6169. 'honeydew': 0xF0FFF0,
  6170. 'hotpink': 0xFF69B4,
  6171. 'indianred': 0xCD5C5C,
  6172. 'indigo': 0x4B0082,
  6173. 'ivory': 0xFFFFF0,
  6174. 'khaki': 0xF0E68C,
  6175. 'lavender': 0xE6E6FA,
  6176. 'lavenderblush': 0xFFF0F5,
  6177. 'lawngreen': 0x7CFC00,
  6178. 'lemonchiffon': 0xFFFACD,
  6179. 'lightblue': 0xADD8E6,
  6180. 'lightcoral': 0xF08080,
  6181. 'lightcyan': 0xE0FFFF,
  6182. 'lightgoldenrodyellow': 0xFAFAD2,
  6183. 'lightgray': 0xD3D3D3,
  6184. 'lightgreen': 0x90EE90,
  6185. 'lightgrey': 0xD3D3D3,
  6186. 'lightpink': 0xFFB6C1,
  6187. 'lightsalmon': 0xFFA07A,
  6188. 'lightseagreen': 0x20B2AA,
  6189. 'lightskyblue': 0x87CEFA,
  6190. 'lightslategray': 0x778899,
  6191. 'lightslategrey': 0x778899,
  6192. 'lightsteelblue': 0xB0C4DE,
  6193. 'lightyellow': 0xFFFFE0,
  6194. 'lime': 0x00FF00,
  6195. 'limegreen': 0x32CD32,
  6196. 'linen': 0xFAF0E6,
  6197. 'magenta': 0xFF00FF,
  6198. 'maroon': 0x800000,
  6199. 'mediumaquamarine': 0x66CDAA,
  6200. 'mediumblue': 0x0000CD,
  6201. 'mediumorchid': 0xBA55D3,
  6202. 'mediumpurple': 0x9370DB,
  6203. 'mediumseagreen': 0x3CB371,
  6204. 'mediumslateblue': 0x7B68EE,
  6205. 'mediumspringgreen': 0x00FA9A,
  6206. 'mediumturquoise': 0x48D1CC,
  6207. 'mediumvioletred': 0xC71585,
  6208. 'midnightblue': 0x191970,
  6209. 'mintcream': 0xF5FFFA,
  6210. 'mistyrose': 0xFFE4E1,
  6211. 'moccasin': 0xFFE4B5,
  6212. 'navajowhite': 0xFFDEAD,
  6213. 'navy': 0x000080,
  6214. 'oldlace': 0xFDF5E6,
  6215. 'olive': 0x808000,
  6216. 'olivedrab': 0x6B8E23,
  6217. 'orange': 0xFFA500,
  6218. 'orangered': 0xFF4500,
  6219. 'orchid': 0xDA70D6,
  6220. 'palegoldenrod': 0xEEE8AA,
  6221. 'palegreen': 0x98FB98,
  6222. 'paleturquoise': 0xAFEEEE,
  6223. 'palevioletred': 0xDB7093,
  6224. 'papayawhip': 0xFFEFD5,
  6225. 'peachpuff': 0xFFDAB9,
  6226. 'peru': 0xCD853F,
  6227. 'pink': 0xFFC0CB,
  6228. 'plum': 0xDDA0DD,
  6229. 'powderblue': 0xB0E0E6,
  6230. 'purple': 0x800080,
  6231. 'rebeccapurple': 0x663399,
  6232. 'red': 0xFF0000,
  6233. 'rosybrown': 0xBC8F8F,
  6234. 'royalblue': 0x4169E1,
  6235. 'saddlebrown': 0x8B4513,
  6236. 'salmon': 0xFA8072,
  6237. 'sandybrown': 0xF4A460,
  6238. 'seagreen': 0x2E8B57,
  6239. 'seashell': 0xFFF5EE,
  6240. 'sienna': 0xA0522D,
  6241. 'silver': 0xC0C0C0,
  6242. 'skyblue': 0x87CEEB,
  6243. 'slateblue': 0x6A5ACD,
  6244. 'slategray': 0x708090,
  6245. 'slategrey': 0x708090,
  6246. 'snow': 0xFFFAFA,
  6247. 'springgreen': 0x00FF7F,
  6248. 'steelblue': 0x4682B4,
  6249. 'tan': 0xD2B48C,
  6250. 'teal': 0x008080,
  6251. 'thistle': 0xD8BFD8,
  6252. 'tomato': 0xFF6347,
  6253. 'turquoise': 0x40E0D0,
  6254. 'violet': 0xEE82EE,
  6255. 'wheat': 0xF5DEB3,
  6256. 'white': 0xFFFFFF,
  6257. 'whitesmoke': 0xF5F5F5,
  6258. 'yellow': 0xFFFF00,
  6259. 'yellowgreen': 0x9ACD32
  6260. };
  6261. var _hslA = {
  6262. h: 0,
  6263. s: 0,
  6264. l: 0
  6265. };
  6266. var _hslB = {
  6267. h: 0,
  6268. s: 0,
  6269. l: 0
  6270. };
  6271. function hue2rgb(p, q, t) {
  6272. if (t < 0) t += 1;
  6273. if (t > 1) t -= 1;
  6274. if (t < 1 / 6) return p + (q - p) * 6 * t;
  6275. if (t < 1 / 2) return q;
  6276. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  6277. return p;
  6278. }
  6279. function SRGBToLinear(c) {
  6280. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  6281. }
  6282. function LinearToSRGB(c) {
  6283. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  6284. }
  6285. var Color = /*#__PURE__*/function () {
  6286. function Color(r, g, b) {
  6287. if (g === undefined && b === undefined) {
  6288. // r is THREE.Color, hex or string
  6289. return this.set(r);
  6290. }
  6291. return this.setRGB(r, g, b);
  6292. }
  6293. var _proto = Color.prototype;
  6294. _proto.set = function set(value) {
  6295. if (value && value.isColor) {
  6296. this.copy(value);
  6297. } else if (typeof value === 'number') {
  6298. this.setHex(value);
  6299. } else if (typeof value === 'string') {
  6300. this.setStyle(value);
  6301. }
  6302. return this;
  6303. };
  6304. _proto.setScalar = function setScalar(scalar) {
  6305. this.r = scalar;
  6306. this.g = scalar;
  6307. this.b = scalar;
  6308. return this;
  6309. };
  6310. _proto.setHex = function setHex(hex) {
  6311. hex = Math.floor(hex);
  6312. this.r = (hex >> 16 & 255) / 255;
  6313. this.g = (hex >> 8 & 255) / 255;
  6314. this.b = (hex & 255) / 255;
  6315. return this;
  6316. };
  6317. _proto.setRGB = function setRGB(r, g, b) {
  6318. this.r = r;
  6319. this.g = g;
  6320. this.b = b;
  6321. return this;
  6322. };
  6323. _proto.setHSL = function setHSL(h, s, l) {
  6324. // h,s,l ranges are in 0.0 - 1.0
  6325. h = MathUtils.euclideanModulo(h, 1);
  6326. s = MathUtils.clamp(s, 0, 1);
  6327. l = MathUtils.clamp(l, 0, 1);
  6328. if (s === 0) {
  6329. this.r = this.g = this.b = l;
  6330. } else {
  6331. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  6332. var q = 2 * l - p;
  6333. this.r = hue2rgb(q, p, h + 1 / 3);
  6334. this.g = hue2rgb(q, p, h);
  6335. this.b = hue2rgb(q, p, h - 1 / 3);
  6336. }
  6337. return this;
  6338. };
  6339. _proto.setStyle = function setStyle(style) {
  6340. function handleAlpha(string) {
  6341. if (string === undefined) return;
  6342. if (parseFloat(string) < 1) {
  6343. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  6344. }
  6345. }
  6346. var m;
  6347. if (m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style)) {
  6348. // rgb / hsl
  6349. var color;
  6350. var name = m[1];
  6351. var components = m[2];
  6352. switch (name) {
  6353. case 'rgb':
  6354. case 'rgba':
  6355. if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6356. // rgb(255,0,0) rgba(255,0,0,0.5)
  6357. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  6358. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  6359. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  6360. handleAlpha(color[4]);
  6361. return this;
  6362. }
  6363. if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6364. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6365. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  6366. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  6367. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  6368. handleAlpha(color[4]);
  6369. return this;
  6370. }
  6371. break;
  6372. case 'hsl':
  6373. case 'hsla':
  6374. if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6375. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6376. var h = parseFloat(color[1]) / 360;
  6377. var s = parseInt(color[2], 10) / 100;
  6378. var l = parseInt(color[3], 10) / 100;
  6379. handleAlpha(color[4]);
  6380. return this.setHSL(h, s, l);
  6381. }
  6382. break;
  6383. }
  6384. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  6385. // hex color
  6386. var hex = m[1];
  6387. var size = hex.length;
  6388. if (size === 3) {
  6389. // #ff0
  6390. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  6391. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  6392. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  6393. return this;
  6394. } else if (size === 6) {
  6395. // #ff0000
  6396. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  6397. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  6398. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  6399. return this;
  6400. }
  6401. }
  6402. if (style && style.length > 0) {
  6403. return this.setColorName(style);
  6404. }
  6405. return this;
  6406. };
  6407. _proto.setColorName = function setColorName(style) {
  6408. // color keywords
  6409. var hex = _colorKeywords[style];
  6410. if (hex !== undefined) {
  6411. // red
  6412. this.setHex(hex);
  6413. } else {
  6414. // unknown color
  6415. console.warn('THREE.Color: Unknown color ' + style);
  6416. }
  6417. return this;
  6418. };
  6419. _proto.clone = function clone() {
  6420. return new this.constructor(this.r, this.g, this.b);
  6421. };
  6422. _proto.copy = function copy(color) {
  6423. this.r = color.r;
  6424. this.g = color.g;
  6425. this.b = color.b;
  6426. return this;
  6427. };
  6428. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  6429. if (gammaFactor === void 0) {
  6430. gammaFactor = 2.0;
  6431. }
  6432. this.r = Math.pow(color.r, gammaFactor);
  6433. this.g = Math.pow(color.g, gammaFactor);
  6434. this.b = Math.pow(color.b, gammaFactor);
  6435. return this;
  6436. };
  6437. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  6438. if (gammaFactor === void 0) {
  6439. gammaFactor = 2.0;
  6440. }
  6441. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  6442. this.r = Math.pow(color.r, safeInverse);
  6443. this.g = Math.pow(color.g, safeInverse);
  6444. this.b = Math.pow(color.b, safeInverse);
  6445. return this;
  6446. };
  6447. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  6448. this.copyGammaToLinear(this, gammaFactor);
  6449. return this;
  6450. };
  6451. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  6452. this.copyLinearToGamma(this, gammaFactor);
  6453. return this;
  6454. };
  6455. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  6456. this.r = SRGBToLinear(color.r);
  6457. this.g = SRGBToLinear(color.g);
  6458. this.b = SRGBToLinear(color.b);
  6459. return this;
  6460. };
  6461. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  6462. this.r = LinearToSRGB(color.r);
  6463. this.g = LinearToSRGB(color.g);
  6464. this.b = LinearToSRGB(color.b);
  6465. return this;
  6466. };
  6467. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  6468. this.copySRGBToLinear(this);
  6469. return this;
  6470. };
  6471. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  6472. this.copyLinearToSRGB(this);
  6473. return this;
  6474. };
  6475. _proto.getHex = function getHex() {
  6476. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  6477. };
  6478. _proto.getHexString = function getHexString() {
  6479. return ('000000' + this.getHex().toString(16)).slice(-6);
  6480. };
  6481. _proto.getHSL = function getHSL(target) {
  6482. // h,s,l ranges are in 0.0 - 1.0
  6483. if (target === undefined) {
  6484. console.warn('THREE.Color: .getHSL() target is now required');
  6485. target = {
  6486. h: 0,
  6487. s: 0,
  6488. l: 0
  6489. };
  6490. }
  6491. var r = this.r,
  6492. g = this.g,
  6493. b = this.b;
  6494. var max = Math.max(r, g, b);
  6495. var min = Math.min(r, g, b);
  6496. var hue, saturation;
  6497. var lightness = (min + max) / 2.0;
  6498. if (min === max) {
  6499. hue = 0;
  6500. saturation = 0;
  6501. } else {
  6502. var delta = max - min;
  6503. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  6504. switch (max) {
  6505. case r:
  6506. hue = (g - b) / delta + (g < b ? 6 : 0);
  6507. break;
  6508. case g:
  6509. hue = (b - r) / delta + 2;
  6510. break;
  6511. case b:
  6512. hue = (r - g) / delta + 4;
  6513. break;
  6514. }
  6515. hue /= 6;
  6516. }
  6517. target.h = hue;
  6518. target.s = saturation;
  6519. target.l = lightness;
  6520. return target;
  6521. };
  6522. _proto.getStyle = function getStyle() {
  6523. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  6524. };
  6525. _proto.offsetHSL = function offsetHSL(h, s, l) {
  6526. this.getHSL(_hslA);
  6527. _hslA.h += h;
  6528. _hslA.s += s;
  6529. _hslA.l += l;
  6530. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  6531. return this;
  6532. };
  6533. _proto.add = function add(color) {
  6534. this.r += color.r;
  6535. this.g += color.g;
  6536. this.b += color.b;
  6537. return this;
  6538. };
  6539. _proto.addColors = function addColors(color1, color2) {
  6540. this.r = color1.r + color2.r;
  6541. this.g = color1.g + color2.g;
  6542. this.b = color1.b + color2.b;
  6543. return this;
  6544. };
  6545. _proto.addScalar = function addScalar(s) {
  6546. this.r += s;
  6547. this.g += s;
  6548. this.b += s;
  6549. return this;
  6550. };
  6551. _proto.sub = function sub(color) {
  6552. this.r = Math.max(0, this.r - color.r);
  6553. this.g = Math.max(0, this.g - color.g);
  6554. this.b = Math.max(0, this.b - color.b);
  6555. return this;
  6556. };
  6557. _proto.multiply = function multiply(color) {
  6558. this.r *= color.r;
  6559. this.g *= color.g;
  6560. this.b *= color.b;
  6561. return this;
  6562. };
  6563. _proto.multiplyScalar = function multiplyScalar(s) {
  6564. this.r *= s;
  6565. this.g *= s;
  6566. this.b *= s;
  6567. return this;
  6568. };
  6569. _proto.lerp = function lerp(color, alpha) {
  6570. this.r += (color.r - this.r) * alpha;
  6571. this.g += (color.g - this.g) * alpha;
  6572. this.b += (color.b - this.b) * alpha;
  6573. return this;
  6574. };
  6575. _proto.lerpColors = function lerpColors(color1, color2, alpha) {
  6576. this.r = color1.r + (color2.r - color1.r) * alpha;
  6577. this.g = color1.g + (color2.g - color1.g) * alpha;
  6578. this.b = color1.b + (color2.b - color1.b) * alpha;
  6579. return this;
  6580. };
  6581. _proto.lerpHSL = function lerpHSL(color, alpha) {
  6582. this.getHSL(_hslA);
  6583. color.getHSL(_hslB);
  6584. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  6585. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  6586. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  6587. this.setHSL(h, s, l);
  6588. return this;
  6589. };
  6590. _proto.equals = function equals(c) {
  6591. return c.r === this.r && c.g === this.g && c.b === this.b;
  6592. };
  6593. _proto.fromArray = function fromArray(array, offset) {
  6594. if (offset === void 0) {
  6595. offset = 0;
  6596. }
  6597. this.r = array[offset];
  6598. this.g = array[offset + 1];
  6599. this.b = array[offset + 2];
  6600. return this;
  6601. };
  6602. _proto.toArray = function toArray(array, offset) {
  6603. if (array === void 0) {
  6604. array = [];
  6605. }
  6606. if (offset === void 0) {
  6607. offset = 0;
  6608. }
  6609. array[offset] = this.r;
  6610. array[offset + 1] = this.g;
  6611. array[offset + 2] = this.b;
  6612. return array;
  6613. };
  6614. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  6615. this.r = attribute.getX(index);
  6616. this.g = attribute.getY(index);
  6617. this.b = attribute.getZ(index);
  6618. if (attribute.normalized === true) {
  6619. // assuming Uint8Array
  6620. this.r /= 255;
  6621. this.g /= 255;
  6622. this.b /= 255;
  6623. }
  6624. return this;
  6625. };
  6626. _proto.toJSON = function toJSON() {
  6627. return this.getHex();
  6628. };
  6629. return Color;
  6630. }();
  6631. Color.NAMES = _colorKeywords;
  6632. Color.prototype.isColor = true;
  6633. Color.prototype.r = 1;
  6634. Color.prototype.g = 1;
  6635. Color.prototype.b = 1;
  6636. /**
  6637. * parameters = {
  6638. * color: <hex>,
  6639. * opacity: <float>,
  6640. * map: new THREE.Texture( <Image> ),
  6641. *
  6642. * lightMap: new THREE.Texture( <Image> ),
  6643. * lightMapIntensity: <float>
  6644. *
  6645. * aoMap: new THREE.Texture( <Image> ),
  6646. * aoMapIntensity: <float>
  6647. *
  6648. * specularMap: new THREE.Texture( <Image> ),
  6649. *
  6650. * alphaMap: new THREE.Texture( <Image> ),
  6651. *
  6652. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  6653. * combine: THREE.Multiply,
  6654. * reflectivity: <float>,
  6655. * refractionRatio: <float>,
  6656. *
  6657. * depthTest: <bool>,
  6658. * depthWrite: <bool>,
  6659. *
  6660. * wireframe: <boolean>,
  6661. * wireframeLinewidth: <float>,
  6662. *
  6663. * skinning: <bool>,
  6664. * morphTargets: <bool>
  6665. * }
  6666. */
  6667. var MeshBasicMaterial = /*#__PURE__*/function (_Material) {
  6668. _inheritsLoose(MeshBasicMaterial, _Material);
  6669. function MeshBasicMaterial(parameters) {
  6670. var _this;
  6671. _this = _Material.call(this) || this;
  6672. _this.type = 'MeshBasicMaterial';
  6673. _this.color = new Color(0xffffff); // emissive
  6674. _this.map = null;
  6675. _this.lightMap = null;
  6676. _this.lightMapIntensity = 1.0;
  6677. _this.aoMap = null;
  6678. _this.aoMapIntensity = 1.0;
  6679. _this.specularMap = null;
  6680. _this.alphaMap = null;
  6681. _this.envMap = null;
  6682. _this.combine = MultiplyOperation;
  6683. _this.reflectivity = 1;
  6684. _this.refractionRatio = 0.98;
  6685. _this.wireframe = false;
  6686. _this.wireframeLinewidth = 1;
  6687. _this.wireframeLinecap = 'round';
  6688. _this.wireframeLinejoin = 'round';
  6689. _this.skinning = false;
  6690. _this.morphTargets = false;
  6691. _this.setValues(parameters);
  6692. return _this;
  6693. }
  6694. var _proto = MeshBasicMaterial.prototype;
  6695. _proto.copy = function copy(source) {
  6696. _Material.prototype.copy.call(this, source);
  6697. this.color.copy(source.color);
  6698. this.map = source.map;
  6699. this.lightMap = source.lightMap;
  6700. this.lightMapIntensity = source.lightMapIntensity;
  6701. this.aoMap = source.aoMap;
  6702. this.aoMapIntensity = source.aoMapIntensity;
  6703. this.specularMap = source.specularMap;
  6704. this.alphaMap = source.alphaMap;
  6705. this.envMap = source.envMap;
  6706. this.combine = source.combine;
  6707. this.reflectivity = source.reflectivity;
  6708. this.refractionRatio = source.refractionRatio;
  6709. this.wireframe = source.wireframe;
  6710. this.wireframeLinewidth = source.wireframeLinewidth;
  6711. this.wireframeLinecap = source.wireframeLinecap;
  6712. this.wireframeLinejoin = source.wireframeLinejoin;
  6713. this.skinning = source.skinning;
  6714. this.morphTargets = source.morphTargets;
  6715. return this;
  6716. };
  6717. return MeshBasicMaterial;
  6718. }(Material);
  6719. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  6720. var _vector$3 = new Vector3();
  6721. var _vector2$1 = new Vector2();
  6722. function BufferAttribute(array, itemSize, normalized) {
  6723. if (Array.isArray(array)) {
  6724. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6725. }
  6726. this.name = '';
  6727. this.array = array;
  6728. this.itemSize = itemSize;
  6729. this.count = array !== undefined ? array.length / itemSize : 0;
  6730. this.normalized = normalized === true;
  6731. this.usage = StaticDrawUsage;
  6732. this.updateRange = {
  6733. offset: 0,
  6734. count: -1
  6735. };
  6736. this.version = 0;
  6737. }
  6738. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6739. set: function set(value) {
  6740. if (value === true) this.version++;
  6741. }
  6742. });
  6743. Object.assign(BufferAttribute.prototype, {
  6744. isBufferAttribute: true,
  6745. onUploadCallback: function onUploadCallback() {},
  6746. setUsage: function setUsage(value) {
  6747. this.usage = value;
  6748. return this;
  6749. },
  6750. copy: function copy(source) {
  6751. this.name = source.name;
  6752. this.array = new source.array.constructor(source.array);
  6753. this.itemSize = source.itemSize;
  6754. this.count = source.count;
  6755. this.normalized = source.normalized;
  6756. this.usage = source.usage;
  6757. return this;
  6758. },
  6759. copyAt: function copyAt(index1, attribute, index2) {
  6760. index1 *= this.itemSize;
  6761. index2 *= attribute.itemSize;
  6762. for (var i = 0, l = this.itemSize; i < l; i++) {
  6763. this.array[index1 + i] = attribute.array[index2 + i];
  6764. }
  6765. return this;
  6766. },
  6767. copyArray: function copyArray(array) {
  6768. this.array.set(array);
  6769. return this;
  6770. },
  6771. copyColorsArray: function copyColorsArray(colors) {
  6772. var array = this.array;
  6773. var offset = 0;
  6774. for (var i = 0, l = colors.length; i < l; i++) {
  6775. var color = colors[i];
  6776. if (color === undefined) {
  6777. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6778. color = new Color();
  6779. }
  6780. array[offset++] = color.r;
  6781. array[offset++] = color.g;
  6782. array[offset++] = color.b;
  6783. }
  6784. return this;
  6785. },
  6786. copyVector2sArray: function copyVector2sArray(vectors) {
  6787. var array = this.array;
  6788. var offset = 0;
  6789. for (var i = 0, l = vectors.length; i < l; i++) {
  6790. var vector = vectors[i];
  6791. if (vector === undefined) {
  6792. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6793. vector = new Vector2();
  6794. }
  6795. array[offset++] = vector.x;
  6796. array[offset++] = vector.y;
  6797. }
  6798. return this;
  6799. },
  6800. copyVector3sArray: function copyVector3sArray(vectors) {
  6801. var array = this.array;
  6802. var offset = 0;
  6803. for (var i = 0, l = vectors.length; i < l; i++) {
  6804. var vector = vectors[i];
  6805. if (vector === undefined) {
  6806. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6807. vector = new Vector3();
  6808. }
  6809. array[offset++] = vector.x;
  6810. array[offset++] = vector.y;
  6811. array[offset++] = vector.z;
  6812. }
  6813. return this;
  6814. },
  6815. copyVector4sArray: function copyVector4sArray(vectors) {
  6816. var array = this.array;
  6817. var offset = 0;
  6818. for (var i = 0, l = vectors.length; i < l; i++) {
  6819. var vector = vectors[i];
  6820. if (vector === undefined) {
  6821. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6822. vector = new Vector4();
  6823. }
  6824. array[offset++] = vector.x;
  6825. array[offset++] = vector.y;
  6826. array[offset++] = vector.z;
  6827. array[offset++] = vector.w;
  6828. }
  6829. return this;
  6830. },
  6831. applyMatrix3: function applyMatrix3(m) {
  6832. if (this.itemSize === 2) {
  6833. for (var i = 0, l = this.count; i < l; i++) {
  6834. _vector2$1.fromBufferAttribute(this, i);
  6835. _vector2$1.applyMatrix3(m);
  6836. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6837. }
  6838. } else if (this.itemSize === 3) {
  6839. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6840. _vector$3.fromBufferAttribute(this, _i);
  6841. _vector$3.applyMatrix3(m);
  6842. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6843. }
  6844. }
  6845. return this;
  6846. },
  6847. applyMatrix4: function applyMatrix4(m) {
  6848. for (var i = 0, l = this.count; i < l; i++) {
  6849. _vector$3.x = this.getX(i);
  6850. _vector$3.y = this.getY(i);
  6851. _vector$3.z = this.getZ(i);
  6852. _vector$3.applyMatrix4(m);
  6853. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6854. }
  6855. return this;
  6856. },
  6857. applyNormalMatrix: function applyNormalMatrix(m) {
  6858. for (var i = 0, l = this.count; i < l; i++) {
  6859. _vector$3.x = this.getX(i);
  6860. _vector$3.y = this.getY(i);
  6861. _vector$3.z = this.getZ(i);
  6862. _vector$3.applyNormalMatrix(m);
  6863. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6864. }
  6865. return this;
  6866. },
  6867. transformDirection: function transformDirection(m) {
  6868. for (var i = 0, l = this.count; i < l; i++) {
  6869. _vector$3.x = this.getX(i);
  6870. _vector$3.y = this.getY(i);
  6871. _vector$3.z = this.getZ(i);
  6872. _vector$3.transformDirection(m);
  6873. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6874. }
  6875. return this;
  6876. },
  6877. set: function set(value, offset) {
  6878. if (offset === void 0) {
  6879. offset = 0;
  6880. }
  6881. this.array.set(value, offset);
  6882. return this;
  6883. },
  6884. getX: function getX(index) {
  6885. return this.array[index * this.itemSize];
  6886. },
  6887. setX: function setX(index, x) {
  6888. this.array[index * this.itemSize] = x;
  6889. return this;
  6890. },
  6891. getY: function getY(index) {
  6892. return this.array[index * this.itemSize + 1];
  6893. },
  6894. setY: function setY(index, y) {
  6895. this.array[index * this.itemSize + 1] = y;
  6896. return this;
  6897. },
  6898. getZ: function getZ(index) {
  6899. return this.array[index * this.itemSize + 2];
  6900. },
  6901. setZ: function setZ(index, z) {
  6902. this.array[index * this.itemSize + 2] = z;
  6903. return this;
  6904. },
  6905. getW: function getW(index) {
  6906. return this.array[index * this.itemSize + 3];
  6907. },
  6908. setW: function setW(index, w) {
  6909. this.array[index * this.itemSize + 3] = w;
  6910. return this;
  6911. },
  6912. setXY: function setXY(index, x, y) {
  6913. index *= this.itemSize;
  6914. this.array[index + 0] = x;
  6915. this.array[index + 1] = y;
  6916. return this;
  6917. },
  6918. setXYZ: function setXYZ(index, x, y, z) {
  6919. index *= this.itemSize;
  6920. this.array[index + 0] = x;
  6921. this.array[index + 1] = y;
  6922. this.array[index + 2] = z;
  6923. return this;
  6924. },
  6925. setXYZW: function setXYZW(index, x, y, z, w) {
  6926. index *= this.itemSize;
  6927. this.array[index + 0] = x;
  6928. this.array[index + 1] = y;
  6929. this.array[index + 2] = z;
  6930. this.array[index + 3] = w;
  6931. return this;
  6932. },
  6933. onUpload: function onUpload(callback) {
  6934. this.onUploadCallback = callback;
  6935. return this;
  6936. },
  6937. clone: function clone() {
  6938. return new this.constructor(this.array, this.itemSize).copy(this);
  6939. },
  6940. toJSON: function toJSON() {
  6941. return {
  6942. itemSize: this.itemSize,
  6943. type: this.array.constructor.name,
  6944. array: Array.prototype.slice.call(this.array),
  6945. normalized: this.normalized
  6946. };
  6947. }
  6948. }); //
  6949. function Int8BufferAttribute(array, itemSize, normalized) {
  6950. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6951. }
  6952. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6953. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6954. function Uint8BufferAttribute(array, itemSize, normalized) {
  6955. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6956. }
  6957. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6958. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6959. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6960. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6961. }
  6962. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6963. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6964. function Int16BufferAttribute(array, itemSize, normalized) {
  6965. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6966. }
  6967. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6968. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6969. function Uint16BufferAttribute(array, itemSize, normalized) {
  6970. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6971. }
  6972. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6973. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6974. function Int32BufferAttribute(array, itemSize, normalized) {
  6975. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6976. }
  6977. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6978. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6979. function Uint32BufferAttribute(array, itemSize, normalized) {
  6980. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6981. }
  6982. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6983. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6984. function Float16BufferAttribute(array, itemSize, normalized) {
  6985. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6986. }
  6987. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6988. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6989. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6990. function Float32BufferAttribute(array, itemSize, normalized) {
  6991. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6992. }
  6993. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6994. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6995. function Float64BufferAttribute(array, itemSize, normalized) {
  6996. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6997. }
  6998. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6999. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  7000. function arrayMax(array) {
  7001. if (array.length === 0) return -Infinity;
  7002. var max = array[0];
  7003. for (var i = 1, l = array.length; i < l; ++i) {
  7004. if (array[i] > max) max = array[i];
  7005. }
  7006. return max;
  7007. }
  7008. var TYPED_ARRAYS = {
  7009. Int8Array: Int8Array,
  7010. Uint8Array: Uint8Array,
  7011. // Workaround for IE11 pre KB2929437. See #11440
  7012. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  7013. Int16Array: Int16Array,
  7014. Uint16Array: Uint16Array,
  7015. Int32Array: Int32Array,
  7016. Uint32Array: Uint32Array,
  7017. Float32Array: Float32Array,
  7018. Float64Array: Float64Array
  7019. };
  7020. function getTypedArray(type, buffer) {
  7021. return new TYPED_ARRAYS[type](buffer);
  7022. }
  7023. var _id = 0;
  7024. var _m1$2 = new Matrix4();
  7025. var _obj = new Object3D();
  7026. var _offset = new Vector3();
  7027. var _box$2 = new Box3();
  7028. var _boxMorphTargets = new Box3();
  7029. var _vector$4 = new Vector3();
  7030. function BufferGeometry() {
  7031. Object.defineProperty(this, 'id', {
  7032. value: _id++
  7033. });
  7034. this.uuid = MathUtils.generateUUID();
  7035. this.name = '';
  7036. this.type = 'BufferGeometry';
  7037. this.index = null;
  7038. this.attributes = {};
  7039. this.morphAttributes = {};
  7040. this.morphTargetsRelative = false;
  7041. this.groups = [];
  7042. this.boundingBox = null;
  7043. this.boundingSphere = null;
  7044. this.drawRange = {
  7045. start: 0,
  7046. count: Infinity
  7047. };
  7048. this.userData = {};
  7049. }
  7050. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  7051. constructor: BufferGeometry,
  7052. isBufferGeometry: true,
  7053. getIndex: function getIndex() {
  7054. return this.index;
  7055. },
  7056. setIndex: function setIndex(index) {
  7057. if (Array.isArray(index)) {
  7058. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  7059. } else {
  7060. this.index = index;
  7061. }
  7062. return this;
  7063. },
  7064. getAttribute: function getAttribute(name) {
  7065. return this.attributes[name];
  7066. },
  7067. setAttribute: function setAttribute(name, attribute) {
  7068. this.attributes[name] = attribute;
  7069. return this;
  7070. },
  7071. deleteAttribute: function deleteAttribute(name) {
  7072. delete this.attributes[name];
  7073. return this;
  7074. },
  7075. hasAttribute: function hasAttribute(name) {
  7076. return this.attributes[name] !== undefined;
  7077. },
  7078. addGroup: function addGroup(start, count, materialIndex) {
  7079. if (materialIndex === void 0) {
  7080. materialIndex = 0;
  7081. }
  7082. this.groups.push({
  7083. start: start,
  7084. count: count,
  7085. materialIndex: materialIndex
  7086. });
  7087. },
  7088. clearGroups: function clearGroups() {
  7089. this.groups = [];
  7090. },
  7091. setDrawRange: function setDrawRange(start, count) {
  7092. this.drawRange.start = start;
  7093. this.drawRange.count = count;
  7094. },
  7095. applyMatrix4: function applyMatrix4(matrix) {
  7096. var position = this.attributes.position;
  7097. if (position !== undefined) {
  7098. position.applyMatrix4(matrix);
  7099. position.needsUpdate = true;
  7100. }
  7101. var normal = this.attributes.normal;
  7102. if (normal !== undefined) {
  7103. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  7104. normal.applyNormalMatrix(normalMatrix);
  7105. normal.needsUpdate = true;
  7106. }
  7107. var tangent = this.attributes.tangent;
  7108. if (tangent !== undefined) {
  7109. tangent.transformDirection(matrix);
  7110. tangent.needsUpdate = true;
  7111. }
  7112. if (this.boundingBox !== null) {
  7113. this.computeBoundingBox();
  7114. }
  7115. if (this.boundingSphere !== null) {
  7116. this.computeBoundingSphere();
  7117. }
  7118. return this;
  7119. },
  7120. rotateX: function rotateX(angle) {
  7121. // rotate geometry around world x-axis
  7122. _m1$2.makeRotationX(angle);
  7123. this.applyMatrix4(_m1$2);
  7124. return this;
  7125. },
  7126. rotateY: function rotateY(angle) {
  7127. // rotate geometry around world y-axis
  7128. _m1$2.makeRotationY(angle);
  7129. this.applyMatrix4(_m1$2);
  7130. return this;
  7131. },
  7132. rotateZ: function rotateZ(angle) {
  7133. // rotate geometry around world z-axis
  7134. _m1$2.makeRotationZ(angle);
  7135. this.applyMatrix4(_m1$2);
  7136. return this;
  7137. },
  7138. translate: function translate(x, y, z) {
  7139. // translate geometry
  7140. _m1$2.makeTranslation(x, y, z);
  7141. this.applyMatrix4(_m1$2);
  7142. return this;
  7143. },
  7144. scale: function scale(x, y, z) {
  7145. // scale geometry
  7146. _m1$2.makeScale(x, y, z);
  7147. this.applyMatrix4(_m1$2);
  7148. return this;
  7149. },
  7150. lookAt: function lookAt(vector) {
  7151. _obj.lookAt(vector);
  7152. _obj.updateMatrix();
  7153. this.applyMatrix4(_obj.matrix);
  7154. return this;
  7155. },
  7156. center: function center() {
  7157. this.computeBoundingBox();
  7158. this.boundingBox.getCenter(_offset).negate();
  7159. this.translate(_offset.x, _offset.y, _offset.z);
  7160. return this;
  7161. },
  7162. setFromPoints: function setFromPoints(points) {
  7163. var position = [];
  7164. for (var i = 0, l = points.length; i < l; i++) {
  7165. var point = points[i];
  7166. position.push(point.x, point.y, point.z || 0);
  7167. }
  7168. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  7169. return this;
  7170. },
  7171. computeBoundingBox: function computeBoundingBox() {
  7172. if (this.boundingBox === null) {
  7173. this.boundingBox = new Box3();
  7174. }
  7175. var position = this.attributes.position;
  7176. var morphAttributesPosition = this.morphAttributes.position;
  7177. if (position && position.isGLBufferAttribute) {
  7178. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  7179. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  7180. return;
  7181. }
  7182. if (position !== undefined) {
  7183. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  7184. if (morphAttributesPosition) {
  7185. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7186. var morphAttribute = morphAttributesPosition[i];
  7187. _box$2.setFromBufferAttribute(morphAttribute);
  7188. if (this.morphTargetsRelative) {
  7189. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  7190. this.boundingBox.expandByPoint(_vector$4);
  7191. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  7192. this.boundingBox.expandByPoint(_vector$4);
  7193. } else {
  7194. this.boundingBox.expandByPoint(_box$2.min);
  7195. this.boundingBox.expandByPoint(_box$2.max);
  7196. }
  7197. }
  7198. }
  7199. } else {
  7200. this.boundingBox.makeEmpty();
  7201. }
  7202. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  7203. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  7204. }
  7205. },
  7206. computeBoundingSphere: function computeBoundingSphere() {
  7207. if (this.boundingSphere === null) {
  7208. this.boundingSphere = new Sphere();
  7209. }
  7210. var position = this.attributes.position;
  7211. var morphAttributesPosition = this.morphAttributes.position;
  7212. if (position && position.isGLBufferAttribute) {
  7213. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  7214. this.boundingSphere.set(new Vector3(), Infinity);
  7215. return;
  7216. }
  7217. if (position) {
  7218. // first, find the center of the bounding sphere
  7219. var center = this.boundingSphere.center;
  7220. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  7221. if (morphAttributesPosition) {
  7222. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7223. var morphAttribute = morphAttributesPosition[i];
  7224. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  7225. if (this.morphTargetsRelative) {
  7226. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  7227. _box$2.expandByPoint(_vector$4);
  7228. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  7229. _box$2.expandByPoint(_vector$4);
  7230. } else {
  7231. _box$2.expandByPoint(_boxMorphTargets.min);
  7232. _box$2.expandByPoint(_boxMorphTargets.max);
  7233. }
  7234. }
  7235. }
  7236. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  7237. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7238. var maxRadiusSq = 0;
  7239. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  7240. _vector$4.fromBufferAttribute(position, _i);
  7241. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7242. } // process morph attributes if present
  7243. if (morphAttributesPosition) {
  7244. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  7245. var _morphAttribute = morphAttributesPosition[_i2];
  7246. var morphTargetsRelative = this.morphTargetsRelative;
  7247. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  7248. _vector$4.fromBufferAttribute(_morphAttribute, j);
  7249. if (morphTargetsRelative) {
  7250. _offset.fromBufferAttribute(position, j);
  7251. _vector$4.add(_offset);
  7252. }
  7253. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7254. }
  7255. }
  7256. }
  7257. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  7258. if (isNaN(this.boundingSphere.radius)) {
  7259. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  7260. }
  7261. }
  7262. },
  7263. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  7264. },
  7265. computeTangents: function computeTangents() {
  7266. var index = this.index;
  7267. var attributes = this.attributes; // based on http://www.terathon.com/code/tangent.html
  7268. // (per vertex tangents)
  7269. if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
  7270. console.error('THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)');
  7271. return;
  7272. }
  7273. var indices = index.array;
  7274. var positions = attributes.position.array;
  7275. var normals = attributes.normal.array;
  7276. var uvs = attributes.uv.array;
  7277. var nVertices = positions.length / 3;
  7278. if (attributes.tangent === undefined) {
  7279. this.setAttribute('tangent', new BufferAttribute(new Float32Array(4 * nVertices), 4));
  7280. }
  7281. var tangents = attributes.tangent.array;
  7282. var tan1 = [],
  7283. tan2 = [];
  7284. for (var i = 0; i < nVertices; i++) {
  7285. tan1[i] = new Vector3();
  7286. tan2[i] = new Vector3();
  7287. }
  7288. var vA = new Vector3(),
  7289. vB = new Vector3(),
  7290. vC = new Vector3(),
  7291. uvA = new Vector2(),
  7292. uvB = new Vector2(),
  7293. uvC = new Vector2(),
  7294. sdir = new Vector3(),
  7295. tdir = new Vector3();
  7296. function handleTriangle(a, b, c) {
  7297. vA.fromArray(positions, a * 3);
  7298. vB.fromArray(positions, b * 3);
  7299. vC.fromArray(positions, c * 3);
  7300. uvA.fromArray(uvs, a * 2);
  7301. uvB.fromArray(uvs, b * 2);
  7302. uvC.fromArray(uvs, c * 2);
  7303. vB.sub(vA);
  7304. vC.sub(vA);
  7305. uvB.sub(uvA);
  7306. uvC.sub(uvA);
  7307. var r = 1.0 / (uvB.x * uvC.y - uvC.x * uvB.y); // silently ignore degenerate uv triangles having coincident or colinear vertices
  7308. if (!isFinite(r)) return;
  7309. sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
  7310. tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
  7311. tan1[a].add(sdir);
  7312. tan1[b].add(sdir);
  7313. tan1[c].add(sdir);
  7314. tan2[a].add(tdir);
  7315. tan2[b].add(tdir);
  7316. tan2[c].add(tdir);
  7317. }
  7318. var groups = this.groups;
  7319. if (groups.length === 0) {
  7320. groups = [{
  7321. start: 0,
  7322. count: indices.length
  7323. }];
  7324. }
  7325. for (var _i3 = 0, il = groups.length; _i3 < il; ++_i3) {
  7326. var group = groups[_i3];
  7327. var start = group.start;
  7328. var count = group.count;
  7329. for (var j = start, jl = start + count; j < jl; j += 3) {
  7330. handleTriangle(indices[j + 0], indices[j + 1], indices[j + 2]);
  7331. }
  7332. }
  7333. var tmp = new Vector3(),
  7334. tmp2 = new Vector3();
  7335. var n = new Vector3(),
  7336. n2 = new Vector3();
  7337. function handleVertex(v) {
  7338. n.fromArray(normals, v * 3);
  7339. n2.copy(n);
  7340. var t = tan1[v]; // Gram-Schmidt orthogonalize
  7341. tmp.copy(t);
  7342. tmp.sub(n.multiplyScalar(n.dot(t))).normalize(); // Calculate handedness
  7343. tmp2.crossVectors(n2, t);
  7344. var test = tmp2.dot(tan2[v]);
  7345. var w = test < 0.0 ? -1.0 : 1.0;
  7346. tangents[v * 4] = tmp.x;
  7347. tangents[v * 4 + 1] = tmp.y;
  7348. tangents[v * 4 + 2] = tmp.z;
  7349. tangents[v * 4 + 3] = w;
  7350. }
  7351. for (var _i4 = 0, _il3 = groups.length; _i4 < _il3; ++_i4) {
  7352. var _group = groups[_i4];
  7353. var _start = _group.start;
  7354. var _count = _group.count;
  7355. for (var _j = _start, _jl = _start + _count; _j < _jl; _j += 3) {
  7356. handleVertex(indices[_j + 0]);
  7357. handleVertex(indices[_j + 1]);
  7358. handleVertex(indices[_j + 2]);
  7359. }
  7360. }
  7361. },
  7362. computeVertexNormals: function computeVertexNormals() {
  7363. var index = this.index;
  7364. var positionAttribute = this.getAttribute('position');
  7365. if (positionAttribute !== undefined) {
  7366. var normalAttribute = this.getAttribute('normal');
  7367. if (normalAttribute === undefined) {
  7368. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  7369. this.setAttribute('normal', normalAttribute);
  7370. } else {
  7371. // reset existing normals to zero
  7372. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  7373. normalAttribute.setXYZ(i, 0, 0, 0);
  7374. }
  7375. }
  7376. var pA = new Vector3(),
  7377. pB = new Vector3(),
  7378. pC = new Vector3();
  7379. var nA = new Vector3(),
  7380. nB = new Vector3(),
  7381. nC = new Vector3();
  7382. var cb = new Vector3(),
  7383. ab = new Vector3(); // indexed elements
  7384. if (index) {
  7385. for (var _i5 = 0, _il4 = index.count; _i5 < _il4; _i5 += 3) {
  7386. var vA = index.getX(_i5 + 0);
  7387. var vB = index.getX(_i5 + 1);
  7388. var vC = index.getX(_i5 + 2);
  7389. pA.fromBufferAttribute(positionAttribute, vA);
  7390. pB.fromBufferAttribute(positionAttribute, vB);
  7391. pC.fromBufferAttribute(positionAttribute, vC);
  7392. cb.subVectors(pC, pB);
  7393. ab.subVectors(pA, pB);
  7394. cb.cross(ab);
  7395. nA.fromBufferAttribute(normalAttribute, vA);
  7396. nB.fromBufferAttribute(normalAttribute, vB);
  7397. nC.fromBufferAttribute(normalAttribute, vC);
  7398. nA.add(cb);
  7399. nB.add(cb);
  7400. nC.add(cb);
  7401. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  7402. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  7403. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  7404. }
  7405. } else {
  7406. // non-indexed elements (unconnected triangle soup)
  7407. for (var _i6 = 0, _il5 = positionAttribute.count; _i6 < _il5; _i6 += 3) {
  7408. pA.fromBufferAttribute(positionAttribute, _i6 + 0);
  7409. pB.fromBufferAttribute(positionAttribute, _i6 + 1);
  7410. pC.fromBufferAttribute(positionAttribute, _i6 + 2);
  7411. cb.subVectors(pC, pB);
  7412. ab.subVectors(pA, pB);
  7413. cb.cross(ab);
  7414. normalAttribute.setXYZ(_i6 + 0, cb.x, cb.y, cb.z);
  7415. normalAttribute.setXYZ(_i6 + 1, cb.x, cb.y, cb.z);
  7416. normalAttribute.setXYZ(_i6 + 2, cb.x, cb.y, cb.z);
  7417. }
  7418. }
  7419. this.normalizeNormals();
  7420. normalAttribute.needsUpdate = true;
  7421. }
  7422. },
  7423. merge: function merge(geometry, offset) {
  7424. if (!(geometry && geometry.isBufferGeometry)) {
  7425. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  7426. return;
  7427. }
  7428. if (offset === undefined) {
  7429. offset = 0;
  7430. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  7431. }
  7432. var attributes = this.attributes;
  7433. for (var key in attributes) {
  7434. if (geometry.attributes[key] === undefined) continue;
  7435. var attribute1 = attributes[key];
  7436. var attributeArray1 = attribute1.array;
  7437. var attribute2 = geometry.attributes[key];
  7438. var attributeArray2 = attribute2.array;
  7439. var attributeOffset = attribute2.itemSize * offset;
  7440. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  7441. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  7442. attributeArray1[j] = attributeArray2[i];
  7443. }
  7444. }
  7445. return this;
  7446. },
  7447. normalizeNormals: function normalizeNormals() {
  7448. var normals = this.attributes.normal;
  7449. for (var i = 0, il = normals.count; i < il; i++) {
  7450. _vector$4.fromBufferAttribute(normals, i);
  7451. _vector$4.normalize();
  7452. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  7453. }
  7454. },
  7455. toNonIndexed: function toNonIndexed() {
  7456. function convertBufferAttribute(attribute, indices) {
  7457. var array = attribute.array;
  7458. var itemSize = attribute.itemSize;
  7459. var normalized = attribute.normalized;
  7460. var array2 = new array.constructor(indices.length * itemSize);
  7461. var index = 0,
  7462. index2 = 0;
  7463. for (var i = 0, l = indices.length; i < l; i++) {
  7464. index = indices[i] * itemSize;
  7465. for (var j = 0; j < itemSize; j++) {
  7466. array2[index2++] = array[index++];
  7467. }
  7468. }
  7469. return new BufferAttribute(array2, itemSize, normalized);
  7470. } //
  7471. if (this.index === null) {
  7472. console.warn('THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.');
  7473. return this;
  7474. }
  7475. var geometry2 = new BufferGeometry();
  7476. var indices = this.index.array;
  7477. var attributes = this.attributes; // attributes
  7478. for (var name in attributes) {
  7479. var attribute = attributes[name];
  7480. var newAttribute = convertBufferAttribute(attribute, indices);
  7481. geometry2.setAttribute(name, newAttribute);
  7482. } // morph attributes
  7483. var morphAttributes = this.morphAttributes;
  7484. for (var _name in morphAttributes) {
  7485. var morphArray = [];
  7486. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  7487. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  7488. var _attribute = morphAttribute[i];
  7489. var _newAttribute = convertBufferAttribute(_attribute, indices);
  7490. morphArray.push(_newAttribute);
  7491. }
  7492. geometry2.morphAttributes[_name] = morphArray;
  7493. }
  7494. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  7495. var groups = this.groups;
  7496. for (var _i7 = 0, l = groups.length; _i7 < l; _i7++) {
  7497. var group = groups[_i7];
  7498. geometry2.addGroup(group.start, group.count, group.materialIndex);
  7499. }
  7500. return geometry2;
  7501. },
  7502. toJSON: function toJSON() {
  7503. var data = {
  7504. metadata: {
  7505. version: 4.5,
  7506. type: 'BufferGeometry',
  7507. generator: 'BufferGeometry.toJSON'
  7508. }
  7509. }; // standard BufferGeometry serialization
  7510. data.uuid = this.uuid;
  7511. data.type = this.type;
  7512. if (this.name !== '') data.name = this.name;
  7513. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  7514. if (this.parameters !== undefined) {
  7515. var parameters = this.parameters;
  7516. for (var key in parameters) {
  7517. if (parameters[key] !== undefined) data[key] = parameters[key];
  7518. }
  7519. return data;
  7520. }
  7521. data.data = {
  7522. attributes: {}
  7523. };
  7524. var index = this.index;
  7525. if (index !== null) {
  7526. data.data.index = {
  7527. type: index.array.constructor.name,
  7528. array: Array.prototype.slice.call(index.array)
  7529. };
  7530. }
  7531. var attributes = this.attributes;
  7532. for (var _key in attributes) {
  7533. var attribute = attributes[_key];
  7534. var attributeData = attribute.toJSON(data.data);
  7535. if (attribute.name !== '') attributeData.name = attribute.name;
  7536. data.data.attributes[_key] = attributeData;
  7537. }
  7538. var morphAttributes = {};
  7539. var hasMorphAttributes = false;
  7540. for (var _key2 in this.morphAttributes) {
  7541. var attributeArray = this.morphAttributes[_key2];
  7542. var array = [];
  7543. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7544. var _attribute2 = attributeArray[i];
  7545. var _attributeData = _attribute2.toJSON(data.data);
  7546. if (_attribute2.name !== '') _attributeData.name = _attribute2.name;
  7547. array.push(_attributeData);
  7548. }
  7549. if (array.length > 0) {
  7550. morphAttributes[_key2] = array;
  7551. hasMorphAttributes = true;
  7552. }
  7553. }
  7554. if (hasMorphAttributes) {
  7555. data.data.morphAttributes = morphAttributes;
  7556. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7557. }
  7558. var groups = this.groups;
  7559. if (groups.length > 0) {
  7560. data.data.groups = JSON.parse(JSON.stringify(groups));
  7561. }
  7562. var boundingSphere = this.boundingSphere;
  7563. if (boundingSphere !== null) {
  7564. data.data.boundingSphere = {
  7565. center: boundingSphere.center.toArray(),
  7566. radius: boundingSphere.radius
  7567. };
  7568. }
  7569. return data;
  7570. },
  7571. clone: function clone() {
  7572. /*
  7573. // Handle primitives
  7574. const parameters = this.parameters;
  7575. if ( parameters !== undefined ) {
  7576. const values = [];
  7577. for ( const key in parameters ) {
  7578. values.push( parameters[ key ] );
  7579. }
  7580. const geometry = Object.create( this.constructor.prototype );
  7581. this.constructor.apply( geometry, values );
  7582. return geometry;
  7583. }
  7584. return new this.constructor().copy( this );
  7585. */
  7586. return new BufferGeometry().copy(this);
  7587. },
  7588. copy: function copy(source) {
  7589. // reset
  7590. this.index = null;
  7591. this.attributes = {};
  7592. this.morphAttributes = {};
  7593. this.groups = [];
  7594. this.boundingBox = null;
  7595. this.boundingSphere = null; // used for storing cloned, shared data
  7596. var data = {}; // name
  7597. this.name = source.name; // index
  7598. var index = source.index;
  7599. if (index !== null) {
  7600. this.setIndex(index.clone(data));
  7601. } // attributes
  7602. var attributes = source.attributes;
  7603. for (var name in attributes) {
  7604. var attribute = attributes[name];
  7605. this.setAttribute(name, attribute.clone(data));
  7606. } // morph attributes
  7607. var morphAttributes = source.morphAttributes;
  7608. for (var _name2 in morphAttributes) {
  7609. var array = [];
  7610. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7611. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7612. array.push(morphAttribute[i].clone(data));
  7613. }
  7614. this.morphAttributes[_name2] = array;
  7615. }
  7616. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7617. var groups = source.groups;
  7618. for (var _i8 = 0, _l = groups.length; _i8 < _l; _i8++) {
  7619. var group = groups[_i8];
  7620. this.addGroup(group.start, group.count, group.materialIndex);
  7621. } // bounding box
  7622. var boundingBox = source.boundingBox;
  7623. if (boundingBox !== null) {
  7624. this.boundingBox = boundingBox.clone();
  7625. } // bounding sphere
  7626. var boundingSphere = source.boundingSphere;
  7627. if (boundingSphere !== null) {
  7628. this.boundingSphere = boundingSphere.clone();
  7629. } // draw range
  7630. this.drawRange.start = source.drawRange.start;
  7631. this.drawRange.count = source.drawRange.count; // user data
  7632. this.userData = source.userData;
  7633. return this;
  7634. },
  7635. dispose: function dispose() {
  7636. this.dispatchEvent({
  7637. type: 'dispose'
  7638. });
  7639. }
  7640. });
  7641. var _inverseMatrix = new Matrix4();
  7642. var _ray = new Ray();
  7643. var _sphere = new Sphere();
  7644. var _vA = new Vector3();
  7645. var _vB = new Vector3();
  7646. var _vC = new Vector3();
  7647. var _tempA = new Vector3();
  7648. var _tempB = new Vector3();
  7649. var _tempC = new Vector3();
  7650. var _morphA = new Vector3();
  7651. var _morphB = new Vector3();
  7652. var _morphC = new Vector3();
  7653. var _uvA = new Vector2();
  7654. var _uvB = new Vector2();
  7655. var _uvC = new Vector2();
  7656. var _intersectionPoint = new Vector3();
  7657. var _intersectionPointWorld = new Vector3();
  7658. function Mesh(geometry, material) {
  7659. if (geometry === void 0) {
  7660. geometry = new BufferGeometry();
  7661. }
  7662. if (material === void 0) {
  7663. material = new MeshBasicMaterial();
  7664. }
  7665. Object3D.call(this);
  7666. this.type = 'Mesh';
  7667. this.geometry = geometry;
  7668. this.material = material;
  7669. this.updateMorphTargets();
  7670. }
  7671. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7672. constructor: Mesh,
  7673. isMesh: true,
  7674. copy: function copy(source) {
  7675. Object3D.prototype.copy.call(this, source);
  7676. if (source.morphTargetInfluences !== undefined) {
  7677. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7678. }
  7679. if (source.morphTargetDictionary !== undefined) {
  7680. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7681. }
  7682. this.material = source.material;
  7683. this.geometry = source.geometry;
  7684. return this;
  7685. },
  7686. updateMorphTargets: function updateMorphTargets() {
  7687. var geometry = this.geometry;
  7688. if (geometry.isBufferGeometry) {
  7689. var morphAttributes = geometry.morphAttributes;
  7690. var keys = Object.keys(morphAttributes);
  7691. if (keys.length > 0) {
  7692. var morphAttribute = morphAttributes[keys[0]];
  7693. if (morphAttribute !== undefined) {
  7694. this.morphTargetInfluences = [];
  7695. this.morphTargetDictionary = {};
  7696. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7697. var name = morphAttribute[m].name || String(m);
  7698. this.morphTargetInfluences.push(0);
  7699. this.morphTargetDictionary[name] = m;
  7700. }
  7701. }
  7702. }
  7703. } else {
  7704. var morphTargets = geometry.morphTargets;
  7705. if (morphTargets !== undefined && morphTargets.length > 0) {
  7706. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7707. }
  7708. }
  7709. },
  7710. raycast: function raycast(raycaster, intersects) {
  7711. var geometry = this.geometry;
  7712. var material = this.material;
  7713. var matrixWorld = this.matrixWorld;
  7714. if (material === undefined) return; // Checking boundingSphere distance to ray
  7715. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7716. _sphere.copy(geometry.boundingSphere);
  7717. _sphere.applyMatrix4(matrixWorld);
  7718. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7719. _inverseMatrix.copy(matrixWorld).invert();
  7720. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7721. if (geometry.boundingBox !== null) {
  7722. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7723. }
  7724. var intersection;
  7725. if (geometry.isBufferGeometry) {
  7726. var index = geometry.index;
  7727. var position = geometry.attributes.position;
  7728. var morphPosition = geometry.morphAttributes.position;
  7729. var morphTargetsRelative = geometry.morphTargetsRelative;
  7730. var uv = geometry.attributes.uv;
  7731. var uv2 = geometry.attributes.uv2;
  7732. var groups = geometry.groups;
  7733. var drawRange = geometry.drawRange;
  7734. if (index !== null) {
  7735. // indexed buffer geometry
  7736. if (Array.isArray(material)) {
  7737. for (var i = 0, il = groups.length; i < il; i++) {
  7738. var group = groups[i];
  7739. var groupMaterial = material[group.materialIndex];
  7740. var start = Math.max(group.start, drawRange.start);
  7741. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7742. for (var j = start, jl = end; j < jl; j += 3) {
  7743. var a = index.getX(j);
  7744. var b = index.getX(j + 1);
  7745. var c = index.getX(j + 2);
  7746. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7747. if (intersection) {
  7748. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7749. intersection.face.materialIndex = group.materialIndex;
  7750. intersects.push(intersection);
  7751. }
  7752. }
  7753. }
  7754. } else {
  7755. var _start = Math.max(0, drawRange.start);
  7756. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7757. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7758. var _a = index.getX(_i);
  7759. var _b = index.getX(_i + 1);
  7760. var _c = index.getX(_i + 2);
  7761. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7762. if (intersection) {
  7763. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7764. intersects.push(intersection);
  7765. }
  7766. }
  7767. }
  7768. } else if (position !== undefined) {
  7769. // non-indexed buffer geometry
  7770. if (Array.isArray(material)) {
  7771. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7772. var _group = groups[_i2];
  7773. var _groupMaterial = material[_group.materialIndex];
  7774. var _start2 = Math.max(_group.start, drawRange.start);
  7775. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7776. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7777. var _a2 = _j;
  7778. var _b2 = _j + 1;
  7779. var _c2 = _j + 2;
  7780. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7781. if (intersection) {
  7782. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7783. intersection.face.materialIndex = _group.materialIndex;
  7784. intersects.push(intersection);
  7785. }
  7786. }
  7787. }
  7788. } else {
  7789. var _start3 = Math.max(0, drawRange.start);
  7790. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7791. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7792. var _a3 = _i3;
  7793. var _b3 = _i3 + 1;
  7794. var _c3 = _i3 + 2;
  7795. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7796. if (intersection) {
  7797. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7798. intersects.push(intersection);
  7799. }
  7800. }
  7801. }
  7802. }
  7803. } else if (geometry.isGeometry) {
  7804. console.error('THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7805. }
  7806. }
  7807. });
  7808. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7809. var intersect;
  7810. if (material.side === BackSide) {
  7811. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7812. } else {
  7813. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7814. }
  7815. if (intersect === null) return null;
  7816. _intersectionPointWorld.copy(point);
  7817. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7818. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7819. if (distance < raycaster.near || distance > raycaster.far) return null;
  7820. return {
  7821. distance: distance,
  7822. point: _intersectionPointWorld.clone(),
  7823. object: object
  7824. };
  7825. }
  7826. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7827. _vA.fromBufferAttribute(position, a);
  7828. _vB.fromBufferAttribute(position, b);
  7829. _vC.fromBufferAttribute(position, c);
  7830. var morphInfluences = object.morphTargetInfluences;
  7831. if (material.morphTargets && morphPosition && morphInfluences) {
  7832. _morphA.set(0, 0, 0);
  7833. _morphB.set(0, 0, 0);
  7834. _morphC.set(0, 0, 0);
  7835. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7836. var influence = morphInfluences[i];
  7837. var morphAttribute = morphPosition[i];
  7838. if (influence === 0) continue;
  7839. _tempA.fromBufferAttribute(morphAttribute, a);
  7840. _tempB.fromBufferAttribute(morphAttribute, b);
  7841. _tempC.fromBufferAttribute(morphAttribute, c);
  7842. if (morphTargetsRelative) {
  7843. _morphA.addScaledVector(_tempA, influence);
  7844. _morphB.addScaledVector(_tempB, influence);
  7845. _morphC.addScaledVector(_tempC, influence);
  7846. } else {
  7847. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7848. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7849. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7850. }
  7851. }
  7852. _vA.add(_morphA);
  7853. _vB.add(_morphB);
  7854. _vC.add(_morphC);
  7855. }
  7856. if (object.isSkinnedMesh && material.skinning) {
  7857. object.boneTransform(a, _vA);
  7858. object.boneTransform(b, _vB);
  7859. object.boneTransform(c, _vC);
  7860. }
  7861. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7862. if (intersection) {
  7863. if (uv) {
  7864. _uvA.fromBufferAttribute(uv, a);
  7865. _uvB.fromBufferAttribute(uv, b);
  7866. _uvC.fromBufferAttribute(uv, c);
  7867. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7868. }
  7869. if (uv2) {
  7870. _uvA.fromBufferAttribute(uv2, a);
  7871. _uvB.fromBufferAttribute(uv2, b);
  7872. _uvC.fromBufferAttribute(uv2, c);
  7873. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7874. }
  7875. var face = {
  7876. a: a,
  7877. b: a,
  7878. c: c,
  7879. normal: new Vector3(),
  7880. materialIndex: 0
  7881. };
  7882. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7883. intersection.face = face;
  7884. }
  7885. return intersection;
  7886. }
  7887. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7888. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7889. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7890. var _this;
  7891. if (width === void 0) {
  7892. width = 1;
  7893. }
  7894. if (height === void 0) {
  7895. height = 1;
  7896. }
  7897. if (depth === void 0) {
  7898. depth = 1;
  7899. }
  7900. if (widthSegments === void 0) {
  7901. widthSegments = 1;
  7902. }
  7903. if (heightSegments === void 0) {
  7904. heightSegments = 1;
  7905. }
  7906. if (depthSegments === void 0) {
  7907. depthSegments = 1;
  7908. }
  7909. _this = _BufferGeometry.call(this) || this;
  7910. _this.type = 'BoxGeometry';
  7911. _this.parameters = {
  7912. width: width,
  7913. height: height,
  7914. depth: depth,
  7915. widthSegments: widthSegments,
  7916. heightSegments: heightSegments,
  7917. depthSegments: depthSegments
  7918. };
  7919. var scope = _assertThisInitialized(_this); // segments
  7920. widthSegments = Math.floor(widthSegments);
  7921. heightSegments = Math.floor(heightSegments);
  7922. depthSegments = Math.floor(depthSegments); // buffers
  7923. var indices = [];
  7924. var vertices = [];
  7925. var normals = [];
  7926. var uvs = []; // helper variables
  7927. var numberOfVertices = 0;
  7928. var groupStart = 0; // build each side of the box geometry
  7929. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7930. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7931. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7932. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7933. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7934. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7935. // build geometry
  7936. _this.setIndex(indices);
  7937. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7938. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7939. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7940. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7941. var segmentWidth = width / gridX;
  7942. var segmentHeight = height / gridY;
  7943. var widthHalf = width / 2;
  7944. var heightHalf = height / 2;
  7945. var depthHalf = depth / 2;
  7946. var gridX1 = gridX + 1;
  7947. var gridY1 = gridY + 1;
  7948. var vertexCounter = 0;
  7949. var groupCount = 0;
  7950. var vector = new Vector3(); // generate vertices, normals and uvs
  7951. for (var iy = 0; iy < gridY1; iy++) {
  7952. var y = iy * segmentHeight - heightHalf;
  7953. for (var ix = 0; ix < gridX1; ix++) {
  7954. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7955. vector[u] = x * udir;
  7956. vector[v] = y * vdir;
  7957. vector[w] = depthHalf; // now apply vector to vertex buffer
  7958. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7959. vector[u] = 0;
  7960. vector[v] = 0;
  7961. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7962. normals.push(vector.x, vector.y, vector.z); // uvs
  7963. uvs.push(ix / gridX);
  7964. uvs.push(1 - iy / gridY); // counters
  7965. vertexCounter += 1;
  7966. }
  7967. } // indices
  7968. // 1. you need three indices to draw a single face
  7969. // 2. a single segment consists of two faces
  7970. // 3. so we need to generate six (2*3) indices per segment
  7971. for (var _iy = 0; _iy < gridY; _iy++) {
  7972. for (var _ix = 0; _ix < gridX; _ix++) {
  7973. var a = numberOfVertices + _ix + gridX1 * _iy;
  7974. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7975. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7976. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7977. indices.push(a, b, d);
  7978. indices.push(b, c, d); // increase counter
  7979. groupCount += 6;
  7980. }
  7981. } // add a group to the geometry. this will ensure multi material support
  7982. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7983. groupStart += groupCount; // update total number of vertices
  7984. numberOfVertices += vertexCounter;
  7985. }
  7986. return _this;
  7987. }
  7988. return BoxGeometry;
  7989. }(BufferGeometry);
  7990. /**
  7991. * Uniform Utilities
  7992. */
  7993. function cloneUniforms(src) {
  7994. var dst = {};
  7995. for (var u in src) {
  7996. dst[u] = {};
  7997. for (var p in src[u]) {
  7998. var property = src[u][p];
  7999. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture || property.isQuaternion)) {
  8000. dst[u][p] = property.clone();
  8001. } else if (Array.isArray(property)) {
  8002. dst[u][p] = property.slice();
  8003. } else {
  8004. dst[u][p] = property;
  8005. }
  8006. }
  8007. }
  8008. return dst;
  8009. }
  8010. function mergeUniforms(uniforms) {
  8011. var merged = {};
  8012. for (var u = 0; u < uniforms.length; u++) {
  8013. var tmp = cloneUniforms(uniforms[u]);
  8014. for (var p in tmp) {
  8015. merged[p] = tmp[p];
  8016. }
  8017. }
  8018. return merged;
  8019. } // Legacy
  8020. var UniformsUtils = {
  8021. clone: cloneUniforms,
  8022. merge: mergeUniforms
  8023. };
  8024. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  8025. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  8026. /**
  8027. * parameters = {
  8028. * defines: { "label" : "value" },
  8029. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  8030. *
  8031. * fragmentShader: <string>,
  8032. * vertexShader: <string>,
  8033. *
  8034. * wireframe: <boolean>,
  8035. * wireframeLinewidth: <float>,
  8036. *
  8037. * lights: <bool>,
  8038. *
  8039. * skinning: <bool>,
  8040. * morphTargets: <bool>,
  8041. * morphNormals: <bool>
  8042. * }
  8043. */
  8044. function ShaderMaterial(parameters) {
  8045. Material.call(this);
  8046. this.type = 'ShaderMaterial';
  8047. this.defines = {};
  8048. this.uniforms = {};
  8049. this.vertexShader = default_vertex;
  8050. this.fragmentShader = default_fragment;
  8051. this.linewidth = 1;
  8052. this.wireframe = false;
  8053. this.wireframeLinewidth = 1;
  8054. this.fog = false; // set to use scene fog
  8055. this.lights = false; // set to use scene lights
  8056. this.clipping = false; // set to use user-defined clipping planes
  8057. this.skinning = false; // set to use skinning attribute streams
  8058. this.morphTargets = false; // set to use morph targets
  8059. this.morphNormals = false; // set to use morph normals
  8060. this.extensions = {
  8061. derivatives: false,
  8062. // set to use derivatives
  8063. fragDepth: false,
  8064. // set to use fragment depth values
  8065. drawBuffers: false,
  8066. // set to use draw buffers
  8067. shaderTextureLOD: false // set to use shader texture LOD
  8068. }; // When rendered geometry doesn't include these attributes but the material does,
  8069. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8070. this.defaultAttributeValues = {
  8071. 'color': [1, 1, 1],
  8072. 'uv': [0, 0],
  8073. 'uv2': [0, 0]
  8074. };
  8075. this.index0AttributeName = undefined;
  8076. this.uniformsNeedUpdate = false;
  8077. this.glslVersion = null;
  8078. if (parameters !== undefined) {
  8079. if (parameters.attributes !== undefined) {
  8080. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  8081. }
  8082. this.setValues(parameters);
  8083. }
  8084. }
  8085. ShaderMaterial.prototype = Object.create(Material.prototype);
  8086. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8087. ShaderMaterial.prototype.isShaderMaterial = true;
  8088. ShaderMaterial.prototype.copy = function (source) {
  8089. Material.prototype.copy.call(this, source);
  8090. this.fragmentShader = source.fragmentShader;
  8091. this.vertexShader = source.vertexShader;
  8092. this.uniforms = cloneUniforms(source.uniforms);
  8093. this.defines = Object.assign({}, source.defines);
  8094. this.wireframe = source.wireframe;
  8095. this.wireframeLinewidth = source.wireframeLinewidth;
  8096. this.lights = source.lights;
  8097. this.clipping = source.clipping;
  8098. this.skinning = source.skinning;
  8099. this.morphTargets = source.morphTargets;
  8100. this.morphNormals = source.morphNormals;
  8101. this.extensions = Object.assign({}, source.extensions);
  8102. this.glslVersion = source.glslVersion;
  8103. return this;
  8104. };
  8105. ShaderMaterial.prototype.toJSON = function (meta) {
  8106. var data = Material.prototype.toJSON.call(this, meta);
  8107. data.glslVersion = this.glslVersion;
  8108. data.uniforms = {};
  8109. for (var name in this.uniforms) {
  8110. var uniform = this.uniforms[name];
  8111. var value = uniform.value;
  8112. if (value && value.isTexture) {
  8113. data.uniforms[name] = {
  8114. type: 't',
  8115. value: value.toJSON(meta).uuid
  8116. };
  8117. } else if (value && value.isColor) {
  8118. data.uniforms[name] = {
  8119. type: 'c',
  8120. value: value.getHex()
  8121. };
  8122. } else if (value && value.isVector2) {
  8123. data.uniforms[name] = {
  8124. type: 'v2',
  8125. value: value.toArray()
  8126. };
  8127. } else if (value && value.isVector3) {
  8128. data.uniforms[name] = {
  8129. type: 'v3',
  8130. value: value.toArray()
  8131. };
  8132. } else if (value && value.isVector4) {
  8133. data.uniforms[name] = {
  8134. type: 'v4',
  8135. value: value.toArray()
  8136. };
  8137. } else if (value && value.isMatrix3) {
  8138. data.uniforms[name] = {
  8139. type: 'm3',
  8140. value: value.toArray()
  8141. };
  8142. } else if (value && value.isMatrix4) {
  8143. data.uniforms[name] = {
  8144. type: 'm4',
  8145. value: value.toArray()
  8146. };
  8147. } else {
  8148. data.uniforms[name] = {
  8149. value: value
  8150. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8151. }
  8152. }
  8153. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  8154. data.vertexShader = this.vertexShader;
  8155. data.fragmentShader = this.fragmentShader;
  8156. var extensions = {};
  8157. for (var key in this.extensions) {
  8158. if (this.extensions[key] === true) extensions[key] = true;
  8159. }
  8160. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  8161. return data;
  8162. };
  8163. function Camera() {
  8164. Object3D.call(this);
  8165. this.type = 'Camera';
  8166. this.matrixWorldInverse = new Matrix4();
  8167. this.projectionMatrix = new Matrix4();
  8168. this.projectionMatrixInverse = new Matrix4();
  8169. }
  8170. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  8171. constructor: Camera,
  8172. isCamera: true,
  8173. copy: function copy(source, recursive) {
  8174. Object3D.prototype.copy.call(this, source, recursive);
  8175. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  8176. this.projectionMatrix.copy(source.projectionMatrix);
  8177. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  8178. return this;
  8179. },
  8180. getWorldDirection: function getWorldDirection(target) {
  8181. if (target === undefined) {
  8182. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  8183. target = new Vector3();
  8184. }
  8185. this.updateWorldMatrix(true, false);
  8186. var e = this.matrixWorld.elements;
  8187. return target.set(-e[8], -e[9], -e[10]).normalize();
  8188. },
  8189. updateMatrixWorld: function updateMatrixWorld(force) {
  8190. Object3D.prototype.updateMatrixWorld.call(this, force);
  8191. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8192. },
  8193. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  8194. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  8195. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8196. },
  8197. clone: function clone() {
  8198. return new this.constructor().copy(this);
  8199. }
  8200. });
  8201. function PerspectiveCamera(fov, aspect, near, far) {
  8202. if (fov === void 0) {
  8203. fov = 50;
  8204. }
  8205. if (aspect === void 0) {
  8206. aspect = 1;
  8207. }
  8208. if (near === void 0) {
  8209. near = 0.1;
  8210. }
  8211. if (far === void 0) {
  8212. far = 2000;
  8213. }
  8214. Camera.call(this);
  8215. this.type = 'PerspectiveCamera';
  8216. this.fov = fov;
  8217. this.zoom = 1;
  8218. this.near = near;
  8219. this.far = far;
  8220. this.focus = 10;
  8221. this.aspect = aspect;
  8222. this.view = null;
  8223. this.filmGauge = 35; // width of the film (default in millimeters)
  8224. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8225. this.updateProjectionMatrix();
  8226. }
  8227. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  8228. constructor: PerspectiveCamera,
  8229. isPerspectiveCamera: true,
  8230. copy: function copy(source, recursive) {
  8231. Camera.prototype.copy.call(this, source, recursive);
  8232. this.fov = source.fov;
  8233. this.zoom = source.zoom;
  8234. this.near = source.near;
  8235. this.far = source.far;
  8236. this.focus = source.focus;
  8237. this.aspect = source.aspect;
  8238. this.view = source.view === null ? null : Object.assign({}, source.view);
  8239. this.filmGauge = source.filmGauge;
  8240. this.filmOffset = source.filmOffset;
  8241. return this;
  8242. },
  8243. /**
  8244. * Sets the FOV by focal length in respect to the current .filmGauge.
  8245. *
  8246. * The default film gauge is 35, so that the focal length can be specified for
  8247. * a 35mm (full frame) camera.
  8248. *
  8249. * Values for focal length and film gauge must have the same unit.
  8250. */
  8251. setFocalLength: function setFocalLength(focalLength) {
  8252. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  8253. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8254. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  8255. this.updateProjectionMatrix();
  8256. },
  8257. /**
  8258. * Calculates the focal length from the current .fov and .filmGauge.
  8259. */
  8260. getFocalLength: function getFocalLength() {
  8261. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  8262. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8263. },
  8264. getEffectiveFOV: function getEffectiveFOV() {
  8265. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  8266. },
  8267. getFilmWidth: function getFilmWidth() {
  8268. // film not completely covered in portrait format (aspect < 1)
  8269. return this.filmGauge * Math.min(this.aspect, 1);
  8270. },
  8271. getFilmHeight: function getFilmHeight() {
  8272. // film not completely covered in landscape format (aspect > 1)
  8273. return this.filmGauge / Math.max(this.aspect, 1);
  8274. },
  8275. /**
  8276. * Sets an offset in a larger frustum. This is useful for multi-window or
  8277. * multi-monitor/multi-machine setups.
  8278. *
  8279. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8280. * the monitors are in grid like this
  8281. *
  8282. * +---+---+---+
  8283. * | A | B | C |
  8284. * +---+---+---+
  8285. * | D | E | F |
  8286. * +---+---+---+
  8287. *
  8288. * then for each monitor you would call it like this
  8289. *
  8290. * const w = 1920;
  8291. * const h = 1080;
  8292. * const fullWidth = w * 3;
  8293. * const fullHeight = h * 2;
  8294. *
  8295. * --A--
  8296. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8297. * --B--
  8298. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8299. * --C--
  8300. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8301. * --D--
  8302. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8303. * --E--
  8304. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8305. * --F--
  8306. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8307. *
  8308. * Note there is no reason monitors have to be the same size or in a grid.
  8309. */
  8310. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  8311. this.aspect = fullWidth / fullHeight;
  8312. if (this.view === null) {
  8313. this.view = {
  8314. enabled: true,
  8315. fullWidth: 1,
  8316. fullHeight: 1,
  8317. offsetX: 0,
  8318. offsetY: 0,
  8319. width: 1,
  8320. height: 1
  8321. };
  8322. }
  8323. this.view.enabled = true;
  8324. this.view.fullWidth = fullWidth;
  8325. this.view.fullHeight = fullHeight;
  8326. this.view.offsetX = x;
  8327. this.view.offsetY = y;
  8328. this.view.width = width;
  8329. this.view.height = height;
  8330. this.updateProjectionMatrix();
  8331. },
  8332. clearViewOffset: function clearViewOffset() {
  8333. if (this.view !== null) {
  8334. this.view.enabled = false;
  8335. }
  8336. this.updateProjectionMatrix();
  8337. },
  8338. updateProjectionMatrix: function updateProjectionMatrix() {
  8339. var near = this.near;
  8340. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  8341. var height = 2 * top;
  8342. var width = this.aspect * height;
  8343. var left = -0.5 * width;
  8344. var view = this.view;
  8345. if (this.view !== null && this.view.enabled) {
  8346. var fullWidth = view.fullWidth,
  8347. fullHeight = view.fullHeight;
  8348. left += view.offsetX * width / fullWidth;
  8349. top -= view.offsetY * height / fullHeight;
  8350. width *= view.width / fullWidth;
  8351. height *= view.height / fullHeight;
  8352. }
  8353. var skew = this.filmOffset;
  8354. if (skew !== 0) left += near * skew / this.getFilmWidth();
  8355. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  8356. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  8357. },
  8358. toJSON: function toJSON(meta) {
  8359. var data = Object3D.prototype.toJSON.call(this, meta);
  8360. data.object.fov = this.fov;
  8361. data.object.zoom = this.zoom;
  8362. data.object.near = this.near;
  8363. data.object.far = this.far;
  8364. data.object.focus = this.focus;
  8365. data.object.aspect = this.aspect;
  8366. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  8367. data.object.filmGauge = this.filmGauge;
  8368. data.object.filmOffset = this.filmOffset;
  8369. return data;
  8370. }
  8371. });
  8372. var fov = 90,
  8373. aspect = 1;
  8374. function CubeCamera(near, far, renderTarget) {
  8375. Object3D.call(this);
  8376. this.type = 'CubeCamera';
  8377. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  8378. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  8379. return;
  8380. }
  8381. this.renderTarget = renderTarget;
  8382. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  8383. cameraPX.layers = this.layers;
  8384. cameraPX.up.set(0, -1, 0);
  8385. cameraPX.lookAt(new Vector3(1, 0, 0));
  8386. this.add(cameraPX);
  8387. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  8388. cameraNX.layers = this.layers;
  8389. cameraNX.up.set(0, -1, 0);
  8390. cameraNX.lookAt(new Vector3(-1, 0, 0));
  8391. this.add(cameraNX);
  8392. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  8393. cameraPY.layers = this.layers;
  8394. cameraPY.up.set(0, 0, 1);
  8395. cameraPY.lookAt(new Vector3(0, 1, 0));
  8396. this.add(cameraPY);
  8397. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  8398. cameraNY.layers = this.layers;
  8399. cameraNY.up.set(0, 0, -1);
  8400. cameraNY.lookAt(new Vector3(0, -1, 0));
  8401. this.add(cameraNY);
  8402. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  8403. cameraPZ.layers = this.layers;
  8404. cameraPZ.up.set(0, -1, 0);
  8405. cameraPZ.lookAt(new Vector3(0, 0, 1));
  8406. this.add(cameraPZ);
  8407. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  8408. cameraNZ.layers = this.layers;
  8409. cameraNZ.up.set(0, -1, 0);
  8410. cameraNZ.lookAt(new Vector3(0, 0, -1));
  8411. this.add(cameraNZ);
  8412. this.update = function (renderer, scene) {
  8413. if (this.parent === null) this.updateMatrixWorld();
  8414. var currentXrEnabled = renderer.xr.enabled;
  8415. var currentRenderTarget = renderer.getRenderTarget();
  8416. renderer.xr.enabled = false;
  8417. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8418. renderTarget.texture.generateMipmaps = false;
  8419. renderer.setRenderTarget(renderTarget, 0);
  8420. renderer.render(scene, cameraPX);
  8421. renderer.setRenderTarget(renderTarget, 1);
  8422. renderer.render(scene, cameraNX);
  8423. renderer.setRenderTarget(renderTarget, 2);
  8424. renderer.render(scene, cameraPY);
  8425. renderer.setRenderTarget(renderTarget, 3);
  8426. renderer.render(scene, cameraNY);
  8427. renderer.setRenderTarget(renderTarget, 4);
  8428. renderer.render(scene, cameraPZ);
  8429. renderTarget.texture.generateMipmaps = generateMipmaps;
  8430. renderer.setRenderTarget(renderTarget, 5);
  8431. renderer.render(scene, cameraNZ);
  8432. renderer.setRenderTarget(currentRenderTarget);
  8433. renderer.xr.enabled = currentXrEnabled;
  8434. };
  8435. }
  8436. CubeCamera.prototype = Object.create(Object3D.prototype);
  8437. CubeCamera.prototype.constructor = CubeCamera;
  8438. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  8439. images = images !== undefined ? images : [];
  8440. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  8441. format = format !== undefined ? format : RGBFormat;
  8442. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8443. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  8444. //
  8445. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  8446. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  8447. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  8448. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  8449. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  8450. // when using WebGLCubeRenderTarget.texture as a cube texture.
  8451. this._needsFlipEnvMap = true;
  8452. }
  8453. CubeTexture.prototype = Object.create(Texture.prototype);
  8454. CubeTexture.prototype.constructor = CubeTexture;
  8455. CubeTexture.prototype.isCubeTexture = true;
  8456. Object.defineProperty(CubeTexture.prototype, 'images', {
  8457. get: function get() {
  8458. return this.image;
  8459. },
  8460. set: function set(value) {
  8461. this.image = value;
  8462. }
  8463. });
  8464. var WebGLCubeRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  8465. _inheritsLoose(WebGLCubeRenderTarget, _WebGLRenderTarget);
  8466. function WebGLCubeRenderTarget(size, options, dummy) {
  8467. var _this;
  8468. if (Number.isInteger(options)) {
  8469. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  8470. options = dummy;
  8471. }
  8472. _this = _WebGLRenderTarget.call(this, size, size, options) || this;
  8473. options = options || {};
  8474. _this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  8475. _this.texture._needsFlipEnvMap = false;
  8476. return _this;
  8477. }
  8478. var _proto = WebGLCubeRenderTarget.prototype;
  8479. _proto.fromEquirectangularTexture = function fromEquirectangularTexture(renderer, texture) {
  8480. this.texture.type = texture.type;
  8481. this.texture.format = RGBAFormat; // see #18859
  8482. this.texture.encoding = texture.encoding;
  8483. this.texture.generateMipmaps = texture.generateMipmaps;
  8484. this.texture.minFilter = texture.minFilter;
  8485. this.texture.magFilter = texture.magFilter;
  8486. var shader = {
  8487. uniforms: {
  8488. tEquirect: {
  8489. value: null
  8490. }
  8491. },
  8492. vertexShader:
  8493. /* glsl */
  8494. "\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",
  8495. fragmentShader:
  8496. /* glsl */
  8497. "\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"
  8498. };
  8499. var geometry = new BoxGeometry(5, 5, 5);
  8500. var material = new ShaderMaterial({
  8501. name: 'CubemapFromEquirect',
  8502. uniforms: cloneUniforms(shader.uniforms),
  8503. vertexShader: shader.vertexShader,
  8504. fragmentShader: shader.fragmentShader,
  8505. side: BackSide,
  8506. blending: NoBlending
  8507. });
  8508. material.uniforms.tEquirect.value = texture;
  8509. var mesh = new Mesh(geometry, material);
  8510. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8511. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8512. var camera = new CubeCamera(1, 10, this);
  8513. camera.update(renderer, mesh);
  8514. texture.minFilter = currentMinFilter;
  8515. mesh.geometry.dispose();
  8516. mesh.material.dispose();
  8517. return this;
  8518. };
  8519. _proto.clear = function clear(renderer, color, depth, stencil) {
  8520. var currentRenderTarget = renderer.getRenderTarget();
  8521. for (var i = 0; i < 6; i++) {
  8522. renderer.setRenderTarget(this, i);
  8523. renderer.clear(color, depth, stencil);
  8524. }
  8525. renderer.setRenderTarget(currentRenderTarget);
  8526. };
  8527. return WebGLCubeRenderTarget;
  8528. }(WebGLRenderTarget);
  8529. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  8530. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8531. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8532. this.image = {
  8533. data: data || null,
  8534. width: width || 1,
  8535. height: height || 1
  8536. };
  8537. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8538. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8539. this.generateMipmaps = false;
  8540. this.flipY = false;
  8541. this.unpackAlignment = 1;
  8542. this.needsUpdate = true;
  8543. }
  8544. DataTexture.prototype = Object.create(Texture.prototype);
  8545. DataTexture.prototype.constructor = DataTexture;
  8546. DataTexture.prototype.isDataTexture = true;
  8547. var _sphere$1 = /*@__PURE__*/new Sphere();
  8548. var _vector$5 = /*@__PURE__*/new Vector3();
  8549. var Frustum = /*#__PURE__*/function () {
  8550. function Frustum(p0, p1, p2, p3, p4, p5) {
  8551. if (p0 === void 0) {
  8552. p0 = new Plane();
  8553. }
  8554. if (p1 === void 0) {
  8555. p1 = new Plane();
  8556. }
  8557. if (p2 === void 0) {
  8558. p2 = new Plane();
  8559. }
  8560. if (p3 === void 0) {
  8561. p3 = new Plane();
  8562. }
  8563. if (p4 === void 0) {
  8564. p4 = new Plane();
  8565. }
  8566. if (p5 === void 0) {
  8567. p5 = new Plane();
  8568. }
  8569. this.planes = [p0, p1, p2, p3, p4, p5];
  8570. }
  8571. var _proto = Frustum.prototype;
  8572. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8573. var planes = this.planes;
  8574. planes[0].copy(p0);
  8575. planes[1].copy(p1);
  8576. planes[2].copy(p2);
  8577. planes[3].copy(p3);
  8578. planes[4].copy(p4);
  8579. planes[5].copy(p5);
  8580. return this;
  8581. };
  8582. _proto.copy = function copy(frustum) {
  8583. var planes = this.planes;
  8584. for (var i = 0; i < 6; i++) {
  8585. planes[i].copy(frustum.planes[i]);
  8586. }
  8587. return this;
  8588. };
  8589. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8590. var planes = this.planes;
  8591. var me = m.elements;
  8592. var me0 = me[0],
  8593. me1 = me[1],
  8594. me2 = me[2],
  8595. me3 = me[3];
  8596. var me4 = me[4],
  8597. me5 = me[5],
  8598. me6 = me[6],
  8599. me7 = me[7];
  8600. var me8 = me[8],
  8601. me9 = me[9],
  8602. me10 = me[10],
  8603. me11 = me[11];
  8604. var me12 = me[12],
  8605. me13 = me[13],
  8606. me14 = me[14],
  8607. me15 = me[15];
  8608. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8609. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8610. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8611. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8612. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8613. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8614. return this;
  8615. };
  8616. _proto.intersectsObject = function intersectsObject(object) {
  8617. var geometry = object.geometry;
  8618. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8619. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8620. return this.intersectsSphere(_sphere$1);
  8621. };
  8622. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8623. _sphere$1.center.set(0, 0, 0);
  8624. _sphere$1.radius = 0.7071067811865476;
  8625. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8626. return this.intersectsSphere(_sphere$1);
  8627. };
  8628. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8629. var planes = this.planes;
  8630. var center = sphere.center;
  8631. var negRadius = -sphere.radius;
  8632. for (var i = 0; i < 6; i++) {
  8633. var distance = planes[i].distanceToPoint(center);
  8634. if (distance < negRadius) {
  8635. return false;
  8636. }
  8637. }
  8638. return true;
  8639. };
  8640. _proto.intersectsBox = function intersectsBox(box) {
  8641. var planes = this.planes;
  8642. for (var i = 0; i < 6; i++) {
  8643. var plane = planes[i]; // corner at max distance
  8644. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8645. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8646. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8647. if (plane.distanceToPoint(_vector$5) < 0) {
  8648. return false;
  8649. }
  8650. }
  8651. return true;
  8652. };
  8653. _proto.containsPoint = function containsPoint(point) {
  8654. var planes = this.planes;
  8655. for (var i = 0; i < 6; i++) {
  8656. if (planes[i].distanceToPoint(point) < 0) {
  8657. return false;
  8658. }
  8659. }
  8660. return true;
  8661. };
  8662. _proto.clone = function clone() {
  8663. return new this.constructor().copy(this);
  8664. };
  8665. return Frustum;
  8666. }();
  8667. function WebGLAnimation() {
  8668. var context = null;
  8669. var isAnimating = false;
  8670. var animationLoop = null;
  8671. var requestId = null;
  8672. function onAnimationFrame(time, frame) {
  8673. animationLoop(time, frame);
  8674. requestId = context.requestAnimationFrame(onAnimationFrame);
  8675. }
  8676. return {
  8677. start: function start() {
  8678. if (isAnimating === true) return;
  8679. if (animationLoop === null) return;
  8680. requestId = context.requestAnimationFrame(onAnimationFrame);
  8681. isAnimating = true;
  8682. },
  8683. stop: function stop() {
  8684. context.cancelAnimationFrame(requestId);
  8685. isAnimating = false;
  8686. },
  8687. setAnimationLoop: function setAnimationLoop(callback) {
  8688. animationLoop = callback;
  8689. },
  8690. setContext: function setContext(value) {
  8691. context = value;
  8692. }
  8693. };
  8694. }
  8695. function WebGLAttributes(gl, capabilities) {
  8696. var isWebGL2 = capabilities.isWebGL2;
  8697. var buffers = new WeakMap();
  8698. function createBuffer(attribute, bufferType) {
  8699. var array = attribute.array;
  8700. var usage = attribute.usage;
  8701. var buffer = gl.createBuffer();
  8702. gl.bindBuffer(bufferType, buffer);
  8703. gl.bufferData(bufferType, array, usage);
  8704. attribute.onUploadCallback();
  8705. var type = 5126;
  8706. if (array instanceof Float32Array) {
  8707. type = 5126;
  8708. } else if (array instanceof Float64Array) {
  8709. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8710. } else if (array instanceof Uint16Array) {
  8711. if (attribute.isFloat16BufferAttribute) {
  8712. if (isWebGL2) {
  8713. type = 5131;
  8714. } else {
  8715. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8716. }
  8717. } else {
  8718. type = 5123;
  8719. }
  8720. } else if (array instanceof Int16Array) {
  8721. type = 5122;
  8722. } else if (array instanceof Uint32Array) {
  8723. type = 5125;
  8724. } else if (array instanceof Int32Array) {
  8725. type = 5124;
  8726. } else if (array instanceof Int8Array) {
  8727. type = 5120;
  8728. } else if (array instanceof Uint8Array) {
  8729. type = 5121;
  8730. }
  8731. return {
  8732. buffer: buffer,
  8733. type: type,
  8734. bytesPerElement: array.BYTES_PER_ELEMENT,
  8735. version: attribute.version
  8736. };
  8737. }
  8738. function updateBuffer(buffer, attribute, bufferType) {
  8739. var array = attribute.array;
  8740. var updateRange = attribute.updateRange;
  8741. gl.bindBuffer(bufferType, buffer);
  8742. if (updateRange.count === -1) {
  8743. // Not using update ranges
  8744. gl.bufferSubData(bufferType, 0, array);
  8745. } else {
  8746. if (isWebGL2) {
  8747. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8748. } else {
  8749. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8750. }
  8751. updateRange.count = -1; // reset range
  8752. }
  8753. } //
  8754. function get(attribute) {
  8755. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8756. return buffers.get(attribute);
  8757. }
  8758. function remove(attribute) {
  8759. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8760. var data = buffers.get(attribute);
  8761. if (data) {
  8762. gl.deleteBuffer(data.buffer);
  8763. buffers.delete(attribute);
  8764. }
  8765. }
  8766. function update(attribute, bufferType) {
  8767. if (attribute.isGLBufferAttribute) {
  8768. var cached = buffers.get(attribute);
  8769. if (!cached || cached.version < attribute.version) {
  8770. buffers.set(attribute, {
  8771. buffer: attribute.buffer,
  8772. type: attribute.type,
  8773. bytesPerElement: attribute.elementSize,
  8774. version: attribute.version
  8775. });
  8776. }
  8777. return;
  8778. }
  8779. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8780. var data = buffers.get(attribute);
  8781. if (data === undefined) {
  8782. buffers.set(attribute, createBuffer(attribute, bufferType));
  8783. } else if (data.version < attribute.version) {
  8784. updateBuffer(data.buffer, attribute, bufferType);
  8785. data.version = attribute.version;
  8786. }
  8787. }
  8788. return {
  8789. get: get,
  8790. remove: remove,
  8791. update: update
  8792. };
  8793. }
  8794. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8795. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8796. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8797. var _this;
  8798. if (width === void 0) {
  8799. width = 1;
  8800. }
  8801. if (height === void 0) {
  8802. height = 1;
  8803. }
  8804. if (widthSegments === void 0) {
  8805. widthSegments = 1;
  8806. }
  8807. if (heightSegments === void 0) {
  8808. heightSegments = 1;
  8809. }
  8810. _this = _BufferGeometry.call(this) || this;
  8811. _this.type = 'PlaneGeometry';
  8812. _this.parameters = {
  8813. width: width,
  8814. height: height,
  8815. widthSegments: widthSegments,
  8816. heightSegments: heightSegments
  8817. };
  8818. var width_half = width / 2;
  8819. var height_half = height / 2;
  8820. var gridX = Math.floor(widthSegments);
  8821. var gridY = Math.floor(heightSegments);
  8822. var gridX1 = gridX + 1;
  8823. var gridY1 = gridY + 1;
  8824. var segment_width = width / gridX;
  8825. var segment_height = height / gridY; //
  8826. var indices = [];
  8827. var vertices = [];
  8828. var normals = [];
  8829. var uvs = [];
  8830. for (var iy = 0; iy < gridY1; iy++) {
  8831. var y = iy * segment_height - height_half;
  8832. for (var ix = 0; ix < gridX1; ix++) {
  8833. var x = ix * segment_width - width_half;
  8834. vertices.push(x, -y, 0);
  8835. normals.push(0, 0, 1);
  8836. uvs.push(ix / gridX);
  8837. uvs.push(1 - iy / gridY);
  8838. }
  8839. }
  8840. for (var _iy = 0; _iy < gridY; _iy++) {
  8841. for (var _ix = 0; _ix < gridX; _ix++) {
  8842. var a = _ix + gridX1 * _iy;
  8843. var b = _ix + gridX1 * (_iy + 1);
  8844. var c = _ix + 1 + gridX1 * (_iy + 1);
  8845. var d = _ix + 1 + gridX1 * _iy;
  8846. indices.push(a, b, d);
  8847. indices.push(b, c, d);
  8848. }
  8849. }
  8850. _this.setIndex(indices);
  8851. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8852. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8853. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8854. return _this;
  8855. }
  8856. return PlaneGeometry;
  8857. }(BufferGeometry);
  8858. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8859. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8860. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8861. 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";
  8862. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8863. var begin_vertex = "vec3 transformed = vec3( position );";
  8864. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8865. 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";
  8866. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  8867. 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";
  8868. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8869. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8870. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8871. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8872. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8873. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8874. 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";
  8875. 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}";
  8876. 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";
  8877. 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";
  8878. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8879. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8880. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8881. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8882. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8883. 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}";
  8884. 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";
  8885. 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";
  8886. 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";
  8887. 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";
  8888. 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";
  8889. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8890. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8891. 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";
  8892. 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";
  8893. 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}";
  8894. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8895. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8896. 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";
  8897. 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";
  8898. 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";
  8899. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8900. 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)";
  8901. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8902. 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)";
  8903. 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";
  8904. 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}";
  8905. 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";
  8906. 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";
  8907. 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";
  8908. 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";
  8909. 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";
  8910. 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";
  8911. 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";
  8912. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8913. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8914. 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";
  8915. 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";
  8916. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8917. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8918. 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";
  8919. 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";
  8920. 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";
  8921. var normal_fragment_begin = "float faceDirection = float( gl_FrontFacing ) * 2.0 - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * faceDirection;\n\t\t\tbitangent = bitangent * faceDirection;\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  8922. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN, faceDirection );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif";
  8923. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= faceDirection;\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8924. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8925. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );\n\t#endif\n#endif";
  8926. 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";
  8927. 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}";
  8928. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8929. 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;";
  8930. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8931. 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";
  8932. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8933. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8934. 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";
  8935. 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";
  8936. 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";
  8937. 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}";
  8938. 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";
  8939. 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";
  8940. 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";
  8941. 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";
  8942. 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";
  8943. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8944. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8945. 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; }";
  8946. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8947. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8948. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8949. 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";
  8950. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8951. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8952. 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";
  8953. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8954. 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";
  8955. 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}";
  8956. 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}";
  8957. 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}";
  8958. 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}";
  8959. 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}";
  8960. 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}";
  8961. 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}";
  8962. 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}";
  8963. 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}";
  8964. 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}";
  8965. 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}";
  8966. 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}";
  8967. 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}";
  8968. 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}";
  8969. 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}";
  8970. 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}";
  8971. 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}";
  8972. 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}";
  8973. 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}";
  8974. 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}";
  8975. 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}";
  8976. 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}";
  8977. 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}";
  8978. 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}";
  8979. 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}";
  8980. 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}";
  8981. 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}";
  8982. 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}";
  8983. 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}";
  8984. 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}";
  8985. 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}";
  8986. 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}";
  8987. var ShaderChunk = {
  8988. alphamap_fragment: alphamap_fragment,
  8989. alphamap_pars_fragment: alphamap_pars_fragment,
  8990. alphatest_fragment: alphatest_fragment,
  8991. aomap_fragment: aomap_fragment,
  8992. aomap_pars_fragment: aomap_pars_fragment,
  8993. begin_vertex: begin_vertex,
  8994. beginnormal_vertex: beginnormal_vertex,
  8995. bsdfs: bsdfs,
  8996. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8997. clipping_planes_fragment: clipping_planes_fragment,
  8998. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8999. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  9000. clipping_planes_vertex: clipping_planes_vertex,
  9001. color_fragment: color_fragment,
  9002. color_pars_fragment: color_pars_fragment,
  9003. color_pars_vertex: color_pars_vertex,
  9004. color_vertex: color_vertex,
  9005. common: common,
  9006. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  9007. defaultnormal_vertex: defaultnormal_vertex,
  9008. displacementmap_pars_vertex: displacementmap_pars_vertex,
  9009. displacementmap_vertex: displacementmap_vertex,
  9010. emissivemap_fragment: emissivemap_fragment,
  9011. emissivemap_pars_fragment: emissivemap_pars_fragment,
  9012. encodings_fragment: encodings_fragment,
  9013. encodings_pars_fragment: encodings_pars_fragment,
  9014. envmap_fragment: envmap_fragment,
  9015. envmap_common_pars_fragment: envmap_common_pars_fragment,
  9016. envmap_pars_fragment: envmap_pars_fragment,
  9017. envmap_pars_vertex: envmap_pars_vertex,
  9018. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  9019. envmap_vertex: envmap_vertex,
  9020. fog_vertex: fog_vertex,
  9021. fog_pars_vertex: fog_pars_vertex,
  9022. fog_fragment: fog_fragment,
  9023. fog_pars_fragment: fog_pars_fragment,
  9024. gradientmap_pars_fragment: gradientmap_pars_fragment,
  9025. lightmap_fragment: lightmap_fragment,
  9026. lightmap_pars_fragment: lightmap_pars_fragment,
  9027. lights_lambert_vertex: lights_lambert_vertex,
  9028. lights_pars_begin: lights_pars_begin,
  9029. lights_toon_fragment: lights_toon_fragment,
  9030. lights_toon_pars_fragment: lights_toon_pars_fragment,
  9031. lights_phong_fragment: lights_phong_fragment,
  9032. lights_phong_pars_fragment: lights_phong_pars_fragment,
  9033. lights_physical_fragment: lights_physical_fragment,
  9034. lights_physical_pars_fragment: lights_physical_pars_fragment,
  9035. lights_fragment_begin: lights_fragment_begin,
  9036. lights_fragment_maps: lights_fragment_maps,
  9037. lights_fragment_end: lights_fragment_end,
  9038. logdepthbuf_fragment: logdepthbuf_fragment,
  9039. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9040. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9041. logdepthbuf_vertex: logdepthbuf_vertex,
  9042. map_fragment: map_fragment,
  9043. map_pars_fragment: map_pars_fragment,
  9044. map_particle_fragment: map_particle_fragment,
  9045. map_particle_pars_fragment: map_particle_pars_fragment,
  9046. metalnessmap_fragment: metalnessmap_fragment,
  9047. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9048. morphnormal_vertex: morphnormal_vertex,
  9049. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9050. morphtarget_vertex: morphtarget_vertex,
  9051. normal_fragment_begin: normal_fragment_begin,
  9052. normal_fragment_maps: normal_fragment_maps,
  9053. normalmap_pars_fragment: normalmap_pars_fragment,
  9054. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9055. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9056. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9057. packing: packing,
  9058. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9059. project_vertex: project_vertex,
  9060. dithering_fragment: dithering_fragment,
  9061. dithering_pars_fragment: dithering_pars_fragment,
  9062. roughnessmap_fragment: roughnessmap_fragment,
  9063. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9064. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9065. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9066. shadowmap_vertex: shadowmap_vertex,
  9067. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9068. skinbase_vertex: skinbase_vertex,
  9069. skinning_pars_vertex: skinning_pars_vertex,
  9070. skinning_vertex: skinning_vertex,
  9071. skinnormal_vertex: skinnormal_vertex,
  9072. specularmap_fragment: specularmap_fragment,
  9073. specularmap_pars_fragment: specularmap_pars_fragment,
  9074. tonemapping_fragment: tonemapping_fragment,
  9075. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9076. transmissionmap_fragment: transmissionmap_fragment,
  9077. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  9078. uv_pars_fragment: uv_pars_fragment,
  9079. uv_pars_vertex: uv_pars_vertex,
  9080. uv_vertex: uv_vertex,
  9081. uv2_pars_fragment: uv2_pars_fragment,
  9082. uv2_pars_vertex: uv2_pars_vertex,
  9083. uv2_vertex: uv2_vertex,
  9084. worldpos_vertex: worldpos_vertex,
  9085. background_frag: background_frag,
  9086. background_vert: background_vert,
  9087. cube_frag: cube_frag,
  9088. cube_vert: cube_vert,
  9089. depth_frag: depth_frag,
  9090. depth_vert: depth_vert,
  9091. distanceRGBA_frag: distanceRGBA_frag,
  9092. distanceRGBA_vert: distanceRGBA_vert,
  9093. equirect_frag: equirect_frag,
  9094. equirect_vert: equirect_vert,
  9095. linedashed_frag: linedashed_frag,
  9096. linedashed_vert: linedashed_vert,
  9097. meshbasic_frag: meshbasic_frag,
  9098. meshbasic_vert: meshbasic_vert,
  9099. meshlambert_frag: meshlambert_frag,
  9100. meshlambert_vert: meshlambert_vert,
  9101. meshmatcap_frag: meshmatcap_frag,
  9102. meshmatcap_vert: meshmatcap_vert,
  9103. meshtoon_frag: meshtoon_frag,
  9104. meshtoon_vert: meshtoon_vert,
  9105. meshphong_frag: meshphong_frag,
  9106. meshphong_vert: meshphong_vert,
  9107. meshphysical_frag: meshphysical_frag,
  9108. meshphysical_vert: meshphysical_vert,
  9109. normal_frag: normal_frag,
  9110. normal_vert: normal_vert,
  9111. points_frag: points_frag,
  9112. points_vert: points_vert,
  9113. shadow_frag: shadow_frag,
  9114. shadow_vert: shadow_vert,
  9115. sprite_frag: sprite_frag,
  9116. sprite_vert: sprite_vert
  9117. };
  9118. /**
  9119. * Uniforms library for shared webgl shaders
  9120. */
  9121. var UniformsLib = {
  9122. common: {
  9123. diffuse: {
  9124. value: new Color(0xeeeeee)
  9125. },
  9126. opacity: {
  9127. value: 1.0
  9128. },
  9129. map: {
  9130. value: null
  9131. },
  9132. uvTransform: {
  9133. value: new Matrix3()
  9134. },
  9135. uv2Transform: {
  9136. value: new Matrix3()
  9137. },
  9138. alphaMap: {
  9139. value: null
  9140. }
  9141. },
  9142. specularmap: {
  9143. specularMap: {
  9144. value: null
  9145. }
  9146. },
  9147. envmap: {
  9148. envMap: {
  9149. value: null
  9150. },
  9151. flipEnvMap: {
  9152. value: -1
  9153. },
  9154. reflectivity: {
  9155. value: 1.0
  9156. },
  9157. refractionRatio: {
  9158. value: 0.98
  9159. },
  9160. maxMipLevel: {
  9161. value: 0
  9162. }
  9163. },
  9164. aomap: {
  9165. aoMap: {
  9166. value: null
  9167. },
  9168. aoMapIntensity: {
  9169. value: 1
  9170. }
  9171. },
  9172. lightmap: {
  9173. lightMap: {
  9174. value: null
  9175. },
  9176. lightMapIntensity: {
  9177. value: 1
  9178. }
  9179. },
  9180. emissivemap: {
  9181. emissiveMap: {
  9182. value: null
  9183. }
  9184. },
  9185. bumpmap: {
  9186. bumpMap: {
  9187. value: null
  9188. },
  9189. bumpScale: {
  9190. value: 1
  9191. }
  9192. },
  9193. normalmap: {
  9194. normalMap: {
  9195. value: null
  9196. },
  9197. normalScale: {
  9198. value: new Vector2(1, 1)
  9199. }
  9200. },
  9201. displacementmap: {
  9202. displacementMap: {
  9203. value: null
  9204. },
  9205. displacementScale: {
  9206. value: 1
  9207. },
  9208. displacementBias: {
  9209. value: 0
  9210. }
  9211. },
  9212. roughnessmap: {
  9213. roughnessMap: {
  9214. value: null
  9215. }
  9216. },
  9217. metalnessmap: {
  9218. metalnessMap: {
  9219. value: null
  9220. }
  9221. },
  9222. gradientmap: {
  9223. gradientMap: {
  9224. value: null
  9225. }
  9226. },
  9227. fog: {
  9228. fogDensity: {
  9229. value: 0.00025
  9230. },
  9231. fogNear: {
  9232. value: 1
  9233. },
  9234. fogFar: {
  9235. value: 2000
  9236. },
  9237. fogColor: {
  9238. value: new Color(0xffffff)
  9239. }
  9240. },
  9241. lights: {
  9242. ambientLightColor: {
  9243. value: []
  9244. },
  9245. lightProbe: {
  9246. value: []
  9247. },
  9248. directionalLights: {
  9249. value: [],
  9250. properties: {
  9251. direction: {},
  9252. color: {}
  9253. }
  9254. },
  9255. directionalLightShadows: {
  9256. value: [],
  9257. properties: {
  9258. shadowBias: {},
  9259. shadowNormalBias: {},
  9260. shadowRadius: {},
  9261. shadowMapSize: {}
  9262. }
  9263. },
  9264. directionalShadowMap: {
  9265. value: []
  9266. },
  9267. directionalShadowMatrix: {
  9268. value: []
  9269. },
  9270. spotLights: {
  9271. value: [],
  9272. properties: {
  9273. color: {},
  9274. position: {},
  9275. direction: {},
  9276. distance: {},
  9277. coneCos: {},
  9278. penumbraCos: {},
  9279. decay: {}
  9280. }
  9281. },
  9282. spotLightShadows: {
  9283. value: [],
  9284. properties: {
  9285. shadowBias: {},
  9286. shadowNormalBias: {},
  9287. shadowRadius: {},
  9288. shadowMapSize: {}
  9289. }
  9290. },
  9291. spotShadowMap: {
  9292. value: []
  9293. },
  9294. spotShadowMatrix: {
  9295. value: []
  9296. },
  9297. pointLights: {
  9298. value: [],
  9299. properties: {
  9300. color: {},
  9301. position: {},
  9302. decay: {},
  9303. distance: {}
  9304. }
  9305. },
  9306. pointLightShadows: {
  9307. value: [],
  9308. properties: {
  9309. shadowBias: {},
  9310. shadowNormalBias: {},
  9311. shadowRadius: {},
  9312. shadowMapSize: {},
  9313. shadowCameraNear: {},
  9314. shadowCameraFar: {}
  9315. }
  9316. },
  9317. pointShadowMap: {
  9318. value: []
  9319. },
  9320. pointShadowMatrix: {
  9321. value: []
  9322. },
  9323. hemisphereLights: {
  9324. value: [],
  9325. properties: {
  9326. direction: {},
  9327. skyColor: {},
  9328. groundColor: {}
  9329. }
  9330. },
  9331. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9332. rectAreaLights: {
  9333. value: [],
  9334. properties: {
  9335. color: {},
  9336. position: {},
  9337. width: {},
  9338. height: {}
  9339. }
  9340. },
  9341. ltc_1: {
  9342. value: null
  9343. },
  9344. ltc_2: {
  9345. value: null
  9346. }
  9347. },
  9348. points: {
  9349. diffuse: {
  9350. value: new Color(0xeeeeee)
  9351. },
  9352. opacity: {
  9353. value: 1.0
  9354. },
  9355. size: {
  9356. value: 1.0
  9357. },
  9358. scale: {
  9359. value: 1.0
  9360. },
  9361. map: {
  9362. value: null
  9363. },
  9364. alphaMap: {
  9365. value: null
  9366. },
  9367. uvTransform: {
  9368. value: new Matrix3()
  9369. }
  9370. },
  9371. sprite: {
  9372. diffuse: {
  9373. value: new Color(0xeeeeee)
  9374. },
  9375. opacity: {
  9376. value: 1.0
  9377. },
  9378. center: {
  9379. value: new Vector2(0.5, 0.5)
  9380. },
  9381. rotation: {
  9382. value: 0.0
  9383. },
  9384. map: {
  9385. value: null
  9386. },
  9387. alphaMap: {
  9388. value: null
  9389. },
  9390. uvTransform: {
  9391. value: new Matrix3()
  9392. }
  9393. }
  9394. };
  9395. var ShaderLib = {
  9396. basic: {
  9397. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  9398. vertexShader: ShaderChunk.meshbasic_vert,
  9399. fragmentShader: ShaderChunk.meshbasic_frag
  9400. },
  9401. lambert: {
  9402. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  9403. emissive: {
  9404. value: new Color(0x000000)
  9405. }
  9406. }]),
  9407. vertexShader: ShaderChunk.meshlambert_vert,
  9408. fragmentShader: ShaderChunk.meshlambert_frag
  9409. },
  9410. phong: {
  9411. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  9412. emissive: {
  9413. value: new Color(0x000000)
  9414. },
  9415. specular: {
  9416. value: new Color(0x111111)
  9417. },
  9418. shininess: {
  9419. value: 30
  9420. }
  9421. }]),
  9422. vertexShader: ShaderChunk.meshphong_vert,
  9423. fragmentShader: ShaderChunk.meshphong_frag
  9424. },
  9425. standard: {
  9426. 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, {
  9427. emissive: {
  9428. value: new Color(0x000000)
  9429. },
  9430. roughness: {
  9431. value: 1.0
  9432. },
  9433. metalness: {
  9434. value: 0.0
  9435. },
  9436. envMapIntensity: {
  9437. value: 1
  9438. } // temporary
  9439. }]),
  9440. vertexShader: ShaderChunk.meshphysical_vert,
  9441. fragmentShader: ShaderChunk.meshphysical_frag
  9442. },
  9443. toon: {
  9444. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  9445. emissive: {
  9446. value: new Color(0x000000)
  9447. }
  9448. }]),
  9449. vertexShader: ShaderChunk.meshtoon_vert,
  9450. fragmentShader: ShaderChunk.meshtoon_frag
  9451. },
  9452. matcap: {
  9453. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  9454. matcap: {
  9455. value: null
  9456. }
  9457. }]),
  9458. vertexShader: ShaderChunk.meshmatcap_vert,
  9459. fragmentShader: ShaderChunk.meshmatcap_frag
  9460. },
  9461. points: {
  9462. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  9463. vertexShader: ShaderChunk.points_vert,
  9464. fragmentShader: ShaderChunk.points_frag
  9465. },
  9466. dashed: {
  9467. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  9468. scale: {
  9469. value: 1
  9470. },
  9471. dashSize: {
  9472. value: 1
  9473. },
  9474. totalSize: {
  9475. value: 2
  9476. }
  9477. }]),
  9478. vertexShader: ShaderChunk.linedashed_vert,
  9479. fragmentShader: ShaderChunk.linedashed_frag
  9480. },
  9481. depth: {
  9482. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  9483. vertexShader: ShaderChunk.depth_vert,
  9484. fragmentShader: ShaderChunk.depth_frag
  9485. },
  9486. normal: {
  9487. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  9488. opacity: {
  9489. value: 1.0
  9490. }
  9491. }]),
  9492. vertexShader: ShaderChunk.normal_vert,
  9493. fragmentShader: ShaderChunk.normal_frag
  9494. },
  9495. sprite: {
  9496. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  9497. vertexShader: ShaderChunk.sprite_vert,
  9498. fragmentShader: ShaderChunk.sprite_frag
  9499. },
  9500. background: {
  9501. uniforms: {
  9502. uvTransform: {
  9503. value: new Matrix3()
  9504. },
  9505. t2D: {
  9506. value: null
  9507. }
  9508. },
  9509. vertexShader: ShaderChunk.background_vert,
  9510. fragmentShader: ShaderChunk.background_frag
  9511. },
  9512. /* -------------------------------------------------------------------------
  9513. // Cube map shader
  9514. ------------------------------------------------------------------------- */
  9515. cube: {
  9516. uniforms: mergeUniforms([UniformsLib.envmap, {
  9517. opacity: {
  9518. value: 1.0
  9519. }
  9520. }]),
  9521. vertexShader: ShaderChunk.cube_vert,
  9522. fragmentShader: ShaderChunk.cube_frag
  9523. },
  9524. equirect: {
  9525. uniforms: {
  9526. tEquirect: {
  9527. value: null
  9528. }
  9529. },
  9530. vertexShader: ShaderChunk.equirect_vert,
  9531. fragmentShader: ShaderChunk.equirect_frag
  9532. },
  9533. distanceRGBA: {
  9534. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9535. referencePosition: {
  9536. value: new Vector3()
  9537. },
  9538. nearDistance: {
  9539. value: 1
  9540. },
  9541. farDistance: {
  9542. value: 1000
  9543. }
  9544. }]),
  9545. vertexShader: ShaderChunk.distanceRGBA_vert,
  9546. fragmentShader: ShaderChunk.distanceRGBA_frag
  9547. },
  9548. shadow: {
  9549. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9550. color: {
  9551. value: new Color(0x00000)
  9552. },
  9553. opacity: {
  9554. value: 1.0
  9555. }
  9556. }]),
  9557. vertexShader: ShaderChunk.shadow_vert,
  9558. fragmentShader: ShaderChunk.shadow_frag
  9559. }
  9560. };
  9561. ShaderLib.physical = {
  9562. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9563. clearcoat: {
  9564. value: 0
  9565. },
  9566. clearcoatMap: {
  9567. value: null
  9568. },
  9569. clearcoatRoughness: {
  9570. value: 0
  9571. },
  9572. clearcoatRoughnessMap: {
  9573. value: null
  9574. },
  9575. clearcoatNormalScale: {
  9576. value: new Vector2(1, 1)
  9577. },
  9578. clearcoatNormalMap: {
  9579. value: null
  9580. },
  9581. sheen: {
  9582. value: new Color(0x000000)
  9583. },
  9584. transmission: {
  9585. value: 0
  9586. },
  9587. transmissionMap: {
  9588. value: null
  9589. }
  9590. }]),
  9591. vertexShader: ShaderChunk.meshphysical_vert,
  9592. fragmentShader: ShaderChunk.meshphysical_frag
  9593. };
  9594. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9595. var clearColor = new Color(0x000000);
  9596. var clearAlpha = 0;
  9597. var planeMesh;
  9598. var boxMesh;
  9599. var currentBackground = null;
  9600. var currentBackgroundVersion = 0;
  9601. var currentTonemapping = null;
  9602. function render(renderList, scene, camera, forceClear) {
  9603. var background = scene.isScene === true ? scene.background : null;
  9604. if (background && background.isTexture) {
  9605. background = cubemaps.get(background);
  9606. } // Ignore background in AR
  9607. // TODO: Reconsider this.
  9608. var xr = renderer.xr;
  9609. var session = xr.getSession && xr.getSession();
  9610. if (session && session.environmentBlendMode === 'additive') {
  9611. background = null;
  9612. }
  9613. if (background === null) {
  9614. setClear(clearColor, clearAlpha);
  9615. } else if (background && background.isColor) {
  9616. setClear(background, 1);
  9617. forceClear = true;
  9618. }
  9619. if (renderer.autoClear || forceClear) {
  9620. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9621. }
  9622. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9623. if (boxMesh === undefined) {
  9624. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9625. name: 'BackgroundCubeMaterial',
  9626. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9627. vertexShader: ShaderLib.cube.vertexShader,
  9628. fragmentShader: ShaderLib.cube.fragmentShader,
  9629. side: BackSide,
  9630. depthTest: false,
  9631. depthWrite: false,
  9632. fog: false
  9633. }));
  9634. boxMesh.geometry.deleteAttribute('normal');
  9635. boxMesh.geometry.deleteAttribute('uv');
  9636. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9637. this.matrixWorld.copyPosition(camera.matrixWorld);
  9638. }; // enable code injection for non-built-in material
  9639. Object.defineProperty(boxMesh.material, 'envMap', {
  9640. get: function get() {
  9641. return this.uniforms.envMap.value;
  9642. }
  9643. });
  9644. objects.update(boxMesh);
  9645. }
  9646. if (background.isWebGLCubeRenderTarget) {
  9647. // TODO Deprecate
  9648. background = background.texture;
  9649. }
  9650. boxMesh.material.uniforms.envMap.value = background;
  9651. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9652. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9653. boxMesh.material.needsUpdate = true;
  9654. currentBackground = background;
  9655. currentBackgroundVersion = background.version;
  9656. currentTonemapping = renderer.toneMapping;
  9657. } // push to the pre-sorted opaque render list
  9658. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9659. } else if (background && background.isTexture) {
  9660. if (planeMesh === undefined) {
  9661. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9662. name: 'BackgroundMaterial',
  9663. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9664. vertexShader: ShaderLib.background.vertexShader,
  9665. fragmentShader: ShaderLib.background.fragmentShader,
  9666. side: FrontSide,
  9667. depthTest: false,
  9668. depthWrite: false,
  9669. fog: false
  9670. }));
  9671. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9672. Object.defineProperty(planeMesh.material, 'map', {
  9673. get: function get() {
  9674. return this.uniforms.t2D.value;
  9675. }
  9676. });
  9677. objects.update(planeMesh);
  9678. }
  9679. planeMesh.material.uniforms.t2D.value = background;
  9680. if (background.matrixAutoUpdate === true) {
  9681. background.updateMatrix();
  9682. }
  9683. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9684. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9685. planeMesh.material.needsUpdate = true;
  9686. currentBackground = background;
  9687. currentBackgroundVersion = background.version;
  9688. currentTonemapping = renderer.toneMapping;
  9689. } // push to the pre-sorted opaque render list
  9690. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9691. }
  9692. }
  9693. function setClear(color, alpha) {
  9694. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9695. }
  9696. return {
  9697. getClearColor: function getClearColor() {
  9698. return clearColor;
  9699. },
  9700. setClearColor: function setClearColor(color, alpha) {
  9701. if (alpha === void 0) {
  9702. alpha = 1;
  9703. }
  9704. clearColor.set(color);
  9705. clearAlpha = alpha;
  9706. setClear(clearColor, clearAlpha);
  9707. },
  9708. getClearAlpha: function getClearAlpha() {
  9709. return clearAlpha;
  9710. },
  9711. setClearAlpha: function setClearAlpha(alpha) {
  9712. clearAlpha = alpha;
  9713. setClear(clearColor, clearAlpha);
  9714. },
  9715. render: render
  9716. };
  9717. }
  9718. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9719. var maxVertexAttributes = gl.getParameter(34921);
  9720. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9721. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9722. var bindingStates = {};
  9723. var defaultState = createBindingState(null);
  9724. var currentState = defaultState;
  9725. function setup(object, material, program, geometry, index) {
  9726. var updateBuffers = false;
  9727. if (vaoAvailable) {
  9728. var state = getBindingState(geometry, program, material);
  9729. if (currentState !== state) {
  9730. currentState = state;
  9731. bindVertexArrayObject(currentState.object);
  9732. }
  9733. updateBuffers = needsUpdate(geometry, index);
  9734. if (updateBuffers) saveCache(geometry, index);
  9735. } else {
  9736. var wireframe = material.wireframe === true;
  9737. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9738. currentState.geometry = geometry.id;
  9739. currentState.program = program.id;
  9740. currentState.wireframe = wireframe;
  9741. updateBuffers = true;
  9742. }
  9743. }
  9744. if (object.isInstancedMesh === true) {
  9745. updateBuffers = true;
  9746. }
  9747. if (index !== null) {
  9748. attributes.update(index, 34963);
  9749. }
  9750. if (updateBuffers) {
  9751. setupVertexAttributes(object, material, program, geometry);
  9752. if (index !== null) {
  9753. gl.bindBuffer(34963, attributes.get(index).buffer);
  9754. }
  9755. }
  9756. }
  9757. function createVertexArrayObject() {
  9758. if (capabilities.isWebGL2) return gl.createVertexArray();
  9759. return extension.createVertexArrayOES();
  9760. }
  9761. function bindVertexArrayObject(vao) {
  9762. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9763. return extension.bindVertexArrayOES(vao);
  9764. }
  9765. function deleteVertexArrayObject(vao) {
  9766. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9767. return extension.deleteVertexArrayOES(vao);
  9768. }
  9769. function getBindingState(geometry, program, material) {
  9770. var wireframe = material.wireframe === true;
  9771. var programMap = bindingStates[geometry.id];
  9772. if (programMap === undefined) {
  9773. programMap = {};
  9774. bindingStates[geometry.id] = programMap;
  9775. }
  9776. var stateMap = programMap[program.id];
  9777. if (stateMap === undefined) {
  9778. stateMap = {};
  9779. programMap[program.id] = stateMap;
  9780. }
  9781. var state = stateMap[wireframe];
  9782. if (state === undefined) {
  9783. state = createBindingState(createVertexArrayObject());
  9784. stateMap[wireframe] = state;
  9785. }
  9786. return state;
  9787. }
  9788. function createBindingState(vao) {
  9789. var newAttributes = [];
  9790. var enabledAttributes = [];
  9791. var attributeDivisors = [];
  9792. for (var i = 0; i < maxVertexAttributes; i++) {
  9793. newAttributes[i] = 0;
  9794. enabledAttributes[i] = 0;
  9795. attributeDivisors[i] = 0;
  9796. }
  9797. return {
  9798. // for backward compatibility on non-VAO support browser
  9799. geometry: null,
  9800. program: null,
  9801. wireframe: false,
  9802. newAttributes: newAttributes,
  9803. enabledAttributes: enabledAttributes,
  9804. attributeDivisors: attributeDivisors,
  9805. object: vao,
  9806. attributes: {},
  9807. index: null
  9808. };
  9809. }
  9810. function needsUpdate(geometry, index) {
  9811. var cachedAttributes = currentState.attributes;
  9812. var geometryAttributes = geometry.attributes;
  9813. var attributesNum = 0;
  9814. for (var key in geometryAttributes) {
  9815. var cachedAttribute = cachedAttributes[key];
  9816. var geometryAttribute = geometryAttributes[key];
  9817. if (cachedAttribute === undefined) return true;
  9818. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9819. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9820. attributesNum++;
  9821. }
  9822. if (currentState.attributesNum !== attributesNum) return true;
  9823. if (currentState.index !== index) return true;
  9824. return false;
  9825. }
  9826. function saveCache(geometry, index) {
  9827. var cache = {};
  9828. var attributes = geometry.attributes;
  9829. var attributesNum = 0;
  9830. for (var key in attributes) {
  9831. var attribute = attributes[key];
  9832. var data = {};
  9833. data.attribute = attribute;
  9834. if (attribute.data) {
  9835. data.data = attribute.data;
  9836. }
  9837. cache[key] = data;
  9838. attributesNum++;
  9839. }
  9840. currentState.attributes = cache;
  9841. currentState.attributesNum = attributesNum;
  9842. currentState.index = index;
  9843. }
  9844. function initAttributes() {
  9845. var newAttributes = currentState.newAttributes;
  9846. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9847. newAttributes[i] = 0;
  9848. }
  9849. }
  9850. function enableAttribute(attribute) {
  9851. enableAttributeAndDivisor(attribute, 0);
  9852. }
  9853. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9854. var newAttributes = currentState.newAttributes;
  9855. var enabledAttributes = currentState.enabledAttributes;
  9856. var attributeDivisors = currentState.attributeDivisors;
  9857. newAttributes[attribute] = 1;
  9858. if (enabledAttributes[attribute] === 0) {
  9859. gl.enableVertexAttribArray(attribute);
  9860. enabledAttributes[attribute] = 1;
  9861. }
  9862. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9863. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9864. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9865. attributeDivisors[attribute] = meshPerAttribute;
  9866. }
  9867. }
  9868. function disableUnusedAttributes() {
  9869. var newAttributes = currentState.newAttributes;
  9870. var enabledAttributes = currentState.enabledAttributes;
  9871. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9872. if (enabledAttributes[i] !== newAttributes[i]) {
  9873. gl.disableVertexAttribArray(i);
  9874. enabledAttributes[i] = 0;
  9875. }
  9876. }
  9877. }
  9878. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9879. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9880. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9881. } else {
  9882. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9883. }
  9884. }
  9885. function setupVertexAttributes(object, material, program, geometry) {
  9886. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9887. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9888. }
  9889. initAttributes();
  9890. var geometryAttributes = geometry.attributes;
  9891. var programAttributes = program.getAttributes();
  9892. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9893. for (var name in programAttributes) {
  9894. var programAttribute = programAttributes[name];
  9895. if (programAttribute >= 0) {
  9896. var geometryAttribute = geometryAttributes[name];
  9897. if (geometryAttribute !== undefined) {
  9898. var normalized = geometryAttribute.normalized;
  9899. var size = geometryAttribute.itemSize;
  9900. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9901. if (attribute === undefined) continue;
  9902. var buffer = attribute.buffer;
  9903. var type = attribute.type;
  9904. var bytesPerElement = attribute.bytesPerElement;
  9905. if (geometryAttribute.isInterleavedBufferAttribute) {
  9906. var data = geometryAttribute.data;
  9907. var stride = data.stride;
  9908. var offset = geometryAttribute.offset;
  9909. if (data && data.isInstancedInterleavedBuffer) {
  9910. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9911. if (geometry._maxInstanceCount === undefined) {
  9912. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9913. }
  9914. } else {
  9915. enableAttribute(programAttribute);
  9916. }
  9917. gl.bindBuffer(34962, buffer);
  9918. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9919. } else {
  9920. if (geometryAttribute.isInstancedBufferAttribute) {
  9921. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9922. if (geometry._maxInstanceCount === undefined) {
  9923. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9924. }
  9925. } else {
  9926. enableAttribute(programAttribute);
  9927. }
  9928. gl.bindBuffer(34962, buffer);
  9929. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9930. }
  9931. } else if (name === 'instanceMatrix') {
  9932. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9933. if (_attribute === undefined) continue;
  9934. var _buffer = _attribute.buffer;
  9935. var _type = _attribute.type;
  9936. enableAttributeAndDivisor(programAttribute + 0, 1);
  9937. enableAttributeAndDivisor(programAttribute + 1, 1);
  9938. enableAttributeAndDivisor(programAttribute + 2, 1);
  9939. enableAttributeAndDivisor(programAttribute + 3, 1);
  9940. gl.bindBuffer(34962, _buffer);
  9941. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9942. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9943. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9944. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9945. } else if (name === 'instanceColor') {
  9946. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9947. if (_attribute2 === undefined) continue;
  9948. var _buffer2 = _attribute2.buffer;
  9949. var _type2 = _attribute2.type;
  9950. enableAttributeAndDivisor(programAttribute, 1);
  9951. gl.bindBuffer(34962, _buffer2);
  9952. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9953. } else if (materialDefaultAttributeValues !== undefined) {
  9954. var value = materialDefaultAttributeValues[name];
  9955. if (value !== undefined) {
  9956. switch (value.length) {
  9957. case 2:
  9958. gl.vertexAttrib2fv(programAttribute, value);
  9959. break;
  9960. case 3:
  9961. gl.vertexAttrib3fv(programAttribute, value);
  9962. break;
  9963. case 4:
  9964. gl.vertexAttrib4fv(programAttribute, value);
  9965. break;
  9966. default:
  9967. gl.vertexAttrib1fv(programAttribute, value);
  9968. }
  9969. }
  9970. }
  9971. }
  9972. }
  9973. disableUnusedAttributes();
  9974. }
  9975. function dispose() {
  9976. reset();
  9977. for (var geometryId in bindingStates) {
  9978. var programMap = bindingStates[geometryId];
  9979. for (var programId in programMap) {
  9980. var stateMap = programMap[programId];
  9981. for (var wireframe in stateMap) {
  9982. deleteVertexArrayObject(stateMap[wireframe].object);
  9983. delete stateMap[wireframe];
  9984. }
  9985. delete programMap[programId];
  9986. }
  9987. delete bindingStates[geometryId];
  9988. }
  9989. }
  9990. function releaseStatesOfGeometry(geometry) {
  9991. if (bindingStates[geometry.id] === undefined) return;
  9992. var programMap = bindingStates[geometry.id];
  9993. for (var programId in programMap) {
  9994. var stateMap = programMap[programId];
  9995. for (var wireframe in stateMap) {
  9996. deleteVertexArrayObject(stateMap[wireframe].object);
  9997. delete stateMap[wireframe];
  9998. }
  9999. delete programMap[programId];
  10000. }
  10001. delete bindingStates[geometry.id];
  10002. }
  10003. function releaseStatesOfProgram(program) {
  10004. for (var geometryId in bindingStates) {
  10005. var programMap = bindingStates[geometryId];
  10006. if (programMap[program.id] === undefined) continue;
  10007. var stateMap = programMap[program.id];
  10008. for (var wireframe in stateMap) {
  10009. deleteVertexArrayObject(stateMap[wireframe].object);
  10010. delete stateMap[wireframe];
  10011. }
  10012. delete programMap[program.id];
  10013. }
  10014. }
  10015. function reset() {
  10016. resetDefaultState();
  10017. if (currentState === defaultState) return;
  10018. currentState = defaultState;
  10019. bindVertexArrayObject(currentState.object);
  10020. } // for backward-compatilibity
  10021. function resetDefaultState() {
  10022. defaultState.geometry = null;
  10023. defaultState.program = null;
  10024. defaultState.wireframe = false;
  10025. }
  10026. return {
  10027. setup: setup,
  10028. reset: reset,
  10029. resetDefaultState: resetDefaultState,
  10030. dispose: dispose,
  10031. releaseStatesOfGeometry: releaseStatesOfGeometry,
  10032. releaseStatesOfProgram: releaseStatesOfProgram,
  10033. initAttributes: initAttributes,
  10034. enableAttribute: enableAttribute,
  10035. disableUnusedAttributes: disableUnusedAttributes
  10036. };
  10037. }
  10038. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  10039. var isWebGL2 = capabilities.isWebGL2;
  10040. var mode;
  10041. function setMode(value) {
  10042. mode = value;
  10043. }
  10044. function render(start, count) {
  10045. gl.drawArrays(mode, start, count);
  10046. info.update(count, mode, 1);
  10047. }
  10048. function renderInstances(start, count, primcount) {
  10049. if (primcount === 0) return;
  10050. var extension, methodName;
  10051. if (isWebGL2) {
  10052. extension = gl;
  10053. methodName = 'drawArraysInstanced';
  10054. } else {
  10055. extension = extensions.get('ANGLE_instanced_arrays');
  10056. methodName = 'drawArraysInstancedANGLE';
  10057. if (extension === null) {
  10058. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10059. return;
  10060. }
  10061. }
  10062. extension[methodName](mode, start, count, primcount);
  10063. info.update(count, mode, primcount);
  10064. } //
  10065. this.setMode = setMode;
  10066. this.render = render;
  10067. this.renderInstances = renderInstances;
  10068. }
  10069. function WebGLCapabilities(gl, extensions, parameters) {
  10070. var maxAnisotropy;
  10071. function getMaxAnisotropy() {
  10072. if (maxAnisotropy !== undefined) return maxAnisotropy;
  10073. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  10074. var extension = extensions.get('EXT_texture_filter_anisotropic');
  10075. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  10076. } else {
  10077. maxAnisotropy = 0;
  10078. }
  10079. return maxAnisotropy;
  10080. }
  10081. function getMaxPrecision(precision) {
  10082. if (precision === 'highp') {
  10083. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  10084. return 'highp';
  10085. }
  10086. precision = 'mediump';
  10087. }
  10088. if (precision === 'mediump') {
  10089. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  10090. return 'mediump';
  10091. }
  10092. }
  10093. return 'lowp';
  10094. }
  10095. /* eslint-disable no-undef */
  10096. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  10097. /* eslint-enable no-undef */
  10098. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10099. var maxPrecision = getMaxPrecision(precision);
  10100. if (maxPrecision !== precision) {
  10101. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  10102. precision = maxPrecision;
  10103. }
  10104. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10105. var maxTextures = gl.getParameter(34930);
  10106. var maxVertexTextures = gl.getParameter(35660);
  10107. var maxTextureSize = gl.getParameter(3379);
  10108. var maxCubemapSize = gl.getParameter(34076);
  10109. var maxAttributes = gl.getParameter(34921);
  10110. var maxVertexUniforms = gl.getParameter(36347);
  10111. var maxVaryings = gl.getParameter(36348);
  10112. var maxFragmentUniforms = gl.getParameter(36349);
  10113. var vertexTextures = maxVertexTextures > 0;
  10114. var floatFragmentTextures = isWebGL2 || extensions.has('OES_texture_float');
  10115. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10116. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  10117. return {
  10118. isWebGL2: isWebGL2,
  10119. getMaxAnisotropy: getMaxAnisotropy,
  10120. getMaxPrecision: getMaxPrecision,
  10121. precision: precision,
  10122. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10123. maxTextures: maxTextures,
  10124. maxVertexTextures: maxVertexTextures,
  10125. maxTextureSize: maxTextureSize,
  10126. maxCubemapSize: maxCubemapSize,
  10127. maxAttributes: maxAttributes,
  10128. maxVertexUniforms: maxVertexUniforms,
  10129. maxVaryings: maxVaryings,
  10130. maxFragmentUniforms: maxFragmentUniforms,
  10131. vertexTextures: vertexTextures,
  10132. floatFragmentTextures: floatFragmentTextures,
  10133. floatVertexTextures: floatVertexTextures,
  10134. maxSamples: maxSamples
  10135. };
  10136. }
  10137. function WebGLClipping(properties) {
  10138. var scope = this;
  10139. var globalState = null,
  10140. numGlobalPlanes = 0,
  10141. localClippingEnabled = false,
  10142. renderingShadows = false;
  10143. var plane = new Plane(),
  10144. viewNormalMatrix = new Matrix3(),
  10145. uniform = {
  10146. value: null,
  10147. needsUpdate: false
  10148. };
  10149. this.uniform = uniform;
  10150. this.numPlanes = 0;
  10151. this.numIntersection = 0;
  10152. this.init = function (planes, enableLocalClipping, camera) {
  10153. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  10154. // run another frame in order to reset the state:
  10155. numGlobalPlanes !== 0 || localClippingEnabled;
  10156. localClippingEnabled = enableLocalClipping;
  10157. globalState = projectPlanes(planes, camera, 0);
  10158. numGlobalPlanes = planes.length;
  10159. return enabled;
  10160. };
  10161. this.beginShadows = function () {
  10162. renderingShadows = true;
  10163. projectPlanes(null);
  10164. };
  10165. this.endShadows = function () {
  10166. renderingShadows = false;
  10167. resetGlobalState();
  10168. };
  10169. this.setState = function (material, camera, useCache) {
  10170. var planes = material.clippingPlanes,
  10171. clipIntersection = material.clipIntersection,
  10172. clipShadows = material.clipShadows;
  10173. var materialProperties = properties.get(material);
  10174. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  10175. // there's no local clipping
  10176. if (renderingShadows) {
  10177. // there's no global clipping
  10178. projectPlanes(null);
  10179. } else {
  10180. resetGlobalState();
  10181. }
  10182. } else {
  10183. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10184. lGlobal = nGlobal * 4;
  10185. var dstArray = materialProperties.clippingState || null;
  10186. uniform.value = dstArray; // ensure unique state
  10187. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  10188. for (var i = 0; i !== lGlobal; ++i) {
  10189. dstArray[i] = globalState[i];
  10190. }
  10191. materialProperties.clippingState = dstArray;
  10192. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10193. this.numPlanes += nGlobal;
  10194. }
  10195. };
  10196. function resetGlobalState() {
  10197. if (uniform.value !== globalState) {
  10198. uniform.value = globalState;
  10199. uniform.needsUpdate = numGlobalPlanes > 0;
  10200. }
  10201. scope.numPlanes = numGlobalPlanes;
  10202. scope.numIntersection = 0;
  10203. }
  10204. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  10205. var nPlanes = planes !== null ? planes.length : 0;
  10206. var dstArray = null;
  10207. if (nPlanes !== 0) {
  10208. dstArray = uniform.value;
  10209. if (skipTransform !== true || dstArray === null) {
  10210. var flatSize = dstOffset + nPlanes * 4,
  10211. viewMatrix = camera.matrixWorldInverse;
  10212. viewNormalMatrix.getNormalMatrix(viewMatrix);
  10213. if (dstArray === null || dstArray.length < flatSize) {
  10214. dstArray = new Float32Array(flatSize);
  10215. }
  10216. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  10217. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  10218. plane.normal.toArray(dstArray, i4);
  10219. dstArray[i4 + 3] = plane.constant;
  10220. }
  10221. }
  10222. uniform.value = dstArray;
  10223. uniform.needsUpdate = true;
  10224. }
  10225. scope.numPlanes = nPlanes;
  10226. scope.numIntersection = 0;
  10227. return dstArray;
  10228. }
  10229. }
  10230. function WebGLCubeMaps(renderer) {
  10231. var cubemaps = new WeakMap();
  10232. function mapTextureMapping(texture, mapping) {
  10233. if (mapping === EquirectangularReflectionMapping) {
  10234. texture.mapping = CubeReflectionMapping;
  10235. } else if (mapping === EquirectangularRefractionMapping) {
  10236. texture.mapping = CubeRefractionMapping;
  10237. }
  10238. return texture;
  10239. }
  10240. function get(texture) {
  10241. if (texture && texture.isTexture) {
  10242. var mapping = texture.mapping;
  10243. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  10244. if (cubemaps.has(texture)) {
  10245. var cubemap = cubemaps.get(texture).texture;
  10246. return mapTextureMapping(cubemap, texture.mapping);
  10247. } else {
  10248. var image = texture.image;
  10249. if (image && image.height > 0) {
  10250. var currentRenderTarget = renderer.getRenderTarget();
  10251. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  10252. renderTarget.fromEquirectangularTexture(renderer, texture);
  10253. cubemaps.set(texture, renderTarget);
  10254. renderer.setRenderTarget(currentRenderTarget);
  10255. texture.addEventListener('dispose', onTextureDispose);
  10256. return mapTextureMapping(renderTarget.texture, texture.mapping);
  10257. } else {
  10258. // image not yet ready. try the conversion next frame
  10259. return null;
  10260. }
  10261. }
  10262. }
  10263. }
  10264. return texture;
  10265. }
  10266. function onTextureDispose(event) {
  10267. var texture = event.target;
  10268. texture.removeEventListener('dispose', onTextureDispose);
  10269. var cubemap = cubemaps.get(texture);
  10270. if (cubemap !== undefined) {
  10271. cubemaps.delete(texture);
  10272. cubemap.dispose();
  10273. }
  10274. }
  10275. function dispose() {
  10276. cubemaps = new WeakMap();
  10277. }
  10278. return {
  10279. get: get,
  10280. dispose: dispose
  10281. };
  10282. }
  10283. function WebGLExtensions(gl) {
  10284. var extensions = {};
  10285. function getExtension(name) {
  10286. if (extensions[name] !== undefined) {
  10287. return extensions[name];
  10288. }
  10289. var extension;
  10290. switch (name) {
  10291. case 'WEBGL_depth_texture':
  10292. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  10293. break;
  10294. case 'EXT_texture_filter_anisotropic':
  10295. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  10296. break;
  10297. case 'WEBGL_compressed_texture_s3tc':
  10298. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  10299. break;
  10300. case 'WEBGL_compressed_texture_pvrtc':
  10301. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  10302. break;
  10303. default:
  10304. extension = gl.getExtension(name);
  10305. }
  10306. extensions[name] = extension;
  10307. return extension;
  10308. }
  10309. return {
  10310. has: function has(name) {
  10311. return getExtension(name) !== null;
  10312. },
  10313. init: function init(capabilities) {
  10314. if (capabilities.isWebGL2) {
  10315. getExtension('EXT_color_buffer_float');
  10316. } else {
  10317. getExtension('WEBGL_depth_texture');
  10318. getExtension('OES_texture_float');
  10319. getExtension('OES_texture_half_float');
  10320. getExtension('OES_texture_half_float_linear');
  10321. getExtension('OES_standard_derivatives');
  10322. getExtension('OES_element_index_uint');
  10323. getExtension('OES_vertex_array_object');
  10324. getExtension('ANGLE_instanced_arrays');
  10325. }
  10326. getExtension('OES_texture_float_linear');
  10327. getExtension('EXT_color_buffer_half_float');
  10328. },
  10329. get: function get(name) {
  10330. var extension = getExtension(name);
  10331. if (extension === null) {
  10332. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  10333. }
  10334. return extension;
  10335. }
  10336. };
  10337. }
  10338. function WebGLGeometries(gl, attributes, info, bindingStates) {
  10339. var geometries = {};
  10340. var wireframeAttributes = new WeakMap();
  10341. function onGeometryDispose(event) {
  10342. var geometry = event.target;
  10343. if (geometry.index !== null) {
  10344. attributes.remove(geometry.index);
  10345. }
  10346. for (var name in geometry.attributes) {
  10347. attributes.remove(geometry.attributes[name]);
  10348. }
  10349. geometry.removeEventListener('dispose', onGeometryDispose);
  10350. delete geometries[geometry.id];
  10351. var attribute = wireframeAttributes.get(geometry);
  10352. if (attribute) {
  10353. attributes.remove(attribute);
  10354. wireframeAttributes.delete(geometry);
  10355. }
  10356. bindingStates.releaseStatesOfGeometry(geometry);
  10357. if (geometry.isInstancedBufferGeometry === true) {
  10358. delete geometry._maxInstanceCount;
  10359. } //
  10360. info.memory.geometries--;
  10361. }
  10362. function get(object, geometry) {
  10363. if (geometries[geometry.id] === true) return geometry;
  10364. geometry.addEventListener('dispose', onGeometryDispose);
  10365. geometries[geometry.id] = true;
  10366. info.memory.geometries++;
  10367. return geometry;
  10368. }
  10369. function update(geometry) {
  10370. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  10371. for (var name in geometryAttributes) {
  10372. attributes.update(geometryAttributes[name], 34962);
  10373. } // morph targets
  10374. var morphAttributes = geometry.morphAttributes;
  10375. for (var _name in morphAttributes) {
  10376. var array = morphAttributes[_name];
  10377. for (var i = 0, l = array.length; i < l; i++) {
  10378. attributes.update(array[i], 34962);
  10379. }
  10380. }
  10381. }
  10382. function updateWireframeAttribute(geometry) {
  10383. var indices = [];
  10384. var geometryIndex = geometry.index;
  10385. var geometryPosition = geometry.attributes.position;
  10386. var version = 0;
  10387. if (geometryIndex !== null) {
  10388. var array = geometryIndex.array;
  10389. version = geometryIndex.version;
  10390. for (var i = 0, l = array.length; i < l; i += 3) {
  10391. var a = array[i + 0];
  10392. var b = array[i + 1];
  10393. var c = array[i + 2];
  10394. indices.push(a, b, b, c, c, a);
  10395. }
  10396. } else {
  10397. var _array = geometryPosition.array;
  10398. version = geometryPosition.version;
  10399. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  10400. var _a = _i + 0;
  10401. var _b = _i + 1;
  10402. var _c = _i + 2;
  10403. indices.push(_a, _b, _b, _c, _c, _a);
  10404. }
  10405. }
  10406. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  10407. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  10408. //
  10409. var previousAttribute = wireframeAttributes.get(geometry);
  10410. if (previousAttribute) attributes.remove(previousAttribute); //
  10411. wireframeAttributes.set(geometry, attribute);
  10412. }
  10413. function getWireframeAttribute(geometry) {
  10414. var currentAttribute = wireframeAttributes.get(geometry);
  10415. if (currentAttribute) {
  10416. var geometryIndex = geometry.index;
  10417. if (geometryIndex !== null) {
  10418. // if the attribute is obsolete, create a new one
  10419. if (currentAttribute.version < geometryIndex.version) {
  10420. updateWireframeAttribute(geometry);
  10421. }
  10422. }
  10423. } else {
  10424. updateWireframeAttribute(geometry);
  10425. }
  10426. return wireframeAttributes.get(geometry);
  10427. }
  10428. return {
  10429. get: get,
  10430. update: update,
  10431. getWireframeAttribute: getWireframeAttribute
  10432. };
  10433. }
  10434. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  10435. var isWebGL2 = capabilities.isWebGL2;
  10436. var mode;
  10437. function setMode(value) {
  10438. mode = value;
  10439. }
  10440. var type, bytesPerElement;
  10441. function setIndex(value) {
  10442. type = value.type;
  10443. bytesPerElement = value.bytesPerElement;
  10444. }
  10445. function render(start, count) {
  10446. gl.drawElements(mode, count, type, start * bytesPerElement);
  10447. info.update(count, mode, 1);
  10448. }
  10449. function renderInstances(start, count, primcount) {
  10450. if (primcount === 0) return;
  10451. var extension, methodName;
  10452. if (isWebGL2) {
  10453. extension = gl;
  10454. methodName = 'drawElementsInstanced';
  10455. } else {
  10456. extension = extensions.get('ANGLE_instanced_arrays');
  10457. methodName = 'drawElementsInstancedANGLE';
  10458. if (extension === null) {
  10459. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10460. return;
  10461. }
  10462. }
  10463. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  10464. info.update(count, mode, primcount);
  10465. } //
  10466. this.setMode = setMode;
  10467. this.setIndex = setIndex;
  10468. this.render = render;
  10469. this.renderInstances = renderInstances;
  10470. }
  10471. function WebGLInfo(gl) {
  10472. var memory = {
  10473. geometries: 0,
  10474. textures: 0
  10475. };
  10476. var render = {
  10477. frame: 0,
  10478. calls: 0,
  10479. triangles: 0,
  10480. points: 0,
  10481. lines: 0
  10482. };
  10483. function update(count, mode, instanceCount) {
  10484. render.calls++;
  10485. switch (mode) {
  10486. case 4:
  10487. render.triangles += instanceCount * (count / 3);
  10488. break;
  10489. case 1:
  10490. render.lines += instanceCount * (count / 2);
  10491. break;
  10492. case 3:
  10493. render.lines += instanceCount * (count - 1);
  10494. break;
  10495. case 2:
  10496. render.lines += instanceCount * count;
  10497. break;
  10498. case 0:
  10499. render.points += instanceCount * count;
  10500. break;
  10501. default:
  10502. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  10503. break;
  10504. }
  10505. }
  10506. function reset() {
  10507. render.frame++;
  10508. render.calls = 0;
  10509. render.triangles = 0;
  10510. render.points = 0;
  10511. render.lines = 0;
  10512. }
  10513. return {
  10514. memory: memory,
  10515. render: render,
  10516. programs: null,
  10517. autoReset: true,
  10518. reset: reset,
  10519. update: update
  10520. };
  10521. }
  10522. function numericalSort(a, b) {
  10523. return a[0] - b[0];
  10524. }
  10525. function absNumericalSort(a, b) {
  10526. return Math.abs(b[1]) - Math.abs(a[1]);
  10527. }
  10528. function WebGLMorphtargets(gl) {
  10529. var influencesList = {};
  10530. var morphInfluences = new Float32Array(8);
  10531. var workInfluences = [];
  10532. for (var i = 0; i < 8; i++) {
  10533. workInfluences[i] = [i, 0];
  10534. }
  10535. function update(object, geometry, material, program) {
  10536. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10537. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10538. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10539. var influences = influencesList[geometry.id];
  10540. if (influences === undefined) {
  10541. // initialise list
  10542. influences = [];
  10543. for (var _i = 0; _i < length; _i++) {
  10544. influences[_i] = [_i, 0];
  10545. }
  10546. influencesList[geometry.id] = influences;
  10547. } // Collect influences
  10548. for (var _i2 = 0; _i2 < length; _i2++) {
  10549. var influence = influences[_i2];
  10550. influence[0] = _i2;
  10551. influence[1] = objectInfluences[_i2];
  10552. }
  10553. influences.sort(absNumericalSort);
  10554. for (var _i3 = 0; _i3 < 8; _i3++) {
  10555. if (_i3 < length && influences[_i3][1]) {
  10556. workInfluences[_i3][0] = influences[_i3][0];
  10557. workInfluences[_i3][1] = influences[_i3][1];
  10558. } else {
  10559. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10560. workInfluences[_i3][1] = 0;
  10561. }
  10562. }
  10563. workInfluences.sort(numericalSort);
  10564. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10565. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10566. var morphInfluencesSum = 0;
  10567. for (var _i4 = 0; _i4 < 8; _i4++) {
  10568. var _influence = workInfluences[_i4];
  10569. var index = _influence[0];
  10570. var value = _influence[1];
  10571. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10572. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10573. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10574. }
  10575. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10576. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10577. }
  10578. morphInfluences[_i4] = value;
  10579. morphInfluencesSum += value;
  10580. } else {
  10581. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10582. geometry.deleteAttribute('morphTarget' + _i4);
  10583. }
  10584. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10585. geometry.deleteAttribute('morphNormal' + _i4);
  10586. }
  10587. morphInfluences[_i4] = 0;
  10588. }
  10589. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10590. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10591. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10592. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10593. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10594. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10595. }
  10596. return {
  10597. update: update
  10598. };
  10599. }
  10600. function WebGLObjects(gl, geometries, attributes, info) {
  10601. var updateMap = new WeakMap();
  10602. function update(object) {
  10603. var frame = info.render.frame;
  10604. var geometry = object.geometry;
  10605. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10606. if (updateMap.get(buffergeometry) !== frame) {
  10607. geometries.update(buffergeometry);
  10608. updateMap.set(buffergeometry, frame);
  10609. }
  10610. if (object.isInstancedMesh) {
  10611. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10612. object.addEventListener('dispose', onInstancedMeshDispose);
  10613. }
  10614. attributes.update(object.instanceMatrix, 34962);
  10615. if (object.instanceColor !== null) {
  10616. attributes.update(object.instanceColor, 34962);
  10617. }
  10618. }
  10619. return buffergeometry;
  10620. }
  10621. function dispose() {
  10622. updateMap = new WeakMap();
  10623. }
  10624. function onInstancedMeshDispose(event) {
  10625. var instancedMesh = event.target;
  10626. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10627. attributes.remove(instancedMesh.instanceMatrix);
  10628. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10629. }
  10630. return {
  10631. update: update,
  10632. dispose: dispose
  10633. };
  10634. }
  10635. function DataTexture2DArray(data, width, height, depth) {
  10636. if (data === void 0) {
  10637. data = null;
  10638. }
  10639. if (width === void 0) {
  10640. width = 1;
  10641. }
  10642. if (height === void 0) {
  10643. height = 1;
  10644. }
  10645. if (depth === void 0) {
  10646. depth = 1;
  10647. }
  10648. Texture.call(this, null);
  10649. this.image = {
  10650. data: data,
  10651. width: width,
  10652. height: height,
  10653. depth: depth
  10654. };
  10655. this.magFilter = NearestFilter;
  10656. this.minFilter = NearestFilter;
  10657. this.wrapR = ClampToEdgeWrapping;
  10658. this.generateMipmaps = false;
  10659. this.flipY = false;
  10660. this.needsUpdate = true;
  10661. }
  10662. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10663. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10664. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10665. function DataTexture3D(data, width, height, depth) {
  10666. if (data === void 0) {
  10667. data = null;
  10668. }
  10669. if (width === void 0) {
  10670. width = 1;
  10671. }
  10672. if (height === void 0) {
  10673. height = 1;
  10674. }
  10675. if (depth === void 0) {
  10676. depth = 1;
  10677. }
  10678. // We're going to add .setXXX() methods for setting properties later.
  10679. // Users can still set in DataTexture3D directly.
  10680. //
  10681. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10682. // texture.anisotropy = 16;
  10683. //
  10684. // See #14839
  10685. Texture.call(this, null);
  10686. this.image = {
  10687. data: data,
  10688. width: width,
  10689. height: height,
  10690. depth: depth
  10691. };
  10692. this.magFilter = NearestFilter;
  10693. this.minFilter = NearestFilter;
  10694. this.wrapR = ClampToEdgeWrapping;
  10695. this.generateMipmaps = false;
  10696. this.flipY = false;
  10697. this.needsUpdate = true;
  10698. }
  10699. DataTexture3D.prototype = Object.create(Texture.prototype);
  10700. DataTexture3D.prototype.constructor = DataTexture3D;
  10701. DataTexture3D.prototype.isDataTexture3D = true;
  10702. /**
  10703. * Uniforms of a program.
  10704. * Those form a tree structure with a special top-level container for the root,
  10705. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10706. *
  10707. *
  10708. * Properties of inner nodes including the top-level container:
  10709. *
  10710. * .seq - array of nested uniforms
  10711. * .map - nested uniforms by name
  10712. *
  10713. *
  10714. * Methods of all nodes except the top-level container:
  10715. *
  10716. * .setValue( gl, value, [textures] )
  10717. *
  10718. * uploads a uniform value(s)
  10719. * the 'textures' parameter is needed for sampler uniforms
  10720. *
  10721. *
  10722. * Static methods of the top-level container (textures factorizations):
  10723. *
  10724. * .upload( gl, seq, values, textures )
  10725. *
  10726. * sets uniforms in 'seq' to 'values[id].value'
  10727. *
  10728. * .seqWithValue( seq, values ) : filteredSeq
  10729. *
  10730. * filters 'seq' entries with corresponding entry in values
  10731. *
  10732. *
  10733. * Methods of the top-level container (textures factorizations):
  10734. *
  10735. * .setValue( gl, name, value, textures )
  10736. *
  10737. * sets uniform with name 'name' to 'value'
  10738. *
  10739. * .setOptional( gl, obj, prop )
  10740. *
  10741. * like .set for an optional property of the object
  10742. *
  10743. */
  10744. var emptyTexture = new Texture();
  10745. var emptyTexture2dArray = new DataTexture2DArray();
  10746. var emptyTexture3d = new DataTexture3D();
  10747. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10748. // Array Caches (provide typed arrays for temporary by size)
  10749. var arrayCacheF32 = [];
  10750. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10751. var mat4array = new Float32Array(16);
  10752. var mat3array = new Float32Array(9);
  10753. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10754. function flatten(array, nBlocks, blockSize) {
  10755. var firstElem = array[0];
  10756. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10757. // see http://jacksondunstan.com/articles/983
  10758. var n = nBlocks * blockSize;
  10759. var r = arrayCacheF32[n];
  10760. if (r === undefined) {
  10761. r = new Float32Array(n);
  10762. arrayCacheF32[n] = r;
  10763. }
  10764. if (nBlocks !== 0) {
  10765. firstElem.toArray(r, 0);
  10766. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10767. offset += blockSize;
  10768. array[i].toArray(r, offset);
  10769. }
  10770. }
  10771. return r;
  10772. }
  10773. function arraysEqual(a, b) {
  10774. if (a.length !== b.length) return false;
  10775. for (var i = 0, l = a.length; i < l; i++) {
  10776. if (a[i] !== b[i]) return false;
  10777. }
  10778. return true;
  10779. }
  10780. function copyArray(a, b) {
  10781. for (var i = 0, l = b.length; i < l; i++) {
  10782. a[i] = b[i];
  10783. }
  10784. } // Texture unit allocation
  10785. function allocTexUnits(textures, n) {
  10786. var r = arrayCacheI32[n];
  10787. if (r === undefined) {
  10788. r = new Int32Array(n);
  10789. arrayCacheI32[n] = r;
  10790. }
  10791. for (var i = 0; i !== n; ++i) {
  10792. r[i] = textures.allocateTextureUnit();
  10793. }
  10794. return r;
  10795. } // --- Setters ---
  10796. // Note: Defining these methods externally, because they come in a bunch
  10797. // and this way their names minify.
  10798. // Single scalar
  10799. function setValueV1f(gl, v) {
  10800. var cache = this.cache;
  10801. if (cache[0] === v) return;
  10802. gl.uniform1f(this.addr, v);
  10803. cache[0] = v;
  10804. } // Single float vector (from flat array or THREE.VectorN)
  10805. function setValueV2f(gl, v) {
  10806. var cache = this.cache;
  10807. if (v.x !== undefined) {
  10808. if (cache[0] !== v.x || cache[1] !== v.y) {
  10809. gl.uniform2f(this.addr, v.x, v.y);
  10810. cache[0] = v.x;
  10811. cache[1] = v.y;
  10812. }
  10813. } else {
  10814. if (arraysEqual(cache, v)) return;
  10815. gl.uniform2fv(this.addr, v);
  10816. copyArray(cache, v);
  10817. }
  10818. }
  10819. function setValueV3f(gl, v) {
  10820. var cache = this.cache;
  10821. if (v.x !== undefined) {
  10822. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10823. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10824. cache[0] = v.x;
  10825. cache[1] = v.y;
  10826. cache[2] = v.z;
  10827. }
  10828. } else if (v.r !== undefined) {
  10829. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10830. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10831. cache[0] = v.r;
  10832. cache[1] = v.g;
  10833. cache[2] = v.b;
  10834. }
  10835. } else {
  10836. if (arraysEqual(cache, v)) return;
  10837. gl.uniform3fv(this.addr, v);
  10838. copyArray(cache, v);
  10839. }
  10840. }
  10841. function setValueV4f(gl, v) {
  10842. var cache = this.cache;
  10843. if (v.x !== undefined) {
  10844. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10845. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10846. cache[0] = v.x;
  10847. cache[1] = v.y;
  10848. cache[2] = v.z;
  10849. cache[3] = v.w;
  10850. }
  10851. } else {
  10852. if (arraysEqual(cache, v)) return;
  10853. gl.uniform4fv(this.addr, v);
  10854. copyArray(cache, v);
  10855. }
  10856. } // Single matrix (from flat array or MatrixN)
  10857. function setValueM2(gl, v) {
  10858. var cache = this.cache;
  10859. var elements = v.elements;
  10860. if (elements === undefined) {
  10861. if (arraysEqual(cache, v)) return;
  10862. gl.uniformMatrix2fv(this.addr, false, v);
  10863. copyArray(cache, v);
  10864. } else {
  10865. if (arraysEqual(cache, elements)) return;
  10866. mat2array.set(elements);
  10867. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10868. copyArray(cache, elements);
  10869. }
  10870. }
  10871. function setValueM3(gl, v) {
  10872. var cache = this.cache;
  10873. var elements = v.elements;
  10874. if (elements === undefined) {
  10875. if (arraysEqual(cache, v)) return;
  10876. gl.uniformMatrix3fv(this.addr, false, v);
  10877. copyArray(cache, v);
  10878. } else {
  10879. if (arraysEqual(cache, elements)) return;
  10880. mat3array.set(elements);
  10881. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10882. copyArray(cache, elements);
  10883. }
  10884. }
  10885. function setValueM4(gl, v) {
  10886. var cache = this.cache;
  10887. var elements = v.elements;
  10888. if (elements === undefined) {
  10889. if (arraysEqual(cache, v)) return;
  10890. gl.uniformMatrix4fv(this.addr, false, v);
  10891. copyArray(cache, v);
  10892. } else {
  10893. if (arraysEqual(cache, elements)) return;
  10894. mat4array.set(elements);
  10895. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10896. copyArray(cache, elements);
  10897. }
  10898. } // Single texture (2D / Cube)
  10899. function setValueT1(gl, v, textures) {
  10900. var cache = this.cache;
  10901. var unit = textures.allocateTextureUnit();
  10902. if (cache[0] !== unit) {
  10903. gl.uniform1i(this.addr, unit);
  10904. cache[0] = unit;
  10905. }
  10906. textures.safeSetTexture2D(v || emptyTexture, unit);
  10907. }
  10908. function setValueT2DArray1(gl, v, textures) {
  10909. var cache = this.cache;
  10910. var unit = textures.allocateTextureUnit();
  10911. if (cache[0] !== unit) {
  10912. gl.uniform1i(this.addr, unit);
  10913. cache[0] = unit;
  10914. }
  10915. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10916. }
  10917. function setValueT3D1(gl, v, textures) {
  10918. var cache = this.cache;
  10919. var unit = textures.allocateTextureUnit();
  10920. if (cache[0] !== unit) {
  10921. gl.uniform1i(this.addr, unit);
  10922. cache[0] = unit;
  10923. }
  10924. textures.setTexture3D(v || emptyTexture3d, unit);
  10925. }
  10926. function setValueT6(gl, v, textures) {
  10927. var cache = this.cache;
  10928. var unit = textures.allocateTextureUnit();
  10929. if (cache[0] !== unit) {
  10930. gl.uniform1i(this.addr, unit);
  10931. cache[0] = unit;
  10932. }
  10933. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10934. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10935. function setValueV1i(gl, v) {
  10936. var cache = this.cache;
  10937. if (cache[0] === v) return;
  10938. gl.uniform1i(this.addr, v);
  10939. cache[0] = v;
  10940. }
  10941. function setValueV2i(gl, v) {
  10942. var cache = this.cache;
  10943. if (arraysEqual(cache, v)) return;
  10944. gl.uniform2iv(this.addr, v);
  10945. copyArray(cache, v);
  10946. }
  10947. function setValueV3i(gl, v) {
  10948. var cache = this.cache;
  10949. if (arraysEqual(cache, v)) return;
  10950. gl.uniform3iv(this.addr, v);
  10951. copyArray(cache, v);
  10952. }
  10953. function setValueV4i(gl, v) {
  10954. var cache = this.cache;
  10955. if (arraysEqual(cache, v)) return;
  10956. gl.uniform4iv(this.addr, v);
  10957. copyArray(cache, v);
  10958. } // uint
  10959. function setValueV1ui(gl, v) {
  10960. var cache = this.cache;
  10961. if (cache[0] === v) return;
  10962. gl.uniform1ui(this.addr, v);
  10963. cache[0] = v;
  10964. } // Helper to pick the right setter for the singular case
  10965. function getSingularSetter(type) {
  10966. switch (type) {
  10967. case 0x1406:
  10968. return setValueV1f;
  10969. // FLOAT
  10970. case 0x8b50:
  10971. return setValueV2f;
  10972. // _VEC2
  10973. case 0x8b51:
  10974. return setValueV3f;
  10975. // _VEC3
  10976. case 0x8b52:
  10977. return setValueV4f;
  10978. // _VEC4
  10979. case 0x8b5a:
  10980. return setValueM2;
  10981. // _MAT2
  10982. case 0x8b5b:
  10983. return setValueM3;
  10984. // _MAT3
  10985. case 0x8b5c:
  10986. return setValueM4;
  10987. // _MAT4
  10988. case 0x1404:
  10989. case 0x8b56:
  10990. return setValueV1i;
  10991. // INT, BOOL
  10992. case 0x8b53:
  10993. case 0x8b57:
  10994. return setValueV2i;
  10995. // _VEC2
  10996. case 0x8b54:
  10997. case 0x8b58:
  10998. return setValueV3i;
  10999. // _VEC3
  11000. case 0x8b55:
  11001. case 0x8b59:
  11002. return setValueV4i;
  11003. // _VEC4
  11004. case 0x1405:
  11005. return setValueV1ui;
  11006. // UINT
  11007. case 0x8b5e: // SAMPLER_2D
  11008. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11009. case 0x8dca: // INT_SAMPLER_2D
  11010. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11011. case 0x8b62:
  11012. // SAMPLER_2D_SHADOW
  11013. return setValueT1;
  11014. case 0x8b5f: // SAMPLER_3D
  11015. case 0x8dcb: // INT_SAMPLER_3D
  11016. case 0x8dd3:
  11017. // UNSIGNED_INT_SAMPLER_3D
  11018. return setValueT3D1;
  11019. case 0x8b60: // SAMPLER_CUBE
  11020. case 0x8dcc: // INT_SAMPLER_CUBE
  11021. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11022. case 0x8dc5:
  11023. // SAMPLER_CUBE_SHADOW
  11024. return setValueT6;
  11025. case 0x8dc1: // SAMPLER_2D_ARRAY
  11026. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  11027. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  11028. case 0x8dc4:
  11029. // SAMPLER_2D_ARRAY_SHADOW
  11030. return setValueT2DArray1;
  11031. }
  11032. } // Array of scalars
  11033. function setValueV1fArray(gl, v) {
  11034. gl.uniform1fv(this.addr, v);
  11035. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  11036. function setValueV1iArray(gl, v) {
  11037. gl.uniform1iv(this.addr, v);
  11038. }
  11039. function setValueV2iArray(gl, v) {
  11040. gl.uniform2iv(this.addr, v);
  11041. }
  11042. function setValueV3iArray(gl, v) {
  11043. gl.uniform3iv(this.addr, v);
  11044. }
  11045. function setValueV4iArray(gl, v) {
  11046. gl.uniform4iv(this.addr, v);
  11047. } // Array of vectors (flat or from THREE classes)
  11048. function setValueV2fArray(gl, v) {
  11049. var data = flatten(v, this.size, 2);
  11050. gl.uniform2fv(this.addr, data);
  11051. }
  11052. function setValueV3fArray(gl, v) {
  11053. var data = flatten(v, this.size, 3);
  11054. gl.uniform3fv(this.addr, data);
  11055. }
  11056. function setValueV4fArray(gl, v) {
  11057. var data = flatten(v, this.size, 4);
  11058. gl.uniform4fv(this.addr, data);
  11059. } // Array of matrices (flat or from THREE clases)
  11060. function setValueM2Array(gl, v) {
  11061. var data = flatten(v, this.size, 4);
  11062. gl.uniformMatrix2fv(this.addr, false, data);
  11063. }
  11064. function setValueM3Array(gl, v) {
  11065. var data = flatten(v, this.size, 9);
  11066. gl.uniformMatrix3fv(this.addr, false, data);
  11067. }
  11068. function setValueM4Array(gl, v) {
  11069. var data = flatten(v, this.size, 16);
  11070. gl.uniformMatrix4fv(this.addr, false, data);
  11071. } // Array of textures (2D / Cube)
  11072. function setValueT1Array(gl, v, textures) {
  11073. var n = v.length;
  11074. var units = allocTexUnits(textures, n);
  11075. gl.uniform1iv(this.addr, units);
  11076. for (var i = 0; i !== n; ++i) {
  11077. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  11078. }
  11079. }
  11080. function setValueT6Array(gl, v, textures) {
  11081. var n = v.length;
  11082. var units = allocTexUnits(textures, n);
  11083. gl.uniform1iv(this.addr, units);
  11084. for (var i = 0; i !== n; ++i) {
  11085. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  11086. }
  11087. } // Helper to pick the right setter for a pure (bottom-level) array
  11088. function getPureArraySetter(type) {
  11089. switch (type) {
  11090. case 0x1406:
  11091. return setValueV1fArray;
  11092. // FLOAT
  11093. case 0x8b50:
  11094. return setValueV2fArray;
  11095. // _VEC2
  11096. case 0x8b51:
  11097. return setValueV3fArray;
  11098. // _VEC3
  11099. case 0x8b52:
  11100. return setValueV4fArray;
  11101. // _VEC4
  11102. case 0x8b5a:
  11103. return setValueM2Array;
  11104. // _MAT2
  11105. case 0x8b5b:
  11106. return setValueM3Array;
  11107. // _MAT3
  11108. case 0x8b5c:
  11109. return setValueM4Array;
  11110. // _MAT4
  11111. case 0x1404:
  11112. case 0x8b56:
  11113. return setValueV1iArray;
  11114. // INT, BOOL
  11115. case 0x8b53:
  11116. case 0x8b57:
  11117. return setValueV2iArray;
  11118. // _VEC2
  11119. case 0x8b54:
  11120. case 0x8b58:
  11121. return setValueV3iArray;
  11122. // _VEC3
  11123. case 0x8b55:
  11124. case 0x8b59:
  11125. return setValueV4iArray;
  11126. // _VEC4
  11127. case 0x8b5e: // SAMPLER_2D
  11128. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11129. case 0x8dca: // INT_SAMPLER_2D
  11130. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11131. case 0x8b62:
  11132. // SAMPLER_2D_SHADOW
  11133. return setValueT1Array;
  11134. case 0x8b60: // SAMPLER_CUBE
  11135. case 0x8dcc: // INT_SAMPLER_CUBE
  11136. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11137. case 0x8dc5:
  11138. // SAMPLER_CUBE_SHADOW
  11139. return setValueT6Array;
  11140. }
  11141. } // --- Uniform Classes ---
  11142. function SingleUniform(id, activeInfo, addr) {
  11143. this.id = id;
  11144. this.addr = addr;
  11145. this.cache = [];
  11146. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11147. }
  11148. function PureArrayUniform(id, activeInfo, addr) {
  11149. this.id = id;
  11150. this.addr = addr;
  11151. this.cache = [];
  11152. this.size = activeInfo.size;
  11153. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11154. }
  11155. PureArrayUniform.prototype.updateCache = function (data) {
  11156. var cache = this.cache;
  11157. if (data instanceof Float32Array && cache.length !== data.length) {
  11158. this.cache = new Float32Array(data.length);
  11159. }
  11160. copyArray(cache, data);
  11161. };
  11162. function StructuredUniform(id) {
  11163. this.id = id;
  11164. this.seq = [];
  11165. this.map = {};
  11166. }
  11167. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  11168. var seq = this.seq;
  11169. for (var i = 0, n = seq.length; i !== n; ++i) {
  11170. var u = seq[i];
  11171. u.setValue(gl, value[u.id], textures);
  11172. }
  11173. }; // --- Top-level ---
  11174. // Parser - builds up the property tree from the path strings
  11175. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  11176. // - the identifier (member name or array index)
  11177. // - followed by an optional right bracket (found when array index)
  11178. // - followed by an optional left bracket or dot (type of subscript)
  11179. //
  11180. // Note: These portions can be read in a non-overlapping fashion and
  11181. // allow straightforward parsing of the hierarchy that WebGL encodes
  11182. // in the uniform names.
  11183. function addUniform(container, uniformObject) {
  11184. container.seq.push(uniformObject);
  11185. container.map[uniformObject.id] = uniformObject;
  11186. }
  11187. function parseUniform(activeInfo, addr, container) {
  11188. var path = activeInfo.name,
  11189. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  11190. RePathPart.lastIndex = 0;
  11191. while (true) {
  11192. var match = RePathPart.exec(path),
  11193. matchEnd = RePathPart.lastIndex;
  11194. var id = match[1];
  11195. var idIsIndex = match[2] === ']',
  11196. subscript = match[3];
  11197. if (idIsIndex) id = id | 0; // convert to integer
  11198. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  11199. // bare name or "pure" bottom-level array "[0]" suffix
  11200. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  11201. break;
  11202. } else {
  11203. // step into inner node / create it in case it doesn't exist
  11204. var map = container.map;
  11205. var next = map[id];
  11206. if (next === undefined) {
  11207. next = new StructuredUniform(id);
  11208. addUniform(container, next);
  11209. }
  11210. container = next;
  11211. }
  11212. }
  11213. } // Root Container
  11214. function WebGLUniforms(gl, program) {
  11215. this.seq = [];
  11216. this.map = {};
  11217. var n = gl.getProgramParameter(program, 35718);
  11218. for (var i = 0; i < n; ++i) {
  11219. var info = gl.getActiveUniform(program, i),
  11220. addr = gl.getUniformLocation(program, info.name);
  11221. parseUniform(info, addr, this);
  11222. }
  11223. }
  11224. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  11225. var u = this.map[name];
  11226. if (u !== undefined) u.setValue(gl, value, textures);
  11227. };
  11228. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  11229. var v = object[name];
  11230. if (v !== undefined) this.setValue(gl, name, v);
  11231. }; // Static interface
  11232. WebGLUniforms.upload = function (gl, seq, values, textures) {
  11233. for (var i = 0, n = seq.length; i !== n; ++i) {
  11234. var u = seq[i],
  11235. v = values[u.id];
  11236. if (v.needsUpdate !== false) {
  11237. // note: always updating when .needsUpdate is undefined
  11238. u.setValue(gl, v.value, textures);
  11239. }
  11240. }
  11241. };
  11242. WebGLUniforms.seqWithValue = function (seq, values) {
  11243. var r = [];
  11244. for (var i = 0, n = seq.length; i !== n; ++i) {
  11245. var u = seq[i];
  11246. if (u.id in values) r.push(u);
  11247. }
  11248. return r;
  11249. };
  11250. function WebGLShader(gl, type, string) {
  11251. var shader = gl.createShader(type);
  11252. gl.shaderSource(shader, string);
  11253. gl.compileShader(shader);
  11254. return shader;
  11255. }
  11256. var programIdCount = 0;
  11257. function addLineNumbers(string) {
  11258. var lines = string.split('\n');
  11259. for (var i = 0; i < lines.length; i++) {
  11260. lines[i] = i + 1 + ': ' + lines[i];
  11261. }
  11262. return lines.join('\n');
  11263. }
  11264. function getEncodingComponents(encoding) {
  11265. switch (encoding) {
  11266. case LinearEncoding:
  11267. return ['Linear', '( value )'];
  11268. case sRGBEncoding:
  11269. return ['sRGB', '( value )'];
  11270. case RGBEEncoding:
  11271. return ['RGBE', '( value )'];
  11272. case RGBM7Encoding:
  11273. return ['RGBM', '( value, 7.0 )'];
  11274. case RGBM16Encoding:
  11275. return ['RGBM', '( value, 16.0 )'];
  11276. case RGBDEncoding:
  11277. return ['RGBD', '( value, 256.0 )'];
  11278. case GammaEncoding:
  11279. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  11280. case LogLuvEncoding:
  11281. return ['LogLuv', '( value )'];
  11282. default:
  11283. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  11284. return ['Linear', '( value )'];
  11285. }
  11286. }
  11287. function getShaderErrors(gl, shader, type) {
  11288. var status = gl.getShaderParameter(shader, 35713);
  11289. var log = gl.getShaderInfoLog(shader).trim();
  11290. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  11291. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11292. var source = gl.getShaderSource(shader);
  11293. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  11294. }
  11295. function getTexelDecodingFunction(functionName, encoding) {
  11296. var components = getEncodingComponents(encoding);
  11297. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  11298. }
  11299. function getTexelEncodingFunction(functionName, encoding) {
  11300. var components = getEncodingComponents(encoding);
  11301. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  11302. }
  11303. function getToneMappingFunction(functionName, toneMapping) {
  11304. var toneMappingName;
  11305. switch (toneMapping) {
  11306. case LinearToneMapping:
  11307. toneMappingName = 'Linear';
  11308. break;
  11309. case ReinhardToneMapping:
  11310. toneMappingName = 'Reinhard';
  11311. break;
  11312. case CineonToneMapping:
  11313. toneMappingName = 'OptimizedCineon';
  11314. break;
  11315. case ACESFilmicToneMapping:
  11316. toneMappingName = 'ACESFilmic';
  11317. break;
  11318. case CustomToneMapping:
  11319. toneMappingName = 'Custom';
  11320. break;
  11321. default:
  11322. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  11323. toneMappingName = 'Linear';
  11324. }
  11325. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11326. }
  11327. function generateExtensions(parameters) {
  11328. 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' : ''];
  11329. return chunks.filter(filterEmptyLine).join('\n');
  11330. }
  11331. function generateDefines(defines) {
  11332. var chunks = [];
  11333. for (var name in defines) {
  11334. var value = defines[name];
  11335. if (value === false) continue;
  11336. chunks.push('#define ' + name + ' ' + value);
  11337. }
  11338. return chunks.join('\n');
  11339. }
  11340. function fetchAttributeLocations(gl, program) {
  11341. var attributes = {};
  11342. var n = gl.getProgramParameter(program, 35721);
  11343. for (var i = 0; i < n; i++) {
  11344. var info = gl.getActiveAttrib(program, i);
  11345. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11346. attributes[name] = gl.getAttribLocation(program, name);
  11347. }
  11348. return attributes;
  11349. }
  11350. function filterEmptyLine(string) {
  11351. return string !== '';
  11352. }
  11353. function replaceLightNums(string, parameters) {
  11354. 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);
  11355. }
  11356. function replaceClippingPlaneNums(string, parameters) {
  11357. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  11358. } // Resolve Includes
  11359. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11360. function resolveIncludes(string) {
  11361. return string.replace(includePattern, includeReplacer);
  11362. }
  11363. function includeReplacer(match, include) {
  11364. var string = ShaderChunk[include];
  11365. if (string === undefined) {
  11366. throw new Error('Can not resolve #include <' + include + '>');
  11367. }
  11368. return resolveIncludes(string);
  11369. } // Unroll Loops
  11370. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11371. 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;
  11372. function unrollLoops(string) {
  11373. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  11374. }
  11375. function deprecatedLoopReplacer(match, start, end, snippet) {
  11376. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  11377. return loopReplacer(match, start, end, snippet);
  11378. }
  11379. function loopReplacer(match, start, end, snippet) {
  11380. var string = '';
  11381. for (var i = parseInt(start); i < parseInt(end); i++) {
  11382. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  11383. }
  11384. return string;
  11385. } //
  11386. function generatePrecision(parameters) {
  11387. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  11388. if (parameters.precision === 'highp') {
  11389. precisionstring += '\n#define HIGH_PRECISION';
  11390. } else if (parameters.precision === 'mediump') {
  11391. precisionstring += '\n#define MEDIUM_PRECISION';
  11392. } else if (parameters.precision === 'lowp') {
  11393. precisionstring += '\n#define LOW_PRECISION';
  11394. }
  11395. return precisionstring;
  11396. }
  11397. function generateShadowMapTypeDefine(parameters) {
  11398. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11399. if (parameters.shadowMapType === PCFShadowMap) {
  11400. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11401. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  11402. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11403. } else if (parameters.shadowMapType === VSMShadowMap) {
  11404. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11405. }
  11406. return shadowMapTypeDefine;
  11407. }
  11408. function generateEnvMapTypeDefine(parameters) {
  11409. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11410. if (parameters.envMap) {
  11411. switch (parameters.envMapMode) {
  11412. case CubeReflectionMapping:
  11413. case CubeRefractionMapping:
  11414. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11415. break;
  11416. case CubeUVReflectionMapping:
  11417. case CubeUVRefractionMapping:
  11418. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11419. break;
  11420. }
  11421. }
  11422. return envMapTypeDefine;
  11423. }
  11424. function generateEnvMapModeDefine(parameters) {
  11425. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11426. if (parameters.envMap) {
  11427. switch (parameters.envMapMode) {
  11428. case CubeRefractionMapping:
  11429. case CubeUVRefractionMapping:
  11430. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11431. break;
  11432. }
  11433. }
  11434. return envMapModeDefine;
  11435. }
  11436. function generateEnvMapBlendingDefine(parameters) {
  11437. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11438. if (parameters.envMap) {
  11439. switch (parameters.combine) {
  11440. case MultiplyOperation:
  11441. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11442. break;
  11443. case MixOperation:
  11444. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11445. break;
  11446. case AddOperation:
  11447. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11448. break;
  11449. }
  11450. }
  11451. return envMapBlendingDefine;
  11452. }
  11453. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  11454. var gl = renderer.getContext();
  11455. var defines = parameters.defines;
  11456. var vertexShader = parameters.vertexShader;
  11457. var fragmentShader = parameters.fragmentShader;
  11458. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  11459. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  11460. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  11461. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  11462. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  11463. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  11464. var customDefines = generateDefines(defines);
  11465. var program = gl.createProgram();
  11466. var prefixVertex, prefixFragment;
  11467. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11468. if (parameters.isRawShaderMaterial) {
  11469. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  11470. if (prefixVertex.length > 0) {
  11471. prefixVertex += '\n';
  11472. }
  11473. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  11474. if (prefixFragment.length > 0) {
  11475. prefixFragment += '\n';
  11476. }
  11477. } else {
  11478. 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');
  11479. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  11480. '#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
  11481. 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
  11482. 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');
  11483. }
  11484. vertexShader = resolveIncludes(vertexShader);
  11485. vertexShader = replaceLightNums(vertexShader, parameters);
  11486. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  11487. fragmentShader = resolveIncludes(fragmentShader);
  11488. fragmentShader = replaceLightNums(fragmentShader, parameters);
  11489. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  11490. vertexShader = unrollLoops(vertexShader);
  11491. fragmentShader = unrollLoops(fragmentShader);
  11492. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  11493. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11494. versionString = '#version 300 es\n';
  11495. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  11496. 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;
  11497. }
  11498. var vertexGlsl = versionString + prefixVertex + vertexShader;
  11499. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  11500. // console.log( '*FRAGMENT*', fragmentGlsl );
  11501. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  11502. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  11503. gl.attachShader(program, glVertexShader);
  11504. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  11505. if (parameters.index0AttributeName !== undefined) {
  11506. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  11507. } else if (parameters.morphTargets === true) {
  11508. // programs with morphTargets displace position out of attribute 0
  11509. gl.bindAttribLocation(program, 0, 'position');
  11510. }
  11511. gl.linkProgram(program); // check for link errors
  11512. if (renderer.debug.checkShaderErrors) {
  11513. var programLog = gl.getProgramInfoLog(program).trim();
  11514. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  11515. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  11516. var runnable = true;
  11517. var haveDiagnostics = true;
  11518. if (gl.getProgramParameter(program, 35714) === false) {
  11519. runnable = false;
  11520. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  11521. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  11522. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11523. } else if (programLog !== '') {
  11524. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11525. } else if (vertexLog === '' || fragmentLog === '') {
  11526. haveDiagnostics = false;
  11527. }
  11528. if (haveDiagnostics) {
  11529. this.diagnostics = {
  11530. runnable: runnable,
  11531. programLog: programLog,
  11532. vertexShader: {
  11533. log: vertexLog,
  11534. prefix: prefixVertex
  11535. },
  11536. fragmentShader: {
  11537. log: fragmentLog,
  11538. prefix: prefixFragment
  11539. }
  11540. };
  11541. }
  11542. } // Clean up
  11543. // Crashes in iOS9 and iOS10. #18402
  11544. // gl.detachShader( program, glVertexShader );
  11545. // gl.detachShader( program, glFragmentShader );
  11546. gl.deleteShader(glVertexShader);
  11547. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11548. var cachedUniforms;
  11549. this.getUniforms = function () {
  11550. if (cachedUniforms === undefined) {
  11551. cachedUniforms = new WebGLUniforms(gl, program);
  11552. }
  11553. return cachedUniforms;
  11554. }; // set up caching for attribute locations
  11555. var cachedAttributes;
  11556. this.getAttributes = function () {
  11557. if (cachedAttributes === undefined) {
  11558. cachedAttributes = fetchAttributeLocations(gl, program);
  11559. }
  11560. return cachedAttributes;
  11561. }; // free resource
  11562. this.destroy = function () {
  11563. bindingStates.releaseStatesOfProgram(this);
  11564. gl.deleteProgram(program);
  11565. this.program = undefined;
  11566. }; //
  11567. this.name = parameters.shaderName;
  11568. this.id = programIdCount++;
  11569. this.cacheKey = cacheKey;
  11570. this.usedTimes = 1;
  11571. this.program = program;
  11572. this.vertexShader = glVertexShader;
  11573. this.fragmentShader = glFragmentShader;
  11574. return this;
  11575. }
  11576. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11577. var programs = [];
  11578. var isWebGL2 = capabilities.isWebGL2;
  11579. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11580. var floatVertexTextures = capabilities.floatVertexTextures;
  11581. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11582. var vertexTextures = capabilities.vertexTextures;
  11583. var precision = capabilities.precision;
  11584. var shaderIDs = {
  11585. MeshDepthMaterial: 'depth',
  11586. MeshDistanceMaterial: 'distanceRGBA',
  11587. MeshNormalMaterial: 'normal',
  11588. MeshBasicMaterial: 'basic',
  11589. MeshLambertMaterial: 'lambert',
  11590. MeshPhongMaterial: 'phong',
  11591. MeshToonMaterial: 'toon',
  11592. MeshStandardMaterial: 'physical',
  11593. MeshPhysicalMaterial: 'physical',
  11594. MeshMatcapMaterial: 'matcap',
  11595. LineBasicMaterial: 'basic',
  11596. LineDashedMaterial: 'dashed',
  11597. PointsMaterial: 'points',
  11598. ShadowMaterial: 'shadow',
  11599. SpriteMaterial: 'sprite'
  11600. };
  11601. 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'];
  11602. function getMaxBones(object) {
  11603. var skeleton = object.skeleton;
  11604. var bones = skeleton.bones;
  11605. if (floatVertexTextures) {
  11606. return 1024;
  11607. } else {
  11608. // default for when object is not specified
  11609. // ( for example when prebuilding shader to be used with multiple objects )
  11610. //
  11611. // - leave some extra space for other uniforms
  11612. // - limit here is ANGLE's 254 max uniform vectors
  11613. // (up to 54 should be safe)
  11614. var nVertexUniforms = maxVertexUniforms;
  11615. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11616. var maxBones = Math.min(nVertexMatrices, bones.length);
  11617. if (maxBones < bones.length) {
  11618. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11619. return 0;
  11620. }
  11621. return maxBones;
  11622. }
  11623. }
  11624. function getTextureEncodingFromMap(map) {
  11625. var encoding;
  11626. if (map && map.isTexture) {
  11627. encoding = map.encoding;
  11628. } else if (map && map.isWebGLRenderTarget) {
  11629. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11630. encoding = map.texture.encoding;
  11631. } else {
  11632. encoding = LinearEncoding;
  11633. }
  11634. return encoding;
  11635. }
  11636. function getParameters(material, lights, shadows, scene, object) {
  11637. var fog = scene.fog;
  11638. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11639. var envMap = cubemaps.get(material.envMap || environment);
  11640. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11641. // (not to blow over maxLights budget)
  11642. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11643. if (material.precision !== null) {
  11644. precision = capabilities.getMaxPrecision(material.precision);
  11645. if (precision !== material.precision) {
  11646. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11647. }
  11648. }
  11649. var vertexShader, fragmentShader;
  11650. if (shaderID) {
  11651. var shader = ShaderLib[shaderID];
  11652. vertexShader = shader.vertexShader;
  11653. fragmentShader = shader.fragmentShader;
  11654. } else {
  11655. vertexShader = material.vertexShader;
  11656. fragmentShader = material.fragmentShader;
  11657. }
  11658. var currentRenderTarget = renderer.getRenderTarget();
  11659. var parameters = {
  11660. isWebGL2: isWebGL2,
  11661. shaderID: shaderID,
  11662. shaderName: material.type,
  11663. vertexShader: vertexShader,
  11664. fragmentShader: fragmentShader,
  11665. defines: material.defines,
  11666. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11667. glslVersion: material.glslVersion,
  11668. precision: precision,
  11669. instancing: object.isInstancedMesh === true,
  11670. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11671. supportsVertexTextures: vertexTextures,
  11672. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11673. map: !!material.map,
  11674. mapEncoding: getTextureEncodingFromMap(material.map),
  11675. matcap: !!material.matcap,
  11676. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11677. envMap: !!envMap,
  11678. envMapMode: envMap && envMap.mapping,
  11679. envMapEncoding: getTextureEncodingFromMap(envMap),
  11680. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11681. lightMap: !!material.lightMap,
  11682. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11683. aoMap: !!material.aoMap,
  11684. emissiveMap: !!material.emissiveMap,
  11685. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11686. bumpMap: !!material.bumpMap,
  11687. normalMap: !!material.normalMap,
  11688. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11689. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11690. clearcoatMap: !!material.clearcoatMap,
  11691. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11692. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11693. displacementMap: !!material.displacementMap,
  11694. roughnessMap: !!material.roughnessMap,
  11695. metalnessMap: !!material.metalnessMap,
  11696. specularMap: !!material.specularMap,
  11697. alphaMap: !!material.alphaMap,
  11698. gradientMap: !!material.gradientMap,
  11699. sheen: !!material.sheen,
  11700. transmissionMap: !!material.transmissionMap,
  11701. combine: material.combine,
  11702. vertexTangents: material.normalMap && material.vertexTangents,
  11703. vertexColors: material.vertexColors,
  11704. 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,
  11705. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11706. fog: !!fog,
  11707. useFog: material.fog,
  11708. fogExp2: fog && fog.isFogExp2,
  11709. flatShading: !!material.flatShading,
  11710. sizeAttenuation: material.sizeAttenuation,
  11711. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11712. skinning: material.skinning && maxBones > 0,
  11713. maxBones: maxBones,
  11714. useVertexTexture: floatVertexTextures,
  11715. morphTargets: material.morphTargets,
  11716. morphNormals: material.morphNormals,
  11717. maxMorphTargets: renderer.maxMorphTargets,
  11718. maxMorphNormals: renderer.maxMorphNormals,
  11719. numDirLights: lights.directional.length,
  11720. numPointLights: lights.point.length,
  11721. numSpotLights: lights.spot.length,
  11722. numRectAreaLights: lights.rectArea.length,
  11723. numHemiLights: lights.hemi.length,
  11724. numDirLightShadows: lights.directionalShadowMap.length,
  11725. numPointLightShadows: lights.pointShadowMap.length,
  11726. numSpotLightShadows: lights.spotShadowMap.length,
  11727. numClippingPlanes: clipping.numPlanes,
  11728. numClipIntersection: clipping.numIntersection,
  11729. dithering: material.dithering,
  11730. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11731. shadowMapType: renderer.shadowMap.type,
  11732. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11733. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11734. premultipliedAlpha: material.premultipliedAlpha,
  11735. alphaTest: material.alphaTest,
  11736. doubleSided: material.side === DoubleSide,
  11737. flipSided: material.side === BackSide,
  11738. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11739. index0AttributeName: material.index0AttributeName,
  11740. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11741. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11742. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11743. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11744. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11745. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11746. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11747. customProgramCacheKey: material.customProgramCacheKey()
  11748. };
  11749. return parameters;
  11750. }
  11751. function getProgramCacheKey(parameters) {
  11752. var array = [];
  11753. if (parameters.shaderID) {
  11754. array.push(parameters.shaderID);
  11755. } else {
  11756. array.push(parameters.fragmentShader);
  11757. array.push(parameters.vertexShader);
  11758. }
  11759. if (parameters.defines !== undefined) {
  11760. for (var name in parameters.defines) {
  11761. array.push(name);
  11762. array.push(parameters.defines[name]);
  11763. }
  11764. }
  11765. if (parameters.isRawShaderMaterial === false) {
  11766. for (var i = 0; i < parameterNames.length; i++) {
  11767. array.push(parameters[parameterNames[i]]);
  11768. }
  11769. array.push(renderer.outputEncoding);
  11770. array.push(renderer.gammaFactor);
  11771. }
  11772. array.push(parameters.customProgramCacheKey);
  11773. return array.join();
  11774. }
  11775. function getUniforms(material) {
  11776. var shaderID = shaderIDs[material.type];
  11777. var uniforms;
  11778. if (shaderID) {
  11779. var shader = ShaderLib[shaderID];
  11780. uniforms = UniformsUtils.clone(shader.uniforms);
  11781. } else {
  11782. uniforms = material.uniforms;
  11783. }
  11784. return uniforms;
  11785. }
  11786. function acquireProgram(parameters, cacheKey) {
  11787. var program; // Check if code has been already compiled
  11788. for (var p = 0, pl = programs.length; p < pl; p++) {
  11789. var preexistingProgram = programs[p];
  11790. if (preexistingProgram.cacheKey === cacheKey) {
  11791. program = preexistingProgram;
  11792. ++program.usedTimes;
  11793. break;
  11794. }
  11795. }
  11796. if (program === undefined) {
  11797. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11798. programs.push(program);
  11799. }
  11800. return program;
  11801. }
  11802. function releaseProgram(program) {
  11803. if (--program.usedTimes === 0) {
  11804. // Remove from unordered set
  11805. var i = programs.indexOf(program);
  11806. programs[i] = programs[programs.length - 1];
  11807. programs.pop(); // Free WebGL resources
  11808. program.destroy();
  11809. }
  11810. }
  11811. return {
  11812. getParameters: getParameters,
  11813. getProgramCacheKey: getProgramCacheKey,
  11814. getUniforms: getUniforms,
  11815. acquireProgram: acquireProgram,
  11816. releaseProgram: releaseProgram,
  11817. // Exposed for resource monitoring & error feedback via renderer.info:
  11818. programs: programs
  11819. };
  11820. }
  11821. function WebGLProperties() {
  11822. var properties = new WeakMap();
  11823. function get(object) {
  11824. var map = properties.get(object);
  11825. if (map === undefined) {
  11826. map = {};
  11827. properties.set(object, map);
  11828. }
  11829. return map;
  11830. }
  11831. function remove(object) {
  11832. properties.delete(object);
  11833. }
  11834. function update(object, key, value) {
  11835. properties.get(object)[key] = value;
  11836. }
  11837. function dispose() {
  11838. properties = new WeakMap();
  11839. }
  11840. return {
  11841. get: get,
  11842. remove: remove,
  11843. update: update,
  11844. dispose: dispose
  11845. };
  11846. }
  11847. function painterSortStable(a, b) {
  11848. if (a.groupOrder !== b.groupOrder) {
  11849. return a.groupOrder - b.groupOrder;
  11850. } else if (a.renderOrder !== b.renderOrder) {
  11851. return a.renderOrder - b.renderOrder;
  11852. } else if (a.program !== b.program) {
  11853. return a.program.id - b.program.id;
  11854. } else if (a.material.id !== b.material.id) {
  11855. return a.material.id - b.material.id;
  11856. } else if (a.z !== b.z) {
  11857. return a.z - b.z;
  11858. } else {
  11859. return a.id - b.id;
  11860. }
  11861. }
  11862. function reversePainterSortStable(a, b) {
  11863. if (a.groupOrder !== b.groupOrder) {
  11864. return a.groupOrder - b.groupOrder;
  11865. } else if (a.renderOrder !== b.renderOrder) {
  11866. return a.renderOrder - b.renderOrder;
  11867. } else if (a.z !== b.z) {
  11868. return b.z - a.z;
  11869. } else {
  11870. return a.id - b.id;
  11871. }
  11872. }
  11873. function WebGLRenderList(properties) {
  11874. var renderItems = [];
  11875. var renderItemsIndex = 0;
  11876. var opaque = [];
  11877. var transparent = [];
  11878. var defaultProgram = {
  11879. id: -1
  11880. };
  11881. function init() {
  11882. renderItemsIndex = 0;
  11883. opaque.length = 0;
  11884. transparent.length = 0;
  11885. }
  11886. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11887. var renderItem = renderItems[renderItemsIndex];
  11888. var materialProperties = properties.get(material);
  11889. if (renderItem === undefined) {
  11890. renderItem = {
  11891. id: object.id,
  11892. object: object,
  11893. geometry: geometry,
  11894. material: material,
  11895. program: materialProperties.program || defaultProgram,
  11896. groupOrder: groupOrder,
  11897. renderOrder: object.renderOrder,
  11898. z: z,
  11899. group: group
  11900. };
  11901. renderItems[renderItemsIndex] = renderItem;
  11902. } else {
  11903. renderItem.id = object.id;
  11904. renderItem.object = object;
  11905. renderItem.geometry = geometry;
  11906. renderItem.material = material;
  11907. renderItem.program = materialProperties.program || defaultProgram;
  11908. renderItem.groupOrder = groupOrder;
  11909. renderItem.renderOrder = object.renderOrder;
  11910. renderItem.z = z;
  11911. renderItem.group = group;
  11912. }
  11913. renderItemsIndex++;
  11914. return renderItem;
  11915. }
  11916. function push(object, geometry, material, groupOrder, z, group) {
  11917. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11918. (material.transparent === true ? transparent : opaque).push(renderItem);
  11919. }
  11920. function unshift(object, geometry, material, groupOrder, z, group) {
  11921. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11922. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11923. }
  11924. function sort(customOpaqueSort, customTransparentSort) {
  11925. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11926. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11927. }
  11928. function finish() {
  11929. // Clear references from inactive renderItems in the list
  11930. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11931. var renderItem = renderItems[i];
  11932. if (renderItem.id === null) break;
  11933. renderItem.id = null;
  11934. renderItem.object = null;
  11935. renderItem.geometry = null;
  11936. renderItem.material = null;
  11937. renderItem.program = null;
  11938. renderItem.group = null;
  11939. }
  11940. }
  11941. return {
  11942. opaque: opaque,
  11943. transparent: transparent,
  11944. init: init,
  11945. push: push,
  11946. unshift: unshift,
  11947. finish: finish,
  11948. sort: sort
  11949. };
  11950. }
  11951. function WebGLRenderLists(properties) {
  11952. var lists = new WeakMap();
  11953. function get(scene, renderCallDepth) {
  11954. var list;
  11955. if (lists.has(scene) === false) {
  11956. list = new WebGLRenderList(properties);
  11957. lists.set(scene, [list]);
  11958. } else {
  11959. if (renderCallDepth >= lists.get(scene).length) {
  11960. list = new WebGLRenderList(properties);
  11961. lists.get(scene).push(list);
  11962. } else {
  11963. list = lists.get(scene)[renderCallDepth];
  11964. }
  11965. }
  11966. return list;
  11967. }
  11968. function dispose() {
  11969. lists = new WeakMap();
  11970. }
  11971. return {
  11972. get: get,
  11973. dispose: dispose
  11974. };
  11975. }
  11976. function UniformsCache() {
  11977. var lights = {};
  11978. return {
  11979. get: function get(light) {
  11980. if (lights[light.id] !== undefined) {
  11981. return lights[light.id];
  11982. }
  11983. var uniforms;
  11984. switch (light.type) {
  11985. case 'DirectionalLight':
  11986. uniforms = {
  11987. direction: new Vector3(),
  11988. color: new Color()
  11989. };
  11990. break;
  11991. case 'SpotLight':
  11992. uniforms = {
  11993. position: new Vector3(),
  11994. direction: new Vector3(),
  11995. color: new Color(),
  11996. distance: 0,
  11997. coneCos: 0,
  11998. penumbraCos: 0,
  11999. decay: 0
  12000. };
  12001. break;
  12002. case 'PointLight':
  12003. uniforms = {
  12004. position: new Vector3(),
  12005. color: new Color(),
  12006. distance: 0,
  12007. decay: 0
  12008. };
  12009. break;
  12010. case 'HemisphereLight':
  12011. uniforms = {
  12012. direction: new Vector3(),
  12013. skyColor: new Color(),
  12014. groundColor: new Color()
  12015. };
  12016. break;
  12017. case 'RectAreaLight':
  12018. uniforms = {
  12019. color: new Color(),
  12020. position: new Vector3(),
  12021. halfWidth: new Vector3(),
  12022. halfHeight: new Vector3()
  12023. };
  12024. break;
  12025. }
  12026. lights[light.id] = uniforms;
  12027. return uniforms;
  12028. }
  12029. };
  12030. }
  12031. function ShadowUniformsCache() {
  12032. var lights = {};
  12033. return {
  12034. get: function get(light) {
  12035. if (lights[light.id] !== undefined) {
  12036. return lights[light.id];
  12037. }
  12038. var uniforms;
  12039. switch (light.type) {
  12040. case 'DirectionalLight':
  12041. uniforms = {
  12042. shadowBias: 0,
  12043. shadowNormalBias: 0,
  12044. shadowRadius: 1,
  12045. shadowMapSize: new Vector2()
  12046. };
  12047. break;
  12048. case 'SpotLight':
  12049. uniforms = {
  12050. shadowBias: 0,
  12051. shadowNormalBias: 0,
  12052. shadowRadius: 1,
  12053. shadowMapSize: new Vector2()
  12054. };
  12055. break;
  12056. case 'PointLight':
  12057. uniforms = {
  12058. shadowBias: 0,
  12059. shadowNormalBias: 0,
  12060. shadowRadius: 1,
  12061. shadowMapSize: new Vector2(),
  12062. shadowCameraNear: 1,
  12063. shadowCameraFar: 1000
  12064. };
  12065. break;
  12066. // TODO (abelnation): set RectAreaLight shadow uniforms
  12067. }
  12068. lights[light.id] = uniforms;
  12069. return uniforms;
  12070. }
  12071. };
  12072. }
  12073. var nextVersion = 0;
  12074. function shadowCastingLightsFirst(lightA, lightB) {
  12075. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  12076. }
  12077. function WebGLLights(extensions, capabilities) {
  12078. var cache = new UniformsCache();
  12079. var shadowCache = ShadowUniformsCache();
  12080. var state = {
  12081. version: 0,
  12082. hash: {
  12083. directionalLength: -1,
  12084. pointLength: -1,
  12085. spotLength: -1,
  12086. rectAreaLength: -1,
  12087. hemiLength: -1,
  12088. numDirectionalShadows: -1,
  12089. numPointShadows: -1,
  12090. numSpotShadows: -1
  12091. },
  12092. ambient: [0, 0, 0],
  12093. probe: [],
  12094. directional: [],
  12095. directionalShadow: [],
  12096. directionalShadowMap: [],
  12097. directionalShadowMatrix: [],
  12098. spot: [],
  12099. spotShadow: [],
  12100. spotShadowMap: [],
  12101. spotShadowMatrix: [],
  12102. rectArea: [],
  12103. rectAreaLTC1: null,
  12104. rectAreaLTC2: null,
  12105. point: [],
  12106. pointShadow: [],
  12107. pointShadowMap: [],
  12108. pointShadowMatrix: [],
  12109. hemi: []
  12110. };
  12111. for (var i = 0; i < 9; i++) {
  12112. state.probe.push(new Vector3());
  12113. }
  12114. var vector3 = new Vector3();
  12115. var matrix4 = new Matrix4();
  12116. var matrix42 = new Matrix4();
  12117. function setup(lights) {
  12118. var r = 0,
  12119. g = 0,
  12120. b = 0;
  12121. for (var _i = 0; _i < 9; _i++) {
  12122. state.probe[_i].set(0, 0, 0);
  12123. }
  12124. var directionalLength = 0;
  12125. var pointLength = 0;
  12126. var spotLength = 0;
  12127. var rectAreaLength = 0;
  12128. var hemiLength = 0;
  12129. var numDirectionalShadows = 0;
  12130. var numPointShadows = 0;
  12131. var numSpotShadows = 0;
  12132. lights.sort(shadowCastingLightsFirst);
  12133. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  12134. var light = lights[_i2];
  12135. var color = light.color;
  12136. var intensity = light.intensity;
  12137. var distance = light.distance;
  12138. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  12139. if (light.isAmbientLight) {
  12140. r += color.r * intensity;
  12141. g += color.g * intensity;
  12142. b += color.b * intensity;
  12143. } else if (light.isLightProbe) {
  12144. for (var j = 0; j < 9; j++) {
  12145. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  12146. }
  12147. } else if (light.isDirectionalLight) {
  12148. var uniforms = cache.get(light);
  12149. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  12150. if (light.castShadow) {
  12151. var shadow = light.shadow;
  12152. var shadowUniforms = shadowCache.get(light);
  12153. shadowUniforms.shadowBias = shadow.bias;
  12154. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12155. shadowUniforms.shadowRadius = shadow.radius;
  12156. shadowUniforms.shadowMapSize = shadow.mapSize;
  12157. state.directionalShadow[directionalLength] = shadowUniforms;
  12158. state.directionalShadowMap[directionalLength] = shadowMap;
  12159. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  12160. numDirectionalShadows++;
  12161. }
  12162. state.directional[directionalLength] = uniforms;
  12163. directionalLength++;
  12164. } else if (light.isSpotLight) {
  12165. var _uniforms = cache.get(light);
  12166. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  12167. _uniforms.color.copy(color).multiplyScalar(intensity);
  12168. _uniforms.distance = distance;
  12169. _uniforms.coneCos = Math.cos(light.angle);
  12170. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  12171. _uniforms.decay = light.decay;
  12172. if (light.castShadow) {
  12173. var _shadow = light.shadow;
  12174. var _shadowUniforms = shadowCache.get(light);
  12175. _shadowUniforms.shadowBias = _shadow.bias;
  12176. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  12177. _shadowUniforms.shadowRadius = _shadow.radius;
  12178. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  12179. state.spotShadow[spotLength] = _shadowUniforms;
  12180. state.spotShadowMap[spotLength] = shadowMap;
  12181. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  12182. numSpotShadows++;
  12183. }
  12184. state.spot[spotLength] = _uniforms;
  12185. spotLength++;
  12186. } else if (light.isRectAreaLight) {
  12187. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  12188. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12189. // (b) intensity is the brightness of the light
  12190. _uniforms2.color.copy(color).multiplyScalar(intensity);
  12191. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12192. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12193. state.rectArea[rectAreaLength] = _uniforms2;
  12194. rectAreaLength++;
  12195. } else if (light.isPointLight) {
  12196. var _uniforms3 = cache.get(light);
  12197. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  12198. _uniforms3.distance = light.distance;
  12199. _uniforms3.decay = light.decay;
  12200. if (light.castShadow) {
  12201. var _shadow2 = light.shadow;
  12202. var _shadowUniforms2 = shadowCache.get(light);
  12203. _shadowUniforms2.shadowBias = _shadow2.bias;
  12204. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  12205. _shadowUniforms2.shadowRadius = _shadow2.radius;
  12206. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  12207. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  12208. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  12209. state.pointShadow[pointLength] = _shadowUniforms2;
  12210. state.pointShadowMap[pointLength] = shadowMap;
  12211. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  12212. numPointShadows++;
  12213. }
  12214. state.point[pointLength] = _uniforms3;
  12215. pointLength++;
  12216. } else if (light.isHemisphereLight) {
  12217. var _uniforms4 = cache.get(light);
  12218. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  12219. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  12220. state.hemi[hemiLength] = _uniforms4;
  12221. hemiLength++;
  12222. }
  12223. }
  12224. if (rectAreaLength > 0) {
  12225. if (capabilities.isWebGL2) {
  12226. // WebGL 2
  12227. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12228. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12229. } else {
  12230. // WebGL 1
  12231. if (extensions.has('OES_texture_float_linear') === true) {
  12232. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12233. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12234. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  12235. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12236. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12237. } else {
  12238. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  12239. }
  12240. }
  12241. }
  12242. state.ambient[0] = r;
  12243. state.ambient[1] = g;
  12244. state.ambient[2] = b;
  12245. var hash = state.hash;
  12246. 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) {
  12247. state.directional.length = directionalLength;
  12248. state.spot.length = spotLength;
  12249. state.rectArea.length = rectAreaLength;
  12250. state.point.length = pointLength;
  12251. state.hemi.length = hemiLength;
  12252. state.directionalShadow.length = numDirectionalShadows;
  12253. state.directionalShadowMap.length = numDirectionalShadows;
  12254. state.pointShadow.length = numPointShadows;
  12255. state.pointShadowMap.length = numPointShadows;
  12256. state.spotShadow.length = numSpotShadows;
  12257. state.spotShadowMap.length = numSpotShadows;
  12258. state.directionalShadowMatrix.length = numDirectionalShadows;
  12259. state.pointShadowMatrix.length = numPointShadows;
  12260. state.spotShadowMatrix.length = numSpotShadows;
  12261. hash.directionalLength = directionalLength;
  12262. hash.pointLength = pointLength;
  12263. hash.spotLength = spotLength;
  12264. hash.rectAreaLength = rectAreaLength;
  12265. hash.hemiLength = hemiLength;
  12266. hash.numDirectionalShadows = numDirectionalShadows;
  12267. hash.numPointShadows = numPointShadows;
  12268. hash.numSpotShadows = numSpotShadows;
  12269. state.version = nextVersion++;
  12270. }
  12271. }
  12272. function setupView(lights, camera) {
  12273. var directionalLength = 0;
  12274. var pointLength = 0;
  12275. var spotLength = 0;
  12276. var rectAreaLength = 0;
  12277. var hemiLength = 0;
  12278. var viewMatrix = camera.matrixWorldInverse;
  12279. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  12280. var light = lights[_i3];
  12281. if (light.isDirectionalLight) {
  12282. var uniforms = state.directional[directionalLength];
  12283. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  12284. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12285. uniforms.direction.sub(vector3);
  12286. uniforms.direction.transformDirection(viewMatrix);
  12287. directionalLength++;
  12288. } else if (light.isSpotLight) {
  12289. var _uniforms5 = state.spot[spotLength];
  12290. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  12291. _uniforms5.position.applyMatrix4(viewMatrix);
  12292. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  12293. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12294. _uniforms5.direction.sub(vector3);
  12295. _uniforms5.direction.transformDirection(viewMatrix);
  12296. spotLength++;
  12297. } else if (light.isRectAreaLight) {
  12298. var _uniforms6 = state.rectArea[rectAreaLength];
  12299. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  12300. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  12301. matrix42.identity();
  12302. matrix4.copy(light.matrixWorld);
  12303. matrix4.premultiply(viewMatrix);
  12304. matrix42.extractRotation(matrix4);
  12305. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12306. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12307. _uniforms6.halfWidth.applyMatrix4(matrix42);
  12308. _uniforms6.halfHeight.applyMatrix4(matrix42);
  12309. rectAreaLength++;
  12310. } else if (light.isPointLight) {
  12311. var _uniforms7 = state.point[pointLength];
  12312. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  12313. _uniforms7.position.applyMatrix4(viewMatrix);
  12314. pointLength++;
  12315. } else if (light.isHemisphereLight) {
  12316. var _uniforms8 = state.hemi[hemiLength];
  12317. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  12318. _uniforms8.direction.transformDirection(viewMatrix);
  12319. _uniforms8.direction.normalize();
  12320. hemiLength++;
  12321. }
  12322. }
  12323. }
  12324. return {
  12325. setup: setup,
  12326. setupView: setupView,
  12327. state: state
  12328. };
  12329. }
  12330. function WebGLRenderState(extensions, capabilities) {
  12331. var lights = new WebGLLights(extensions, capabilities);
  12332. var lightsArray = [];
  12333. var shadowsArray = [];
  12334. function init() {
  12335. lightsArray.length = 0;
  12336. shadowsArray.length = 0;
  12337. }
  12338. function pushLight(light) {
  12339. lightsArray.push(light);
  12340. }
  12341. function pushShadow(shadowLight) {
  12342. shadowsArray.push(shadowLight);
  12343. }
  12344. function setupLights() {
  12345. lights.setup(lightsArray);
  12346. }
  12347. function setupLightsView(camera) {
  12348. lights.setupView(lightsArray, camera);
  12349. }
  12350. var state = {
  12351. lightsArray: lightsArray,
  12352. shadowsArray: shadowsArray,
  12353. lights: lights
  12354. };
  12355. return {
  12356. init: init,
  12357. state: state,
  12358. setupLights: setupLights,
  12359. setupLightsView: setupLightsView,
  12360. pushLight: pushLight,
  12361. pushShadow: pushShadow
  12362. };
  12363. }
  12364. function WebGLRenderStates(extensions, capabilities) {
  12365. var renderStates = new WeakMap();
  12366. function get(scene, renderCallDepth) {
  12367. if (renderCallDepth === void 0) {
  12368. renderCallDepth = 0;
  12369. }
  12370. var renderState;
  12371. if (renderStates.has(scene) === false) {
  12372. renderState = new WebGLRenderState(extensions, capabilities);
  12373. renderStates.set(scene, [renderState]);
  12374. } else {
  12375. if (renderCallDepth >= renderStates.get(scene).length) {
  12376. renderState = new WebGLRenderState(extensions, capabilities);
  12377. renderStates.get(scene).push(renderState);
  12378. } else {
  12379. renderState = renderStates.get(scene)[renderCallDepth];
  12380. }
  12381. }
  12382. return renderState;
  12383. }
  12384. function dispose() {
  12385. renderStates = new WeakMap();
  12386. }
  12387. return {
  12388. get: get,
  12389. dispose: dispose
  12390. };
  12391. }
  12392. /**
  12393. * parameters = {
  12394. *
  12395. * opacity: <float>,
  12396. *
  12397. * map: new THREE.Texture( <Image> ),
  12398. *
  12399. * alphaMap: new THREE.Texture( <Image> ),
  12400. *
  12401. * displacementMap: new THREE.Texture( <Image> ),
  12402. * displacementScale: <float>,
  12403. * displacementBias: <float>,
  12404. *
  12405. * wireframe: <boolean>,
  12406. * wireframeLinewidth: <float>
  12407. * }
  12408. */
  12409. var MeshDepthMaterial = /*#__PURE__*/function (_Material) {
  12410. _inheritsLoose(MeshDepthMaterial, _Material);
  12411. function MeshDepthMaterial(parameters) {
  12412. var _this;
  12413. _this = _Material.call(this) || this;
  12414. _this.type = 'MeshDepthMaterial';
  12415. _this.depthPacking = BasicDepthPacking;
  12416. _this.skinning = false;
  12417. _this.morphTargets = false;
  12418. _this.map = null;
  12419. _this.alphaMap = null;
  12420. _this.displacementMap = null;
  12421. _this.displacementScale = 1;
  12422. _this.displacementBias = 0;
  12423. _this.wireframe = false;
  12424. _this.wireframeLinewidth = 1;
  12425. _this.fog = false;
  12426. _this.setValues(parameters);
  12427. return _this;
  12428. }
  12429. var _proto = MeshDepthMaterial.prototype;
  12430. _proto.copy = function copy(source) {
  12431. _Material.prototype.copy.call(this, source);
  12432. this.depthPacking = source.depthPacking;
  12433. this.skinning = source.skinning;
  12434. this.morphTargets = source.morphTargets;
  12435. this.map = source.map;
  12436. this.alphaMap = source.alphaMap;
  12437. this.displacementMap = source.displacementMap;
  12438. this.displacementScale = source.displacementScale;
  12439. this.displacementBias = source.displacementBias;
  12440. this.wireframe = source.wireframe;
  12441. this.wireframeLinewidth = source.wireframeLinewidth;
  12442. return this;
  12443. };
  12444. return MeshDepthMaterial;
  12445. }(Material);
  12446. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12447. /**
  12448. * parameters = {
  12449. *
  12450. * referencePosition: <float>,
  12451. * nearDistance: <float>,
  12452. * farDistance: <float>,
  12453. *
  12454. * skinning: <bool>,
  12455. * morphTargets: <bool>,
  12456. *
  12457. * map: new THREE.Texture( <Image> ),
  12458. *
  12459. * alphaMap: new THREE.Texture( <Image> ),
  12460. *
  12461. * displacementMap: new THREE.Texture( <Image> ),
  12462. * displacementScale: <float>,
  12463. * displacementBias: <float>
  12464. *
  12465. * }
  12466. */
  12467. var MeshDistanceMaterial = /*#__PURE__*/function (_Material) {
  12468. _inheritsLoose(MeshDistanceMaterial, _Material);
  12469. function MeshDistanceMaterial(parameters) {
  12470. var _this;
  12471. _this = _Material.call(this) || this;
  12472. _this.type = 'MeshDistanceMaterial';
  12473. _this.referencePosition = new Vector3();
  12474. _this.nearDistance = 1;
  12475. _this.farDistance = 1000;
  12476. _this.skinning = false;
  12477. _this.morphTargets = false;
  12478. _this.map = null;
  12479. _this.alphaMap = null;
  12480. _this.displacementMap = null;
  12481. _this.displacementScale = 1;
  12482. _this.displacementBias = 0;
  12483. _this.fog = false;
  12484. _this.setValues(parameters);
  12485. return _this;
  12486. }
  12487. var _proto = MeshDistanceMaterial.prototype;
  12488. _proto.copy = function copy(source) {
  12489. _Material.prototype.copy.call(this, source);
  12490. this.referencePosition.copy(source.referencePosition);
  12491. this.nearDistance = source.nearDistance;
  12492. this.farDistance = source.farDistance;
  12493. this.skinning = source.skinning;
  12494. this.morphTargets = source.morphTargets;
  12495. this.map = source.map;
  12496. this.alphaMap = source.alphaMap;
  12497. this.displacementMap = source.displacementMap;
  12498. this.displacementScale = source.displacementScale;
  12499. this.displacementBias = source.displacementBias;
  12500. return this;
  12501. };
  12502. return MeshDistanceMaterial;
  12503. }(Material);
  12504. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12505. 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}";
  12506. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12507. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  12508. var _frustum = new Frustum();
  12509. var _shadowMapSize = new Vector2(),
  12510. _viewportSize = new Vector2(),
  12511. _viewport = new Vector4(),
  12512. _depthMaterials = [],
  12513. _distanceMaterials = [],
  12514. _materialCache = {};
  12515. var shadowSide = {
  12516. 0: BackSide,
  12517. 1: FrontSide,
  12518. 2: DoubleSide
  12519. };
  12520. var shadowMaterialVertical = new ShaderMaterial({
  12521. defines: {
  12522. SAMPLE_RATE: 2.0 / 8.0,
  12523. HALF_SAMPLE_RATE: 1.0 / 8.0
  12524. },
  12525. uniforms: {
  12526. shadow_pass: {
  12527. value: null
  12528. },
  12529. resolution: {
  12530. value: new Vector2()
  12531. },
  12532. radius: {
  12533. value: 4.0
  12534. }
  12535. },
  12536. vertexShader: vsm_vert,
  12537. fragmentShader: vsm_frag
  12538. });
  12539. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12540. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12541. var fullScreenTri = new BufferGeometry();
  12542. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12543. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12544. var scope = this;
  12545. this.enabled = false;
  12546. this.autoUpdate = true;
  12547. this.needsUpdate = false;
  12548. this.type = PCFShadowMap;
  12549. this.render = function (lights, scene, camera) {
  12550. if (scope.enabled === false) return;
  12551. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12552. if (lights.length === 0) return;
  12553. var currentRenderTarget = _renderer.getRenderTarget();
  12554. var activeCubeFace = _renderer.getActiveCubeFace();
  12555. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12556. var _state = _renderer.state; // Set GL state for depth map.
  12557. _state.setBlending(NoBlending);
  12558. _state.buffers.color.setClear(1, 1, 1, 1);
  12559. _state.buffers.depth.setTest(true);
  12560. _state.setScissorTest(false); // render depth map
  12561. for (var i = 0, il = lights.length; i < il; i++) {
  12562. var light = lights[i];
  12563. var shadow = light.shadow;
  12564. if (shadow === undefined) {
  12565. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12566. continue;
  12567. }
  12568. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12569. _shadowMapSize.copy(shadow.mapSize);
  12570. var shadowFrameExtents = shadow.getFrameExtents();
  12571. _shadowMapSize.multiply(shadowFrameExtents);
  12572. _viewportSize.copy(shadow.mapSize);
  12573. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12574. if (_shadowMapSize.x > maxTextureSize) {
  12575. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12576. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12577. shadow.mapSize.x = _viewportSize.x;
  12578. }
  12579. if (_shadowMapSize.y > maxTextureSize) {
  12580. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12581. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12582. shadow.mapSize.y = _viewportSize.y;
  12583. }
  12584. }
  12585. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12586. var pars = {
  12587. minFilter: LinearFilter,
  12588. magFilter: LinearFilter,
  12589. format: RGBAFormat
  12590. };
  12591. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12592. shadow.map.texture.name = light.name + '.shadowMap';
  12593. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12594. shadow.camera.updateProjectionMatrix();
  12595. }
  12596. if (shadow.map === null) {
  12597. var _pars = {
  12598. minFilter: NearestFilter,
  12599. magFilter: NearestFilter,
  12600. format: RGBAFormat
  12601. };
  12602. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12603. shadow.map.texture.name = light.name + '.shadowMap';
  12604. shadow.camera.updateProjectionMatrix();
  12605. }
  12606. _renderer.setRenderTarget(shadow.map);
  12607. _renderer.clear();
  12608. var viewportCount = shadow.getViewportCount();
  12609. for (var vp = 0; vp < viewportCount; vp++) {
  12610. var viewport = shadow.getViewport(vp);
  12611. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12612. _state.viewport(_viewport);
  12613. shadow.updateMatrices(light, vp);
  12614. _frustum = shadow.getFrustum();
  12615. renderObject(scene, camera, shadow.camera, light, this.type);
  12616. } // do blur pass for VSM
  12617. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12618. VSMPass(shadow, camera);
  12619. }
  12620. shadow.needsUpdate = false;
  12621. }
  12622. scope.needsUpdate = false;
  12623. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12624. };
  12625. function VSMPass(shadow, camera) {
  12626. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12627. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12628. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12629. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12630. _renderer.setRenderTarget(shadow.mapPass);
  12631. _renderer.clear();
  12632. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12633. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12634. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12635. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12636. _renderer.setRenderTarget(shadow.map);
  12637. _renderer.clear();
  12638. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12639. }
  12640. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12641. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12642. var material = _depthMaterials[index];
  12643. if (material === undefined) {
  12644. material = new MeshDepthMaterial({
  12645. depthPacking: RGBADepthPacking,
  12646. morphTargets: useMorphing,
  12647. skinning: useSkinning
  12648. });
  12649. _depthMaterials[index] = material;
  12650. }
  12651. return material;
  12652. }
  12653. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12654. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12655. var material = _distanceMaterials[index];
  12656. if (material === undefined) {
  12657. material = new MeshDistanceMaterial({
  12658. morphTargets: useMorphing,
  12659. skinning: useSkinning
  12660. });
  12661. _distanceMaterials[index] = material;
  12662. }
  12663. return material;
  12664. }
  12665. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12666. var result = null;
  12667. var getMaterialVariant = getDepthMaterialVariant;
  12668. var customMaterial = object.customDepthMaterial;
  12669. if (light.isPointLight === true) {
  12670. getMaterialVariant = getDistanceMaterialVariant;
  12671. customMaterial = object.customDistanceMaterial;
  12672. }
  12673. if (customMaterial === undefined) {
  12674. var useMorphing = false;
  12675. if (material.morphTargets === true) {
  12676. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12677. }
  12678. var useSkinning = false;
  12679. if (object.isSkinnedMesh === true) {
  12680. if (material.skinning === true) {
  12681. useSkinning = true;
  12682. } else {
  12683. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12684. }
  12685. }
  12686. var useInstancing = object.isInstancedMesh === true;
  12687. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12688. } else {
  12689. result = customMaterial;
  12690. }
  12691. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12692. // in this case we need a unique material instance reflecting the
  12693. // appropriate state
  12694. var keyA = result.uuid,
  12695. keyB = material.uuid;
  12696. var materialsForVariant = _materialCache[keyA];
  12697. if (materialsForVariant === undefined) {
  12698. materialsForVariant = {};
  12699. _materialCache[keyA] = materialsForVariant;
  12700. }
  12701. var cachedMaterial = materialsForVariant[keyB];
  12702. if (cachedMaterial === undefined) {
  12703. cachedMaterial = result.clone();
  12704. materialsForVariant[keyB] = cachedMaterial;
  12705. }
  12706. result = cachedMaterial;
  12707. }
  12708. result.visible = material.visible;
  12709. result.wireframe = material.wireframe;
  12710. if (type === VSMShadowMap) {
  12711. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12712. } else {
  12713. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12714. }
  12715. result.clipShadows = material.clipShadows;
  12716. result.clippingPlanes = material.clippingPlanes;
  12717. result.clipIntersection = material.clipIntersection;
  12718. result.wireframeLinewidth = material.wireframeLinewidth;
  12719. result.linewidth = material.linewidth;
  12720. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12721. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12722. result.nearDistance = shadowCameraNear;
  12723. result.farDistance = shadowCameraFar;
  12724. }
  12725. return result;
  12726. }
  12727. function renderObject(object, camera, shadowCamera, light, type) {
  12728. if (object.visible === false) return;
  12729. var visible = object.layers.test(camera.layers);
  12730. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12731. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12732. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12733. var geometry = _objects.update(object);
  12734. var material = object.material;
  12735. if (Array.isArray(material)) {
  12736. var groups = geometry.groups;
  12737. for (var k = 0, kl = groups.length; k < kl; k++) {
  12738. var group = groups[k];
  12739. var groupMaterial = material[group.materialIndex];
  12740. if (groupMaterial && groupMaterial.visible) {
  12741. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12742. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12743. }
  12744. }
  12745. } else if (material.visible) {
  12746. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12747. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12748. }
  12749. }
  12750. }
  12751. var children = object.children;
  12752. for (var i = 0, l = children.length; i < l; i++) {
  12753. renderObject(children[i], camera, shadowCamera, light, type);
  12754. }
  12755. }
  12756. }
  12757. function WebGLState(gl, extensions, capabilities) {
  12758. var _equationToGL, _factorToGL;
  12759. var isWebGL2 = capabilities.isWebGL2;
  12760. function ColorBuffer() {
  12761. var locked = false;
  12762. var color = new Vector4();
  12763. var currentColorMask = null;
  12764. var currentColorClear = new Vector4(0, 0, 0, 0);
  12765. return {
  12766. setMask: function setMask(colorMask) {
  12767. if (currentColorMask !== colorMask && !locked) {
  12768. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12769. currentColorMask = colorMask;
  12770. }
  12771. },
  12772. setLocked: function setLocked(lock) {
  12773. locked = lock;
  12774. },
  12775. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12776. if (premultipliedAlpha === true) {
  12777. r *= a;
  12778. g *= a;
  12779. b *= a;
  12780. }
  12781. color.set(r, g, b, a);
  12782. if (currentColorClear.equals(color) === false) {
  12783. gl.clearColor(r, g, b, a);
  12784. currentColorClear.copy(color);
  12785. }
  12786. },
  12787. reset: function reset() {
  12788. locked = false;
  12789. currentColorMask = null;
  12790. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12791. }
  12792. };
  12793. }
  12794. function DepthBuffer() {
  12795. var locked = false;
  12796. var currentDepthMask = null;
  12797. var currentDepthFunc = null;
  12798. var currentDepthClear = null;
  12799. return {
  12800. setTest: function setTest(depthTest) {
  12801. if (depthTest) {
  12802. enable(2929);
  12803. } else {
  12804. disable(2929);
  12805. }
  12806. },
  12807. setMask: function setMask(depthMask) {
  12808. if (currentDepthMask !== depthMask && !locked) {
  12809. gl.depthMask(depthMask);
  12810. currentDepthMask = depthMask;
  12811. }
  12812. },
  12813. setFunc: function setFunc(depthFunc) {
  12814. if (currentDepthFunc !== depthFunc) {
  12815. if (depthFunc) {
  12816. switch (depthFunc) {
  12817. case NeverDepth:
  12818. gl.depthFunc(512);
  12819. break;
  12820. case AlwaysDepth:
  12821. gl.depthFunc(519);
  12822. break;
  12823. case LessDepth:
  12824. gl.depthFunc(513);
  12825. break;
  12826. case LessEqualDepth:
  12827. gl.depthFunc(515);
  12828. break;
  12829. case EqualDepth:
  12830. gl.depthFunc(514);
  12831. break;
  12832. case GreaterEqualDepth:
  12833. gl.depthFunc(518);
  12834. break;
  12835. case GreaterDepth:
  12836. gl.depthFunc(516);
  12837. break;
  12838. case NotEqualDepth:
  12839. gl.depthFunc(517);
  12840. break;
  12841. default:
  12842. gl.depthFunc(515);
  12843. }
  12844. } else {
  12845. gl.depthFunc(515);
  12846. }
  12847. currentDepthFunc = depthFunc;
  12848. }
  12849. },
  12850. setLocked: function setLocked(lock) {
  12851. locked = lock;
  12852. },
  12853. setClear: function setClear(depth) {
  12854. if (currentDepthClear !== depth) {
  12855. gl.clearDepth(depth);
  12856. currentDepthClear = depth;
  12857. }
  12858. },
  12859. reset: function reset() {
  12860. locked = false;
  12861. currentDepthMask = null;
  12862. currentDepthFunc = null;
  12863. currentDepthClear = null;
  12864. }
  12865. };
  12866. }
  12867. function StencilBuffer() {
  12868. var locked = false;
  12869. var currentStencilMask = null;
  12870. var currentStencilFunc = null;
  12871. var currentStencilRef = null;
  12872. var currentStencilFuncMask = null;
  12873. var currentStencilFail = null;
  12874. var currentStencilZFail = null;
  12875. var currentStencilZPass = null;
  12876. var currentStencilClear = null;
  12877. return {
  12878. setTest: function setTest(stencilTest) {
  12879. if (!locked) {
  12880. if (stencilTest) {
  12881. enable(2960);
  12882. } else {
  12883. disable(2960);
  12884. }
  12885. }
  12886. },
  12887. setMask: function setMask(stencilMask) {
  12888. if (currentStencilMask !== stencilMask && !locked) {
  12889. gl.stencilMask(stencilMask);
  12890. currentStencilMask = stencilMask;
  12891. }
  12892. },
  12893. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12894. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12895. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12896. currentStencilFunc = stencilFunc;
  12897. currentStencilRef = stencilRef;
  12898. currentStencilFuncMask = stencilMask;
  12899. }
  12900. },
  12901. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12902. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12903. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12904. currentStencilFail = stencilFail;
  12905. currentStencilZFail = stencilZFail;
  12906. currentStencilZPass = stencilZPass;
  12907. }
  12908. },
  12909. setLocked: function setLocked(lock) {
  12910. locked = lock;
  12911. },
  12912. setClear: function setClear(stencil) {
  12913. if (currentStencilClear !== stencil) {
  12914. gl.clearStencil(stencil);
  12915. currentStencilClear = stencil;
  12916. }
  12917. },
  12918. reset: function reset() {
  12919. locked = false;
  12920. currentStencilMask = null;
  12921. currentStencilFunc = null;
  12922. currentStencilRef = null;
  12923. currentStencilFuncMask = null;
  12924. currentStencilFail = null;
  12925. currentStencilZFail = null;
  12926. currentStencilZPass = null;
  12927. currentStencilClear = null;
  12928. }
  12929. };
  12930. } //
  12931. var colorBuffer = new ColorBuffer();
  12932. var depthBuffer = new DepthBuffer();
  12933. var stencilBuffer = new StencilBuffer();
  12934. var enabledCapabilities = {};
  12935. var currentProgram = null;
  12936. var currentBlendingEnabled = false;
  12937. var currentBlending = null;
  12938. var currentBlendEquation = null;
  12939. var currentBlendSrc = null;
  12940. var currentBlendDst = null;
  12941. var currentBlendEquationAlpha = null;
  12942. var currentBlendSrcAlpha = null;
  12943. var currentBlendDstAlpha = null;
  12944. var currentPremultipledAlpha = false;
  12945. var currentFlipSided = null;
  12946. var currentCullFace = null;
  12947. var currentLineWidth = null;
  12948. var currentPolygonOffsetFactor = null;
  12949. var currentPolygonOffsetUnits = null;
  12950. var maxTextures = gl.getParameter(35661);
  12951. var lineWidthAvailable = false;
  12952. var version = 0;
  12953. var glVersion = gl.getParameter(7938);
  12954. if (glVersion.indexOf('WebGL') !== -1) {
  12955. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12956. lineWidthAvailable = version >= 1.0;
  12957. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12958. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12959. lineWidthAvailable = version >= 2.0;
  12960. }
  12961. var currentTextureSlot = null;
  12962. var currentBoundTextures = {};
  12963. var currentScissor = new Vector4();
  12964. var currentViewport = new Vector4();
  12965. function createTexture(type, target, count) {
  12966. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12967. var texture = gl.createTexture();
  12968. gl.bindTexture(type, texture);
  12969. gl.texParameteri(type, 10241, 9728);
  12970. gl.texParameteri(type, 10240, 9728);
  12971. for (var i = 0; i < count; i++) {
  12972. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12973. }
  12974. return texture;
  12975. }
  12976. var emptyTextures = {};
  12977. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12978. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12979. colorBuffer.setClear(0, 0, 0, 1);
  12980. depthBuffer.setClear(1);
  12981. stencilBuffer.setClear(0);
  12982. enable(2929);
  12983. depthBuffer.setFunc(LessEqualDepth);
  12984. setFlipSided(false);
  12985. setCullFace(CullFaceBack);
  12986. enable(2884);
  12987. setBlending(NoBlending); //
  12988. function enable(id) {
  12989. if (enabledCapabilities[id] !== true) {
  12990. gl.enable(id);
  12991. enabledCapabilities[id] = true;
  12992. }
  12993. }
  12994. function disable(id) {
  12995. if (enabledCapabilities[id] !== false) {
  12996. gl.disable(id);
  12997. enabledCapabilities[id] = false;
  12998. }
  12999. }
  13000. function useProgram(program) {
  13001. if (currentProgram !== program) {
  13002. gl.useProgram(program);
  13003. currentProgram = program;
  13004. return true;
  13005. }
  13006. return false;
  13007. }
  13008. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  13009. if (isWebGL2) {
  13010. equationToGL[MinEquation] = 32775;
  13011. equationToGL[MaxEquation] = 32776;
  13012. } else {
  13013. var extension = extensions.get('EXT_blend_minmax');
  13014. if (extension !== null) {
  13015. equationToGL[MinEquation] = extension.MIN_EXT;
  13016. equationToGL[MaxEquation] = extension.MAX_EXT;
  13017. }
  13018. }
  13019. 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);
  13020. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  13021. if (blending === NoBlending) {
  13022. if (currentBlendingEnabled === true) {
  13023. disable(3042);
  13024. currentBlendingEnabled = false;
  13025. }
  13026. return;
  13027. }
  13028. if (currentBlendingEnabled === false) {
  13029. enable(3042);
  13030. currentBlendingEnabled = true;
  13031. }
  13032. if (blending !== CustomBlending) {
  13033. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  13034. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  13035. gl.blendEquation(32774);
  13036. currentBlendEquation = AddEquation;
  13037. currentBlendEquationAlpha = AddEquation;
  13038. }
  13039. if (premultipliedAlpha) {
  13040. switch (blending) {
  13041. case NormalBlending:
  13042. gl.blendFuncSeparate(1, 771, 1, 771);
  13043. break;
  13044. case AdditiveBlending:
  13045. gl.blendFunc(1, 1);
  13046. break;
  13047. case SubtractiveBlending:
  13048. gl.blendFuncSeparate(0, 0, 769, 771);
  13049. break;
  13050. case MultiplyBlending:
  13051. gl.blendFuncSeparate(0, 768, 0, 770);
  13052. break;
  13053. default:
  13054. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13055. break;
  13056. }
  13057. } else {
  13058. switch (blending) {
  13059. case NormalBlending:
  13060. gl.blendFuncSeparate(770, 771, 1, 771);
  13061. break;
  13062. case AdditiveBlending:
  13063. gl.blendFunc(770, 1);
  13064. break;
  13065. case SubtractiveBlending:
  13066. gl.blendFunc(0, 769);
  13067. break;
  13068. case MultiplyBlending:
  13069. gl.blendFunc(0, 768);
  13070. break;
  13071. default:
  13072. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13073. break;
  13074. }
  13075. }
  13076. currentBlendSrc = null;
  13077. currentBlendDst = null;
  13078. currentBlendSrcAlpha = null;
  13079. currentBlendDstAlpha = null;
  13080. currentBlending = blending;
  13081. currentPremultipledAlpha = premultipliedAlpha;
  13082. }
  13083. return;
  13084. } // custom blending
  13085. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13086. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13087. blendDstAlpha = blendDstAlpha || blendDst;
  13088. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  13089. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  13090. currentBlendEquation = blendEquation;
  13091. currentBlendEquationAlpha = blendEquationAlpha;
  13092. }
  13093. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  13094. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  13095. currentBlendSrc = blendSrc;
  13096. currentBlendDst = blendDst;
  13097. currentBlendSrcAlpha = blendSrcAlpha;
  13098. currentBlendDstAlpha = blendDstAlpha;
  13099. }
  13100. currentBlending = blending;
  13101. currentPremultipledAlpha = null;
  13102. }
  13103. function setMaterial(material, frontFaceCW) {
  13104. material.side === DoubleSide ? disable(2884) : enable(2884);
  13105. var flipSided = material.side === BackSide;
  13106. if (frontFaceCW) flipSided = !flipSided;
  13107. setFlipSided(flipSided);
  13108. 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);
  13109. depthBuffer.setFunc(material.depthFunc);
  13110. depthBuffer.setTest(material.depthTest);
  13111. depthBuffer.setMask(material.depthWrite);
  13112. colorBuffer.setMask(material.colorWrite);
  13113. var stencilWrite = material.stencilWrite;
  13114. stencilBuffer.setTest(stencilWrite);
  13115. if (stencilWrite) {
  13116. stencilBuffer.setMask(material.stencilWriteMask);
  13117. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  13118. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  13119. }
  13120. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  13121. } //
  13122. function setFlipSided(flipSided) {
  13123. if (currentFlipSided !== flipSided) {
  13124. if (flipSided) {
  13125. gl.frontFace(2304);
  13126. } else {
  13127. gl.frontFace(2305);
  13128. }
  13129. currentFlipSided = flipSided;
  13130. }
  13131. }
  13132. function setCullFace(cullFace) {
  13133. if (cullFace !== CullFaceNone) {
  13134. enable(2884);
  13135. if (cullFace !== currentCullFace) {
  13136. if (cullFace === CullFaceBack) {
  13137. gl.cullFace(1029);
  13138. } else if (cullFace === CullFaceFront) {
  13139. gl.cullFace(1028);
  13140. } else {
  13141. gl.cullFace(1032);
  13142. }
  13143. }
  13144. } else {
  13145. disable(2884);
  13146. }
  13147. currentCullFace = cullFace;
  13148. }
  13149. function setLineWidth(width) {
  13150. if (width !== currentLineWidth) {
  13151. if (lineWidthAvailable) gl.lineWidth(width);
  13152. currentLineWidth = width;
  13153. }
  13154. }
  13155. function setPolygonOffset(polygonOffset, factor, units) {
  13156. if (polygonOffset) {
  13157. enable(32823);
  13158. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  13159. gl.polygonOffset(factor, units);
  13160. currentPolygonOffsetFactor = factor;
  13161. currentPolygonOffsetUnits = units;
  13162. }
  13163. } else {
  13164. disable(32823);
  13165. }
  13166. }
  13167. function setScissorTest(scissorTest) {
  13168. if (scissorTest) {
  13169. enable(3089);
  13170. } else {
  13171. disable(3089);
  13172. }
  13173. } // texture
  13174. function activeTexture(webglSlot) {
  13175. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  13176. if (currentTextureSlot !== webglSlot) {
  13177. gl.activeTexture(webglSlot);
  13178. currentTextureSlot = webglSlot;
  13179. }
  13180. }
  13181. function bindTexture(webglType, webglTexture) {
  13182. if (currentTextureSlot === null) {
  13183. activeTexture();
  13184. }
  13185. var boundTexture = currentBoundTextures[currentTextureSlot];
  13186. if (boundTexture === undefined) {
  13187. boundTexture = {
  13188. type: undefined,
  13189. texture: undefined
  13190. };
  13191. currentBoundTextures[currentTextureSlot] = boundTexture;
  13192. }
  13193. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  13194. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  13195. boundTexture.type = webglType;
  13196. boundTexture.texture = webglTexture;
  13197. }
  13198. }
  13199. function unbindTexture() {
  13200. var boundTexture = currentBoundTextures[currentTextureSlot];
  13201. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  13202. gl.bindTexture(boundTexture.type, null);
  13203. boundTexture.type = undefined;
  13204. boundTexture.texture = undefined;
  13205. }
  13206. }
  13207. function compressedTexImage2D() {
  13208. try {
  13209. gl.compressedTexImage2D.apply(gl, arguments);
  13210. } catch (error) {
  13211. console.error('THREE.WebGLState:', error);
  13212. }
  13213. }
  13214. function texImage2D() {
  13215. try {
  13216. gl.texImage2D.apply(gl, arguments);
  13217. } catch (error) {
  13218. console.error('THREE.WebGLState:', error);
  13219. }
  13220. }
  13221. function texImage3D() {
  13222. try {
  13223. gl.texImage3D.apply(gl, arguments);
  13224. } catch (error) {
  13225. console.error('THREE.WebGLState:', error);
  13226. }
  13227. } //
  13228. function scissor(scissor) {
  13229. if (currentScissor.equals(scissor) === false) {
  13230. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  13231. currentScissor.copy(scissor);
  13232. }
  13233. }
  13234. function viewport(viewport) {
  13235. if (currentViewport.equals(viewport) === false) {
  13236. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  13237. currentViewport.copy(viewport);
  13238. }
  13239. } //
  13240. function reset() {
  13241. // reset state
  13242. gl.disable(3042);
  13243. gl.disable(2884);
  13244. gl.disable(2929);
  13245. gl.disable(32823);
  13246. gl.disable(3089);
  13247. gl.disable(2960);
  13248. gl.blendEquation(32774);
  13249. gl.blendFunc(1, 0);
  13250. gl.blendFuncSeparate(1, 0, 1, 0);
  13251. gl.colorMask(true, true, true, true);
  13252. gl.clearColor(0, 0, 0, 0);
  13253. gl.depthMask(true);
  13254. gl.depthFunc(513);
  13255. gl.clearDepth(1);
  13256. gl.stencilMask(0xffffffff);
  13257. gl.stencilFunc(519, 0, 0xffffffff);
  13258. gl.stencilOp(7680, 7680, 7680);
  13259. gl.clearStencil(0);
  13260. gl.cullFace(1029);
  13261. gl.frontFace(2305);
  13262. gl.polygonOffset(0, 0);
  13263. gl.activeTexture(33984);
  13264. gl.useProgram(null);
  13265. gl.lineWidth(1);
  13266. gl.scissor(0, 0, gl.canvas.width, gl.canvas.height);
  13267. gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); // reset internals
  13268. enabledCapabilities = {};
  13269. currentTextureSlot = null;
  13270. currentBoundTextures = {};
  13271. currentProgram = null;
  13272. currentBlendingEnabled = false;
  13273. currentBlending = null;
  13274. currentBlendEquation = null;
  13275. currentBlendSrc = null;
  13276. currentBlendDst = null;
  13277. currentBlendEquationAlpha = null;
  13278. currentBlendSrcAlpha = null;
  13279. currentBlendDstAlpha = null;
  13280. currentPremultipledAlpha = false;
  13281. currentFlipSided = null;
  13282. currentCullFace = null;
  13283. currentLineWidth = null;
  13284. currentPolygonOffsetFactor = null;
  13285. currentPolygonOffsetUnits = null;
  13286. colorBuffer.reset();
  13287. depthBuffer.reset();
  13288. stencilBuffer.reset();
  13289. }
  13290. return {
  13291. buffers: {
  13292. color: colorBuffer,
  13293. depth: depthBuffer,
  13294. stencil: stencilBuffer
  13295. },
  13296. enable: enable,
  13297. disable: disable,
  13298. useProgram: useProgram,
  13299. setBlending: setBlending,
  13300. setMaterial: setMaterial,
  13301. setFlipSided: setFlipSided,
  13302. setCullFace: setCullFace,
  13303. setLineWidth: setLineWidth,
  13304. setPolygonOffset: setPolygonOffset,
  13305. setScissorTest: setScissorTest,
  13306. activeTexture: activeTexture,
  13307. bindTexture: bindTexture,
  13308. unbindTexture: unbindTexture,
  13309. compressedTexImage2D: compressedTexImage2D,
  13310. texImage2D: texImage2D,
  13311. texImage3D: texImage3D,
  13312. scissor: scissor,
  13313. viewport: viewport,
  13314. reset: reset
  13315. };
  13316. }
  13317. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  13318. var _wrappingToGL, _filterToGL;
  13319. var isWebGL2 = capabilities.isWebGL2;
  13320. var maxTextures = capabilities.maxTextures;
  13321. var maxCubemapSize = capabilities.maxCubemapSize;
  13322. var maxTextureSize = capabilities.maxTextureSize;
  13323. var maxSamples = capabilities.maxSamples;
  13324. var _videoTextures = new WeakMap();
  13325. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13326. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13327. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13328. var useOffscreenCanvas = false;
  13329. try {
  13330. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  13331. } catch (err) {// Ignore any errors
  13332. }
  13333. function createCanvas(width, height) {
  13334. // Use OffscreenCanvas when available. Specially needed in web workers
  13335. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  13336. }
  13337. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  13338. var scale = 1; // handle case if texture exceeds max size
  13339. if (image.width > maxSize || image.height > maxSize) {
  13340. scale = maxSize / Math.max(image.width, image.height);
  13341. } // only perform resize if necessary
  13342. if (scale < 1 || needsPowerOfTwo === true) {
  13343. // only perform resize for certain image types
  13344. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  13345. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13346. var width = floor(scale * image.width);
  13347. var height = floor(scale * image.height);
  13348. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  13349. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  13350. canvas.width = width;
  13351. canvas.height = height;
  13352. var context = canvas.getContext('2d');
  13353. context.drawImage(image, 0, 0, width, height);
  13354. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  13355. return canvas;
  13356. } else {
  13357. if ('data' in image) {
  13358. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  13359. }
  13360. return image;
  13361. }
  13362. }
  13363. return image;
  13364. }
  13365. function isPowerOfTwo(image) {
  13366. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  13367. }
  13368. function textureNeedsPowerOfTwo(texture) {
  13369. if (isWebGL2) return false;
  13370. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13371. }
  13372. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  13373. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13374. }
  13375. function generateMipmap(target, texture, width, height) {
  13376. _gl.generateMipmap(target);
  13377. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13378. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  13379. }
  13380. function getInternalFormat(internalFormatName, glFormat, glType) {
  13381. if (isWebGL2 === false) return glFormat;
  13382. if (internalFormatName !== null) {
  13383. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  13384. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  13385. }
  13386. var internalFormat = glFormat;
  13387. if (glFormat === 6403) {
  13388. if (glType === 5126) internalFormat = 33326;
  13389. if (glType === 5131) internalFormat = 33325;
  13390. if (glType === 5121) internalFormat = 33321;
  13391. }
  13392. if (glFormat === 6407) {
  13393. if (glType === 5126) internalFormat = 34837;
  13394. if (glType === 5131) internalFormat = 34843;
  13395. if (glType === 5121) internalFormat = 32849;
  13396. }
  13397. if (glFormat === 6408) {
  13398. if (glType === 5126) internalFormat = 34836;
  13399. if (glType === 5131) internalFormat = 34842;
  13400. if (glType === 5121) internalFormat = 32856;
  13401. }
  13402. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  13403. extensions.get('EXT_color_buffer_float');
  13404. }
  13405. return internalFormat;
  13406. } // Fallback filters for non-power-of-2 textures
  13407. function filterFallback(f) {
  13408. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  13409. return 9728;
  13410. }
  13411. return 9729;
  13412. } //
  13413. function onTextureDispose(event) {
  13414. var texture = event.target;
  13415. texture.removeEventListener('dispose', onTextureDispose);
  13416. deallocateTexture(texture);
  13417. if (texture.isVideoTexture) {
  13418. _videoTextures.delete(texture);
  13419. }
  13420. info.memory.textures--;
  13421. }
  13422. function onRenderTargetDispose(event) {
  13423. var renderTarget = event.target;
  13424. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  13425. deallocateRenderTarget(renderTarget);
  13426. info.memory.textures--;
  13427. } //
  13428. function deallocateTexture(texture) {
  13429. var textureProperties = properties.get(texture);
  13430. if (textureProperties.__webglInit === undefined) return;
  13431. _gl.deleteTexture(textureProperties.__webglTexture);
  13432. properties.remove(texture);
  13433. }
  13434. function deallocateRenderTarget(renderTarget) {
  13435. var texture = renderTarget.texture;
  13436. var renderTargetProperties = properties.get(renderTarget);
  13437. var textureProperties = properties.get(texture);
  13438. if (!renderTarget) return;
  13439. if (textureProperties.__webglTexture !== undefined) {
  13440. _gl.deleteTexture(textureProperties.__webglTexture);
  13441. }
  13442. if (renderTarget.depthTexture) {
  13443. renderTarget.depthTexture.dispose();
  13444. }
  13445. if (renderTarget.isWebGLCubeRenderTarget) {
  13446. for (var i = 0; i < 6; i++) {
  13447. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  13448. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  13449. }
  13450. } else {
  13451. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  13452. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  13453. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  13454. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  13455. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  13456. }
  13457. properties.remove(texture);
  13458. properties.remove(renderTarget);
  13459. } //
  13460. var textureUnits = 0;
  13461. function resetTextureUnits() {
  13462. textureUnits = 0;
  13463. }
  13464. function allocateTextureUnit() {
  13465. var textureUnit = textureUnits;
  13466. if (textureUnit >= maxTextures) {
  13467. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  13468. }
  13469. textureUnits += 1;
  13470. return textureUnit;
  13471. } //
  13472. function setTexture2D(texture, slot) {
  13473. var textureProperties = properties.get(texture);
  13474. if (texture.isVideoTexture) updateVideoTexture(texture);
  13475. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13476. var image = texture.image;
  13477. if (image === undefined) {
  13478. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  13479. } else if (image.complete === false) {
  13480. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  13481. } else {
  13482. uploadTexture(textureProperties, texture, slot);
  13483. return;
  13484. }
  13485. }
  13486. state.activeTexture(33984 + slot);
  13487. state.bindTexture(3553, textureProperties.__webglTexture);
  13488. }
  13489. function setTexture2DArray(texture, slot) {
  13490. var textureProperties = properties.get(texture);
  13491. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13492. uploadTexture(textureProperties, texture, slot);
  13493. return;
  13494. }
  13495. state.activeTexture(33984 + slot);
  13496. state.bindTexture(35866, textureProperties.__webglTexture);
  13497. }
  13498. function setTexture3D(texture, slot) {
  13499. var textureProperties = properties.get(texture);
  13500. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13501. uploadTexture(textureProperties, texture, slot);
  13502. return;
  13503. }
  13504. state.activeTexture(33984 + slot);
  13505. state.bindTexture(32879, textureProperties.__webglTexture);
  13506. }
  13507. function setTextureCube(texture, slot) {
  13508. var textureProperties = properties.get(texture);
  13509. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13510. uploadCubeTexture(textureProperties, texture, slot);
  13511. return;
  13512. }
  13513. state.activeTexture(33984 + slot);
  13514. state.bindTexture(34067, textureProperties.__webglTexture);
  13515. }
  13516. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  13517. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  13518. function setTextureParameters(textureType, texture, supportsMips) {
  13519. if (supportsMips) {
  13520. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  13521. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  13522. if (textureType === 32879 || textureType === 35866) {
  13523. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  13524. }
  13525. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  13526. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  13527. } else {
  13528. _gl.texParameteri(textureType, 10242, 33071);
  13529. _gl.texParameteri(textureType, 10243, 33071);
  13530. if (textureType === 32879 || textureType === 35866) {
  13531. _gl.texParameteri(textureType, 32882, 33071);
  13532. }
  13533. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  13534. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  13535. }
  13536. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  13537. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  13538. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  13539. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  13540. }
  13541. }
  13542. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  13543. var extension = extensions.get('EXT_texture_filter_anisotropic');
  13544. if (texture.type === FloatType && extensions.has('OES_texture_float_linear') === false) return; // verify extension for WebGL 1 and WebGL 2
  13545. if (isWebGL2 === false && texture.type === HalfFloatType && extensions.has('OES_texture_half_float_linear') === false) return; // verify extension for WebGL 1 only
  13546. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  13547. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  13548. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  13549. }
  13550. }
  13551. }
  13552. function initTexture(textureProperties, texture) {
  13553. if (textureProperties.__webglInit === undefined) {
  13554. textureProperties.__webglInit = true;
  13555. texture.addEventListener('dispose', onTextureDispose);
  13556. textureProperties.__webglTexture = _gl.createTexture();
  13557. info.memory.textures++;
  13558. }
  13559. }
  13560. function uploadTexture(textureProperties, texture, slot) {
  13561. var textureType = 3553;
  13562. if (texture.isDataTexture2DArray) textureType = 35866;
  13563. if (texture.isDataTexture3D) textureType = 32879;
  13564. initTexture(textureProperties, texture);
  13565. state.activeTexture(33984 + slot);
  13566. state.bindTexture(textureType, textureProperties.__webglTexture);
  13567. _gl.pixelStorei(37440, texture.flipY);
  13568. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13569. _gl.pixelStorei(3317, texture.unpackAlignment);
  13570. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13571. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13572. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13573. glFormat = utils.convert(texture.format);
  13574. var glType = utils.convert(texture.type),
  13575. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13576. setTextureParameters(textureType, texture, supportsMips);
  13577. var mipmap;
  13578. var mipmaps = texture.mipmaps;
  13579. if (texture.isDepthTexture) {
  13580. // populate depth texture with dummy data
  13581. glInternalFormat = 6402;
  13582. if (isWebGL2) {
  13583. if (texture.type === FloatType) {
  13584. glInternalFormat = 36012;
  13585. } else if (texture.type === UnsignedIntType) {
  13586. glInternalFormat = 33190;
  13587. } else if (texture.type === UnsignedInt248Type) {
  13588. glInternalFormat = 35056;
  13589. } else {
  13590. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13591. }
  13592. } else {
  13593. if (texture.type === FloatType) {
  13594. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13595. }
  13596. } // validation checks for WebGL 1
  13597. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13598. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13599. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13600. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13601. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13602. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13603. texture.type = UnsignedShortType;
  13604. glType = utils.convert(texture.type);
  13605. }
  13606. }
  13607. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13608. // Depth stencil textures need the DEPTH_STENCIL internal format
  13609. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13610. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13611. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13612. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13613. if (texture.type !== UnsignedInt248Type) {
  13614. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13615. texture.type = UnsignedInt248Type;
  13616. glType = utils.convert(texture.type);
  13617. }
  13618. } //
  13619. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13620. } else if (texture.isDataTexture) {
  13621. // use manually created mipmaps if available
  13622. // if there are no manual mipmaps
  13623. // set 0 level mipmap and then use GL to generate other mipmap levels
  13624. if (mipmaps.length > 0 && supportsMips) {
  13625. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13626. mipmap = mipmaps[i];
  13627. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13628. }
  13629. texture.generateMipmaps = false;
  13630. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13631. } else {
  13632. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13633. textureProperties.__maxMipLevel = 0;
  13634. }
  13635. } else if (texture.isCompressedTexture) {
  13636. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13637. mipmap = mipmaps[_i];
  13638. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13639. if (glFormat !== null) {
  13640. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13641. } else {
  13642. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13643. }
  13644. } else {
  13645. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13646. }
  13647. }
  13648. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13649. } else if (texture.isDataTexture2DArray) {
  13650. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13651. textureProperties.__maxMipLevel = 0;
  13652. } else if (texture.isDataTexture3D) {
  13653. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13654. textureProperties.__maxMipLevel = 0;
  13655. } else {
  13656. // regular Texture (image, video, canvas)
  13657. // use manually created mipmaps if available
  13658. // if there are no manual mipmaps
  13659. // set 0 level mipmap and then use GL to generate other mipmap levels
  13660. if (mipmaps.length > 0 && supportsMips) {
  13661. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13662. mipmap = mipmaps[_i2];
  13663. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13664. }
  13665. texture.generateMipmaps = false;
  13666. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13667. } else {
  13668. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13669. textureProperties.__maxMipLevel = 0;
  13670. }
  13671. }
  13672. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13673. generateMipmap(textureType, texture, image.width, image.height);
  13674. }
  13675. textureProperties.__version = texture.version;
  13676. if (texture.onUpdate) texture.onUpdate(texture);
  13677. }
  13678. function uploadCubeTexture(textureProperties, texture, slot) {
  13679. if (texture.image.length !== 6) return;
  13680. initTexture(textureProperties, texture);
  13681. state.activeTexture(33984 + slot);
  13682. state.bindTexture(34067, textureProperties.__webglTexture);
  13683. _gl.pixelStorei(37440, texture.flipY);
  13684. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13685. _gl.pixelStorei(3317, texture.unpackAlignment);
  13686. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13687. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13688. var cubeImage = [];
  13689. for (var i = 0; i < 6; i++) {
  13690. if (!isCompressed && !isDataTexture) {
  13691. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13692. } else {
  13693. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13694. }
  13695. }
  13696. var image = cubeImage[0],
  13697. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13698. glFormat = utils.convert(texture.format),
  13699. glType = utils.convert(texture.type),
  13700. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13701. setTextureParameters(34067, texture, supportsMips);
  13702. var mipmaps;
  13703. if (isCompressed) {
  13704. for (var _i3 = 0; _i3 < 6; _i3++) {
  13705. mipmaps = cubeImage[_i3].mipmaps;
  13706. for (var j = 0; j < mipmaps.length; j++) {
  13707. var mipmap = mipmaps[j];
  13708. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13709. if (glFormat !== null) {
  13710. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13711. } else {
  13712. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13713. }
  13714. } else {
  13715. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13716. }
  13717. }
  13718. }
  13719. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13720. } else {
  13721. mipmaps = texture.mipmaps;
  13722. for (var _i4 = 0; _i4 < 6; _i4++) {
  13723. if (isDataTexture) {
  13724. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13725. for (var _j = 0; _j < mipmaps.length; _j++) {
  13726. var _mipmap = mipmaps[_j];
  13727. var mipmapImage = _mipmap.image[_i4].image;
  13728. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13729. }
  13730. } else {
  13731. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13732. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13733. var _mipmap2 = mipmaps[_j2];
  13734. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13735. }
  13736. }
  13737. }
  13738. textureProperties.__maxMipLevel = mipmaps.length;
  13739. }
  13740. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13741. // We assume images for cube map have the same size.
  13742. generateMipmap(34067, texture, image.width, image.height);
  13743. }
  13744. textureProperties.__version = texture.version;
  13745. if (texture.onUpdate) texture.onUpdate(texture);
  13746. } // Render targets
  13747. // Setup storage for target texture and bind it to correct framebuffer
  13748. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13749. var texture = renderTarget.texture;
  13750. var glFormat = utils.convert(texture.format);
  13751. var glType = utils.convert(texture.type);
  13752. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13753. if (textureTarget === 32879 || textureTarget === 35866) {
  13754. state.texImage3D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null);
  13755. } else {
  13756. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13757. }
  13758. _gl.bindFramebuffer(36160, framebuffer);
  13759. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(texture).__webglTexture, 0);
  13760. _gl.bindFramebuffer(36160, null);
  13761. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13762. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13763. _gl.bindRenderbuffer(36161, renderbuffer);
  13764. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13765. var glInternalFormat = 33189;
  13766. if (isMultisample) {
  13767. var depthTexture = renderTarget.depthTexture;
  13768. if (depthTexture && depthTexture.isDepthTexture) {
  13769. if (depthTexture.type === FloatType) {
  13770. glInternalFormat = 36012;
  13771. } else if (depthTexture.type === UnsignedIntType) {
  13772. glInternalFormat = 33190;
  13773. }
  13774. }
  13775. var samples = getRenderTargetSamples(renderTarget);
  13776. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13777. } else {
  13778. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13779. }
  13780. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13781. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13782. if (isMultisample) {
  13783. var _samples = getRenderTargetSamples(renderTarget);
  13784. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13785. } else {
  13786. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13787. }
  13788. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13789. } else {
  13790. var texture = renderTarget.texture;
  13791. var glFormat = utils.convert(texture.format);
  13792. var glType = utils.convert(texture.type);
  13793. var _glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13794. if (isMultisample) {
  13795. var _samples2 = getRenderTargetSamples(renderTarget);
  13796. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13797. } else {
  13798. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13799. }
  13800. }
  13801. _gl.bindRenderbuffer(36161, null);
  13802. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13803. function setupDepthTexture(framebuffer, renderTarget) {
  13804. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13805. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13806. _gl.bindFramebuffer(36160, framebuffer);
  13807. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13808. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13809. } // upload an empty depth texture with framebuffer size
  13810. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13811. renderTarget.depthTexture.image.width = renderTarget.width;
  13812. renderTarget.depthTexture.image.height = renderTarget.height;
  13813. renderTarget.depthTexture.needsUpdate = true;
  13814. }
  13815. setTexture2D(renderTarget.depthTexture, 0);
  13816. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13817. if (renderTarget.depthTexture.format === DepthFormat) {
  13818. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13819. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13820. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13821. } else {
  13822. throw new Error('Unknown depthTexture format');
  13823. }
  13824. } // Setup GL resources for a non-texture depth buffer
  13825. function setupDepthRenderbuffer(renderTarget) {
  13826. var renderTargetProperties = properties.get(renderTarget);
  13827. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13828. if (renderTarget.depthTexture) {
  13829. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13830. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13831. } else {
  13832. if (isCube) {
  13833. renderTargetProperties.__webglDepthbuffer = [];
  13834. for (var i = 0; i < 6; i++) {
  13835. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13836. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13837. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13838. }
  13839. } else {
  13840. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13841. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13842. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13843. }
  13844. }
  13845. _gl.bindFramebuffer(36160, null);
  13846. } // Set up GL resources for the render target
  13847. function setupRenderTarget(renderTarget) {
  13848. var texture = renderTarget.texture;
  13849. var renderTargetProperties = properties.get(renderTarget);
  13850. var textureProperties = properties.get(texture);
  13851. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13852. textureProperties.__webglTexture = _gl.createTexture();
  13853. info.memory.textures++;
  13854. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13855. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13856. var isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
  13857. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13858. if (isWebGL2 && texture.format === RGBFormat && (texture.type === FloatType || texture.type === HalfFloatType)) {
  13859. texture.format = RGBAFormat;
  13860. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13861. } // Setup framebuffer
  13862. if (isCube) {
  13863. renderTargetProperties.__webglFramebuffer = [];
  13864. for (var i = 0; i < 6; i++) {
  13865. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13866. }
  13867. } else {
  13868. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13869. if (isMultisample) {
  13870. if (isWebGL2) {
  13871. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13872. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13873. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13874. var glFormat = utils.convert(texture.format);
  13875. var glType = utils.convert(texture.type);
  13876. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13877. var samples = getRenderTargetSamples(renderTarget);
  13878. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13879. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13880. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13881. _gl.bindRenderbuffer(36161, null);
  13882. if (renderTarget.depthBuffer) {
  13883. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13884. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13885. }
  13886. _gl.bindFramebuffer(36160, null);
  13887. } else {
  13888. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13889. }
  13890. }
  13891. } // Setup color buffer
  13892. if (isCube) {
  13893. state.bindTexture(34067, textureProperties.__webglTexture);
  13894. setTextureParameters(34067, texture, supportsMips);
  13895. for (var _i5 = 0; _i5 < 6; _i5++) {
  13896. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13897. }
  13898. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13899. generateMipmap(34067, texture, renderTarget.width, renderTarget.height);
  13900. }
  13901. state.bindTexture(34067, null);
  13902. } else {
  13903. var glTextureType = 3553;
  13904. if (isRenderTarget3D) {
  13905. // Render targets containing layers, i.e: Texture 3D and 2d arrays
  13906. if (isWebGL2) {
  13907. var isTexture3D = texture.isDataTexture3D;
  13908. glTextureType = isTexture3D ? 32879 : 35866;
  13909. } else {
  13910. console.warn('THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.');
  13911. }
  13912. }
  13913. state.bindTexture(glTextureType, textureProperties.__webglTexture);
  13914. setTextureParameters(glTextureType, texture, supportsMips);
  13915. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, glTextureType);
  13916. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13917. generateMipmap(3553, texture, renderTarget.width, renderTarget.height);
  13918. }
  13919. state.bindTexture(3553, null);
  13920. } // Setup depth and stencil buffers
  13921. if (renderTarget.depthBuffer) {
  13922. setupDepthRenderbuffer(renderTarget);
  13923. }
  13924. }
  13925. function updateRenderTargetMipmap(renderTarget) {
  13926. var texture = renderTarget.texture;
  13927. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13928. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13929. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13930. var webglTexture = properties.get(texture).__webglTexture;
  13931. state.bindTexture(target, webglTexture);
  13932. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13933. state.bindTexture(target, null);
  13934. }
  13935. }
  13936. function updateMultisampleRenderTarget(renderTarget) {
  13937. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13938. if (isWebGL2) {
  13939. var renderTargetProperties = properties.get(renderTarget);
  13940. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13941. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13942. var width = renderTarget.width;
  13943. var height = renderTarget.height;
  13944. var mask = 16384;
  13945. if (renderTarget.depthBuffer) mask |= 256;
  13946. if (renderTarget.stencilBuffer) mask |= 1024;
  13947. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13948. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13949. } else {
  13950. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13951. }
  13952. }
  13953. }
  13954. function getRenderTargetSamples(renderTarget) {
  13955. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13956. }
  13957. function updateVideoTexture(texture) {
  13958. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13959. if (_videoTextures.get(texture) !== frame) {
  13960. _videoTextures.set(texture, frame);
  13961. texture.update();
  13962. }
  13963. } // backwards compatibility
  13964. var warnedTexture2D = false;
  13965. var warnedTextureCube = false;
  13966. function safeSetTexture2D(texture, slot) {
  13967. if (texture && texture.isWebGLRenderTarget) {
  13968. if (warnedTexture2D === false) {
  13969. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13970. warnedTexture2D = true;
  13971. }
  13972. texture = texture.texture;
  13973. }
  13974. setTexture2D(texture, slot);
  13975. }
  13976. function safeSetTextureCube(texture, slot) {
  13977. if (texture && texture.isWebGLCubeRenderTarget) {
  13978. if (warnedTextureCube === false) {
  13979. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13980. warnedTextureCube = true;
  13981. }
  13982. texture = texture.texture;
  13983. }
  13984. setTextureCube(texture, slot);
  13985. } //
  13986. this.allocateTextureUnit = allocateTextureUnit;
  13987. this.resetTextureUnits = resetTextureUnits;
  13988. this.setTexture2D = setTexture2D;
  13989. this.setTexture2DArray = setTexture2DArray;
  13990. this.setTexture3D = setTexture3D;
  13991. this.setTextureCube = setTextureCube;
  13992. this.setupRenderTarget = setupRenderTarget;
  13993. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13994. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13995. this.safeSetTexture2D = safeSetTexture2D;
  13996. this.safeSetTextureCube = safeSetTextureCube;
  13997. }
  13998. function WebGLUtils(gl, extensions, capabilities) {
  13999. var isWebGL2 = capabilities.isWebGL2;
  14000. function convert(p) {
  14001. var extension;
  14002. if (p === UnsignedByteType) return 5121;
  14003. if (p === UnsignedShort4444Type) return 32819;
  14004. if (p === UnsignedShort5551Type) return 32820;
  14005. if (p === UnsignedShort565Type) return 33635;
  14006. if (p === ByteType) return 5120;
  14007. if (p === ShortType) return 5122;
  14008. if (p === UnsignedShortType) return 5123;
  14009. if (p === IntType) return 5124;
  14010. if (p === UnsignedIntType) return 5125;
  14011. if (p === FloatType) return 5126;
  14012. if (p === HalfFloatType) {
  14013. if (isWebGL2) return 5131;
  14014. extension = extensions.get('OES_texture_half_float');
  14015. if (extension !== null) {
  14016. return extension.HALF_FLOAT_OES;
  14017. } else {
  14018. return null;
  14019. }
  14020. }
  14021. if (p === AlphaFormat) return 6406;
  14022. if (p === RGBFormat) return 6407;
  14023. if (p === RGBAFormat) return 6408;
  14024. if (p === LuminanceFormat) return 6409;
  14025. if (p === LuminanceAlphaFormat) return 6410;
  14026. if (p === DepthFormat) return 6402;
  14027. if (p === DepthStencilFormat) return 34041;
  14028. if (p === RedFormat) return 6403; // WebGL2 formats.
  14029. if (p === RedIntegerFormat) return 36244;
  14030. if (p === RGFormat) return 33319;
  14031. if (p === RGIntegerFormat) return 33320;
  14032. if (p === RGBIntegerFormat) return 36248;
  14033. if (p === RGBAIntegerFormat) return 36249;
  14034. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  14035. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  14036. if (extension !== null) {
  14037. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  14038. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  14039. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  14040. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  14041. } else {
  14042. return null;
  14043. }
  14044. }
  14045. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  14046. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  14047. if (extension !== null) {
  14048. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  14049. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  14050. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  14051. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  14052. } else {
  14053. return null;
  14054. }
  14055. }
  14056. if (p === RGB_ETC1_Format) {
  14057. extension = extensions.get('WEBGL_compressed_texture_etc1');
  14058. if (extension !== null) {
  14059. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  14060. } else {
  14061. return null;
  14062. }
  14063. }
  14064. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  14065. extension = extensions.get('WEBGL_compressed_texture_etc');
  14066. if (extension !== null) {
  14067. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  14068. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  14069. }
  14070. }
  14071. 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) {
  14072. extension = extensions.get('WEBGL_compressed_texture_astc');
  14073. if (extension !== null) {
  14074. // TODO Complete?
  14075. return p;
  14076. } else {
  14077. return null;
  14078. }
  14079. }
  14080. if (p === RGBA_BPTC_Format) {
  14081. extension = extensions.get('EXT_texture_compression_bptc');
  14082. if (extension !== null) {
  14083. // TODO Complete?
  14084. return p;
  14085. } else {
  14086. return null;
  14087. }
  14088. }
  14089. if (p === UnsignedInt248Type) {
  14090. if (isWebGL2) return 34042;
  14091. extension = extensions.get('WEBGL_depth_texture');
  14092. if (extension !== null) {
  14093. return extension.UNSIGNED_INT_24_8_WEBGL;
  14094. } else {
  14095. return null;
  14096. }
  14097. }
  14098. }
  14099. return {
  14100. convert: convert
  14101. };
  14102. }
  14103. function ArrayCamera(array) {
  14104. if (array === void 0) {
  14105. array = [];
  14106. }
  14107. PerspectiveCamera.call(this);
  14108. this.cameras = array;
  14109. }
  14110. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  14111. constructor: ArrayCamera,
  14112. isArrayCamera: true
  14113. });
  14114. var Group = /*#__PURE__*/function (_Object3D) {
  14115. _inheritsLoose(Group, _Object3D);
  14116. function Group() {
  14117. var _this;
  14118. _this = _Object3D.call(this) || this;
  14119. _this.type = 'Group';
  14120. return _this;
  14121. }
  14122. return Group;
  14123. }(Object3D);
  14124. Group.prototype.isGroup = true;
  14125. function WebXRController() {
  14126. this._targetRay = null;
  14127. this._grip = null;
  14128. this._hand = null;
  14129. }
  14130. Object.assign(WebXRController.prototype, {
  14131. constructor: WebXRController,
  14132. getHandSpace: function getHandSpace() {
  14133. if (this._hand === null) {
  14134. this._hand = new Group();
  14135. this._hand.matrixAutoUpdate = false;
  14136. this._hand.visible = false;
  14137. this._hand.joints = {};
  14138. this._hand.inputState = {
  14139. pinching: false
  14140. };
  14141. }
  14142. return this._hand;
  14143. },
  14144. getTargetRaySpace: function getTargetRaySpace() {
  14145. if (this._targetRay === null) {
  14146. this._targetRay = new Group();
  14147. this._targetRay.matrixAutoUpdate = false;
  14148. this._targetRay.visible = false;
  14149. }
  14150. return this._targetRay;
  14151. },
  14152. getGripSpace: function getGripSpace() {
  14153. if (this._grip === null) {
  14154. this._grip = new Group();
  14155. this._grip.matrixAutoUpdate = false;
  14156. this._grip.visible = false;
  14157. }
  14158. return this._grip;
  14159. },
  14160. dispatchEvent: function dispatchEvent(event) {
  14161. if (this._targetRay !== null) {
  14162. this._targetRay.dispatchEvent(event);
  14163. }
  14164. if (this._grip !== null) {
  14165. this._grip.dispatchEvent(event);
  14166. }
  14167. if (this._hand !== null) {
  14168. this._hand.dispatchEvent(event);
  14169. }
  14170. return this;
  14171. },
  14172. disconnect: function disconnect(inputSource) {
  14173. this.dispatchEvent({
  14174. type: 'disconnected',
  14175. data: inputSource
  14176. });
  14177. if (this._targetRay !== null) {
  14178. this._targetRay.visible = false;
  14179. }
  14180. if (this._grip !== null) {
  14181. this._grip.visible = false;
  14182. }
  14183. if (this._hand !== null) {
  14184. this._hand.visible = false;
  14185. }
  14186. return this;
  14187. },
  14188. update: function update(inputSource, frame, referenceSpace) {
  14189. var inputPose = null;
  14190. var gripPose = null;
  14191. var handPose = null;
  14192. var targetRay = this._targetRay;
  14193. var grip = this._grip;
  14194. var hand = this._hand;
  14195. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  14196. if (hand && inputSource.hand) {
  14197. handPose = true;
  14198. for (var _iterator = _createForOfIteratorHelperLoose(inputSource.hand.values()), _step; !(_step = _iterator()).done;) {
  14199. var inputjoint = _step.value;
  14200. // Update the joints groups with the XRJoint poses
  14201. var jointPose = frame.getJointPose(inputjoint, referenceSpace);
  14202. if (hand.joints[inputjoint.jointName] === undefined) {
  14203. // The transform of this joint will be updated with the joint pose on each frame
  14204. var _joint = new Group();
  14205. _joint.matrixAutoUpdate = false;
  14206. _joint.visible = false;
  14207. hand.joints[inputjoint.jointName] = _joint; // ??
  14208. hand.add(_joint);
  14209. }
  14210. var joint = hand.joints[inputjoint.jointName];
  14211. if (jointPose !== null) {
  14212. joint.matrix.fromArray(jointPose.transform.matrix);
  14213. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  14214. joint.jointRadius = jointPose.radius;
  14215. }
  14216. joint.visible = jointPose !== null;
  14217. } // Custom events
  14218. // Check pinchz
  14219. var indexTip = hand.joints['index-finger-tip'];
  14220. var thumbTip = hand.joints['thumb-tip'];
  14221. var distance = indexTip.position.distanceTo(thumbTip.position);
  14222. var distanceToPinch = 0.02;
  14223. var threshold = 0.005;
  14224. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  14225. hand.inputState.pinching = false;
  14226. this.dispatchEvent({
  14227. type: 'pinchend',
  14228. handedness: inputSource.handedness,
  14229. target: this
  14230. });
  14231. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  14232. hand.inputState.pinching = true;
  14233. this.dispatchEvent({
  14234. type: 'pinchstart',
  14235. handedness: inputSource.handedness,
  14236. target: this
  14237. });
  14238. }
  14239. } else {
  14240. if (targetRay !== null) {
  14241. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  14242. if (inputPose !== null) {
  14243. targetRay.matrix.fromArray(inputPose.transform.matrix);
  14244. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  14245. }
  14246. }
  14247. if (grip !== null && inputSource.gripSpace) {
  14248. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  14249. if (gripPose !== null) {
  14250. grip.matrix.fromArray(gripPose.transform.matrix);
  14251. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  14252. }
  14253. }
  14254. }
  14255. }
  14256. if (targetRay !== null) {
  14257. targetRay.visible = inputPose !== null;
  14258. }
  14259. if (grip !== null) {
  14260. grip.visible = gripPose !== null;
  14261. }
  14262. if (hand !== null) {
  14263. hand.visible = handPose !== null;
  14264. }
  14265. return this;
  14266. }
  14267. });
  14268. function WebXRManager(renderer, gl) {
  14269. var scope = this;
  14270. var session = null;
  14271. var framebufferScaleFactor = 1.0;
  14272. var referenceSpace = null;
  14273. var referenceSpaceType = 'local-floor';
  14274. var pose = null;
  14275. var controllers = [];
  14276. var inputSourcesMap = new Map(); //
  14277. var cameraL = new PerspectiveCamera();
  14278. cameraL.layers.enable(1);
  14279. cameraL.viewport = new Vector4();
  14280. var cameraR = new PerspectiveCamera();
  14281. cameraR.layers.enable(2);
  14282. cameraR.viewport = new Vector4();
  14283. var cameras = [cameraL, cameraR];
  14284. var cameraVR = new ArrayCamera();
  14285. cameraVR.layers.enable(1);
  14286. cameraVR.layers.enable(2);
  14287. var _currentDepthNear = null;
  14288. var _currentDepthFar = null; //
  14289. this.enabled = false;
  14290. this.isPresenting = false;
  14291. this.getController = function (index) {
  14292. var controller = controllers[index];
  14293. if (controller === undefined) {
  14294. controller = new WebXRController();
  14295. controllers[index] = controller;
  14296. }
  14297. return controller.getTargetRaySpace();
  14298. };
  14299. this.getControllerGrip = function (index) {
  14300. var controller = controllers[index];
  14301. if (controller === undefined) {
  14302. controller = new WebXRController();
  14303. controllers[index] = controller;
  14304. }
  14305. return controller.getGripSpace();
  14306. };
  14307. this.getHand = function (index) {
  14308. var controller = controllers[index];
  14309. if (controller === undefined) {
  14310. controller = new WebXRController();
  14311. controllers[index] = controller;
  14312. }
  14313. return controller.getHandSpace();
  14314. }; //
  14315. function onSessionEvent(event) {
  14316. var controller = inputSourcesMap.get(event.inputSource);
  14317. if (controller) {
  14318. controller.dispatchEvent({
  14319. type: event.type,
  14320. data: event.inputSource
  14321. });
  14322. }
  14323. }
  14324. function onSessionEnd() {
  14325. inputSourcesMap.forEach(function (controller, inputSource) {
  14326. controller.disconnect(inputSource);
  14327. });
  14328. inputSourcesMap.clear();
  14329. _currentDepthNear = null;
  14330. _currentDepthFar = null; //
  14331. renderer.setFramebuffer(null);
  14332. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  14333. animation.stop();
  14334. scope.isPresenting = false;
  14335. scope.dispatchEvent({
  14336. type: 'sessionend'
  14337. });
  14338. }
  14339. this.setFramebufferScaleFactor = function (value) {
  14340. framebufferScaleFactor = value;
  14341. if (scope.isPresenting === true) {
  14342. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  14343. }
  14344. };
  14345. this.setReferenceSpaceType = function (value) {
  14346. referenceSpaceType = value;
  14347. if (scope.isPresenting === true) {
  14348. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  14349. }
  14350. };
  14351. this.getReferenceSpace = function () {
  14352. return referenceSpace;
  14353. };
  14354. this.getSession = function () {
  14355. return session;
  14356. };
  14357. this.setSession = /*#__PURE__*/function () {
  14358. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
  14359. var attributes, layerInit, baseLayer;
  14360. return regeneratorRuntime.wrap(function _callee$(_context) {
  14361. while (1) {
  14362. switch (_context.prev = _context.next) {
  14363. case 0:
  14364. session = value;
  14365. if (!(session !== null)) {
  14366. _context.next = 24;
  14367. break;
  14368. }
  14369. session.addEventListener('select', onSessionEvent);
  14370. session.addEventListener('selectstart', onSessionEvent);
  14371. session.addEventListener('selectend', onSessionEvent);
  14372. session.addEventListener('squeeze', onSessionEvent);
  14373. session.addEventListener('squeezestart', onSessionEvent);
  14374. session.addEventListener('squeezeend', onSessionEvent);
  14375. session.addEventListener('end', onSessionEnd);
  14376. session.addEventListener('inputsourceschange', onInputSourcesChange);
  14377. attributes = gl.getContextAttributes();
  14378. if (!(attributes.xrCompatible !== true)) {
  14379. _context.next = 14;
  14380. break;
  14381. }
  14382. _context.next = 14;
  14383. return gl.makeXRCompatible();
  14384. case 14:
  14385. layerInit = {
  14386. antialias: attributes.antialias,
  14387. alpha: attributes.alpha,
  14388. depth: attributes.depth,
  14389. stencil: attributes.stencil,
  14390. framebufferScaleFactor: framebufferScaleFactor
  14391. }; // eslint-disable-next-line no-undef
  14392. baseLayer = new XRWebGLLayer(session, gl, layerInit);
  14393. session.updateRenderState({
  14394. baseLayer: baseLayer
  14395. });
  14396. _context.next = 19;
  14397. return session.requestReferenceSpace(referenceSpaceType);
  14398. case 19:
  14399. referenceSpace = _context.sent;
  14400. animation.setContext(session);
  14401. animation.start();
  14402. scope.isPresenting = true;
  14403. scope.dispatchEvent({
  14404. type: 'sessionstart'
  14405. });
  14406. case 24:
  14407. case "end":
  14408. return _context.stop();
  14409. }
  14410. }
  14411. }, _callee);
  14412. }));
  14413. return function (_x) {
  14414. return _ref.apply(this, arguments);
  14415. };
  14416. }();
  14417. function onInputSourcesChange(event) {
  14418. var inputSources = session.inputSources; // Assign inputSources to available controllers
  14419. for (var i = 0; i < controllers.length; i++) {
  14420. inputSourcesMap.set(inputSources[i], controllers[i]);
  14421. } // Notify disconnected
  14422. for (var _i = 0; _i < event.removed.length; _i++) {
  14423. var inputSource = event.removed[_i];
  14424. var controller = inputSourcesMap.get(inputSource);
  14425. if (controller) {
  14426. controller.dispatchEvent({
  14427. type: 'disconnected',
  14428. data: inputSource
  14429. });
  14430. inputSourcesMap.delete(inputSource);
  14431. }
  14432. } // Notify connected
  14433. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  14434. var _inputSource = event.added[_i2];
  14435. var _controller = inputSourcesMap.get(_inputSource);
  14436. if (_controller) {
  14437. _controller.dispatchEvent({
  14438. type: 'connected',
  14439. data: _inputSource
  14440. });
  14441. }
  14442. }
  14443. } //
  14444. var cameraLPos = new Vector3();
  14445. var cameraRPos = new Vector3();
  14446. /**
  14447. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14448. * the cameras' projection and world matrices have already been set.
  14449. * And that near and far planes are identical for both cameras.
  14450. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14451. */
  14452. function setProjectionFromUnion(camera, cameraL, cameraR) {
  14453. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  14454. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  14455. var ipd = cameraLPos.distanceTo(cameraRPos);
  14456. var projL = cameraL.projectionMatrix.elements;
  14457. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  14458. // most likely identical top and bottom frustum extents.
  14459. // Use the left camera for these values.
  14460. var near = projL[14] / (projL[10] - 1);
  14461. var far = projL[14] / (projL[10] + 1);
  14462. var topFov = (projL[9] + 1) / projL[5];
  14463. var bottomFov = (projL[9] - 1) / projL[5];
  14464. var leftFov = (projL[8] - 1) / projL[0];
  14465. var rightFov = (projR[8] + 1) / projR[0];
  14466. var left = near * leftFov;
  14467. var right = near * rightFov; // Calculate the new camera's position offset from the
  14468. // left camera. xOffset should be roughly half `ipd`.
  14469. var zOffset = ipd / (-leftFov + rightFov);
  14470. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  14471. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  14472. camera.translateX(xOffset);
  14473. camera.translateZ(zOffset);
  14474. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  14475. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  14476. // the values so that the near plane's position does not change in world space,
  14477. // although must now be relative to the new union camera.
  14478. var near2 = near + zOffset;
  14479. var far2 = far + zOffset;
  14480. var left2 = left - xOffset;
  14481. var right2 = right + (ipd - xOffset);
  14482. var top2 = topFov * far / far2 * near2;
  14483. var bottom2 = bottomFov * far / far2 * near2;
  14484. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  14485. }
  14486. function updateCamera(camera, parent) {
  14487. if (parent === null) {
  14488. camera.matrixWorld.copy(camera.matrix);
  14489. } else {
  14490. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  14491. }
  14492. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  14493. }
  14494. this.getCamera = function (camera) {
  14495. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14496. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14497. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  14498. // Note that the new renderState won't apply until the next frame. See #18320
  14499. session.updateRenderState({
  14500. depthNear: cameraVR.near,
  14501. depthFar: cameraVR.far
  14502. });
  14503. _currentDepthNear = cameraVR.near;
  14504. _currentDepthFar = cameraVR.far;
  14505. }
  14506. var parent = camera.parent;
  14507. var cameras = cameraVR.cameras;
  14508. updateCamera(cameraVR, parent);
  14509. for (var i = 0; i < cameras.length; i++) {
  14510. updateCamera(cameras[i], parent);
  14511. } // update camera and its children
  14512. camera.matrixWorld.copy(cameraVR.matrixWorld);
  14513. camera.matrix.copy(cameraVR.matrix);
  14514. camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
  14515. var children = camera.children;
  14516. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  14517. children[_i3].updateMatrixWorld(true);
  14518. } // update projection matrix for proper view frustum culling
  14519. if (cameras.length === 2) {
  14520. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  14521. } else {
  14522. // assume single camera setup (AR)
  14523. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  14524. }
  14525. return cameraVR;
  14526. }; // Animation Loop
  14527. var onAnimationFrameCallback = null;
  14528. function onAnimationFrame(time, frame) {
  14529. pose = frame.getViewerPose(referenceSpace);
  14530. if (pose !== null) {
  14531. var views = pose.views;
  14532. var baseLayer = session.renderState.baseLayer;
  14533. renderer.setFramebuffer(baseLayer.framebuffer);
  14534. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  14535. if (views.length !== cameraVR.cameras.length) {
  14536. cameraVR.cameras.length = 0;
  14537. cameraVRNeedsUpdate = true;
  14538. }
  14539. for (var i = 0; i < views.length; i++) {
  14540. var view = views[i];
  14541. var viewport = baseLayer.getViewport(view);
  14542. var camera = cameras[i];
  14543. camera.matrix.fromArray(view.transform.matrix);
  14544. camera.projectionMatrix.fromArray(view.projectionMatrix);
  14545. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  14546. if (i === 0) {
  14547. cameraVR.matrix.copy(camera.matrix);
  14548. }
  14549. if (cameraVRNeedsUpdate === true) {
  14550. cameraVR.cameras.push(camera);
  14551. }
  14552. }
  14553. } //
  14554. var inputSources = session.inputSources;
  14555. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  14556. var controller = controllers[_i4];
  14557. var inputSource = inputSources[_i4];
  14558. controller.update(inputSource, frame, referenceSpace);
  14559. }
  14560. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  14561. }
  14562. var animation = new WebGLAnimation();
  14563. animation.setAnimationLoop(onAnimationFrame);
  14564. this.setAnimationLoop = function (callback) {
  14565. onAnimationFrameCallback = callback;
  14566. };
  14567. this.dispose = function () {};
  14568. }
  14569. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  14570. function WebGLMaterials(properties) {
  14571. function refreshFogUniforms(uniforms, fog) {
  14572. uniforms.fogColor.value.copy(fog.color);
  14573. if (fog.isFog) {
  14574. uniforms.fogNear.value = fog.near;
  14575. uniforms.fogFar.value = fog.far;
  14576. } else if (fog.isFogExp2) {
  14577. uniforms.fogDensity.value = fog.density;
  14578. }
  14579. }
  14580. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  14581. if (material.isMeshBasicMaterial) {
  14582. refreshUniformsCommon(uniforms, material);
  14583. } else if (material.isMeshLambertMaterial) {
  14584. refreshUniformsCommon(uniforms, material);
  14585. refreshUniformsLambert(uniforms, material);
  14586. } else if (material.isMeshToonMaterial) {
  14587. refreshUniformsCommon(uniforms, material);
  14588. refreshUniformsToon(uniforms, material);
  14589. } else if (material.isMeshPhongMaterial) {
  14590. refreshUniformsCommon(uniforms, material);
  14591. refreshUniformsPhong(uniforms, material);
  14592. } else if (material.isMeshStandardMaterial) {
  14593. refreshUniformsCommon(uniforms, material);
  14594. if (material.isMeshPhysicalMaterial) {
  14595. refreshUniformsPhysical(uniforms, material);
  14596. } else {
  14597. refreshUniformsStandard(uniforms, material);
  14598. }
  14599. } else if (material.isMeshMatcapMaterial) {
  14600. refreshUniformsCommon(uniforms, material);
  14601. refreshUniformsMatcap(uniforms, material);
  14602. } else if (material.isMeshDepthMaterial) {
  14603. refreshUniformsCommon(uniforms, material);
  14604. refreshUniformsDepth(uniforms, material);
  14605. } else if (material.isMeshDistanceMaterial) {
  14606. refreshUniformsCommon(uniforms, material);
  14607. refreshUniformsDistance(uniforms, material);
  14608. } else if (material.isMeshNormalMaterial) {
  14609. refreshUniformsCommon(uniforms, material);
  14610. refreshUniformsNormal(uniforms, material);
  14611. } else if (material.isLineBasicMaterial) {
  14612. refreshUniformsLine(uniforms, material);
  14613. if (material.isLineDashedMaterial) {
  14614. refreshUniformsDash(uniforms, material);
  14615. }
  14616. } else if (material.isPointsMaterial) {
  14617. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14618. } else if (material.isSpriteMaterial) {
  14619. refreshUniformsSprites(uniforms, material);
  14620. } else if (material.isShadowMaterial) {
  14621. uniforms.color.value.copy(material.color);
  14622. uniforms.opacity.value = material.opacity;
  14623. } else if (material.isShaderMaterial) {
  14624. material.uniformsNeedUpdate = false; // #15581
  14625. }
  14626. }
  14627. function refreshUniformsCommon(uniforms, material) {
  14628. uniforms.opacity.value = material.opacity;
  14629. if (material.color) {
  14630. uniforms.diffuse.value.copy(material.color);
  14631. }
  14632. if (material.emissive) {
  14633. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14634. }
  14635. if (material.map) {
  14636. uniforms.map.value = material.map;
  14637. }
  14638. if (material.alphaMap) {
  14639. uniforms.alphaMap.value = material.alphaMap;
  14640. }
  14641. if (material.specularMap) {
  14642. uniforms.specularMap.value = material.specularMap;
  14643. }
  14644. var envMap = properties.get(material).envMap;
  14645. if (envMap) {
  14646. uniforms.envMap.value = envMap;
  14647. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14648. uniforms.reflectivity.value = material.reflectivity;
  14649. uniforms.refractionRatio.value = material.refractionRatio;
  14650. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14651. if (maxMipLevel !== undefined) {
  14652. uniforms.maxMipLevel.value = maxMipLevel;
  14653. }
  14654. }
  14655. if (material.lightMap) {
  14656. uniforms.lightMap.value = material.lightMap;
  14657. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14658. }
  14659. if (material.aoMap) {
  14660. uniforms.aoMap.value = material.aoMap;
  14661. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14662. } // uv repeat and offset setting priorities
  14663. // 1. color map
  14664. // 2. specular map
  14665. // 3. displacementMap map
  14666. // 4. normal map
  14667. // 5. bump map
  14668. // 6. roughnessMap map
  14669. // 7. metalnessMap map
  14670. // 8. alphaMap map
  14671. // 9. emissiveMap map
  14672. // 10. clearcoat map
  14673. // 11. clearcoat normal map
  14674. // 12. clearcoat roughnessMap map
  14675. var uvScaleMap;
  14676. if (material.map) {
  14677. uvScaleMap = material.map;
  14678. } else if (material.specularMap) {
  14679. uvScaleMap = material.specularMap;
  14680. } else if (material.displacementMap) {
  14681. uvScaleMap = material.displacementMap;
  14682. } else if (material.normalMap) {
  14683. uvScaleMap = material.normalMap;
  14684. } else if (material.bumpMap) {
  14685. uvScaleMap = material.bumpMap;
  14686. } else if (material.roughnessMap) {
  14687. uvScaleMap = material.roughnessMap;
  14688. } else if (material.metalnessMap) {
  14689. uvScaleMap = material.metalnessMap;
  14690. } else if (material.alphaMap) {
  14691. uvScaleMap = material.alphaMap;
  14692. } else if (material.emissiveMap) {
  14693. uvScaleMap = material.emissiveMap;
  14694. } else if (material.clearcoatMap) {
  14695. uvScaleMap = material.clearcoatMap;
  14696. } else if (material.clearcoatNormalMap) {
  14697. uvScaleMap = material.clearcoatNormalMap;
  14698. } else if (material.clearcoatRoughnessMap) {
  14699. uvScaleMap = material.clearcoatRoughnessMap;
  14700. }
  14701. if (uvScaleMap !== undefined) {
  14702. // backwards compatibility
  14703. if (uvScaleMap.isWebGLRenderTarget) {
  14704. uvScaleMap = uvScaleMap.texture;
  14705. }
  14706. if (uvScaleMap.matrixAutoUpdate === true) {
  14707. uvScaleMap.updateMatrix();
  14708. }
  14709. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14710. } // uv repeat and offset setting priorities for uv2
  14711. // 1. ao map
  14712. // 2. light map
  14713. var uv2ScaleMap;
  14714. if (material.aoMap) {
  14715. uv2ScaleMap = material.aoMap;
  14716. } else if (material.lightMap) {
  14717. uv2ScaleMap = material.lightMap;
  14718. }
  14719. if (uv2ScaleMap !== undefined) {
  14720. // backwards compatibility
  14721. if (uv2ScaleMap.isWebGLRenderTarget) {
  14722. uv2ScaleMap = uv2ScaleMap.texture;
  14723. }
  14724. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14725. uv2ScaleMap.updateMatrix();
  14726. }
  14727. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14728. }
  14729. }
  14730. function refreshUniformsLine(uniforms, material) {
  14731. uniforms.diffuse.value.copy(material.color);
  14732. uniforms.opacity.value = material.opacity;
  14733. }
  14734. function refreshUniformsDash(uniforms, material) {
  14735. uniforms.dashSize.value = material.dashSize;
  14736. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14737. uniforms.scale.value = material.scale;
  14738. }
  14739. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14740. uniforms.diffuse.value.copy(material.color);
  14741. uniforms.opacity.value = material.opacity;
  14742. uniforms.size.value = material.size * pixelRatio;
  14743. uniforms.scale.value = height * 0.5;
  14744. if (material.map) {
  14745. uniforms.map.value = material.map;
  14746. }
  14747. if (material.alphaMap) {
  14748. uniforms.alphaMap.value = material.alphaMap;
  14749. } // uv repeat and offset setting priorities
  14750. // 1. color map
  14751. // 2. alpha map
  14752. var uvScaleMap;
  14753. if (material.map) {
  14754. uvScaleMap = material.map;
  14755. } else if (material.alphaMap) {
  14756. uvScaleMap = material.alphaMap;
  14757. }
  14758. if (uvScaleMap !== undefined) {
  14759. if (uvScaleMap.matrixAutoUpdate === true) {
  14760. uvScaleMap.updateMatrix();
  14761. }
  14762. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14763. }
  14764. }
  14765. function refreshUniformsSprites(uniforms, material) {
  14766. uniforms.diffuse.value.copy(material.color);
  14767. uniforms.opacity.value = material.opacity;
  14768. uniforms.rotation.value = material.rotation;
  14769. if (material.map) {
  14770. uniforms.map.value = material.map;
  14771. }
  14772. if (material.alphaMap) {
  14773. uniforms.alphaMap.value = material.alphaMap;
  14774. } // uv repeat and offset setting priorities
  14775. // 1. color map
  14776. // 2. alpha map
  14777. var uvScaleMap;
  14778. if (material.map) {
  14779. uvScaleMap = material.map;
  14780. } else if (material.alphaMap) {
  14781. uvScaleMap = material.alphaMap;
  14782. }
  14783. if (uvScaleMap !== undefined) {
  14784. if (uvScaleMap.matrixAutoUpdate === true) {
  14785. uvScaleMap.updateMatrix();
  14786. }
  14787. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14788. }
  14789. }
  14790. function refreshUniformsLambert(uniforms, material) {
  14791. if (material.emissiveMap) {
  14792. uniforms.emissiveMap.value = material.emissiveMap;
  14793. }
  14794. }
  14795. function refreshUniformsPhong(uniforms, material) {
  14796. uniforms.specular.value.copy(material.specular);
  14797. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14798. if (material.emissiveMap) {
  14799. uniforms.emissiveMap.value = material.emissiveMap;
  14800. }
  14801. if (material.bumpMap) {
  14802. uniforms.bumpMap.value = material.bumpMap;
  14803. uniforms.bumpScale.value = material.bumpScale;
  14804. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14805. }
  14806. if (material.normalMap) {
  14807. uniforms.normalMap.value = material.normalMap;
  14808. uniforms.normalScale.value.copy(material.normalScale);
  14809. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14810. }
  14811. if (material.displacementMap) {
  14812. uniforms.displacementMap.value = material.displacementMap;
  14813. uniforms.displacementScale.value = material.displacementScale;
  14814. uniforms.displacementBias.value = material.displacementBias;
  14815. }
  14816. }
  14817. function refreshUniformsToon(uniforms, material) {
  14818. if (material.gradientMap) {
  14819. uniforms.gradientMap.value = material.gradientMap;
  14820. }
  14821. if (material.emissiveMap) {
  14822. uniforms.emissiveMap.value = material.emissiveMap;
  14823. }
  14824. if (material.bumpMap) {
  14825. uniforms.bumpMap.value = material.bumpMap;
  14826. uniforms.bumpScale.value = material.bumpScale;
  14827. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14828. }
  14829. if (material.normalMap) {
  14830. uniforms.normalMap.value = material.normalMap;
  14831. uniforms.normalScale.value.copy(material.normalScale);
  14832. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14833. }
  14834. if (material.displacementMap) {
  14835. uniforms.displacementMap.value = material.displacementMap;
  14836. uniforms.displacementScale.value = material.displacementScale;
  14837. uniforms.displacementBias.value = material.displacementBias;
  14838. }
  14839. }
  14840. function refreshUniformsStandard(uniforms, material) {
  14841. uniforms.roughness.value = material.roughness;
  14842. uniforms.metalness.value = material.metalness;
  14843. if (material.roughnessMap) {
  14844. uniforms.roughnessMap.value = material.roughnessMap;
  14845. }
  14846. if (material.metalnessMap) {
  14847. uniforms.metalnessMap.value = material.metalnessMap;
  14848. }
  14849. if (material.emissiveMap) {
  14850. uniforms.emissiveMap.value = material.emissiveMap;
  14851. }
  14852. if (material.bumpMap) {
  14853. uniforms.bumpMap.value = material.bumpMap;
  14854. uniforms.bumpScale.value = material.bumpScale;
  14855. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14856. }
  14857. if (material.normalMap) {
  14858. uniforms.normalMap.value = material.normalMap;
  14859. uniforms.normalScale.value.copy(material.normalScale);
  14860. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14861. }
  14862. if (material.displacementMap) {
  14863. uniforms.displacementMap.value = material.displacementMap;
  14864. uniforms.displacementScale.value = material.displacementScale;
  14865. uniforms.displacementBias.value = material.displacementBias;
  14866. }
  14867. var envMap = properties.get(material).envMap;
  14868. if (envMap) {
  14869. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14870. uniforms.envMapIntensity.value = material.envMapIntensity;
  14871. }
  14872. }
  14873. function refreshUniformsPhysical(uniforms, material) {
  14874. refreshUniformsStandard(uniforms, material);
  14875. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14876. uniforms.clearcoat.value = material.clearcoat;
  14877. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14878. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14879. if (material.clearcoatMap) {
  14880. uniforms.clearcoatMap.value = material.clearcoatMap;
  14881. }
  14882. if (material.clearcoatRoughnessMap) {
  14883. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14884. }
  14885. if (material.clearcoatNormalMap) {
  14886. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14887. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14888. if (material.side === BackSide) {
  14889. uniforms.clearcoatNormalScale.value.negate();
  14890. }
  14891. }
  14892. uniforms.transmission.value = material.transmission;
  14893. if (material.transmissionMap) {
  14894. uniforms.transmissionMap.value = material.transmissionMap;
  14895. }
  14896. }
  14897. function refreshUniformsMatcap(uniforms, material) {
  14898. if (material.matcap) {
  14899. uniforms.matcap.value = material.matcap;
  14900. }
  14901. if (material.bumpMap) {
  14902. uniforms.bumpMap.value = material.bumpMap;
  14903. uniforms.bumpScale.value = material.bumpScale;
  14904. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14905. }
  14906. if (material.normalMap) {
  14907. uniforms.normalMap.value = material.normalMap;
  14908. uniforms.normalScale.value.copy(material.normalScale);
  14909. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14910. }
  14911. if (material.displacementMap) {
  14912. uniforms.displacementMap.value = material.displacementMap;
  14913. uniforms.displacementScale.value = material.displacementScale;
  14914. uniforms.displacementBias.value = material.displacementBias;
  14915. }
  14916. }
  14917. function refreshUniformsDepth(uniforms, material) {
  14918. if (material.displacementMap) {
  14919. uniforms.displacementMap.value = material.displacementMap;
  14920. uniforms.displacementScale.value = material.displacementScale;
  14921. uniforms.displacementBias.value = material.displacementBias;
  14922. }
  14923. }
  14924. function refreshUniformsDistance(uniforms, material) {
  14925. if (material.displacementMap) {
  14926. uniforms.displacementMap.value = material.displacementMap;
  14927. uniforms.displacementScale.value = material.displacementScale;
  14928. uniforms.displacementBias.value = material.displacementBias;
  14929. }
  14930. uniforms.referencePosition.value.copy(material.referencePosition);
  14931. uniforms.nearDistance.value = material.nearDistance;
  14932. uniforms.farDistance.value = material.farDistance;
  14933. }
  14934. function refreshUniformsNormal(uniforms, material) {
  14935. if (material.bumpMap) {
  14936. uniforms.bumpMap.value = material.bumpMap;
  14937. uniforms.bumpScale.value = material.bumpScale;
  14938. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14939. }
  14940. if (material.normalMap) {
  14941. uniforms.normalMap.value = material.normalMap;
  14942. uniforms.normalScale.value.copy(material.normalScale);
  14943. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14944. }
  14945. if (material.displacementMap) {
  14946. uniforms.displacementMap.value = material.displacementMap;
  14947. uniforms.displacementScale.value = material.displacementScale;
  14948. uniforms.displacementBias.value = material.displacementBias;
  14949. }
  14950. }
  14951. return {
  14952. refreshFogUniforms: refreshFogUniforms,
  14953. refreshMaterialUniforms: refreshMaterialUniforms
  14954. };
  14955. }
  14956. function createCanvasElement() {
  14957. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14958. canvas.style.display = 'block';
  14959. return canvas;
  14960. }
  14961. function WebGLRenderer(parameters) {
  14962. parameters = parameters || {};
  14963. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14964. _context = parameters.context !== undefined ? parameters.context : null,
  14965. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14966. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14967. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14968. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14969. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14970. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14971. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14972. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14973. var currentRenderList = null;
  14974. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14975. // We track this so that the nested render call gets its list and state isolated from the parent render call.
  14976. var renderListStack = [];
  14977. var renderStateStack = []; // public properties
  14978. this.domElement = _canvas; // Debug configuration container
  14979. this.debug = {
  14980. /**
  14981. * Enables error checking and reporting when shader programs are being compiled
  14982. * @type {boolean}
  14983. */
  14984. checkShaderErrors: true
  14985. }; // clearing
  14986. this.autoClear = true;
  14987. this.autoClearColor = true;
  14988. this.autoClearDepth = true;
  14989. this.autoClearStencil = true; // scene graph
  14990. this.sortObjects = true; // user-defined clipping
  14991. this.clippingPlanes = [];
  14992. this.localClippingEnabled = false; // physically based shading
  14993. this.gammaFactor = 2.0; // for backwards compatibility
  14994. this.outputEncoding = LinearEncoding; // physical lights
  14995. this.physicallyCorrectLights = false; // tone mapping
  14996. this.toneMapping = NoToneMapping;
  14997. this.toneMappingExposure = 1.0; // morphs
  14998. this.maxMorphTargets = 8;
  14999. this.maxMorphNormals = 4; // internal properties
  15000. var _this = this;
  15001. var _isContextLost = false; // internal state cache
  15002. var _framebuffer = null;
  15003. var _currentActiveCubeFace = 0;
  15004. var _currentActiveMipmapLevel = 0;
  15005. var _currentRenderTarget = null;
  15006. var _currentFramebuffer = null;
  15007. var _currentMaterialId = -1;
  15008. var _currentCamera = null;
  15009. var _currentViewport = new Vector4();
  15010. var _currentScissor = new Vector4();
  15011. var _currentScissorTest = null; //
  15012. var _width = _canvas.width;
  15013. var _height = _canvas.height;
  15014. var _pixelRatio = 1;
  15015. var _opaqueSort = null;
  15016. var _transparentSort = null;
  15017. var _viewport = new Vector4(0, 0, _width, _height);
  15018. var _scissor = new Vector4(0, 0, _width, _height);
  15019. var _scissorTest = false; // frustum
  15020. var _frustum = new Frustum(); // clipping
  15021. var _clippingEnabled = false;
  15022. var _localClippingEnabled = false; // camera matrices cache
  15023. var _projScreenMatrix = new Matrix4();
  15024. var _vector3 = new Vector3();
  15025. var _emptyScene = {
  15026. background: null,
  15027. fog: null,
  15028. environment: null,
  15029. overrideMaterial: null,
  15030. isScene: true
  15031. };
  15032. function getTargetPixelRatio() {
  15033. return _currentRenderTarget === null ? _pixelRatio : 1;
  15034. } // initialize
  15035. var _gl = _context;
  15036. function getContext(contextNames, contextAttributes) {
  15037. for (var i = 0; i < contextNames.length; i++) {
  15038. var contextName = contextNames[i];
  15039. var context = _canvas.getContext(contextName, contextAttributes);
  15040. if (context !== null) return context;
  15041. }
  15042. return null;
  15043. }
  15044. try {
  15045. var contextAttributes = {
  15046. alpha: _alpha,
  15047. depth: _depth,
  15048. stencil: _stencil,
  15049. antialias: _antialias,
  15050. premultipliedAlpha: _premultipliedAlpha,
  15051. preserveDrawingBuffer: _preserveDrawingBuffer,
  15052. powerPreference: _powerPreference,
  15053. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  15054. }; // event listeners must be registered before WebGL context is created, see #12753
  15055. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  15056. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  15057. if (_gl === null) {
  15058. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  15059. if (_this.isWebGL1Renderer === true) {
  15060. contextNames.shift();
  15061. }
  15062. _gl = getContext(contextNames, contextAttributes);
  15063. if (_gl === null) {
  15064. if (getContext(contextNames)) {
  15065. throw new Error('Error creating WebGL context with your selected attributes.');
  15066. } else {
  15067. throw new Error('Error creating WebGL context.');
  15068. }
  15069. }
  15070. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  15071. if (_gl.getShaderPrecisionFormat === undefined) {
  15072. _gl.getShaderPrecisionFormat = function () {
  15073. return {
  15074. 'rangeMin': 1,
  15075. 'rangeMax': 1,
  15076. 'precision': 1
  15077. };
  15078. };
  15079. }
  15080. } catch (error) {
  15081. console.error('THREE.WebGLRenderer: ' + error.message);
  15082. throw error;
  15083. }
  15084. var extensions, capabilities, state, info;
  15085. var properties, textures, cubemaps, attributes, geometries, objects;
  15086. var programCache, materials, renderLists, renderStates, clipping;
  15087. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  15088. var utils, bindingStates;
  15089. function initGLContext() {
  15090. extensions = new WebGLExtensions(_gl);
  15091. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  15092. extensions.init(capabilities);
  15093. utils = new WebGLUtils(_gl, extensions, capabilities);
  15094. state = new WebGLState(_gl, extensions, capabilities);
  15095. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15096. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15097. info = new WebGLInfo(_gl);
  15098. properties = new WebGLProperties();
  15099. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  15100. cubemaps = new WebGLCubeMaps(_this);
  15101. attributes = new WebGLAttributes(_gl, capabilities);
  15102. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  15103. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  15104. objects = new WebGLObjects(_gl, geometries, attributes, info);
  15105. morphtargets = new WebGLMorphtargets(_gl);
  15106. clipping = new WebGLClipping(properties);
  15107. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  15108. materials = new WebGLMaterials(properties);
  15109. renderLists = new WebGLRenderLists(properties);
  15110. renderStates = new WebGLRenderStates(extensions, capabilities);
  15111. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  15112. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  15113. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  15114. info.programs = programCache.programs;
  15115. _this.capabilities = capabilities;
  15116. _this.extensions = extensions;
  15117. _this.properties = properties;
  15118. _this.renderLists = renderLists;
  15119. _this.state = state;
  15120. _this.info = info;
  15121. }
  15122. initGLContext(); // xr
  15123. var xr = new WebXRManager(_this, _gl);
  15124. this.xr = xr; // shadow map
  15125. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  15126. this.shadowMap = shadowMap; // API
  15127. this.getContext = function () {
  15128. return _gl;
  15129. };
  15130. this.getContextAttributes = function () {
  15131. return _gl.getContextAttributes();
  15132. };
  15133. this.forceContextLoss = function () {
  15134. var extension = extensions.get('WEBGL_lose_context');
  15135. if (extension) extension.loseContext();
  15136. };
  15137. this.forceContextRestore = function () {
  15138. var extension = extensions.get('WEBGL_lose_context');
  15139. if (extension) extension.restoreContext();
  15140. };
  15141. this.getPixelRatio = function () {
  15142. return _pixelRatio;
  15143. };
  15144. this.setPixelRatio = function (value) {
  15145. if (value === undefined) return;
  15146. _pixelRatio = value;
  15147. this.setSize(_width, _height, false);
  15148. };
  15149. this.getSize = function (target) {
  15150. if (target === undefined) {
  15151. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  15152. target = new Vector2();
  15153. }
  15154. return target.set(_width, _height);
  15155. };
  15156. this.setSize = function (width, height, updateStyle) {
  15157. if (xr.isPresenting) {
  15158. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  15159. return;
  15160. }
  15161. _width = width;
  15162. _height = height;
  15163. _canvas.width = Math.floor(width * _pixelRatio);
  15164. _canvas.height = Math.floor(height * _pixelRatio);
  15165. if (updateStyle !== false) {
  15166. _canvas.style.width = width + 'px';
  15167. _canvas.style.height = height + 'px';
  15168. }
  15169. this.setViewport(0, 0, width, height);
  15170. };
  15171. this.getDrawingBufferSize = function (target) {
  15172. if (target === undefined) {
  15173. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  15174. target = new Vector2();
  15175. }
  15176. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  15177. };
  15178. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  15179. _width = width;
  15180. _height = height;
  15181. _pixelRatio = pixelRatio;
  15182. _canvas.width = Math.floor(width * pixelRatio);
  15183. _canvas.height = Math.floor(height * pixelRatio);
  15184. this.setViewport(0, 0, width, height);
  15185. };
  15186. this.getCurrentViewport = function (target) {
  15187. if (target === undefined) {
  15188. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  15189. target = new Vector4();
  15190. }
  15191. return target.copy(_currentViewport);
  15192. };
  15193. this.getViewport = function (target) {
  15194. return target.copy(_viewport);
  15195. };
  15196. this.setViewport = function (x, y, width, height) {
  15197. if (x.isVector4) {
  15198. _viewport.set(x.x, x.y, x.z, x.w);
  15199. } else {
  15200. _viewport.set(x, y, width, height);
  15201. }
  15202. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15203. };
  15204. this.getScissor = function (target) {
  15205. return target.copy(_scissor);
  15206. };
  15207. this.setScissor = function (x, y, width, height) {
  15208. if (x.isVector4) {
  15209. _scissor.set(x.x, x.y, x.z, x.w);
  15210. } else {
  15211. _scissor.set(x, y, width, height);
  15212. }
  15213. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15214. };
  15215. this.getScissorTest = function () {
  15216. return _scissorTest;
  15217. };
  15218. this.setScissorTest = function (boolean) {
  15219. state.setScissorTest(_scissorTest = boolean);
  15220. };
  15221. this.setOpaqueSort = function (method) {
  15222. _opaqueSort = method;
  15223. };
  15224. this.setTransparentSort = function (method) {
  15225. _transparentSort = method;
  15226. }; // Clearing
  15227. this.getClearColor = function (target) {
  15228. if (target === undefined) {
  15229. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  15230. target = new Color();
  15231. }
  15232. return target.copy(background.getClearColor());
  15233. };
  15234. this.setClearColor = function () {
  15235. background.setClearColor.apply(background, arguments);
  15236. };
  15237. this.getClearAlpha = function () {
  15238. return background.getClearAlpha();
  15239. };
  15240. this.setClearAlpha = function () {
  15241. background.setClearAlpha.apply(background, arguments);
  15242. };
  15243. this.clear = function (color, depth, stencil) {
  15244. var bits = 0;
  15245. if (color === undefined || color) bits |= 16384;
  15246. if (depth === undefined || depth) bits |= 256;
  15247. if (stencil === undefined || stencil) bits |= 1024;
  15248. _gl.clear(bits);
  15249. };
  15250. this.clearColor = function () {
  15251. this.clear(true, false, false);
  15252. };
  15253. this.clearDepth = function () {
  15254. this.clear(false, true, false);
  15255. };
  15256. this.clearStencil = function () {
  15257. this.clear(false, false, true);
  15258. }; //
  15259. this.dispose = function () {
  15260. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  15261. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  15262. renderLists.dispose();
  15263. renderStates.dispose();
  15264. properties.dispose();
  15265. cubemaps.dispose();
  15266. objects.dispose();
  15267. bindingStates.dispose();
  15268. xr.dispose();
  15269. animation.stop();
  15270. }; // Events
  15271. function onContextLost(event) {
  15272. event.preventDefault();
  15273. console.log('THREE.WebGLRenderer: Context Lost.');
  15274. _isContextLost = true;
  15275. }
  15276. function onContextRestore()
  15277. /* event */
  15278. {
  15279. console.log('THREE.WebGLRenderer: Context Restored.');
  15280. _isContextLost = false;
  15281. initGLContext();
  15282. }
  15283. function onMaterialDispose(event) {
  15284. var material = event.target;
  15285. material.removeEventListener('dispose', onMaterialDispose);
  15286. deallocateMaterial(material);
  15287. } // Buffer deallocation
  15288. function deallocateMaterial(material) {
  15289. releaseMaterialProgramReference(material);
  15290. properties.remove(material);
  15291. }
  15292. function releaseMaterialProgramReference(material) {
  15293. var programInfo = properties.get(material).program;
  15294. if (programInfo !== undefined) {
  15295. programCache.releaseProgram(programInfo);
  15296. }
  15297. } // Buffer rendering
  15298. function renderObjectImmediate(object, program) {
  15299. object.render(function (object) {
  15300. _this.renderBufferImmediate(object, program);
  15301. });
  15302. }
  15303. this.renderBufferImmediate = function (object, program) {
  15304. bindingStates.initAttributes();
  15305. var buffers = properties.get(object);
  15306. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  15307. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  15308. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  15309. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  15310. var programAttributes = program.getAttributes();
  15311. if (object.hasPositions) {
  15312. _gl.bindBuffer(34962, buffers.position);
  15313. _gl.bufferData(34962, object.positionArray, 35048);
  15314. bindingStates.enableAttribute(programAttributes.position);
  15315. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  15316. }
  15317. if (object.hasNormals) {
  15318. _gl.bindBuffer(34962, buffers.normal);
  15319. _gl.bufferData(34962, object.normalArray, 35048);
  15320. bindingStates.enableAttribute(programAttributes.normal);
  15321. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  15322. }
  15323. if (object.hasUvs) {
  15324. _gl.bindBuffer(34962, buffers.uv);
  15325. _gl.bufferData(34962, object.uvArray, 35048);
  15326. bindingStates.enableAttribute(programAttributes.uv);
  15327. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  15328. }
  15329. if (object.hasColors) {
  15330. _gl.bindBuffer(34962, buffers.color);
  15331. _gl.bufferData(34962, object.colorArray, 35048);
  15332. bindingStates.enableAttribute(programAttributes.color);
  15333. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  15334. }
  15335. bindingStates.disableUnusedAttributes();
  15336. _gl.drawArrays(4, 0, object.count);
  15337. object.count = 0;
  15338. };
  15339. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  15340. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15341. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  15342. var program = setProgram(camera, scene, material, object);
  15343. state.setMaterial(material, frontFaceCW); //
  15344. var index = geometry.index;
  15345. var position = geometry.attributes.position; //
  15346. if (index === null) {
  15347. if (position === undefined || position.count === 0) return;
  15348. } else if (index.count === 0) {
  15349. return;
  15350. } //
  15351. var rangeFactor = 1;
  15352. if (material.wireframe === true) {
  15353. index = geometries.getWireframeAttribute(geometry);
  15354. rangeFactor = 2;
  15355. }
  15356. if (material.morphTargets || material.morphNormals) {
  15357. morphtargets.update(object, geometry, material, program);
  15358. }
  15359. bindingStates.setup(object, material, program, geometry, index);
  15360. var attribute;
  15361. var renderer = bufferRenderer;
  15362. if (index !== null) {
  15363. attribute = attributes.get(index);
  15364. renderer = indexedBufferRenderer;
  15365. renderer.setIndex(attribute);
  15366. } //
  15367. var dataCount = index !== null ? index.count : position.count;
  15368. var rangeStart = geometry.drawRange.start * rangeFactor;
  15369. var rangeCount = geometry.drawRange.count * rangeFactor;
  15370. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15371. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15372. var drawStart = Math.max(rangeStart, groupStart);
  15373. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  15374. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  15375. if (drawCount === 0) return; //
  15376. if (object.isMesh) {
  15377. if (material.wireframe === true) {
  15378. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  15379. renderer.setMode(1);
  15380. } else {
  15381. renderer.setMode(4);
  15382. }
  15383. } else if (object.isLine) {
  15384. var lineWidth = material.linewidth;
  15385. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  15386. state.setLineWidth(lineWidth * getTargetPixelRatio());
  15387. if (object.isLineSegments) {
  15388. renderer.setMode(1);
  15389. } else if (object.isLineLoop) {
  15390. renderer.setMode(2);
  15391. } else {
  15392. renderer.setMode(3);
  15393. }
  15394. } else if (object.isPoints) {
  15395. renderer.setMode(0);
  15396. } else if (object.isSprite) {
  15397. renderer.setMode(4);
  15398. }
  15399. if (object.isInstancedMesh) {
  15400. renderer.renderInstances(drawStart, drawCount, object.count);
  15401. } else if (geometry.isInstancedBufferGeometry) {
  15402. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  15403. renderer.renderInstances(drawStart, drawCount, instanceCount);
  15404. } else {
  15405. renderer.render(drawStart, drawCount);
  15406. }
  15407. }; // Compile
  15408. this.compile = function (scene, camera) {
  15409. currentRenderState = renderStates.get(scene);
  15410. currentRenderState.init();
  15411. scene.traverseVisible(function (object) {
  15412. if (object.isLight && object.layers.test(camera.layers)) {
  15413. currentRenderState.pushLight(object);
  15414. if (object.castShadow) {
  15415. currentRenderState.pushShadow(object);
  15416. }
  15417. }
  15418. });
  15419. currentRenderState.setupLights();
  15420. var compiled = new WeakMap();
  15421. scene.traverse(function (object) {
  15422. var material = object.material;
  15423. if (material) {
  15424. if (Array.isArray(material)) {
  15425. for (var i = 0; i < material.length; i++) {
  15426. var material2 = material[i];
  15427. if (compiled.has(material2) === false) {
  15428. initMaterial(material2, scene, object);
  15429. compiled.set(material2);
  15430. }
  15431. }
  15432. } else if (compiled.has(material) === false) {
  15433. initMaterial(material, scene, object);
  15434. compiled.set(material);
  15435. }
  15436. }
  15437. });
  15438. }; // Animation Loop
  15439. var onAnimationFrameCallback = null;
  15440. function onAnimationFrame(time) {
  15441. if (xr.isPresenting) return;
  15442. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  15443. }
  15444. var animation = new WebGLAnimation();
  15445. animation.setAnimationLoop(onAnimationFrame);
  15446. if (typeof window !== 'undefined') animation.setContext(window);
  15447. this.setAnimationLoop = function (callback) {
  15448. onAnimationFrameCallback = callback;
  15449. xr.setAnimationLoop(callback);
  15450. callback === null ? animation.stop() : animation.start();
  15451. }; // Rendering
  15452. this.render = function (scene, camera) {
  15453. var renderTarget, forceClear;
  15454. if (arguments[2] !== undefined) {
  15455. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  15456. renderTarget = arguments[2];
  15457. }
  15458. if (arguments[3] !== undefined) {
  15459. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  15460. forceClear = arguments[3];
  15461. }
  15462. if (camera !== undefined && camera.isCamera !== true) {
  15463. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  15464. return;
  15465. }
  15466. if (_isContextLost === true) return; // reset caching for this frame
  15467. bindingStates.resetDefaultState();
  15468. _currentMaterialId = -1;
  15469. _currentCamera = null; // update scene graph
  15470. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  15471. if (camera.parent === null) camera.updateMatrixWorld();
  15472. if (xr.enabled === true && xr.isPresenting === true) {
  15473. camera = xr.getCamera(camera);
  15474. } //
  15475. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  15476. currentRenderState = renderStates.get(scene, renderStateStack.length);
  15477. currentRenderState.init();
  15478. renderStateStack.push(currentRenderState);
  15479. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  15480. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  15481. _localClippingEnabled = this.localClippingEnabled;
  15482. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  15483. currentRenderList = renderLists.get(scene, renderListStack.length);
  15484. currentRenderList.init();
  15485. renderListStack.push(currentRenderList);
  15486. projectObject(scene, camera, 0, _this.sortObjects);
  15487. currentRenderList.finish();
  15488. if (_this.sortObjects === true) {
  15489. currentRenderList.sort(_opaqueSort, _transparentSort);
  15490. } //
  15491. if (_clippingEnabled === true) clipping.beginShadows();
  15492. var shadowsArray = currentRenderState.state.shadowsArray;
  15493. shadowMap.render(shadowsArray, scene, camera);
  15494. currentRenderState.setupLights();
  15495. currentRenderState.setupLightsView(camera);
  15496. if (_clippingEnabled === true) clipping.endShadows(); //
  15497. if (this.info.autoReset === true) this.info.reset();
  15498. if (renderTarget !== undefined) {
  15499. this.setRenderTarget(renderTarget);
  15500. } //
  15501. background.render(currentRenderList, scene, camera, forceClear); // render scene
  15502. var opaqueObjects = currentRenderList.opaque;
  15503. var transparentObjects = currentRenderList.transparent;
  15504. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  15505. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  15506. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  15507. if (_currentRenderTarget !== null) {
  15508. // Generate mipmap if we're using any kind of mipmap filtering
  15509. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  15510. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  15511. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  15512. state.buffers.depth.setTest(true);
  15513. state.buffers.depth.setMask(true);
  15514. state.buffers.color.setMask(true);
  15515. state.setPolygonOffset(false); // _gl.finish();
  15516. renderStateStack.pop();
  15517. if (renderStateStack.length > 0) {
  15518. currentRenderState = renderStateStack[renderStateStack.length - 1];
  15519. } else {
  15520. currentRenderState = null;
  15521. }
  15522. renderListStack.pop();
  15523. if (renderListStack.length > 0) {
  15524. currentRenderList = renderListStack[renderListStack.length - 1];
  15525. } else {
  15526. currentRenderList = null;
  15527. }
  15528. };
  15529. function projectObject(object, camera, groupOrder, sortObjects) {
  15530. if (object.visible === false) return;
  15531. var visible = object.layers.test(camera.layers);
  15532. if (visible) {
  15533. if (object.isGroup) {
  15534. groupOrder = object.renderOrder;
  15535. } else if (object.isLOD) {
  15536. if (object.autoUpdate === true) object.update(camera);
  15537. } else if (object.isLight) {
  15538. currentRenderState.pushLight(object);
  15539. if (object.castShadow) {
  15540. currentRenderState.pushShadow(object);
  15541. }
  15542. } else if (object.isSprite) {
  15543. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  15544. if (sortObjects) {
  15545. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15546. }
  15547. var geometry = objects.update(object);
  15548. var material = object.material;
  15549. if (material.visible) {
  15550. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  15551. }
  15552. }
  15553. } else if (object.isImmediateRenderObject) {
  15554. if (sortObjects) {
  15555. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15556. }
  15557. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  15558. } else if (object.isMesh || object.isLine || object.isPoints) {
  15559. if (object.isSkinnedMesh) {
  15560. // update skeleton only once in a frame
  15561. if (object.skeleton.frame !== info.render.frame) {
  15562. object.skeleton.update();
  15563. object.skeleton.frame = info.render.frame;
  15564. }
  15565. }
  15566. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  15567. if (sortObjects) {
  15568. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15569. }
  15570. var _geometry = objects.update(object);
  15571. var _material = object.material;
  15572. if (Array.isArray(_material)) {
  15573. var groups = _geometry.groups;
  15574. for (var i = 0, l = groups.length; i < l; i++) {
  15575. var group = groups[i];
  15576. var groupMaterial = _material[group.materialIndex];
  15577. if (groupMaterial && groupMaterial.visible) {
  15578. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  15579. }
  15580. }
  15581. } else if (_material.visible) {
  15582. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  15583. }
  15584. }
  15585. }
  15586. }
  15587. var children = object.children;
  15588. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  15589. projectObject(children[_i], camera, groupOrder, sortObjects);
  15590. }
  15591. }
  15592. function renderObjects(renderList, scene, camera) {
  15593. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15594. for (var i = 0, l = renderList.length; i < l; i++) {
  15595. var renderItem = renderList[i];
  15596. var object = renderItem.object;
  15597. var geometry = renderItem.geometry;
  15598. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15599. var group = renderItem.group;
  15600. if (camera.isArrayCamera) {
  15601. var cameras = camera.cameras;
  15602. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15603. var camera2 = cameras[j];
  15604. if (object.layers.test(camera2.layers)) {
  15605. state.viewport(_currentViewport.copy(camera2.viewport));
  15606. currentRenderState.setupLightsView(camera2);
  15607. renderObject(object, scene, camera2, geometry, material, group);
  15608. }
  15609. }
  15610. } else {
  15611. renderObject(object, scene, camera, geometry, material, group);
  15612. }
  15613. }
  15614. }
  15615. function renderObject(object, scene, camera, geometry, material, group) {
  15616. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15617. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15618. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15619. if (object.isImmediateRenderObject) {
  15620. var program = setProgram(camera, scene, material, object);
  15621. state.setMaterial(material);
  15622. bindingStates.reset();
  15623. renderObjectImmediate(object, program);
  15624. } else {
  15625. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15626. }
  15627. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15628. }
  15629. function initMaterial(material, scene, object) {
  15630. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15631. var materialProperties = properties.get(material);
  15632. var lights = currentRenderState.state.lights;
  15633. var shadowsArray = currentRenderState.state.shadowsArray;
  15634. var lightsStateVersion = lights.state.version;
  15635. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15636. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15637. var program = materialProperties.program;
  15638. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15639. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15640. materialProperties.fog = scene.fog;
  15641. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15642. if (program === undefined) {
  15643. // new material
  15644. material.addEventListener('dispose', onMaterialDispose);
  15645. } else if (program.cacheKey !== programCacheKey) {
  15646. // changed glsl or parameters
  15647. releaseMaterialProgramReference(material);
  15648. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15649. programChange = false;
  15650. } else if (parameters.shaderID !== undefined) {
  15651. // same glsl and uniform list
  15652. return;
  15653. } else {
  15654. // only rebuild uniform list
  15655. programChange = false;
  15656. }
  15657. if (programChange) {
  15658. parameters.uniforms = programCache.getUniforms(material);
  15659. material.onBeforeCompile(parameters, _this);
  15660. program = programCache.acquireProgram(parameters, programCacheKey);
  15661. materialProperties.program = program;
  15662. materialProperties.uniforms = parameters.uniforms;
  15663. materialProperties.outputEncoding = parameters.outputEncoding;
  15664. }
  15665. var uniforms = materialProperties.uniforms;
  15666. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15667. materialProperties.numClippingPlanes = clipping.numPlanes;
  15668. materialProperties.numIntersection = clipping.numIntersection;
  15669. uniforms.clippingPlanes = clipping.uniform;
  15670. } // store the light setup it was created for
  15671. materialProperties.needsLights = materialNeedsLights(material);
  15672. materialProperties.lightsStateVersion = lightsStateVersion;
  15673. if (materialProperties.needsLights) {
  15674. // wire up the material to this renderer's lighting state
  15675. uniforms.ambientLightColor.value = lights.state.ambient;
  15676. uniforms.lightProbe.value = lights.state.probe;
  15677. uniforms.directionalLights.value = lights.state.directional;
  15678. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15679. uniforms.spotLights.value = lights.state.spot;
  15680. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15681. uniforms.rectAreaLights.value = lights.state.rectArea;
  15682. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15683. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15684. uniforms.pointLights.value = lights.state.point;
  15685. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15686. uniforms.hemisphereLights.value = lights.state.hemi;
  15687. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15688. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15689. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15690. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15691. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15692. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15693. }
  15694. var progUniforms = materialProperties.program.getUniforms();
  15695. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15696. materialProperties.uniformsList = uniformsList;
  15697. }
  15698. function setProgram(camera, scene, material, object) {
  15699. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15700. textures.resetTextureUnits();
  15701. var fog = scene.fog;
  15702. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15703. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15704. var envMap = cubemaps.get(material.envMap || environment);
  15705. var materialProperties = properties.get(material);
  15706. var lights = currentRenderState.state.lights;
  15707. if (_clippingEnabled === true) {
  15708. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15709. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15710. // object instead of the material, once it becomes feasible
  15711. // (#8465, #8379)
  15712. clipping.setState(material, camera, useCache);
  15713. }
  15714. }
  15715. if (material.version === materialProperties.__version) {
  15716. if (material.fog && materialProperties.fog !== fog) {
  15717. initMaterial(material, scene, object);
  15718. } else if (materialProperties.environment !== environment) {
  15719. initMaterial(material, scene, object);
  15720. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15721. initMaterial(material, scene, object);
  15722. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15723. initMaterial(material, scene, object);
  15724. } else if (materialProperties.outputEncoding !== encoding) {
  15725. initMaterial(material, scene, object);
  15726. } else if (materialProperties.envMap !== envMap) {
  15727. initMaterial(material, scene, object);
  15728. }
  15729. } else {
  15730. initMaterial(material, scene, object);
  15731. materialProperties.__version = material.version;
  15732. }
  15733. var refreshProgram = false;
  15734. var refreshMaterial = false;
  15735. var refreshLights = false;
  15736. var program = materialProperties.program,
  15737. p_uniforms = program.getUniforms(),
  15738. m_uniforms = materialProperties.uniforms;
  15739. if (state.useProgram(program.program)) {
  15740. refreshProgram = true;
  15741. refreshMaterial = true;
  15742. refreshLights = true;
  15743. }
  15744. if (material.id !== _currentMaterialId) {
  15745. _currentMaterialId = material.id;
  15746. refreshMaterial = true;
  15747. }
  15748. if (refreshProgram || _currentCamera !== camera) {
  15749. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15750. if (capabilities.logarithmicDepthBuffer) {
  15751. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15752. }
  15753. if (_currentCamera !== camera) {
  15754. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15755. // now, in case this material supports lights - or later, when
  15756. // the next material that does gets activated:
  15757. refreshMaterial = true; // set to true on material change
  15758. refreshLights = true; // remains set until update done
  15759. } // load material specific uniforms
  15760. // (shader material also gets them for the sake of genericity)
  15761. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15762. var uCamPos = p_uniforms.map.cameraPosition;
  15763. if (uCamPos !== undefined) {
  15764. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15765. }
  15766. }
  15767. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15768. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15769. }
  15770. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15771. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15772. }
  15773. } // skinning uniforms must be set even if material didn't change
  15774. // auto-setting of texture unit for bone texture must go before other textures
  15775. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15776. if (material.skinning) {
  15777. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15778. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15779. var skeleton = object.skeleton;
  15780. if (skeleton) {
  15781. var bones = skeleton.bones;
  15782. if (capabilities.floatVertexTextures) {
  15783. if (skeleton.boneTexture === null) {
  15784. // layout (1 matrix = 4 pixels)
  15785. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15786. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15787. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15788. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15789. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15790. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15791. size = MathUtils.ceilPowerOfTwo(size);
  15792. size = Math.max(size, 4);
  15793. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15794. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15795. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15796. skeleton.boneMatrices = boneMatrices;
  15797. skeleton.boneTexture = boneTexture;
  15798. skeleton.boneTextureSize = size;
  15799. }
  15800. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15801. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15802. } else {
  15803. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15804. }
  15805. }
  15806. }
  15807. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15808. materialProperties.receiveShadow = object.receiveShadow;
  15809. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15810. }
  15811. if (refreshMaterial) {
  15812. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15813. if (materialProperties.needsLights) {
  15814. // the current material requires lighting info
  15815. // note: all lighting uniforms are always set correctly
  15816. // they simply reference the renderer's state for their
  15817. // values
  15818. //
  15819. // use the current material's .needsUpdate flags to set
  15820. // the GL state when required
  15821. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15822. } // refresh uniforms common to several materials
  15823. if (fog && material.fog) {
  15824. materials.refreshFogUniforms(m_uniforms, fog);
  15825. }
  15826. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15827. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15828. }
  15829. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15830. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15831. material.uniformsNeedUpdate = false;
  15832. }
  15833. if (material.isSpriteMaterial) {
  15834. p_uniforms.setValue(_gl, 'center', object.center);
  15835. } // common matrices
  15836. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15837. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15838. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15839. return program;
  15840. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15841. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15842. uniforms.ambientLightColor.needsUpdate = value;
  15843. uniforms.lightProbe.needsUpdate = value;
  15844. uniforms.directionalLights.needsUpdate = value;
  15845. uniforms.directionalLightShadows.needsUpdate = value;
  15846. uniforms.pointLights.needsUpdate = value;
  15847. uniforms.pointLightShadows.needsUpdate = value;
  15848. uniforms.spotLights.needsUpdate = value;
  15849. uniforms.spotLightShadows.needsUpdate = value;
  15850. uniforms.rectAreaLights.needsUpdate = value;
  15851. uniforms.hemisphereLights.needsUpdate = value;
  15852. }
  15853. function materialNeedsLights(material) {
  15854. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15855. } //
  15856. this.setFramebuffer = function (value) {
  15857. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15858. _framebuffer = value;
  15859. };
  15860. this.getActiveCubeFace = function () {
  15861. return _currentActiveCubeFace;
  15862. };
  15863. this.getActiveMipmapLevel = function () {
  15864. return _currentActiveMipmapLevel;
  15865. };
  15866. this.getRenderTarget = function () {
  15867. return _currentRenderTarget;
  15868. };
  15869. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15870. if (activeCubeFace === void 0) {
  15871. activeCubeFace = 0;
  15872. }
  15873. if (activeMipmapLevel === void 0) {
  15874. activeMipmapLevel = 0;
  15875. }
  15876. _currentRenderTarget = renderTarget;
  15877. _currentActiveCubeFace = activeCubeFace;
  15878. _currentActiveMipmapLevel = activeMipmapLevel;
  15879. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15880. textures.setupRenderTarget(renderTarget);
  15881. }
  15882. var framebuffer = _framebuffer;
  15883. var isCube = false;
  15884. var isRenderTarget3D = false;
  15885. if (renderTarget) {
  15886. var texture = renderTarget.texture;
  15887. if (texture.isDataTexture3D || texture.isDataTexture2DArray) {
  15888. isRenderTarget3D = true;
  15889. }
  15890. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15891. if (renderTarget.isWebGLCubeRenderTarget) {
  15892. framebuffer = __webglFramebuffer[activeCubeFace];
  15893. isCube = true;
  15894. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15895. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15896. } else {
  15897. framebuffer = __webglFramebuffer;
  15898. }
  15899. _currentViewport.copy(renderTarget.viewport);
  15900. _currentScissor.copy(renderTarget.scissor);
  15901. _currentScissorTest = renderTarget.scissorTest;
  15902. } else {
  15903. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15904. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15905. _currentScissorTest = _scissorTest;
  15906. }
  15907. if (_currentFramebuffer !== framebuffer) {
  15908. _gl.bindFramebuffer(36160, framebuffer);
  15909. _currentFramebuffer = framebuffer;
  15910. }
  15911. state.viewport(_currentViewport);
  15912. state.scissor(_currentScissor);
  15913. state.setScissorTest(_currentScissorTest);
  15914. if (isCube) {
  15915. var textureProperties = properties.get(renderTarget.texture);
  15916. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15917. } else if (isRenderTarget3D) {
  15918. var _textureProperties = properties.get(renderTarget.texture);
  15919. var layer = activeCubeFace || 0;
  15920. _gl.framebufferTextureLayer(36160, 36064, _textureProperties.__webglTexture, activeMipmapLevel || 0, layer);
  15921. }
  15922. };
  15923. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15924. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15925. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15926. return;
  15927. }
  15928. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15929. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15930. framebuffer = framebuffer[activeCubeFaceIndex];
  15931. }
  15932. if (framebuffer) {
  15933. var restore = false;
  15934. if (framebuffer !== _currentFramebuffer) {
  15935. _gl.bindFramebuffer(36160, framebuffer);
  15936. restore = true;
  15937. }
  15938. try {
  15939. var texture = renderTarget.texture;
  15940. var textureFormat = texture.format;
  15941. var textureType = texture.type;
  15942. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15943. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15944. return;
  15945. }
  15946. var halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has('EXT_color_buffer_half_float') || capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float'));
  15947. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15948. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has('OES_texture_float') || extensions.has('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15949. !halfFloatSupportedByExt) {
  15950. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15951. return;
  15952. }
  15953. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15954. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15955. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15956. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15957. }
  15958. } else {
  15959. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15960. }
  15961. } finally {
  15962. if (restore) {
  15963. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15964. }
  15965. }
  15966. }
  15967. };
  15968. this.copyFramebufferToTexture = function (position, texture, level) {
  15969. if (level === void 0) {
  15970. level = 0;
  15971. }
  15972. var levelScale = Math.pow(2, -level);
  15973. var width = Math.floor(texture.image.width * levelScale);
  15974. var height = Math.floor(texture.image.height * levelScale);
  15975. var glFormat = utils.convert(texture.format);
  15976. textures.setTexture2D(texture, 0);
  15977. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15978. state.unbindTexture();
  15979. };
  15980. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15981. if (level === void 0) {
  15982. level = 0;
  15983. }
  15984. var width = srcTexture.image.width;
  15985. var height = srcTexture.image.height;
  15986. var glFormat = utils.convert(dstTexture.format);
  15987. var glType = utils.convert(dstTexture.type);
  15988. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15989. // parameters, make sure they are correct for the dstTexture
  15990. _gl.pixelStorei(37440, dstTexture.flipY);
  15991. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15992. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15993. if (srcTexture.isDataTexture) {
  15994. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15995. } else {
  15996. if (srcTexture.isCompressedTexture) {
  15997. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15998. } else {
  15999. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  16000. }
  16001. } // Generate mipmaps only when copying level 0
  16002. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  16003. state.unbindTexture();
  16004. };
  16005. this.copyTextureToTexture3D = function (sourceBox, position, srcTexture, dstTexture, level) {
  16006. if (level === void 0) {
  16007. level = 0;
  16008. }
  16009. if (_this.isWebGL1Renderer) {
  16010. console.warn('THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.');
  16011. return;
  16012. }
  16013. var _srcTexture$image = srcTexture.image,
  16014. width = _srcTexture$image.width,
  16015. height = _srcTexture$image.height,
  16016. data = _srcTexture$image.data;
  16017. var glFormat = utils.convert(dstTexture.format);
  16018. var glType = utils.convert(dstTexture.type);
  16019. var glTarget;
  16020. if (dstTexture.isDataTexture3D) {
  16021. textures.setTexture3D(dstTexture, 0);
  16022. glTarget = 32879;
  16023. } else if (dstTexture.isDataTexture2DArray) {
  16024. textures.setTexture2DArray(dstTexture, 0);
  16025. glTarget = 35866;
  16026. } else {
  16027. console.warn('THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.');
  16028. return;
  16029. }
  16030. _gl.pixelStorei(37440, dstTexture.flipY);
  16031. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  16032. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  16033. var unpackRowLen = _gl.getParameter(3314);
  16034. var unpackImageHeight = _gl.getParameter(32878);
  16035. var unpackSkipPixels = _gl.getParameter(3316);
  16036. var unpackSkipRows = _gl.getParameter(3315);
  16037. var unpackSkipImages = _gl.getParameter(32877);
  16038. _gl.pixelStorei(3314, width);
  16039. _gl.pixelStorei(32878, height);
  16040. _gl.pixelStorei(3316, sourceBox.min.x);
  16041. _gl.pixelStorei(3315, sourceBox.min.y);
  16042. _gl.pixelStorei(32877, sourceBox.min.z);
  16043. _gl.texSubImage3D(glTarget, level, position.x, position.y, position.z, sourceBox.max.x - sourceBox.min.x + 1, sourceBox.max.y - sourceBox.min.y + 1, sourceBox.max.z - sourceBox.min.z + 1, glFormat, glType, data);
  16044. _gl.pixelStorei(3314, unpackRowLen);
  16045. _gl.pixelStorei(32878, unpackImageHeight);
  16046. _gl.pixelStorei(3316, unpackSkipPixels);
  16047. _gl.pixelStorei(3315, unpackSkipRows);
  16048. _gl.pixelStorei(32877, unpackSkipImages); // Generate mipmaps only when copying level 0
  16049. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(glTarget);
  16050. state.unbindTexture();
  16051. };
  16052. this.initTexture = function (texture) {
  16053. textures.setTexture2D(texture, 0);
  16054. state.unbindTexture();
  16055. };
  16056. this.resetState = function () {
  16057. state.reset();
  16058. bindingStates.reset();
  16059. };
  16060. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  16061. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  16062. detail: this
  16063. })); // eslint-disable-line no-undef
  16064. }
  16065. }
  16066. var WebGL1Renderer = /*#__PURE__*/function (_WebGLRenderer) {
  16067. _inheritsLoose(WebGL1Renderer, _WebGLRenderer);
  16068. function WebGL1Renderer() {
  16069. return _WebGLRenderer.apply(this, arguments) || this;
  16070. }
  16071. return WebGL1Renderer;
  16072. }(WebGLRenderer);
  16073. WebGL1Renderer.prototype.isWebGL1Renderer = true;
  16074. var FogExp2 = /*#__PURE__*/function () {
  16075. function FogExp2(color, density) {
  16076. this.name = '';
  16077. this.color = new Color(color);
  16078. this.density = density !== undefined ? density : 0.00025;
  16079. }
  16080. var _proto = FogExp2.prototype;
  16081. _proto.clone = function clone() {
  16082. return new FogExp2(this.color, this.density);
  16083. };
  16084. _proto.toJSON = function toJSON()
  16085. /* meta */
  16086. {
  16087. return {
  16088. type: 'FogExp2',
  16089. color: this.color.getHex(),
  16090. density: this.density
  16091. };
  16092. };
  16093. return FogExp2;
  16094. }();
  16095. FogExp2.prototype.isFogExp2 = true;
  16096. var Fog = /*#__PURE__*/function () {
  16097. function Fog(color, near, far) {
  16098. this.name = '';
  16099. this.color = new Color(color);
  16100. this.near = near !== undefined ? near : 1;
  16101. this.far = far !== undefined ? far : 1000;
  16102. }
  16103. var _proto = Fog.prototype;
  16104. _proto.clone = function clone() {
  16105. return new Fog(this.color, this.near, this.far);
  16106. };
  16107. _proto.toJSON = function toJSON()
  16108. /* meta */
  16109. {
  16110. return {
  16111. type: 'Fog',
  16112. color: this.color.getHex(),
  16113. near: this.near,
  16114. far: this.far
  16115. };
  16116. };
  16117. return Fog;
  16118. }();
  16119. Fog.prototype.isFog = true;
  16120. var Scene = /*#__PURE__*/function (_Object3D) {
  16121. _inheritsLoose(Scene, _Object3D);
  16122. function Scene() {
  16123. var _this;
  16124. _this = _Object3D.call(this) || this;
  16125. _this.type = 'Scene';
  16126. _this.background = null;
  16127. _this.environment = null;
  16128. _this.fog = null;
  16129. _this.overrideMaterial = null;
  16130. _this.autoUpdate = true; // checked by the renderer
  16131. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  16132. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  16133. detail: _assertThisInitialized(_this)
  16134. })); // eslint-disable-line no-undef
  16135. }
  16136. return _this;
  16137. }
  16138. var _proto = Scene.prototype;
  16139. _proto.copy = function copy(source, recursive) {
  16140. _Object3D.prototype.copy.call(this, source, recursive);
  16141. if (source.background !== null) this.background = source.background.clone();
  16142. if (source.environment !== null) this.environment = source.environment.clone();
  16143. if (source.fog !== null) this.fog = source.fog.clone();
  16144. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  16145. this.autoUpdate = source.autoUpdate;
  16146. this.matrixAutoUpdate = source.matrixAutoUpdate;
  16147. return this;
  16148. };
  16149. _proto.toJSON = function toJSON(meta) {
  16150. var data = _Object3D.prototype.toJSON.call(this, meta);
  16151. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  16152. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  16153. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  16154. return data;
  16155. };
  16156. return Scene;
  16157. }(Object3D);
  16158. Scene.prototype.isScene = true;
  16159. function InterleavedBuffer(array, stride) {
  16160. this.array = array;
  16161. this.stride = stride;
  16162. this.count = array !== undefined ? array.length / stride : 0;
  16163. this.usage = StaticDrawUsage;
  16164. this.updateRange = {
  16165. offset: 0,
  16166. count: -1
  16167. };
  16168. this.version = 0;
  16169. this.uuid = MathUtils.generateUUID();
  16170. }
  16171. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  16172. set: function set(value) {
  16173. if (value === true) this.version++;
  16174. }
  16175. });
  16176. Object.assign(InterleavedBuffer.prototype, {
  16177. isInterleavedBuffer: true,
  16178. onUploadCallback: function onUploadCallback() {},
  16179. setUsage: function setUsage(value) {
  16180. this.usage = value;
  16181. return this;
  16182. },
  16183. copy: function copy(source) {
  16184. this.array = new source.array.constructor(source.array);
  16185. this.count = source.count;
  16186. this.stride = source.stride;
  16187. this.usage = source.usage;
  16188. return this;
  16189. },
  16190. copyAt: function copyAt(index1, attribute, index2) {
  16191. index1 *= this.stride;
  16192. index2 *= attribute.stride;
  16193. for (var i = 0, l = this.stride; i < l; i++) {
  16194. this.array[index1 + i] = attribute.array[index2 + i];
  16195. }
  16196. return this;
  16197. },
  16198. set: function set(value, offset) {
  16199. if (offset === void 0) {
  16200. offset = 0;
  16201. }
  16202. this.array.set(value, offset);
  16203. return this;
  16204. },
  16205. clone: function clone(data) {
  16206. if (data.arrayBuffers === undefined) {
  16207. data.arrayBuffers = {};
  16208. }
  16209. if (this.array.buffer._uuid === undefined) {
  16210. this.array.buffer._uuid = MathUtils.generateUUID();
  16211. }
  16212. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16213. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  16214. }
  16215. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  16216. var ib = new InterleavedBuffer(array, this.stride);
  16217. ib.setUsage(this.usage);
  16218. return ib;
  16219. },
  16220. onUpload: function onUpload(callback) {
  16221. this.onUploadCallback = callback;
  16222. return this;
  16223. },
  16224. toJSON: function toJSON(data) {
  16225. if (data.arrayBuffers === undefined) {
  16226. data.arrayBuffers = {};
  16227. } // generate UUID for array buffer if necessary
  16228. if (this.array.buffer._uuid === undefined) {
  16229. this.array.buffer._uuid = MathUtils.generateUUID();
  16230. }
  16231. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16232. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  16233. } //
  16234. return {
  16235. uuid: this.uuid,
  16236. buffer: this.array.buffer._uuid,
  16237. type: this.array.constructor.name,
  16238. stride: this.stride
  16239. };
  16240. }
  16241. });
  16242. var _vector$6 = new Vector3();
  16243. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  16244. this.name = '';
  16245. this.data = interleavedBuffer;
  16246. this.itemSize = itemSize;
  16247. this.offset = offset;
  16248. this.normalized = normalized === true;
  16249. }
  16250. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  16251. count: {
  16252. get: function get() {
  16253. return this.data.count;
  16254. }
  16255. },
  16256. array: {
  16257. get: function get() {
  16258. return this.data.array;
  16259. }
  16260. },
  16261. needsUpdate: {
  16262. set: function set(value) {
  16263. this.data.needsUpdate = value;
  16264. }
  16265. }
  16266. });
  16267. Object.assign(InterleavedBufferAttribute.prototype, {
  16268. isInterleavedBufferAttribute: true,
  16269. applyMatrix4: function applyMatrix4(m) {
  16270. for (var i = 0, l = this.data.count; i < l; i++) {
  16271. _vector$6.x = this.getX(i);
  16272. _vector$6.y = this.getY(i);
  16273. _vector$6.z = this.getZ(i);
  16274. _vector$6.applyMatrix4(m);
  16275. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  16276. }
  16277. return this;
  16278. },
  16279. setX: function setX(index, x) {
  16280. this.data.array[index * this.data.stride + this.offset] = x;
  16281. return this;
  16282. },
  16283. setY: function setY(index, y) {
  16284. this.data.array[index * this.data.stride + this.offset + 1] = y;
  16285. return this;
  16286. },
  16287. setZ: function setZ(index, z) {
  16288. this.data.array[index * this.data.stride + this.offset + 2] = z;
  16289. return this;
  16290. },
  16291. setW: function setW(index, w) {
  16292. this.data.array[index * this.data.stride + this.offset + 3] = w;
  16293. return this;
  16294. },
  16295. getX: function getX(index) {
  16296. return this.data.array[index * this.data.stride + this.offset];
  16297. },
  16298. getY: function getY(index) {
  16299. return this.data.array[index * this.data.stride + this.offset + 1];
  16300. },
  16301. getZ: function getZ(index) {
  16302. return this.data.array[index * this.data.stride + this.offset + 2];
  16303. },
  16304. getW: function getW(index) {
  16305. return this.data.array[index * this.data.stride + this.offset + 3];
  16306. },
  16307. setXY: function setXY(index, x, y) {
  16308. index = index * this.data.stride + this.offset;
  16309. this.data.array[index + 0] = x;
  16310. this.data.array[index + 1] = y;
  16311. return this;
  16312. },
  16313. setXYZ: function setXYZ(index, x, y, z) {
  16314. index = index * this.data.stride + this.offset;
  16315. this.data.array[index + 0] = x;
  16316. this.data.array[index + 1] = y;
  16317. this.data.array[index + 2] = z;
  16318. return this;
  16319. },
  16320. setXYZW: function setXYZW(index, x, y, z, w) {
  16321. index = index * this.data.stride + this.offset;
  16322. this.data.array[index + 0] = x;
  16323. this.data.array[index + 1] = y;
  16324. this.data.array[index + 2] = z;
  16325. this.data.array[index + 3] = w;
  16326. return this;
  16327. },
  16328. clone: function clone(data) {
  16329. if (data === undefined) {
  16330. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  16331. var array = [];
  16332. for (var i = 0; i < this.count; i++) {
  16333. var index = i * this.data.stride + this.offset;
  16334. for (var j = 0; j < this.itemSize; j++) {
  16335. array.push(this.data.array[index + j]);
  16336. }
  16337. }
  16338. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  16339. } else {
  16340. if (data.interleavedBuffers === undefined) {
  16341. data.interleavedBuffers = {};
  16342. }
  16343. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16344. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  16345. }
  16346. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  16347. }
  16348. },
  16349. toJSON: function toJSON(data) {
  16350. if (data === undefined) {
  16351. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  16352. var array = [];
  16353. for (var i = 0; i < this.count; i++) {
  16354. var index = i * this.data.stride + this.offset;
  16355. for (var j = 0; j < this.itemSize; j++) {
  16356. array.push(this.data.array[index + j]);
  16357. }
  16358. } // deinterleave data and save it as an ordinary buffer attribute for now
  16359. return {
  16360. itemSize: this.itemSize,
  16361. type: this.array.constructor.name,
  16362. array: array,
  16363. normalized: this.normalized
  16364. };
  16365. } else {
  16366. // save as true interlaved attribtue
  16367. if (data.interleavedBuffers === undefined) {
  16368. data.interleavedBuffers = {};
  16369. }
  16370. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16371. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  16372. }
  16373. return {
  16374. isInterleavedBufferAttribute: true,
  16375. itemSize: this.itemSize,
  16376. data: this.data.uuid,
  16377. offset: this.offset,
  16378. normalized: this.normalized
  16379. };
  16380. }
  16381. }
  16382. });
  16383. /**
  16384. * parameters = {
  16385. * color: <hex>,
  16386. * map: new THREE.Texture( <Image> ),
  16387. * alphaMap: new THREE.Texture( <Image> ),
  16388. * rotation: <float>,
  16389. * sizeAttenuation: <bool>
  16390. * }
  16391. */
  16392. var SpriteMaterial = /*#__PURE__*/function (_Material) {
  16393. _inheritsLoose(SpriteMaterial, _Material);
  16394. function SpriteMaterial(parameters) {
  16395. var _this;
  16396. _this = _Material.call(this) || this;
  16397. _this.type = 'SpriteMaterial';
  16398. _this.color = new Color(0xffffff);
  16399. _this.map = null;
  16400. _this.alphaMap = null;
  16401. _this.rotation = 0;
  16402. _this.sizeAttenuation = true;
  16403. _this.transparent = true;
  16404. _this.setValues(parameters);
  16405. return _this;
  16406. }
  16407. var _proto = SpriteMaterial.prototype;
  16408. _proto.copy = function copy(source) {
  16409. _Material.prototype.copy.call(this, source);
  16410. this.color.copy(source.color);
  16411. this.map = source.map;
  16412. this.alphaMap = source.alphaMap;
  16413. this.rotation = source.rotation;
  16414. this.sizeAttenuation = source.sizeAttenuation;
  16415. return this;
  16416. };
  16417. return SpriteMaterial;
  16418. }(Material);
  16419. SpriteMaterial.prototype.isSpriteMaterial = true;
  16420. var _geometry;
  16421. var _intersectPoint = /*@__PURE__*/new Vector3();
  16422. var _worldScale = /*@__PURE__*/new Vector3();
  16423. var _mvPosition = /*@__PURE__*/new Vector3();
  16424. var _alignedPosition = /*@__PURE__*/new Vector2();
  16425. var _rotatedPosition = /*@__PURE__*/new Vector2();
  16426. var _viewWorldMatrix = /*@__PURE__*/new Matrix4();
  16427. var _vA$1 = /*@__PURE__*/new Vector3();
  16428. var _vB$1 = /*@__PURE__*/new Vector3();
  16429. var _vC$1 = /*@__PURE__*/new Vector3();
  16430. var _uvA$1 = /*@__PURE__*/new Vector2();
  16431. var _uvB$1 = /*@__PURE__*/new Vector2();
  16432. var _uvC$1 = /*@__PURE__*/new Vector2();
  16433. var Sprite = /*#__PURE__*/function (_Object3D) {
  16434. _inheritsLoose(Sprite, _Object3D);
  16435. function Sprite(material) {
  16436. var _this;
  16437. _this = _Object3D.call(this) || this;
  16438. _this.type = 'Sprite';
  16439. if (_geometry === undefined) {
  16440. _geometry = new BufferGeometry();
  16441. 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]);
  16442. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  16443. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  16444. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  16445. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  16446. }
  16447. _this.geometry = _geometry;
  16448. _this.material = material !== undefined ? material : new SpriteMaterial();
  16449. _this.center = new Vector2(0.5, 0.5);
  16450. return _this;
  16451. }
  16452. var _proto = Sprite.prototype;
  16453. _proto.raycast = function raycast(raycaster, intersects) {
  16454. if (raycaster.camera === null) {
  16455. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  16456. }
  16457. _worldScale.setFromMatrixScale(this.matrixWorld);
  16458. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  16459. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  16460. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  16461. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  16462. _worldScale.multiplyScalar(-_mvPosition.z);
  16463. }
  16464. var rotation = this.material.rotation;
  16465. var sin, cos;
  16466. if (rotation !== 0) {
  16467. cos = Math.cos(rotation);
  16468. sin = Math.sin(rotation);
  16469. }
  16470. var center = this.center;
  16471. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16472. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16473. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16474. _uvA$1.set(0, 0);
  16475. _uvB$1.set(1, 0);
  16476. _uvC$1.set(1, 1); // check first triangle
  16477. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  16478. if (intersect === null) {
  16479. // check second triangle
  16480. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16481. _uvB$1.set(0, 1);
  16482. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  16483. if (intersect === null) {
  16484. return;
  16485. }
  16486. }
  16487. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  16488. if (distance < raycaster.near || distance > raycaster.far) return;
  16489. intersects.push({
  16490. distance: distance,
  16491. point: _intersectPoint.clone(),
  16492. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  16493. face: null,
  16494. object: this
  16495. });
  16496. };
  16497. _proto.copy = function copy(source) {
  16498. _Object3D.prototype.copy.call(this, source);
  16499. if (source.center !== undefined) this.center.copy(source.center);
  16500. this.material = source.material;
  16501. return this;
  16502. };
  16503. return Sprite;
  16504. }(Object3D);
  16505. Sprite.prototype.isSprite = true;
  16506. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  16507. // compute position in camera space
  16508. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  16509. if (sin !== undefined) {
  16510. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  16511. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  16512. } else {
  16513. _rotatedPosition.copy(_alignedPosition);
  16514. }
  16515. vertexPosition.copy(mvPosition);
  16516. vertexPosition.x += _rotatedPosition.x;
  16517. vertexPosition.y += _rotatedPosition.y; // transform to world space
  16518. vertexPosition.applyMatrix4(_viewWorldMatrix);
  16519. }
  16520. var _v1$4 = /*@__PURE__*/new Vector3();
  16521. var _v2$2 = /*@__PURE__*/new Vector3();
  16522. var LOD = /*#__PURE__*/function (_Object3D) {
  16523. _inheritsLoose(LOD, _Object3D);
  16524. function LOD() {
  16525. var _this;
  16526. _this = _Object3D.call(this) || this;
  16527. _this._currentLevel = 0;
  16528. _this.type = 'LOD';
  16529. Object.defineProperties(_assertThisInitialized(_this), {
  16530. levels: {
  16531. enumerable: true,
  16532. value: []
  16533. },
  16534. isLOD: {
  16535. value: true
  16536. }
  16537. });
  16538. _this.autoUpdate = true;
  16539. return _this;
  16540. }
  16541. var _proto = LOD.prototype;
  16542. _proto.copy = function copy(source) {
  16543. _Object3D.prototype.copy.call(this, source, false);
  16544. var levels = source.levels;
  16545. for (var i = 0, l = levels.length; i < l; i++) {
  16546. var level = levels[i];
  16547. this.addLevel(level.object.clone(), level.distance);
  16548. }
  16549. this.autoUpdate = source.autoUpdate;
  16550. return this;
  16551. };
  16552. _proto.addLevel = function addLevel(object, distance) {
  16553. if (distance === void 0) {
  16554. distance = 0;
  16555. }
  16556. distance = Math.abs(distance);
  16557. var levels = this.levels;
  16558. var l;
  16559. for (l = 0; l < levels.length; l++) {
  16560. if (distance < levels[l].distance) {
  16561. break;
  16562. }
  16563. }
  16564. levels.splice(l, 0, {
  16565. distance: distance,
  16566. object: object
  16567. });
  16568. this.add(object);
  16569. return this;
  16570. };
  16571. _proto.getCurrentLevel = function getCurrentLevel() {
  16572. return this._currentLevel;
  16573. };
  16574. _proto.getObjectForDistance = function getObjectForDistance(distance) {
  16575. var levels = this.levels;
  16576. if (levels.length > 0) {
  16577. var i, l;
  16578. for (i = 1, l = levels.length; i < l; i++) {
  16579. if (distance < levels[i].distance) {
  16580. break;
  16581. }
  16582. }
  16583. return levels[i - 1].object;
  16584. }
  16585. return null;
  16586. };
  16587. _proto.raycast = function raycast(raycaster, intersects) {
  16588. var levels = this.levels;
  16589. if (levels.length > 0) {
  16590. _v1$4.setFromMatrixPosition(this.matrixWorld);
  16591. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  16592. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  16593. }
  16594. };
  16595. _proto.update = function update(camera) {
  16596. var levels = this.levels;
  16597. if (levels.length > 1) {
  16598. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  16599. _v2$2.setFromMatrixPosition(this.matrixWorld);
  16600. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  16601. levels[0].object.visible = true;
  16602. var i, l;
  16603. for (i = 1, l = levels.length; i < l; i++) {
  16604. if (distance >= levels[i].distance) {
  16605. levels[i - 1].object.visible = false;
  16606. levels[i].object.visible = true;
  16607. } else {
  16608. break;
  16609. }
  16610. }
  16611. this._currentLevel = i - 1;
  16612. for (; i < l; i++) {
  16613. levels[i].object.visible = false;
  16614. }
  16615. }
  16616. };
  16617. _proto.toJSON = function toJSON(meta) {
  16618. var data = _Object3D.prototype.toJSON.call(this, meta);
  16619. if (this.autoUpdate === false) data.object.autoUpdate = false;
  16620. data.object.levels = [];
  16621. var levels = this.levels;
  16622. for (var i = 0, l = levels.length; i < l; i++) {
  16623. var level = levels[i];
  16624. data.object.levels.push({
  16625. object: level.object.uuid,
  16626. distance: level.distance
  16627. });
  16628. }
  16629. return data;
  16630. };
  16631. return LOD;
  16632. }(Object3D);
  16633. var _basePosition = new Vector3();
  16634. var _skinIndex = new Vector4();
  16635. var _skinWeight = new Vector4();
  16636. var _vector$7 = new Vector3();
  16637. var _matrix$1 = new Matrix4();
  16638. function SkinnedMesh(geometry, material) {
  16639. Mesh.call(this, geometry, material);
  16640. this.type = 'SkinnedMesh';
  16641. this.bindMode = 'attached';
  16642. this.bindMatrix = new Matrix4();
  16643. this.bindMatrixInverse = new Matrix4();
  16644. }
  16645. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16646. constructor: SkinnedMesh,
  16647. isSkinnedMesh: true,
  16648. copy: function copy(source) {
  16649. Mesh.prototype.copy.call(this, source);
  16650. this.bindMode = source.bindMode;
  16651. this.bindMatrix.copy(source.bindMatrix);
  16652. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  16653. this.skeleton = source.skeleton;
  16654. return this;
  16655. },
  16656. bind: function bind(skeleton, bindMatrix) {
  16657. this.skeleton = skeleton;
  16658. if (bindMatrix === undefined) {
  16659. this.updateMatrixWorld(true);
  16660. this.skeleton.calculateInverses();
  16661. bindMatrix = this.matrixWorld;
  16662. }
  16663. this.bindMatrix.copy(bindMatrix);
  16664. this.bindMatrixInverse.copy(bindMatrix).invert();
  16665. },
  16666. pose: function pose() {
  16667. this.skeleton.pose();
  16668. },
  16669. normalizeSkinWeights: function normalizeSkinWeights() {
  16670. var vector = new Vector4();
  16671. var skinWeight = this.geometry.attributes.skinWeight;
  16672. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16673. vector.x = skinWeight.getX(i);
  16674. vector.y = skinWeight.getY(i);
  16675. vector.z = skinWeight.getZ(i);
  16676. vector.w = skinWeight.getW(i);
  16677. var scale = 1.0 / vector.manhattanLength();
  16678. if (scale !== Infinity) {
  16679. vector.multiplyScalar(scale);
  16680. } else {
  16681. vector.set(1, 0, 0, 0); // do something reasonable
  16682. }
  16683. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16684. }
  16685. },
  16686. updateMatrixWorld: function updateMatrixWorld(force) {
  16687. Mesh.prototype.updateMatrixWorld.call(this, force);
  16688. if (this.bindMode === 'attached') {
  16689. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16690. } else if (this.bindMode === 'detached') {
  16691. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16692. } else {
  16693. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16694. }
  16695. },
  16696. boneTransform: function boneTransform(index, target) {
  16697. var skeleton = this.skeleton;
  16698. var geometry = this.geometry;
  16699. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16700. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16701. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16702. target.set(0, 0, 0);
  16703. for (var i = 0; i < 4; i++) {
  16704. var weight = _skinWeight.getComponent(i);
  16705. if (weight !== 0) {
  16706. var boneIndex = _skinIndex.getComponent(i);
  16707. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16708. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16709. }
  16710. }
  16711. return target.applyMatrix4(this.bindMatrixInverse);
  16712. }
  16713. });
  16714. function Bone() {
  16715. Object3D.call(this);
  16716. this.type = 'Bone';
  16717. }
  16718. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16719. constructor: Bone,
  16720. isBone: true
  16721. });
  16722. var _offsetMatrix = /*@__PURE__*/new Matrix4();
  16723. var _identityMatrix = /*@__PURE__*/new Matrix4();
  16724. var Skeleton = /*#__PURE__*/function () {
  16725. function Skeleton(bones, boneInverses) {
  16726. if (bones === void 0) {
  16727. bones = [];
  16728. }
  16729. if (boneInverses === void 0) {
  16730. boneInverses = [];
  16731. }
  16732. this.uuid = MathUtils.generateUUID();
  16733. this.bones = bones.slice(0);
  16734. this.boneInverses = boneInverses;
  16735. this.boneMatrices = null;
  16736. this.boneTexture = null;
  16737. this.boneTextureSize = 0;
  16738. this.frame = -1;
  16739. this.init();
  16740. }
  16741. var _proto = Skeleton.prototype;
  16742. _proto.init = function init() {
  16743. var bones = this.bones;
  16744. var boneInverses = this.boneInverses;
  16745. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16746. if (boneInverses.length === 0) {
  16747. this.calculateInverses();
  16748. } else {
  16749. // handle special case
  16750. if (bones.length !== boneInverses.length) {
  16751. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16752. this.boneInverses = [];
  16753. for (var i = 0, il = this.bones.length; i < il; i++) {
  16754. this.boneInverses.push(new Matrix4());
  16755. }
  16756. }
  16757. }
  16758. };
  16759. _proto.calculateInverses = function calculateInverses() {
  16760. this.boneInverses.length = 0;
  16761. for (var i = 0, il = this.bones.length; i < il; i++) {
  16762. var inverse = new Matrix4();
  16763. if (this.bones[i]) {
  16764. inverse.copy(this.bones[i].matrixWorld).invert();
  16765. }
  16766. this.boneInverses.push(inverse);
  16767. }
  16768. };
  16769. _proto.pose = function pose() {
  16770. // recover the bind-time world matrices
  16771. for (var i = 0, il = this.bones.length; i < il; i++) {
  16772. var bone = this.bones[i];
  16773. if (bone) {
  16774. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16775. }
  16776. } // compute the local matrices, positions, rotations and scales
  16777. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16778. var _bone = this.bones[_i];
  16779. if (_bone) {
  16780. if (_bone.parent && _bone.parent.isBone) {
  16781. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16782. _bone.matrix.multiply(_bone.matrixWorld);
  16783. } else {
  16784. _bone.matrix.copy(_bone.matrixWorld);
  16785. }
  16786. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16787. }
  16788. }
  16789. };
  16790. _proto.update = function update() {
  16791. var bones = this.bones;
  16792. var boneInverses = this.boneInverses;
  16793. var boneMatrices = this.boneMatrices;
  16794. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16795. for (var i = 0, il = bones.length; i < il; i++) {
  16796. // compute the offset between the current and the original transform
  16797. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16798. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16799. _offsetMatrix.toArray(boneMatrices, i * 16);
  16800. }
  16801. if (boneTexture !== null) {
  16802. boneTexture.needsUpdate = true;
  16803. }
  16804. };
  16805. _proto.clone = function clone() {
  16806. return new Skeleton(this.bones, this.boneInverses);
  16807. };
  16808. _proto.getBoneByName = function getBoneByName(name) {
  16809. for (var i = 0, il = this.bones.length; i < il; i++) {
  16810. var bone = this.bones[i];
  16811. if (bone.name === name) {
  16812. return bone;
  16813. }
  16814. }
  16815. return undefined;
  16816. };
  16817. _proto.dispose = function dispose() {
  16818. if (this.boneTexture !== null) {
  16819. this.boneTexture.dispose();
  16820. this.boneTexture = null;
  16821. }
  16822. };
  16823. _proto.fromJSON = function fromJSON(json, bones) {
  16824. this.uuid = json.uuid;
  16825. for (var i = 0, l = json.bones.length; i < l; i++) {
  16826. var uuid = json.bones[i];
  16827. var bone = bones[uuid];
  16828. if (bone === undefined) {
  16829. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16830. bone = new Bone();
  16831. }
  16832. this.bones.push(bone);
  16833. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16834. }
  16835. this.init();
  16836. return this;
  16837. };
  16838. _proto.toJSON = function toJSON() {
  16839. var data = {
  16840. metadata: {
  16841. version: 4.5,
  16842. type: 'Skeleton',
  16843. generator: 'Skeleton.toJSON'
  16844. },
  16845. bones: [],
  16846. boneInverses: []
  16847. };
  16848. data.uuid = this.uuid;
  16849. var bones = this.bones;
  16850. var boneInverses = this.boneInverses;
  16851. for (var i = 0, l = bones.length; i < l; i++) {
  16852. var bone = bones[i];
  16853. data.bones.push(bone.uuid);
  16854. var boneInverse = boneInverses[i];
  16855. data.boneInverses.push(boneInverse.toArray());
  16856. }
  16857. return data;
  16858. };
  16859. return Skeleton;
  16860. }();
  16861. var _instanceLocalMatrix = new Matrix4();
  16862. var _instanceWorldMatrix = new Matrix4();
  16863. var _instanceIntersects = [];
  16864. var _mesh = new Mesh();
  16865. function InstancedMesh(geometry, material, count) {
  16866. Mesh.call(this, geometry, material);
  16867. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16868. this.instanceColor = null;
  16869. this.count = count;
  16870. this.frustumCulled = false;
  16871. }
  16872. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16873. constructor: InstancedMesh,
  16874. isInstancedMesh: true,
  16875. copy: function copy(source) {
  16876. Mesh.prototype.copy.call(this, source);
  16877. this.instanceMatrix.copy(source.instanceMatrix);
  16878. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16879. this.count = source.count;
  16880. return this;
  16881. },
  16882. getColorAt: function getColorAt(index, color) {
  16883. color.fromArray(this.instanceColor.array, index * 3);
  16884. },
  16885. getMatrixAt: function getMatrixAt(index, matrix) {
  16886. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16887. },
  16888. raycast: function raycast(raycaster, intersects) {
  16889. var matrixWorld = this.matrixWorld;
  16890. var raycastTimes = this.count;
  16891. _mesh.geometry = this.geometry;
  16892. _mesh.material = this.material;
  16893. if (_mesh.material === undefined) return;
  16894. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16895. // calculate the world matrix for each instance
  16896. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16897. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16898. _mesh.matrixWorld = _instanceWorldMatrix;
  16899. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16900. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16901. var intersect = _instanceIntersects[i];
  16902. intersect.instanceId = instanceId;
  16903. intersect.object = this;
  16904. intersects.push(intersect);
  16905. }
  16906. _instanceIntersects.length = 0;
  16907. }
  16908. },
  16909. setColorAt: function setColorAt(index, color) {
  16910. if (this.instanceColor === null) {
  16911. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16912. }
  16913. color.toArray(this.instanceColor.array, index * 3);
  16914. },
  16915. setMatrixAt: function setMatrixAt(index, matrix) {
  16916. matrix.toArray(this.instanceMatrix.array, index * 16);
  16917. },
  16918. updateMorphTargets: function updateMorphTargets() {},
  16919. dispose: function dispose() {
  16920. this.dispatchEvent({
  16921. type: 'dispose'
  16922. });
  16923. }
  16924. });
  16925. /**
  16926. * parameters = {
  16927. * color: <hex>,
  16928. * opacity: <float>,
  16929. *
  16930. * linewidth: <float>,
  16931. * linecap: "round",
  16932. * linejoin: "round"
  16933. * }
  16934. */
  16935. var LineBasicMaterial = /*#__PURE__*/function (_Material) {
  16936. _inheritsLoose(LineBasicMaterial, _Material);
  16937. function LineBasicMaterial(parameters) {
  16938. var _this;
  16939. _this = _Material.call(this) || this;
  16940. _this.type = 'LineBasicMaterial';
  16941. _this.color = new Color(0xffffff);
  16942. _this.linewidth = 1;
  16943. _this.linecap = 'round';
  16944. _this.linejoin = 'round';
  16945. _this.morphTargets = false;
  16946. _this.setValues(parameters);
  16947. return _this;
  16948. }
  16949. var _proto = LineBasicMaterial.prototype;
  16950. _proto.copy = function copy(source) {
  16951. _Material.prototype.copy.call(this, source);
  16952. this.color.copy(source.color);
  16953. this.linewidth = source.linewidth;
  16954. this.linecap = source.linecap;
  16955. this.linejoin = source.linejoin;
  16956. this.morphTargets = source.morphTargets;
  16957. return this;
  16958. };
  16959. return LineBasicMaterial;
  16960. }(Material);
  16961. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16962. var _start = new Vector3();
  16963. var _end = new Vector3();
  16964. var _inverseMatrix$1 = new Matrix4();
  16965. var _ray$1 = new Ray();
  16966. var _sphere$2 = new Sphere();
  16967. function Line(geometry, material) {
  16968. if (geometry === void 0) {
  16969. geometry = new BufferGeometry();
  16970. }
  16971. if (material === void 0) {
  16972. material = new LineBasicMaterial();
  16973. }
  16974. Object3D.call(this);
  16975. this.type = 'Line';
  16976. this.geometry = geometry;
  16977. this.material = material;
  16978. this.updateMorphTargets();
  16979. }
  16980. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16981. constructor: Line,
  16982. isLine: true,
  16983. copy: function copy(source) {
  16984. Object3D.prototype.copy.call(this, source);
  16985. this.material = source.material;
  16986. this.geometry = source.geometry;
  16987. return this;
  16988. },
  16989. computeLineDistances: function computeLineDistances() {
  16990. var geometry = this.geometry;
  16991. if (geometry.isBufferGeometry) {
  16992. // we assume non-indexed geometry
  16993. if (geometry.index === null) {
  16994. var positionAttribute = geometry.attributes.position;
  16995. var lineDistances = [0];
  16996. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16997. _start.fromBufferAttribute(positionAttribute, i - 1);
  16998. _end.fromBufferAttribute(positionAttribute, i);
  16999. lineDistances[i] = lineDistances[i - 1];
  17000. lineDistances[i] += _start.distanceTo(_end);
  17001. }
  17002. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  17003. } else {
  17004. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  17005. }
  17006. } else if (geometry.isGeometry) {
  17007. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17008. }
  17009. return this;
  17010. },
  17011. raycast: function raycast(raycaster, intersects) {
  17012. var geometry = this.geometry;
  17013. var matrixWorld = this.matrixWorld;
  17014. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  17015. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17016. _sphere$2.copy(geometry.boundingSphere);
  17017. _sphere$2.applyMatrix4(matrixWorld);
  17018. _sphere$2.radius += threshold;
  17019. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  17020. _inverseMatrix$1.copy(matrixWorld).invert();
  17021. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  17022. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17023. var localThresholdSq = localThreshold * localThreshold;
  17024. var vStart = new Vector3();
  17025. var vEnd = new Vector3();
  17026. var interSegment = new Vector3();
  17027. var interRay = new Vector3();
  17028. var step = this.isLineSegments ? 2 : 1;
  17029. if (geometry.isBufferGeometry) {
  17030. var index = geometry.index;
  17031. var attributes = geometry.attributes;
  17032. var positionAttribute = attributes.position;
  17033. if (index !== null) {
  17034. var indices = index.array;
  17035. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  17036. var a = indices[i];
  17037. var b = indices[i + 1];
  17038. vStart.fromBufferAttribute(positionAttribute, a);
  17039. vEnd.fromBufferAttribute(positionAttribute, b);
  17040. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  17041. if (distSq > localThresholdSq) continue;
  17042. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  17043. var distance = raycaster.ray.origin.distanceTo(interRay);
  17044. if (distance < raycaster.near || distance > raycaster.far) continue;
  17045. intersects.push({
  17046. distance: distance,
  17047. // What do we want? intersection point on the ray or on the segment??
  17048. // point: raycaster.ray.at( distance ),
  17049. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  17050. index: i,
  17051. face: null,
  17052. faceIndex: null,
  17053. object: this
  17054. });
  17055. }
  17056. } else {
  17057. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  17058. vStart.fromBufferAttribute(positionAttribute, _i);
  17059. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  17060. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  17061. if (_distSq > localThresholdSq) continue;
  17062. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  17063. var _distance = raycaster.ray.origin.distanceTo(interRay);
  17064. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  17065. intersects.push({
  17066. distance: _distance,
  17067. // What do we want? intersection point on the ray or on the segment??
  17068. // point: raycaster.ray.at( distance ),
  17069. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  17070. index: _i,
  17071. face: null,
  17072. faceIndex: null,
  17073. object: this
  17074. });
  17075. }
  17076. }
  17077. } else if (geometry.isGeometry) {
  17078. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17079. }
  17080. },
  17081. updateMorphTargets: function updateMorphTargets() {
  17082. var geometry = this.geometry;
  17083. if (geometry.isBufferGeometry) {
  17084. var morphAttributes = geometry.morphAttributes;
  17085. var keys = Object.keys(morphAttributes);
  17086. if (keys.length > 0) {
  17087. var morphAttribute = morphAttributes[keys[0]];
  17088. if (morphAttribute !== undefined) {
  17089. this.morphTargetInfluences = [];
  17090. this.morphTargetDictionary = {};
  17091. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17092. var name = morphAttribute[m].name || String(m);
  17093. this.morphTargetInfluences.push(0);
  17094. this.morphTargetDictionary[name] = m;
  17095. }
  17096. }
  17097. }
  17098. } else {
  17099. var morphTargets = geometry.morphTargets;
  17100. if (morphTargets !== undefined && morphTargets.length > 0) {
  17101. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17102. }
  17103. }
  17104. }
  17105. });
  17106. var _start$1 = new Vector3();
  17107. var _end$1 = new Vector3();
  17108. function LineSegments(geometry, material) {
  17109. Line.call(this, geometry, material);
  17110. this.type = 'LineSegments';
  17111. }
  17112. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  17113. constructor: LineSegments,
  17114. isLineSegments: true,
  17115. computeLineDistances: function computeLineDistances() {
  17116. var geometry = this.geometry;
  17117. if (geometry.isBufferGeometry) {
  17118. // we assume non-indexed geometry
  17119. if (geometry.index === null) {
  17120. var positionAttribute = geometry.attributes.position;
  17121. var lineDistances = [];
  17122. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  17123. _start$1.fromBufferAttribute(positionAttribute, i);
  17124. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  17125. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  17126. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  17127. }
  17128. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  17129. } else {
  17130. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  17131. }
  17132. } else if (geometry.isGeometry) {
  17133. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17134. }
  17135. return this;
  17136. }
  17137. });
  17138. var LineLoop = /*#__PURE__*/function (_Line) {
  17139. _inheritsLoose(LineLoop, _Line);
  17140. function LineLoop(geometry, material) {
  17141. var _this;
  17142. _this = _Line.call(this, geometry, material) || this;
  17143. _this.type = 'LineLoop';
  17144. return _this;
  17145. }
  17146. return LineLoop;
  17147. }(Line);
  17148. LineLoop.prototype.isLineLoop = true;
  17149. /**
  17150. * parameters = {
  17151. * color: <hex>,
  17152. * opacity: <float>,
  17153. * map: new THREE.Texture( <Image> ),
  17154. * alphaMap: new THREE.Texture( <Image> ),
  17155. *
  17156. * size: <float>,
  17157. * sizeAttenuation: <bool>
  17158. *
  17159. * morphTargets: <bool>
  17160. * }
  17161. */
  17162. var PointsMaterial = /*#__PURE__*/function (_Material) {
  17163. _inheritsLoose(PointsMaterial, _Material);
  17164. function PointsMaterial(parameters) {
  17165. var _this;
  17166. _this = _Material.call(this) || this;
  17167. _this.type = 'PointsMaterial';
  17168. _this.color = new Color(0xffffff);
  17169. _this.map = null;
  17170. _this.alphaMap = null;
  17171. _this.size = 1;
  17172. _this.sizeAttenuation = true;
  17173. _this.morphTargets = false;
  17174. _this.setValues(parameters);
  17175. return _this;
  17176. }
  17177. var _proto = PointsMaterial.prototype;
  17178. _proto.copy = function copy(source) {
  17179. _Material.prototype.copy.call(this, source);
  17180. this.color.copy(source.color);
  17181. this.map = source.map;
  17182. this.alphaMap = source.alphaMap;
  17183. this.size = source.size;
  17184. this.sizeAttenuation = source.sizeAttenuation;
  17185. this.morphTargets = source.morphTargets;
  17186. return this;
  17187. };
  17188. return PointsMaterial;
  17189. }(Material);
  17190. PointsMaterial.prototype.isPointsMaterial = true;
  17191. var _inverseMatrix$2 = new Matrix4();
  17192. var _ray$2 = new Ray();
  17193. var _sphere$3 = new Sphere();
  17194. var _position$1 = new Vector3();
  17195. function Points(geometry, material) {
  17196. if (geometry === void 0) {
  17197. geometry = new BufferGeometry();
  17198. }
  17199. if (material === void 0) {
  17200. material = new PointsMaterial();
  17201. }
  17202. Object3D.call(this);
  17203. this.type = 'Points';
  17204. this.geometry = geometry;
  17205. this.material = material;
  17206. this.updateMorphTargets();
  17207. }
  17208. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  17209. constructor: Points,
  17210. isPoints: true,
  17211. copy: function copy(source) {
  17212. Object3D.prototype.copy.call(this, source);
  17213. this.material = source.material;
  17214. this.geometry = source.geometry;
  17215. return this;
  17216. },
  17217. raycast: function raycast(raycaster, intersects) {
  17218. var geometry = this.geometry;
  17219. var matrixWorld = this.matrixWorld;
  17220. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  17221. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17222. _sphere$3.copy(geometry.boundingSphere);
  17223. _sphere$3.applyMatrix4(matrixWorld);
  17224. _sphere$3.radius += threshold;
  17225. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  17226. _inverseMatrix$2.copy(matrixWorld).invert();
  17227. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  17228. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17229. var localThresholdSq = localThreshold * localThreshold;
  17230. if (geometry.isBufferGeometry) {
  17231. var index = geometry.index;
  17232. var attributes = geometry.attributes;
  17233. var positionAttribute = attributes.position;
  17234. if (index !== null) {
  17235. var indices = index.array;
  17236. for (var i = 0, il = indices.length; i < il; i++) {
  17237. var a = indices[i];
  17238. _position$1.fromBufferAttribute(positionAttribute, a);
  17239. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17240. }
  17241. } else {
  17242. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  17243. _position$1.fromBufferAttribute(positionAttribute, _i);
  17244. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17245. }
  17246. }
  17247. } else {
  17248. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17249. }
  17250. },
  17251. updateMorphTargets: function updateMorphTargets() {
  17252. var geometry = this.geometry;
  17253. if (geometry.isBufferGeometry) {
  17254. var morphAttributes = geometry.morphAttributes;
  17255. var keys = Object.keys(morphAttributes);
  17256. if (keys.length > 0) {
  17257. var morphAttribute = morphAttributes[keys[0]];
  17258. if (morphAttribute !== undefined) {
  17259. this.morphTargetInfluences = [];
  17260. this.morphTargetDictionary = {};
  17261. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17262. var name = morphAttribute[m].name || String(m);
  17263. this.morphTargetInfluences.push(0);
  17264. this.morphTargetDictionary[name] = m;
  17265. }
  17266. }
  17267. }
  17268. } else {
  17269. var morphTargets = geometry.morphTargets;
  17270. if (morphTargets !== undefined && morphTargets.length > 0) {
  17271. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17272. }
  17273. }
  17274. }
  17275. });
  17276. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  17277. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  17278. if (rayPointDistanceSq < localThresholdSq) {
  17279. var intersectPoint = new Vector3();
  17280. _ray$2.closestPointToPoint(point, intersectPoint);
  17281. intersectPoint.applyMatrix4(matrixWorld);
  17282. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  17283. if (distance < raycaster.near || distance > raycaster.far) return;
  17284. intersects.push({
  17285. distance: distance,
  17286. distanceToRay: Math.sqrt(rayPointDistanceSq),
  17287. point: intersectPoint,
  17288. index: index,
  17289. face: null,
  17290. object: object
  17291. });
  17292. }
  17293. }
  17294. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17295. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17296. this.format = format !== undefined ? format : RGBFormat;
  17297. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17298. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17299. this.generateMipmaps = false;
  17300. var scope = this;
  17301. function updateVideo() {
  17302. scope.needsUpdate = true;
  17303. video.requestVideoFrameCallback(updateVideo);
  17304. }
  17305. if ('requestVideoFrameCallback' in video) {
  17306. video.requestVideoFrameCallback(updateVideo);
  17307. }
  17308. }
  17309. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  17310. constructor: VideoTexture,
  17311. clone: function clone() {
  17312. return new this.constructor(this.image).copy(this);
  17313. },
  17314. isVideoTexture: true,
  17315. update: function update() {
  17316. var video = this.image;
  17317. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  17318. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  17319. this.needsUpdate = true;
  17320. }
  17321. }
  17322. });
  17323. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  17324. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  17325. this.image = {
  17326. width: width,
  17327. height: height
  17328. };
  17329. this.mipmaps = mipmaps; // no flipping for cube textures
  17330. // (also flipping doesn't work for compressed textures )
  17331. this.flipY = false; // can't generate mipmaps for compressed textures
  17332. // mips must be embedded in DDS files
  17333. this.generateMipmaps = false;
  17334. }
  17335. CompressedTexture.prototype = Object.create(Texture.prototype);
  17336. CompressedTexture.prototype.constructor = CompressedTexture;
  17337. CompressedTexture.prototype.isCompressedTexture = true;
  17338. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17339. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17340. this.needsUpdate = true;
  17341. }
  17342. CanvasTexture.prototype = Object.create(Texture.prototype);
  17343. CanvasTexture.prototype.constructor = CanvasTexture;
  17344. CanvasTexture.prototype.isCanvasTexture = true;
  17345. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  17346. format = format !== undefined ? format : DepthFormat;
  17347. if (format !== DepthFormat && format !== DepthStencilFormat) {
  17348. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  17349. }
  17350. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  17351. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  17352. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17353. this.image = {
  17354. width: width,
  17355. height: height
  17356. };
  17357. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17358. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17359. this.flipY = false;
  17360. this.generateMipmaps = false;
  17361. }
  17362. DepthTexture.prototype = Object.create(Texture.prototype);
  17363. DepthTexture.prototype.constructor = DepthTexture;
  17364. DepthTexture.prototype.isDepthTexture = true;
  17365. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17366. _inheritsLoose(CircleGeometry, _BufferGeometry);
  17367. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17368. var _this;
  17369. if (radius === void 0) {
  17370. radius = 1;
  17371. }
  17372. if (segments === void 0) {
  17373. segments = 8;
  17374. }
  17375. if (thetaStart === void 0) {
  17376. thetaStart = 0;
  17377. }
  17378. if (thetaLength === void 0) {
  17379. thetaLength = Math.PI * 2;
  17380. }
  17381. _this = _BufferGeometry.call(this) || this;
  17382. _this.type = 'CircleGeometry';
  17383. _this.parameters = {
  17384. radius: radius,
  17385. segments: segments,
  17386. thetaStart: thetaStart,
  17387. thetaLength: thetaLength
  17388. };
  17389. segments = Math.max(3, segments); // buffers
  17390. var indices = [];
  17391. var vertices = [];
  17392. var normals = [];
  17393. var uvs = []; // helper variables
  17394. var vertex = new Vector3();
  17395. var uv = new Vector2(); // center point
  17396. vertices.push(0, 0, 0);
  17397. normals.push(0, 0, 1);
  17398. uvs.push(0.5, 0.5);
  17399. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17400. var segment = thetaStart + s / segments * thetaLength; // vertex
  17401. vertex.x = radius * Math.cos(segment);
  17402. vertex.y = radius * Math.sin(segment);
  17403. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17404. normals.push(0, 0, 1); // uvs
  17405. uv.x = (vertices[i] / radius + 1) / 2;
  17406. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17407. uvs.push(uv.x, uv.y);
  17408. } // indices
  17409. for (var _i = 1; _i <= segments; _i++) {
  17410. indices.push(_i, _i + 1, 0);
  17411. } // build geometry
  17412. _this.setIndex(indices);
  17413. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17414. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17415. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17416. return _this;
  17417. }
  17418. return CircleGeometry;
  17419. }(BufferGeometry);
  17420. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17421. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  17422. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17423. var _this;
  17424. if (radiusTop === void 0) {
  17425. radiusTop = 1;
  17426. }
  17427. if (radiusBottom === void 0) {
  17428. radiusBottom = 1;
  17429. }
  17430. if (height === void 0) {
  17431. height = 1;
  17432. }
  17433. if (radialSegments === void 0) {
  17434. radialSegments = 8;
  17435. }
  17436. if (heightSegments === void 0) {
  17437. heightSegments = 1;
  17438. }
  17439. if (openEnded === void 0) {
  17440. openEnded = false;
  17441. }
  17442. if (thetaStart === void 0) {
  17443. thetaStart = 0;
  17444. }
  17445. if (thetaLength === void 0) {
  17446. thetaLength = Math.PI * 2;
  17447. }
  17448. _this = _BufferGeometry.call(this) || this;
  17449. _this.type = 'CylinderGeometry';
  17450. _this.parameters = {
  17451. radiusTop: radiusTop,
  17452. radiusBottom: radiusBottom,
  17453. height: height,
  17454. radialSegments: radialSegments,
  17455. heightSegments: heightSegments,
  17456. openEnded: openEnded,
  17457. thetaStart: thetaStart,
  17458. thetaLength: thetaLength
  17459. };
  17460. var scope = _assertThisInitialized(_this);
  17461. radialSegments = Math.floor(radialSegments);
  17462. heightSegments = Math.floor(heightSegments); // buffers
  17463. var indices = [];
  17464. var vertices = [];
  17465. var normals = [];
  17466. var uvs = []; // helper variables
  17467. var index = 0;
  17468. var indexArray = [];
  17469. var halfHeight = height / 2;
  17470. var groupStart = 0; // generate geometry
  17471. generateTorso();
  17472. if (openEnded === false) {
  17473. if (radiusTop > 0) generateCap(true);
  17474. if (radiusBottom > 0) generateCap(false);
  17475. } // build geometry
  17476. _this.setIndex(indices);
  17477. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17478. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17479. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17480. function generateTorso() {
  17481. var normal = new Vector3();
  17482. var vertex = new Vector3();
  17483. var groupCount = 0; // this will be used to calculate the normal
  17484. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17485. for (var y = 0; y <= heightSegments; y++) {
  17486. var indexRow = [];
  17487. var v = y / heightSegments; // calculate the radius of the current row
  17488. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17489. for (var x = 0; x <= radialSegments; x++) {
  17490. var u = x / radialSegments;
  17491. var theta = u * thetaLength + thetaStart;
  17492. var sinTheta = Math.sin(theta);
  17493. var cosTheta = Math.cos(theta); // vertex
  17494. vertex.x = radius * sinTheta;
  17495. vertex.y = -v * height + halfHeight;
  17496. vertex.z = radius * cosTheta;
  17497. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17498. normal.set(sinTheta, slope, cosTheta).normalize();
  17499. normals.push(normal.x, normal.y, normal.z); // uv
  17500. uvs.push(u, 1 - v); // save index of vertex in respective row
  17501. indexRow.push(index++);
  17502. } // now save vertices of the row in our index array
  17503. indexArray.push(indexRow);
  17504. } // generate indices
  17505. for (var _x = 0; _x < radialSegments; _x++) {
  17506. for (var _y = 0; _y < heightSegments; _y++) {
  17507. // we use the index array to access the correct indices
  17508. var a = indexArray[_y][_x];
  17509. var b = indexArray[_y + 1][_x];
  17510. var c = indexArray[_y + 1][_x + 1];
  17511. var d = indexArray[_y][_x + 1]; // faces
  17512. indices.push(a, b, d);
  17513. indices.push(b, c, d); // update group counter
  17514. groupCount += 6;
  17515. }
  17516. } // add a group to the geometry. this will ensure multi material support
  17517. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17518. groupStart += groupCount;
  17519. }
  17520. function generateCap(top) {
  17521. // save the index of the first center vertex
  17522. var centerIndexStart = index;
  17523. var uv = new Vector2();
  17524. var vertex = new Vector3();
  17525. var groupCount = 0;
  17526. var radius = top === true ? radiusTop : radiusBottom;
  17527. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17528. // because the geometry needs one set of uvs per face,
  17529. // we must generate a center vertex per face/segment
  17530. for (var x = 1; x <= radialSegments; x++) {
  17531. // vertex
  17532. vertices.push(0, halfHeight * sign, 0); // normal
  17533. normals.push(0, sign, 0); // uv
  17534. uvs.push(0.5, 0.5); // increase index
  17535. index++;
  17536. } // save the index of the last center vertex
  17537. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17538. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17539. var u = _x2 / radialSegments;
  17540. var theta = u * thetaLength + thetaStart;
  17541. var cosTheta = Math.cos(theta);
  17542. var sinTheta = Math.sin(theta); // vertex
  17543. vertex.x = radius * sinTheta;
  17544. vertex.y = halfHeight * sign;
  17545. vertex.z = radius * cosTheta;
  17546. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17547. normals.push(0, sign, 0); // uv
  17548. uv.x = cosTheta * 0.5 + 0.5;
  17549. uv.y = sinTheta * 0.5 * sign + 0.5;
  17550. uvs.push(uv.x, uv.y); // increase index
  17551. index++;
  17552. } // generate indices
  17553. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17554. var c = centerIndexStart + _x3;
  17555. var i = centerIndexEnd + _x3;
  17556. if (top === true) {
  17557. // face top
  17558. indices.push(i, i + 1, c);
  17559. } else {
  17560. // face bottom
  17561. indices.push(i + 1, i, c);
  17562. }
  17563. groupCount += 3;
  17564. } // add a group to the geometry. this will ensure multi material support
  17565. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17566. groupStart += groupCount;
  17567. }
  17568. return _this;
  17569. }
  17570. return CylinderGeometry;
  17571. }(BufferGeometry);
  17572. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17573. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17574. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17575. var _this;
  17576. if (radius === void 0) {
  17577. radius = 1;
  17578. }
  17579. if (height === void 0) {
  17580. height = 1;
  17581. }
  17582. if (radialSegments === void 0) {
  17583. radialSegments = 8;
  17584. }
  17585. if (heightSegments === void 0) {
  17586. heightSegments = 1;
  17587. }
  17588. if (openEnded === void 0) {
  17589. openEnded = false;
  17590. }
  17591. if (thetaStart === void 0) {
  17592. thetaStart = 0;
  17593. }
  17594. if (thetaLength === void 0) {
  17595. thetaLength = Math.PI * 2;
  17596. }
  17597. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17598. _this.type = 'ConeGeometry';
  17599. _this.parameters = {
  17600. radius: radius,
  17601. height: height,
  17602. radialSegments: radialSegments,
  17603. heightSegments: heightSegments,
  17604. openEnded: openEnded,
  17605. thetaStart: thetaStart,
  17606. thetaLength: thetaLength
  17607. };
  17608. return _this;
  17609. }
  17610. return ConeGeometry;
  17611. }(CylinderGeometry);
  17612. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17613. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  17614. function PolyhedronGeometry(vertices, indices, radius, detail) {
  17615. var _this;
  17616. if (radius === void 0) {
  17617. radius = 1;
  17618. }
  17619. if (detail === void 0) {
  17620. detail = 0;
  17621. }
  17622. _this = _BufferGeometry.call(this) || this;
  17623. _this.type = 'PolyhedronGeometry';
  17624. _this.parameters = {
  17625. vertices: vertices,
  17626. indices: indices,
  17627. radius: radius,
  17628. detail: detail
  17629. }; // default buffer data
  17630. var vertexBuffer = [];
  17631. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17632. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17633. applyRadius(radius); // finally, create the uv data
  17634. generateUVs(); // build non-indexed geometry
  17635. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17636. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17637. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17638. if (detail === 0) {
  17639. _this.computeVertexNormals(); // flat normals
  17640. } else {
  17641. _this.normalizeNormals(); // smooth normals
  17642. } // helper functions
  17643. function subdivide(detail) {
  17644. var a = new Vector3();
  17645. var b = new Vector3();
  17646. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17647. for (var i = 0; i < indices.length; i += 3) {
  17648. // get the vertices of the face
  17649. getVertexByIndex(indices[i + 0], a);
  17650. getVertexByIndex(indices[i + 1], b);
  17651. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17652. subdivideFace(a, b, c, detail);
  17653. }
  17654. }
  17655. function subdivideFace(a, b, c, detail) {
  17656. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17657. var v = []; // construct all of the vertices for this subdivision
  17658. for (var i = 0; i <= cols; i++) {
  17659. v[i] = [];
  17660. var aj = a.clone().lerp(c, i / cols);
  17661. var bj = b.clone().lerp(c, i / cols);
  17662. var rows = cols - i;
  17663. for (var j = 0; j <= rows; j++) {
  17664. if (j === 0 && i === cols) {
  17665. v[i][j] = aj;
  17666. } else {
  17667. v[i][j] = aj.clone().lerp(bj, j / rows);
  17668. }
  17669. }
  17670. } // construct all of the faces
  17671. for (var _i = 0; _i < cols; _i++) {
  17672. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17673. var k = Math.floor(_j / 2);
  17674. if (_j % 2 === 0) {
  17675. pushVertex(v[_i][k + 1]);
  17676. pushVertex(v[_i + 1][k]);
  17677. pushVertex(v[_i][k]);
  17678. } else {
  17679. pushVertex(v[_i][k + 1]);
  17680. pushVertex(v[_i + 1][k + 1]);
  17681. pushVertex(v[_i + 1][k]);
  17682. }
  17683. }
  17684. }
  17685. }
  17686. function applyRadius(radius) {
  17687. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17688. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17689. vertex.x = vertexBuffer[i + 0];
  17690. vertex.y = vertexBuffer[i + 1];
  17691. vertex.z = vertexBuffer[i + 2];
  17692. vertex.normalize().multiplyScalar(radius);
  17693. vertexBuffer[i + 0] = vertex.x;
  17694. vertexBuffer[i + 1] = vertex.y;
  17695. vertexBuffer[i + 2] = vertex.z;
  17696. }
  17697. }
  17698. function generateUVs() {
  17699. var vertex = new Vector3();
  17700. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17701. vertex.x = vertexBuffer[i + 0];
  17702. vertex.y = vertexBuffer[i + 1];
  17703. vertex.z = vertexBuffer[i + 2];
  17704. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17705. var v = inclination(vertex) / Math.PI + 0.5;
  17706. uvBuffer.push(u, 1 - v);
  17707. }
  17708. correctUVs();
  17709. correctSeam();
  17710. }
  17711. function correctSeam() {
  17712. // handle case when face straddles the seam, see #3269
  17713. for (var i = 0; i < uvBuffer.length; i += 6) {
  17714. // uv data of a single face
  17715. var x0 = uvBuffer[i + 0];
  17716. var x1 = uvBuffer[i + 2];
  17717. var x2 = uvBuffer[i + 4];
  17718. var max = Math.max(x0, x1, x2);
  17719. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17720. if (max > 0.9 && min < 0.1) {
  17721. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17722. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17723. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17724. }
  17725. }
  17726. }
  17727. function pushVertex(vertex) {
  17728. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17729. }
  17730. function getVertexByIndex(index, vertex) {
  17731. var stride = index * 3;
  17732. vertex.x = vertices[stride + 0];
  17733. vertex.y = vertices[stride + 1];
  17734. vertex.z = vertices[stride + 2];
  17735. }
  17736. function correctUVs() {
  17737. var a = new Vector3();
  17738. var b = new Vector3();
  17739. var c = new Vector3();
  17740. var centroid = new Vector3();
  17741. var uvA = new Vector2();
  17742. var uvB = new Vector2();
  17743. var uvC = new Vector2();
  17744. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17745. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17746. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17747. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17748. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17749. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17750. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17751. centroid.copy(a).add(b).add(c).divideScalar(3);
  17752. var azi = azimuth(centroid);
  17753. correctUV(uvA, j + 0, a, azi);
  17754. correctUV(uvB, j + 2, b, azi);
  17755. correctUV(uvC, j + 4, c, azi);
  17756. }
  17757. }
  17758. function correctUV(uv, stride, vector, azimuth) {
  17759. if (azimuth < 0 && uv.x === 1) {
  17760. uvBuffer[stride] = uv.x - 1;
  17761. }
  17762. if (vector.x === 0 && vector.z === 0) {
  17763. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17764. }
  17765. } // Angle around the Y axis, counter-clockwise when looking from above.
  17766. function azimuth(vector) {
  17767. return Math.atan2(vector.z, -vector.x);
  17768. } // Angle above the XZ plane.
  17769. function inclination(vector) {
  17770. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17771. }
  17772. return _this;
  17773. }
  17774. return PolyhedronGeometry;
  17775. }(BufferGeometry);
  17776. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17777. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17778. function DodecahedronGeometry(radius, detail) {
  17779. var _this;
  17780. if (radius === void 0) {
  17781. radius = 1;
  17782. }
  17783. if (detail === void 0) {
  17784. detail = 0;
  17785. }
  17786. var t = (1 + Math.sqrt(5)) / 2;
  17787. var r = 1 / t;
  17788. var vertices = [// (±1, ±1, ±1)
  17789. -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/φ, ±φ)
  17790. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17791. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17792. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17793. 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];
  17794. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17795. _this.type = 'DodecahedronGeometry';
  17796. _this.parameters = {
  17797. radius: radius,
  17798. detail: detail
  17799. };
  17800. return _this;
  17801. }
  17802. return DodecahedronGeometry;
  17803. }(PolyhedronGeometry);
  17804. var _v0$2 = new Vector3();
  17805. var _v1$5 = new Vector3();
  17806. var _normal$1 = new Vector3();
  17807. var _triangle = new Triangle();
  17808. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17809. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17810. function EdgesGeometry(geometry, thresholdAngle) {
  17811. var _this;
  17812. _this = _BufferGeometry.call(this) || this;
  17813. _this.type = 'EdgesGeometry';
  17814. _this.parameters = {
  17815. thresholdAngle: thresholdAngle
  17816. };
  17817. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17818. if (geometry.isGeometry === true) {
  17819. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17820. return _assertThisInitialized(_this);
  17821. }
  17822. var precisionPoints = 4;
  17823. var precision = Math.pow(10, precisionPoints);
  17824. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17825. var indexAttr = geometry.getIndex();
  17826. var positionAttr = geometry.getAttribute('position');
  17827. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17828. var indexArr = [0, 0, 0];
  17829. var vertKeys = ['a', 'b', 'c'];
  17830. var hashes = new Array(3);
  17831. var edgeData = {};
  17832. var vertices = [];
  17833. for (var i = 0; i < indexCount; i += 3) {
  17834. if (indexAttr) {
  17835. indexArr[0] = indexAttr.getX(i);
  17836. indexArr[1] = indexAttr.getX(i + 1);
  17837. indexArr[2] = indexAttr.getX(i + 2);
  17838. } else {
  17839. indexArr[0] = i;
  17840. indexArr[1] = i + 1;
  17841. indexArr[2] = i + 2;
  17842. }
  17843. var a = _triangle.a,
  17844. b = _triangle.b,
  17845. c = _triangle.c;
  17846. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17847. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17848. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17849. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17850. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17851. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17852. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17853. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17854. continue;
  17855. } // iterate over every edge
  17856. for (var j = 0; j < 3; j++) {
  17857. // get the first and next vertex making up the edge
  17858. var jNext = (j + 1) % 3;
  17859. var vecHash0 = hashes[j];
  17860. var vecHash1 = hashes[jNext];
  17861. var v0 = _triangle[vertKeys[j]];
  17862. var v1 = _triangle[vertKeys[jNext]];
  17863. var hash = vecHash0 + "_" + vecHash1;
  17864. var reverseHash = vecHash1 + "_" + vecHash0;
  17865. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17866. // if we found a sibling edge add it into the vertex array if
  17867. // it meets the angle threshold and delete the edge from the map.
  17868. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17869. vertices.push(v0.x, v0.y, v0.z);
  17870. vertices.push(v1.x, v1.y, v1.z);
  17871. }
  17872. edgeData[reverseHash] = null;
  17873. } else if (!(hash in edgeData)) {
  17874. // if we've already got an edge here then skip adding a new one
  17875. edgeData[hash] = {
  17876. index0: indexArr[j],
  17877. index1: indexArr[jNext],
  17878. normal: _normal$1.clone()
  17879. };
  17880. }
  17881. }
  17882. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17883. for (var key in edgeData) {
  17884. if (edgeData[key]) {
  17885. var _edgeData$key = edgeData[key],
  17886. index0 = _edgeData$key.index0,
  17887. index1 = _edgeData$key.index1;
  17888. _v0$2.fromBufferAttribute(positionAttr, index0);
  17889. _v1$5.fromBufferAttribute(positionAttr, index1);
  17890. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17891. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17892. }
  17893. }
  17894. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17895. return _this;
  17896. }
  17897. return EdgesGeometry;
  17898. }(BufferGeometry);
  17899. /**
  17900. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17901. */
  17902. var Earcut = {
  17903. triangulate: function triangulate(data, holeIndices, dim) {
  17904. dim = dim || 2;
  17905. var hasHoles = holeIndices && holeIndices.length;
  17906. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17907. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17908. var triangles = [];
  17909. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17910. var minX, minY, maxX, maxY, x, y, invSize;
  17911. 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
  17912. if (data.length > 80 * dim) {
  17913. minX = maxX = data[0];
  17914. minY = maxY = data[1];
  17915. for (var i = dim; i < outerLen; i += dim) {
  17916. x = data[i];
  17917. y = data[i + 1];
  17918. if (x < minX) minX = x;
  17919. if (y < minY) minY = y;
  17920. if (x > maxX) maxX = x;
  17921. if (y > maxY) maxY = y;
  17922. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17923. invSize = Math.max(maxX - minX, maxY - minY);
  17924. invSize = invSize !== 0 ? 1 / invSize : 0;
  17925. }
  17926. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17927. return triangles;
  17928. }
  17929. }; // create a circular doubly linked list from polygon points in the specified winding order
  17930. function linkedList(data, start, end, dim, clockwise) {
  17931. var i, last;
  17932. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17933. for (i = start; i < end; i += dim) {
  17934. last = insertNode(i, data[i], data[i + 1], last);
  17935. }
  17936. } else {
  17937. for (i = end - dim; i >= start; i -= dim) {
  17938. last = insertNode(i, data[i], data[i + 1], last);
  17939. }
  17940. }
  17941. if (last && equals(last, last.next)) {
  17942. removeNode(last);
  17943. last = last.next;
  17944. }
  17945. return last;
  17946. } // eliminate colinear or duplicate points
  17947. function filterPoints(start, end) {
  17948. if (!start) return start;
  17949. if (!end) end = start;
  17950. var p = start,
  17951. again;
  17952. do {
  17953. again = false;
  17954. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17955. removeNode(p);
  17956. p = end = p.prev;
  17957. if (p === p.next) break;
  17958. again = true;
  17959. } else {
  17960. p = p.next;
  17961. }
  17962. } while (again || p !== end);
  17963. return end;
  17964. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17965. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17966. if (!ear) return; // interlink polygon nodes in z-order
  17967. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17968. var stop = ear,
  17969. prev,
  17970. next; // iterate through ears, slicing them one by one
  17971. while (ear.prev !== ear.next) {
  17972. prev = ear.prev;
  17973. next = ear.next;
  17974. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17975. // cut off the triangle
  17976. triangles.push(prev.i / dim);
  17977. triangles.push(ear.i / dim);
  17978. triangles.push(next.i / dim);
  17979. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17980. ear = next.next;
  17981. stop = next.next;
  17982. continue;
  17983. }
  17984. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17985. if (ear === stop) {
  17986. // try filtering points and slicing again
  17987. if (!pass) {
  17988. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17989. } else if (pass === 1) {
  17990. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17991. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17992. } else if (pass === 2) {
  17993. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17994. }
  17995. break;
  17996. }
  17997. }
  17998. } // check whether a polygon node forms a valid ear with adjacent nodes
  17999. function isEar(ear) {
  18000. var a = ear.prev,
  18001. b = ear,
  18002. c = ear.next;
  18003. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18004. // now make sure we don't have other points inside the potential ear
  18005. var p = ear.next.next;
  18006. while (p !== ear.prev) {
  18007. 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;
  18008. p = p.next;
  18009. }
  18010. return true;
  18011. }
  18012. function isEarHashed(ear, minX, minY, invSize) {
  18013. var a = ear.prev,
  18014. b = ear,
  18015. c = ear.next;
  18016. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18017. // triangle bbox; min & max are calculated like this for speed
  18018. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  18019. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  18020. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  18021. 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;
  18022. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  18023. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  18024. var p = ear.prevZ,
  18025. n = ear.nextZ; // look for points inside the triangle in both directions
  18026. while (p && p.z >= minZ && n && n.z <= maxZ) {
  18027. 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;
  18028. p = p.prevZ;
  18029. 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;
  18030. n = n.nextZ;
  18031. } // look for remaining points in decreasing z-order
  18032. while (p && p.z >= minZ) {
  18033. 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;
  18034. p = p.prevZ;
  18035. } // look for remaining points in increasing z-order
  18036. while (n && n.z <= maxZ) {
  18037. 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;
  18038. n = n.nextZ;
  18039. }
  18040. return true;
  18041. } // go through all polygon nodes and cure small local self-intersections
  18042. function cureLocalIntersections(start, triangles, dim) {
  18043. var p = start;
  18044. do {
  18045. var a = p.prev,
  18046. b = p.next.next;
  18047. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  18048. triangles.push(a.i / dim);
  18049. triangles.push(p.i / dim);
  18050. triangles.push(b.i / dim); // remove two nodes involved
  18051. removeNode(p);
  18052. removeNode(p.next);
  18053. p = start = b;
  18054. }
  18055. p = p.next;
  18056. } while (p !== start);
  18057. return filterPoints(p);
  18058. } // try splitting polygon into two and triangulate them independently
  18059. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  18060. // look for a valid diagonal that divides the polygon into two
  18061. var a = start;
  18062. do {
  18063. var b = a.next.next;
  18064. while (b !== a.prev) {
  18065. if (a.i !== b.i && isValidDiagonal(a, b)) {
  18066. // split the polygon in two by the diagonal
  18067. var c = splitPolygon(a, b); // filter colinear points around the cuts
  18068. a = filterPoints(a, a.next);
  18069. c = filterPoints(c, c.next); // run earcut on each half
  18070. earcutLinked(a, triangles, dim, minX, minY, invSize);
  18071. earcutLinked(c, triangles, dim, minX, minY, invSize);
  18072. return;
  18073. }
  18074. b = b.next;
  18075. }
  18076. a = a.next;
  18077. } while (a !== start);
  18078. } // link every hole into the outer loop, producing a single-ring polygon without holes
  18079. function eliminateHoles(data, holeIndices, outerNode, dim) {
  18080. var queue = [];
  18081. var i, len, start, end, list;
  18082. for (i = 0, len = holeIndices.length; i < len; i++) {
  18083. start = holeIndices[i] * dim;
  18084. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  18085. list = linkedList(data, start, end, dim, false);
  18086. if (list === list.next) list.steiner = true;
  18087. queue.push(getLeftmost(list));
  18088. }
  18089. queue.sort(compareX); // process holes from left to right
  18090. for (i = 0; i < queue.length; i++) {
  18091. eliminateHole(queue[i], outerNode);
  18092. outerNode = filterPoints(outerNode, outerNode.next);
  18093. }
  18094. return outerNode;
  18095. }
  18096. function compareX(a, b) {
  18097. return a.x - b.x;
  18098. } // find a bridge between vertices that connects hole with an outer ring and and link it
  18099. function eliminateHole(hole, outerNode) {
  18100. outerNode = findHoleBridge(hole, outerNode);
  18101. if (outerNode) {
  18102. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  18103. filterPoints(outerNode, outerNode.next);
  18104. filterPoints(b, b.next);
  18105. }
  18106. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18107. function findHoleBridge(hole, outerNode) {
  18108. var p = outerNode;
  18109. var hx = hole.x;
  18110. var hy = hole.y;
  18111. var qx = -Infinity,
  18112. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18113. // segment's endpoint with lesser x will be potential connection point
  18114. do {
  18115. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18116. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18117. if (x <= hx && x > qx) {
  18118. qx = x;
  18119. if (x === hx) {
  18120. if (hy === p.y) return p;
  18121. if (hy === p.next.y) return p.next;
  18122. }
  18123. m = p.x < p.next.x ? p : p.next;
  18124. }
  18125. }
  18126. p = p.next;
  18127. } while (p !== outerNode);
  18128. if (!m) return null;
  18129. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18130. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18131. // if there are no points found, we have a valid connection;
  18132. // otherwise choose the point of the minimum angle with the ray as connection point
  18133. var stop = m,
  18134. mx = m.x,
  18135. my = m.y;
  18136. var tanMin = Infinity,
  18137. tan;
  18138. p = m;
  18139. do {
  18140. 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)) {
  18141. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18142. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18143. m = p;
  18144. tanMin = tan;
  18145. }
  18146. }
  18147. p = p.next;
  18148. } while (p !== stop);
  18149. return m;
  18150. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18151. function sectorContainsSector(m, p) {
  18152. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18153. } // interlink polygon nodes in z-order
  18154. function indexCurve(start, minX, minY, invSize) {
  18155. var p = start;
  18156. do {
  18157. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18158. p.prevZ = p.prev;
  18159. p.nextZ = p.next;
  18160. p = p.next;
  18161. } while (p !== start);
  18162. p.prevZ.nextZ = null;
  18163. p.prevZ = null;
  18164. sortLinked(p);
  18165. } // Simon Tatham's linked list merge sort algorithm
  18166. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18167. function sortLinked(list) {
  18168. var i,
  18169. p,
  18170. q,
  18171. e,
  18172. tail,
  18173. numMerges,
  18174. pSize,
  18175. qSize,
  18176. inSize = 1;
  18177. do {
  18178. p = list;
  18179. list = null;
  18180. tail = null;
  18181. numMerges = 0;
  18182. while (p) {
  18183. numMerges++;
  18184. q = p;
  18185. pSize = 0;
  18186. for (i = 0; i < inSize; i++) {
  18187. pSize++;
  18188. q = q.nextZ;
  18189. if (!q) break;
  18190. }
  18191. qSize = inSize;
  18192. while (pSize > 0 || qSize > 0 && q) {
  18193. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18194. e = p;
  18195. p = p.nextZ;
  18196. pSize--;
  18197. } else {
  18198. e = q;
  18199. q = q.nextZ;
  18200. qSize--;
  18201. }
  18202. if (tail) tail.nextZ = e;else list = e;
  18203. e.prevZ = tail;
  18204. tail = e;
  18205. }
  18206. p = q;
  18207. }
  18208. tail.nextZ = null;
  18209. inSize *= 2;
  18210. } while (numMerges > 1);
  18211. return list;
  18212. } // z-order of a point given coords and inverse of the longer side of data bbox
  18213. function zOrder(x, y, minX, minY, invSize) {
  18214. // coords are transformed into non-negative 15-bit integer range
  18215. x = 32767 * (x - minX) * invSize;
  18216. y = 32767 * (y - minY) * invSize;
  18217. x = (x | x << 8) & 0x00FF00FF;
  18218. x = (x | x << 4) & 0x0F0F0F0F;
  18219. x = (x | x << 2) & 0x33333333;
  18220. x = (x | x << 1) & 0x55555555;
  18221. y = (y | y << 8) & 0x00FF00FF;
  18222. y = (y | y << 4) & 0x0F0F0F0F;
  18223. y = (y | y << 2) & 0x33333333;
  18224. y = (y | y << 1) & 0x55555555;
  18225. return x | y << 1;
  18226. } // find the leftmost node of a polygon ring
  18227. function getLeftmost(start) {
  18228. var p = start,
  18229. leftmost = start;
  18230. do {
  18231. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18232. p = p.next;
  18233. } while (p !== start);
  18234. return leftmost;
  18235. } // check if a point lies within a convex triangle
  18236. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18237. 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;
  18238. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18239. function isValidDiagonal(a, b) {
  18240. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18241. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18242. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18243. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18244. } // signed area of a triangle
  18245. function area(p, q, r) {
  18246. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18247. } // check if two points are equal
  18248. function equals(p1, p2) {
  18249. return p1.x === p2.x && p1.y === p2.y;
  18250. } // check if two segments intersect
  18251. function intersects(p1, q1, p2, q2) {
  18252. var o1 = sign(area(p1, q1, p2));
  18253. var o2 = sign(area(p1, q1, q2));
  18254. var o3 = sign(area(p2, q2, p1));
  18255. var o4 = sign(area(p2, q2, q1));
  18256. if (o1 !== o2 && o3 !== o4) return true; // general case
  18257. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18258. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18259. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18260. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18261. return false;
  18262. } // for collinear points p, q, r, check if point q lies on segment pr
  18263. function onSegment(p, q, r) {
  18264. 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);
  18265. }
  18266. function sign(num) {
  18267. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18268. } // check if a polygon diagonal intersects any polygon segments
  18269. function intersectsPolygon(a, b) {
  18270. var p = a;
  18271. do {
  18272. 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;
  18273. p = p.next;
  18274. } while (p !== a);
  18275. return false;
  18276. } // check if a polygon diagonal is locally inside the polygon
  18277. function locallyInside(a, b) {
  18278. 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;
  18279. } // check if the middle point of a polygon diagonal is inside the polygon
  18280. function middleInside(a, b) {
  18281. var p = a,
  18282. inside = false;
  18283. var px = (a.x + b.x) / 2,
  18284. py = (a.y + b.y) / 2;
  18285. do {
  18286. 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;
  18287. p = p.next;
  18288. } while (p !== a);
  18289. return inside;
  18290. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18291. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18292. function splitPolygon(a, b) {
  18293. var a2 = new Node(a.i, a.x, a.y),
  18294. b2 = new Node(b.i, b.x, b.y),
  18295. an = a.next,
  18296. bp = b.prev;
  18297. a.next = b;
  18298. b.prev = a;
  18299. a2.next = an;
  18300. an.prev = a2;
  18301. b2.next = a2;
  18302. a2.prev = b2;
  18303. bp.next = b2;
  18304. b2.prev = bp;
  18305. return b2;
  18306. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18307. function insertNode(i, x, y, last) {
  18308. var p = new Node(i, x, y);
  18309. if (!last) {
  18310. p.prev = p;
  18311. p.next = p;
  18312. } else {
  18313. p.next = last.next;
  18314. p.prev = last;
  18315. last.next.prev = p;
  18316. last.next = p;
  18317. }
  18318. return p;
  18319. }
  18320. function removeNode(p) {
  18321. p.next.prev = p.prev;
  18322. p.prev.next = p.next;
  18323. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18324. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18325. }
  18326. function Node(i, x, y) {
  18327. // vertex index in coordinates array
  18328. this.i = i; // vertex coordinates
  18329. this.x = x;
  18330. this.y = y; // previous and next vertex nodes in a polygon ring
  18331. this.prev = null;
  18332. this.next = null; // z-order curve value
  18333. this.z = null; // previous and next nodes in z-order
  18334. this.prevZ = null;
  18335. this.nextZ = null; // indicates whether this is a steiner point
  18336. this.steiner = false;
  18337. }
  18338. function signedArea(data, start, end, dim) {
  18339. var sum = 0;
  18340. for (var i = start, j = end - dim; i < end; i += dim) {
  18341. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18342. j = i;
  18343. }
  18344. return sum;
  18345. }
  18346. var ShapeUtils = {
  18347. // calculate area of the contour polygon
  18348. area: function area(contour) {
  18349. var n = contour.length;
  18350. var a = 0.0;
  18351. for (var p = n - 1, q = 0; q < n; p = q++) {
  18352. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18353. }
  18354. return a * 0.5;
  18355. },
  18356. isClockWise: function isClockWise(pts) {
  18357. return ShapeUtils.area(pts) < 0;
  18358. },
  18359. triangulateShape: function triangulateShape(contour, holes) {
  18360. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18361. var holeIndices = []; // array of hole indices
  18362. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18363. removeDupEndPts(contour);
  18364. addContour(vertices, contour); //
  18365. var holeIndex = contour.length;
  18366. holes.forEach(removeDupEndPts);
  18367. for (var i = 0; i < holes.length; i++) {
  18368. holeIndices.push(holeIndex);
  18369. holeIndex += holes[i].length;
  18370. addContour(vertices, holes[i]);
  18371. } //
  18372. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18373. for (var _i = 0; _i < triangles.length; _i += 3) {
  18374. faces.push(triangles.slice(_i, _i + 3));
  18375. }
  18376. return faces;
  18377. }
  18378. };
  18379. function removeDupEndPts(points) {
  18380. var l = points.length;
  18381. if (l > 2 && points[l - 1].equals(points[0])) {
  18382. points.pop();
  18383. }
  18384. }
  18385. function addContour(vertices, contour) {
  18386. for (var i = 0; i < contour.length; i++) {
  18387. vertices.push(contour[i].x);
  18388. vertices.push(contour[i].y);
  18389. }
  18390. }
  18391. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18392. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  18393. function ExtrudeGeometry(shapes, options) {
  18394. var _this;
  18395. _this = _BufferGeometry.call(this) || this;
  18396. _this.type = 'ExtrudeGeometry';
  18397. _this.parameters = {
  18398. shapes: shapes,
  18399. options: options
  18400. };
  18401. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18402. var scope = _assertThisInitialized(_this);
  18403. var verticesArray = [];
  18404. var uvArray = [];
  18405. for (var i = 0, l = shapes.length; i < l; i++) {
  18406. var shape = shapes[i];
  18407. addShape(shape);
  18408. } // build geometry
  18409. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18410. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18411. _this.computeVertexNormals(); // functions
  18412. function addShape(shape) {
  18413. var placeholder = []; // options
  18414. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18415. var steps = options.steps !== undefined ? options.steps : 1;
  18416. var depth = options.depth !== undefined ? options.depth : 100;
  18417. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18418. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18419. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18420. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18421. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18422. var extrudePath = options.extrudePath;
  18423. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18424. if (options.amount !== undefined) {
  18425. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18426. depth = options.amount;
  18427. } //
  18428. var extrudePts,
  18429. extrudeByPath = false;
  18430. var splineTube, binormal, normal, position2;
  18431. if (extrudePath) {
  18432. extrudePts = extrudePath.getSpacedPoints(steps);
  18433. extrudeByPath = true;
  18434. bevelEnabled = false; // bevels not supported for path extrusion
  18435. // SETUP TNB variables
  18436. // TODO1 - have a .isClosed in spline?
  18437. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18438. binormal = new Vector3();
  18439. normal = new Vector3();
  18440. position2 = new Vector3();
  18441. } // Safeguards if bevels are not enabled
  18442. if (!bevelEnabled) {
  18443. bevelSegments = 0;
  18444. bevelThickness = 0;
  18445. bevelSize = 0;
  18446. bevelOffset = 0;
  18447. } // Variables initialization
  18448. var shapePoints = shape.extractPoints(curveSegments);
  18449. var vertices = shapePoints.shape;
  18450. var holes = shapePoints.holes;
  18451. var reverse = !ShapeUtils.isClockWise(vertices);
  18452. if (reverse) {
  18453. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18454. for (var h = 0, hl = holes.length; h < hl; h++) {
  18455. var ahole = holes[h];
  18456. if (ShapeUtils.isClockWise(ahole)) {
  18457. holes[h] = ahole.reverse();
  18458. }
  18459. }
  18460. }
  18461. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18462. /* Vertices */
  18463. var contour = vertices; // vertices has all points but contour has only points of circumference
  18464. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18465. var _ahole = holes[_h];
  18466. vertices = vertices.concat(_ahole);
  18467. }
  18468. function scalePt2(pt, vec, size) {
  18469. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18470. return vec.clone().multiplyScalar(size).add(pt);
  18471. }
  18472. var vlen = vertices.length,
  18473. flen = faces.length; // Find directions for point movement
  18474. function getBevelVec(inPt, inPrev, inNext) {
  18475. // computes for inPt the corresponding point inPt' on a new contour
  18476. // shifted by 1 unit (length of normalized vector) to the left
  18477. // if we walk along contour clockwise, this new contour is outside the old one
  18478. //
  18479. // inPt' is the intersection of the two lines parallel to the two
  18480. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18481. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18482. // good reading for geometry algorithms (here: line-line intersection)
  18483. // http://geomalgorithms.com/a05-_intersect-1.html
  18484. var v_prev_x = inPt.x - inPrev.x,
  18485. v_prev_y = inPt.y - inPrev.y;
  18486. var v_next_x = inNext.x - inPt.x,
  18487. v_next_y = inNext.y - inPt.y;
  18488. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18489. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18490. if (Math.abs(collinear0) > Number.EPSILON) {
  18491. // not collinear
  18492. // length of vectors for normalizing
  18493. var v_prev_len = Math.sqrt(v_prev_lensq);
  18494. 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
  18495. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18496. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18497. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18498. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18499. 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
  18500. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18501. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18502. // but prevent crazy spikes
  18503. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18504. if (v_trans_lensq <= 2) {
  18505. return new Vector2(v_trans_x, v_trans_y);
  18506. } else {
  18507. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18508. }
  18509. } else {
  18510. // handle special case of collinear edges
  18511. var direction_eq = false; // assumes: opposite
  18512. if (v_prev_x > Number.EPSILON) {
  18513. if (v_next_x > Number.EPSILON) {
  18514. direction_eq = true;
  18515. }
  18516. } else {
  18517. if (v_prev_x < -Number.EPSILON) {
  18518. if (v_next_x < -Number.EPSILON) {
  18519. direction_eq = true;
  18520. }
  18521. } else {
  18522. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18523. direction_eq = true;
  18524. }
  18525. }
  18526. }
  18527. if (direction_eq) {
  18528. // console.log("Warning: lines are a straight sequence");
  18529. v_trans_x = -v_prev_y;
  18530. v_trans_y = v_prev_x;
  18531. shrink_by = Math.sqrt(v_prev_lensq);
  18532. } else {
  18533. // console.log("Warning: lines are a straight spike");
  18534. v_trans_x = v_prev_x;
  18535. v_trans_y = v_prev_y;
  18536. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18537. }
  18538. }
  18539. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18540. }
  18541. var contourMovements = [];
  18542. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18543. if (j === il) j = 0;
  18544. if (k === il) k = 0; // (j)---(i)---(k)
  18545. // console.log('i,j,k', i, j , k)
  18546. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18547. }
  18548. var holesMovements = [];
  18549. var oneHoleMovements,
  18550. verticesMovements = contourMovements.concat();
  18551. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18552. var _ahole2 = holes[_h2];
  18553. oneHoleMovements = [];
  18554. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18555. if (_j === _il) _j = 0;
  18556. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18557. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18558. }
  18559. holesMovements.push(oneHoleMovements);
  18560. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18561. } // Loop bevelSegments, 1 for the front, 1 for the back
  18562. for (var b = 0; b < bevelSegments; b++) {
  18563. //for ( b = bevelSegments; b > 0; b -- ) {
  18564. var t = b / bevelSegments;
  18565. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18566. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18567. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18568. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18569. v(vert.x, vert.y, -z);
  18570. } // expand holes
  18571. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18572. var _ahole3 = holes[_h3];
  18573. oneHoleMovements = holesMovements[_h3];
  18574. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18575. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18576. v(_vert.x, _vert.y, -z);
  18577. }
  18578. }
  18579. }
  18580. var bs = bevelSize + bevelOffset; // Back facing vertices
  18581. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18582. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18583. if (!extrudeByPath) {
  18584. v(_vert2.x, _vert2.y, 0);
  18585. } else {
  18586. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18587. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18588. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18589. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18590. v(position2.x, position2.y, position2.z);
  18591. }
  18592. } // Add stepped vertices...
  18593. // Including front facing vertices
  18594. for (var s = 1; s <= steps; s++) {
  18595. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18596. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18597. if (!extrudeByPath) {
  18598. v(_vert3.x, _vert3.y, depth / steps * s);
  18599. } else {
  18600. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18601. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18602. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18603. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18604. v(position2.x, position2.y, position2.z);
  18605. }
  18606. }
  18607. } // Add bevel segments planes
  18608. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18609. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18610. var _t = _b / bevelSegments;
  18611. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18612. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18613. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18614. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18615. v(_vert4.x, _vert4.y, depth + _z);
  18616. } // expand holes
  18617. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18618. var _ahole4 = holes[_h4];
  18619. oneHoleMovements = holesMovements[_h4];
  18620. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18621. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18622. if (!extrudeByPath) {
  18623. v(_vert5.x, _vert5.y, depth + _z);
  18624. } else {
  18625. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18626. }
  18627. }
  18628. }
  18629. }
  18630. /* Faces */
  18631. // Top and bottom faces
  18632. buildLidFaces(); // Sides faces
  18633. buildSideFaces(); ///// Internal functions
  18634. function buildLidFaces() {
  18635. var start = verticesArray.length / 3;
  18636. if (bevelEnabled) {
  18637. var layer = 0; // steps + 1
  18638. var offset = vlen * layer; // Bottom faces
  18639. for (var _i9 = 0; _i9 < flen; _i9++) {
  18640. var face = faces[_i9];
  18641. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18642. }
  18643. layer = steps + bevelSegments * 2;
  18644. offset = vlen * layer; // Top faces
  18645. for (var _i10 = 0; _i10 < flen; _i10++) {
  18646. var _face = faces[_i10];
  18647. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18648. }
  18649. } else {
  18650. // Bottom faces
  18651. for (var _i11 = 0; _i11 < flen; _i11++) {
  18652. var _face2 = faces[_i11];
  18653. f3(_face2[2], _face2[1], _face2[0]);
  18654. } // Top faces
  18655. for (var _i12 = 0; _i12 < flen; _i12++) {
  18656. var _face3 = faces[_i12];
  18657. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18658. }
  18659. }
  18660. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18661. } // Create faces for the z-sides of the shape
  18662. function buildSideFaces() {
  18663. var start = verticesArray.length / 3;
  18664. var layeroffset = 0;
  18665. sidewalls(contour, layeroffset);
  18666. layeroffset += contour.length;
  18667. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18668. var _ahole5 = holes[_h5];
  18669. sidewalls(_ahole5, layeroffset); //, true
  18670. layeroffset += _ahole5.length;
  18671. }
  18672. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18673. }
  18674. function sidewalls(contour, layeroffset) {
  18675. var i = contour.length;
  18676. while (--i >= 0) {
  18677. var _j2 = i;
  18678. var _k2 = i - 1;
  18679. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18680. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18681. var slen1 = vlen * _s;
  18682. var slen2 = vlen * (_s + 1);
  18683. var a = layeroffset + _j2 + slen1,
  18684. _b2 = layeroffset + _k2 + slen1,
  18685. c = layeroffset + _k2 + slen2,
  18686. d = layeroffset + _j2 + slen2;
  18687. f4(a, _b2, c, d);
  18688. }
  18689. }
  18690. }
  18691. function v(x, y, z) {
  18692. placeholder.push(x);
  18693. placeholder.push(y);
  18694. placeholder.push(z);
  18695. }
  18696. function f3(a, b, c) {
  18697. addVertex(a);
  18698. addVertex(b);
  18699. addVertex(c);
  18700. var nextIndex = verticesArray.length / 3;
  18701. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18702. addUV(uvs[0]);
  18703. addUV(uvs[1]);
  18704. addUV(uvs[2]);
  18705. }
  18706. function f4(a, b, c, d) {
  18707. addVertex(a);
  18708. addVertex(b);
  18709. addVertex(d);
  18710. addVertex(b);
  18711. addVertex(c);
  18712. addVertex(d);
  18713. var nextIndex = verticesArray.length / 3;
  18714. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18715. addUV(uvs[0]);
  18716. addUV(uvs[1]);
  18717. addUV(uvs[3]);
  18718. addUV(uvs[1]);
  18719. addUV(uvs[2]);
  18720. addUV(uvs[3]);
  18721. }
  18722. function addVertex(index) {
  18723. verticesArray.push(placeholder[index * 3 + 0]);
  18724. verticesArray.push(placeholder[index * 3 + 1]);
  18725. verticesArray.push(placeholder[index * 3 + 2]);
  18726. }
  18727. function addUV(vector2) {
  18728. uvArray.push(vector2.x);
  18729. uvArray.push(vector2.y);
  18730. }
  18731. }
  18732. return _this;
  18733. }
  18734. var _proto = ExtrudeGeometry.prototype;
  18735. _proto.toJSON = function toJSON() {
  18736. var data = BufferGeometry.prototype.toJSON.call(this);
  18737. var shapes = this.parameters.shapes;
  18738. var options = this.parameters.options;
  18739. return _toJSON(shapes, options, data);
  18740. };
  18741. return ExtrudeGeometry;
  18742. }(BufferGeometry);
  18743. var WorldUVGenerator = {
  18744. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18745. var a_x = vertices[indexA * 3];
  18746. var a_y = vertices[indexA * 3 + 1];
  18747. var b_x = vertices[indexB * 3];
  18748. var b_y = vertices[indexB * 3 + 1];
  18749. var c_x = vertices[indexC * 3];
  18750. var c_y = vertices[indexC * 3 + 1];
  18751. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18752. },
  18753. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18754. var a_x = vertices[indexA * 3];
  18755. var a_y = vertices[indexA * 3 + 1];
  18756. var a_z = vertices[indexA * 3 + 2];
  18757. var b_x = vertices[indexB * 3];
  18758. var b_y = vertices[indexB * 3 + 1];
  18759. var b_z = vertices[indexB * 3 + 2];
  18760. var c_x = vertices[indexC * 3];
  18761. var c_y = vertices[indexC * 3 + 1];
  18762. var c_z = vertices[indexC * 3 + 2];
  18763. var d_x = vertices[indexD * 3];
  18764. var d_y = vertices[indexD * 3 + 1];
  18765. var d_z = vertices[indexD * 3 + 2];
  18766. if (Math.abs(a_y - b_y) < 0.01) {
  18767. 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)];
  18768. } else {
  18769. 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)];
  18770. }
  18771. }
  18772. };
  18773. function _toJSON(shapes, options, data) {
  18774. data.shapes = [];
  18775. if (Array.isArray(shapes)) {
  18776. for (var i = 0, l = shapes.length; i < l; i++) {
  18777. var shape = shapes[i];
  18778. data.shapes.push(shape.uuid);
  18779. }
  18780. } else {
  18781. data.shapes.push(shapes.uuid);
  18782. }
  18783. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18784. return data;
  18785. }
  18786. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18787. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18788. function IcosahedronGeometry(radius, detail) {
  18789. var _this;
  18790. if (radius === void 0) {
  18791. radius = 1;
  18792. }
  18793. if (detail === void 0) {
  18794. detail = 0;
  18795. }
  18796. var t = (1 + Math.sqrt(5)) / 2;
  18797. 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];
  18798. 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];
  18799. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18800. _this.type = 'IcosahedronGeometry';
  18801. _this.parameters = {
  18802. radius: radius,
  18803. detail: detail
  18804. };
  18805. return _this;
  18806. }
  18807. return IcosahedronGeometry;
  18808. }(PolyhedronGeometry);
  18809. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18810. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18811. function LatheGeometry(points, segments, phiStart, phiLength) {
  18812. var _this;
  18813. if (segments === void 0) {
  18814. segments = 12;
  18815. }
  18816. if (phiStart === void 0) {
  18817. phiStart = 0;
  18818. }
  18819. if (phiLength === void 0) {
  18820. phiLength = Math.PI * 2;
  18821. }
  18822. _this = _BufferGeometry.call(this) || this;
  18823. _this.type = 'LatheGeometry';
  18824. _this.parameters = {
  18825. points: points,
  18826. segments: segments,
  18827. phiStart: phiStart,
  18828. phiLength: phiLength
  18829. };
  18830. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18831. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18832. var indices = [];
  18833. var vertices = [];
  18834. var uvs = []; // helper variables
  18835. var inverseSegments = 1.0 / segments;
  18836. var vertex = new Vector3();
  18837. var uv = new Vector2(); // generate vertices and uvs
  18838. for (var i = 0; i <= segments; i++) {
  18839. var phi = phiStart + i * inverseSegments * phiLength;
  18840. var sin = Math.sin(phi);
  18841. var cos = Math.cos(phi);
  18842. for (var j = 0; j <= points.length - 1; j++) {
  18843. // vertex
  18844. vertex.x = points[j].x * sin;
  18845. vertex.y = points[j].y;
  18846. vertex.z = points[j].x * cos;
  18847. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18848. uv.x = i / segments;
  18849. uv.y = j / (points.length - 1);
  18850. uvs.push(uv.x, uv.y);
  18851. }
  18852. } // indices
  18853. for (var _i = 0; _i < segments; _i++) {
  18854. for (var _j = 0; _j < points.length - 1; _j++) {
  18855. var base = _j + _i * points.length;
  18856. var a = base;
  18857. var b = base + points.length;
  18858. var c = base + points.length + 1;
  18859. var d = base + 1; // faces
  18860. indices.push(a, b, d);
  18861. indices.push(b, c, d);
  18862. }
  18863. } // build geometry
  18864. _this.setIndex(indices);
  18865. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18866. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18867. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18868. // because the corresponding vertices are identical (but still have different UVs).
  18869. if (phiLength === Math.PI * 2) {
  18870. var normals = _this.attributes.normal.array;
  18871. var n1 = new Vector3();
  18872. var n2 = new Vector3();
  18873. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18874. var _base = segments * points.length * 3;
  18875. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18876. // select the normal of the vertex in the first line
  18877. n1.x = normals[_j2 + 0];
  18878. n1.y = normals[_j2 + 1];
  18879. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18880. n2.x = normals[_base + _j2 + 0];
  18881. n2.y = normals[_base + _j2 + 1];
  18882. n2.z = normals[_base + _j2 + 2]; // average normals
  18883. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18884. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18885. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18886. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18887. }
  18888. }
  18889. return _this;
  18890. }
  18891. return LatheGeometry;
  18892. }(BufferGeometry);
  18893. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18894. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18895. function OctahedronGeometry(radius, detail) {
  18896. var _this;
  18897. if (radius === void 0) {
  18898. radius = 1;
  18899. }
  18900. if (detail === void 0) {
  18901. detail = 0;
  18902. }
  18903. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18904. 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];
  18905. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18906. _this.type = 'OctahedronGeometry';
  18907. _this.parameters = {
  18908. radius: radius,
  18909. detail: detail
  18910. };
  18911. return _this;
  18912. }
  18913. return OctahedronGeometry;
  18914. }(PolyhedronGeometry);
  18915. /**
  18916. * Parametric Surfaces Geometry
  18917. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18918. */
  18919. function ParametricGeometry(func, slices, stacks) {
  18920. BufferGeometry.call(this);
  18921. this.type = 'ParametricGeometry';
  18922. this.parameters = {
  18923. func: func,
  18924. slices: slices,
  18925. stacks: stacks
  18926. }; // buffers
  18927. var indices = [];
  18928. var vertices = [];
  18929. var normals = [];
  18930. var uvs = [];
  18931. var EPS = 0.00001;
  18932. var normal = new Vector3();
  18933. var p0 = new Vector3(),
  18934. p1 = new Vector3();
  18935. var pu = new Vector3(),
  18936. pv = new Vector3();
  18937. if (func.length < 3) {
  18938. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18939. } // generate vertices, normals and uvs
  18940. var sliceCount = slices + 1;
  18941. for (var i = 0; i <= stacks; i++) {
  18942. var v = i / stacks;
  18943. for (var j = 0; j <= slices; j++) {
  18944. var u = j / slices; // vertex
  18945. func(u, v, p0);
  18946. vertices.push(p0.x, p0.y, p0.z); // normal
  18947. // approximate tangent vectors via finite differences
  18948. if (u - EPS >= 0) {
  18949. func(u - EPS, v, p1);
  18950. pu.subVectors(p0, p1);
  18951. } else {
  18952. func(u + EPS, v, p1);
  18953. pu.subVectors(p1, p0);
  18954. }
  18955. if (v - EPS >= 0) {
  18956. func(u, v - EPS, p1);
  18957. pv.subVectors(p0, p1);
  18958. } else {
  18959. func(u, v + EPS, p1);
  18960. pv.subVectors(p1, p0);
  18961. } // cross product of tangent vectors returns surface normal
  18962. normal.crossVectors(pu, pv).normalize();
  18963. normals.push(normal.x, normal.y, normal.z); // uv
  18964. uvs.push(u, v);
  18965. }
  18966. } // generate indices
  18967. for (var _i = 0; _i < stacks; _i++) {
  18968. for (var _j = 0; _j < slices; _j++) {
  18969. var a = _i * sliceCount + _j;
  18970. var b = _i * sliceCount + _j + 1;
  18971. var c = (_i + 1) * sliceCount + _j + 1;
  18972. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18973. indices.push(a, b, d);
  18974. indices.push(b, c, d);
  18975. }
  18976. } // build geometry
  18977. this.setIndex(indices);
  18978. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18979. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18980. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18981. }
  18982. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18983. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18984. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18985. _inheritsLoose(RingGeometry, _BufferGeometry);
  18986. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18987. var _this;
  18988. if (innerRadius === void 0) {
  18989. innerRadius = 0.5;
  18990. }
  18991. if (outerRadius === void 0) {
  18992. outerRadius = 1;
  18993. }
  18994. if (thetaSegments === void 0) {
  18995. thetaSegments = 8;
  18996. }
  18997. if (phiSegments === void 0) {
  18998. phiSegments = 1;
  18999. }
  19000. if (thetaStart === void 0) {
  19001. thetaStart = 0;
  19002. }
  19003. if (thetaLength === void 0) {
  19004. thetaLength = Math.PI * 2;
  19005. }
  19006. _this = _BufferGeometry.call(this) || this;
  19007. _this.type = 'RingGeometry';
  19008. _this.parameters = {
  19009. innerRadius: innerRadius,
  19010. outerRadius: outerRadius,
  19011. thetaSegments: thetaSegments,
  19012. phiSegments: phiSegments,
  19013. thetaStart: thetaStart,
  19014. thetaLength: thetaLength
  19015. };
  19016. thetaSegments = Math.max(3, thetaSegments);
  19017. phiSegments = Math.max(1, phiSegments); // buffers
  19018. var indices = [];
  19019. var vertices = [];
  19020. var normals = [];
  19021. var uvs = []; // some helper variables
  19022. var radius = innerRadius;
  19023. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  19024. var vertex = new Vector3();
  19025. var uv = new Vector2(); // generate vertices, normals and uvs
  19026. for (var j = 0; j <= phiSegments; j++) {
  19027. for (var i = 0; i <= thetaSegments; i++) {
  19028. // values are generate from the inside of the ring to the outside
  19029. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  19030. vertex.x = radius * Math.cos(segment);
  19031. vertex.y = radius * Math.sin(segment);
  19032. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19033. normals.push(0, 0, 1); // uv
  19034. uv.x = (vertex.x / outerRadius + 1) / 2;
  19035. uv.y = (vertex.y / outerRadius + 1) / 2;
  19036. uvs.push(uv.x, uv.y);
  19037. } // increase the radius for next row of vertices
  19038. radius += radiusStep;
  19039. } // indices
  19040. for (var _j = 0; _j < phiSegments; _j++) {
  19041. var thetaSegmentLevel = _j * (thetaSegments + 1);
  19042. for (var _i = 0; _i < thetaSegments; _i++) {
  19043. var _segment = _i + thetaSegmentLevel;
  19044. var a = _segment;
  19045. var b = _segment + thetaSegments + 1;
  19046. var c = _segment + thetaSegments + 2;
  19047. var d = _segment + 1; // faces
  19048. indices.push(a, b, d);
  19049. indices.push(b, c, d);
  19050. }
  19051. } // build geometry
  19052. _this.setIndex(indices);
  19053. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19054. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19055. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19056. return _this;
  19057. }
  19058. return RingGeometry;
  19059. }(BufferGeometry);
  19060. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19061. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  19062. function ShapeGeometry(shapes, curveSegments) {
  19063. var _this;
  19064. if (curveSegments === void 0) {
  19065. curveSegments = 12;
  19066. }
  19067. _this = _BufferGeometry.call(this) || this;
  19068. _this.type = 'ShapeGeometry';
  19069. _this.parameters = {
  19070. shapes: shapes,
  19071. curveSegments: curveSegments
  19072. }; // buffers
  19073. var indices = [];
  19074. var vertices = [];
  19075. var normals = [];
  19076. var uvs = []; // helper variables
  19077. var groupStart = 0;
  19078. var groupCount = 0; // allow single and array values for "shapes" parameter
  19079. if (Array.isArray(shapes) === false) {
  19080. addShape(shapes);
  19081. } else {
  19082. for (var i = 0; i < shapes.length; i++) {
  19083. addShape(shapes[i]);
  19084. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19085. groupStart += groupCount;
  19086. groupCount = 0;
  19087. }
  19088. } // build geometry
  19089. _this.setIndex(indices);
  19090. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19091. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19092. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19093. function addShape(shape) {
  19094. var indexOffset = vertices.length / 3;
  19095. var points = shape.extractPoints(curveSegments);
  19096. var shapeVertices = points.shape;
  19097. var shapeHoles = points.holes; // check direction of vertices
  19098. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19099. shapeVertices = shapeVertices.reverse();
  19100. }
  19101. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19102. var shapeHole = shapeHoles[_i];
  19103. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19104. shapeHoles[_i] = shapeHole.reverse();
  19105. }
  19106. }
  19107. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19108. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19109. var _shapeHole = shapeHoles[_i2];
  19110. shapeVertices = shapeVertices.concat(_shapeHole);
  19111. } // vertices, normals, uvs
  19112. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19113. var vertex = shapeVertices[_i3];
  19114. vertices.push(vertex.x, vertex.y, 0);
  19115. normals.push(0, 0, 1);
  19116. uvs.push(vertex.x, vertex.y); // world uvs
  19117. } // incides
  19118. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19119. var face = faces[_i4];
  19120. var a = face[0] + indexOffset;
  19121. var b = face[1] + indexOffset;
  19122. var c = face[2] + indexOffset;
  19123. indices.push(a, b, c);
  19124. groupCount += 3;
  19125. }
  19126. }
  19127. return _this;
  19128. }
  19129. var _proto = ShapeGeometry.prototype;
  19130. _proto.toJSON = function toJSON() {
  19131. var data = BufferGeometry.prototype.toJSON.call(this);
  19132. var shapes = this.parameters.shapes;
  19133. return _toJSON$1(shapes, data);
  19134. };
  19135. return ShapeGeometry;
  19136. }(BufferGeometry);
  19137. function _toJSON$1(shapes, data) {
  19138. data.shapes = [];
  19139. if (Array.isArray(shapes)) {
  19140. for (var i = 0, l = shapes.length; i < l; i++) {
  19141. var shape = shapes[i];
  19142. data.shapes.push(shape.uuid);
  19143. }
  19144. } else {
  19145. data.shapes.push(shapes.uuid);
  19146. }
  19147. return data;
  19148. }
  19149. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19150. _inheritsLoose(SphereGeometry, _BufferGeometry);
  19151. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19152. var _this;
  19153. if (radius === void 0) {
  19154. radius = 1;
  19155. }
  19156. if (widthSegments === void 0) {
  19157. widthSegments = 8;
  19158. }
  19159. if (heightSegments === void 0) {
  19160. heightSegments = 6;
  19161. }
  19162. if (phiStart === void 0) {
  19163. phiStart = 0;
  19164. }
  19165. if (phiLength === void 0) {
  19166. phiLength = Math.PI * 2;
  19167. }
  19168. if (thetaStart === void 0) {
  19169. thetaStart = 0;
  19170. }
  19171. if (thetaLength === void 0) {
  19172. thetaLength = Math.PI;
  19173. }
  19174. _this = _BufferGeometry.call(this) || this;
  19175. _this.type = 'SphereGeometry';
  19176. _this.parameters = {
  19177. radius: radius,
  19178. widthSegments: widthSegments,
  19179. heightSegments: heightSegments,
  19180. phiStart: phiStart,
  19181. phiLength: phiLength,
  19182. thetaStart: thetaStart,
  19183. thetaLength: thetaLength
  19184. };
  19185. widthSegments = Math.max(3, Math.floor(widthSegments));
  19186. heightSegments = Math.max(2, Math.floor(heightSegments));
  19187. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19188. var index = 0;
  19189. var grid = [];
  19190. var vertex = new Vector3();
  19191. var normal = new Vector3(); // buffers
  19192. var indices = [];
  19193. var vertices = [];
  19194. var normals = [];
  19195. var uvs = []; // generate vertices, normals and uvs
  19196. for (var iy = 0; iy <= heightSegments; iy++) {
  19197. var verticesRow = [];
  19198. var v = iy / heightSegments; // special case for the poles
  19199. var uOffset = 0;
  19200. if (iy == 0 && thetaStart == 0) {
  19201. uOffset = 0.5 / widthSegments;
  19202. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19203. uOffset = -0.5 / widthSegments;
  19204. }
  19205. for (var ix = 0; ix <= widthSegments; ix++) {
  19206. var u = ix / widthSegments; // vertex
  19207. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19208. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19209. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19210. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19211. normal.copy(vertex).normalize();
  19212. normals.push(normal.x, normal.y, normal.z); // uv
  19213. uvs.push(u + uOffset, 1 - v);
  19214. verticesRow.push(index++);
  19215. }
  19216. grid.push(verticesRow);
  19217. } // indices
  19218. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19219. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19220. var a = grid[_iy][_ix + 1];
  19221. var b = grid[_iy][_ix];
  19222. var c = grid[_iy + 1][_ix];
  19223. var d = grid[_iy + 1][_ix + 1];
  19224. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19225. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19226. }
  19227. } // build geometry
  19228. _this.setIndex(indices);
  19229. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19230. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19231. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19232. return _this;
  19233. }
  19234. return SphereGeometry;
  19235. }(BufferGeometry);
  19236. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  19237. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  19238. function TetrahedronGeometry(radius, detail) {
  19239. var _this;
  19240. if (radius === void 0) {
  19241. radius = 1;
  19242. }
  19243. if (detail === void 0) {
  19244. detail = 0;
  19245. }
  19246. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19247. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19248. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  19249. _this.type = 'TetrahedronGeometry';
  19250. _this.parameters = {
  19251. radius: radius,
  19252. detail: detail
  19253. };
  19254. return _this;
  19255. }
  19256. return TetrahedronGeometry;
  19257. }(PolyhedronGeometry);
  19258. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  19259. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  19260. function TextGeometry(text, parameters) {
  19261. var _this;
  19262. if (parameters === void 0) {
  19263. parameters = {};
  19264. }
  19265. var font = parameters.font;
  19266. if (!(font && font.isFont)) {
  19267. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19268. return new BufferGeometry() || _assertThisInitialized(_this);
  19269. }
  19270. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19271. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19272. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19273. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19274. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19275. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  19276. _this.type = 'TextGeometry';
  19277. return _this;
  19278. }
  19279. return TextGeometry;
  19280. }(ExtrudeGeometry);
  19281. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19282. _inheritsLoose(TorusGeometry, _BufferGeometry);
  19283. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19284. var _this;
  19285. if (radius === void 0) {
  19286. radius = 1;
  19287. }
  19288. if (tube === void 0) {
  19289. tube = 0.4;
  19290. }
  19291. if (radialSegments === void 0) {
  19292. radialSegments = 8;
  19293. }
  19294. if (tubularSegments === void 0) {
  19295. tubularSegments = 6;
  19296. }
  19297. if (arc === void 0) {
  19298. arc = Math.PI * 2;
  19299. }
  19300. _this = _BufferGeometry.call(this) || this;
  19301. _this.type = 'TorusGeometry';
  19302. _this.parameters = {
  19303. radius: radius,
  19304. tube: tube,
  19305. radialSegments: radialSegments,
  19306. tubularSegments: tubularSegments,
  19307. arc: arc
  19308. };
  19309. radialSegments = Math.floor(radialSegments);
  19310. tubularSegments = Math.floor(tubularSegments); // buffers
  19311. var indices = [];
  19312. var vertices = [];
  19313. var normals = [];
  19314. var uvs = []; // helper variables
  19315. var center = new Vector3();
  19316. var vertex = new Vector3();
  19317. var normal = new Vector3(); // generate vertices, normals and uvs
  19318. for (var j = 0; j <= radialSegments; j++) {
  19319. for (var i = 0; i <= tubularSegments; i++) {
  19320. var u = i / tubularSegments * arc;
  19321. var v = j / radialSegments * Math.PI * 2; // vertex
  19322. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19323. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19324. vertex.z = tube * Math.sin(v);
  19325. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19326. center.x = radius * Math.cos(u);
  19327. center.y = radius * Math.sin(u);
  19328. normal.subVectors(vertex, center).normalize();
  19329. normals.push(normal.x, normal.y, normal.z); // uv
  19330. uvs.push(i / tubularSegments);
  19331. uvs.push(j / radialSegments);
  19332. }
  19333. } // generate indices
  19334. for (var _j = 1; _j <= radialSegments; _j++) {
  19335. for (var _i = 1; _i <= tubularSegments; _i++) {
  19336. // indices
  19337. var a = (tubularSegments + 1) * _j + _i - 1;
  19338. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19339. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19340. var d = (tubularSegments + 1) * _j + _i; // faces
  19341. indices.push(a, b, d);
  19342. indices.push(b, c, d);
  19343. }
  19344. } // build geometry
  19345. _this.setIndex(indices);
  19346. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19347. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19348. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19349. return _this;
  19350. }
  19351. return TorusGeometry;
  19352. }(BufferGeometry);
  19353. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19354. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  19355. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19356. var _this;
  19357. if (radius === void 0) {
  19358. radius = 1;
  19359. }
  19360. if (tube === void 0) {
  19361. tube = 0.4;
  19362. }
  19363. if (tubularSegments === void 0) {
  19364. tubularSegments = 64;
  19365. }
  19366. if (radialSegments === void 0) {
  19367. radialSegments = 8;
  19368. }
  19369. if (p === void 0) {
  19370. p = 2;
  19371. }
  19372. if (q === void 0) {
  19373. q = 3;
  19374. }
  19375. _this = _BufferGeometry.call(this) || this;
  19376. _this.type = 'TorusKnotGeometry';
  19377. _this.parameters = {
  19378. radius: radius,
  19379. tube: tube,
  19380. tubularSegments: tubularSegments,
  19381. radialSegments: radialSegments,
  19382. p: p,
  19383. q: q
  19384. };
  19385. tubularSegments = Math.floor(tubularSegments);
  19386. radialSegments = Math.floor(radialSegments); // buffers
  19387. var indices = [];
  19388. var vertices = [];
  19389. var normals = [];
  19390. var uvs = []; // helper variables
  19391. var vertex = new Vector3();
  19392. var normal = new Vector3();
  19393. var P1 = new Vector3();
  19394. var P2 = new Vector3();
  19395. var B = new Vector3();
  19396. var T = new Vector3();
  19397. var N = new Vector3(); // generate vertices, normals and uvs
  19398. for (var i = 0; i <= tubularSegments; ++i) {
  19399. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19400. 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.
  19401. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19402. calculatePositionOnCurve(u, p, q, radius, P1);
  19403. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19404. T.subVectors(P2, P1);
  19405. N.addVectors(P2, P1);
  19406. B.crossVectors(T, N);
  19407. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19408. B.normalize();
  19409. N.normalize();
  19410. for (var j = 0; j <= radialSegments; ++j) {
  19411. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19412. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19413. var v = j / radialSegments * Math.PI * 2;
  19414. var cx = -tube * Math.cos(v);
  19415. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19416. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19417. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19418. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19419. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19420. 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)
  19421. normal.subVectors(vertex, P1).normalize();
  19422. normals.push(normal.x, normal.y, normal.z); // uv
  19423. uvs.push(i / tubularSegments);
  19424. uvs.push(j / radialSegments);
  19425. }
  19426. } // generate indices
  19427. for (var _j = 1; _j <= tubularSegments; _j++) {
  19428. for (var _i = 1; _i <= radialSegments; _i++) {
  19429. // indices
  19430. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19431. var b = (radialSegments + 1) * _j + (_i - 1);
  19432. var c = (radialSegments + 1) * _j + _i;
  19433. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19434. indices.push(a, b, d);
  19435. indices.push(b, c, d);
  19436. }
  19437. } // build geometry
  19438. _this.setIndex(indices);
  19439. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19440. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19441. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19442. function calculatePositionOnCurve(u, p, q, radius, position) {
  19443. var cu = Math.cos(u);
  19444. var su = Math.sin(u);
  19445. var quOverP = q / p * u;
  19446. var cs = Math.cos(quOverP);
  19447. position.x = radius * (2 + cs) * 0.5 * cu;
  19448. position.y = radius * (2 + cs) * su * 0.5;
  19449. position.z = radius * Math.sin(quOverP) * 0.5;
  19450. }
  19451. return _this;
  19452. }
  19453. return TorusKnotGeometry;
  19454. }(BufferGeometry);
  19455. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19456. _inheritsLoose(TubeGeometry, _BufferGeometry);
  19457. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19458. var _this;
  19459. if (tubularSegments === void 0) {
  19460. tubularSegments = 64;
  19461. }
  19462. if (radius === void 0) {
  19463. radius = 1;
  19464. }
  19465. if (radialSegments === void 0) {
  19466. radialSegments = 8;
  19467. }
  19468. if (closed === void 0) {
  19469. closed = false;
  19470. }
  19471. _this = _BufferGeometry.call(this) || this;
  19472. _this.type = 'TubeGeometry';
  19473. _this.parameters = {
  19474. path: path,
  19475. tubularSegments: tubularSegments,
  19476. radius: radius,
  19477. radialSegments: radialSegments,
  19478. closed: closed
  19479. };
  19480. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19481. _this.tangents = frames.tangents;
  19482. _this.normals = frames.normals;
  19483. _this.binormals = frames.binormals; // helper variables
  19484. var vertex = new Vector3();
  19485. var normal = new Vector3();
  19486. var uv = new Vector2();
  19487. var P = new Vector3(); // buffer
  19488. var vertices = [];
  19489. var normals = [];
  19490. var uvs = [];
  19491. var indices = []; // create buffer data
  19492. generateBufferData(); // build geometry
  19493. _this.setIndex(indices);
  19494. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19495. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19496. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19497. function generateBufferData() {
  19498. for (var i = 0; i < tubularSegments; i++) {
  19499. generateSegment(i);
  19500. } // if the geometry is not closed, generate the last row of vertices and normals
  19501. // at the regular position on the given path
  19502. //
  19503. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19504. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19505. // this makes it easy compute correct values for closed geometries
  19506. generateUVs(); // finally create faces
  19507. generateIndices();
  19508. }
  19509. function generateSegment(i) {
  19510. // we use getPointAt to sample evenly distributed points from the given path
  19511. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19512. var N = frames.normals[i];
  19513. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19514. for (var j = 0; j <= radialSegments; j++) {
  19515. var v = j / radialSegments * Math.PI * 2;
  19516. var sin = Math.sin(v);
  19517. var cos = -Math.cos(v); // normal
  19518. normal.x = cos * N.x + sin * B.x;
  19519. normal.y = cos * N.y + sin * B.y;
  19520. normal.z = cos * N.z + sin * B.z;
  19521. normal.normalize();
  19522. normals.push(normal.x, normal.y, normal.z); // vertex
  19523. vertex.x = P.x + radius * normal.x;
  19524. vertex.y = P.y + radius * normal.y;
  19525. vertex.z = P.z + radius * normal.z;
  19526. vertices.push(vertex.x, vertex.y, vertex.z);
  19527. }
  19528. }
  19529. function generateIndices() {
  19530. for (var j = 1; j <= tubularSegments; j++) {
  19531. for (var i = 1; i <= radialSegments; i++) {
  19532. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19533. var b = (radialSegments + 1) * j + (i - 1);
  19534. var c = (radialSegments + 1) * j + i;
  19535. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19536. indices.push(a, b, d);
  19537. indices.push(b, c, d);
  19538. }
  19539. }
  19540. }
  19541. function generateUVs() {
  19542. for (var i = 0; i <= tubularSegments; i++) {
  19543. for (var j = 0; j <= radialSegments; j++) {
  19544. uv.x = i / tubularSegments;
  19545. uv.y = j / radialSegments;
  19546. uvs.push(uv.x, uv.y);
  19547. }
  19548. }
  19549. }
  19550. return _this;
  19551. }
  19552. var _proto = TubeGeometry.prototype;
  19553. _proto.toJSON = function toJSON() {
  19554. var data = BufferGeometry.prototype.toJSON.call(this);
  19555. data.path = this.parameters.path.toJSON();
  19556. return data;
  19557. };
  19558. return TubeGeometry;
  19559. }(BufferGeometry);
  19560. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19561. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19562. function WireframeGeometry(geometry) {
  19563. var _this;
  19564. _this = _BufferGeometry.call(this) || this;
  19565. _this.type = 'WireframeGeometry';
  19566. if (geometry.isGeometry === true) {
  19567. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  19568. return _assertThisInitialized(_this);
  19569. } // buffer
  19570. var vertices = []; // helper variables
  19571. var edge = [0, 0],
  19572. edges = {};
  19573. var vertex = new Vector3();
  19574. if (geometry.index !== null) {
  19575. // indexed BufferGeometry
  19576. var position = geometry.attributes.position;
  19577. var indices = geometry.index;
  19578. var groups = geometry.groups;
  19579. if (groups.length === 0) {
  19580. groups = [{
  19581. start: 0,
  19582. count: indices.count,
  19583. materialIndex: 0
  19584. }];
  19585. } // create a data structure that contains all eges without duplicates
  19586. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19587. var group = groups[o];
  19588. var start = group.start;
  19589. var count = group.count;
  19590. for (var i = start, l = start + count; i < l; i += 3) {
  19591. for (var j = 0; j < 3; j++) {
  19592. var edge1 = indices.getX(i + j);
  19593. var edge2 = indices.getX(i + (j + 1) % 3);
  19594. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19595. edge[1] = Math.max(edge1, edge2);
  19596. var key = edge[0] + ',' + edge[1];
  19597. if (edges[key] === undefined) {
  19598. edges[key] = {
  19599. index1: edge[0],
  19600. index2: edge[1]
  19601. };
  19602. }
  19603. }
  19604. }
  19605. } // generate vertices
  19606. for (var _key in edges) {
  19607. var e = edges[_key];
  19608. vertex.fromBufferAttribute(position, e.index1);
  19609. vertices.push(vertex.x, vertex.y, vertex.z);
  19610. vertex.fromBufferAttribute(position, e.index2);
  19611. vertices.push(vertex.x, vertex.y, vertex.z);
  19612. }
  19613. } else {
  19614. // non-indexed BufferGeometry
  19615. var _position = geometry.attributes.position;
  19616. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  19617. for (var _j = 0; _j < 3; _j++) {
  19618. // three edges per triangle, an edge is represented as (index1, index2)
  19619. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19620. var index1 = 3 * _i + _j;
  19621. vertex.fromBufferAttribute(_position, index1);
  19622. vertices.push(vertex.x, vertex.y, vertex.z);
  19623. var index2 = 3 * _i + (_j + 1) % 3;
  19624. vertex.fromBufferAttribute(_position, index2);
  19625. vertices.push(vertex.x, vertex.y, vertex.z);
  19626. }
  19627. }
  19628. } // build geometry
  19629. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19630. return _this;
  19631. }
  19632. return WireframeGeometry;
  19633. }(BufferGeometry);
  19634. var Geometries = /*#__PURE__*/Object.freeze({
  19635. __proto__: null,
  19636. BoxGeometry: BoxGeometry,
  19637. BoxBufferGeometry: BoxGeometry,
  19638. CircleGeometry: CircleGeometry,
  19639. CircleBufferGeometry: CircleGeometry,
  19640. ConeGeometry: ConeGeometry,
  19641. ConeBufferGeometry: ConeGeometry,
  19642. CylinderGeometry: CylinderGeometry,
  19643. CylinderBufferGeometry: CylinderGeometry,
  19644. DodecahedronGeometry: DodecahedronGeometry,
  19645. DodecahedronBufferGeometry: DodecahedronGeometry,
  19646. EdgesGeometry: EdgesGeometry,
  19647. ExtrudeGeometry: ExtrudeGeometry,
  19648. ExtrudeBufferGeometry: ExtrudeGeometry,
  19649. IcosahedronGeometry: IcosahedronGeometry,
  19650. IcosahedronBufferGeometry: IcosahedronGeometry,
  19651. LatheGeometry: LatheGeometry,
  19652. LatheBufferGeometry: LatheGeometry,
  19653. OctahedronGeometry: OctahedronGeometry,
  19654. OctahedronBufferGeometry: OctahedronGeometry,
  19655. ParametricGeometry: ParametricGeometry,
  19656. ParametricBufferGeometry: ParametricGeometry,
  19657. PlaneGeometry: PlaneGeometry,
  19658. PlaneBufferGeometry: PlaneGeometry,
  19659. PolyhedronGeometry: PolyhedronGeometry,
  19660. PolyhedronBufferGeometry: PolyhedronGeometry,
  19661. RingGeometry: RingGeometry,
  19662. RingBufferGeometry: RingGeometry,
  19663. ShapeGeometry: ShapeGeometry,
  19664. ShapeBufferGeometry: ShapeGeometry,
  19665. SphereGeometry: SphereGeometry,
  19666. SphereBufferGeometry: SphereGeometry,
  19667. TetrahedronGeometry: TetrahedronGeometry,
  19668. TetrahedronBufferGeometry: TetrahedronGeometry,
  19669. TextGeometry: TextGeometry,
  19670. TextBufferGeometry: TextGeometry,
  19671. TorusGeometry: TorusGeometry,
  19672. TorusBufferGeometry: TorusGeometry,
  19673. TorusKnotGeometry: TorusKnotGeometry,
  19674. TorusKnotBufferGeometry: TorusKnotGeometry,
  19675. TubeGeometry: TubeGeometry,
  19676. TubeBufferGeometry: TubeGeometry,
  19677. WireframeGeometry: WireframeGeometry
  19678. });
  19679. /**
  19680. * parameters = {
  19681. * color: <THREE.Color>
  19682. * }
  19683. */
  19684. var ShadowMaterial = /*#__PURE__*/function (_Material) {
  19685. _inheritsLoose(ShadowMaterial, _Material);
  19686. function ShadowMaterial(parameters) {
  19687. var _this;
  19688. _this = _Material.call(this) || this;
  19689. _this.type = 'ShadowMaterial';
  19690. _this.color = new Color(0x000000);
  19691. _this.transparent = true;
  19692. _this.setValues(parameters);
  19693. return _this;
  19694. }
  19695. var _proto = ShadowMaterial.prototype;
  19696. _proto.copy = function copy(source) {
  19697. _Material.prototype.copy.call(this, source);
  19698. this.color.copy(source.color);
  19699. return this;
  19700. };
  19701. return ShadowMaterial;
  19702. }(Material);
  19703. ShadowMaterial.prototype.isShadowMaterial = true;
  19704. var RawShaderMaterial = /*#__PURE__*/function (_ShaderMaterial) {
  19705. _inheritsLoose(RawShaderMaterial, _ShaderMaterial);
  19706. function RawShaderMaterial(parameters) {
  19707. var _this;
  19708. _this = _ShaderMaterial.call(this, parameters) || this;
  19709. _this.type = 'RawShaderMaterial';
  19710. return _this;
  19711. }
  19712. return RawShaderMaterial;
  19713. }(ShaderMaterial);
  19714. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19715. /**
  19716. * parameters = {
  19717. * color: <hex>,
  19718. * roughness: <float>,
  19719. * metalness: <float>,
  19720. * opacity: <float>,
  19721. *
  19722. * map: new THREE.Texture( <Image> ),
  19723. *
  19724. * lightMap: new THREE.Texture( <Image> ),
  19725. * lightMapIntensity: <float>
  19726. *
  19727. * aoMap: new THREE.Texture( <Image> ),
  19728. * aoMapIntensity: <float>
  19729. *
  19730. * emissive: <hex>,
  19731. * emissiveIntensity: <float>
  19732. * emissiveMap: new THREE.Texture( <Image> ),
  19733. *
  19734. * bumpMap: new THREE.Texture( <Image> ),
  19735. * bumpScale: <float>,
  19736. *
  19737. * normalMap: new THREE.Texture( <Image> ),
  19738. * normalMapType: THREE.TangentSpaceNormalMap,
  19739. * normalScale: <Vector2>,
  19740. *
  19741. * displacementMap: new THREE.Texture( <Image> ),
  19742. * displacementScale: <float>,
  19743. * displacementBias: <float>,
  19744. *
  19745. * roughnessMap: new THREE.Texture( <Image> ),
  19746. *
  19747. * metalnessMap: new THREE.Texture( <Image> ),
  19748. *
  19749. * alphaMap: new THREE.Texture( <Image> ),
  19750. *
  19751. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19752. * envMapIntensity: <float>
  19753. *
  19754. * refractionRatio: <float>,
  19755. *
  19756. * wireframe: <boolean>,
  19757. * wireframeLinewidth: <float>,
  19758. *
  19759. * skinning: <bool>,
  19760. * morphTargets: <bool>,
  19761. * morphNormals: <bool>,
  19762. *
  19763. * flatShading: <bool>
  19764. * }
  19765. */
  19766. var MeshStandardMaterial = /*#__PURE__*/function (_Material) {
  19767. _inheritsLoose(MeshStandardMaterial, _Material);
  19768. function MeshStandardMaterial(parameters) {
  19769. var _this;
  19770. _this = _Material.call(this) || this;
  19771. _this.defines = {
  19772. 'STANDARD': ''
  19773. };
  19774. _this.type = 'MeshStandardMaterial';
  19775. _this.color = new Color(0xffffff); // diffuse
  19776. _this.roughness = 1.0;
  19777. _this.metalness = 0.0;
  19778. _this.map = null;
  19779. _this.lightMap = null;
  19780. _this.lightMapIntensity = 1.0;
  19781. _this.aoMap = null;
  19782. _this.aoMapIntensity = 1.0;
  19783. _this.emissive = new Color(0x000000);
  19784. _this.emissiveIntensity = 1.0;
  19785. _this.emissiveMap = null;
  19786. _this.bumpMap = null;
  19787. _this.bumpScale = 1;
  19788. _this.normalMap = null;
  19789. _this.normalMapType = TangentSpaceNormalMap;
  19790. _this.normalScale = new Vector2(1, 1);
  19791. _this.displacementMap = null;
  19792. _this.displacementScale = 1;
  19793. _this.displacementBias = 0;
  19794. _this.roughnessMap = null;
  19795. _this.metalnessMap = null;
  19796. _this.alphaMap = null;
  19797. _this.envMap = null;
  19798. _this.envMapIntensity = 1.0;
  19799. _this.refractionRatio = 0.98;
  19800. _this.wireframe = false;
  19801. _this.wireframeLinewidth = 1;
  19802. _this.wireframeLinecap = 'round';
  19803. _this.wireframeLinejoin = 'round';
  19804. _this.skinning = false;
  19805. _this.morphTargets = false;
  19806. _this.morphNormals = false;
  19807. _this.flatShading = false;
  19808. _this.vertexTangents = false;
  19809. _this.setValues(parameters);
  19810. return _this;
  19811. }
  19812. var _proto = MeshStandardMaterial.prototype;
  19813. _proto.copy = function copy(source) {
  19814. _Material.prototype.copy.call(this, source);
  19815. this.defines = {
  19816. 'STANDARD': ''
  19817. };
  19818. this.color.copy(source.color);
  19819. this.roughness = source.roughness;
  19820. this.metalness = source.metalness;
  19821. this.map = source.map;
  19822. this.lightMap = source.lightMap;
  19823. this.lightMapIntensity = source.lightMapIntensity;
  19824. this.aoMap = source.aoMap;
  19825. this.aoMapIntensity = source.aoMapIntensity;
  19826. this.emissive.copy(source.emissive);
  19827. this.emissiveMap = source.emissiveMap;
  19828. this.emissiveIntensity = source.emissiveIntensity;
  19829. this.bumpMap = source.bumpMap;
  19830. this.bumpScale = source.bumpScale;
  19831. this.normalMap = source.normalMap;
  19832. this.normalMapType = source.normalMapType;
  19833. this.normalScale.copy(source.normalScale);
  19834. this.displacementMap = source.displacementMap;
  19835. this.displacementScale = source.displacementScale;
  19836. this.displacementBias = source.displacementBias;
  19837. this.roughnessMap = source.roughnessMap;
  19838. this.metalnessMap = source.metalnessMap;
  19839. this.alphaMap = source.alphaMap;
  19840. this.envMap = source.envMap;
  19841. this.envMapIntensity = source.envMapIntensity;
  19842. this.refractionRatio = source.refractionRatio;
  19843. this.wireframe = source.wireframe;
  19844. this.wireframeLinewidth = source.wireframeLinewidth;
  19845. this.wireframeLinecap = source.wireframeLinecap;
  19846. this.wireframeLinejoin = source.wireframeLinejoin;
  19847. this.skinning = source.skinning;
  19848. this.morphTargets = source.morphTargets;
  19849. this.morphNormals = source.morphNormals;
  19850. this.flatShading = source.flatShading;
  19851. this.vertexTangents = source.vertexTangents;
  19852. return this;
  19853. };
  19854. return MeshStandardMaterial;
  19855. }(Material);
  19856. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19857. /**
  19858. * parameters = {
  19859. * clearcoat: <float>,
  19860. * clearcoatMap: new THREE.Texture( <Image> ),
  19861. * clearcoatRoughness: <float>,
  19862. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19863. * clearcoatNormalScale: <Vector2>,
  19864. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19865. *
  19866. * reflectivity: <float>,
  19867. * ior: <float>,
  19868. *
  19869. * sheen: <Color>,
  19870. *
  19871. * transmission: <float>,
  19872. * transmissionMap: new THREE.Texture( <Image> )
  19873. * }
  19874. */
  19875. var MeshPhysicalMaterial = /*#__PURE__*/function (_MeshStandardMaterial) {
  19876. _inheritsLoose(MeshPhysicalMaterial, _MeshStandardMaterial);
  19877. function MeshPhysicalMaterial(parameters) {
  19878. var _this;
  19879. _this = _MeshStandardMaterial.call(this) || this;
  19880. _this.defines = {
  19881. 'STANDARD': '',
  19882. 'PHYSICAL': ''
  19883. };
  19884. _this.type = 'MeshPhysicalMaterial';
  19885. _this.clearcoat = 0.0;
  19886. _this.clearcoatMap = null;
  19887. _this.clearcoatRoughness = 0.0;
  19888. _this.clearcoatRoughnessMap = null;
  19889. _this.clearcoatNormalScale = new Vector2(1, 1);
  19890. _this.clearcoatNormalMap = null;
  19891. _this.reflectivity = 0.5; // maps to F0 = 0.04
  19892. Object.defineProperty(_assertThisInitialized(_this), 'ior', {
  19893. get: function get() {
  19894. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19895. },
  19896. set: function set(ior) {
  19897. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19898. }
  19899. });
  19900. _this.sheen = null; // null will disable sheen bsdf
  19901. _this.transmission = 0.0;
  19902. _this.transmissionMap = null;
  19903. _this.setValues(parameters);
  19904. return _this;
  19905. }
  19906. var _proto = MeshPhysicalMaterial.prototype;
  19907. _proto.copy = function copy(source) {
  19908. _MeshStandardMaterial.prototype.copy.call(this, source);
  19909. this.defines = {
  19910. 'STANDARD': '',
  19911. 'PHYSICAL': ''
  19912. };
  19913. this.clearcoat = source.clearcoat;
  19914. this.clearcoatMap = source.clearcoatMap;
  19915. this.clearcoatRoughness = source.clearcoatRoughness;
  19916. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19917. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19918. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19919. this.reflectivity = source.reflectivity;
  19920. if (source.sheen) {
  19921. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19922. } else {
  19923. this.sheen = null;
  19924. }
  19925. this.transmission = source.transmission;
  19926. this.transmissionMap = source.transmissionMap;
  19927. return this;
  19928. };
  19929. return MeshPhysicalMaterial;
  19930. }(MeshStandardMaterial);
  19931. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19932. /**
  19933. * parameters = {
  19934. * color: <hex>,
  19935. * specular: <hex>,
  19936. * shininess: <float>,
  19937. * opacity: <float>,
  19938. *
  19939. * map: new THREE.Texture( <Image> ),
  19940. *
  19941. * lightMap: new THREE.Texture( <Image> ),
  19942. * lightMapIntensity: <float>
  19943. *
  19944. * aoMap: new THREE.Texture( <Image> ),
  19945. * aoMapIntensity: <float>
  19946. *
  19947. * emissive: <hex>,
  19948. * emissiveIntensity: <float>
  19949. * emissiveMap: new THREE.Texture( <Image> ),
  19950. *
  19951. * bumpMap: new THREE.Texture( <Image> ),
  19952. * bumpScale: <float>,
  19953. *
  19954. * normalMap: new THREE.Texture( <Image> ),
  19955. * normalMapType: THREE.TangentSpaceNormalMap,
  19956. * normalScale: <Vector2>,
  19957. *
  19958. * displacementMap: new THREE.Texture( <Image> ),
  19959. * displacementScale: <float>,
  19960. * displacementBias: <float>,
  19961. *
  19962. * specularMap: new THREE.Texture( <Image> ),
  19963. *
  19964. * alphaMap: new THREE.Texture( <Image> ),
  19965. *
  19966. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19967. * combine: THREE.MultiplyOperation,
  19968. * reflectivity: <float>,
  19969. * refractionRatio: <float>,
  19970. *
  19971. * wireframe: <boolean>,
  19972. * wireframeLinewidth: <float>,
  19973. *
  19974. * skinning: <bool>,
  19975. * morphTargets: <bool>,
  19976. * morphNormals: <bool>,
  19977. *
  19978. * flatShading: <bool>
  19979. * }
  19980. */
  19981. var MeshPhongMaterial = /*#__PURE__*/function (_Material) {
  19982. _inheritsLoose(MeshPhongMaterial, _Material);
  19983. function MeshPhongMaterial(parameters) {
  19984. var _this;
  19985. _this = _Material.call(this) || this;
  19986. _this.type = 'MeshPhongMaterial';
  19987. _this.color = new Color(0xffffff); // diffuse
  19988. _this.specular = new Color(0x111111);
  19989. _this.shininess = 30;
  19990. _this.map = null;
  19991. _this.lightMap = null;
  19992. _this.lightMapIntensity = 1.0;
  19993. _this.aoMap = null;
  19994. _this.aoMapIntensity = 1.0;
  19995. _this.emissive = new Color(0x000000);
  19996. _this.emissiveIntensity = 1.0;
  19997. _this.emissiveMap = null;
  19998. _this.bumpMap = null;
  19999. _this.bumpScale = 1;
  20000. _this.normalMap = null;
  20001. _this.normalMapType = TangentSpaceNormalMap;
  20002. _this.normalScale = new Vector2(1, 1);
  20003. _this.displacementMap = null;
  20004. _this.displacementScale = 1;
  20005. _this.displacementBias = 0;
  20006. _this.specularMap = null;
  20007. _this.alphaMap = null;
  20008. _this.envMap = null;
  20009. _this.combine = MultiplyOperation;
  20010. _this.reflectivity = 1;
  20011. _this.refractionRatio = 0.98;
  20012. _this.wireframe = false;
  20013. _this.wireframeLinewidth = 1;
  20014. _this.wireframeLinecap = 'round';
  20015. _this.wireframeLinejoin = 'round';
  20016. _this.skinning = false;
  20017. _this.morphTargets = false;
  20018. _this.morphNormals = false;
  20019. _this.flatShading = false;
  20020. _this.setValues(parameters);
  20021. return _this;
  20022. }
  20023. var _proto = MeshPhongMaterial.prototype;
  20024. _proto.copy = function copy(source) {
  20025. _Material.prototype.copy.call(this, source);
  20026. this.color.copy(source.color);
  20027. this.specular.copy(source.specular);
  20028. this.shininess = source.shininess;
  20029. this.map = source.map;
  20030. this.lightMap = source.lightMap;
  20031. this.lightMapIntensity = source.lightMapIntensity;
  20032. this.aoMap = source.aoMap;
  20033. this.aoMapIntensity = source.aoMapIntensity;
  20034. this.emissive.copy(source.emissive);
  20035. this.emissiveMap = source.emissiveMap;
  20036. this.emissiveIntensity = source.emissiveIntensity;
  20037. this.bumpMap = source.bumpMap;
  20038. this.bumpScale = source.bumpScale;
  20039. this.normalMap = source.normalMap;
  20040. this.normalMapType = source.normalMapType;
  20041. this.normalScale.copy(source.normalScale);
  20042. this.displacementMap = source.displacementMap;
  20043. this.displacementScale = source.displacementScale;
  20044. this.displacementBias = source.displacementBias;
  20045. this.specularMap = source.specularMap;
  20046. this.alphaMap = source.alphaMap;
  20047. this.envMap = source.envMap;
  20048. this.combine = source.combine;
  20049. this.reflectivity = source.reflectivity;
  20050. this.refractionRatio = source.refractionRatio;
  20051. this.wireframe = source.wireframe;
  20052. this.wireframeLinewidth = source.wireframeLinewidth;
  20053. this.wireframeLinecap = source.wireframeLinecap;
  20054. this.wireframeLinejoin = source.wireframeLinejoin;
  20055. this.skinning = source.skinning;
  20056. this.morphTargets = source.morphTargets;
  20057. this.morphNormals = source.morphNormals;
  20058. this.flatShading = source.flatShading;
  20059. return this;
  20060. };
  20061. return MeshPhongMaterial;
  20062. }(Material);
  20063. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20064. /**
  20065. * parameters = {
  20066. * color: <hex>,
  20067. *
  20068. * map: new THREE.Texture( <Image> ),
  20069. * gradientMap: new THREE.Texture( <Image> ),
  20070. *
  20071. * lightMap: new THREE.Texture( <Image> ),
  20072. * lightMapIntensity: <float>
  20073. *
  20074. * aoMap: new THREE.Texture( <Image> ),
  20075. * aoMapIntensity: <float>
  20076. *
  20077. * emissive: <hex>,
  20078. * emissiveIntensity: <float>
  20079. * emissiveMap: new THREE.Texture( <Image> ),
  20080. *
  20081. * bumpMap: new THREE.Texture( <Image> ),
  20082. * bumpScale: <float>,
  20083. *
  20084. * normalMap: new THREE.Texture( <Image> ),
  20085. * normalMapType: THREE.TangentSpaceNormalMap,
  20086. * normalScale: <Vector2>,
  20087. *
  20088. * displacementMap: new THREE.Texture( <Image> ),
  20089. * displacementScale: <float>,
  20090. * displacementBias: <float>,
  20091. *
  20092. * alphaMap: new THREE.Texture( <Image> ),
  20093. *
  20094. * wireframe: <boolean>,
  20095. * wireframeLinewidth: <float>,
  20096. *
  20097. * skinning: <bool>,
  20098. * morphTargets: <bool>,
  20099. * morphNormals: <bool>
  20100. * }
  20101. */
  20102. var MeshToonMaterial = /*#__PURE__*/function (_Material) {
  20103. _inheritsLoose(MeshToonMaterial, _Material);
  20104. function MeshToonMaterial(parameters) {
  20105. var _this;
  20106. _this = _Material.call(this) || this;
  20107. _this.defines = {
  20108. 'TOON': ''
  20109. };
  20110. _this.type = 'MeshToonMaterial';
  20111. _this.color = new Color(0xffffff);
  20112. _this.map = null;
  20113. _this.gradientMap = null;
  20114. _this.lightMap = null;
  20115. _this.lightMapIntensity = 1.0;
  20116. _this.aoMap = null;
  20117. _this.aoMapIntensity = 1.0;
  20118. _this.emissive = new Color(0x000000);
  20119. _this.emissiveIntensity = 1.0;
  20120. _this.emissiveMap = null;
  20121. _this.bumpMap = null;
  20122. _this.bumpScale = 1;
  20123. _this.normalMap = null;
  20124. _this.normalMapType = TangentSpaceNormalMap;
  20125. _this.normalScale = new Vector2(1, 1);
  20126. _this.displacementMap = null;
  20127. _this.displacementScale = 1;
  20128. _this.displacementBias = 0;
  20129. _this.alphaMap = null;
  20130. _this.wireframe = false;
  20131. _this.wireframeLinewidth = 1;
  20132. _this.wireframeLinecap = 'round';
  20133. _this.wireframeLinejoin = 'round';
  20134. _this.skinning = false;
  20135. _this.morphTargets = false;
  20136. _this.morphNormals = false;
  20137. _this.setValues(parameters);
  20138. return _this;
  20139. }
  20140. var _proto = MeshToonMaterial.prototype;
  20141. _proto.copy = function copy(source) {
  20142. _Material.prototype.copy.call(this, source);
  20143. this.color.copy(source.color);
  20144. this.map = source.map;
  20145. this.gradientMap = source.gradientMap;
  20146. this.lightMap = source.lightMap;
  20147. this.lightMapIntensity = source.lightMapIntensity;
  20148. this.aoMap = source.aoMap;
  20149. this.aoMapIntensity = source.aoMapIntensity;
  20150. this.emissive.copy(source.emissive);
  20151. this.emissiveMap = source.emissiveMap;
  20152. this.emissiveIntensity = source.emissiveIntensity;
  20153. this.bumpMap = source.bumpMap;
  20154. this.bumpScale = source.bumpScale;
  20155. this.normalMap = source.normalMap;
  20156. this.normalMapType = source.normalMapType;
  20157. this.normalScale.copy(source.normalScale);
  20158. this.displacementMap = source.displacementMap;
  20159. this.displacementScale = source.displacementScale;
  20160. this.displacementBias = source.displacementBias;
  20161. this.alphaMap = source.alphaMap;
  20162. this.wireframe = source.wireframe;
  20163. this.wireframeLinewidth = source.wireframeLinewidth;
  20164. this.wireframeLinecap = source.wireframeLinecap;
  20165. this.wireframeLinejoin = source.wireframeLinejoin;
  20166. this.skinning = source.skinning;
  20167. this.morphTargets = source.morphTargets;
  20168. this.morphNormals = source.morphNormals;
  20169. return this;
  20170. };
  20171. return MeshToonMaterial;
  20172. }(Material);
  20173. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20174. /**
  20175. * parameters = {
  20176. * opacity: <float>,
  20177. *
  20178. * bumpMap: new THREE.Texture( <Image> ),
  20179. * bumpScale: <float>,
  20180. *
  20181. * normalMap: new THREE.Texture( <Image> ),
  20182. * normalMapType: THREE.TangentSpaceNormalMap,
  20183. * normalScale: <Vector2>,
  20184. *
  20185. * displacementMap: new THREE.Texture( <Image> ),
  20186. * displacementScale: <float>,
  20187. * displacementBias: <float>,
  20188. *
  20189. * wireframe: <boolean>,
  20190. * wireframeLinewidth: <float>
  20191. *
  20192. * skinning: <bool>,
  20193. * morphTargets: <bool>,
  20194. * morphNormals: <bool>,
  20195. *
  20196. * flatShading: <bool>
  20197. * }
  20198. */
  20199. var MeshNormalMaterial = /*#__PURE__*/function (_Material) {
  20200. _inheritsLoose(MeshNormalMaterial, _Material);
  20201. function MeshNormalMaterial(parameters) {
  20202. var _this;
  20203. _this = _Material.call(this) || this;
  20204. _this.type = 'MeshNormalMaterial';
  20205. _this.bumpMap = null;
  20206. _this.bumpScale = 1;
  20207. _this.normalMap = null;
  20208. _this.normalMapType = TangentSpaceNormalMap;
  20209. _this.normalScale = new Vector2(1, 1);
  20210. _this.displacementMap = null;
  20211. _this.displacementScale = 1;
  20212. _this.displacementBias = 0;
  20213. _this.wireframe = false;
  20214. _this.wireframeLinewidth = 1;
  20215. _this.fog = false;
  20216. _this.skinning = false;
  20217. _this.morphTargets = false;
  20218. _this.morphNormals = false;
  20219. _this.flatShading = false;
  20220. _this.setValues(parameters);
  20221. return _this;
  20222. }
  20223. var _proto = MeshNormalMaterial.prototype;
  20224. _proto.copy = function copy(source) {
  20225. _Material.prototype.copy.call(this, source);
  20226. this.bumpMap = source.bumpMap;
  20227. this.bumpScale = source.bumpScale;
  20228. this.normalMap = source.normalMap;
  20229. this.normalMapType = source.normalMapType;
  20230. this.normalScale.copy(source.normalScale);
  20231. this.displacementMap = source.displacementMap;
  20232. this.displacementScale = source.displacementScale;
  20233. this.displacementBias = source.displacementBias;
  20234. this.wireframe = source.wireframe;
  20235. this.wireframeLinewidth = source.wireframeLinewidth;
  20236. this.skinning = source.skinning;
  20237. this.morphTargets = source.morphTargets;
  20238. this.morphNormals = source.morphNormals;
  20239. this.flatShading = source.flatShading;
  20240. return this;
  20241. };
  20242. return MeshNormalMaterial;
  20243. }(Material);
  20244. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20245. /**
  20246. * parameters = {
  20247. * color: <hex>,
  20248. * opacity: <float>,
  20249. *
  20250. * map: new THREE.Texture( <Image> ),
  20251. *
  20252. * lightMap: new THREE.Texture( <Image> ),
  20253. * lightMapIntensity: <float>
  20254. *
  20255. * aoMap: new THREE.Texture( <Image> ),
  20256. * aoMapIntensity: <float>
  20257. *
  20258. * emissive: <hex>,
  20259. * emissiveIntensity: <float>
  20260. * emissiveMap: new THREE.Texture( <Image> ),
  20261. *
  20262. * specularMap: new THREE.Texture( <Image> ),
  20263. *
  20264. * alphaMap: new THREE.Texture( <Image> ),
  20265. *
  20266. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20267. * combine: THREE.Multiply,
  20268. * reflectivity: <float>,
  20269. * refractionRatio: <float>,
  20270. *
  20271. * wireframe: <boolean>,
  20272. * wireframeLinewidth: <float>,
  20273. *
  20274. * skinning: <bool>,
  20275. * morphTargets: <bool>,
  20276. * morphNormals: <bool>
  20277. * }
  20278. */
  20279. var MeshLambertMaterial = /*#__PURE__*/function (_Material) {
  20280. _inheritsLoose(MeshLambertMaterial, _Material);
  20281. function MeshLambertMaterial(parameters) {
  20282. var _this;
  20283. _this = _Material.call(this) || this;
  20284. _this.type = 'MeshLambertMaterial';
  20285. _this.color = new Color(0xffffff); // diffuse
  20286. _this.map = null;
  20287. _this.lightMap = null;
  20288. _this.lightMapIntensity = 1.0;
  20289. _this.aoMap = null;
  20290. _this.aoMapIntensity = 1.0;
  20291. _this.emissive = new Color(0x000000);
  20292. _this.emissiveIntensity = 1.0;
  20293. _this.emissiveMap = null;
  20294. _this.specularMap = null;
  20295. _this.alphaMap = null;
  20296. _this.envMap = null;
  20297. _this.combine = MultiplyOperation;
  20298. _this.reflectivity = 1;
  20299. _this.refractionRatio = 0.98;
  20300. _this.wireframe = false;
  20301. _this.wireframeLinewidth = 1;
  20302. _this.wireframeLinecap = 'round';
  20303. _this.wireframeLinejoin = 'round';
  20304. _this.skinning = false;
  20305. _this.morphTargets = false;
  20306. _this.morphNormals = false;
  20307. _this.setValues(parameters);
  20308. return _this;
  20309. }
  20310. var _proto = MeshLambertMaterial.prototype;
  20311. _proto.copy = function copy(source) {
  20312. _Material.prototype.copy.call(this, source);
  20313. this.color.copy(source.color);
  20314. this.map = source.map;
  20315. this.lightMap = source.lightMap;
  20316. this.lightMapIntensity = source.lightMapIntensity;
  20317. this.aoMap = source.aoMap;
  20318. this.aoMapIntensity = source.aoMapIntensity;
  20319. this.emissive.copy(source.emissive);
  20320. this.emissiveMap = source.emissiveMap;
  20321. this.emissiveIntensity = source.emissiveIntensity;
  20322. this.specularMap = source.specularMap;
  20323. this.alphaMap = source.alphaMap;
  20324. this.envMap = source.envMap;
  20325. this.combine = source.combine;
  20326. this.reflectivity = source.reflectivity;
  20327. this.refractionRatio = source.refractionRatio;
  20328. this.wireframe = source.wireframe;
  20329. this.wireframeLinewidth = source.wireframeLinewidth;
  20330. this.wireframeLinecap = source.wireframeLinecap;
  20331. this.wireframeLinejoin = source.wireframeLinejoin;
  20332. this.skinning = source.skinning;
  20333. this.morphTargets = source.morphTargets;
  20334. this.morphNormals = source.morphNormals;
  20335. return this;
  20336. };
  20337. return MeshLambertMaterial;
  20338. }(Material);
  20339. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20340. /**
  20341. * parameters = {
  20342. * color: <hex>,
  20343. * opacity: <float>,
  20344. *
  20345. * matcap: new THREE.Texture( <Image> ),
  20346. *
  20347. * map: new THREE.Texture( <Image> ),
  20348. *
  20349. * bumpMap: new THREE.Texture( <Image> ),
  20350. * bumpScale: <float>,
  20351. *
  20352. * normalMap: new THREE.Texture( <Image> ),
  20353. * normalMapType: THREE.TangentSpaceNormalMap,
  20354. * normalScale: <Vector2>,
  20355. *
  20356. * displacementMap: new THREE.Texture( <Image> ),
  20357. * displacementScale: <float>,
  20358. * displacementBias: <float>,
  20359. *
  20360. * alphaMap: new THREE.Texture( <Image> ),
  20361. *
  20362. * skinning: <bool>,
  20363. * morphTargets: <bool>,
  20364. * morphNormals: <bool>
  20365. *
  20366. * flatShading: <bool>
  20367. * }
  20368. */
  20369. var MeshMatcapMaterial = /*#__PURE__*/function (_Material) {
  20370. _inheritsLoose(MeshMatcapMaterial, _Material);
  20371. function MeshMatcapMaterial(parameters) {
  20372. var _this;
  20373. _this = _Material.call(this) || this;
  20374. _this.defines = {
  20375. 'MATCAP': ''
  20376. };
  20377. _this.type = 'MeshMatcapMaterial';
  20378. _this.color = new Color(0xffffff); // diffuse
  20379. _this.matcap = null;
  20380. _this.map = null;
  20381. _this.bumpMap = null;
  20382. _this.bumpScale = 1;
  20383. _this.normalMap = null;
  20384. _this.normalMapType = TangentSpaceNormalMap;
  20385. _this.normalScale = new Vector2(1, 1);
  20386. _this.displacementMap = null;
  20387. _this.displacementScale = 1;
  20388. _this.displacementBias = 0;
  20389. _this.alphaMap = null;
  20390. _this.skinning = false;
  20391. _this.morphTargets = false;
  20392. _this.morphNormals = false;
  20393. _this.flatShading = false;
  20394. _this.setValues(parameters);
  20395. return _this;
  20396. }
  20397. var _proto = MeshMatcapMaterial.prototype;
  20398. _proto.copy = function copy(source) {
  20399. _Material.prototype.copy.call(this, source);
  20400. this.defines = {
  20401. 'MATCAP': ''
  20402. };
  20403. this.color.copy(source.color);
  20404. this.matcap = source.matcap;
  20405. this.map = source.map;
  20406. this.bumpMap = source.bumpMap;
  20407. this.bumpScale = source.bumpScale;
  20408. this.normalMap = source.normalMap;
  20409. this.normalMapType = source.normalMapType;
  20410. this.normalScale.copy(source.normalScale);
  20411. this.displacementMap = source.displacementMap;
  20412. this.displacementScale = source.displacementScale;
  20413. this.displacementBias = source.displacementBias;
  20414. this.alphaMap = source.alphaMap;
  20415. this.skinning = source.skinning;
  20416. this.morphTargets = source.morphTargets;
  20417. this.morphNormals = source.morphNormals;
  20418. this.flatShading = source.flatShading;
  20419. return this;
  20420. };
  20421. return MeshMatcapMaterial;
  20422. }(Material);
  20423. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20424. /**
  20425. * parameters = {
  20426. * color: <hex>,
  20427. * opacity: <float>,
  20428. *
  20429. * linewidth: <float>,
  20430. *
  20431. * scale: <float>,
  20432. * dashSize: <float>,
  20433. * gapSize: <float>
  20434. * }
  20435. */
  20436. var LineDashedMaterial = /*#__PURE__*/function (_LineBasicMaterial) {
  20437. _inheritsLoose(LineDashedMaterial, _LineBasicMaterial);
  20438. function LineDashedMaterial(parameters) {
  20439. var _this;
  20440. _this = _LineBasicMaterial.call(this) || this;
  20441. _this.type = 'LineDashedMaterial';
  20442. _this.scale = 1;
  20443. _this.dashSize = 3;
  20444. _this.gapSize = 1;
  20445. _this.setValues(parameters);
  20446. return _this;
  20447. }
  20448. var _proto = LineDashedMaterial.prototype;
  20449. _proto.copy = function copy(source) {
  20450. _LineBasicMaterial.prototype.copy.call(this, source);
  20451. this.scale = source.scale;
  20452. this.dashSize = source.dashSize;
  20453. this.gapSize = source.gapSize;
  20454. return this;
  20455. };
  20456. return LineDashedMaterial;
  20457. }(LineBasicMaterial);
  20458. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20459. var Materials = /*#__PURE__*/Object.freeze({
  20460. __proto__: null,
  20461. ShadowMaterial: ShadowMaterial,
  20462. SpriteMaterial: SpriteMaterial,
  20463. RawShaderMaterial: RawShaderMaterial,
  20464. ShaderMaterial: ShaderMaterial,
  20465. PointsMaterial: PointsMaterial,
  20466. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20467. MeshStandardMaterial: MeshStandardMaterial,
  20468. MeshPhongMaterial: MeshPhongMaterial,
  20469. MeshToonMaterial: MeshToonMaterial,
  20470. MeshNormalMaterial: MeshNormalMaterial,
  20471. MeshLambertMaterial: MeshLambertMaterial,
  20472. MeshDepthMaterial: MeshDepthMaterial,
  20473. MeshDistanceMaterial: MeshDistanceMaterial,
  20474. MeshBasicMaterial: MeshBasicMaterial,
  20475. MeshMatcapMaterial: MeshMatcapMaterial,
  20476. LineDashedMaterial: LineDashedMaterial,
  20477. LineBasicMaterial: LineBasicMaterial,
  20478. Material: Material
  20479. });
  20480. var AnimationUtils = {
  20481. // same as Array.prototype.slice, but also works on typed arrays
  20482. arraySlice: function arraySlice(array, from, to) {
  20483. if (AnimationUtils.isTypedArray(array)) {
  20484. // in ios9 array.subarray(from, undefined) will return empty array
  20485. // but array.subarray(from) or array.subarray(from, len) is correct
  20486. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20487. }
  20488. return array.slice(from, to);
  20489. },
  20490. // converts an array to a specific type
  20491. convertArray: function convertArray(array, type, forceClone) {
  20492. if (!array || // let 'undefined' and 'null' pass
  20493. !forceClone && array.constructor === type) return array;
  20494. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20495. return new type(array); // create typed array
  20496. }
  20497. return Array.prototype.slice.call(array); // create Array
  20498. },
  20499. isTypedArray: function isTypedArray(object) {
  20500. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20501. },
  20502. // returns an array by which times and values can be sorted
  20503. getKeyframeOrder: function getKeyframeOrder(times) {
  20504. function compareTime(i, j) {
  20505. return times[i] - times[j];
  20506. }
  20507. var n = times.length;
  20508. var result = new Array(n);
  20509. for (var i = 0; i !== n; ++i) {
  20510. result[i] = i;
  20511. }
  20512. result.sort(compareTime);
  20513. return result;
  20514. },
  20515. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20516. sortedArray: function sortedArray(values, stride, order) {
  20517. var nValues = values.length;
  20518. var result = new values.constructor(nValues);
  20519. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20520. var srcOffset = order[i] * stride;
  20521. for (var j = 0; j !== stride; ++j) {
  20522. result[dstOffset++] = values[srcOffset + j];
  20523. }
  20524. }
  20525. return result;
  20526. },
  20527. // function for parsing AOS keyframe formats
  20528. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20529. var i = 1,
  20530. key = jsonKeys[0];
  20531. while (key !== undefined && key[valuePropertyName] === undefined) {
  20532. key = jsonKeys[i++];
  20533. }
  20534. if (key === undefined) return; // no data
  20535. var value = key[valuePropertyName];
  20536. if (value === undefined) return; // no data
  20537. if (Array.isArray(value)) {
  20538. do {
  20539. value = key[valuePropertyName];
  20540. if (value !== undefined) {
  20541. times.push(key.time);
  20542. values.push.apply(values, value); // push all elements
  20543. }
  20544. key = jsonKeys[i++];
  20545. } while (key !== undefined);
  20546. } else if (value.toArray !== undefined) {
  20547. // ...assume THREE.Math-ish
  20548. do {
  20549. value = key[valuePropertyName];
  20550. if (value !== undefined) {
  20551. times.push(key.time);
  20552. value.toArray(values, values.length);
  20553. }
  20554. key = jsonKeys[i++];
  20555. } while (key !== undefined);
  20556. } else {
  20557. // otherwise push as-is
  20558. do {
  20559. value = key[valuePropertyName];
  20560. if (value !== undefined) {
  20561. times.push(key.time);
  20562. values.push(value);
  20563. }
  20564. key = jsonKeys[i++];
  20565. } while (key !== undefined);
  20566. }
  20567. },
  20568. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20569. if (fps === void 0) {
  20570. fps = 30;
  20571. }
  20572. var clip = sourceClip.clone();
  20573. clip.name = name;
  20574. var tracks = [];
  20575. for (var i = 0; i < clip.tracks.length; ++i) {
  20576. var track = clip.tracks[i];
  20577. var valueSize = track.getValueSize();
  20578. var times = [];
  20579. var values = [];
  20580. for (var j = 0; j < track.times.length; ++j) {
  20581. var frame = track.times[j] * fps;
  20582. if (frame < startFrame || frame >= endFrame) continue;
  20583. times.push(track.times[j]);
  20584. for (var k = 0; k < valueSize; ++k) {
  20585. values.push(track.values[j * valueSize + k]);
  20586. }
  20587. }
  20588. if (times.length === 0) continue;
  20589. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20590. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20591. tracks.push(track);
  20592. }
  20593. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20594. var minStartTime = Infinity;
  20595. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20596. if (minStartTime > clip.tracks[_i].times[0]) {
  20597. minStartTime = clip.tracks[_i].times[0];
  20598. }
  20599. } // shift all tracks such that clip begins at t=0
  20600. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20601. clip.tracks[_i2].shift(-1 * minStartTime);
  20602. }
  20603. clip.resetDuration();
  20604. return clip;
  20605. },
  20606. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20607. if (referenceFrame === void 0) {
  20608. referenceFrame = 0;
  20609. }
  20610. if (referenceClip === void 0) {
  20611. referenceClip = targetClip;
  20612. }
  20613. if (fps === void 0) {
  20614. fps = 30;
  20615. }
  20616. if (fps <= 0) fps = 30;
  20617. var numTracks = referenceClip.tracks.length;
  20618. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20619. var _loop = function _loop(i) {
  20620. var referenceTrack = referenceClip.tracks[i];
  20621. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20622. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20623. var targetTrack = targetClip.tracks.find(function (track) {
  20624. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20625. });
  20626. if (targetTrack === undefined) return "continue";
  20627. var referenceOffset = 0;
  20628. var referenceValueSize = referenceTrack.getValueSize();
  20629. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20630. referenceOffset = referenceValueSize / 3;
  20631. }
  20632. var targetOffset = 0;
  20633. var targetValueSize = targetTrack.getValueSize();
  20634. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20635. targetOffset = targetValueSize / 3;
  20636. }
  20637. var lastIndex = referenceTrack.times.length - 1;
  20638. var referenceValue = void 0; // Find the value to subtract out of the track
  20639. if (referenceTime <= referenceTrack.times[0]) {
  20640. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20641. var startIndex = referenceOffset;
  20642. var endIndex = referenceValueSize - referenceOffset;
  20643. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20644. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20645. // Reference frame is after the last keyframe, so just use the last keyframe
  20646. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20647. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20648. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20649. } else {
  20650. // Interpolate to the reference value
  20651. var interpolant = referenceTrack.createInterpolant();
  20652. var _startIndex2 = referenceOffset;
  20653. var _endIndex2 = referenceValueSize - referenceOffset;
  20654. interpolant.evaluate(referenceTime);
  20655. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20656. } // Conjugate the quaternion
  20657. if (referenceTrackType === 'quaternion') {
  20658. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20659. referenceQuat.toArray(referenceValue);
  20660. } // Subtract the reference value from all of the track values
  20661. var numTimes = targetTrack.times.length;
  20662. for (var j = 0; j < numTimes; ++j) {
  20663. var valueStart = j * targetValueSize + targetOffset;
  20664. if (referenceTrackType === 'quaternion') {
  20665. // Multiply the conjugate for quaternion track types
  20666. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20667. } else {
  20668. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20669. for (var k = 0; k < valueEnd; ++k) {
  20670. targetTrack.values[valueStart + k] -= referenceValue[k];
  20671. }
  20672. }
  20673. }
  20674. };
  20675. for (var i = 0; i < numTracks; ++i) {
  20676. var _ret = _loop(i);
  20677. if (_ret === "continue") continue;
  20678. }
  20679. targetClip.blendMode = AdditiveAnimationBlendMode;
  20680. return targetClip;
  20681. }
  20682. };
  20683. /**
  20684. * Abstract base class of interpolants over parametric samples.
  20685. *
  20686. * The parameter domain is one dimensional, typically the time or a path
  20687. * along a curve defined by the data.
  20688. *
  20689. * The sample values can have any dimensionality and derived classes may
  20690. * apply special interpretations to the data.
  20691. *
  20692. * This class provides the interval seek in a Template Method, deferring
  20693. * the actual interpolation to derived classes.
  20694. *
  20695. * Time complexity is O(1) for linear access crossing at most two points
  20696. * and O(log N) for random access, where N is the number of positions.
  20697. *
  20698. * References:
  20699. *
  20700. * http://www.oodesign.com/template-method-pattern.html
  20701. *
  20702. */
  20703. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20704. this.parameterPositions = parameterPositions;
  20705. this._cachedIndex = 0;
  20706. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20707. this.sampleValues = sampleValues;
  20708. this.valueSize = sampleSize;
  20709. }
  20710. Object.assign(Interpolant.prototype, {
  20711. evaluate: function evaluate(t) {
  20712. var pp = this.parameterPositions;
  20713. var i1 = this._cachedIndex,
  20714. t1 = pp[i1],
  20715. t0 = pp[i1 - 1];
  20716. validate_interval: {
  20717. seek: {
  20718. var right;
  20719. linear_scan: {
  20720. //- See http://jsperf.com/comparison-to-undefined/3
  20721. //- slower code:
  20722. //-
  20723. //- if ( t >= t1 || t1 === undefined ) {
  20724. forward_scan: if (!(t < t1)) {
  20725. for (var giveUpAt = i1 + 2;;) {
  20726. if (t1 === undefined) {
  20727. if (t < t0) break forward_scan; // after end
  20728. i1 = pp.length;
  20729. this._cachedIndex = i1;
  20730. return this.afterEnd_(i1 - 1, t, t0);
  20731. }
  20732. if (i1 === giveUpAt) break; // this loop
  20733. t0 = t1;
  20734. t1 = pp[++i1];
  20735. if (t < t1) {
  20736. // we have arrived at the sought interval
  20737. break seek;
  20738. }
  20739. } // prepare binary search on the right side of the index
  20740. right = pp.length;
  20741. break linear_scan;
  20742. } //- slower code:
  20743. //- if ( t < t0 || t0 === undefined ) {
  20744. if (!(t >= t0)) {
  20745. // looping?
  20746. var t1global = pp[1];
  20747. if (t < t1global) {
  20748. i1 = 2; // + 1, using the scan for the details
  20749. t0 = t1global;
  20750. } // linear reverse scan
  20751. for (var _giveUpAt = i1 - 2;;) {
  20752. if (t0 === undefined) {
  20753. // before start
  20754. this._cachedIndex = 0;
  20755. return this.beforeStart_(0, t, t1);
  20756. }
  20757. if (i1 === _giveUpAt) break; // this loop
  20758. t1 = t0;
  20759. t0 = pp[--i1 - 1];
  20760. if (t >= t0) {
  20761. // we have arrived at the sought interval
  20762. break seek;
  20763. }
  20764. } // prepare binary search on the left side of the index
  20765. right = i1;
  20766. i1 = 0;
  20767. break linear_scan;
  20768. } // the interval is valid
  20769. break validate_interval;
  20770. } // linear scan
  20771. // binary search
  20772. while (i1 < right) {
  20773. var mid = i1 + right >>> 1;
  20774. if (t < pp[mid]) {
  20775. right = mid;
  20776. } else {
  20777. i1 = mid + 1;
  20778. }
  20779. }
  20780. t1 = pp[i1];
  20781. t0 = pp[i1 - 1]; // check boundary cases, again
  20782. if (t0 === undefined) {
  20783. this._cachedIndex = 0;
  20784. return this.beforeStart_(0, t, t1);
  20785. }
  20786. if (t1 === undefined) {
  20787. i1 = pp.length;
  20788. this._cachedIndex = i1;
  20789. return this.afterEnd_(i1 - 1, t0, t);
  20790. }
  20791. } // seek
  20792. this._cachedIndex = i1;
  20793. this.intervalChanged_(i1, t0, t1);
  20794. } // validate_interval
  20795. return this.interpolate_(i1, t0, t, t1);
  20796. },
  20797. settings: null,
  20798. // optional, subclass-specific settings structure
  20799. // Note: The indirection allows central control of many interpolants.
  20800. // --- Protected interface
  20801. DefaultSettings_: {},
  20802. getSettings_: function getSettings_() {
  20803. return this.settings || this.DefaultSettings_;
  20804. },
  20805. copySampleValue_: function copySampleValue_(index) {
  20806. // copies a sample value to the result buffer
  20807. var result = this.resultBuffer,
  20808. values = this.sampleValues,
  20809. stride = this.valueSize,
  20810. offset = index * stride;
  20811. for (var i = 0; i !== stride; ++i) {
  20812. result[i] = values[offset + i];
  20813. }
  20814. return result;
  20815. },
  20816. // Template methods for derived classes:
  20817. interpolate_: function interpolate_()
  20818. /* i1, t0, t, t1 */
  20819. {
  20820. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20821. },
  20822. intervalChanged_: function intervalChanged_()
  20823. /* i1, t0, t1 */
  20824. {// empty
  20825. }
  20826. }); // DECLARE ALIAS AFTER assign prototype
  20827. Object.assign(Interpolant.prototype, {
  20828. //( 0, t, t0 ), returns this.resultBuffer
  20829. beforeStart_: Interpolant.prototype.copySampleValue_,
  20830. //( N-1, tN-1, t ), returns this.resultBuffer
  20831. afterEnd_: Interpolant.prototype.copySampleValue_
  20832. });
  20833. /**
  20834. * Fast and simple cubic spline interpolant.
  20835. *
  20836. * It was derived from a Hermitian construction setting the first derivative
  20837. * at each sample position to the linear slope between neighboring positions
  20838. * over their parameter interval.
  20839. */
  20840. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20841. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20842. this._weightPrev = -0;
  20843. this._offsetPrev = -0;
  20844. this._weightNext = -0;
  20845. this._offsetNext = -0;
  20846. }
  20847. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20848. constructor: CubicInterpolant,
  20849. DefaultSettings_: {
  20850. endingStart: ZeroCurvatureEnding,
  20851. endingEnd: ZeroCurvatureEnding
  20852. },
  20853. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20854. var pp = this.parameterPositions;
  20855. var iPrev = i1 - 2,
  20856. iNext = i1 + 1,
  20857. tPrev = pp[iPrev],
  20858. tNext = pp[iNext];
  20859. if (tPrev === undefined) {
  20860. switch (this.getSettings_().endingStart) {
  20861. case ZeroSlopeEnding:
  20862. // f'(t0) = 0
  20863. iPrev = i1;
  20864. tPrev = 2 * t0 - t1;
  20865. break;
  20866. case WrapAroundEnding:
  20867. // use the other end of the curve
  20868. iPrev = pp.length - 2;
  20869. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20870. break;
  20871. default:
  20872. // ZeroCurvatureEnding
  20873. // f''(t0) = 0 a.k.a. Natural Spline
  20874. iPrev = i1;
  20875. tPrev = t1;
  20876. }
  20877. }
  20878. if (tNext === undefined) {
  20879. switch (this.getSettings_().endingEnd) {
  20880. case ZeroSlopeEnding:
  20881. // f'(tN) = 0
  20882. iNext = i1;
  20883. tNext = 2 * t1 - t0;
  20884. break;
  20885. case WrapAroundEnding:
  20886. // use the other end of the curve
  20887. iNext = 1;
  20888. tNext = t1 + pp[1] - pp[0];
  20889. break;
  20890. default:
  20891. // ZeroCurvatureEnding
  20892. // f''(tN) = 0, a.k.a. Natural Spline
  20893. iNext = i1 - 1;
  20894. tNext = t0;
  20895. }
  20896. }
  20897. var halfDt = (t1 - t0) * 0.5,
  20898. stride = this.valueSize;
  20899. this._weightPrev = halfDt / (t0 - tPrev);
  20900. this._weightNext = halfDt / (tNext - t1);
  20901. this._offsetPrev = iPrev * stride;
  20902. this._offsetNext = iNext * stride;
  20903. },
  20904. interpolate_: function interpolate_(i1, t0, t, t1) {
  20905. var result = this.resultBuffer,
  20906. values = this.sampleValues,
  20907. stride = this.valueSize,
  20908. o1 = i1 * stride,
  20909. o0 = o1 - stride,
  20910. oP = this._offsetPrev,
  20911. oN = this._offsetNext,
  20912. wP = this._weightPrev,
  20913. wN = this._weightNext,
  20914. p = (t - t0) / (t1 - t0),
  20915. pp = p * p,
  20916. ppp = pp * p; // evaluate polynomials
  20917. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20918. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20919. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20920. var sN = wN * ppp - wN * pp; // combine data linearly
  20921. for (var i = 0; i !== stride; ++i) {
  20922. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20923. }
  20924. return result;
  20925. }
  20926. });
  20927. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20928. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20929. }
  20930. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20931. constructor: LinearInterpolant,
  20932. interpolate_: function interpolate_(i1, t0, t, t1) {
  20933. var result = this.resultBuffer,
  20934. values = this.sampleValues,
  20935. stride = this.valueSize,
  20936. offset1 = i1 * stride,
  20937. offset0 = offset1 - stride,
  20938. weight1 = (t - t0) / (t1 - t0),
  20939. weight0 = 1 - weight1;
  20940. for (var i = 0; i !== stride; ++i) {
  20941. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20942. }
  20943. return result;
  20944. }
  20945. });
  20946. /**
  20947. *
  20948. * Interpolant that evaluates to the sample value at the position preceeding
  20949. * the parameter.
  20950. */
  20951. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20952. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20953. }
  20954. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20955. constructor: DiscreteInterpolant,
  20956. interpolate_: function interpolate_(i1
  20957. /*, t0, t, t1 */
  20958. ) {
  20959. return this.copySampleValue_(i1 - 1);
  20960. }
  20961. });
  20962. var KeyframeTrack = /*#__PURE__*/function () {
  20963. function KeyframeTrack(name, times, values, interpolation) {
  20964. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20965. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20966. this.name = name;
  20967. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20968. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20969. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20970. } // Serialization (in static context, because of constructor invocation
  20971. // and automatic invocation of .toJSON):
  20972. KeyframeTrack.toJSON = function toJSON(track) {
  20973. var trackType = track.constructor;
  20974. var json; // derived classes can define a static toJSON method
  20975. if (trackType.toJSON !== undefined) {
  20976. json = trackType.toJSON(track);
  20977. } else {
  20978. // by default, we assume the data can be serialized as-is
  20979. json = {
  20980. 'name': track.name,
  20981. 'times': AnimationUtils.convertArray(track.times, Array),
  20982. 'values': AnimationUtils.convertArray(track.values, Array)
  20983. };
  20984. var interpolation = track.getInterpolation();
  20985. if (interpolation !== track.DefaultInterpolation) {
  20986. json.interpolation = interpolation;
  20987. }
  20988. }
  20989. json.type = track.ValueTypeName; // mandatory
  20990. return json;
  20991. };
  20992. var _proto = KeyframeTrack.prototype;
  20993. _proto.InterpolantFactoryMethodDiscrete = function InterpolantFactoryMethodDiscrete(result) {
  20994. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20995. };
  20996. _proto.InterpolantFactoryMethodLinear = function InterpolantFactoryMethodLinear(result) {
  20997. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20998. };
  20999. _proto.InterpolantFactoryMethodSmooth = function InterpolantFactoryMethodSmooth(result) {
  21000. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  21001. };
  21002. _proto.setInterpolation = function setInterpolation(interpolation) {
  21003. var factoryMethod;
  21004. switch (interpolation) {
  21005. case InterpolateDiscrete:
  21006. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21007. break;
  21008. case InterpolateLinear:
  21009. factoryMethod = this.InterpolantFactoryMethodLinear;
  21010. break;
  21011. case InterpolateSmooth:
  21012. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21013. break;
  21014. }
  21015. if (factoryMethod === undefined) {
  21016. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  21017. if (this.createInterpolant === undefined) {
  21018. // fall back to default, unless the default itself is messed up
  21019. if (interpolation !== this.DefaultInterpolation) {
  21020. this.setInterpolation(this.DefaultInterpolation);
  21021. } else {
  21022. throw new Error(message); // fatal, in this case
  21023. }
  21024. }
  21025. console.warn('THREE.KeyframeTrack:', message);
  21026. return this;
  21027. }
  21028. this.createInterpolant = factoryMethod;
  21029. return this;
  21030. };
  21031. _proto.getInterpolation = function getInterpolation() {
  21032. switch (this.createInterpolant) {
  21033. case this.InterpolantFactoryMethodDiscrete:
  21034. return InterpolateDiscrete;
  21035. case this.InterpolantFactoryMethodLinear:
  21036. return InterpolateLinear;
  21037. case this.InterpolantFactoryMethodSmooth:
  21038. return InterpolateSmooth;
  21039. }
  21040. };
  21041. _proto.getValueSize = function getValueSize() {
  21042. return this.values.length / this.times.length;
  21043. } // move all keyframes either forwards or backwards in time
  21044. ;
  21045. _proto.shift = function shift(timeOffset) {
  21046. if (timeOffset !== 0.0) {
  21047. var times = this.times;
  21048. for (var i = 0, n = times.length; i !== n; ++i) {
  21049. times[i] += timeOffset;
  21050. }
  21051. }
  21052. return this;
  21053. } // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21054. ;
  21055. _proto.scale = function scale(timeScale) {
  21056. if (timeScale !== 1.0) {
  21057. var times = this.times;
  21058. for (var i = 0, n = times.length; i !== n; ++i) {
  21059. times[i] *= timeScale;
  21060. }
  21061. }
  21062. return this;
  21063. } // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21064. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21065. ;
  21066. _proto.trim = function trim(startTime, endTime) {
  21067. var times = this.times,
  21068. nKeys = times.length;
  21069. var from = 0,
  21070. to = nKeys - 1;
  21071. while (from !== nKeys && times[from] < startTime) {
  21072. ++from;
  21073. }
  21074. while (to !== -1 && times[to] > endTime) {
  21075. --to;
  21076. }
  21077. ++to; // inclusive -> exclusive bound
  21078. if (from !== 0 || to !== nKeys) {
  21079. // empty tracks are forbidden, so keep at least one keyframe
  21080. if (from >= to) {
  21081. to = Math.max(to, 1);
  21082. from = to - 1;
  21083. }
  21084. var stride = this.getValueSize();
  21085. this.times = AnimationUtils.arraySlice(times, from, to);
  21086. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21087. }
  21088. return this;
  21089. } // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21090. ;
  21091. _proto.validate = function validate() {
  21092. var valid = true;
  21093. var valueSize = this.getValueSize();
  21094. if (valueSize - Math.floor(valueSize) !== 0) {
  21095. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21096. valid = false;
  21097. }
  21098. var times = this.times,
  21099. values = this.values,
  21100. nKeys = times.length;
  21101. if (nKeys === 0) {
  21102. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21103. valid = false;
  21104. }
  21105. var prevTime = null;
  21106. for (var i = 0; i !== nKeys; i++) {
  21107. var currTime = times[i];
  21108. if (typeof currTime === 'number' && isNaN(currTime)) {
  21109. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21110. valid = false;
  21111. break;
  21112. }
  21113. if (prevTime !== null && prevTime > currTime) {
  21114. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21115. valid = false;
  21116. break;
  21117. }
  21118. prevTime = currTime;
  21119. }
  21120. if (values !== undefined) {
  21121. if (AnimationUtils.isTypedArray(values)) {
  21122. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21123. var value = values[_i];
  21124. if (isNaN(value)) {
  21125. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21126. valid = false;
  21127. break;
  21128. }
  21129. }
  21130. }
  21131. }
  21132. return valid;
  21133. } // removes equivalent sequential keys as common in morph target sequences
  21134. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21135. ;
  21136. _proto.optimize = function optimize() {
  21137. // times or values may be shared with other tracks, so overwriting is unsafe
  21138. var times = AnimationUtils.arraySlice(this.times),
  21139. values = AnimationUtils.arraySlice(this.values),
  21140. stride = this.getValueSize(),
  21141. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21142. lastIndex = times.length - 1;
  21143. var writeIndex = 1;
  21144. for (var i = 1; i < lastIndex; ++i) {
  21145. var keep = false;
  21146. var time = times[i];
  21147. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21148. if (time !== timeNext && (i !== 1 || time !== times[0])) {
  21149. if (!smoothInterpolation) {
  21150. // remove unnecessary keyframes same as their neighbors
  21151. var offset = i * stride,
  21152. offsetP = offset - stride,
  21153. offsetN = offset + stride;
  21154. for (var j = 0; j !== stride; ++j) {
  21155. var value = values[offset + j];
  21156. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21157. keep = true;
  21158. break;
  21159. }
  21160. }
  21161. } else {
  21162. keep = true;
  21163. }
  21164. } // in-place compaction
  21165. if (keep) {
  21166. if (i !== writeIndex) {
  21167. times[writeIndex] = times[i];
  21168. var readOffset = i * stride,
  21169. writeOffset = writeIndex * stride;
  21170. for (var _j = 0; _j !== stride; ++_j) {
  21171. values[writeOffset + _j] = values[readOffset + _j];
  21172. }
  21173. }
  21174. ++writeIndex;
  21175. }
  21176. } // flush last keyframe (compaction looks ahead)
  21177. if (lastIndex > 0) {
  21178. times[writeIndex] = times[lastIndex];
  21179. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21180. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21181. }
  21182. ++writeIndex;
  21183. }
  21184. if (writeIndex !== times.length) {
  21185. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21186. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21187. } else {
  21188. this.times = times;
  21189. this.values = values;
  21190. }
  21191. return this;
  21192. };
  21193. _proto.clone = function clone() {
  21194. var times = AnimationUtils.arraySlice(this.times, 0);
  21195. var values = AnimationUtils.arraySlice(this.values, 0);
  21196. var TypedKeyframeTrack = this.constructor;
  21197. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21198. track.createInterpolant = this.createInterpolant;
  21199. return track;
  21200. };
  21201. return KeyframeTrack;
  21202. }();
  21203. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  21204. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  21205. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  21206. /**
  21207. * A Track of Boolean keyframe values.
  21208. */
  21209. var BooleanKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21210. _inheritsLoose(BooleanKeyframeTrack, _KeyframeTrack);
  21211. function BooleanKeyframeTrack() {
  21212. return _KeyframeTrack.apply(this, arguments) || this;
  21213. }
  21214. return BooleanKeyframeTrack;
  21215. }(KeyframeTrack);
  21216. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  21217. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  21218. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  21219. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  21220. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined; // Note: Actually this track could have a optimized / compressed
  21221. /**
  21222. * A Track of keyframe values that represent color.
  21223. */
  21224. var ColorKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21225. _inheritsLoose(ColorKeyframeTrack, _KeyframeTrack);
  21226. function ColorKeyframeTrack() {
  21227. return _KeyframeTrack.apply(this, arguments) || this;
  21228. }
  21229. return ColorKeyframeTrack;
  21230. }(KeyframeTrack);
  21231. ColorKeyframeTrack.prototype.ValueTypeName = 'color'; // ValueBufferType is inherited
  21232. /**
  21233. * A Track of numeric keyframe values.
  21234. */
  21235. var NumberKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21236. _inheritsLoose(NumberKeyframeTrack, _KeyframeTrack);
  21237. function NumberKeyframeTrack() {
  21238. return _KeyframeTrack.apply(this, arguments) || this;
  21239. }
  21240. return NumberKeyframeTrack;
  21241. }(KeyframeTrack);
  21242. NumberKeyframeTrack.prototype.ValueTypeName = 'number'; // ValueBufferType is inherited
  21243. /**
  21244. * Spherical linear unit quaternion interpolant.
  21245. */
  21246. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21247. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21248. }
  21249. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21250. constructor: QuaternionLinearInterpolant,
  21251. interpolate_: function interpolate_(i1, t0, t, t1) {
  21252. var result = this.resultBuffer,
  21253. values = this.sampleValues,
  21254. stride = this.valueSize,
  21255. alpha = (t - t0) / (t1 - t0);
  21256. var offset = i1 * stride;
  21257. for (var end = offset + stride; offset !== end; offset += 4) {
  21258. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21259. }
  21260. return result;
  21261. }
  21262. });
  21263. /**
  21264. * A Track of quaternion keyframe values.
  21265. */
  21266. var QuaternionKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21267. _inheritsLoose(QuaternionKeyframeTrack, _KeyframeTrack);
  21268. function QuaternionKeyframeTrack() {
  21269. return _KeyframeTrack.apply(this, arguments) || this;
  21270. }
  21271. var _proto = QuaternionKeyframeTrack.prototype;
  21272. _proto.InterpolantFactoryMethodLinear = function InterpolantFactoryMethodLinear(result) {
  21273. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21274. };
  21275. return QuaternionKeyframeTrack;
  21276. }(KeyframeTrack);
  21277. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion'; // ValueBufferType is inherited
  21278. QuaternionKeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  21279. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  21280. /**
  21281. * A Track that interpolates Strings
  21282. */
  21283. var StringKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21284. _inheritsLoose(StringKeyframeTrack, _KeyframeTrack);
  21285. function StringKeyframeTrack() {
  21286. return _KeyframeTrack.apply(this, arguments) || this;
  21287. }
  21288. return StringKeyframeTrack;
  21289. }(KeyframeTrack);
  21290. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  21291. StringKeyframeTrack.prototype.ValueBufferType = Array;
  21292. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  21293. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  21294. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  21295. /**
  21296. * A Track of vectored keyframe values.
  21297. */
  21298. var VectorKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21299. _inheritsLoose(VectorKeyframeTrack, _KeyframeTrack);
  21300. function VectorKeyframeTrack() {
  21301. return _KeyframeTrack.apply(this, arguments) || this;
  21302. }
  21303. return VectorKeyframeTrack;
  21304. }(KeyframeTrack);
  21305. VectorKeyframeTrack.prototype.ValueTypeName = 'vector'; // ValueBufferType is inherited
  21306. function AnimationClip(name, duration, tracks, blendMode) {
  21307. if (duration === void 0) {
  21308. duration = -1;
  21309. }
  21310. if (blendMode === void 0) {
  21311. blendMode = NormalAnimationBlendMode;
  21312. }
  21313. this.name = name;
  21314. this.tracks = tracks;
  21315. this.duration = duration;
  21316. this.blendMode = blendMode;
  21317. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21318. if (this.duration < 0) {
  21319. this.resetDuration();
  21320. }
  21321. }
  21322. function getTrackTypeForValueTypeName(typeName) {
  21323. switch (typeName.toLowerCase()) {
  21324. case 'scalar':
  21325. case 'double':
  21326. case 'float':
  21327. case 'number':
  21328. case 'integer':
  21329. return NumberKeyframeTrack;
  21330. case 'vector':
  21331. case 'vector2':
  21332. case 'vector3':
  21333. case 'vector4':
  21334. return VectorKeyframeTrack;
  21335. case 'color':
  21336. return ColorKeyframeTrack;
  21337. case 'quaternion':
  21338. return QuaternionKeyframeTrack;
  21339. case 'bool':
  21340. case 'boolean':
  21341. return BooleanKeyframeTrack;
  21342. case 'string':
  21343. return StringKeyframeTrack;
  21344. }
  21345. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21346. }
  21347. function parseKeyframeTrack(json) {
  21348. if (json.type === undefined) {
  21349. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21350. }
  21351. var trackType = getTrackTypeForValueTypeName(json.type);
  21352. if (json.times === undefined) {
  21353. var times = [],
  21354. values = [];
  21355. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21356. json.times = times;
  21357. json.values = values;
  21358. } // derived classes can define a static parse method
  21359. if (trackType.parse !== undefined) {
  21360. return trackType.parse(json);
  21361. } else {
  21362. // by default, we assume a constructor compatible with the base
  21363. return new trackType(json.name, json.times, json.values, json.interpolation);
  21364. }
  21365. }
  21366. Object.assign(AnimationClip, {
  21367. parse: function parse(json) {
  21368. var tracks = [],
  21369. jsonTracks = json.tracks,
  21370. frameTime = 1.0 / (json.fps || 1.0);
  21371. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21372. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21373. }
  21374. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21375. clip.uuid = json.uuid;
  21376. return clip;
  21377. },
  21378. toJSON: function toJSON(clip) {
  21379. var tracks = [],
  21380. clipTracks = clip.tracks;
  21381. var json = {
  21382. 'name': clip.name,
  21383. 'duration': clip.duration,
  21384. 'tracks': tracks,
  21385. 'uuid': clip.uuid,
  21386. 'blendMode': clip.blendMode
  21387. };
  21388. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21389. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21390. }
  21391. return json;
  21392. },
  21393. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21394. var numMorphTargets = morphTargetSequence.length;
  21395. var tracks = [];
  21396. for (var i = 0; i < numMorphTargets; i++) {
  21397. var times = [];
  21398. var values = [];
  21399. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21400. values.push(0, 1, 0);
  21401. var order = AnimationUtils.getKeyframeOrder(times);
  21402. times = AnimationUtils.sortedArray(times, 1, order);
  21403. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21404. // last frame as well for perfect loop.
  21405. if (!noLoop && times[0] === 0) {
  21406. times.push(numMorphTargets);
  21407. values.push(values[0]);
  21408. }
  21409. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21410. }
  21411. return new AnimationClip(name, -1, tracks);
  21412. },
  21413. findByName: function findByName(objectOrClipArray, name) {
  21414. var clipArray = objectOrClipArray;
  21415. if (!Array.isArray(objectOrClipArray)) {
  21416. var o = objectOrClipArray;
  21417. clipArray = o.geometry && o.geometry.animations || o.animations;
  21418. }
  21419. for (var i = 0; i < clipArray.length; i++) {
  21420. if (clipArray[i].name === name) {
  21421. return clipArray[i];
  21422. }
  21423. }
  21424. return null;
  21425. },
  21426. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21427. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21428. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21429. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21430. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21431. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21432. var morphTarget = morphTargets[i];
  21433. var parts = morphTarget.name.match(pattern);
  21434. if (parts && parts.length > 1) {
  21435. var name = parts[1];
  21436. var animationMorphTargets = animationToMorphTargets[name];
  21437. if (!animationMorphTargets) {
  21438. animationToMorphTargets[name] = animationMorphTargets = [];
  21439. }
  21440. animationMorphTargets.push(morphTarget);
  21441. }
  21442. }
  21443. var clips = [];
  21444. for (var _name in animationToMorphTargets) {
  21445. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21446. }
  21447. return clips;
  21448. },
  21449. // parse the animation.hierarchy format
  21450. parseAnimation: function parseAnimation(animation, bones) {
  21451. if (!animation) {
  21452. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21453. return null;
  21454. }
  21455. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21456. // only return track if there are actually keys.
  21457. if (animationKeys.length !== 0) {
  21458. var times = [];
  21459. var values = [];
  21460. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21461. if (times.length !== 0) {
  21462. destTracks.push(new trackType(trackName, times, values));
  21463. }
  21464. }
  21465. };
  21466. var tracks = [];
  21467. var clipName = animation.name || 'default';
  21468. var fps = animation.fps || 30;
  21469. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21470. var duration = animation.length || -1;
  21471. var hierarchyTracks = animation.hierarchy || [];
  21472. for (var h = 0; h < hierarchyTracks.length; h++) {
  21473. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21474. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21475. if (animationKeys[0].morphTargets) {
  21476. // figure out all morph targets used in this track
  21477. var morphTargetNames = {};
  21478. var k = void 0;
  21479. for (k = 0; k < animationKeys.length; k++) {
  21480. if (animationKeys[k].morphTargets) {
  21481. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21482. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21483. }
  21484. }
  21485. } // create a track for each morph target with all zero
  21486. // morphTargetInfluences except for the keys in which
  21487. // the morphTarget is named.
  21488. for (var morphTargetName in morphTargetNames) {
  21489. var times = [];
  21490. var values = [];
  21491. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21492. var animationKey = animationKeys[k];
  21493. times.push(animationKey.time);
  21494. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21495. }
  21496. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21497. }
  21498. duration = morphTargetNames.length * (fps || 1.0);
  21499. } else {
  21500. // ...assume skeletal animation
  21501. var boneName = '.bones[' + bones[h].name + ']';
  21502. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21503. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21504. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21505. }
  21506. }
  21507. if (tracks.length === 0) {
  21508. return null;
  21509. }
  21510. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21511. return clip;
  21512. }
  21513. });
  21514. Object.assign(AnimationClip.prototype, {
  21515. resetDuration: function resetDuration() {
  21516. var tracks = this.tracks;
  21517. var duration = 0;
  21518. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21519. var track = this.tracks[i];
  21520. duration = Math.max(duration, track.times[track.times.length - 1]);
  21521. }
  21522. this.duration = duration;
  21523. return this;
  21524. },
  21525. trim: function trim() {
  21526. for (var i = 0; i < this.tracks.length; i++) {
  21527. this.tracks[i].trim(0, this.duration);
  21528. }
  21529. return this;
  21530. },
  21531. validate: function validate() {
  21532. var valid = true;
  21533. for (var i = 0; i < this.tracks.length; i++) {
  21534. valid = valid && this.tracks[i].validate();
  21535. }
  21536. return valid;
  21537. },
  21538. optimize: function optimize() {
  21539. for (var i = 0; i < this.tracks.length; i++) {
  21540. this.tracks[i].optimize();
  21541. }
  21542. return this;
  21543. },
  21544. clone: function clone() {
  21545. var tracks = [];
  21546. for (var i = 0; i < this.tracks.length; i++) {
  21547. tracks.push(this.tracks[i].clone());
  21548. }
  21549. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21550. },
  21551. toJSON: function toJSON() {
  21552. return AnimationClip.toJSON(this);
  21553. }
  21554. });
  21555. var Cache = {
  21556. enabled: false,
  21557. files: {},
  21558. add: function add(key, file) {
  21559. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21560. this.files[key] = file;
  21561. },
  21562. get: function get(key) {
  21563. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21564. return this.files[key];
  21565. },
  21566. remove: function remove(key) {
  21567. delete this.files[key];
  21568. },
  21569. clear: function clear() {
  21570. this.files = {};
  21571. }
  21572. };
  21573. function LoadingManager(onLoad, onProgress, onError) {
  21574. var scope = this;
  21575. var isLoading = false;
  21576. var itemsLoaded = 0;
  21577. var itemsTotal = 0;
  21578. var urlModifier = undefined;
  21579. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21580. // in the constructor
  21581. this.onStart = undefined;
  21582. this.onLoad = onLoad;
  21583. this.onProgress = onProgress;
  21584. this.onError = onError;
  21585. this.itemStart = function (url) {
  21586. itemsTotal++;
  21587. if (isLoading === false) {
  21588. if (scope.onStart !== undefined) {
  21589. scope.onStart(url, itemsLoaded, itemsTotal);
  21590. }
  21591. }
  21592. isLoading = true;
  21593. };
  21594. this.itemEnd = function (url) {
  21595. itemsLoaded++;
  21596. if (scope.onProgress !== undefined) {
  21597. scope.onProgress(url, itemsLoaded, itemsTotal);
  21598. }
  21599. if (itemsLoaded === itemsTotal) {
  21600. isLoading = false;
  21601. if (scope.onLoad !== undefined) {
  21602. scope.onLoad();
  21603. }
  21604. }
  21605. };
  21606. this.itemError = function (url) {
  21607. if (scope.onError !== undefined) {
  21608. scope.onError(url);
  21609. }
  21610. };
  21611. this.resolveURL = function (url) {
  21612. if (urlModifier) {
  21613. return urlModifier(url);
  21614. }
  21615. return url;
  21616. };
  21617. this.setURLModifier = function (transform) {
  21618. urlModifier = transform;
  21619. return this;
  21620. };
  21621. this.addHandler = function (regex, loader) {
  21622. handlers.push(regex, loader);
  21623. return this;
  21624. };
  21625. this.removeHandler = function (regex) {
  21626. var index = handlers.indexOf(regex);
  21627. if (index !== -1) {
  21628. handlers.splice(index, 2);
  21629. }
  21630. return this;
  21631. };
  21632. this.getHandler = function (file) {
  21633. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21634. var regex = handlers[i];
  21635. var loader = handlers[i + 1];
  21636. if (regex.global) regex.lastIndex = 0; // see #17920
  21637. if (regex.test(file)) {
  21638. return loader;
  21639. }
  21640. }
  21641. return null;
  21642. };
  21643. }
  21644. var DefaultLoadingManager = new LoadingManager();
  21645. function Loader(manager) {
  21646. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21647. this.crossOrigin = 'anonymous';
  21648. this.withCredentials = false;
  21649. this.path = '';
  21650. this.resourcePath = '';
  21651. this.requestHeader = {};
  21652. }
  21653. Object.assign(Loader.prototype, {
  21654. load: function load()
  21655. /* url, onLoad, onProgress, onError */
  21656. {},
  21657. loadAsync: function loadAsync(url, onProgress) {
  21658. var scope = this;
  21659. return new Promise(function (resolve, reject) {
  21660. scope.load(url, resolve, onProgress, reject);
  21661. });
  21662. },
  21663. parse: function parse()
  21664. /* data */
  21665. {},
  21666. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21667. this.crossOrigin = crossOrigin;
  21668. return this;
  21669. },
  21670. setWithCredentials: function setWithCredentials(value) {
  21671. this.withCredentials = value;
  21672. return this;
  21673. },
  21674. setPath: function setPath(path) {
  21675. this.path = path;
  21676. return this;
  21677. },
  21678. setResourcePath: function setResourcePath(resourcePath) {
  21679. this.resourcePath = resourcePath;
  21680. return this;
  21681. },
  21682. setRequestHeader: function setRequestHeader(requestHeader) {
  21683. this.requestHeader = requestHeader;
  21684. return this;
  21685. }
  21686. });
  21687. var loading = {};
  21688. function FileLoader(manager) {
  21689. Loader.call(this, manager);
  21690. }
  21691. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21692. constructor: FileLoader,
  21693. load: function load(url, onLoad, onProgress, onError) {
  21694. if (url === undefined) url = '';
  21695. if (this.path !== undefined) url = this.path + url;
  21696. url = this.manager.resolveURL(url);
  21697. var scope = this;
  21698. var cached = Cache.get(url);
  21699. if (cached !== undefined) {
  21700. scope.manager.itemStart(url);
  21701. setTimeout(function () {
  21702. if (onLoad) onLoad(cached);
  21703. scope.manager.itemEnd(url);
  21704. }, 0);
  21705. return cached;
  21706. } // Check if request is duplicate
  21707. if (loading[url] !== undefined) {
  21708. loading[url].push({
  21709. onLoad: onLoad,
  21710. onProgress: onProgress,
  21711. onError: onError
  21712. });
  21713. return;
  21714. } // Check for data: URI
  21715. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21716. var dataUriRegexResult = url.match(dataUriRegex);
  21717. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21718. if (dataUriRegexResult) {
  21719. var mimeType = dataUriRegexResult[1];
  21720. var isBase64 = !!dataUriRegexResult[2];
  21721. var data = dataUriRegexResult[3];
  21722. data = decodeURIComponent(data);
  21723. if (isBase64) data = atob(data);
  21724. try {
  21725. var response;
  21726. var responseType = (this.responseType || '').toLowerCase();
  21727. switch (responseType) {
  21728. case 'arraybuffer':
  21729. case 'blob':
  21730. var view = new Uint8Array(data.length);
  21731. for (var i = 0; i < data.length; i++) {
  21732. view[i] = data.charCodeAt(i);
  21733. }
  21734. if (responseType === 'blob') {
  21735. response = new Blob([view.buffer], {
  21736. type: mimeType
  21737. });
  21738. } else {
  21739. response = view.buffer;
  21740. }
  21741. break;
  21742. case 'document':
  21743. var parser = new DOMParser();
  21744. response = parser.parseFromString(data, mimeType);
  21745. break;
  21746. case 'json':
  21747. response = JSON.parse(data);
  21748. break;
  21749. default:
  21750. // 'text' or other
  21751. response = data;
  21752. break;
  21753. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21754. setTimeout(function () {
  21755. if (onLoad) onLoad(response);
  21756. scope.manager.itemEnd(url);
  21757. }, 0);
  21758. } catch (error) {
  21759. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21760. setTimeout(function () {
  21761. if (onError) onError(error);
  21762. scope.manager.itemError(url);
  21763. scope.manager.itemEnd(url);
  21764. }, 0);
  21765. }
  21766. } else {
  21767. // Initialise array for duplicate requests
  21768. loading[url] = [];
  21769. loading[url].push({
  21770. onLoad: onLoad,
  21771. onProgress: onProgress,
  21772. onError: onError
  21773. });
  21774. request = new XMLHttpRequest();
  21775. request.open('GET', url, true);
  21776. request.addEventListener('load', function (event) {
  21777. var response = this.response;
  21778. var callbacks = loading[url];
  21779. delete loading[url];
  21780. if (this.status === 200 || this.status === 0) {
  21781. // Some browsers return HTTP Status 0 when using non-http protocol
  21782. // e.g. 'file://' or 'data://'. Handle as success.
  21783. 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
  21784. // error response bodies as proper responses to requests.
  21785. Cache.add(url, response);
  21786. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21787. var callback = callbacks[_i];
  21788. if (callback.onLoad) callback.onLoad(response);
  21789. }
  21790. scope.manager.itemEnd(url);
  21791. } else {
  21792. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21793. var _callback = callbacks[_i2];
  21794. if (_callback.onError) _callback.onError(event);
  21795. }
  21796. scope.manager.itemError(url);
  21797. scope.manager.itemEnd(url);
  21798. }
  21799. }, false);
  21800. request.addEventListener('progress', function (event) {
  21801. var callbacks = loading[url];
  21802. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21803. var callback = callbacks[_i3];
  21804. if (callback.onProgress) callback.onProgress(event);
  21805. }
  21806. }, false);
  21807. request.addEventListener('error', function (event) {
  21808. var callbacks = loading[url];
  21809. delete loading[url];
  21810. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21811. var callback = callbacks[_i4];
  21812. if (callback.onError) callback.onError(event);
  21813. }
  21814. scope.manager.itemError(url);
  21815. scope.manager.itemEnd(url);
  21816. }, false);
  21817. request.addEventListener('abort', function (event) {
  21818. var callbacks = loading[url];
  21819. delete loading[url];
  21820. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21821. var callback = callbacks[_i5];
  21822. if (callback.onError) callback.onError(event);
  21823. }
  21824. scope.manager.itemError(url);
  21825. scope.manager.itemEnd(url);
  21826. }, false);
  21827. if (this.responseType !== undefined) request.responseType = this.responseType;
  21828. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21829. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21830. for (var header in this.requestHeader) {
  21831. request.setRequestHeader(header, this.requestHeader[header]);
  21832. }
  21833. request.send(null);
  21834. }
  21835. scope.manager.itemStart(url);
  21836. return request;
  21837. },
  21838. setResponseType: function setResponseType(value) {
  21839. this.responseType = value;
  21840. return this;
  21841. },
  21842. setMimeType: function setMimeType(value) {
  21843. this.mimeType = value;
  21844. return this;
  21845. }
  21846. });
  21847. var AnimationLoader = /*#__PURE__*/function (_Loader) {
  21848. _inheritsLoose(AnimationLoader, _Loader);
  21849. function AnimationLoader(manager) {
  21850. return _Loader.call(this, manager) || this;
  21851. }
  21852. var _proto = AnimationLoader.prototype;
  21853. _proto.load = function load(url, onLoad, onProgress, onError) {
  21854. var scope = this;
  21855. var loader = new FileLoader(this.manager);
  21856. loader.setPath(this.path);
  21857. loader.setRequestHeader(this.requestHeader);
  21858. loader.setWithCredentials(this.withCredentials);
  21859. loader.load(url, function (text) {
  21860. try {
  21861. onLoad(scope.parse(JSON.parse(text)));
  21862. } catch (e) {
  21863. if (onError) {
  21864. onError(e);
  21865. } else {
  21866. console.error(e);
  21867. }
  21868. scope.manager.itemError(url);
  21869. }
  21870. }, onProgress, onError);
  21871. };
  21872. _proto.parse = function parse(json) {
  21873. var animations = [];
  21874. for (var i = 0; i < json.length; i++) {
  21875. var clip = AnimationClip.parse(json[i]);
  21876. animations.push(clip);
  21877. }
  21878. return animations;
  21879. };
  21880. return AnimationLoader;
  21881. }(Loader);
  21882. /**
  21883. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21884. *
  21885. * Sub classes have to implement the parse() method which will be used in load().
  21886. */
  21887. function CompressedTextureLoader(manager) {
  21888. Loader.call(this, manager);
  21889. }
  21890. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21891. constructor: CompressedTextureLoader,
  21892. load: function load(url, onLoad, onProgress, onError) {
  21893. var scope = this;
  21894. var images = [];
  21895. var texture = new CompressedTexture();
  21896. var loader = new FileLoader(this.manager);
  21897. loader.setPath(this.path);
  21898. loader.setResponseType('arraybuffer');
  21899. loader.setRequestHeader(this.requestHeader);
  21900. loader.setWithCredentials(scope.withCredentials);
  21901. var loaded = 0;
  21902. function loadTexture(i) {
  21903. loader.load(url[i], function (buffer) {
  21904. var texDatas = scope.parse(buffer, true);
  21905. images[i] = {
  21906. width: texDatas.width,
  21907. height: texDatas.height,
  21908. format: texDatas.format,
  21909. mipmaps: texDatas.mipmaps
  21910. };
  21911. loaded += 1;
  21912. if (loaded === 6) {
  21913. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21914. texture.image = images;
  21915. texture.format = texDatas.format;
  21916. texture.needsUpdate = true;
  21917. if (onLoad) onLoad(texture);
  21918. }
  21919. }, onProgress, onError);
  21920. }
  21921. if (Array.isArray(url)) {
  21922. for (var i = 0, il = url.length; i < il; ++i) {
  21923. loadTexture(i);
  21924. }
  21925. } else {
  21926. // compressed cubemap texture stored in a single DDS file
  21927. loader.load(url, function (buffer) {
  21928. var texDatas = scope.parse(buffer, true);
  21929. if (texDatas.isCubemap) {
  21930. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21931. for (var f = 0; f < faces; f++) {
  21932. images[f] = {
  21933. mipmaps: []
  21934. };
  21935. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21936. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21937. images[f].format = texDatas.format;
  21938. images[f].width = texDatas.width;
  21939. images[f].height = texDatas.height;
  21940. }
  21941. }
  21942. texture.image = images;
  21943. } else {
  21944. texture.image.width = texDatas.width;
  21945. texture.image.height = texDatas.height;
  21946. texture.mipmaps = texDatas.mipmaps;
  21947. }
  21948. if (texDatas.mipmapCount === 1) {
  21949. texture.minFilter = LinearFilter;
  21950. }
  21951. texture.format = texDatas.format;
  21952. texture.needsUpdate = true;
  21953. if (onLoad) onLoad(texture);
  21954. }, onProgress, onError);
  21955. }
  21956. return texture;
  21957. }
  21958. });
  21959. var ImageLoader = /*#__PURE__*/function (_Loader) {
  21960. _inheritsLoose(ImageLoader, _Loader);
  21961. function ImageLoader(manager) {
  21962. return _Loader.call(this, manager) || this;
  21963. }
  21964. var _proto = ImageLoader.prototype;
  21965. _proto.load = function load(url, onLoad, onProgress, onError) {
  21966. if (this.path !== undefined) url = this.path + url;
  21967. url = this.manager.resolveURL(url);
  21968. var scope = this;
  21969. var cached = Cache.get(url);
  21970. if (cached !== undefined) {
  21971. scope.manager.itemStart(url);
  21972. setTimeout(function () {
  21973. if (onLoad) onLoad(cached);
  21974. scope.manager.itemEnd(url);
  21975. }, 0);
  21976. return cached;
  21977. }
  21978. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21979. function onImageLoad() {
  21980. image.removeEventListener('load', onImageLoad, false);
  21981. image.removeEventListener('error', onImageError, false);
  21982. Cache.add(url, this);
  21983. if (onLoad) onLoad(this);
  21984. scope.manager.itemEnd(url);
  21985. }
  21986. function onImageError(event) {
  21987. image.removeEventListener('load', onImageLoad, false);
  21988. image.removeEventListener('error', onImageError, false);
  21989. if (onError) onError(event);
  21990. scope.manager.itemError(url);
  21991. scope.manager.itemEnd(url);
  21992. }
  21993. image.addEventListener('load', onImageLoad, false);
  21994. image.addEventListener('error', onImageError, false);
  21995. if (url.substr(0, 5) !== 'data:') {
  21996. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21997. }
  21998. scope.manager.itemStart(url);
  21999. image.src = url;
  22000. return image;
  22001. };
  22002. return ImageLoader;
  22003. }(Loader);
  22004. var CubeTextureLoader = /*#__PURE__*/function (_Loader) {
  22005. _inheritsLoose(CubeTextureLoader, _Loader);
  22006. function CubeTextureLoader(manager) {
  22007. return _Loader.call(this, manager) || this;
  22008. }
  22009. var _proto = CubeTextureLoader.prototype;
  22010. _proto.load = function load(urls, onLoad, onProgress, onError) {
  22011. var texture = new CubeTexture();
  22012. var loader = new ImageLoader(this.manager);
  22013. loader.setCrossOrigin(this.crossOrigin);
  22014. loader.setPath(this.path);
  22015. var loaded = 0;
  22016. function loadTexture(i) {
  22017. loader.load(urls[i], function (image) {
  22018. texture.images[i] = image;
  22019. loaded++;
  22020. if (loaded === 6) {
  22021. texture.needsUpdate = true;
  22022. if (onLoad) onLoad(texture);
  22023. }
  22024. }, undefined, onError);
  22025. }
  22026. for (var i = 0; i < urls.length; ++i) {
  22027. loadTexture(i);
  22028. }
  22029. return texture;
  22030. };
  22031. return CubeTextureLoader;
  22032. }(Loader);
  22033. /**
  22034. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22035. *
  22036. * Sub classes have to implement the parse() method which will be used in load().
  22037. */
  22038. function DataTextureLoader(manager) {
  22039. Loader.call(this, manager);
  22040. }
  22041. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22042. constructor: DataTextureLoader,
  22043. load: function load(url, onLoad, onProgress, onError) {
  22044. var scope = this;
  22045. var texture = new DataTexture();
  22046. var loader = new FileLoader(this.manager);
  22047. loader.setResponseType('arraybuffer');
  22048. loader.setRequestHeader(this.requestHeader);
  22049. loader.setPath(this.path);
  22050. loader.setWithCredentials(scope.withCredentials);
  22051. loader.load(url, function (buffer) {
  22052. var texData = scope.parse(buffer);
  22053. if (!texData) return;
  22054. if (texData.image !== undefined) {
  22055. texture.image = texData.image;
  22056. } else if (texData.data !== undefined) {
  22057. texture.image.width = texData.width;
  22058. texture.image.height = texData.height;
  22059. texture.image.data = texData.data;
  22060. }
  22061. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22062. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22063. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22064. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22065. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22066. if (texData.encoding !== undefined) {
  22067. texture.encoding = texData.encoding;
  22068. }
  22069. if (texData.flipY !== undefined) {
  22070. texture.flipY = texData.flipY;
  22071. }
  22072. if (texData.format !== undefined) {
  22073. texture.format = texData.format;
  22074. }
  22075. if (texData.type !== undefined) {
  22076. texture.type = texData.type;
  22077. }
  22078. if (texData.mipmaps !== undefined) {
  22079. texture.mipmaps = texData.mipmaps;
  22080. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22081. }
  22082. if (texData.mipmapCount === 1) {
  22083. texture.minFilter = LinearFilter;
  22084. }
  22085. texture.needsUpdate = true;
  22086. if (onLoad) onLoad(texture, texData);
  22087. }, onProgress, onError);
  22088. return texture;
  22089. }
  22090. });
  22091. function TextureLoader(manager) {
  22092. Loader.call(this, manager);
  22093. }
  22094. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22095. constructor: TextureLoader,
  22096. load: function load(url, onLoad, onProgress, onError) {
  22097. var texture = new Texture();
  22098. var loader = new ImageLoader(this.manager);
  22099. loader.setCrossOrigin(this.crossOrigin);
  22100. loader.setPath(this.path);
  22101. loader.load(url, function (image) {
  22102. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22103. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22104. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22105. texture.needsUpdate = true;
  22106. if (onLoad !== undefined) {
  22107. onLoad(texture);
  22108. }
  22109. }, onProgress, onError);
  22110. return texture;
  22111. }
  22112. });
  22113. /**
  22114. * Extensible curve object.
  22115. *
  22116. * Some common of curve methods:
  22117. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22118. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22119. * .getPoints(), .getSpacedPoints()
  22120. * .getLength()
  22121. * .updateArcLengths()
  22122. *
  22123. * This following curves inherit from THREE.Curve:
  22124. *
  22125. * -- 2D curves --
  22126. * THREE.ArcCurve
  22127. * THREE.CubicBezierCurve
  22128. * THREE.EllipseCurve
  22129. * THREE.LineCurve
  22130. * THREE.QuadraticBezierCurve
  22131. * THREE.SplineCurve
  22132. *
  22133. * -- 3D curves --
  22134. * THREE.CatmullRomCurve3
  22135. * THREE.CubicBezierCurve3
  22136. * THREE.LineCurve3
  22137. * THREE.QuadraticBezierCurve3
  22138. *
  22139. * A series of curves can be represented as a THREE.CurvePath.
  22140. *
  22141. **/
  22142. function Curve() {
  22143. this.type = 'Curve';
  22144. this.arcLengthDivisions = 200;
  22145. }
  22146. Object.assign(Curve.prototype, {
  22147. // Virtual base class method to overwrite and implement in subclasses
  22148. // - t [0 .. 1]
  22149. getPoint: function getPoint()
  22150. /* t, optionalTarget */
  22151. {
  22152. console.warn('THREE.Curve: .getPoint() not implemented.');
  22153. return null;
  22154. },
  22155. // Get point at relative position in curve according to arc length
  22156. // - u [0 .. 1]
  22157. getPointAt: function getPointAt(u, optionalTarget) {
  22158. var t = this.getUtoTmapping(u);
  22159. return this.getPoint(t, optionalTarget);
  22160. },
  22161. // Get sequence of points using getPoint( t )
  22162. getPoints: function getPoints(divisions) {
  22163. if (divisions === void 0) {
  22164. divisions = 5;
  22165. }
  22166. var points = [];
  22167. for (var d = 0; d <= divisions; d++) {
  22168. points.push(this.getPoint(d / divisions));
  22169. }
  22170. return points;
  22171. },
  22172. // Get sequence of points using getPointAt( u )
  22173. getSpacedPoints: function getSpacedPoints(divisions) {
  22174. if (divisions === void 0) {
  22175. divisions = 5;
  22176. }
  22177. var points = [];
  22178. for (var d = 0; d <= divisions; d++) {
  22179. points.push(this.getPointAt(d / divisions));
  22180. }
  22181. return points;
  22182. },
  22183. // Get total curve arc length
  22184. getLength: function getLength() {
  22185. var lengths = this.getLengths();
  22186. return lengths[lengths.length - 1];
  22187. },
  22188. // Get list of cumulative segment lengths
  22189. getLengths: function getLengths(divisions) {
  22190. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22191. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22192. return this.cacheArcLengths;
  22193. }
  22194. this.needsUpdate = false;
  22195. var cache = [];
  22196. var current,
  22197. last = this.getPoint(0);
  22198. var sum = 0;
  22199. cache.push(0);
  22200. for (var p = 1; p <= divisions; p++) {
  22201. current = this.getPoint(p / divisions);
  22202. sum += current.distanceTo(last);
  22203. cache.push(sum);
  22204. last = current;
  22205. }
  22206. this.cacheArcLengths = cache;
  22207. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22208. },
  22209. updateArcLengths: function updateArcLengths() {
  22210. this.needsUpdate = true;
  22211. this.getLengths();
  22212. },
  22213. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22214. getUtoTmapping: function getUtoTmapping(u, distance) {
  22215. var arcLengths = this.getLengths();
  22216. var i = 0;
  22217. var il = arcLengths.length;
  22218. var targetArcLength; // The targeted u distance value to get
  22219. if (distance) {
  22220. targetArcLength = distance;
  22221. } else {
  22222. targetArcLength = u * arcLengths[il - 1];
  22223. } // binary search for the index with largest value smaller than target u distance
  22224. var low = 0,
  22225. high = il - 1,
  22226. comparison;
  22227. while (low <= high) {
  22228. 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
  22229. comparison = arcLengths[i] - targetArcLength;
  22230. if (comparison < 0) {
  22231. low = i + 1;
  22232. } else if (comparison > 0) {
  22233. high = i - 1;
  22234. } else {
  22235. high = i;
  22236. break; // DONE
  22237. }
  22238. }
  22239. i = high;
  22240. if (arcLengths[i] === targetArcLength) {
  22241. return i / (il - 1);
  22242. } // we could get finer grain at lengths, or use simple interpolation between two points
  22243. var lengthBefore = arcLengths[i];
  22244. var lengthAfter = arcLengths[i + 1];
  22245. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22246. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22247. var t = (i + segmentFraction) / (il - 1);
  22248. return t;
  22249. },
  22250. // Returns a unit vector tangent at t
  22251. // In case any sub curve does not implement its tangent derivation,
  22252. // 2 points a small delta apart will be used to find its gradient
  22253. // which seems to give a reasonable approximation
  22254. getTangent: function getTangent(t, optionalTarget) {
  22255. var delta = 0.0001;
  22256. var t1 = t - delta;
  22257. var t2 = t + delta; // Capping in case of danger
  22258. if (t1 < 0) t1 = 0;
  22259. if (t2 > 1) t2 = 1;
  22260. var pt1 = this.getPoint(t1);
  22261. var pt2 = this.getPoint(t2);
  22262. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22263. tangent.copy(pt2).sub(pt1).normalize();
  22264. return tangent;
  22265. },
  22266. getTangentAt: function getTangentAt(u, optionalTarget) {
  22267. var t = this.getUtoTmapping(u);
  22268. return this.getTangent(t, optionalTarget);
  22269. },
  22270. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22271. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22272. var normal = new Vector3();
  22273. var tangents = [];
  22274. var normals = [];
  22275. var binormals = [];
  22276. var vec = new Vector3();
  22277. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22278. for (var i = 0; i <= segments; i++) {
  22279. var u = i / segments;
  22280. tangents[i] = this.getTangentAt(u, new Vector3());
  22281. tangents[i].normalize();
  22282. } // select an initial normal vector perpendicular to the first tangent vector,
  22283. // and in the direction of the minimum tangent xyz component
  22284. normals[0] = new Vector3();
  22285. binormals[0] = new Vector3();
  22286. var min = Number.MAX_VALUE;
  22287. var tx = Math.abs(tangents[0].x);
  22288. var ty = Math.abs(tangents[0].y);
  22289. var tz = Math.abs(tangents[0].z);
  22290. if (tx <= min) {
  22291. min = tx;
  22292. normal.set(1, 0, 0);
  22293. }
  22294. if (ty <= min) {
  22295. min = ty;
  22296. normal.set(0, 1, 0);
  22297. }
  22298. if (tz <= min) {
  22299. normal.set(0, 0, 1);
  22300. }
  22301. vec.crossVectors(tangents[0], normal).normalize();
  22302. normals[0].crossVectors(tangents[0], vec);
  22303. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22304. for (var _i = 1; _i <= segments; _i++) {
  22305. normals[_i] = normals[_i - 1].clone();
  22306. binormals[_i] = binormals[_i - 1].clone();
  22307. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22308. if (vec.length() > Number.EPSILON) {
  22309. vec.normalize();
  22310. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22311. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22312. }
  22313. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22314. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22315. if (closed === true) {
  22316. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22317. _theta /= segments;
  22318. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22319. _theta = -_theta;
  22320. }
  22321. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22322. // twist a little...
  22323. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22324. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22325. }
  22326. }
  22327. return {
  22328. tangents: tangents,
  22329. normals: normals,
  22330. binormals: binormals
  22331. };
  22332. },
  22333. clone: function clone() {
  22334. return new this.constructor().copy(this);
  22335. },
  22336. copy: function copy(source) {
  22337. this.arcLengthDivisions = source.arcLengthDivisions;
  22338. return this;
  22339. },
  22340. toJSON: function toJSON() {
  22341. var data = {
  22342. metadata: {
  22343. version: 4.5,
  22344. type: 'Curve',
  22345. generator: 'Curve.toJSON'
  22346. }
  22347. };
  22348. data.arcLengthDivisions = this.arcLengthDivisions;
  22349. data.type = this.type;
  22350. return data;
  22351. },
  22352. fromJSON: function fromJSON(json) {
  22353. this.arcLengthDivisions = json.arcLengthDivisions;
  22354. return this;
  22355. }
  22356. });
  22357. var EllipseCurve = /*#__PURE__*/function (_Curve) {
  22358. _inheritsLoose(EllipseCurve, _Curve);
  22359. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22360. var _this;
  22361. if (aX === void 0) {
  22362. aX = 0;
  22363. }
  22364. if (aY === void 0) {
  22365. aY = 0;
  22366. }
  22367. if (xRadius === void 0) {
  22368. xRadius = 1;
  22369. }
  22370. if (yRadius === void 0) {
  22371. yRadius = 1;
  22372. }
  22373. if (aStartAngle === void 0) {
  22374. aStartAngle = 0;
  22375. }
  22376. if (aEndAngle === void 0) {
  22377. aEndAngle = Math.PI * 2;
  22378. }
  22379. if (aClockwise === void 0) {
  22380. aClockwise = false;
  22381. }
  22382. if (aRotation === void 0) {
  22383. aRotation = 0;
  22384. }
  22385. _this = _Curve.call(this) || this;
  22386. _this.type = 'EllipseCurve';
  22387. _this.aX = aX;
  22388. _this.aY = aY;
  22389. _this.xRadius = xRadius;
  22390. _this.yRadius = yRadius;
  22391. _this.aStartAngle = aStartAngle;
  22392. _this.aEndAngle = aEndAngle;
  22393. _this.aClockwise = aClockwise;
  22394. _this.aRotation = aRotation;
  22395. return _this;
  22396. }
  22397. var _proto = EllipseCurve.prototype;
  22398. _proto.getPoint = function getPoint(t, optionalTarget) {
  22399. var point = optionalTarget || new Vector2();
  22400. var twoPi = Math.PI * 2;
  22401. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22402. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22403. while (deltaAngle < 0) {
  22404. deltaAngle += twoPi;
  22405. }
  22406. while (deltaAngle > twoPi) {
  22407. deltaAngle -= twoPi;
  22408. }
  22409. if (deltaAngle < Number.EPSILON) {
  22410. if (samePoints) {
  22411. deltaAngle = 0;
  22412. } else {
  22413. deltaAngle = twoPi;
  22414. }
  22415. }
  22416. if (this.aClockwise === true && !samePoints) {
  22417. if (deltaAngle === twoPi) {
  22418. deltaAngle = -twoPi;
  22419. } else {
  22420. deltaAngle = deltaAngle - twoPi;
  22421. }
  22422. }
  22423. var angle = this.aStartAngle + t * deltaAngle;
  22424. var x = this.aX + this.xRadius * Math.cos(angle);
  22425. var y = this.aY + this.yRadius * Math.sin(angle);
  22426. if (this.aRotation !== 0) {
  22427. var cos = Math.cos(this.aRotation);
  22428. var sin = Math.sin(this.aRotation);
  22429. var tx = x - this.aX;
  22430. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22431. x = tx * cos - ty * sin + this.aX;
  22432. y = tx * sin + ty * cos + this.aY;
  22433. }
  22434. return point.set(x, y);
  22435. };
  22436. _proto.copy = function copy(source) {
  22437. _Curve.prototype.copy.call(this, source);
  22438. this.aX = source.aX;
  22439. this.aY = source.aY;
  22440. this.xRadius = source.xRadius;
  22441. this.yRadius = source.yRadius;
  22442. this.aStartAngle = source.aStartAngle;
  22443. this.aEndAngle = source.aEndAngle;
  22444. this.aClockwise = source.aClockwise;
  22445. this.aRotation = source.aRotation;
  22446. return this;
  22447. };
  22448. _proto.toJSON = function toJSON() {
  22449. var data = _Curve.prototype.toJSON.call(this);
  22450. data.aX = this.aX;
  22451. data.aY = this.aY;
  22452. data.xRadius = this.xRadius;
  22453. data.yRadius = this.yRadius;
  22454. data.aStartAngle = this.aStartAngle;
  22455. data.aEndAngle = this.aEndAngle;
  22456. data.aClockwise = this.aClockwise;
  22457. data.aRotation = this.aRotation;
  22458. return data;
  22459. };
  22460. _proto.fromJSON = function fromJSON(json) {
  22461. _Curve.prototype.fromJSON.call(this, json);
  22462. this.aX = json.aX;
  22463. this.aY = json.aY;
  22464. this.xRadius = json.xRadius;
  22465. this.yRadius = json.yRadius;
  22466. this.aStartAngle = json.aStartAngle;
  22467. this.aEndAngle = json.aEndAngle;
  22468. this.aClockwise = json.aClockwise;
  22469. this.aRotation = json.aRotation;
  22470. return this;
  22471. };
  22472. return EllipseCurve;
  22473. }(Curve);
  22474. EllipseCurve.prototype.isEllipseCurve = true;
  22475. var ArcCurve = /*#__PURE__*/function (_EllipseCurve) {
  22476. _inheritsLoose(ArcCurve, _EllipseCurve);
  22477. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22478. var _this;
  22479. _this = _EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise) || this;
  22480. _this.type = 'ArcCurve';
  22481. return _this;
  22482. }
  22483. return ArcCurve;
  22484. }(EllipseCurve);
  22485. ArcCurve.prototype.isArcCurve = true;
  22486. /**
  22487. * Centripetal CatmullRom Curve - which is useful for avoiding
  22488. * cusps and self-intersections in non-uniform catmull rom curves.
  22489. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22490. *
  22491. * curve.type accepts centripetal(default), chordal and catmullrom
  22492. * curve.tension is used for catmullrom which defaults to 0.5
  22493. */
  22494. /*
  22495. Based on an optimized c++ solution in
  22496. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22497. - http://ideone.com/NoEbVM
  22498. This CubicPoly class could be used for reusing some variables and calculations,
  22499. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22500. which can be placed in CurveUtils.
  22501. */
  22502. function CubicPoly() {
  22503. var c0 = 0,
  22504. c1 = 0,
  22505. c2 = 0,
  22506. c3 = 0;
  22507. /*
  22508. * Compute coefficients for a cubic polynomial
  22509. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22510. * such that
  22511. * p(0) = x0, p(1) = x1
  22512. * and
  22513. * p'(0) = t0, p'(1) = t1.
  22514. */
  22515. function init(x0, x1, t0, t1) {
  22516. c0 = x0;
  22517. c1 = t0;
  22518. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22519. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22520. }
  22521. return {
  22522. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22523. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22524. },
  22525. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22526. // compute tangents when parameterized in [t1,t2]
  22527. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22528. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22529. t1 *= dt1;
  22530. t2 *= dt1;
  22531. init(x1, x2, t1, t2);
  22532. },
  22533. calc: function calc(t) {
  22534. var t2 = t * t;
  22535. var t3 = t2 * t;
  22536. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22537. }
  22538. };
  22539. } //
  22540. var tmp = new Vector3();
  22541. var px = new CubicPoly(),
  22542. py = new CubicPoly(),
  22543. pz = new CubicPoly();
  22544. var CatmullRomCurve3 = /*#__PURE__*/function (_Curve) {
  22545. _inheritsLoose(CatmullRomCurve3, _Curve);
  22546. function CatmullRomCurve3(points, closed, curveType, tension) {
  22547. var _this;
  22548. if (points === void 0) {
  22549. points = [];
  22550. }
  22551. if (closed === void 0) {
  22552. closed = false;
  22553. }
  22554. if (curveType === void 0) {
  22555. curveType = 'centripetal';
  22556. }
  22557. if (tension === void 0) {
  22558. tension = 0.5;
  22559. }
  22560. _this = _Curve.call(this) || this;
  22561. _this.type = 'CatmullRomCurve3';
  22562. _this.points = points;
  22563. _this.closed = closed;
  22564. _this.curveType = curveType;
  22565. _this.tension = tension;
  22566. return _this;
  22567. }
  22568. var _proto = CatmullRomCurve3.prototype;
  22569. _proto.getPoint = function getPoint(t, optionalTarget) {
  22570. if (optionalTarget === void 0) {
  22571. optionalTarget = new Vector3();
  22572. }
  22573. var point = optionalTarget;
  22574. var points = this.points;
  22575. var l = points.length;
  22576. var p = (l - (this.closed ? 0 : 1)) * t;
  22577. var intPoint = Math.floor(p);
  22578. var weight = p - intPoint;
  22579. if (this.closed) {
  22580. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22581. } else if (weight === 0 && intPoint === l - 1) {
  22582. intPoint = l - 2;
  22583. weight = 1;
  22584. }
  22585. var p0, p3; // 4 points (p1 & p2 defined below)
  22586. if (this.closed || intPoint > 0) {
  22587. p0 = points[(intPoint - 1) % l];
  22588. } else {
  22589. // extrapolate first point
  22590. tmp.subVectors(points[0], points[1]).add(points[0]);
  22591. p0 = tmp;
  22592. }
  22593. var p1 = points[intPoint % l];
  22594. var p2 = points[(intPoint + 1) % l];
  22595. if (this.closed || intPoint + 2 < l) {
  22596. p3 = points[(intPoint + 2) % l];
  22597. } else {
  22598. // extrapolate last point
  22599. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22600. p3 = tmp;
  22601. }
  22602. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22603. // init Centripetal / Chordal Catmull-Rom
  22604. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22605. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22606. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22607. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22608. if (dt1 < 1e-4) dt1 = 1.0;
  22609. if (dt0 < 1e-4) dt0 = dt1;
  22610. if (dt2 < 1e-4) dt2 = dt1;
  22611. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22612. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22613. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22614. } else if (this.curveType === 'catmullrom') {
  22615. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22616. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22617. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22618. }
  22619. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22620. return point;
  22621. };
  22622. _proto.copy = function copy(source) {
  22623. _Curve.prototype.copy.call(this, source);
  22624. this.points = [];
  22625. for (var i = 0, l = source.points.length; i < l; i++) {
  22626. var point = source.points[i];
  22627. this.points.push(point.clone());
  22628. }
  22629. this.closed = source.closed;
  22630. this.curveType = source.curveType;
  22631. this.tension = source.tension;
  22632. return this;
  22633. };
  22634. _proto.toJSON = function toJSON() {
  22635. var data = _Curve.prototype.toJSON.call(this);
  22636. data.points = [];
  22637. for (var i = 0, l = this.points.length; i < l; i++) {
  22638. var point = this.points[i];
  22639. data.points.push(point.toArray());
  22640. }
  22641. data.closed = this.closed;
  22642. data.curveType = this.curveType;
  22643. data.tension = this.tension;
  22644. return data;
  22645. };
  22646. _proto.fromJSON = function fromJSON(json) {
  22647. _Curve.prototype.fromJSON.call(this, json);
  22648. this.points = [];
  22649. for (var i = 0, l = json.points.length; i < l; i++) {
  22650. var point = json.points[i];
  22651. this.points.push(new Vector3().fromArray(point));
  22652. }
  22653. this.closed = json.closed;
  22654. this.curveType = json.curveType;
  22655. this.tension = json.tension;
  22656. return this;
  22657. };
  22658. return CatmullRomCurve3;
  22659. }(Curve);
  22660. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22661. /**
  22662. * Bezier Curves formulas obtained from
  22663. * http://en.wikipedia.org/wiki/Bézier_curve
  22664. */
  22665. function CatmullRom(t, p0, p1, p2, p3) {
  22666. var v0 = (p2 - p0) * 0.5;
  22667. var v1 = (p3 - p1) * 0.5;
  22668. var t2 = t * t;
  22669. var t3 = t * t2;
  22670. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22671. } //
  22672. function QuadraticBezierP0(t, p) {
  22673. var k = 1 - t;
  22674. return k * k * p;
  22675. }
  22676. function QuadraticBezierP1(t, p) {
  22677. return 2 * (1 - t) * t * p;
  22678. }
  22679. function QuadraticBezierP2(t, p) {
  22680. return t * t * p;
  22681. }
  22682. function QuadraticBezier(t, p0, p1, p2) {
  22683. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22684. } //
  22685. function CubicBezierP0(t, p) {
  22686. var k = 1 - t;
  22687. return k * k * k * p;
  22688. }
  22689. function CubicBezierP1(t, p) {
  22690. var k = 1 - t;
  22691. return 3 * k * k * t * p;
  22692. }
  22693. function CubicBezierP2(t, p) {
  22694. return 3 * (1 - t) * t * t * p;
  22695. }
  22696. function CubicBezierP3(t, p) {
  22697. return t * t * t * p;
  22698. }
  22699. function CubicBezier(t, p0, p1, p2, p3) {
  22700. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22701. }
  22702. var CubicBezierCurve = /*#__PURE__*/function (_Curve) {
  22703. _inheritsLoose(CubicBezierCurve, _Curve);
  22704. function CubicBezierCurve(v0, v1, v2, v3) {
  22705. var _this;
  22706. if (v0 === void 0) {
  22707. v0 = new Vector2();
  22708. }
  22709. if (v1 === void 0) {
  22710. v1 = new Vector2();
  22711. }
  22712. if (v2 === void 0) {
  22713. v2 = new Vector2();
  22714. }
  22715. if (v3 === void 0) {
  22716. v3 = new Vector2();
  22717. }
  22718. _this = _Curve.call(this) || this;
  22719. _this.type = 'CubicBezierCurve';
  22720. _this.v0 = v0;
  22721. _this.v1 = v1;
  22722. _this.v2 = v2;
  22723. _this.v3 = v3;
  22724. return _this;
  22725. }
  22726. var _proto = CubicBezierCurve.prototype;
  22727. _proto.getPoint = function getPoint(t, optionalTarget) {
  22728. if (optionalTarget === void 0) {
  22729. optionalTarget = new Vector2();
  22730. }
  22731. var point = optionalTarget;
  22732. var v0 = this.v0,
  22733. v1 = this.v1,
  22734. v2 = this.v2,
  22735. v3 = this.v3;
  22736. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22737. return point;
  22738. };
  22739. _proto.copy = function copy(source) {
  22740. _Curve.prototype.copy.call(this, source);
  22741. this.v0.copy(source.v0);
  22742. this.v1.copy(source.v1);
  22743. this.v2.copy(source.v2);
  22744. this.v3.copy(source.v3);
  22745. return this;
  22746. };
  22747. _proto.toJSON = function toJSON() {
  22748. var data = _Curve.prototype.toJSON.call(this);
  22749. data.v0 = this.v0.toArray();
  22750. data.v1 = this.v1.toArray();
  22751. data.v2 = this.v2.toArray();
  22752. data.v3 = this.v3.toArray();
  22753. return data;
  22754. };
  22755. _proto.fromJSON = function fromJSON(json) {
  22756. _Curve.prototype.fromJSON.call(this, json);
  22757. this.v0.fromArray(json.v0);
  22758. this.v1.fromArray(json.v1);
  22759. this.v2.fromArray(json.v2);
  22760. this.v3.fromArray(json.v3);
  22761. return this;
  22762. };
  22763. return CubicBezierCurve;
  22764. }(Curve);
  22765. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22766. var CubicBezierCurve3 = /*#__PURE__*/function (_Curve) {
  22767. _inheritsLoose(CubicBezierCurve3, _Curve);
  22768. function CubicBezierCurve3(v0, v1, v2, v3) {
  22769. var _this;
  22770. if (v0 === void 0) {
  22771. v0 = new Vector3();
  22772. }
  22773. if (v1 === void 0) {
  22774. v1 = new Vector3();
  22775. }
  22776. if (v2 === void 0) {
  22777. v2 = new Vector3();
  22778. }
  22779. if (v3 === void 0) {
  22780. v3 = new Vector3();
  22781. }
  22782. _this = _Curve.call(this) || this;
  22783. _this.type = 'CubicBezierCurve3';
  22784. _this.v0 = v0;
  22785. _this.v1 = v1;
  22786. _this.v2 = v2;
  22787. _this.v3 = v3;
  22788. return _this;
  22789. }
  22790. var _proto = CubicBezierCurve3.prototype;
  22791. _proto.getPoint = function getPoint(t, optionalTarget) {
  22792. if (optionalTarget === void 0) {
  22793. optionalTarget = new Vector3();
  22794. }
  22795. var point = optionalTarget;
  22796. var v0 = this.v0,
  22797. v1 = this.v1,
  22798. v2 = this.v2,
  22799. v3 = this.v3;
  22800. 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));
  22801. return point;
  22802. };
  22803. _proto.copy = function copy(source) {
  22804. _Curve.prototype.copy.call(this, source);
  22805. this.v0.copy(source.v0);
  22806. this.v1.copy(source.v1);
  22807. this.v2.copy(source.v2);
  22808. this.v3.copy(source.v3);
  22809. return this;
  22810. };
  22811. _proto.toJSON = function toJSON() {
  22812. var data = _Curve.prototype.toJSON.call(this);
  22813. data.v0 = this.v0.toArray();
  22814. data.v1 = this.v1.toArray();
  22815. data.v2 = this.v2.toArray();
  22816. data.v3 = this.v3.toArray();
  22817. return data;
  22818. };
  22819. _proto.fromJSON = function fromJSON(json) {
  22820. _Curve.prototype.fromJSON.call(this, json);
  22821. this.v0.fromArray(json.v0);
  22822. this.v1.fromArray(json.v1);
  22823. this.v2.fromArray(json.v2);
  22824. this.v3.fromArray(json.v3);
  22825. return this;
  22826. };
  22827. return CubicBezierCurve3;
  22828. }(Curve);
  22829. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22830. var LineCurve = /*#__PURE__*/function (_Curve) {
  22831. _inheritsLoose(LineCurve, _Curve);
  22832. function LineCurve(v1, v2) {
  22833. var _this;
  22834. if (v1 === void 0) {
  22835. v1 = new Vector2();
  22836. }
  22837. if (v2 === void 0) {
  22838. v2 = new Vector2();
  22839. }
  22840. _this = _Curve.call(this) || this;
  22841. _this.type = 'LineCurve';
  22842. _this.v1 = v1;
  22843. _this.v2 = v2;
  22844. return _this;
  22845. }
  22846. var _proto = LineCurve.prototype;
  22847. _proto.getPoint = function getPoint(t, optionalTarget) {
  22848. if (optionalTarget === void 0) {
  22849. optionalTarget = new Vector2();
  22850. }
  22851. var point = optionalTarget;
  22852. if (t === 1) {
  22853. point.copy(this.v2);
  22854. } else {
  22855. point.copy(this.v2).sub(this.v1);
  22856. point.multiplyScalar(t).add(this.v1);
  22857. }
  22858. return point;
  22859. } // Line curve is linear, so we can overwrite default getPointAt
  22860. ;
  22861. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22862. return this.getPoint(u, optionalTarget);
  22863. };
  22864. _proto.getTangent = function getTangent(t, optionalTarget) {
  22865. var tangent = optionalTarget || new Vector2();
  22866. tangent.copy(this.v2).sub(this.v1).normalize();
  22867. return tangent;
  22868. };
  22869. _proto.copy = function copy(source) {
  22870. _Curve.prototype.copy.call(this, source);
  22871. this.v1.copy(source.v1);
  22872. this.v2.copy(source.v2);
  22873. return this;
  22874. };
  22875. _proto.toJSON = function toJSON() {
  22876. var data = _Curve.prototype.toJSON.call(this);
  22877. data.v1 = this.v1.toArray();
  22878. data.v2 = this.v2.toArray();
  22879. return data;
  22880. };
  22881. _proto.fromJSON = function fromJSON(json) {
  22882. _Curve.prototype.fromJSON.call(this, json);
  22883. this.v1.fromArray(json.v1);
  22884. this.v2.fromArray(json.v2);
  22885. return this;
  22886. };
  22887. return LineCurve;
  22888. }(Curve);
  22889. LineCurve.prototype.isLineCurve = true;
  22890. var LineCurve3 = /*#__PURE__*/function (_Curve) {
  22891. _inheritsLoose(LineCurve3, _Curve);
  22892. function LineCurve3(v1, v2) {
  22893. var _this;
  22894. if (v1 === void 0) {
  22895. v1 = new Vector3();
  22896. }
  22897. if (v2 === void 0) {
  22898. v2 = new Vector3();
  22899. }
  22900. _this = _Curve.call(this) || this;
  22901. _this.type = 'LineCurve3';
  22902. _this.isLineCurve3 = true;
  22903. _this.v1 = v1;
  22904. _this.v2 = v2;
  22905. return _this;
  22906. }
  22907. var _proto = LineCurve3.prototype;
  22908. _proto.getPoint = function getPoint(t, optionalTarget) {
  22909. if (optionalTarget === void 0) {
  22910. optionalTarget = new Vector3();
  22911. }
  22912. var point = optionalTarget;
  22913. if (t === 1) {
  22914. point.copy(this.v2);
  22915. } else {
  22916. point.copy(this.v2).sub(this.v1);
  22917. point.multiplyScalar(t).add(this.v1);
  22918. }
  22919. return point;
  22920. } // Line curve is linear, so we can overwrite default getPointAt
  22921. ;
  22922. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22923. return this.getPoint(u, optionalTarget);
  22924. };
  22925. _proto.copy = function copy(source) {
  22926. _Curve.prototype.copy.call(this, source);
  22927. this.v1.copy(source.v1);
  22928. this.v2.copy(source.v2);
  22929. return this;
  22930. };
  22931. _proto.toJSON = function toJSON() {
  22932. var data = _Curve.prototype.toJSON.call(this);
  22933. data.v1 = this.v1.toArray();
  22934. data.v2 = this.v2.toArray();
  22935. return data;
  22936. };
  22937. _proto.fromJSON = function fromJSON(json) {
  22938. _Curve.prototype.fromJSON.call(this, json);
  22939. this.v1.fromArray(json.v1);
  22940. this.v2.fromArray(json.v2);
  22941. return this;
  22942. };
  22943. return LineCurve3;
  22944. }(Curve);
  22945. var QuadraticBezierCurve = /*#__PURE__*/function (_Curve) {
  22946. _inheritsLoose(QuadraticBezierCurve, _Curve);
  22947. function QuadraticBezierCurve(v0, v1, v2) {
  22948. var _this;
  22949. if (v0 === void 0) {
  22950. v0 = new Vector2();
  22951. }
  22952. if (v1 === void 0) {
  22953. v1 = new Vector2();
  22954. }
  22955. if (v2 === void 0) {
  22956. v2 = new Vector2();
  22957. }
  22958. _this = _Curve.call(this) || this;
  22959. _this.type = 'QuadraticBezierCurve';
  22960. _this.v0 = v0;
  22961. _this.v1 = v1;
  22962. _this.v2 = v2;
  22963. return _this;
  22964. }
  22965. var _proto = QuadraticBezierCurve.prototype;
  22966. _proto.getPoint = function getPoint(t, optionalTarget) {
  22967. if (optionalTarget === void 0) {
  22968. optionalTarget = new Vector2();
  22969. }
  22970. var point = optionalTarget;
  22971. var v0 = this.v0,
  22972. v1 = this.v1,
  22973. v2 = this.v2;
  22974. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22975. return point;
  22976. };
  22977. _proto.copy = function copy(source) {
  22978. _Curve.prototype.copy.call(this, source);
  22979. this.v0.copy(source.v0);
  22980. this.v1.copy(source.v1);
  22981. this.v2.copy(source.v2);
  22982. return this;
  22983. };
  22984. _proto.toJSON = function toJSON() {
  22985. var data = _Curve.prototype.toJSON.call(this);
  22986. data.v0 = this.v0.toArray();
  22987. data.v1 = this.v1.toArray();
  22988. data.v2 = this.v2.toArray();
  22989. return data;
  22990. };
  22991. _proto.fromJSON = function fromJSON(json) {
  22992. _Curve.prototype.fromJSON.call(this, json);
  22993. this.v0.fromArray(json.v0);
  22994. this.v1.fromArray(json.v1);
  22995. this.v2.fromArray(json.v2);
  22996. return this;
  22997. };
  22998. return QuadraticBezierCurve;
  22999. }(Curve);
  23000. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  23001. var QuadraticBezierCurve3 = /*#__PURE__*/function (_Curve) {
  23002. _inheritsLoose(QuadraticBezierCurve3, _Curve);
  23003. function QuadraticBezierCurve3(v0, v1, v2) {
  23004. var _this;
  23005. if (v0 === void 0) {
  23006. v0 = new Vector3();
  23007. }
  23008. if (v1 === void 0) {
  23009. v1 = new Vector3();
  23010. }
  23011. if (v2 === void 0) {
  23012. v2 = new Vector3();
  23013. }
  23014. _this = _Curve.call(this) || this;
  23015. _this.type = 'QuadraticBezierCurve3';
  23016. _this.v0 = v0;
  23017. _this.v1 = v1;
  23018. _this.v2 = v2;
  23019. return _this;
  23020. }
  23021. var _proto = QuadraticBezierCurve3.prototype;
  23022. _proto.getPoint = function getPoint(t, optionalTarget) {
  23023. if (optionalTarget === void 0) {
  23024. optionalTarget = new Vector3();
  23025. }
  23026. var point = optionalTarget;
  23027. var v0 = this.v0,
  23028. v1 = this.v1,
  23029. v2 = this.v2;
  23030. 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));
  23031. return point;
  23032. };
  23033. _proto.copy = function copy(source) {
  23034. _Curve.prototype.copy.call(this, source);
  23035. this.v0.copy(source.v0);
  23036. this.v1.copy(source.v1);
  23037. this.v2.copy(source.v2);
  23038. return this;
  23039. };
  23040. _proto.toJSON = function toJSON() {
  23041. var data = _Curve.prototype.toJSON.call(this);
  23042. data.v0 = this.v0.toArray();
  23043. data.v1 = this.v1.toArray();
  23044. data.v2 = this.v2.toArray();
  23045. return data;
  23046. };
  23047. _proto.fromJSON = function fromJSON(json) {
  23048. _Curve.prototype.fromJSON.call(this, json);
  23049. this.v0.fromArray(json.v0);
  23050. this.v1.fromArray(json.v1);
  23051. this.v2.fromArray(json.v2);
  23052. return this;
  23053. };
  23054. return QuadraticBezierCurve3;
  23055. }(Curve);
  23056. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  23057. var SplineCurve = /*#__PURE__*/function (_Curve) {
  23058. _inheritsLoose(SplineCurve, _Curve);
  23059. function SplineCurve(points) {
  23060. var _this;
  23061. if (points === void 0) {
  23062. points = [];
  23063. }
  23064. _this = _Curve.call(this) || this;
  23065. _this.type = 'SplineCurve';
  23066. _this.points = points;
  23067. return _this;
  23068. }
  23069. var _proto = SplineCurve.prototype;
  23070. _proto.getPoint = function getPoint(t, optionalTarget) {
  23071. if (optionalTarget === void 0) {
  23072. optionalTarget = new Vector2();
  23073. }
  23074. var point = optionalTarget;
  23075. var points = this.points;
  23076. var p = (points.length - 1) * t;
  23077. var intPoint = Math.floor(p);
  23078. var weight = p - intPoint;
  23079. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  23080. var p1 = points[intPoint];
  23081. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  23082. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  23083. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  23084. return point;
  23085. };
  23086. _proto.copy = function copy(source) {
  23087. _Curve.prototype.copy.call(this, source);
  23088. this.points = [];
  23089. for (var i = 0, l = source.points.length; i < l; i++) {
  23090. var point = source.points[i];
  23091. this.points.push(point.clone());
  23092. }
  23093. return this;
  23094. };
  23095. _proto.toJSON = function toJSON() {
  23096. var data = _Curve.prototype.toJSON.call(this);
  23097. data.points = [];
  23098. for (var i = 0, l = this.points.length; i < l; i++) {
  23099. var point = this.points[i];
  23100. data.points.push(point.toArray());
  23101. }
  23102. return data;
  23103. };
  23104. _proto.fromJSON = function fromJSON(json) {
  23105. _Curve.prototype.fromJSON.call(this, json);
  23106. this.points = [];
  23107. for (var i = 0, l = json.points.length; i < l; i++) {
  23108. var point = json.points[i];
  23109. this.points.push(new Vector2().fromArray(point));
  23110. }
  23111. return this;
  23112. };
  23113. return SplineCurve;
  23114. }(Curve);
  23115. SplineCurve.prototype.isSplineCurve = true;
  23116. var Curves = /*#__PURE__*/Object.freeze({
  23117. __proto__: null,
  23118. ArcCurve: ArcCurve,
  23119. CatmullRomCurve3: CatmullRomCurve3,
  23120. CubicBezierCurve: CubicBezierCurve,
  23121. CubicBezierCurve3: CubicBezierCurve3,
  23122. EllipseCurve: EllipseCurve,
  23123. LineCurve: LineCurve,
  23124. LineCurve3: LineCurve3,
  23125. QuadraticBezierCurve: QuadraticBezierCurve,
  23126. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23127. SplineCurve: SplineCurve
  23128. });
  23129. /**************************************************************
  23130. * Curved Path - a curve path is simply a array of connected
  23131. * curves, but retains the api of a curve
  23132. **************************************************************/
  23133. var CurvePath = /*#__PURE__*/function (_Curve) {
  23134. _inheritsLoose(CurvePath, _Curve);
  23135. function CurvePath() {
  23136. var _this;
  23137. _this = _Curve.call(this) || this;
  23138. _this.type = 'CurvePath';
  23139. _this.curves = [];
  23140. _this.autoClose = false; // Automatically closes the path
  23141. return _this;
  23142. }
  23143. var _proto = CurvePath.prototype;
  23144. _proto.add = function add(curve) {
  23145. this.curves.push(curve);
  23146. };
  23147. _proto.closePath = function closePath() {
  23148. // Add a line curve if start and end of lines are not connected
  23149. var startPoint = this.curves[0].getPoint(0);
  23150. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  23151. if (!startPoint.equals(endPoint)) {
  23152. this.curves.push(new LineCurve(endPoint, startPoint));
  23153. }
  23154. } // To get accurate point with reference to
  23155. // entire path distance at time t,
  23156. // following has to be done:
  23157. // 1. Length of each sub path have to be known
  23158. // 2. Locate and identify type of curve
  23159. // 3. Get t for the curve
  23160. // 4. Return curve.getPointAt(t')
  23161. ;
  23162. _proto.getPoint = function getPoint(t) {
  23163. var d = t * this.getLength();
  23164. var curveLengths = this.getCurveLengths();
  23165. var i = 0; // To think about boundaries points.
  23166. while (i < curveLengths.length) {
  23167. if (curveLengths[i] >= d) {
  23168. var diff = curveLengths[i] - d;
  23169. var curve = this.curves[i];
  23170. var segmentLength = curve.getLength();
  23171. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23172. return curve.getPointAt(u);
  23173. }
  23174. i++;
  23175. }
  23176. return null; // loop where sum != 0, sum > d , sum+1 <d
  23177. } // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23178. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23179. // getPoint() depends on getLength
  23180. ;
  23181. _proto.getLength = function getLength() {
  23182. var lens = this.getCurveLengths();
  23183. return lens[lens.length - 1];
  23184. } // cacheLengths must be recalculated.
  23185. ;
  23186. _proto.updateArcLengths = function updateArcLengths() {
  23187. this.needsUpdate = true;
  23188. this.cacheLengths = null;
  23189. this.getCurveLengths();
  23190. } // Compute lengths and cache them
  23191. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23192. ;
  23193. _proto.getCurveLengths = function getCurveLengths() {
  23194. // We use cache values if curves and cache array are same length
  23195. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23196. return this.cacheLengths;
  23197. } // Get length of sub-curve
  23198. // Push sums into cached array
  23199. var lengths = [];
  23200. var sums = 0;
  23201. for (var i = 0, l = this.curves.length; i < l; i++) {
  23202. sums += this.curves[i].getLength();
  23203. lengths.push(sums);
  23204. }
  23205. this.cacheLengths = lengths;
  23206. return lengths;
  23207. };
  23208. _proto.getSpacedPoints = function getSpacedPoints(divisions) {
  23209. if (divisions === void 0) {
  23210. divisions = 40;
  23211. }
  23212. var points = [];
  23213. for (var i = 0; i <= divisions; i++) {
  23214. points.push(this.getPoint(i / divisions));
  23215. }
  23216. if (this.autoClose) {
  23217. points.push(points[0]);
  23218. }
  23219. return points;
  23220. };
  23221. _proto.getPoints = function getPoints(divisions) {
  23222. if (divisions === void 0) {
  23223. divisions = 12;
  23224. }
  23225. var points = [];
  23226. var last;
  23227. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23228. var curve = curves[i];
  23229. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23230. var pts = curve.getPoints(resolution);
  23231. for (var j = 0; j < pts.length; j++) {
  23232. var point = pts[j];
  23233. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23234. points.push(point);
  23235. last = point;
  23236. }
  23237. }
  23238. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23239. points.push(points[0]);
  23240. }
  23241. return points;
  23242. };
  23243. _proto.copy = function copy(source) {
  23244. _Curve.prototype.copy.call(this, source);
  23245. this.curves = [];
  23246. for (var i = 0, l = source.curves.length; i < l; i++) {
  23247. var curve = source.curves[i];
  23248. this.curves.push(curve.clone());
  23249. }
  23250. this.autoClose = source.autoClose;
  23251. return this;
  23252. };
  23253. _proto.toJSON = function toJSON() {
  23254. var data = _Curve.prototype.toJSON.call(this);
  23255. data.autoClose = this.autoClose;
  23256. data.curves = [];
  23257. for (var i = 0, l = this.curves.length; i < l; i++) {
  23258. var curve = this.curves[i];
  23259. data.curves.push(curve.toJSON());
  23260. }
  23261. return data;
  23262. };
  23263. _proto.fromJSON = function fromJSON(json) {
  23264. _Curve.prototype.fromJSON.call(this, json);
  23265. this.autoClose = json.autoClose;
  23266. this.curves = [];
  23267. for (var i = 0, l = json.curves.length; i < l; i++) {
  23268. var curve = json.curves[i];
  23269. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23270. }
  23271. return this;
  23272. };
  23273. return CurvePath;
  23274. }(Curve);
  23275. var Path = /*#__PURE__*/function (_CurvePath) {
  23276. _inheritsLoose(Path, _CurvePath);
  23277. function Path(points) {
  23278. var _this;
  23279. _this = _CurvePath.call(this) || this;
  23280. _this.type = 'Path';
  23281. _this.currentPoint = new Vector2();
  23282. if (points) {
  23283. _this.setFromPoints(points);
  23284. }
  23285. return _this;
  23286. }
  23287. var _proto = Path.prototype;
  23288. _proto.setFromPoints = function setFromPoints(points) {
  23289. this.moveTo(points[0].x, points[0].y);
  23290. for (var i = 1, l = points.length; i < l; i++) {
  23291. this.lineTo(points[i].x, points[i].y);
  23292. }
  23293. return this;
  23294. };
  23295. _proto.moveTo = function moveTo(x, y) {
  23296. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23297. return this;
  23298. };
  23299. _proto.lineTo = function lineTo(x, y) {
  23300. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23301. this.curves.push(curve);
  23302. this.currentPoint.set(x, y);
  23303. return this;
  23304. };
  23305. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23306. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23307. this.curves.push(curve);
  23308. this.currentPoint.set(aX, aY);
  23309. return this;
  23310. };
  23311. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23312. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23313. this.curves.push(curve);
  23314. this.currentPoint.set(aX, aY);
  23315. return this;
  23316. };
  23317. _proto.splineThru = function splineThru(pts
  23318. /*Array of Vector*/
  23319. ) {
  23320. var npts = [this.currentPoint.clone()].concat(pts);
  23321. var curve = new SplineCurve(npts);
  23322. this.curves.push(curve);
  23323. this.currentPoint.copy(pts[pts.length - 1]);
  23324. return this;
  23325. };
  23326. _proto.arc = function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23327. var x0 = this.currentPoint.x;
  23328. var y0 = this.currentPoint.y;
  23329. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23330. return this;
  23331. };
  23332. _proto.absarc = function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23333. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23334. return this;
  23335. };
  23336. _proto.ellipse = function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23337. var x0 = this.currentPoint.x;
  23338. var y0 = this.currentPoint.y;
  23339. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23340. return this;
  23341. };
  23342. _proto.absellipse = function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23343. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23344. if (this.curves.length > 0) {
  23345. // if a previous curve is present, attempt to join
  23346. var firstPoint = curve.getPoint(0);
  23347. if (!firstPoint.equals(this.currentPoint)) {
  23348. this.lineTo(firstPoint.x, firstPoint.y);
  23349. }
  23350. }
  23351. this.curves.push(curve);
  23352. var lastPoint = curve.getPoint(1);
  23353. this.currentPoint.copy(lastPoint);
  23354. return this;
  23355. };
  23356. _proto.copy = function copy(source) {
  23357. _CurvePath.prototype.copy.call(this, source);
  23358. this.currentPoint.copy(source.currentPoint);
  23359. return this;
  23360. };
  23361. _proto.toJSON = function toJSON() {
  23362. var data = _CurvePath.prototype.toJSON.call(this);
  23363. data.currentPoint = this.currentPoint.toArray();
  23364. return data;
  23365. };
  23366. _proto.fromJSON = function fromJSON(json) {
  23367. _CurvePath.prototype.fromJSON.call(this, json);
  23368. this.currentPoint.fromArray(json.currentPoint);
  23369. return this;
  23370. };
  23371. return Path;
  23372. }(CurvePath);
  23373. var Shape = /*#__PURE__*/function (_Path) {
  23374. _inheritsLoose(Shape, _Path);
  23375. function Shape(points) {
  23376. var _this;
  23377. _this = _Path.call(this, points) || this;
  23378. _this.uuid = MathUtils.generateUUID();
  23379. _this.type = 'Shape';
  23380. _this.holes = [];
  23381. return _this;
  23382. }
  23383. var _proto = Shape.prototype;
  23384. _proto.getPointsHoles = function getPointsHoles(divisions) {
  23385. var holesPts = [];
  23386. for (var i = 0, l = this.holes.length; i < l; i++) {
  23387. holesPts[i] = this.holes[i].getPoints(divisions);
  23388. }
  23389. return holesPts;
  23390. } // get points of shape and holes (keypoints based on segments parameter)
  23391. ;
  23392. _proto.extractPoints = function extractPoints(divisions) {
  23393. return {
  23394. shape: this.getPoints(divisions),
  23395. holes: this.getPointsHoles(divisions)
  23396. };
  23397. };
  23398. _proto.copy = function copy(source) {
  23399. _Path.prototype.copy.call(this, source);
  23400. this.holes = [];
  23401. for (var i = 0, l = source.holes.length; i < l; i++) {
  23402. var hole = source.holes[i];
  23403. this.holes.push(hole.clone());
  23404. }
  23405. return this;
  23406. };
  23407. _proto.toJSON = function toJSON() {
  23408. var data = _Path.prototype.toJSON.call(this);
  23409. data.uuid = this.uuid;
  23410. data.holes = [];
  23411. for (var i = 0, l = this.holes.length; i < l; i++) {
  23412. var hole = this.holes[i];
  23413. data.holes.push(hole.toJSON());
  23414. }
  23415. return data;
  23416. };
  23417. _proto.fromJSON = function fromJSON(json) {
  23418. _Path.prototype.fromJSON.call(this, json);
  23419. this.uuid = json.uuid;
  23420. this.holes = [];
  23421. for (var i = 0, l = json.holes.length; i < l; i++) {
  23422. var hole = json.holes[i];
  23423. this.holes.push(new Path().fromJSON(hole));
  23424. }
  23425. return this;
  23426. };
  23427. return Shape;
  23428. }(Path);
  23429. var Light = /*#__PURE__*/function (_Object3D) {
  23430. _inheritsLoose(Light, _Object3D);
  23431. function Light(color, intensity) {
  23432. var _this;
  23433. if (intensity === void 0) {
  23434. intensity = 1;
  23435. }
  23436. _this = _Object3D.call(this) || this;
  23437. _this.type = 'Light';
  23438. _this.color = new Color(color);
  23439. _this.intensity = intensity;
  23440. return _this;
  23441. }
  23442. var _proto = Light.prototype;
  23443. _proto.copy = function copy(source) {
  23444. _Object3D.prototype.copy.call(this, source);
  23445. this.color.copy(source.color);
  23446. this.intensity = source.intensity;
  23447. return this;
  23448. };
  23449. _proto.toJSON = function toJSON(meta) {
  23450. var data = _Object3D.prototype.toJSON.call(this, meta);
  23451. data.object.color = this.color.getHex();
  23452. data.object.intensity = this.intensity;
  23453. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23454. if (this.distance !== undefined) data.object.distance = this.distance;
  23455. if (this.angle !== undefined) data.object.angle = this.angle;
  23456. if (this.decay !== undefined) data.object.decay = this.decay;
  23457. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23458. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23459. return data;
  23460. };
  23461. return Light;
  23462. }(Object3D);
  23463. Light.prototype.isLight = true;
  23464. var HemisphereLight = /*#__PURE__*/function (_Light) {
  23465. _inheritsLoose(HemisphereLight, _Light);
  23466. function HemisphereLight(skyColor, groundColor, intensity) {
  23467. var _this;
  23468. _this = _Light.call(this, skyColor, intensity) || this;
  23469. _this.type = 'HemisphereLight';
  23470. _this.position.copy(Object3D.DefaultUp);
  23471. _this.updateMatrix();
  23472. _this.groundColor = new Color(groundColor);
  23473. return _this;
  23474. }
  23475. var _proto = HemisphereLight.prototype;
  23476. _proto.copy = function copy(source) {
  23477. Light.prototype.copy.call(this, source);
  23478. this.groundColor.copy(source.groundColor);
  23479. return this;
  23480. };
  23481. return HemisphereLight;
  23482. }(Light);
  23483. HemisphereLight.prototype.isHemisphereLight = true;
  23484. var _projScreenMatrix = /*@__PURE__*/new Matrix4();
  23485. var _lightPositionWorld = /*@__PURE__*/new Vector3();
  23486. var _lookTarget = /*@__PURE__*/new Vector3();
  23487. var LightShadow = /*#__PURE__*/function () {
  23488. function LightShadow(camera) {
  23489. this.camera = camera;
  23490. this.bias = 0;
  23491. this.normalBias = 0;
  23492. this.radius = 1;
  23493. this.mapSize = new Vector2(512, 512);
  23494. this.map = null;
  23495. this.mapPass = null;
  23496. this.matrix = new Matrix4();
  23497. this.autoUpdate = true;
  23498. this.needsUpdate = false;
  23499. this._frustum = new Frustum();
  23500. this._frameExtents = new Vector2(1, 1);
  23501. this._viewportCount = 1;
  23502. this._viewports = [new Vector4(0, 0, 1, 1)];
  23503. }
  23504. var _proto = LightShadow.prototype;
  23505. _proto.getViewportCount = function getViewportCount() {
  23506. return this._viewportCount;
  23507. };
  23508. _proto.getFrustum = function getFrustum() {
  23509. return this._frustum;
  23510. };
  23511. _proto.updateMatrices = function updateMatrices(light) {
  23512. var shadowCamera = this.camera;
  23513. var shadowMatrix = this.matrix;
  23514. _lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23515. shadowCamera.position.copy(_lightPositionWorld);
  23516. _lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23517. shadowCamera.lookAt(_lookTarget);
  23518. shadowCamera.updateMatrixWorld();
  23519. _projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23520. this._frustum.setFromProjectionMatrix(_projScreenMatrix);
  23521. 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);
  23522. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23523. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23524. };
  23525. _proto.getViewport = function getViewport(viewportIndex) {
  23526. return this._viewports[viewportIndex];
  23527. };
  23528. _proto.getFrameExtents = function getFrameExtents() {
  23529. return this._frameExtents;
  23530. };
  23531. _proto.copy = function copy(source) {
  23532. this.camera = source.camera.clone();
  23533. this.bias = source.bias;
  23534. this.radius = source.radius;
  23535. this.mapSize.copy(source.mapSize);
  23536. return this;
  23537. };
  23538. _proto.clone = function clone() {
  23539. return new this.constructor().copy(this);
  23540. };
  23541. _proto.toJSON = function toJSON() {
  23542. var object = {};
  23543. if (this.bias !== 0) object.bias = this.bias;
  23544. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23545. if (this.radius !== 1) object.radius = this.radius;
  23546. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23547. object.camera = this.camera.toJSON(false).object;
  23548. delete object.camera.matrix;
  23549. return object;
  23550. };
  23551. return LightShadow;
  23552. }();
  23553. var SpotLightShadow = /*#__PURE__*/function (_LightShadow) {
  23554. _inheritsLoose(SpotLightShadow, _LightShadow);
  23555. function SpotLightShadow() {
  23556. var _this;
  23557. _this = _LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500)) || this;
  23558. _this.focus = 1;
  23559. return _this;
  23560. }
  23561. var _proto = SpotLightShadow.prototype;
  23562. _proto.updateMatrices = function updateMatrices(light) {
  23563. var camera = this.camera;
  23564. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23565. var aspect = this.mapSize.width / this.mapSize.height;
  23566. var far = light.distance || camera.far;
  23567. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23568. camera.fov = fov;
  23569. camera.aspect = aspect;
  23570. camera.far = far;
  23571. camera.updateProjectionMatrix();
  23572. }
  23573. _LightShadow.prototype.updateMatrices.call(this, light);
  23574. };
  23575. return SpotLightShadow;
  23576. }(LightShadow);
  23577. SpotLightShadow.prototype.isSpotLightShadow = true;
  23578. var SpotLight = /*#__PURE__*/function (_Light) {
  23579. _inheritsLoose(SpotLight, _Light);
  23580. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23581. var _this;
  23582. if (distance === void 0) {
  23583. distance = 0;
  23584. }
  23585. if (angle === void 0) {
  23586. angle = Math.PI / 3;
  23587. }
  23588. if (penumbra === void 0) {
  23589. penumbra = 0;
  23590. }
  23591. if (decay === void 0) {
  23592. decay = 1;
  23593. }
  23594. _this = _Light.call(this, color, intensity) || this;
  23595. _this.type = 'SpotLight';
  23596. _this.position.copy(Object3D.DefaultUp);
  23597. _this.updateMatrix();
  23598. _this.target = new Object3D();
  23599. _this.distance = distance;
  23600. _this.angle = angle;
  23601. _this.penumbra = penumbra;
  23602. _this.decay = decay; // for physically correct lights, should be 2.
  23603. _this.shadow = new SpotLightShadow();
  23604. return _this;
  23605. }
  23606. var _proto = SpotLight.prototype;
  23607. _proto.copy = function copy(source) {
  23608. _Light.prototype.copy.call(this, source);
  23609. this.distance = source.distance;
  23610. this.angle = source.angle;
  23611. this.penumbra = source.penumbra;
  23612. this.decay = source.decay;
  23613. this.target = source.target.clone();
  23614. this.shadow = source.shadow.clone();
  23615. return this;
  23616. };
  23617. _createClass(SpotLight, [{
  23618. key: "power",
  23619. get: function get() {
  23620. // intensity = power per solid angle.
  23621. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23622. return this.intensity * Math.PI;
  23623. },
  23624. set: function set(power) {
  23625. // intensity = power per solid angle.
  23626. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23627. this.intensity = power / Math.PI;
  23628. }
  23629. }]);
  23630. return SpotLight;
  23631. }(Light);
  23632. SpotLight.prototype.isSpotLight = true;
  23633. var _projScreenMatrix$1 = /*@__PURE__*/new Matrix4();
  23634. var _lightPositionWorld$1 = /*@__PURE__*/new Vector3();
  23635. var _lookTarget$1 = /*@__PURE__*/new Vector3();
  23636. var PointLightShadow = /*#__PURE__*/function (_LightShadow) {
  23637. _inheritsLoose(PointLightShadow, _LightShadow);
  23638. function PointLightShadow() {
  23639. var _this;
  23640. _this = _LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500)) || this;
  23641. _this._frameExtents = new Vector2(4, 2);
  23642. _this._viewportCount = 6;
  23643. _this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23644. // following orientation:
  23645. //
  23646. // xzXZ
  23647. // y Y
  23648. //
  23649. // X - Positive x direction
  23650. // x - Negative x direction
  23651. // Y - Positive y direction
  23652. // y - Negative y direction
  23653. // Z - Positive z direction
  23654. // z - Negative z direction
  23655. // positive X
  23656. new Vector4(2, 1, 1, 1), // negative X
  23657. new Vector4(0, 1, 1, 1), // positive Z
  23658. new Vector4(3, 1, 1, 1), // negative Z
  23659. new Vector4(1, 1, 1, 1), // positive Y
  23660. new Vector4(3, 0, 1, 1), // negative Y
  23661. new Vector4(1, 0, 1, 1)];
  23662. _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)];
  23663. _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)];
  23664. return _this;
  23665. }
  23666. var _proto = PointLightShadow.prototype;
  23667. _proto.updateMatrices = function updateMatrices(light, viewportIndex) {
  23668. if (viewportIndex === void 0) {
  23669. viewportIndex = 0;
  23670. }
  23671. var camera = this.camera;
  23672. var shadowMatrix = this.matrix;
  23673. _lightPositionWorld$1.setFromMatrixPosition(light.matrixWorld);
  23674. camera.position.copy(_lightPositionWorld$1);
  23675. _lookTarget$1.copy(camera.position);
  23676. _lookTarget$1.add(this._cubeDirections[viewportIndex]);
  23677. camera.up.copy(this._cubeUps[viewportIndex]);
  23678. camera.lookAt(_lookTarget$1);
  23679. camera.updateMatrixWorld();
  23680. shadowMatrix.makeTranslation(-_lightPositionWorld$1.x, -_lightPositionWorld$1.y, -_lightPositionWorld$1.z);
  23681. _projScreenMatrix$1.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23682. this._frustum.setFromProjectionMatrix(_projScreenMatrix$1);
  23683. };
  23684. return PointLightShadow;
  23685. }(LightShadow);
  23686. PointLightShadow.prototype.isPointLightShadow = true;
  23687. var PointLight = /*#__PURE__*/function (_Light) {
  23688. _inheritsLoose(PointLight, _Light);
  23689. function PointLight(color, intensity, distance, decay) {
  23690. var _this;
  23691. if (distance === void 0) {
  23692. distance = 0;
  23693. }
  23694. if (decay === void 0) {
  23695. decay = 1;
  23696. }
  23697. _this = _Light.call(this, color, intensity) || this;
  23698. _this.type = 'PointLight';
  23699. _this.distance = distance;
  23700. _this.decay = decay; // for physically correct lights, should be 2.
  23701. _this.shadow = new PointLightShadow();
  23702. return _this;
  23703. }
  23704. var _proto = PointLight.prototype;
  23705. _proto.copy = function copy(source) {
  23706. _Light.prototype.copy.call(this, source);
  23707. this.distance = source.distance;
  23708. this.decay = source.decay;
  23709. this.shadow = source.shadow.clone();
  23710. return this;
  23711. };
  23712. _createClass(PointLight, [{
  23713. key: "power",
  23714. get: function get() {
  23715. // intensity = power per solid angle.
  23716. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23717. return this.intensity * 4 * Math.PI;
  23718. },
  23719. set: function set(power) {
  23720. // intensity = power per solid angle.
  23721. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23722. this.intensity = power / (4 * Math.PI);
  23723. }
  23724. }]);
  23725. return PointLight;
  23726. }(Light);
  23727. PointLight.prototype.isPointLight = true;
  23728. function OrthographicCamera(left, right, top, bottom, near, far) {
  23729. if (left === void 0) {
  23730. left = -1;
  23731. }
  23732. if (right === void 0) {
  23733. right = 1;
  23734. }
  23735. if (top === void 0) {
  23736. top = 1;
  23737. }
  23738. if (bottom === void 0) {
  23739. bottom = -1;
  23740. }
  23741. if (near === void 0) {
  23742. near = 0.1;
  23743. }
  23744. if (far === void 0) {
  23745. far = 2000;
  23746. }
  23747. Camera.call(this);
  23748. this.type = 'OrthographicCamera';
  23749. this.zoom = 1;
  23750. this.view = null;
  23751. this.left = left;
  23752. this.right = right;
  23753. this.top = top;
  23754. this.bottom = bottom;
  23755. this.near = near;
  23756. this.far = far;
  23757. this.updateProjectionMatrix();
  23758. }
  23759. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23760. constructor: OrthographicCamera,
  23761. isOrthographicCamera: true,
  23762. copy: function copy(source, recursive) {
  23763. Camera.prototype.copy.call(this, source, recursive);
  23764. this.left = source.left;
  23765. this.right = source.right;
  23766. this.top = source.top;
  23767. this.bottom = source.bottom;
  23768. this.near = source.near;
  23769. this.far = source.far;
  23770. this.zoom = source.zoom;
  23771. this.view = source.view === null ? null : Object.assign({}, source.view);
  23772. return this;
  23773. },
  23774. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23775. if (this.view === null) {
  23776. this.view = {
  23777. enabled: true,
  23778. fullWidth: 1,
  23779. fullHeight: 1,
  23780. offsetX: 0,
  23781. offsetY: 0,
  23782. width: 1,
  23783. height: 1
  23784. };
  23785. }
  23786. this.view.enabled = true;
  23787. this.view.fullWidth = fullWidth;
  23788. this.view.fullHeight = fullHeight;
  23789. this.view.offsetX = x;
  23790. this.view.offsetY = y;
  23791. this.view.width = width;
  23792. this.view.height = height;
  23793. this.updateProjectionMatrix();
  23794. },
  23795. clearViewOffset: function clearViewOffset() {
  23796. if (this.view !== null) {
  23797. this.view.enabled = false;
  23798. }
  23799. this.updateProjectionMatrix();
  23800. },
  23801. updateProjectionMatrix: function updateProjectionMatrix() {
  23802. var dx = (this.right - this.left) / (2 * this.zoom);
  23803. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23804. var cx = (this.right + this.left) / 2;
  23805. var cy = (this.top + this.bottom) / 2;
  23806. var left = cx - dx;
  23807. var right = cx + dx;
  23808. var top = cy + dy;
  23809. var bottom = cy - dy;
  23810. if (this.view !== null && this.view.enabled) {
  23811. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23812. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23813. left += scaleW * this.view.offsetX;
  23814. right = left + scaleW * this.view.width;
  23815. top -= scaleH * this.view.offsetY;
  23816. bottom = top - scaleH * this.view.height;
  23817. }
  23818. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23819. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23820. },
  23821. toJSON: function toJSON(meta) {
  23822. var data = Object3D.prototype.toJSON.call(this, meta);
  23823. data.object.zoom = this.zoom;
  23824. data.object.left = this.left;
  23825. data.object.right = this.right;
  23826. data.object.top = this.top;
  23827. data.object.bottom = this.bottom;
  23828. data.object.near = this.near;
  23829. data.object.far = this.far;
  23830. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23831. return data;
  23832. }
  23833. });
  23834. var DirectionalLightShadow = /*#__PURE__*/function (_LightShadow) {
  23835. _inheritsLoose(DirectionalLightShadow, _LightShadow);
  23836. function DirectionalLightShadow() {
  23837. return _LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500)) || this;
  23838. }
  23839. return DirectionalLightShadow;
  23840. }(LightShadow);
  23841. DirectionalLightShadow.prototype.isDirectionalLightShadow = true;
  23842. var DirectionalLight = /*#__PURE__*/function (_Light) {
  23843. _inheritsLoose(DirectionalLight, _Light);
  23844. function DirectionalLight(color, intensity) {
  23845. var _this;
  23846. _this = _Light.call(this, color, intensity) || this;
  23847. _this.type = 'DirectionalLight';
  23848. _this.position.copy(Object3D.DefaultUp);
  23849. _this.updateMatrix();
  23850. _this.target = new Object3D();
  23851. _this.shadow = new DirectionalLightShadow();
  23852. return _this;
  23853. }
  23854. var _proto = DirectionalLight.prototype;
  23855. _proto.copy = function copy(source) {
  23856. _Light.prototype.copy.call(this, source);
  23857. this.target = source.target.clone();
  23858. this.shadow = source.shadow.clone();
  23859. return this;
  23860. };
  23861. return DirectionalLight;
  23862. }(Light);
  23863. DirectionalLight.prototype.isDirectionalLight = true;
  23864. var AmbientLight = /*#__PURE__*/function (_Light) {
  23865. _inheritsLoose(AmbientLight, _Light);
  23866. function AmbientLight(color, intensity) {
  23867. var _this;
  23868. _this = _Light.call(this, color, intensity) || this;
  23869. _this.type = 'AmbientLight';
  23870. return _this;
  23871. }
  23872. return AmbientLight;
  23873. }(Light);
  23874. AmbientLight.prototype.isAmbientLight = true;
  23875. var RectAreaLight = /*#__PURE__*/function (_Light) {
  23876. _inheritsLoose(RectAreaLight, _Light);
  23877. function RectAreaLight(color, intensity, width, height) {
  23878. var _this;
  23879. if (width === void 0) {
  23880. width = 10;
  23881. }
  23882. if (height === void 0) {
  23883. height = 10;
  23884. }
  23885. _this = _Light.call(this, color, intensity) || this;
  23886. _this.type = 'RectAreaLight';
  23887. _this.width = width;
  23888. _this.height = height;
  23889. return _this;
  23890. }
  23891. var _proto = RectAreaLight.prototype;
  23892. _proto.copy = function copy(source) {
  23893. _Light.prototype.copy.call(this, source);
  23894. this.width = source.width;
  23895. this.height = source.height;
  23896. return this;
  23897. };
  23898. _proto.toJSON = function toJSON(meta) {
  23899. var data = _Light.prototype.toJSON.call(this, meta);
  23900. data.object.width = this.width;
  23901. data.object.height = this.height;
  23902. return data;
  23903. };
  23904. return RectAreaLight;
  23905. }(Light);
  23906. RectAreaLight.prototype.isRectAreaLight = true;
  23907. /**
  23908. * Primary reference:
  23909. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23910. *
  23911. * Secondary reference:
  23912. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23913. */
  23914. // 3-band SH defined by 9 coefficients
  23915. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23916. function SphericalHarmonics3() {
  23917. this.coefficients = [];
  23918. for (var i = 0; i < 9; i++) {
  23919. this.coefficients.push(new Vector3());
  23920. }
  23921. }
  23922. var _proto = SphericalHarmonics3.prototype;
  23923. _proto.set = function set(coefficients) {
  23924. for (var i = 0; i < 9; i++) {
  23925. this.coefficients[i].copy(coefficients[i]);
  23926. }
  23927. return this;
  23928. };
  23929. _proto.zero = function zero() {
  23930. for (var i = 0; i < 9; i++) {
  23931. this.coefficients[i].set(0, 0, 0);
  23932. }
  23933. return this;
  23934. } // get the radiance in the direction of the normal
  23935. // target is a Vector3
  23936. ;
  23937. _proto.getAt = function getAt(normal, target) {
  23938. // normal is assumed to be unit length
  23939. var x = normal.x,
  23940. y = normal.y,
  23941. z = normal.z;
  23942. var coeff = this.coefficients; // band 0
  23943. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23944. target.addScaledVector(coeff[1], 0.488603 * y);
  23945. target.addScaledVector(coeff[2], 0.488603 * z);
  23946. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23947. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23948. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23949. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23950. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23951. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23952. return target;
  23953. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23954. // target is a Vector3
  23955. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23956. ;
  23957. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23958. // normal is assumed to be unit length
  23959. var x = normal.x,
  23960. y = normal.y,
  23961. z = normal.z;
  23962. var coeff = this.coefficients; // band 0
  23963. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23964. // band 1
  23965. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23966. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23967. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23968. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23969. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23970. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23971. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23972. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23973. return target;
  23974. };
  23975. _proto.add = function add(sh) {
  23976. for (var i = 0; i < 9; i++) {
  23977. this.coefficients[i].add(sh.coefficients[i]);
  23978. }
  23979. return this;
  23980. };
  23981. _proto.addScaledSH = function addScaledSH(sh, s) {
  23982. for (var i = 0; i < 9; i++) {
  23983. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23984. }
  23985. return this;
  23986. };
  23987. _proto.scale = function scale(s) {
  23988. for (var i = 0; i < 9; i++) {
  23989. this.coefficients[i].multiplyScalar(s);
  23990. }
  23991. return this;
  23992. };
  23993. _proto.lerp = function lerp(sh, alpha) {
  23994. for (var i = 0; i < 9; i++) {
  23995. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23996. }
  23997. return this;
  23998. };
  23999. _proto.equals = function equals(sh) {
  24000. for (var i = 0; i < 9; i++) {
  24001. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  24002. return false;
  24003. }
  24004. }
  24005. return true;
  24006. };
  24007. _proto.copy = function copy(sh) {
  24008. return this.set(sh.coefficients);
  24009. };
  24010. _proto.clone = function clone() {
  24011. return new this.constructor().copy(this);
  24012. };
  24013. _proto.fromArray = function fromArray(array, offset) {
  24014. if (offset === void 0) {
  24015. offset = 0;
  24016. }
  24017. var coefficients = this.coefficients;
  24018. for (var i = 0; i < 9; i++) {
  24019. coefficients[i].fromArray(array, offset + i * 3);
  24020. }
  24021. return this;
  24022. };
  24023. _proto.toArray = function toArray(array, offset) {
  24024. if (array === void 0) {
  24025. array = [];
  24026. }
  24027. if (offset === void 0) {
  24028. offset = 0;
  24029. }
  24030. var coefficients = this.coefficients;
  24031. for (var i = 0; i < 9; i++) {
  24032. coefficients[i].toArray(array, offset + i * 3);
  24033. }
  24034. return array;
  24035. } // evaluate the basis functions
  24036. // shBasis is an Array[ 9 ]
  24037. ;
  24038. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  24039. // normal is assumed to be unit length
  24040. var x = normal.x,
  24041. y = normal.y,
  24042. z = normal.z; // band 0
  24043. shBasis[0] = 0.282095; // band 1
  24044. shBasis[1] = 0.488603 * y;
  24045. shBasis[2] = 0.488603 * z;
  24046. shBasis[3] = 0.488603 * x; // band 2
  24047. shBasis[4] = 1.092548 * x * y;
  24048. shBasis[5] = 1.092548 * y * z;
  24049. shBasis[6] = 0.315392 * (3 * z * z - 1);
  24050. shBasis[7] = 1.092548 * x * z;
  24051. shBasis[8] = 0.546274 * (x * x - y * y);
  24052. };
  24053. return SphericalHarmonics3;
  24054. }();
  24055. SphericalHarmonics3.prototype.isSphericalHarmonics3 = true;
  24056. var LightProbe = /*#__PURE__*/function (_Light) {
  24057. _inheritsLoose(LightProbe, _Light);
  24058. function LightProbe(sh, intensity) {
  24059. var _this;
  24060. if (sh === void 0) {
  24061. sh = new SphericalHarmonics3();
  24062. }
  24063. if (intensity === void 0) {
  24064. intensity = 1;
  24065. }
  24066. _this = _Light.call(this, undefined, intensity) || this;
  24067. _this.sh = sh;
  24068. return _this;
  24069. }
  24070. var _proto = LightProbe.prototype;
  24071. _proto.copy = function copy(source) {
  24072. _Light.prototype.copy.call(this, source);
  24073. this.sh.copy(source.sh);
  24074. return this;
  24075. };
  24076. _proto.fromJSON = function fromJSON(json) {
  24077. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24078. this.sh.fromArray(json.sh);
  24079. return this;
  24080. };
  24081. _proto.toJSON = function toJSON(meta) {
  24082. var data = _Light.prototype.toJSON.call(this, meta);
  24083. data.object.sh = this.sh.toArray();
  24084. return data;
  24085. };
  24086. return LightProbe;
  24087. }(Light);
  24088. LightProbe.prototype.isLightProbe = true;
  24089. var MaterialLoader = /*#__PURE__*/function (_Loader) {
  24090. _inheritsLoose(MaterialLoader, _Loader);
  24091. function MaterialLoader(manager) {
  24092. var _this;
  24093. _this = _Loader.call(this, manager) || this;
  24094. _this.textures = {};
  24095. return _this;
  24096. }
  24097. var _proto = MaterialLoader.prototype;
  24098. _proto.load = function load(url, onLoad, onProgress, onError) {
  24099. var scope = this;
  24100. var loader = new FileLoader(scope.manager);
  24101. loader.setPath(scope.path);
  24102. loader.setRequestHeader(scope.requestHeader);
  24103. loader.setWithCredentials(scope.withCredentials);
  24104. loader.load(url, function (text) {
  24105. try {
  24106. onLoad(scope.parse(JSON.parse(text)));
  24107. } catch (e) {
  24108. if (onError) {
  24109. onError(e);
  24110. } else {
  24111. console.error(e);
  24112. }
  24113. scope.manager.itemError(url);
  24114. }
  24115. }, onProgress, onError);
  24116. };
  24117. _proto.parse = function parse(json) {
  24118. var textures = this.textures;
  24119. function getTexture(name) {
  24120. if (textures[name] === undefined) {
  24121. console.warn('THREE.MaterialLoader: Undefined texture', name);
  24122. }
  24123. return textures[name];
  24124. }
  24125. var material = new Materials[json.type]();
  24126. if (json.uuid !== undefined) material.uuid = json.uuid;
  24127. if (json.name !== undefined) material.name = json.name;
  24128. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  24129. if (json.roughness !== undefined) material.roughness = json.roughness;
  24130. if (json.metalness !== undefined) material.metalness = json.metalness;
  24131. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  24132. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  24133. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  24134. if (json.shininess !== undefined) material.shininess = json.shininess;
  24135. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  24136. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  24137. if (json.fog !== undefined) material.fog = json.fog;
  24138. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  24139. if (json.blending !== undefined) material.blending = json.blending;
  24140. if (json.combine !== undefined) material.combine = json.combine;
  24141. if (json.side !== undefined) material.side = json.side;
  24142. if (json.opacity !== undefined) material.opacity = json.opacity;
  24143. if (json.transparent !== undefined) material.transparent = json.transparent;
  24144. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  24145. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  24146. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  24147. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  24148. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  24149. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  24150. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  24151. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  24152. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  24153. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  24154. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  24155. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  24156. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  24157. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  24158. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  24159. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  24160. if (json.rotation !== undefined) material.rotation = json.rotation;
  24161. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  24162. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  24163. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  24164. if (json.scale !== undefined) material.scale = json.scale;
  24165. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  24166. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24167. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24168. if (json.skinning !== undefined) material.skinning = json.skinning;
  24169. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  24170. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  24171. if (json.dithering !== undefined) material.dithering = json.dithering;
  24172. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  24173. if (json.visible !== undefined) material.visible = json.visible;
  24174. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  24175. if (json.userData !== undefined) material.userData = json.userData;
  24176. if (json.vertexColors !== undefined) {
  24177. if (typeof json.vertexColors === 'number') {
  24178. material.vertexColors = json.vertexColors > 0 ? true : false;
  24179. } else {
  24180. material.vertexColors = json.vertexColors;
  24181. }
  24182. } // Shader Material
  24183. if (json.uniforms !== undefined) {
  24184. for (var name in json.uniforms) {
  24185. var uniform = json.uniforms[name];
  24186. material.uniforms[name] = {};
  24187. switch (uniform.type) {
  24188. case 't':
  24189. material.uniforms[name].value = getTexture(uniform.value);
  24190. break;
  24191. case 'c':
  24192. material.uniforms[name].value = new Color().setHex(uniform.value);
  24193. break;
  24194. case 'v2':
  24195. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  24196. break;
  24197. case 'v3':
  24198. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  24199. break;
  24200. case 'v4':
  24201. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  24202. break;
  24203. case 'm3':
  24204. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  24205. break;
  24206. case 'm4':
  24207. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24208. break;
  24209. default:
  24210. material.uniforms[name].value = uniform.value;
  24211. }
  24212. }
  24213. }
  24214. if (json.defines !== undefined) material.defines = json.defines;
  24215. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24216. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24217. if (json.extensions !== undefined) {
  24218. for (var key in json.extensions) {
  24219. material.extensions[key] = json.extensions[key];
  24220. }
  24221. } // Deprecated
  24222. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24223. // for PointsMaterial
  24224. if (json.size !== undefined) material.size = json.size;
  24225. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24226. if (json.map !== undefined) material.map = getTexture(json.map);
  24227. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24228. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24229. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24230. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24231. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24232. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24233. if (json.normalScale !== undefined) {
  24234. var normalScale = json.normalScale;
  24235. if (Array.isArray(normalScale) === false) {
  24236. // Blender exporter used to export a scalar. See #7459
  24237. normalScale = [normalScale, normalScale];
  24238. }
  24239. material.normalScale = new Vector2().fromArray(normalScale);
  24240. }
  24241. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24242. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24243. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24244. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24245. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24246. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24247. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24248. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24249. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24250. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24251. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24252. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24253. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24254. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24255. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24256. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24257. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24258. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24259. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24260. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24261. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24262. if (json.transmission !== undefined) material.transmission = json.transmission;
  24263. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24264. return material;
  24265. };
  24266. _proto.setTextures = function setTextures(value) {
  24267. this.textures = value;
  24268. return this;
  24269. };
  24270. return MaterialLoader;
  24271. }(Loader);
  24272. var LoaderUtils = {
  24273. decodeText: function decodeText(array) {
  24274. if (typeof TextDecoder !== 'undefined') {
  24275. return new TextDecoder().decode(array);
  24276. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24277. // throws a "maximum call stack size exceeded" error for large arrays.
  24278. var s = '';
  24279. for (var i = 0, il = array.length; i < il; i++) {
  24280. // Implicitly assumes little-endian.
  24281. s += String.fromCharCode(array[i]);
  24282. }
  24283. try {
  24284. // merges multi-byte utf-8 characters.
  24285. return decodeURIComponent(escape(s));
  24286. } catch (e) {
  24287. // see #16358
  24288. return s;
  24289. }
  24290. },
  24291. extractUrlBase: function extractUrlBase(url) {
  24292. var index = url.lastIndexOf('/');
  24293. if (index === -1) return './';
  24294. return url.substr(0, index + 1);
  24295. }
  24296. };
  24297. function InstancedBufferGeometry() {
  24298. BufferGeometry.call(this);
  24299. this.type = 'InstancedBufferGeometry';
  24300. this.instanceCount = Infinity;
  24301. }
  24302. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24303. constructor: InstancedBufferGeometry,
  24304. isInstancedBufferGeometry: true,
  24305. copy: function copy(source) {
  24306. BufferGeometry.prototype.copy.call(this, source);
  24307. this.instanceCount = source.instanceCount;
  24308. return this;
  24309. },
  24310. clone: function clone() {
  24311. return new this.constructor().copy(this);
  24312. },
  24313. toJSON: function toJSON() {
  24314. var data = BufferGeometry.prototype.toJSON.call(this);
  24315. data.instanceCount = this.instanceCount;
  24316. data.isInstancedBufferGeometry = true;
  24317. return data;
  24318. }
  24319. });
  24320. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24321. if (typeof normalized === 'number') {
  24322. meshPerAttribute = normalized;
  24323. normalized = false;
  24324. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24325. }
  24326. BufferAttribute.call(this, array, itemSize, normalized);
  24327. this.meshPerAttribute = meshPerAttribute || 1;
  24328. }
  24329. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24330. constructor: InstancedBufferAttribute,
  24331. isInstancedBufferAttribute: true,
  24332. copy: function copy(source) {
  24333. BufferAttribute.prototype.copy.call(this, source);
  24334. this.meshPerAttribute = source.meshPerAttribute;
  24335. return this;
  24336. },
  24337. toJSON: function toJSON() {
  24338. var data = BufferAttribute.prototype.toJSON.call(this);
  24339. data.meshPerAttribute = this.meshPerAttribute;
  24340. data.isInstancedBufferAttribute = true;
  24341. return data;
  24342. }
  24343. });
  24344. var BufferGeometryLoader = /*#__PURE__*/function (_Loader) {
  24345. _inheritsLoose(BufferGeometryLoader, _Loader);
  24346. function BufferGeometryLoader(manager) {
  24347. return _Loader.call(this, manager) || this;
  24348. }
  24349. var _proto = BufferGeometryLoader.prototype;
  24350. _proto.load = function load(url, onLoad, onProgress, onError) {
  24351. var scope = this;
  24352. var loader = new FileLoader(scope.manager);
  24353. loader.setPath(scope.path);
  24354. loader.setRequestHeader(scope.requestHeader);
  24355. loader.setWithCredentials(scope.withCredentials);
  24356. loader.load(url, function (text) {
  24357. try {
  24358. onLoad(scope.parse(JSON.parse(text)));
  24359. } catch (e) {
  24360. if (onError) {
  24361. onError(e);
  24362. } else {
  24363. console.error(e);
  24364. }
  24365. scope.manager.itemError(url);
  24366. }
  24367. }, onProgress, onError);
  24368. };
  24369. _proto.parse = function parse(json) {
  24370. var interleavedBufferMap = {};
  24371. var arrayBufferMap = {};
  24372. function getInterleavedBuffer(json, uuid) {
  24373. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24374. var interleavedBuffers = json.interleavedBuffers;
  24375. var interleavedBuffer = interleavedBuffers[uuid];
  24376. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24377. var array = getTypedArray(interleavedBuffer.type, buffer);
  24378. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24379. ib.uuid = interleavedBuffer.uuid;
  24380. interleavedBufferMap[uuid] = ib;
  24381. return ib;
  24382. }
  24383. function getArrayBuffer(json, uuid) {
  24384. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24385. var arrayBuffers = json.arrayBuffers;
  24386. var arrayBuffer = arrayBuffers[uuid];
  24387. var ab = new Uint32Array(arrayBuffer).buffer;
  24388. arrayBufferMap[uuid] = ab;
  24389. return ab;
  24390. }
  24391. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24392. var index = json.data.index;
  24393. if (index !== undefined) {
  24394. var typedArray = getTypedArray(index.type, index.array);
  24395. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24396. }
  24397. var attributes = json.data.attributes;
  24398. for (var key in attributes) {
  24399. var attribute = attributes[key];
  24400. var bufferAttribute = void 0;
  24401. if (attribute.isInterleavedBufferAttribute) {
  24402. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24403. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24404. } else {
  24405. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24406. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24407. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24408. }
  24409. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24410. geometry.setAttribute(key, bufferAttribute);
  24411. }
  24412. var morphAttributes = json.data.morphAttributes;
  24413. if (morphAttributes) {
  24414. for (var _key in morphAttributes) {
  24415. var attributeArray = morphAttributes[_key];
  24416. var array = [];
  24417. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24418. var _attribute = attributeArray[i];
  24419. var _bufferAttribute = void 0;
  24420. if (_attribute.isInterleavedBufferAttribute) {
  24421. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24422. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24423. } else {
  24424. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24425. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24426. }
  24427. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24428. array.push(_bufferAttribute);
  24429. }
  24430. geometry.morphAttributes[_key] = array;
  24431. }
  24432. }
  24433. var morphTargetsRelative = json.data.morphTargetsRelative;
  24434. if (morphTargetsRelative) {
  24435. geometry.morphTargetsRelative = true;
  24436. }
  24437. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24438. if (groups !== undefined) {
  24439. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24440. var group = groups[_i];
  24441. geometry.addGroup(group.start, group.count, group.materialIndex);
  24442. }
  24443. }
  24444. var boundingSphere = json.data.boundingSphere;
  24445. if (boundingSphere !== undefined) {
  24446. var center = new Vector3();
  24447. if (boundingSphere.center !== undefined) {
  24448. center.fromArray(boundingSphere.center);
  24449. }
  24450. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24451. }
  24452. if (json.name) geometry.name = json.name;
  24453. if (json.userData) geometry.userData = json.userData;
  24454. return geometry;
  24455. };
  24456. return BufferGeometryLoader;
  24457. }(Loader);
  24458. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24459. _inheritsLoose(ObjectLoader, _Loader);
  24460. function ObjectLoader(manager) {
  24461. return _Loader.call(this, manager) || this;
  24462. }
  24463. var _proto = ObjectLoader.prototype;
  24464. _proto.load = function load(url, onLoad, onProgress, onError) {
  24465. var scope = this;
  24466. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24467. this.resourcePath = this.resourcePath || path;
  24468. var loader = new FileLoader(this.manager);
  24469. loader.setPath(this.path);
  24470. loader.setRequestHeader(this.requestHeader);
  24471. loader.setWithCredentials(this.withCredentials);
  24472. loader.load(url, function (text) {
  24473. var json = null;
  24474. try {
  24475. json = JSON.parse(text);
  24476. } catch (error) {
  24477. if (onError !== undefined) onError(error);
  24478. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24479. return;
  24480. }
  24481. var metadata = json.metadata;
  24482. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24483. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24484. return;
  24485. }
  24486. scope.parse(json, onLoad);
  24487. }, onProgress, onError);
  24488. };
  24489. _proto.parse = function parse(json, onLoad) {
  24490. var animations = this.parseAnimations(json.animations);
  24491. var shapes = this.parseShapes(json.shapes);
  24492. var geometries = this.parseGeometries(json.geometries, shapes);
  24493. var images = this.parseImages(json.images, function () {
  24494. if (onLoad !== undefined) onLoad(object);
  24495. });
  24496. var textures = this.parseTextures(json.textures, images);
  24497. var materials = this.parseMaterials(json.materials, textures);
  24498. var object = this.parseObject(json.object, geometries, materials, animations);
  24499. var skeletons = this.parseSkeletons(json.skeletons, object);
  24500. this.bindSkeletons(object, skeletons); //
  24501. if (onLoad !== undefined) {
  24502. var hasImages = false;
  24503. for (var uuid in images) {
  24504. if (images[uuid] instanceof HTMLImageElement) {
  24505. hasImages = true;
  24506. break;
  24507. }
  24508. }
  24509. if (hasImages === false) onLoad(object);
  24510. }
  24511. return object;
  24512. };
  24513. _proto.parseShapes = function parseShapes(json) {
  24514. var shapes = {};
  24515. if (json !== undefined) {
  24516. for (var i = 0, l = json.length; i < l; i++) {
  24517. var shape = new Shape().fromJSON(json[i]);
  24518. shapes[shape.uuid] = shape;
  24519. }
  24520. }
  24521. return shapes;
  24522. };
  24523. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24524. var skeletons = {};
  24525. var bones = {}; // generate bone lookup table
  24526. object.traverse(function (child) {
  24527. if (child.isBone) bones[child.uuid] = child;
  24528. }); // create skeletons
  24529. if (json !== undefined) {
  24530. for (var i = 0, l = json.length; i < l; i++) {
  24531. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24532. skeletons[skeleton.uuid] = skeleton;
  24533. }
  24534. }
  24535. return skeletons;
  24536. };
  24537. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24538. var geometries = {};
  24539. var geometryShapes;
  24540. if (json !== undefined) {
  24541. var bufferGeometryLoader = new BufferGeometryLoader();
  24542. for (var i = 0, l = json.length; i < l; i++) {
  24543. var geometry = void 0;
  24544. var data = json[i];
  24545. switch (data.type) {
  24546. case 'PlaneGeometry':
  24547. case 'PlaneBufferGeometry':
  24548. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24549. break;
  24550. case 'BoxGeometry':
  24551. case 'BoxBufferGeometry':
  24552. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24553. break;
  24554. case 'CircleGeometry':
  24555. case 'CircleBufferGeometry':
  24556. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24557. break;
  24558. case 'CylinderGeometry':
  24559. case 'CylinderBufferGeometry':
  24560. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24561. break;
  24562. case 'ConeGeometry':
  24563. case 'ConeBufferGeometry':
  24564. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24565. break;
  24566. case 'SphereGeometry':
  24567. case 'SphereBufferGeometry':
  24568. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24569. break;
  24570. case 'DodecahedronGeometry':
  24571. case 'DodecahedronBufferGeometry':
  24572. case 'IcosahedronGeometry':
  24573. case 'IcosahedronBufferGeometry':
  24574. case 'OctahedronGeometry':
  24575. case 'OctahedronBufferGeometry':
  24576. case 'TetrahedronGeometry':
  24577. case 'TetrahedronBufferGeometry':
  24578. geometry = new Geometries[data.type](data.radius, data.detail);
  24579. break;
  24580. case 'RingGeometry':
  24581. case 'RingBufferGeometry':
  24582. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24583. break;
  24584. case 'TorusGeometry':
  24585. case 'TorusBufferGeometry':
  24586. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24587. break;
  24588. case 'TorusKnotGeometry':
  24589. case 'TorusKnotBufferGeometry':
  24590. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24591. break;
  24592. case 'TubeGeometry':
  24593. case 'TubeBufferGeometry':
  24594. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24595. // User defined curves or instances of CurvePath will not be deserialized.
  24596. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24597. break;
  24598. case 'LatheGeometry':
  24599. case 'LatheBufferGeometry':
  24600. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24601. break;
  24602. case 'PolyhedronGeometry':
  24603. case 'PolyhedronBufferGeometry':
  24604. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24605. break;
  24606. case 'ShapeGeometry':
  24607. case 'ShapeBufferGeometry':
  24608. geometryShapes = [];
  24609. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24610. var shape = shapes[data.shapes[j]];
  24611. geometryShapes.push(shape);
  24612. }
  24613. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24614. break;
  24615. case 'ExtrudeGeometry':
  24616. case 'ExtrudeBufferGeometry':
  24617. geometryShapes = [];
  24618. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24619. var _shape = shapes[data.shapes[_j]];
  24620. geometryShapes.push(_shape);
  24621. }
  24622. var extrudePath = data.options.extrudePath;
  24623. if (extrudePath !== undefined) {
  24624. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24625. }
  24626. geometry = new Geometries[data.type](geometryShapes, data.options);
  24627. break;
  24628. case 'BufferGeometry':
  24629. case 'InstancedBufferGeometry':
  24630. geometry = bufferGeometryLoader.parse(data);
  24631. break;
  24632. case 'Geometry':
  24633. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24634. break;
  24635. default:
  24636. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24637. continue;
  24638. }
  24639. geometry.uuid = data.uuid;
  24640. if (data.name !== undefined) geometry.name = data.name;
  24641. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24642. geometries[data.uuid] = geometry;
  24643. }
  24644. }
  24645. return geometries;
  24646. };
  24647. _proto.parseMaterials = function parseMaterials(json, textures) {
  24648. var cache = {}; // MultiMaterial
  24649. var materials = {};
  24650. if (json !== undefined) {
  24651. var loader = new MaterialLoader();
  24652. loader.setTextures(textures);
  24653. for (var i = 0, l = json.length; i < l; i++) {
  24654. var data = json[i];
  24655. if (data.type === 'MultiMaterial') {
  24656. // Deprecated
  24657. var array = [];
  24658. for (var j = 0; j < data.materials.length; j++) {
  24659. var material = data.materials[j];
  24660. if (cache[material.uuid] === undefined) {
  24661. cache[material.uuid] = loader.parse(material);
  24662. }
  24663. array.push(cache[material.uuid]);
  24664. }
  24665. materials[data.uuid] = array;
  24666. } else {
  24667. if (cache[data.uuid] === undefined) {
  24668. cache[data.uuid] = loader.parse(data);
  24669. }
  24670. materials[data.uuid] = cache[data.uuid];
  24671. }
  24672. }
  24673. }
  24674. return materials;
  24675. };
  24676. _proto.parseAnimations = function parseAnimations(json) {
  24677. var animations = {};
  24678. if (json !== undefined) {
  24679. for (var i = 0; i < json.length; i++) {
  24680. var data = json[i];
  24681. var clip = AnimationClip.parse(data);
  24682. animations[clip.uuid] = clip;
  24683. }
  24684. }
  24685. return animations;
  24686. };
  24687. _proto.parseImages = function parseImages(json, onLoad) {
  24688. var scope = this;
  24689. var images = {};
  24690. var loader;
  24691. function loadImage(url) {
  24692. scope.manager.itemStart(url);
  24693. return loader.load(url, function () {
  24694. scope.manager.itemEnd(url);
  24695. }, undefined, function () {
  24696. scope.manager.itemError(url);
  24697. scope.manager.itemEnd(url);
  24698. });
  24699. }
  24700. function deserializeImage(image) {
  24701. if (typeof image === 'string') {
  24702. var url = image;
  24703. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24704. return loadImage(path);
  24705. } else {
  24706. if (image.data) {
  24707. return {
  24708. data: getTypedArray(image.type, image.data),
  24709. width: image.width,
  24710. height: image.height
  24711. };
  24712. } else {
  24713. return null;
  24714. }
  24715. }
  24716. }
  24717. if (json !== undefined && json.length > 0) {
  24718. var manager = new LoadingManager(onLoad);
  24719. loader = new ImageLoader(manager);
  24720. loader.setCrossOrigin(this.crossOrigin);
  24721. for (var i = 0, il = json.length; i < il; i++) {
  24722. var image = json[i];
  24723. var url = image.url;
  24724. if (Array.isArray(url)) {
  24725. // load array of images e.g CubeTexture
  24726. images[image.uuid] = [];
  24727. for (var j = 0, jl = url.length; j < jl; j++) {
  24728. var currentUrl = url[j];
  24729. var deserializedImage = deserializeImage(currentUrl);
  24730. if (deserializedImage !== null) {
  24731. if (deserializedImage instanceof HTMLImageElement) {
  24732. images[image.uuid].push(deserializedImage);
  24733. } else {
  24734. // special case: handle array of data textures for cube textures
  24735. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24736. }
  24737. }
  24738. }
  24739. } else {
  24740. // load single image
  24741. var _deserializedImage = deserializeImage(image.url);
  24742. if (_deserializedImage !== null) {
  24743. images[image.uuid] = _deserializedImage;
  24744. }
  24745. }
  24746. }
  24747. }
  24748. return images;
  24749. };
  24750. _proto.parseTextures = function parseTextures(json, images) {
  24751. function parseConstant(value, type) {
  24752. if (typeof value === 'number') return value;
  24753. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24754. return type[value];
  24755. }
  24756. var textures = {};
  24757. if (json !== undefined) {
  24758. for (var i = 0, l = json.length; i < l; i++) {
  24759. var data = json[i];
  24760. if (data.image === undefined) {
  24761. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24762. }
  24763. if (images[data.image] === undefined) {
  24764. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24765. }
  24766. var texture = void 0;
  24767. var image = images[data.image];
  24768. if (Array.isArray(image)) {
  24769. texture = new CubeTexture(image);
  24770. if (image.length === 6) texture.needsUpdate = true;
  24771. } else {
  24772. if (image && image.data) {
  24773. texture = new DataTexture(image.data, image.width, image.height);
  24774. } else {
  24775. texture = new Texture(image);
  24776. }
  24777. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24778. }
  24779. texture.uuid = data.uuid;
  24780. if (data.name !== undefined) texture.name = data.name;
  24781. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24782. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24783. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24784. if (data.center !== undefined) texture.center.fromArray(data.center);
  24785. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24786. if (data.wrap !== undefined) {
  24787. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24788. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24789. }
  24790. if (data.format !== undefined) texture.format = data.format;
  24791. if (data.type !== undefined) texture.type = data.type;
  24792. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24793. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24794. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24795. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24796. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24797. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24798. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24799. textures[data.uuid] = texture;
  24800. }
  24801. }
  24802. return textures;
  24803. };
  24804. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  24805. var object;
  24806. function getGeometry(name) {
  24807. if (geometries[name] === undefined) {
  24808. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24809. }
  24810. return geometries[name];
  24811. }
  24812. function getMaterial(name) {
  24813. if (name === undefined) return undefined;
  24814. if (Array.isArray(name)) {
  24815. var array = [];
  24816. for (var i = 0, l = name.length; i < l; i++) {
  24817. var uuid = name[i];
  24818. if (materials[uuid] === undefined) {
  24819. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24820. }
  24821. array.push(materials[uuid]);
  24822. }
  24823. return array;
  24824. }
  24825. if (materials[name] === undefined) {
  24826. console.warn('THREE.ObjectLoader: Undefined material', name);
  24827. }
  24828. return materials[name];
  24829. }
  24830. var geometry, material;
  24831. switch (data.type) {
  24832. case 'Scene':
  24833. object = new Scene();
  24834. if (data.background !== undefined) {
  24835. if (Number.isInteger(data.background)) {
  24836. object.background = new Color(data.background);
  24837. }
  24838. }
  24839. if (data.fog !== undefined) {
  24840. if (data.fog.type === 'Fog') {
  24841. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24842. } else if (data.fog.type === 'FogExp2') {
  24843. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24844. }
  24845. }
  24846. break;
  24847. case 'PerspectiveCamera':
  24848. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24849. if (data.focus !== undefined) object.focus = data.focus;
  24850. if (data.zoom !== undefined) object.zoom = data.zoom;
  24851. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24852. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24853. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24854. break;
  24855. case 'OrthographicCamera':
  24856. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24857. if (data.zoom !== undefined) object.zoom = data.zoom;
  24858. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24859. break;
  24860. case 'AmbientLight':
  24861. object = new AmbientLight(data.color, data.intensity);
  24862. break;
  24863. case 'DirectionalLight':
  24864. object = new DirectionalLight(data.color, data.intensity);
  24865. break;
  24866. case 'PointLight':
  24867. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24868. break;
  24869. case 'RectAreaLight':
  24870. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24871. break;
  24872. case 'SpotLight':
  24873. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24874. break;
  24875. case 'HemisphereLight':
  24876. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24877. break;
  24878. case 'LightProbe':
  24879. object = new LightProbe().fromJSON(data);
  24880. break;
  24881. case 'SkinnedMesh':
  24882. geometry = getGeometry(data.geometry);
  24883. material = getMaterial(data.material);
  24884. object = new SkinnedMesh(geometry, material);
  24885. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24886. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24887. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24888. break;
  24889. case 'Mesh':
  24890. geometry = getGeometry(data.geometry);
  24891. material = getMaterial(data.material);
  24892. object = new Mesh(geometry, material);
  24893. break;
  24894. case 'InstancedMesh':
  24895. geometry = getGeometry(data.geometry);
  24896. material = getMaterial(data.material);
  24897. var count = data.count;
  24898. var instanceMatrix = data.instanceMatrix;
  24899. object = new InstancedMesh(geometry, material, count);
  24900. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24901. break;
  24902. case 'LOD':
  24903. object = new LOD();
  24904. break;
  24905. case 'Line':
  24906. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  24907. break;
  24908. case 'LineLoop':
  24909. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24910. break;
  24911. case 'LineSegments':
  24912. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24913. break;
  24914. case 'PointCloud':
  24915. case 'Points':
  24916. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24917. break;
  24918. case 'Sprite':
  24919. object = new Sprite(getMaterial(data.material));
  24920. break;
  24921. case 'Group':
  24922. object = new Group();
  24923. break;
  24924. case 'Bone':
  24925. object = new Bone();
  24926. break;
  24927. default:
  24928. object = new Object3D();
  24929. }
  24930. object.uuid = data.uuid;
  24931. if (data.name !== undefined) object.name = data.name;
  24932. if (data.matrix !== undefined) {
  24933. object.matrix.fromArray(data.matrix);
  24934. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24935. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24936. } else {
  24937. if (data.position !== undefined) object.position.fromArray(data.position);
  24938. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24939. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24940. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24941. }
  24942. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24943. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24944. if (data.shadow) {
  24945. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24946. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24947. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24948. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24949. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24950. }
  24951. if (data.visible !== undefined) object.visible = data.visible;
  24952. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24953. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24954. if (data.userData !== undefined) object.userData = data.userData;
  24955. if (data.layers !== undefined) object.layers.mask = data.layers;
  24956. if (data.children !== undefined) {
  24957. var children = data.children;
  24958. for (var i = 0; i < children.length; i++) {
  24959. object.add(this.parseObject(children[i], geometries, materials, animations));
  24960. }
  24961. }
  24962. if (data.animations !== undefined) {
  24963. var objectAnimations = data.animations;
  24964. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24965. var uuid = objectAnimations[_i];
  24966. object.animations.push(animations[uuid]);
  24967. }
  24968. }
  24969. if (data.type === 'LOD') {
  24970. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24971. var levels = data.levels;
  24972. for (var l = 0; l < levels.length; l++) {
  24973. var level = levels[l];
  24974. var child = object.getObjectByProperty('uuid', level.object);
  24975. if (child !== undefined) {
  24976. object.addLevel(child, level.distance);
  24977. }
  24978. }
  24979. }
  24980. return object;
  24981. };
  24982. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24983. if (Object.keys(skeletons).length === 0) return;
  24984. object.traverse(function (child) {
  24985. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24986. var skeleton = skeletons[child.skeleton];
  24987. if (skeleton === undefined) {
  24988. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24989. } else {
  24990. child.bind(skeleton, child.bindMatrix);
  24991. }
  24992. }
  24993. });
  24994. }
  24995. /* DEPRECATED */
  24996. ;
  24997. _proto.setTexturePath = function setTexturePath(value) {
  24998. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24999. return this.setResourcePath(value);
  25000. };
  25001. return ObjectLoader;
  25002. }(Loader);
  25003. var TEXTURE_MAPPING = {
  25004. UVMapping: UVMapping,
  25005. CubeReflectionMapping: CubeReflectionMapping,
  25006. CubeRefractionMapping: CubeRefractionMapping,
  25007. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  25008. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  25009. CubeUVReflectionMapping: CubeUVReflectionMapping,
  25010. CubeUVRefractionMapping: CubeUVRefractionMapping
  25011. };
  25012. var TEXTURE_WRAPPING = {
  25013. RepeatWrapping: RepeatWrapping,
  25014. ClampToEdgeWrapping: ClampToEdgeWrapping,
  25015. MirroredRepeatWrapping: MirroredRepeatWrapping
  25016. };
  25017. var TEXTURE_FILTER = {
  25018. NearestFilter: NearestFilter,
  25019. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  25020. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  25021. LinearFilter: LinearFilter,
  25022. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  25023. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  25024. };
  25025. function ImageBitmapLoader(manager) {
  25026. if (typeof createImageBitmap === 'undefined') {
  25027. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  25028. }
  25029. if (typeof fetch === 'undefined') {
  25030. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  25031. }
  25032. Loader.call(this, manager);
  25033. this.options = {
  25034. premultiplyAlpha: 'none'
  25035. };
  25036. }
  25037. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25038. constructor: ImageBitmapLoader,
  25039. isImageBitmapLoader: true,
  25040. setOptions: function setOptions(options) {
  25041. this.options = options;
  25042. return this;
  25043. },
  25044. load: function load(url, onLoad, onProgress, onError) {
  25045. if (url === undefined) url = '';
  25046. if (this.path !== undefined) url = this.path + url;
  25047. url = this.manager.resolveURL(url);
  25048. var scope = this;
  25049. var cached = Cache.get(url);
  25050. if (cached !== undefined) {
  25051. scope.manager.itemStart(url);
  25052. setTimeout(function () {
  25053. if (onLoad) onLoad(cached);
  25054. scope.manager.itemEnd(url);
  25055. }, 0);
  25056. return cached;
  25057. }
  25058. var fetchOptions = {};
  25059. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  25060. fetchOptions.headers = this.requestHeader;
  25061. fetch(url, fetchOptions).then(function (res) {
  25062. return res.blob();
  25063. }).then(function (blob) {
  25064. return createImageBitmap(blob, scope.options);
  25065. }).then(function (imageBitmap) {
  25066. Cache.add(url, imageBitmap);
  25067. if (onLoad) onLoad(imageBitmap);
  25068. scope.manager.itemEnd(url);
  25069. }).catch(function (e) {
  25070. if (onError) onError(e);
  25071. scope.manager.itemError(url);
  25072. scope.manager.itemEnd(url);
  25073. });
  25074. scope.manager.itemStart(url);
  25075. }
  25076. });
  25077. var ShapePath = /*#__PURE__*/function () {
  25078. function ShapePath() {
  25079. this.type = 'ShapePath';
  25080. this.color = new Color();
  25081. this.subPaths = [];
  25082. this.currentPath = null;
  25083. }
  25084. var _proto = ShapePath.prototype;
  25085. _proto.moveTo = function moveTo(x, y) {
  25086. this.currentPath = new Path();
  25087. this.subPaths.push(this.currentPath);
  25088. this.currentPath.moveTo(x, y);
  25089. return this;
  25090. };
  25091. _proto.lineTo = function lineTo(x, y) {
  25092. this.currentPath.lineTo(x, y);
  25093. return this;
  25094. };
  25095. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  25096. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  25097. return this;
  25098. };
  25099. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  25100. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  25101. return this;
  25102. };
  25103. _proto.splineThru = function splineThru(pts) {
  25104. this.currentPath.splineThru(pts);
  25105. return this;
  25106. };
  25107. _proto.toShapes = function toShapes(isCCW, noHoles) {
  25108. function toShapesNoHoles(inSubpaths) {
  25109. var shapes = [];
  25110. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  25111. var _tmpPath = inSubpaths[i];
  25112. var _tmpShape = new Shape();
  25113. _tmpShape.curves = _tmpPath.curves;
  25114. shapes.push(_tmpShape);
  25115. }
  25116. return shapes;
  25117. }
  25118. function isPointInsidePolygon(inPt, inPolygon) {
  25119. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  25120. // toggling of inside/outside at every single! intersection point of an edge
  25121. // with the horizontal line through inPt, left of inPt
  25122. // not counting lowerY endpoints of edges and whole edges on that line
  25123. var inside = false;
  25124. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  25125. var edgeLowPt = inPolygon[p];
  25126. var edgeHighPt = inPolygon[q];
  25127. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  25128. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25129. if (Math.abs(edgeDy) > Number.EPSILON) {
  25130. // not parallel
  25131. if (edgeDy < 0) {
  25132. edgeLowPt = inPolygon[q];
  25133. edgeDx = -edgeDx;
  25134. edgeHighPt = inPolygon[p];
  25135. edgeDy = -edgeDy;
  25136. }
  25137. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  25138. if (inPt.y === edgeLowPt.y) {
  25139. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  25140. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25141. } else {
  25142. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  25143. if (perpEdge === 0) return true; // inPt is on contour ?
  25144. if (perpEdge < 0) continue;
  25145. inside = !inside; // true intersection left of inPt
  25146. }
  25147. } else {
  25148. // parallel or collinear
  25149. if (inPt.y !== edgeLowPt.y) continue; // parallel
  25150. // edge lies on the same horizontal line as inPt
  25151. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  25152. // continue;
  25153. }
  25154. }
  25155. return inside;
  25156. }
  25157. var isClockWise = ShapeUtils.isClockWise;
  25158. var subPaths = this.subPaths;
  25159. if (subPaths.length === 0) return [];
  25160. if (noHoles === true) return toShapesNoHoles(subPaths);
  25161. var solid, tmpPath, tmpShape;
  25162. var shapes = [];
  25163. if (subPaths.length === 1) {
  25164. tmpPath = subPaths[0];
  25165. tmpShape = new Shape();
  25166. tmpShape.curves = tmpPath.curves;
  25167. shapes.push(tmpShape);
  25168. return shapes;
  25169. }
  25170. var holesFirst = !isClockWise(subPaths[0].getPoints());
  25171. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  25172. var betterShapeHoles = [];
  25173. var newShapes = [];
  25174. var newShapeHoles = [];
  25175. var mainIdx = 0;
  25176. var tmpPoints;
  25177. newShapes[mainIdx] = undefined;
  25178. newShapeHoles[mainIdx] = [];
  25179. for (var i = 0, l = subPaths.length; i < l; i++) {
  25180. tmpPath = subPaths[i];
  25181. tmpPoints = tmpPath.getPoints();
  25182. solid = isClockWise(tmpPoints);
  25183. solid = isCCW ? !solid : solid;
  25184. if (solid) {
  25185. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  25186. newShapes[mainIdx] = {
  25187. s: new Shape(),
  25188. p: tmpPoints
  25189. };
  25190. newShapes[mainIdx].s.curves = tmpPath.curves;
  25191. if (holesFirst) mainIdx++;
  25192. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  25193. } else {
  25194. newShapeHoles[mainIdx].push({
  25195. h: tmpPath,
  25196. p: tmpPoints[0]
  25197. }); //console.log('ccw', i);
  25198. }
  25199. } // only Holes? -> probably all Shapes with wrong orientation
  25200. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  25201. if (newShapes.length > 1) {
  25202. var ambiguous = false;
  25203. var toChange = [];
  25204. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  25205. betterShapeHoles[sIdx] = [];
  25206. }
  25207. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  25208. var sho = newShapeHoles[_sIdx];
  25209. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  25210. var ho = sho[hIdx];
  25211. var hole_unassigned = true;
  25212. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  25213. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  25214. if (_sIdx !== s2Idx) toChange.push({
  25215. froms: _sIdx,
  25216. tos: s2Idx,
  25217. hole: hIdx
  25218. });
  25219. if (hole_unassigned) {
  25220. hole_unassigned = false;
  25221. betterShapeHoles[s2Idx].push(ho);
  25222. } else {
  25223. ambiguous = true;
  25224. }
  25225. }
  25226. }
  25227. if (hole_unassigned) {
  25228. betterShapeHoles[_sIdx].push(ho);
  25229. }
  25230. }
  25231. } // console.log("ambiguous: ", ambiguous);
  25232. if (toChange.length > 0) {
  25233. // console.log("to change: ", toChange);
  25234. if (!ambiguous) newShapeHoles = betterShapeHoles;
  25235. }
  25236. }
  25237. var tmpHoles;
  25238. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  25239. tmpShape = newShapes[_i].s;
  25240. shapes.push(tmpShape);
  25241. tmpHoles = newShapeHoles[_i];
  25242. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  25243. tmpShape.holes.push(tmpHoles[j].h);
  25244. }
  25245. } //console.log("shape", shapes);
  25246. return shapes;
  25247. };
  25248. return ShapePath;
  25249. }();
  25250. var Font = /*#__PURE__*/function () {
  25251. function Font(data) {
  25252. this.type = 'Font';
  25253. this.data = data;
  25254. }
  25255. var _proto = Font.prototype;
  25256. _proto.generateShapes = function generateShapes(text, size) {
  25257. if (size === void 0) {
  25258. size = 100;
  25259. }
  25260. var shapes = [];
  25261. var paths = createPaths(text, size, this.data);
  25262. for (var p = 0, pl = paths.length; p < pl; p++) {
  25263. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25264. }
  25265. return shapes;
  25266. };
  25267. return Font;
  25268. }();
  25269. function createPaths(text, size, data) {
  25270. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25271. var scale = size / data.resolution;
  25272. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25273. var paths = [];
  25274. var offsetX = 0,
  25275. offsetY = 0;
  25276. for (var i = 0; i < chars.length; i++) {
  25277. var char = chars[i];
  25278. if (char === '\n') {
  25279. offsetX = 0;
  25280. offsetY -= line_height;
  25281. } else {
  25282. var ret = createPath(char, scale, offsetX, offsetY, data);
  25283. offsetX += ret.offsetX;
  25284. paths.push(ret.path);
  25285. }
  25286. }
  25287. return paths;
  25288. }
  25289. function createPath(char, scale, offsetX, offsetY, data) {
  25290. var glyph = data.glyphs[char] || data.glyphs['?'];
  25291. if (!glyph) {
  25292. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25293. return;
  25294. }
  25295. var path = new ShapePath();
  25296. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25297. if (glyph.o) {
  25298. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25299. for (var i = 0, l = outline.length; i < l;) {
  25300. var action = outline[i++];
  25301. switch (action) {
  25302. case 'm':
  25303. // moveTo
  25304. x = outline[i++] * scale + offsetX;
  25305. y = outline[i++] * scale + offsetY;
  25306. path.moveTo(x, y);
  25307. break;
  25308. case 'l':
  25309. // lineTo
  25310. x = outline[i++] * scale + offsetX;
  25311. y = outline[i++] * scale + offsetY;
  25312. path.lineTo(x, y);
  25313. break;
  25314. case 'q':
  25315. // quadraticCurveTo
  25316. cpx = outline[i++] * scale + offsetX;
  25317. cpy = outline[i++] * scale + offsetY;
  25318. cpx1 = outline[i++] * scale + offsetX;
  25319. cpy1 = outline[i++] * scale + offsetY;
  25320. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25321. break;
  25322. case 'b':
  25323. // bezierCurveTo
  25324. cpx = outline[i++] * scale + offsetX;
  25325. cpy = outline[i++] * scale + offsetY;
  25326. cpx1 = outline[i++] * scale + offsetX;
  25327. cpy1 = outline[i++] * scale + offsetY;
  25328. cpx2 = outline[i++] * scale + offsetX;
  25329. cpy2 = outline[i++] * scale + offsetY;
  25330. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25331. break;
  25332. }
  25333. }
  25334. }
  25335. return {
  25336. offsetX: glyph.ha * scale,
  25337. path: path
  25338. };
  25339. }
  25340. Font.prototype.isFont = true;
  25341. var FontLoader = /*#__PURE__*/function (_Loader) {
  25342. _inheritsLoose(FontLoader, _Loader);
  25343. function FontLoader(manager) {
  25344. return _Loader.call(this, manager) || this;
  25345. }
  25346. var _proto = FontLoader.prototype;
  25347. _proto.load = function load(url, onLoad, onProgress, onError) {
  25348. var scope = this;
  25349. var loader = new FileLoader(this.manager);
  25350. loader.setPath(this.path);
  25351. loader.setRequestHeader(this.requestHeader);
  25352. loader.setWithCredentials(scope.withCredentials);
  25353. loader.load(url, function (text) {
  25354. var json;
  25355. try {
  25356. json = JSON.parse(text);
  25357. } catch (e) {
  25358. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25359. json = JSON.parse(text.substring(65, text.length - 2));
  25360. }
  25361. var font = scope.parse(json);
  25362. if (onLoad) onLoad(font);
  25363. }, onProgress, onError);
  25364. };
  25365. _proto.parse = function parse(json) {
  25366. return new Font(json);
  25367. };
  25368. return FontLoader;
  25369. }(Loader);
  25370. var _context;
  25371. var AudioContext = {
  25372. getContext: function getContext() {
  25373. if (_context === undefined) {
  25374. _context = new (window.AudioContext || window.webkitAudioContext)();
  25375. }
  25376. return _context;
  25377. },
  25378. setContext: function setContext(value) {
  25379. _context = value;
  25380. }
  25381. };
  25382. var AudioLoader = /*#__PURE__*/function (_Loader) {
  25383. _inheritsLoose(AudioLoader, _Loader);
  25384. function AudioLoader(manager) {
  25385. return _Loader.call(this, manager) || this;
  25386. }
  25387. var _proto = AudioLoader.prototype;
  25388. _proto.load = function load(url, onLoad, onProgress, onError) {
  25389. var scope = this;
  25390. var loader = new FileLoader(this.manager);
  25391. loader.setResponseType('arraybuffer');
  25392. loader.setPath(this.path);
  25393. loader.setRequestHeader(this.requestHeader);
  25394. loader.setWithCredentials(this.withCredentials);
  25395. loader.load(url, function (buffer) {
  25396. try {
  25397. // Create a copy of the buffer. The `decodeAudioData` method
  25398. // detaches the buffer when complete, preventing reuse.
  25399. var bufferCopy = buffer.slice(0);
  25400. var context = AudioContext.getContext();
  25401. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25402. onLoad(audioBuffer);
  25403. });
  25404. } catch (e) {
  25405. if (onError) {
  25406. onError(e);
  25407. } else {
  25408. console.error(e);
  25409. }
  25410. scope.manager.itemError(url);
  25411. }
  25412. }, onProgress, onError);
  25413. };
  25414. return AudioLoader;
  25415. }(Loader);
  25416. var HemisphereLightProbe = /*#__PURE__*/function (_LightProbe) {
  25417. _inheritsLoose(HemisphereLightProbe, _LightProbe);
  25418. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25419. var _this;
  25420. if (intensity === void 0) {
  25421. intensity = 1;
  25422. }
  25423. _this = _LightProbe.call(this, undefined, intensity) || this;
  25424. var color1 = new Color().set(skyColor);
  25425. var color2 = new Color().set(groundColor);
  25426. var sky = new Vector3(color1.r, color1.g, color1.b);
  25427. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25428. var c0 = Math.sqrt(Math.PI);
  25429. var c1 = c0 * Math.sqrt(0.75);
  25430. _this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25431. _this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25432. return _this;
  25433. }
  25434. return HemisphereLightProbe;
  25435. }(LightProbe);
  25436. HemisphereLightProbe.prototype.isHemisphereLightProbe = true;
  25437. var AmbientLightProbe = /*#__PURE__*/function (_LightProbe) {
  25438. _inheritsLoose(AmbientLightProbe, _LightProbe);
  25439. function AmbientLightProbe(color, intensity) {
  25440. var _this;
  25441. if (intensity === void 0) {
  25442. intensity = 1;
  25443. }
  25444. _this = _LightProbe.call(this, undefined, intensity) || this;
  25445. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25446. _this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25447. return _this;
  25448. }
  25449. return AmbientLightProbe;
  25450. }(LightProbe);
  25451. AmbientLightProbe.prototype.isAmbientLightProbe = true;
  25452. var _eyeRight = new Matrix4();
  25453. var _eyeLeft = new Matrix4();
  25454. function StereoCamera() {
  25455. this.type = 'StereoCamera';
  25456. this.aspect = 1;
  25457. this.eyeSep = 0.064;
  25458. this.cameraL = new PerspectiveCamera();
  25459. this.cameraL.layers.enable(1);
  25460. this.cameraL.matrixAutoUpdate = false;
  25461. this.cameraR = new PerspectiveCamera();
  25462. this.cameraR.layers.enable(2);
  25463. this.cameraR.matrixAutoUpdate = false;
  25464. this._cache = {
  25465. focus: null,
  25466. fov: null,
  25467. aspect: null,
  25468. near: null,
  25469. far: null,
  25470. zoom: null,
  25471. eyeSep: null
  25472. };
  25473. }
  25474. Object.assign(StereoCamera.prototype, {
  25475. update: function update(camera) {
  25476. var cache = this._cache;
  25477. 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;
  25478. if (needsUpdate) {
  25479. cache.focus = camera.focus;
  25480. cache.fov = camera.fov;
  25481. cache.aspect = camera.aspect * this.aspect;
  25482. cache.near = camera.near;
  25483. cache.far = camera.far;
  25484. cache.zoom = camera.zoom;
  25485. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25486. // http://paulbourke.net/stereographics/stereorender/
  25487. var projectionMatrix = camera.projectionMatrix.clone();
  25488. var eyeSepHalf = cache.eyeSep / 2;
  25489. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25490. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25491. var xmin, xmax; // translate xOffset
  25492. _eyeLeft.elements[12] = -eyeSepHalf;
  25493. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25494. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25495. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25496. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25497. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25498. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25499. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25500. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25501. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25502. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25503. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25504. }
  25505. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25506. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25507. }
  25508. });
  25509. var Clock = /*#__PURE__*/function () {
  25510. function Clock(autoStart) {
  25511. this.autoStart = autoStart !== undefined ? autoStart : true;
  25512. this.startTime = 0;
  25513. this.oldTime = 0;
  25514. this.elapsedTime = 0;
  25515. this.running = false;
  25516. }
  25517. var _proto = Clock.prototype;
  25518. _proto.start = function start() {
  25519. this.startTime = now();
  25520. this.oldTime = this.startTime;
  25521. this.elapsedTime = 0;
  25522. this.running = true;
  25523. };
  25524. _proto.stop = function stop() {
  25525. this.getElapsedTime();
  25526. this.running = false;
  25527. this.autoStart = false;
  25528. };
  25529. _proto.getElapsedTime = function getElapsedTime() {
  25530. this.getDelta();
  25531. return this.elapsedTime;
  25532. };
  25533. _proto.getDelta = function getDelta() {
  25534. var diff = 0;
  25535. if (this.autoStart && !this.running) {
  25536. this.start();
  25537. return 0;
  25538. }
  25539. if (this.running) {
  25540. var newTime = now();
  25541. diff = (newTime - this.oldTime) / 1000;
  25542. this.oldTime = newTime;
  25543. this.elapsedTime += diff;
  25544. }
  25545. return diff;
  25546. };
  25547. return Clock;
  25548. }();
  25549. function now() {
  25550. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25551. }
  25552. var _position$2 = /*@__PURE__*/new Vector3();
  25553. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25554. var _scale$1 = /*@__PURE__*/new Vector3();
  25555. var _orientation = /*@__PURE__*/new Vector3();
  25556. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25557. _inheritsLoose(AudioListener, _Object3D);
  25558. function AudioListener() {
  25559. var _this;
  25560. _this = _Object3D.call(this) || this;
  25561. _this.type = 'AudioListener';
  25562. _this.context = AudioContext.getContext();
  25563. _this.gain = _this.context.createGain();
  25564. _this.gain.connect(_this.context.destination);
  25565. _this.filter = null;
  25566. _this.timeDelta = 0; // private
  25567. _this._clock = new Clock();
  25568. return _this;
  25569. }
  25570. var _proto = AudioListener.prototype;
  25571. _proto.getInput = function getInput() {
  25572. return this.gain;
  25573. };
  25574. _proto.removeFilter = function removeFilter() {
  25575. if (this.filter !== null) {
  25576. this.gain.disconnect(this.filter);
  25577. this.filter.disconnect(this.context.destination);
  25578. this.gain.connect(this.context.destination);
  25579. this.filter = null;
  25580. }
  25581. return this;
  25582. };
  25583. _proto.getFilter = function getFilter() {
  25584. return this.filter;
  25585. };
  25586. _proto.setFilter = function setFilter(value) {
  25587. if (this.filter !== null) {
  25588. this.gain.disconnect(this.filter);
  25589. this.filter.disconnect(this.context.destination);
  25590. } else {
  25591. this.gain.disconnect(this.context.destination);
  25592. }
  25593. this.filter = value;
  25594. this.gain.connect(this.filter);
  25595. this.filter.connect(this.context.destination);
  25596. return this;
  25597. };
  25598. _proto.getMasterVolume = function getMasterVolume() {
  25599. return this.gain.gain.value;
  25600. };
  25601. _proto.setMasterVolume = function setMasterVolume(value) {
  25602. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25603. return this;
  25604. };
  25605. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25606. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25607. var listener = this.context.listener;
  25608. var up = this.up;
  25609. this.timeDelta = this._clock.getDelta();
  25610. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25611. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25612. if (listener.positionX) {
  25613. // code path for Chrome (see #14393)
  25614. var endTime = this.context.currentTime + this.timeDelta;
  25615. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25616. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25617. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25618. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25619. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25620. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25621. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25622. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25623. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25624. } else {
  25625. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25626. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25627. }
  25628. };
  25629. return AudioListener;
  25630. }(Object3D);
  25631. var Audio = /*#__PURE__*/function (_Object3D) {
  25632. _inheritsLoose(Audio, _Object3D);
  25633. function Audio(listener) {
  25634. var _this;
  25635. _this = _Object3D.call(this) || this;
  25636. _this.type = 'Audio';
  25637. _this.listener = listener;
  25638. _this.context = listener.context;
  25639. _this.gain = _this.context.createGain();
  25640. _this.gain.connect(listener.getInput());
  25641. _this.autoplay = false;
  25642. _this.buffer = null;
  25643. _this.detune = 0;
  25644. _this.loop = false;
  25645. _this.loopStart = 0;
  25646. _this.loopEnd = 0;
  25647. _this.offset = 0;
  25648. _this.duration = undefined;
  25649. _this.playbackRate = 1;
  25650. _this.isPlaying = false;
  25651. _this.hasPlaybackControl = true;
  25652. _this.source = null;
  25653. _this.sourceType = 'empty';
  25654. _this._startedAt = 0;
  25655. _this._progress = 0;
  25656. _this._connected = false;
  25657. _this.filters = [];
  25658. return _this;
  25659. }
  25660. var _proto = Audio.prototype;
  25661. _proto.getOutput = function getOutput() {
  25662. return this.gain;
  25663. };
  25664. _proto.setNodeSource = function setNodeSource(audioNode) {
  25665. this.hasPlaybackControl = false;
  25666. this.sourceType = 'audioNode';
  25667. this.source = audioNode;
  25668. this.connect();
  25669. return this;
  25670. };
  25671. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25672. this.hasPlaybackControl = false;
  25673. this.sourceType = 'mediaNode';
  25674. this.source = this.context.createMediaElementSource(mediaElement);
  25675. this.connect();
  25676. return this;
  25677. };
  25678. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25679. this.hasPlaybackControl = false;
  25680. this.sourceType = 'mediaStreamNode';
  25681. this.source = this.context.createMediaStreamSource(mediaStream);
  25682. this.connect();
  25683. return this;
  25684. };
  25685. _proto.setBuffer = function setBuffer(audioBuffer) {
  25686. this.buffer = audioBuffer;
  25687. this.sourceType = 'buffer';
  25688. if (this.autoplay) this.play();
  25689. return this;
  25690. };
  25691. _proto.play = function play(delay) {
  25692. if (delay === void 0) {
  25693. delay = 0;
  25694. }
  25695. if (this.isPlaying === true) {
  25696. console.warn('THREE.Audio: Audio is already playing.');
  25697. return;
  25698. }
  25699. if (this.hasPlaybackControl === false) {
  25700. console.warn('THREE.Audio: this Audio has no playback control.');
  25701. return;
  25702. }
  25703. this._startedAt = this.context.currentTime + delay;
  25704. var source = this.context.createBufferSource();
  25705. source.buffer = this.buffer;
  25706. source.loop = this.loop;
  25707. source.loopStart = this.loopStart;
  25708. source.loopEnd = this.loopEnd;
  25709. source.onended = this.onEnded.bind(this);
  25710. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25711. this.isPlaying = true;
  25712. this.source = source;
  25713. this.setDetune(this.detune);
  25714. this.setPlaybackRate(this.playbackRate);
  25715. return this.connect();
  25716. };
  25717. _proto.pause = function pause() {
  25718. if (this.hasPlaybackControl === false) {
  25719. console.warn('THREE.Audio: this Audio has no playback control.');
  25720. return;
  25721. }
  25722. if (this.isPlaying === true) {
  25723. // update current progress
  25724. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25725. if (this.loop === true) {
  25726. // ensure _progress does not exceed duration with looped audios
  25727. this._progress = this._progress % (this.duration || this.buffer.duration);
  25728. }
  25729. this.source.stop();
  25730. this.source.onended = null;
  25731. this.isPlaying = false;
  25732. }
  25733. return this;
  25734. };
  25735. _proto.stop = function stop() {
  25736. if (this.hasPlaybackControl === false) {
  25737. console.warn('THREE.Audio: this Audio has no playback control.');
  25738. return;
  25739. }
  25740. this._progress = 0;
  25741. this.source.stop();
  25742. this.source.onended = null;
  25743. this.isPlaying = false;
  25744. return this;
  25745. };
  25746. _proto.connect = function connect() {
  25747. if (this.filters.length > 0) {
  25748. this.source.connect(this.filters[0]);
  25749. for (var i = 1, l = this.filters.length; i < l; i++) {
  25750. this.filters[i - 1].connect(this.filters[i]);
  25751. }
  25752. this.filters[this.filters.length - 1].connect(this.getOutput());
  25753. } else {
  25754. this.source.connect(this.getOutput());
  25755. }
  25756. this._connected = true;
  25757. return this;
  25758. };
  25759. _proto.disconnect = function disconnect() {
  25760. if (this.filters.length > 0) {
  25761. this.source.disconnect(this.filters[0]);
  25762. for (var i = 1, l = this.filters.length; i < l; i++) {
  25763. this.filters[i - 1].disconnect(this.filters[i]);
  25764. }
  25765. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25766. } else {
  25767. this.source.disconnect(this.getOutput());
  25768. }
  25769. this._connected = false;
  25770. return this;
  25771. };
  25772. _proto.getFilters = function getFilters() {
  25773. return this.filters;
  25774. };
  25775. _proto.setFilters = function setFilters(value) {
  25776. if (!value) value = [];
  25777. if (this._connected === true) {
  25778. this.disconnect();
  25779. this.filters = value.slice();
  25780. this.connect();
  25781. } else {
  25782. this.filters = value.slice();
  25783. }
  25784. return this;
  25785. };
  25786. _proto.setDetune = function setDetune(value) {
  25787. this.detune = value;
  25788. if (this.source.detune === undefined) return; // only set detune when available
  25789. if (this.isPlaying === true) {
  25790. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25791. }
  25792. return this;
  25793. };
  25794. _proto.getDetune = function getDetune() {
  25795. return this.detune;
  25796. };
  25797. _proto.getFilter = function getFilter() {
  25798. return this.getFilters()[0];
  25799. };
  25800. _proto.setFilter = function setFilter(filter) {
  25801. return this.setFilters(filter ? [filter] : []);
  25802. };
  25803. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25804. if (this.hasPlaybackControl === false) {
  25805. console.warn('THREE.Audio: this Audio has no playback control.');
  25806. return;
  25807. }
  25808. this.playbackRate = value;
  25809. if (this.isPlaying === true) {
  25810. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25811. }
  25812. return this;
  25813. };
  25814. _proto.getPlaybackRate = function getPlaybackRate() {
  25815. return this.playbackRate;
  25816. };
  25817. _proto.onEnded = function onEnded() {
  25818. this.isPlaying = false;
  25819. };
  25820. _proto.getLoop = function getLoop() {
  25821. if (this.hasPlaybackControl === false) {
  25822. console.warn('THREE.Audio: this Audio has no playback control.');
  25823. return false;
  25824. }
  25825. return this.loop;
  25826. };
  25827. _proto.setLoop = function setLoop(value) {
  25828. if (this.hasPlaybackControl === false) {
  25829. console.warn('THREE.Audio: this Audio has no playback control.');
  25830. return;
  25831. }
  25832. this.loop = value;
  25833. if (this.isPlaying === true) {
  25834. this.source.loop = this.loop;
  25835. }
  25836. return this;
  25837. };
  25838. _proto.setLoopStart = function setLoopStart(value) {
  25839. this.loopStart = value;
  25840. return this;
  25841. };
  25842. _proto.setLoopEnd = function setLoopEnd(value) {
  25843. this.loopEnd = value;
  25844. return this;
  25845. };
  25846. _proto.getVolume = function getVolume() {
  25847. return this.gain.gain.value;
  25848. };
  25849. _proto.setVolume = function setVolume(value) {
  25850. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25851. return this;
  25852. };
  25853. return Audio;
  25854. }(Object3D);
  25855. var _position$3 = /*@__PURE__*/new Vector3();
  25856. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25857. var _scale$2 = /*@__PURE__*/new Vector3();
  25858. var _orientation$1 = /*@__PURE__*/new Vector3();
  25859. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25860. _inheritsLoose(PositionalAudio, _Audio);
  25861. function PositionalAudio(listener) {
  25862. var _this;
  25863. _this = _Audio.call(this, listener) || this;
  25864. _this.panner = _this.context.createPanner();
  25865. _this.panner.panningModel = 'HRTF';
  25866. _this.panner.connect(_this.gain);
  25867. return _this;
  25868. }
  25869. var _proto = PositionalAudio.prototype;
  25870. _proto.getOutput = function getOutput() {
  25871. return this.panner;
  25872. };
  25873. _proto.getRefDistance = function getRefDistance() {
  25874. return this.panner.refDistance;
  25875. };
  25876. _proto.setRefDistance = function setRefDistance(value) {
  25877. this.panner.refDistance = value;
  25878. return this;
  25879. };
  25880. _proto.getRolloffFactor = function getRolloffFactor() {
  25881. return this.panner.rolloffFactor;
  25882. };
  25883. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25884. this.panner.rolloffFactor = value;
  25885. return this;
  25886. };
  25887. _proto.getDistanceModel = function getDistanceModel() {
  25888. return this.panner.distanceModel;
  25889. };
  25890. _proto.setDistanceModel = function setDistanceModel(value) {
  25891. this.panner.distanceModel = value;
  25892. return this;
  25893. };
  25894. _proto.getMaxDistance = function getMaxDistance() {
  25895. return this.panner.maxDistance;
  25896. };
  25897. _proto.setMaxDistance = function setMaxDistance(value) {
  25898. this.panner.maxDistance = value;
  25899. return this;
  25900. };
  25901. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25902. this.panner.coneInnerAngle = coneInnerAngle;
  25903. this.panner.coneOuterAngle = coneOuterAngle;
  25904. this.panner.coneOuterGain = coneOuterGain;
  25905. return this;
  25906. };
  25907. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25908. _Audio.prototype.updateMatrixWorld.call(this, force);
  25909. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25910. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25911. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25912. var panner = this.panner;
  25913. if (panner.positionX) {
  25914. // code path for Chrome and Firefox (see #14393)
  25915. var endTime = this.context.currentTime + this.listener.timeDelta;
  25916. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25917. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25918. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25919. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25920. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25921. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25922. } else {
  25923. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25924. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25925. }
  25926. };
  25927. return PositionalAudio;
  25928. }(Audio);
  25929. var AudioAnalyser = /*#__PURE__*/function () {
  25930. function AudioAnalyser(audio, fftSize) {
  25931. if (fftSize === void 0) {
  25932. fftSize = 2048;
  25933. }
  25934. this.analyser = audio.context.createAnalyser();
  25935. this.analyser.fftSize = fftSize;
  25936. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25937. audio.getOutput().connect(this.analyser);
  25938. }
  25939. var _proto = AudioAnalyser.prototype;
  25940. _proto.getFrequencyData = function getFrequencyData() {
  25941. this.analyser.getByteFrequencyData(this.data);
  25942. return this.data;
  25943. };
  25944. _proto.getAverageFrequency = function getAverageFrequency() {
  25945. var value = 0;
  25946. var data = this.getFrequencyData();
  25947. for (var i = 0; i < data.length; i++) {
  25948. value += data[i];
  25949. }
  25950. return value / data.length;
  25951. };
  25952. return AudioAnalyser;
  25953. }();
  25954. function PropertyMixer(binding, typeName, valueSize) {
  25955. this.binding = binding;
  25956. this.valueSize = valueSize;
  25957. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25958. //
  25959. // interpolators can use .buffer as their .result
  25960. // the data then goes to 'incoming'
  25961. //
  25962. // 'accu0' and 'accu1' are used frame-interleaved for
  25963. // the cumulative result and are compared to detect
  25964. // changes
  25965. //
  25966. // 'orig' stores the original state of the property
  25967. //
  25968. // 'add' is used for additive cumulative results
  25969. //
  25970. // 'work' is optional and is only present for quaternion types. It is used
  25971. // to store intermediate quaternion multiplication results
  25972. switch (typeName) {
  25973. case 'quaternion':
  25974. mixFunction = this._slerp;
  25975. mixFunctionAdditive = this._slerpAdditive;
  25976. setIdentity = this._setAdditiveIdentityQuaternion;
  25977. this.buffer = new Float64Array(valueSize * 6);
  25978. this._workIndex = 5;
  25979. break;
  25980. case 'string':
  25981. case 'bool':
  25982. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25983. // additive is not relevant for non-numeric types
  25984. mixFunctionAdditive = this._select;
  25985. setIdentity = this._setAdditiveIdentityOther;
  25986. this.buffer = new Array(valueSize * 5);
  25987. break;
  25988. default:
  25989. mixFunction = this._lerp;
  25990. mixFunctionAdditive = this._lerpAdditive;
  25991. setIdentity = this._setAdditiveIdentityNumeric;
  25992. this.buffer = new Float64Array(valueSize * 5);
  25993. }
  25994. this._mixBufferRegion = mixFunction;
  25995. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25996. this._setIdentity = setIdentity;
  25997. this._origIndex = 3;
  25998. this._addIndex = 4;
  25999. this.cumulativeWeight = 0;
  26000. this.cumulativeWeightAdditive = 0;
  26001. this.useCount = 0;
  26002. this.referenceCount = 0;
  26003. }
  26004. Object.assign(PropertyMixer.prototype, {
  26005. // accumulate data in the 'incoming' region into 'accu<i>'
  26006. accumulate: function accumulate(accuIndex, weight) {
  26007. // note: happily accumulating nothing when weight = 0, the caller knows
  26008. // the weight and shouldn't have made the call in the first place
  26009. var buffer = this.buffer,
  26010. stride = this.valueSize,
  26011. offset = accuIndex * stride + stride;
  26012. var currentWeight = this.cumulativeWeight;
  26013. if (currentWeight === 0) {
  26014. // accuN := incoming * weight
  26015. for (var i = 0; i !== stride; ++i) {
  26016. buffer[offset + i] = buffer[i];
  26017. }
  26018. currentWeight = weight;
  26019. } else {
  26020. // accuN := accuN + incoming * weight
  26021. currentWeight += weight;
  26022. var mix = weight / currentWeight;
  26023. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  26024. }
  26025. this.cumulativeWeight = currentWeight;
  26026. },
  26027. // accumulate data in the 'incoming' region into 'add'
  26028. accumulateAdditive: function accumulateAdditive(weight) {
  26029. var buffer = this.buffer,
  26030. stride = this.valueSize,
  26031. offset = stride * this._addIndex;
  26032. if (this.cumulativeWeightAdditive === 0) {
  26033. // add = identity
  26034. this._setIdentity();
  26035. } // add := add + incoming * weight
  26036. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  26037. this.cumulativeWeightAdditive += weight;
  26038. },
  26039. // apply the state of 'accu<i>' to the binding when accus differ
  26040. apply: function apply(accuIndex) {
  26041. var stride = this.valueSize,
  26042. buffer = this.buffer,
  26043. offset = accuIndex * stride + stride,
  26044. weight = this.cumulativeWeight,
  26045. weightAdditive = this.cumulativeWeightAdditive,
  26046. binding = this.binding;
  26047. this.cumulativeWeight = 0;
  26048. this.cumulativeWeightAdditive = 0;
  26049. if (weight < 1) {
  26050. // accuN := accuN + original * ( 1 - cumulativeWeight )
  26051. var originalValueOffset = stride * this._origIndex;
  26052. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  26053. }
  26054. if (weightAdditive > 0) {
  26055. // accuN := accuN + additive accuN
  26056. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  26057. }
  26058. for (var i = stride, e = stride + stride; i !== e; ++i) {
  26059. if (buffer[i] !== buffer[i + stride]) {
  26060. // value has changed -> update scene graph
  26061. binding.setValue(buffer, offset);
  26062. break;
  26063. }
  26064. }
  26065. },
  26066. // remember the state of the bound property and copy it to both accus
  26067. saveOriginalState: function saveOriginalState() {
  26068. var binding = this.binding;
  26069. var buffer = this.buffer,
  26070. stride = this.valueSize,
  26071. originalValueOffset = stride * this._origIndex;
  26072. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  26073. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  26074. buffer[i] = buffer[originalValueOffset + i % stride];
  26075. } // Add to identity for additive
  26076. this._setIdentity();
  26077. this.cumulativeWeight = 0;
  26078. this.cumulativeWeightAdditive = 0;
  26079. },
  26080. // apply the state previously taken via 'saveOriginalState' to the binding
  26081. restoreOriginalState: function restoreOriginalState() {
  26082. var originalValueOffset = this.valueSize * 3;
  26083. this.binding.setValue(this.buffer, originalValueOffset);
  26084. },
  26085. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  26086. var startIndex = this._addIndex * this.valueSize;
  26087. var endIndex = startIndex + this.valueSize;
  26088. for (var i = startIndex; i < endIndex; i++) {
  26089. this.buffer[i] = 0;
  26090. }
  26091. },
  26092. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  26093. this._setAdditiveIdentityNumeric();
  26094. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  26095. },
  26096. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  26097. var startIndex = this._origIndex * this.valueSize;
  26098. var targetIndex = this._addIndex * this.valueSize;
  26099. for (var i = 0; i < this.valueSize; i++) {
  26100. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  26101. }
  26102. },
  26103. // mix functions
  26104. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  26105. if (t >= 0.5) {
  26106. for (var i = 0; i !== stride; ++i) {
  26107. buffer[dstOffset + i] = buffer[srcOffset + i];
  26108. }
  26109. }
  26110. },
  26111. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  26112. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  26113. },
  26114. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26115. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  26116. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  26117. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  26118. },
  26119. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  26120. var s = 1 - t;
  26121. for (var i = 0; i !== stride; ++i) {
  26122. var j = dstOffset + i;
  26123. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  26124. }
  26125. },
  26126. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26127. for (var i = 0; i !== stride; ++i) {
  26128. var j = dstOffset + i;
  26129. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  26130. }
  26131. }
  26132. });
  26133. // Characters [].:/ are reserved for track binding syntax.
  26134. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26135. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26136. // only latin characters, and the unicode \p{L} is not yet supported. So
  26137. // instead, we exclude reserved characters and match everything else.
  26138. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26139. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26140. // be matched to parse the rest of the track name.
  26141. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26142. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  26143. // characters. Accessor may contain any character except closing bracket.
  26144. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  26145. // contain any non-bracket characters.
  26146. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  26147. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  26148. var _supportedObjectNames = ['material', 'materials', 'bones'];
  26149. function Composite(targetGroup, path, optionalParsedPath) {
  26150. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  26151. this._targetGroup = targetGroup;
  26152. this._bindings = targetGroup.subscribe_(path, parsedPath);
  26153. }
  26154. Object.assign(Composite.prototype, {
  26155. getValue: function getValue(array, offset) {
  26156. this.bind(); // bind all binding
  26157. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26158. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  26159. if (binding !== undefined) binding.getValue(array, offset);
  26160. },
  26161. setValue: function setValue(array, offset) {
  26162. var bindings = this._bindings;
  26163. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26164. bindings[i].setValue(array, offset);
  26165. }
  26166. },
  26167. bind: function bind() {
  26168. var bindings = this._bindings;
  26169. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26170. bindings[i].bind();
  26171. }
  26172. },
  26173. unbind: function unbind() {
  26174. var bindings = this._bindings;
  26175. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26176. bindings[i].unbind();
  26177. }
  26178. }
  26179. });
  26180. function PropertyBinding(rootNode, path, parsedPath) {
  26181. this.path = path;
  26182. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  26183. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  26184. this.rootNode = rootNode;
  26185. }
  26186. Object.assign(PropertyBinding, {
  26187. Composite: Composite,
  26188. create: function create(root, path, parsedPath) {
  26189. if (!(root && root.isAnimationObjectGroup)) {
  26190. return new PropertyBinding(root, path, parsedPath);
  26191. } else {
  26192. return new PropertyBinding.Composite(root, path, parsedPath);
  26193. }
  26194. },
  26195. /**
  26196. * Replaces spaces with underscores and removes unsupported characters from
  26197. * node names, to ensure compatibility with parseTrackName().
  26198. *
  26199. * @param {string} name Node name to be sanitized.
  26200. * @return {string}
  26201. */
  26202. sanitizeNodeName: function sanitizeNodeName(name) {
  26203. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  26204. },
  26205. parseTrackName: function parseTrackName(trackName) {
  26206. var matches = _trackRe.exec(trackName);
  26207. if (!matches) {
  26208. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  26209. }
  26210. var results = {
  26211. // directoryName: matches[ 1 ], // (tschw) currently unused
  26212. nodeName: matches[2],
  26213. objectName: matches[3],
  26214. objectIndex: matches[4],
  26215. propertyName: matches[5],
  26216. // required
  26217. propertyIndex: matches[6]
  26218. };
  26219. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  26220. if (lastDot !== undefined && lastDot !== -1) {
  26221. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  26222. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26223. // 'bar' could be the objectName, or part of a nodeName (which can
  26224. // include '.' characters).
  26225. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  26226. results.nodeName = results.nodeName.substring(0, lastDot);
  26227. results.objectName = objectName;
  26228. }
  26229. }
  26230. if (results.propertyName === null || results.propertyName.length === 0) {
  26231. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  26232. }
  26233. return results;
  26234. },
  26235. findNode: function findNode(root, nodeName) {
  26236. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  26237. return root;
  26238. } // search into skeleton bones.
  26239. if (root.skeleton) {
  26240. var bone = root.skeleton.getBoneByName(nodeName);
  26241. if (bone !== undefined) {
  26242. return bone;
  26243. }
  26244. } // search into node subtree.
  26245. if (root.children) {
  26246. var searchNodeSubtree = function searchNodeSubtree(children) {
  26247. for (var i = 0; i < children.length; i++) {
  26248. var childNode = children[i];
  26249. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  26250. return childNode;
  26251. }
  26252. var result = searchNodeSubtree(childNode.children);
  26253. if (result) return result;
  26254. }
  26255. return null;
  26256. };
  26257. var subTreeNode = searchNodeSubtree(root.children);
  26258. if (subTreeNode) {
  26259. return subTreeNode;
  26260. }
  26261. }
  26262. return null;
  26263. }
  26264. });
  26265. Object.assign(PropertyBinding.prototype, {
  26266. // prototype, continued
  26267. // these are used to "bind" a nonexistent property
  26268. _getValue_unavailable: function _getValue_unavailable() {},
  26269. _setValue_unavailable: function _setValue_unavailable() {},
  26270. BindingType: {
  26271. Direct: 0,
  26272. EntireArray: 1,
  26273. ArrayElement: 2,
  26274. HasFromToArray: 3
  26275. },
  26276. Versioning: {
  26277. None: 0,
  26278. NeedsUpdate: 1,
  26279. MatrixWorldNeedsUpdate: 2
  26280. },
  26281. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26282. buffer[offset] = this.node[this.propertyName];
  26283. }, function getValue_array(buffer, offset) {
  26284. var source = this.resolvedProperty;
  26285. for (var i = 0, n = source.length; i !== n; ++i) {
  26286. buffer[offset++] = source[i];
  26287. }
  26288. }, function getValue_arrayElement(buffer, offset) {
  26289. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26290. }, function getValue_toArray(buffer, offset) {
  26291. this.resolvedProperty.toArray(buffer, offset);
  26292. }],
  26293. SetterByBindingTypeAndVersioning: [[// Direct
  26294. function setValue_direct(buffer, offset) {
  26295. this.targetObject[this.propertyName] = buffer[offset];
  26296. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26297. this.targetObject[this.propertyName] = buffer[offset];
  26298. this.targetObject.needsUpdate = true;
  26299. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26300. this.targetObject[this.propertyName] = buffer[offset];
  26301. this.targetObject.matrixWorldNeedsUpdate = true;
  26302. }], [// EntireArray
  26303. function setValue_array(buffer, offset) {
  26304. var dest = this.resolvedProperty;
  26305. for (var i = 0, n = dest.length; i !== n; ++i) {
  26306. dest[i] = buffer[offset++];
  26307. }
  26308. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26309. var dest = this.resolvedProperty;
  26310. for (var i = 0, n = dest.length; i !== n; ++i) {
  26311. dest[i] = buffer[offset++];
  26312. }
  26313. this.targetObject.needsUpdate = true;
  26314. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26315. var dest = this.resolvedProperty;
  26316. for (var i = 0, n = dest.length; i !== n; ++i) {
  26317. dest[i] = buffer[offset++];
  26318. }
  26319. this.targetObject.matrixWorldNeedsUpdate = true;
  26320. }], [// ArrayElement
  26321. function setValue_arrayElement(buffer, offset) {
  26322. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26323. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26324. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26325. this.targetObject.needsUpdate = true;
  26326. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26327. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26328. this.targetObject.matrixWorldNeedsUpdate = true;
  26329. }], [// HasToFromArray
  26330. function setValue_fromArray(buffer, offset) {
  26331. this.resolvedProperty.fromArray(buffer, offset);
  26332. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26333. this.resolvedProperty.fromArray(buffer, offset);
  26334. this.targetObject.needsUpdate = true;
  26335. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26336. this.resolvedProperty.fromArray(buffer, offset);
  26337. this.targetObject.matrixWorldNeedsUpdate = true;
  26338. }]],
  26339. getValue: function getValue_unbound(targetArray, offset) {
  26340. this.bind();
  26341. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26342. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26343. // prototype version of these methods with one that represents
  26344. // the bound state. When the property is not found, the methods
  26345. // become no-ops.
  26346. },
  26347. setValue: function getValue_unbound(sourceArray, offset) {
  26348. this.bind();
  26349. this.setValue(sourceArray, offset);
  26350. },
  26351. // create getter / setter pair for a property in the scene graph
  26352. bind: function bind() {
  26353. var targetObject = this.node;
  26354. var parsedPath = this.parsedPath;
  26355. var objectName = parsedPath.objectName;
  26356. var propertyName = parsedPath.propertyName;
  26357. var propertyIndex = parsedPath.propertyIndex;
  26358. if (!targetObject) {
  26359. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26360. this.node = targetObject;
  26361. } // set fail state so we can just 'return' on error
  26362. this.getValue = this._getValue_unavailable;
  26363. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26364. if (!targetObject) {
  26365. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26366. return;
  26367. }
  26368. if (objectName) {
  26369. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26370. switch (objectName) {
  26371. case 'materials':
  26372. if (!targetObject.material) {
  26373. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26374. return;
  26375. }
  26376. if (!targetObject.material.materials) {
  26377. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26378. return;
  26379. }
  26380. targetObject = targetObject.material.materials;
  26381. break;
  26382. case 'bones':
  26383. if (!targetObject.skeleton) {
  26384. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26385. return;
  26386. } // potential future optimization: skip this if propertyIndex is already an integer
  26387. // and convert the integer string to a true integer.
  26388. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26389. for (var i = 0; i < targetObject.length; i++) {
  26390. if (targetObject[i].name === objectIndex) {
  26391. objectIndex = i;
  26392. break;
  26393. }
  26394. }
  26395. break;
  26396. default:
  26397. if (targetObject[objectName] === undefined) {
  26398. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26399. return;
  26400. }
  26401. targetObject = targetObject[objectName];
  26402. }
  26403. if (objectIndex !== undefined) {
  26404. if (targetObject[objectIndex] === undefined) {
  26405. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26406. return;
  26407. }
  26408. targetObject = targetObject[objectIndex];
  26409. }
  26410. } // resolve property
  26411. var nodeProperty = targetObject[propertyName];
  26412. if (nodeProperty === undefined) {
  26413. var nodeName = parsedPath.nodeName;
  26414. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26415. return;
  26416. } // determine versioning scheme
  26417. var versioning = this.Versioning.None;
  26418. this.targetObject = targetObject;
  26419. if (targetObject.needsUpdate !== undefined) {
  26420. // material
  26421. versioning = this.Versioning.NeedsUpdate;
  26422. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26423. // node transform
  26424. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26425. } // determine how the property gets bound
  26426. var bindingType = this.BindingType.Direct;
  26427. if (propertyIndex !== undefined) {
  26428. // access a sub element of the property array (only primitives are supported right now)
  26429. if (propertyName === 'morphTargetInfluences') {
  26430. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26431. // support resolving morphTarget names into indices.
  26432. if (!targetObject.geometry) {
  26433. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26434. return;
  26435. }
  26436. if (targetObject.geometry.isBufferGeometry) {
  26437. if (!targetObject.geometry.morphAttributes) {
  26438. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26439. return;
  26440. }
  26441. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26442. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26443. }
  26444. } else {
  26445. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26446. return;
  26447. }
  26448. }
  26449. bindingType = this.BindingType.ArrayElement;
  26450. this.resolvedProperty = nodeProperty;
  26451. this.propertyIndex = propertyIndex;
  26452. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26453. // must use copy for Object3D.Euler/Quaternion
  26454. bindingType = this.BindingType.HasFromToArray;
  26455. this.resolvedProperty = nodeProperty;
  26456. } else if (Array.isArray(nodeProperty)) {
  26457. bindingType = this.BindingType.EntireArray;
  26458. this.resolvedProperty = nodeProperty;
  26459. } else {
  26460. this.propertyName = propertyName;
  26461. } // select getter / setter
  26462. this.getValue = this.GetterByBindingType[bindingType];
  26463. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26464. },
  26465. unbind: function unbind() {
  26466. this.node = null; // back to the prototype version of getValue / setValue
  26467. // note: avoiding to mutate the shape of 'this' via 'delete'
  26468. this.getValue = this._getValue_unbound;
  26469. this.setValue = this._setValue_unbound;
  26470. }
  26471. }); // DECLARE ALIAS AFTER assign prototype
  26472. Object.assign(PropertyBinding.prototype, {
  26473. // initial state of these methods that calls 'bind'
  26474. _getValue_unbound: PropertyBinding.prototype.getValue,
  26475. _setValue_unbound: PropertyBinding.prototype.setValue
  26476. });
  26477. /**
  26478. *
  26479. * A group of objects that receives a shared animation state.
  26480. *
  26481. * Usage:
  26482. *
  26483. * - Add objects you would otherwise pass as 'root' to the
  26484. * constructor or the .clipAction method of AnimationMixer.
  26485. *
  26486. * - Instead pass this object as 'root'.
  26487. *
  26488. * - You can also add and remove objects later when the mixer
  26489. * is running.
  26490. *
  26491. * Note:
  26492. *
  26493. * Objects of this class appear as one object to the mixer,
  26494. * so cache control of the individual objects must be done
  26495. * on the group.
  26496. *
  26497. * Limitation:
  26498. *
  26499. * - The animated properties must be compatible among the
  26500. * all objects in the group.
  26501. *
  26502. * - A single property can either be controlled through a
  26503. * target group or directly, but not both.
  26504. */
  26505. function AnimationObjectGroup() {
  26506. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26507. this._objects = Array.prototype.slice.call(arguments);
  26508. this.nCachedObjects_ = 0; // threshold
  26509. // note: read by PropertyBinding.Composite
  26510. var indices = {};
  26511. this._indicesByUUID = indices; // for bookkeeping
  26512. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26513. indices[arguments[i].uuid] = i;
  26514. }
  26515. this._paths = []; // inside: string
  26516. this._parsedPaths = []; // inside: { we don't care, here }
  26517. this._bindings = []; // inside: Array< PropertyBinding >
  26518. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26519. var scope = this;
  26520. this.stats = {
  26521. objects: {
  26522. get total() {
  26523. return scope._objects.length;
  26524. },
  26525. get inUse() {
  26526. return this.total - scope.nCachedObjects_;
  26527. }
  26528. },
  26529. get bindingsPerObject() {
  26530. return scope._bindings.length;
  26531. }
  26532. };
  26533. }
  26534. Object.assign(AnimationObjectGroup.prototype, {
  26535. isAnimationObjectGroup: true,
  26536. add: function add() {
  26537. var objects = this._objects,
  26538. indicesByUUID = this._indicesByUUID,
  26539. paths = this._paths,
  26540. parsedPaths = this._parsedPaths,
  26541. bindings = this._bindings,
  26542. nBindings = bindings.length;
  26543. var knownObject = undefined,
  26544. nObjects = objects.length,
  26545. nCachedObjects = this.nCachedObjects_;
  26546. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26547. var object = arguments[i],
  26548. uuid = object.uuid;
  26549. var index = indicesByUUID[uuid];
  26550. if (index === undefined) {
  26551. // unknown object -> add it to the ACTIVE region
  26552. index = nObjects++;
  26553. indicesByUUID[uuid] = index;
  26554. objects.push(object); // accounting is done, now do the same for all bindings
  26555. for (var j = 0, m = nBindings; j !== m; ++j) {
  26556. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26557. }
  26558. } else if (index < nCachedObjects) {
  26559. knownObject = objects[index]; // move existing object to the ACTIVE region
  26560. var firstActiveIndex = --nCachedObjects,
  26561. lastCachedObject = objects[firstActiveIndex];
  26562. indicesByUUID[lastCachedObject.uuid] = index;
  26563. objects[index] = lastCachedObject;
  26564. indicesByUUID[uuid] = firstActiveIndex;
  26565. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26566. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26567. var bindingsForPath = bindings[_j],
  26568. lastCached = bindingsForPath[firstActiveIndex];
  26569. var binding = bindingsForPath[index];
  26570. bindingsForPath[index] = lastCached;
  26571. if (binding === undefined) {
  26572. // since we do not bother to create new bindings
  26573. // for objects that are cached, the binding may
  26574. // or may not exist
  26575. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26576. }
  26577. bindingsForPath[firstActiveIndex] = binding;
  26578. }
  26579. } else if (objects[index] !== knownObject) {
  26580. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26581. } // else the object is already where we want it to be
  26582. } // for arguments
  26583. this.nCachedObjects_ = nCachedObjects;
  26584. },
  26585. remove: function remove() {
  26586. var objects = this._objects,
  26587. indicesByUUID = this._indicesByUUID,
  26588. bindings = this._bindings,
  26589. nBindings = bindings.length;
  26590. var nCachedObjects = this.nCachedObjects_;
  26591. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26592. var object = arguments[i],
  26593. uuid = object.uuid,
  26594. index = indicesByUUID[uuid];
  26595. if (index !== undefined && index >= nCachedObjects) {
  26596. // move existing object into the CACHED region
  26597. var lastCachedIndex = nCachedObjects++,
  26598. firstActiveObject = objects[lastCachedIndex];
  26599. indicesByUUID[firstActiveObject.uuid] = index;
  26600. objects[index] = firstActiveObject;
  26601. indicesByUUID[uuid] = lastCachedIndex;
  26602. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26603. for (var j = 0, m = nBindings; j !== m; ++j) {
  26604. var bindingsForPath = bindings[j],
  26605. firstActive = bindingsForPath[lastCachedIndex],
  26606. binding = bindingsForPath[index];
  26607. bindingsForPath[index] = firstActive;
  26608. bindingsForPath[lastCachedIndex] = binding;
  26609. }
  26610. }
  26611. } // for arguments
  26612. this.nCachedObjects_ = nCachedObjects;
  26613. },
  26614. // remove & forget
  26615. uncache: function uncache() {
  26616. var objects = this._objects,
  26617. indicesByUUID = this._indicesByUUID,
  26618. bindings = this._bindings,
  26619. nBindings = bindings.length;
  26620. var nCachedObjects = this.nCachedObjects_,
  26621. nObjects = objects.length;
  26622. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26623. var object = arguments[i],
  26624. uuid = object.uuid,
  26625. index = indicesByUUID[uuid];
  26626. if (index !== undefined) {
  26627. delete indicesByUUID[uuid];
  26628. if (index < nCachedObjects) {
  26629. // object is cached, shrink the CACHED region
  26630. var firstActiveIndex = --nCachedObjects,
  26631. lastCachedObject = objects[firstActiveIndex],
  26632. lastIndex = --nObjects,
  26633. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26634. indicesByUUID[lastCachedObject.uuid] = index;
  26635. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26636. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26637. objects[firstActiveIndex] = lastObject;
  26638. objects.pop(); // accounting is done, now do the same for all bindings
  26639. for (var j = 0, m = nBindings; j !== m; ++j) {
  26640. var bindingsForPath = bindings[j],
  26641. lastCached = bindingsForPath[firstActiveIndex],
  26642. last = bindingsForPath[lastIndex];
  26643. bindingsForPath[index] = lastCached;
  26644. bindingsForPath[firstActiveIndex] = last;
  26645. bindingsForPath.pop();
  26646. }
  26647. } else {
  26648. // object is active, just swap with the last and pop
  26649. var _lastIndex = --nObjects,
  26650. _lastObject = objects[_lastIndex];
  26651. if (_lastIndex > 0) {
  26652. indicesByUUID[_lastObject.uuid] = index;
  26653. }
  26654. objects[index] = _lastObject;
  26655. objects.pop(); // accounting is done, now do the same for all bindings
  26656. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26657. var _bindingsForPath = bindings[_j2];
  26658. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26659. _bindingsForPath.pop();
  26660. }
  26661. } // cached or active
  26662. } // if object is known
  26663. } // for arguments
  26664. this.nCachedObjects_ = nCachedObjects;
  26665. },
  26666. // Internal interface used by befriended PropertyBinding.Composite:
  26667. subscribe_: function subscribe_(path, parsedPath) {
  26668. // returns an array of bindings for the given path that is changed
  26669. // according to the contained objects in the group
  26670. var indicesByPath = this._bindingsIndicesByPath;
  26671. var index = indicesByPath[path];
  26672. var bindings = this._bindings;
  26673. if (index !== undefined) return bindings[index];
  26674. var paths = this._paths,
  26675. parsedPaths = this._parsedPaths,
  26676. objects = this._objects,
  26677. nObjects = objects.length,
  26678. nCachedObjects = this.nCachedObjects_,
  26679. bindingsForPath = new Array(nObjects);
  26680. index = bindings.length;
  26681. indicesByPath[path] = index;
  26682. paths.push(path);
  26683. parsedPaths.push(parsedPath);
  26684. bindings.push(bindingsForPath);
  26685. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26686. var object = objects[i];
  26687. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26688. }
  26689. return bindingsForPath;
  26690. },
  26691. unsubscribe_: function unsubscribe_(path) {
  26692. // tells the group to forget about a property path and no longer
  26693. // update the array previously obtained with 'subscribe_'
  26694. var indicesByPath = this._bindingsIndicesByPath,
  26695. index = indicesByPath[path];
  26696. if (index !== undefined) {
  26697. var paths = this._paths,
  26698. parsedPaths = this._parsedPaths,
  26699. bindings = this._bindings,
  26700. lastBindingsIndex = bindings.length - 1,
  26701. lastBindings = bindings[lastBindingsIndex],
  26702. lastBindingsPath = path[lastBindingsIndex];
  26703. indicesByPath[lastBindingsPath] = index;
  26704. bindings[index] = lastBindings;
  26705. bindings.pop();
  26706. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26707. parsedPaths.pop();
  26708. paths[index] = paths[lastBindingsIndex];
  26709. paths.pop();
  26710. }
  26711. }
  26712. });
  26713. var AnimationAction = /*#__PURE__*/function () {
  26714. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26715. if (localRoot === void 0) {
  26716. localRoot = null;
  26717. }
  26718. if (blendMode === void 0) {
  26719. blendMode = clip.blendMode;
  26720. }
  26721. this._mixer = mixer;
  26722. this._clip = clip;
  26723. this._localRoot = localRoot;
  26724. this.blendMode = blendMode;
  26725. var tracks = clip.tracks,
  26726. nTracks = tracks.length,
  26727. interpolants = new Array(nTracks);
  26728. var interpolantSettings = {
  26729. endingStart: ZeroCurvatureEnding,
  26730. endingEnd: ZeroCurvatureEnding
  26731. };
  26732. for (var i = 0; i !== nTracks; ++i) {
  26733. var interpolant = tracks[i].createInterpolant(null);
  26734. interpolants[i] = interpolant;
  26735. interpolant.settings = interpolantSettings;
  26736. }
  26737. this._interpolantSettings = interpolantSettings;
  26738. this._interpolants = interpolants; // bound by the mixer
  26739. // inside: PropertyMixer (managed by the mixer)
  26740. this._propertyBindings = new Array(nTracks);
  26741. this._cacheIndex = null; // for the memory manager
  26742. this._byClipCacheIndex = null; // for the memory manager
  26743. this._timeScaleInterpolant = null;
  26744. this._weightInterpolant = null;
  26745. this.loop = LoopRepeat;
  26746. this._loopCount = -1; // global mixer time when the action is to be started
  26747. // it's set back to 'null' upon start of the action
  26748. this._startTime = null; // scaled local time of the action
  26749. // gets clamped or wrapped to 0..clip.duration according to loop
  26750. this.time = 0;
  26751. this.timeScale = 1;
  26752. this._effectiveTimeScale = 1;
  26753. this.weight = 1;
  26754. this._effectiveWeight = 1;
  26755. this.repetitions = Infinity; // no. of repetitions when looping
  26756. this.paused = false; // true -> zero effective time scale
  26757. this.enabled = true; // false -> zero effective weight
  26758. this.clampWhenFinished = false; // keep feeding the last frame?
  26759. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26760. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26761. } // State & Scheduling
  26762. var _proto = AnimationAction.prototype;
  26763. _proto.play = function play() {
  26764. this._mixer._activateAction(this);
  26765. return this;
  26766. };
  26767. _proto.stop = function stop() {
  26768. this._mixer._deactivateAction(this);
  26769. return this.reset();
  26770. };
  26771. _proto.reset = function reset() {
  26772. this.paused = false;
  26773. this.enabled = true;
  26774. this.time = 0; // restart clip
  26775. this._loopCount = -1; // forget previous loops
  26776. this._startTime = null; // forget scheduling
  26777. return this.stopFading().stopWarping();
  26778. };
  26779. _proto.isRunning = function isRunning() {
  26780. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26781. } // return true when play has been called
  26782. ;
  26783. _proto.isScheduled = function isScheduled() {
  26784. return this._mixer._isActiveAction(this);
  26785. };
  26786. _proto.startAt = function startAt(time) {
  26787. this._startTime = time;
  26788. return this;
  26789. };
  26790. _proto.setLoop = function setLoop(mode, repetitions) {
  26791. this.loop = mode;
  26792. this.repetitions = repetitions;
  26793. return this;
  26794. } // Weight
  26795. // set the weight stopping any scheduled fading
  26796. // although .enabled = false yields an effective weight of zero, this
  26797. // method does *not* change .enabled, because it would be confusing
  26798. ;
  26799. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26800. this.weight = weight; // note: same logic as when updated at runtime
  26801. this._effectiveWeight = this.enabled ? weight : 0;
  26802. return this.stopFading();
  26803. } // return the weight considering fading and .enabled
  26804. ;
  26805. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26806. return this._effectiveWeight;
  26807. };
  26808. _proto.fadeIn = function fadeIn(duration) {
  26809. return this._scheduleFading(duration, 0, 1);
  26810. };
  26811. _proto.fadeOut = function fadeOut(duration) {
  26812. return this._scheduleFading(duration, 1, 0);
  26813. };
  26814. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26815. fadeOutAction.fadeOut(duration);
  26816. this.fadeIn(duration);
  26817. if (warp) {
  26818. var fadeInDuration = this._clip.duration,
  26819. fadeOutDuration = fadeOutAction._clip.duration,
  26820. startEndRatio = fadeOutDuration / fadeInDuration,
  26821. endStartRatio = fadeInDuration / fadeOutDuration;
  26822. fadeOutAction.warp(1.0, startEndRatio, duration);
  26823. this.warp(endStartRatio, 1.0, duration);
  26824. }
  26825. return this;
  26826. };
  26827. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26828. return fadeInAction.crossFadeFrom(this, duration, warp);
  26829. };
  26830. _proto.stopFading = function stopFading() {
  26831. var weightInterpolant = this._weightInterpolant;
  26832. if (weightInterpolant !== null) {
  26833. this._weightInterpolant = null;
  26834. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26835. }
  26836. return this;
  26837. } // Time Scale Control
  26838. // set the time scale stopping any scheduled warping
  26839. // although .paused = true yields an effective time scale of zero, this
  26840. // method does *not* change .paused, because it would be confusing
  26841. ;
  26842. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26843. this.timeScale = timeScale;
  26844. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26845. return this.stopWarping();
  26846. } // return the time scale considering warping and .paused
  26847. ;
  26848. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26849. return this._effectiveTimeScale;
  26850. };
  26851. _proto.setDuration = function setDuration(duration) {
  26852. this.timeScale = this._clip.duration / duration;
  26853. return this.stopWarping();
  26854. };
  26855. _proto.syncWith = function syncWith(action) {
  26856. this.time = action.time;
  26857. this.timeScale = action.timeScale;
  26858. return this.stopWarping();
  26859. };
  26860. _proto.halt = function halt(duration) {
  26861. return this.warp(this._effectiveTimeScale, 0, duration);
  26862. };
  26863. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26864. var mixer = this._mixer,
  26865. now = mixer.time,
  26866. timeScale = this.timeScale;
  26867. var interpolant = this._timeScaleInterpolant;
  26868. if (interpolant === null) {
  26869. interpolant = mixer._lendControlInterpolant();
  26870. this._timeScaleInterpolant = interpolant;
  26871. }
  26872. var times = interpolant.parameterPositions,
  26873. values = interpolant.sampleValues;
  26874. times[0] = now;
  26875. times[1] = now + duration;
  26876. values[0] = startTimeScale / timeScale;
  26877. values[1] = endTimeScale / timeScale;
  26878. return this;
  26879. };
  26880. _proto.stopWarping = function stopWarping() {
  26881. var timeScaleInterpolant = this._timeScaleInterpolant;
  26882. if (timeScaleInterpolant !== null) {
  26883. this._timeScaleInterpolant = null;
  26884. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26885. }
  26886. return this;
  26887. } // Object Accessors
  26888. ;
  26889. _proto.getMixer = function getMixer() {
  26890. return this._mixer;
  26891. };
  26892. _proto.getClip = function getClip() {
  26893. return this._clip;
  26894. };
  26895. _proto.getRoot = function getRoot() {
  26896. return this._localRoot || this._mixer._root;
  26897. } // Interna
  26898. ;
  26899. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26900. // called by the mixer
  26901. if (!this.enabled) {
  26902. // call ._updateWeight() to update ._effectiveWeight
  26903. this._updateWeight(time);
  26904. return;
  26905. }
  26906. var startTime = this._startTime;
  26907. if (startTime !== null) {
  26908. // check for scheduled start of action
  26909. var timeRunning = (time - startTime) * timeDirection;
  26910. if (timeRunning < 0 || timeDirection === 0) {
  26911. return; // yet to come / don't decide when delta = 0
  26912. } // start
  26913. this._startTime = null; // unschedule
  26914. deltaTime = timeDirection * timeRunning;
  26915. } // apply time scale and advance time
  26916. deltaTime *= this._updateTimeScale(time);
  26917. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26918. // an effective weight of 0
  26919. var weight = this._updateWeight(time);
  26920. if (weight > 0) {
  26921. var _interpolants = this._interpolants;
  26922. var propertyMixers = this._propertyBindings;
  26923. switch (this.blendMode) {
  26924. case AdditiveAnimationBlendMode:
  26925. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26926. _interpolants[j].evaluate(clipTime);
  26927. propertyMixers[j].accumulateAdditive(weight);
  26928. }
  26929. break;
  26930. case NormalAnimationBlendMode:
  26931. default:
  26932. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26933. _interpolants[_j].evaluate(clipTime);
  26934. propertyMixers[_j].accumulate(accuIndex, weight);
  26935. }
  26936. }
  26937. }
  26938. };
  26939. _proto._updateWeight = function _updateWeight(time) {
  26940. var weight = 0;
  26941. if (this.enabled) {
  26942. weight = this.weight;
  26943. var interpolant = this._weightInterpolant;
  26944. if (interpolant !== null) {
  26945. var interpolantValue = interpolant.evaluate(time)[0];
  26946. weight *= interpolantValue;
  26947. if (time > interpolant.parameterPositions[1]) {
  26948. this.stopFading();
  26949. if (interpolantValue === 0) {
  26950. // faded out, disable
  26951. this.enabled = false;
  26952. }
  26953. }
  26954. }
  26955. }
  26956. this._effectiveWeight = weight;
  26957. return weight;
  26958. };
  26959. _proto._updateTimeScale = function _updateTimeScale(time) {
  26960. var timeScale = 0;
  26961. if (!this.paused) {
  26962. timeScale = this.timeScale;
  26963. var interpolant = this._timeScaleInterpolant;
  26964. if (interpolant !== null) {
  26965. var interpolantValue = interpolant.evaluate(time)[0];
  26966. timeScale *= interpolantValue;
  26967. if (time > interpolant.parameterPositions[1]) {
  26968. this.stopWarping();
  26969. if (timeScale === 0) {
  26970. // motion has halted, pause
  26971. this.paused = true;
  26972. } else {
  26973. // warp done - apply final time scale
  26974. this.timeScale = timeScale;
  26975. }
  26976. }
  26977. }
  26978. }
  26979. this._effectiveTimeScale = timeScale;
  26980. return timeScale;
  26981. };
  26982. _proto._updateTime = function _updateTime(deltaTime) {
  26983. var duration = this._clip.duration;
  26984. var loop = this.loop;
  26985. var time = this.time + deltaTime;
  26986. var loopCount = this._loopCount;
  26987. var pingPong = loop === LoopPingPong;
  26988. if (deltaTime === 0) {
  26989. if (loopCount === -1) return time;
  26990. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26991. }
  26992. if (loop === LoopOnce) {
  26993. if (loopCount === -1) {
  26994. // just started
  26995. this._loopCount = 0;
  26996. this._setEndings(true, true, false);
  26997. }
  26998. handle_stop: {
  26999. if (time >= duration) {
  27000. time = duration;
  27001. } else if (time < 0) {
  27002. time = 0;
  27003. } else {
  27004. this.time = time;
  27005. break handle_stop;
  27006. }
  27007. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27008. this.time = time;
  27009. this._mixer.dispatchEvent({
  27010. type: 'finished',
  27011. action: this,
  27012. direction: deltaTime < 0 ? -1 : 1
  27013. });
  27014. }
  27015. } else {
  27016. // repetitive Repeat or PingPong
  27017. if (loopCount === -1) {
  27018. // just started
  27019. if (deltaTime >= 0) {
  27020. loopCount = 0;
  27021. this._setEndings(true, this.repetitions === 0, pingPong);
  27022. } else {
  27023. // when looping in reverse direction, the initial
  27024. // transition through zero counts as a repetition,
  27025. // so leave loopCount at -1
  27026. this._setEndings(this.repetitions === 0, true, pingPong);
  27027. }
  27028. }
  27029. if (time >= duration || time < 0) {
  27030. // wrap around
  27031. var loopDelta = Math.floor(time / duration); // signed
  27032. time -= duration * loopDelta;
  27033. loopCount += Math.abs(loopDelta);
  27034. var pending = this.repetitions - loopCount;
  27035. if (pending <= 0) {
  27036. // have to stop (switch state, clamp time, fire event)
  27037. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27038. time = deltaTime > 0 ? duration : 0;
  27039. this.time = time;
  27040. this._mixer.dispatchEvent({
  27041. type: 'finished',
  27042. action: this,
  27043. direction: deltaTime > 0 ? 1 : -1
  27044. });
  27045. } else {
  27046. // keep running
  27047. if (pending === 1) {
  27048. // entering the last round
  27049. var atStart = deltaTime < 0;
  27050. this._setEndings(atStart, !atStart, pingPong);
  27051. } else {
  27052. this._setEndings(false, false, pingPong);
  27053. }
  27054. this._loopCount = loopCount;
  27055. this.time = time;
  27056. this._mixer.dispatchEvent({
  27057. type: 'loop',
  27058. action: this,
  27059. loopDelta: loopDelta
  27060. });
  27061. }
  27062. } else {
  27063. this.time = time;
  27064. }
  27065. if (pingPong && (loopCount & 1) === 1) {
  27066. // invert time for the "pong round"
  27067. return duration - time;
  27068. }
  27069. }
  27070. return time;
  27071. };
  27072. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  27073. var settings = this._interpolantSettings;
  27074. if (pingPong) {
  27075. settings.endingStart = ZeroSlopeEnding;
  27076. settings.endingEnd = ZeroSlopeEnding;
  27077. } else {
  27078. // assuming for LoopOnce atStart == atEnd == true
  27079. if (atStart) {
  27080. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27081. } else {
  27082. settings.endingStart = WrapAroundEnding;
  27083. }
  27084. if (atEnd) {
  27085. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27086. } else {
  27087. settings.endingEnd = WrapAroundEnding;
  27088. }
  27089. }
  27090. };
  27091. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  27092. var mixer = this._mixer,
  27093. now = mixer.time;
  27094. var interpolant = this._weightInterpolant;
  27095. if (interpolant === null) {
  27096. interpolant = mixer._lendControlInterpolant();
  27097. this._weightInterpolant = interpolant;
  27098. }
  27099. var times = interpolant.parameterPositions,
  27100. values = interpolant.sampleValues;
  27101. times[0] = now;
  27102. values[0] = weightNow;
  27103. times[1] = now + duration;
  27104. values[1] = weightThen;
  27105. return this;
  27106. };
  27107. return AnimationAction;
  27108. }();
  27109. function AnimationMixer(root) {
  27110. this._root = root;
  27111. this._initMemoryManager();
  27112. this._accuIndex = 0;
  27113. this.time = 0;
  27114. this.timeScale = 1.0;
  27115. }
  27116. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  27117. constructor: AnimationMixer,
  27118. _bindAction: function _bindAction(action, prototypeAction) {
  27119. var root = action._localRoot || this._root,
  27120. tracks = action._clip.tracks,
  27121. nTracks = tracks.length,
  27122. bindings = action._propertyBindings,
  27123. interpolants = action._interpolants,
  27124. rootUuid = root.uuid,
  27125. bindingsByRoot = this._bindingsByRootAndName;
  27126. var bindingsByName = bindingsByRoot[rootUuid];
  27127. if (bindingsByName === undefined) {
  27128. bindingsByName = {};
  27129. bindingsByRoot[rootUuid] = bindingsByName;
  27130. }
  27131. for (var i = 0; i !== nTracks; ++i) {
  27132. var track = tracks[i],
  27133. trackName = track.name;
  27134. var binding = bindingsByName[trackName];
  27135. if (binding !== undefined) {
  27136. bindings[i] = binding;
  27137. } else {
  27138. binding = bindings[i];
  27139. if (binding !== undefined) {
  27140. // existing binding, make sure the cache knows
  27141. if (binding._cacheIndex === null) {
  27142. ++binding.referenceCount;
  27143. this._addInactiveBinding(binding, rootUuid, trackName);
  27144. }
  27145. continue;
  27146. }
  27147. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  27148. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  27149. ++binding.referenceCount;
  27150. this._addInactiveBinding(binding, rootUuid, trackName);
  27151. bindings[i] = binding;
  27152. }
  27153. interpolants[i].resultBuffer = binding.buffer;
  27154. }
  27155. },
  27156. _activateAction: function _activateAction(action) {
  27157. if (!this._isActiveAction(action)) {
  27158. if (action._cacheIndex === null) {
  27159. // this action has been forgotten by the cache, but the user
  27160. // appears to be still using it -> rebind
  27161. var rootUuid = (action._localRoot || this._root).uuid,
  27162. clipUuid = action._clip.uuid,
  27163. actionsForClip = this._actionsByClip[clipUuid];
  27164. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  27165. this._addInactiveAction(action, clipUuid, rootUuid);
  27166. }
  27167. var bindings = action._propertyBindings; // increment reference counts / sort out state
  27168. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27169. var binding = bindings[i];
  27170. if (binding.useCount++ === 0) {
  27171. this._lendBinding(binding);
  27172. binding.saveOriginalState();
  27173. }
  27174. }
  27175. this._lendAction(action);
  27176. }
  27177. },
  27178. _deactivateAction: function _deactivateAction(action) {
  27179. if (this._isActiveAction(action)) {
  27180. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  27181. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27182. var binding = bindings[i];
  27183. if (--binding.useCount === 0) {
  27184. binding.restoreOriginalState();
  27185. this._takeBackBinding(binding);
  27186. }
  27187. }
  27188. this._takeBackAction(action);
  27189. }
  27190. },
  27191. // Memory manager
  27192. _initMemoryManager: function _initMemoryManager() {
  27193. this._actions = []; // 'nActiveActions' followed by inactive ones
  27194. this._nActiveActions = 0;
  27195. this._actionsByClip = {}; // inside:
  27196. // {
  27197. // knownActions: Array< AnimationAction > - used as prototypes
  27198. // actionByRoot: AnimationAction - lookup
  27199. // }
  27200. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27201. this._nActiveBindings = 0;
  27202. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27203. this._controlInterpolants = []; // same game as above
  27204. this._nActiveControlInterpolants = 0;
  27205. var scope = this;
  27206. this.stats = {
  27207. actions: {
  27208. get total() {
  27209. return scope._actions.length;
  27210. },
  27211. get inUse() {
  27212. return scope._nActiveActions;
  27213. }
  27214. },
  27215. bindings: {
  27216. get total() {
  27217. return scope._bindings.length;
  27218. },
  27219. get inUse() {
  27220. return scope._nActiveBindings;
  27221. }
  27222. },
  27223. controlInterpolants: {
  27224. get total() {
  27225. return scope._controlInterpolants.length;
  27226. },
  27227. get inUse() {
  27228. return scope._nActiveControlInterpolants;
  27229. }
  27230. }
  27231. };
  27232. },
  27233. // Memory management for AnimationAction objects
  27234. _isActiveAction: function _isActiveAction(action) {
  27235. var index = action._cacheIndex;
  27236. return index !== null && index < this._nActiveActions;
  27237. },
  27238. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  27239. var actions = this._actions,
  27240. actionsByClip = this._actionsByClip;
  27241. var actionsForClip = actionsByClip[clipUuid];
  27242. if (actionsForClip === undefined) {
  27243. actionsForClip = {
  27244. knownActions: [action],
  27245. actionByRoot: {}
  27246. };
  27247. action._byClipCacheIndex = 0;
  27248. actionsByClip[clipUuid] = actionsForClip;
  27249. } else {
  27250. var knownActions = actionsForClip.knownActions;
  27251. action._byClipCacheIndex = knownActions.length;
  27252. knownActions.push(action);
  27253. }
  27254. action._cacheIndex = actions.length;
  27255. actions.push(action);
  27256. actionsForClip.actionByRoot[rootUuid] = action;
  27257. },
  27258. _removeInactiveAction: function _removeInactiveAction(action) {
  27259. var actions = this._actions,
  27260. lastInactiveAction = actions[actions.length - 1],
  27261. cacheIndex = action._cacheIndex;
  27262. lastInactiveAction._cacheIndex = cacheIndex;
  27263. actions[cacheIndex] = lastInactiveAction;
  27264. actions.pop();
  27265. action._cacheIndex = null;
  27266. var clipUuid = action._clip.uuid,
  27267. actionsByClip = this._actionsByClip,
  27268. actionsForClip = actionsByClip[clipUuid],
  27269. knownActionsForClip = actionsForClip.knownActions,
  27270. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27271. byClipCacheIndex = action._byClipCacheIndex;
  27272. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27273. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27274. knownActionsForClip.pop();
  27275. action._byClipCacheIndex = null;
  27276. var actionByRoot = actionsForClip.actionByRoot,
  27277. rootUuid = (action._localRoot || this._root).uuid;
  27278. delete actionByRoot[rootUuid];
  27279. if (knownActionsForClip.length === 0) {
  27280. delete actionsByClip[clipUuid];
  27281. }
  27282. this._removeInactiveBindingsForAction(action);
  27283. },
  27284. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27285. var bindings = action._propertyBindings;
  27286. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27287. var binding = bindings[i];
  27288. if (--binding.referenceCount === 0) {
  27289. this._removeInactiveBinding(binding);
  27290. }
  27291. }
  27292. },
  27293. _lendAction: function _lendAction(action) {
  27294. // [ active actions | inactive actions ]
  27295. // [ active actions >| inactive actions ]
  27296. // s a
  27297. // <-swap->
  27298. // a s
  27299. var actions = this._actions,
  27300. prevIndex = action._cacheIndex,
  27301. lastActiveIndex = this._nActiveActions++,
  27302. firstInactiveAction = actions[lastActiveIndex];
  27303. action._cacheIndex = lastActiveIndex;
  27304. actions[lastActiveIndex] = action;
  27305. firstInactiveAction._cacheIndex = prevIndex;
  27306. actions[prevIndex] = firstInactiveAction;
  27307. },
  27308. _takeBackAction: function _takeBackAction(action) {
  27309. // [ active actions | inactive actions ]
  27310. // [ active actions |< inactive actions ]
  27311. // a s
  27312. // <-swap->
  27313. // s a
  27314. var actions = this._actions,
  27315. prevIndex = action._cacheIndex,
  27316. firstInactiveIndex = --this._nActiveActions,
  27317. lastActiveAction = actions[firstInactiveIndex];
  27318. action._cacheIndex = firstInactiveIndex;
  27319. actions[firstInactiveIndex] = action;
  27320. lastActiveAction._cacheIndex = prevIndex;
  27321. actions[prevIndex] = lastActiveAction;
  27322. },
  27323. // Memory management for PropertyMixer objects
  27324. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27325. var bindingsByRoot = this._bindingsByRootAndName,
  27326. bindings = this._bindings;
  27327. var bindingByName = bindingsByRoot[rootUuid];
  27328. if (bindingByName === undefined) {
  27329. bindingByName = {};
  27330. bindingsByRoot[rootUuid] = bindingByName;
  27331. }
  27332. bindingByName[trackName] = binding;
  27333. binding._cacheIndex = bindings.length;
  27334. bindings.push(binding);
  27335. },
  27336. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27337. var bindings = this._bindings,
  27338. propBinding = binding.binding,
  27339. rootUuid = propBinding.rootNode.uuid,
  27340. trackName = propBinding.path,
  27341. bindingsByRoot = this._bindingsByRootAndName,
  27342. bindingByName = bindingsByRoot[rootUuid],
  27343. lastInactiveBinding = bindings[bindings.length - 1],
  27344. cacheIndex = binding._cacheIndex;
  27345. lastInactiveBinding._cacheIndex = cacheIndex;
  27346. bindings[cacheIndex] = lastInactiveBinding;
  27347. bindings.pop();
  27348. delete bindingByName[trackName];
  27349. if (Object.keys(bindingByName).length === 0) {
  27350. delete bindingsByRoot[rootUuid];
  27351. }
  27352. },
  27353. _lendBinding: function _lendBinding(binding) {
  27354. var bindings = this._bindings,
  27355. prevIndex = binding._cacheIndex,
  27356. lastActiveIndex = this._nActiveBindings++,
  27357. firstInactiveBinding = bindings[lastActiveIndex];
  27358. binding._cacheIndex = lastActiveIndex;
  27359. bindings[lastActiveIndex] = binding;
  27360. firstInactiveBinding._cacheIndex = prevIndex;
  27361. bindings[prevIndex] = firstInactiveBinding;
  27362. },
  27363. _takeBackBinding: function _takeBackBinding(binding) {
  27364. var bindings = this._bindings,
  27365. prevIndex = binding._cacheIndex,
  27366. firstInactiveIndex = --this._nActiveBindings,
  27367. lastActiveBinding = bindings[firstInactiveIndex];
  27368. binding._cacheIndex = firstInactiveIndex;
  27369. bindings[firstInactiveIndex] = binding;
  27370. lastActiveBinding._cacheIndex = prevIndex;
  27371. bindings[prevIndex] = lastActiveBinding;
  27372. },
  27373. // Memory management of Interpolants for weight and time scale
  27374. _lendControlInterpolant: function _lendControlInterpolant() {
  27375. var interpolants = this._controlInterpolants,
  27376. lastActiveIndex = this._nActiveControlInterpolants++;
  27377. var interpolant = interpolants[lastActiveIndex];
  27378. if (interpolant === undefined) {
  27379. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27380. interpolant.__cacheIndex = lastActiveIndex;
  27381. interpolants[lastActiveIndex] = interpolant;
  27382. }
  27383. return interpolant;
  27384. },
  27385. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27386. var interpolants = this._controlInterpolants,
  27387. prevIndex = interpolant.__cacheIndex,
  27388. firstInactiveIndex = --this._nActiveControlInterpolants,
  27389. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27390. interpolant.__cacheIndex = firstInactiveIndex;
  27391. interpolants[firstInactiveIndex] = interpolant;
  27392. lastActiveInterpolant.__cacheIndex = prevIndex;
  27393. interpolants[prevIndex] = lastActiveInterpolant;
  27394. },
  27395. _controlInterpolantsResultBuffer: new Float32Array(1),
  27396. // return an action for a clip optionally using a custom root target
  27397. // object (this method allocates a lot of dynamic memory in case a
  27398. // previously unknown clip/root combination is specified)
  27399. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27400. var root = optionalRoot || this._root,
  27401. rootUuid = root.uuid;
  27402. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27403. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27404. var actionsForClip = this._actionsByClip[clipUuid];
  27405. var prototypeAction = null;
  27406. if (blendMode === undefined) {
  27407. if (clipObject !== null) {
  27408. blendMode = clipObject.blendMode;
  27409. } else {
  27410. blendMode = NormalAnimationBlendMode;
  27411. }
  27412. }
  27413. if (actionsForClip !== undefined) {
  27414. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27415. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27416. return existingAction;
  27417. } // we know the clip, so we don't have to parse all
  27418. // the bindings again but can just copy
  27419. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27420. if (clipObject === null) clipObject = prototypeAction._clip;
  27421. } // clip must be known when specified via string
  27422. if (clipObject === null) return null; // allocate all resources required to run it
  27423. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27424. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27425. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27426. return newAction;
  27427. },
  27428. // get an existing action
  27429. existingAction: function existingAction(clip, optionalRoot) {
  27430. var root = optionalRoot || this._root,
  27431. rootUuid = root.uuid,
  27432. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27433. clipUuid = clipObject ? clipObject.uuid : clip,
  27434. actionsForClip = this._actionsByClip[clipUuid];
  27435. if (actionsForClip !== undefined) {
  27436. return actionsForClip.actionByRoot[rootUuid] || null;
  27437. }
  27438. return null;
  27439. },
  27440. // deactivates all previously scheduled actions
  27441. stopAllAction: function stopAllAction() {
  27442. var actions = this._actions,
  27443. nActions = this._nActiveActions;
  27444. for (var i = nActions - 1; i >= 0; --i) {
  27445. actions[i].stop();
  27446. }
  27447. return this;
  27448. },
  27449. // advance the time and update apply the animation
  27450. update: function update(deltaTime) {
  27451. deltaTime *= this.timeScale;
  27452. var actions = this._actions,
  27453. nActions = this._nActiveActions,
  27454. time = this.time += deltaTime,
  27455. timeDirection = Math.sign(deltaTime),
  27456. accuIndex = this._accuIndex ^= 1; // run active actions
  27457. for (var i = 0; i !== nActions; ++i) {
  27458. var action = actions[i];
  27459. action._update(time, deltaTime, timeDirection, accuIndex);
  27460. } // update scene graph
  27461. var bindings = this._bindings,
  27462. nBindings = this._nActiveBindings;
  27463. for (var _i = 0; _i !== nBindings; ++_i) {
  27464. bindings[_i].apply(accuIndex);
  27465. }
  27466. return this;
  27467. },
  27468. // Allows you to seek to a specific time in an animation.
  27469. setTime: function setTime(timeInSeconds) {
  27470. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27471. for (var i = 0; i < this._actions.length; i++) {
  27472. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27473. }
  27474. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27475. },
  27476. // return this mixer's root target object
  27477. getRoot: function getRoot() {
  27478. return this._root;
  27479. },
  27480. // free all resources specific to a particular clip
  27481. uncacheClip: function uncacheClip(clip) {
  27482. var actions = this._actions,
  27483. clipUuid = clip.uuid,
  27484. actionsByClip = this._actionsByClip,
  27485. actionsForClip = actionsByClip[clipUuid];
  27486. if (actionsForClip !== undefined) {
  27487. // note: just calling _removeInactiveAction would mess up the
  27488. // iteration state and also require updating the state we can
  27489. // just throw away
  27490. var actionsToRemove = actionsForClip.knownActions;
  27491. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27492. var action = actionsToRemove[i];
  27493. this._deactivateAction(action);
  27494. var cacheIndex = action._cacheIndex,
  27495. lastInactiveAction = actions[actions.length - 1];
  27496. action._cacheIndex = null;
  27497. action._byClipCacheIndex = null;
  27498. lastInactiveAction._cacheIndex = cacheIndex;
  27499. actions[cacheIndex] = lastInactiveAction;
  27500. actions.pop();
  27501. this._removeInactiveBindingsForAction(action);
  27502. }
  27503. delete actionsByClip[clipUuid];
  27504. }
  27505. },
  27506. // free all resources specific to a particular root target object
  27507. uncacheRoot: function uncacheRoot(root) {
  27508. var rootUuid = root.uuid,
  27509. actionsByClip = this._actionsByClip;
  27510. for (var clipUuid in actionsByClip) {
  27511. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27512. action = actionByRoot[rootUuid];
  27513. if (action !== undefined) {
  27514. this._deactivateAction(action);
  27515. this._removeInactiveAction(action);
  27516. }
  27517. }
  27518. var bindingsByRoot = this._bindingsByRootAndName,
  27519. bindingByName = bindingsByRoot[rootUuid];
  27520. if (bindingByName !== undefined) {
  27521. for (var trackName in bindingByName) {
  27522. var binding = bindingByName[trackName];
  27523. binding.restoreOriginalState();
  27524. this._removeInactiveBinding(binding);
  27525. }
  27526. }
  27527. },
  27528. // remove a targeted clip from the cache
  27529. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27530. var action = this.existingAction(clip, optionalRoot);
  27531. if (action !== null) {
  27532. this._deactivateAction(action);
  27533. this._removeInactiveAction(action);
  27534. }
  27535. }
  27536. });
  27537. var Uniform = /*#__PURE__*/function () {
  27538. function Uniform(value) {
  27539. if (typeof value === 'string') {
  27540. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27541. value = arguments[1];
  27542. }
  27543. this.value = value;
  27544. }
  27545. var _proto = Uniform.prototype;
  27546. _proto.clone = function clone() {
  27547. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27548. };
  27549. return Uniform;
  27550. }();
  27551. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27552. InterleavedBuffer.call(this, array, stride);
  27553. this.meshPerAttribute = meshPerAttribute || 1;
  27554. }
  27555. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27556. constructor: InstancedInterleavedBuffer,
  27557. isInstancedInterleavedBuffer: true,
  27558. copy: function copy(source) {
  27559. InterleavedBuffer.prototype.copy.call(this, source);
  27560. this.meshPerAttribute = source.meshPerAttribute;
  27561. return this;
  27562. },
  27563. clone: function clone(data) {
  27564. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27565. ib.meshPerAttribute = this.meshPerAttribute;
  27566. return ib;
  27567. },
  27568. toJSON: function toJSON(data) {
  27569. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27570. json.isInstancedInterleavedBuffer = true;
  27571. json.meshPerAttribute = this.meshPerAttribute;
  27572. return json;
  27573. }
  27574. });
  27575. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27576. this.buffer = buffer;
  27577. this.type = type;
  27578. this.itemSize = itemSize;
  27579. this.elementSize = elementSize;
  27580. this.count = count;
  27581. this.version = 0;
  27582. }
  27583. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27584. set: function set(value) {
  27585. if (value === true) this.version++;
  27586. }
  27587. });
  27588. Object.assign(GLBufferAttribute.prototype, {
  27589. isGLBufferAttribute: true,
  27590. setBuffer: function setBuffer(buffer) {
  27591. this.buffer = buffer;
  27592. return this;
  27593. },
  27594. setType: function setType(type, elementSize) {
  27595. this.type = type;
  27596. this.elementSize = elementSize;
  27597. return this;
  27598. },
  27599. setItemSize: function setItemSize(itemSize) {
  27600. this.itemSize = itemSize;
  27601. return this;
  27602. },
  27603. setCount: function setCount(count) {
  27604. this.count = count;
  27605. return this;
  27606. }
  27607. });
  27608. function Raycaster(origin, direction, near, far) {
  27609. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27610. this.near = near || 0;
  27611. this.far = far || Infinity;
  27612. this.camera = null;
  27613. this.layers = new Layers();
  27614. this.params = {
  27615. Mesh: {},
  27616. Line: {
  27617. threshold: 1
  27618. },
  27619. LOD: {},
  27620. Points: {
  27621. threshold: 1
  27622. },
  27623. Sprite: {}
  27624. };
  27625. Object.defineProperties(this.params, {
  27626. PointCloud: {
  27627. get: function get() {
  27628. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27629. return this.Points;
  27630. }
  27631. }
  27632. });
  27633. }
  27634. function ascSort(a, b) {
  27635. return a.distance - b.distance;
  27636. }
  27637. function _intersectObject(object, raycaster, intersects, recursive) {
  27638. if (object.layers.test(raycaster.layers)) {
  27639. object.raycast(raycaster, intersects);
  27640. }
  27641. if (recursive === true) {
  27642. var children = object.children;
  27643. for (var i = 0, l = children.length; i < l; i++) {
  27644. _intersectObject(children[i], raycaster, intersects, true);
  27645. }
  27646. }
  27647. }
  27648. Object.assign(Raycaster.prototype, {
  27649. set: function set(origin, direction) {
  27650. // direction is assumed to be normalized (for accurate distance calculations)
  27651. this.ray.set(origin, direction);
  27652. },
  27653. setFromCamera: function setFromCamera(coords, camera) {
  27654. if (camera && camera.isPerspectiveCamera) {
  27655. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27656. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27657. this.camera = camera;
  27658. } else if (camera && camera.isOrthographicCamera) {
  27659. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27660. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27661. this.camera = camera;
  27662. } else {
  27663. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27664. }
  27665. },
  27666. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27667. var intersects = optionalTarget || [];
  27668. _intersectObject(object, this, intersects, recursive);
  27669. intersects.sort(ascSort);
  27670. return intersects;
  27671. },
  27672. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27673. var intersects = optionalTarget || [];
  27674. if (Array.isArray(objects) === false) {
  27675. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27676. return intersects;
  27677. }
  27678. for (var i = 0, l = objects.length; i < l; i++) {
  27679. _intersectObject(objects[i], this, intersects, recursive);
  27680. }
  27681. intersects.sort(ascSort);
  27682. return intersects;
  27683. }
  27684. });
  27685. /**
  27686. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27687. *
  27688. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27689. * The azimuthal angle (theta) is measured from the positive z-axis.
  27690. */
  27691. var Spherical = /*#__PURE__*/function () {
  27692. function Spherical(radius, phi, theta) {
  27693. if (radius === void 0) {
  27694. radius = 1;
  27695. }
  27696. if (phi === void 0) {
  27697. phi = 0;
  27698. }
  27699. if (theta === void 0) {
  27700. theta = 0;
  27701. }
  27702. this.radius = radius;
  27703. this.phi = phi; // polar angle
  27704. this.theta = theta; // azimuthal angle
  27705. return this;
  27706. }
  27707. var _proto = Spherical.prototype;
  27708. _proto.set = function set(radius, phi, theta) {
  27709. this.radius = radius;
  27710. this.phi = phi;
  27711. this.theta = theta;
  27712. return this;
  27713. };
  27714. _proto.copy = function copy(other) {
  27715. this.radius = other.radius;
  27716. this.phi = other.phi;
  27717. this.theta = other.theta;
  27718. return this;
  27719. } // restrict phi to be betwee EPS and PI-EPS
  27720. ;
  27721. _proto.makeSafe = function makeSafe() {
  27722. var EPS = 0.000001;
  27723. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27724. return this;
  27725. };
  27726. _proto.setFromVector3 = function setFromVector3(v) {
  27727. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27728. };
  27729. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27730. this.radius = Math.sqrt(x * x + y * y + z * z);
  27731. if (this.radius === 0) {
  27732. this.theta = 0;
  27733. this.phi = 0;
  27734. } else {
  27735. this.theta = Math.atan2(x, z);
  27736. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27737. }
  27738. return this;
  27739. };
  27740. _proto.clone = function clone() {
  27741. return new this.constructor().copy(this);
  27742. };
  27743. return Spherical;
  27744. }();
  27745. /**
  27746. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27747. */
  27748. var Cylindrical = /*#__PURE__*/function () {
  27749. function Cylindrical(radius, theta, y) {
  27750. if (radius === void 0) {
  27751. radius = 1;
  27752. }
  27753. if (theta === void 0) {
  27754. theta = 0;
  27755. }
  27756. if (y === void 0) {
  27757. y = 0;
  27758. }
  27759. this.radius = radius; // distance from the origin to a point in the x-z plane
  27760. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27761. this.y = y; // height above the x-z plane
  27762. return this;
  27763. }
  27764. var _proto = Cylindrical.prototype;
  27765. _proto.set = function set(radius, theta, y) {
  27766. this.radius = radius;
  27767. this.theta = theta;
  27768. this.y = y;
  27769. return this;
  27770. };
  27771. _proto.copy = function copy(other) {
  27772. this.radius = other.radius;
  27773. this.theta = other.theta;
  27774. this.y = other.y;
  27775. return this;
  27776. };
  27777. _proto.setFromVector3 = function setFromVector3(v) {
  27778. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27779. };
  27780. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27781. this.radius = Math.sqrt(x * x + z * z);
  27782. this.theta = Math.atan2(x, z);
  27783. this.y = y;
  27784. return this;
  27785. };
  27786. _proto.clone = function clone() {
  27787. return new this.constructor().copy(this);
  27788. };
  27789. return Cylindrical;
  27790. }();
  27791. var _vector$8 = /*@__PURE__*/new Vector2();
  27792. var Box2 = /*#__PURE__*/function () {
  27793. function Box2(min, max) {
  27794. if (min === void 0) {
  27795. min = new Vector2(+Infinity, +Infinity);
  27796. }
  27797. if (max === void 0) {
  27798. max = new Vector2(-Infinity, -Infinity);
  27799. }
  27800. this.min = min;
  27801. this.max = max;
  27802. }
  27803. var _proto = Box2.prototype;
  27804. _proto.set = function set(min, max) {
  27805. this.min.copy(min);
  27806. this.max.copy(max);
  27807. return this;
  27808. };
  27809. _proto.setFromPoints = function setFromPoints(points) {
  27810. this.makeEmpty();
  27811. for (var i = 0, il = points.length; i < il; i++) {
  27812. this.expandByPoint(points[i]);
  27813. }
  27814. return this;
  27815. };
  27816. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27817. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27818. this.min.copy(center).sub(halfSize);
  27819. this.max.copy(center).add(halfSize);
  27820. return this;
  27821. };
  27822. _proto.clone = function clone() {
  27823. return new this.constructor().copy(this);
  27824. };
  27825. _proto.copy = function copy(box) {
  27826. this.min.copy(box.min);
  27827. this.max.copy(box.max);
  27828. return this;
  27829. };
  27830. _proto.makeEmpty = function makeEmpty() {
  27831. this.min.x = this.min.y = +Infinity;
  27832. this.max.x = this.max.y = -Infinity;
  27833. return this;
  27834. };
  27835. _proto.isEmpty = function isEmpty() {
  27836. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27837. return this.max.x < this.min.x || this.max.y < this.min.y;
  27838. };
  27839. _proto.getCenter = function getCenter(target) {
  27840. if (target === undefined) {
  27841. console.warn('THREE.Box2: .getCenter() target is now required');
  27842. target = new Vector2();
  27843. }
  27844. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27845. };
  27846. _proto.getSize = function getSize(target) {
  27847. if (target === undefined) {
  27848. console.warn('THREE.Box2: .getSize() target is now required');
  27849. target = new Vector2();
  27850. }
  27851. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27852. };
  27853. _proto.expandByPoint = function expandByPoint(point) {
  27854. this.min.min(point);
  27855. this.max.max(point);
  27856. return this;
  27857. };
  27858. _proto.expandByVector = function expandByVector(vector) {
  27859. this.min.sub(vector);
  27860. this.max.add(vector);
  27861. return this;
  27862. };
  27863. _proto.expandByScalar = function expandByScalar(scalar) {
  27864. this.min.addScalar(-scalar);
  27865. this.max.addScalar(scalar);
  27866. return this;
  27867. };
  27868. _proto.containsPoint = function containsPoint(point) {
  27869. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27870. };
  27871. _proto.containsBox = function containsBox(box) {
  27872. 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;
  27873. };
  27874. _proto.getParameter = function getParameter(point, target) {
  27875. // This can potentially have a divide by zero if the box
  27876. // has a size dimension of 0.
  27877. if (target === undefined) {
  27878. console.warn('THREE.Box2: .getParameter() target is now required');
  27879. target = new Vector2();
  27880. }
  27881. 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));
  27882. };
  27883. _proto.intersectsBox = function intersectsBox(box) {
  27884. // using 4 splitting planes to rule out intersections
  27885. 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;
  27886. };
  27887. _proto.clampPoint = function clampPoint(point, target) {
  27888. if (target === undefined) {
  27889. console.warn('THREE.Box2: .clampPoint() target is now required');
  27890. target = new Vector2();
  27891. }
  27892. return target.copy(point).clamp(this.min, this.max);
  27893. };
  27894. _proto.distanceToPoint = function distanceToPoint(point) {
  27895. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27896. return clampedPoint.sub(point).length();
  27897. };
  27898. _proto.intersect = function intersect(box) {
  27899. this.min.max(box.min);
  27900. this.max.min(box.max);
  27901. return this;
  27902. };
  27903. _proto.union = function union(box) {
  27904. this.min.min(box.min);
  27905. this.max.max(box.max);
  27906. return this;
  27907. };
  27908. _proto.translate = function translate(offset) {
  27909. this.min.add(offset);
  27910. this.max.add(offset);
  27911. return this;
  27912. };
  27913. _proto.equals = function equals(box) {
  27914. return box.min.equals(this.min) && box.max.equals(this.max);
  27915. };
  27916. return Box2;
  27917. }();
  27918. Box2.prototype.isBox2 = true;
  27919. var _startP = /*@__PURE__*/new Vector3();
  27920. var _startEnd = /*@__PURE__*/new Vector3();
  27921. var Line3 = /*#__PURE__*/function () {
  27922. function Line3(start, end) {
  27923. if (start === void 0) {
  27924. start = new Vector3();
  27925. }
  27926. if (end === void 0) {
  27927. end = new Vector3();
  27928. }
  27929. this.start = start;
  27930. this.end = end;
  27931. }
  27932. var _proto = Line3.prototype;
  27933. _proto.set = function set(start, end) {
  27934. this.start.copy(start);
  27935. this.end.copy(end);
  27936. return this;
  27937. };
  27938. _proto.copy = function copy(line) {
  27939. this.start.copy(line.start);
  27940. this.end.copy(line.end);
  27941. return this;
  27942. };
  27943. _proto.getCenter = function getCenter(target) {
  27944. if (target === undefined) {
  27945. console.warn('THREE.Line3: .getCenter() target is now required');
  27946. target = new Vector3();
  27947. }
  27948. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27949. };
  27950. _proto.delta = function delta(target) {
  27951. if (target === undefined) {
  27952. console.warn('THREE.Line3: .delta() target is now required');
  27953. target = new Vector3();
  27954. }
  27955. return target.subVectors(this.end, this.start);
  27956. };
  27957. _proto.distanceSq = function distanceSq() {
  27958. return this.start.distanceToSquared(this.end);
  27959. };
  27960. _proto.distance = function distance() {
  27961. return this.start.distanceTo(this.end);
  27962. };
  27963. _proto.at = function at(t, target) {
  27964. if (target === undefined) {
  27965. console.warn('THREE.Line3: .at() target is now required');
  27966. target = new Vector3();
  27967. }
  27968. return this.delta(target).multiplyScalar(t).add(this.start);
  27969. };
  27970. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27971. _startP.subVectors(point, this.start);
  27972. _startEnd.subVectors(this.end, this.start);
  27973. var startEnd2 = _startEnd.dot(_startEnd);
  27974. var startEnd_startP = _startEnd.dot(_startP);
  27975. var t = startEnd_startP / startEnd2;
  27976. if (clampToLine) {
  27977. t = MathUtils.clamp(t, 0, 1);
  27978. }
  27979. return t;
  27980. };
  27981. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27982. var t = this.closestPointToPointParameter(point, clampToLine);
  27983. if (target === undefined) {
  27984. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27985. target = new Vector3();
  27986. }
  27987. return this.delta(target).multiplyScalar(t).add(this.start);
  27988. };
  27989. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27990. this.start.applyMatrix4(matrix);
  27991. this.end.applyMatrix4(matrix);
  27992. return this;
  27993. };
  27994. _proto.equals = function equals(line) {
  27995. return line.start.equals(this.start) && line.end.equals(this.end);
  27996. };
  27997. _proto.clone = function clone() {
  27998. return new this.constructor().copy(this);
  27999. };
  28000. return Line3;
  28001. }();
  28002. function ImmediateRenderObject(material) {
  28003. Object3D.call(this);
  28004. this.material = material;
  28005. this.render = function ()
  28006. /* renderCallback */
  28007. {};
  28008. this.hasPositions = false;
  28009. this.hasNormals = false;
  28010. this.hasColors = false;
  28011. this.hasUvs = false;
  28012. this.positionArray = null;
  28013. this.normalArray = null;
  28014. this.colorArray = null;
  28015. this.uvArray = null;
  28016. this.count = 0;
  28017. }
  28018. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  28019. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  28020. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  28021. var _vector$9 = /*@__PURE__*/new Vector3();
  28022. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  28023. _inheritsLoose(SpotLightHelper, _Object3D);
  28024. function SpotLightHelper(light, color) {
  28025. var _this;
  28026. _this = _Object3D.call(this) || this;
  28027. _this.light = light;
  28028. _this.light.updateMatrixWorld();
  28029. _this.matrix = light.matrixWorld;
  28030. _this.matrixAutoUpdate = false;
  28031. _this.color = color;
  28032. var geometry = new BufferGeometry();
  28033. 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];
  28034. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  28035. var p1 = i / l * Math.PI * 2;
  28036. var p2 = j / l * Math.PI * 2;
  28037. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  28038. }
  28039. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28040. var material = new LineBasicMaterial({
  28041. fog: false,
  28042. toneMapped: false
  28043. });
  28044. _this.cone = new LineSegments(geometry, material);
  28045. _this.add(_this.cone);
  28046. _this.update();
  28047. return _this;
  28048. }
  28049. var _proto = SpotLightHelper.prototype;
  28050. _proto.dispose = function dispose() {
  28051. this.cone.geometry.dispose();
  28052. this.cone.material.dispose();
  28053. };
  28054. _proto.update = function update() {
  28055. this.light.updateMatrixWorld();
  28056. var coneLength = this.light.distance ? this.light.distance : 1000;
  28057. var coneWidth = coneLength * Math.tan(this.light.angle);
  28058. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  28059. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  28060. this.cone.lookAt(_vector$9);
  28061. if (this.color !== undefined) {
  28062. this.cone.material.color.set(this.color);
  28063. } else {
  28064. this.cone.material.color.copy(this.light.color);
  28065. }
  28066. };
  28067. return SpotLightHelper;
  28068. }(Object3D);
  28069. var _vector$a = /*@__PURE__*/new Vector3();
  28070. var _boneMatrix = /*@__PURE__*/new Matrix4();
  28071. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  28072. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  28073. _inheritsLoose(SkeletonHelper, _LineSegments);
  28074. function SkeletonHelper(object) {
  28075. var _this;
  28076. var bones = getBoneList(object);
  28077. var geometry = new BufferGeometry();
  28078. var vertices = [];
  28079. var colors = [];
  28080. var color1 = new Color(0, 0, 1);
  28081. var color2 = new Color(0, 1, 0);
  28082. for (var i = 0; i < bones.length; i++) {
  28083. var bone = bones[i];
  28084. if (bone.parent && bone.parent.isBone) {
  28085. vertices.push(0, 0, 0);
  28086. vertices.push(0, 0, 0);
  28087. colors.push(color1.r, color1.g, color1.b);
  28088. colors.push(color2.r, color2.g, color2.b);
  28089. }
  28090. }
  28091. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28092. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28093. var material = new LineBasicMaterial({
  28094. vertexColors: true,
  28095. depthTest: false,
  28096. depthWrite: false,
  28097. toneMapped: false,
  28098. transparent: true
  28099. });
  28100. _this = _LineSegments.call(this, geometry, material) || this;
  28101. _this.type = 'SkeletonHelper';
  28102. _this.isSkeletonHelper = true;
  28103. _this.root = object;
  28104. _this.bones = bones;
  28105. _this.matrix = object.matrixWorld;
  28106. _this.matrixAutoUpdate = false;
  28107. return _this;
  28108. }
  28109. var _proto = SkeletonHelper.prototype;
  28110. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28111. var bones = this.bones;
  28112. var geometry = this.geometry;
  28113. var position = geometry.getAttribute('position');
  28114. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  28115. for (var i = 0, j = 0; i < bones.length; i++) {
  28116. var bone = bones[i];
  28117. if (bone.parent && bone.parent.isBone) {
  28118. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  28119. _vector$a.setFromMatrixPosition(_boneMatrix);
  28120. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  28121. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  28122. _vector$a.setFromMatrixPosition(_boneMatrix);
  28123. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  28124. j += 2;
  28125. }
  28126. }
  28127. geometry.getAttribute('position').needsUpdate = true;
  28128. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28129. };
  28130. return SkeletonHelper;
  28131. }(LineSegments);
  28132. function getBoneList(object) {
  28133. var boneList = [];
  28134. if (object && object.isBone) {
  28135. boneList.push(object);
  28136. }
  28137. for (var i = 0; i < object.children.length; i++) {
  28138. boneList.push.apply(boneList, getBoneList(object.children[i]));
  28139. }
  28140. return boneList;
  28141. }
  28142. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  28143. _inheritsLoose(PointLightHelper, _Mesh);
  28144. function PointLightHelper(light, sphereSize, color) {
  28145. var _this;
  28146. var geometry = new SphereGeometry(sphereSize, 4, 2);
  28147. var material = new MeshBasicMaterial({
  28148. wireframe: true,
  28149. fog: false,
  28150. toneMapped: false
  28151. });
  28152. _this = _Mesh.call(this, geometry, material) || this;
  28153. _this.light = light;
  28154. _this.light.updateMatrixWorld();
  28155. _this.color = color;
  28156. _this.type = 'PointLightHelper';
  28157. _this.matrix = _this.light.matrixWorld;
  28158. _this.matrixAutoUpdate = false;
  28159. _this.update();
  28160. /*
  28161. // TODO: delete this comment?
  28162. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28163. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28164. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28165. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28166. const d = light.distance;
  28167. if ( d === 0.0 ) {
  28168. this.lightDistance.visible = false;
  28169. } else {
  28170. this.lightDistance.scale.set( d, d, d );
  28171. }
  28172. this.add( this.lightDistance );
  28173. */
  28174. return _this;
  28175. }
  28176. var _proto = PointLightHelper.prototype;
  28177. _proto.dispose = function dispose() {
  28178. this.geometry.dispose();
  28179. this.material.dispose();
  28180. };
  28181. _proto.update = function update() {
  28182. if (this.color !== undefined) {
  28183. this.material.color.set(this.color);
  28184. } else {
  28185. this.material.color.copy(this.light.color);
  28186. }
  28187. /*
  28188. const d = this.light.distance;
  28189. if ( d === 0.0 ) {
  28190. this.lightDistance.visible = false;
  28191. } else {
  28192. this.lightDistance.visible = true;
  28193. this.lightDistance.scale.set( d, d, d );
  28194. }
  28195. */
  28196. };
  28197. return PointLightHelper;
  28198. }(Mesh);
  28199. var _vector$b = /*@__PURE__*/new Vector3();
  28200. var _color1 = /*@__PURE__*/new Color();
  28201. var _color2 = /*@__PURE__*/new Color();
  28202. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  28203. _inheritsLoose(HemisphereLightHelper, _Object3D);
  28204. function HemisphereLightHelper(light, size, color) {
  28205. var _this;
  28206. _this = _Object3D.call(this) || this;
  28207. _this.light = light;
  28208. _this.light.updateMatrixWorld();
  28209. _this.matrix = light.matrixWorld;
  28210. _this.matrixAutoUpdate = false;
  28211. _this.color = color;
  28212. var geometry = new OctahedronGeometry(size);
  28213. geometry.rotateY(Math.PI * 0.5);
  28214. _this.material = new MeshBasicMaterial({
  28215. wireframe: true,
  28216. fog: false,
  28217. toneMapped: false
  28218. });
  28219. if (_this.color === undefined) _this.material.vertexColors = true;
  28220. var position = geometry.getAttribute('position');
  28221. var colors = new Float32Array(position.count * 3);
  28222. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28223. _this.add(new Mesh(geometry, _this.material));
  28224. _this.update();
  28225. return _this;
  28226. }
  28227. var _proto = HemisphereLightHelper.prototype;
  28228. _proto.dispose = function dispose() {
  28229. this.children[0].geometry.dispose();
  28230. this.children[0].material.dispose();
  28231. };
  28232. _proto.update = function update() {
  28233. var mesh = this.children[0];
  28234. if (this.color !== undefined) {
  28235. this.material.color.set(this.color);
  28236. } else {
  28237. var colors = mesh.geometry.getAttribute('color');
  28238. _color1.copy(this.light.color);
  28239. _color2.copy(this.light.groundColor);
  28240. for (var i = 0, l = colors.count; i < l; i++) {
  28241. var color = i < l / 2 ? _color1 : _color2;
  28242. colors.setXYZ(i, color.r, color.g, color.b);
  28243. }
  28244. colors.needsUpdate = true;
  28245. }
  28246. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  28247. };
  28248. return HemisphereLightHelper;
  28249. }(Object3D);
  28250. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28251. _inheritsLoose(GridHelper, _LineSegments);
  28252. function GridHelper(size, divisions, color1, color2) {
  28253. var _this;
  28254. if (size === void 0) {
  28255. size = 10;
  28256. }
  28257. if (divisions === void 0) {
  28258. divisions = 10;
  28259. }
  28260. if (color1 === void 0) {
  28261. color1 = 0x444444;
  28262. }
  28263. if (color2 === void 0) {
  28264. color2 = 0x888888;
  28265. }
  28266. color1 = new Color(color1);
  28267. color2 = new Color(color2);
  28268. var center = divisions / 2;
  28269. var step = size / divisions;
  28270. var halfSize = size / 2;
  28271. var vertices = [],
  28272. colors = [];
  28273. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28274. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28275. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28276. var color = i === center ? color1 : color2;
  28277. color.toArray(colors, j);
  28278. j += 3;
  28279. color.toArray(colors, j);
  28280. j += 3;
  28281. color.toArray(colors, j);
  28282. j += 3;
  28283. color.toArray(colors, j);
  28284. j += 3;
  28285. }
  28286. var geometry = new BufferGeometry();
  28287. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28288. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28289. var material = new LineBasicMaterial({
  28290. vertexColors: true,
  28291. toneMapped: false
  28292. });
  28293. _this = _LineSegments.call(this, geometry, material) || this;
  28294. _this.type = 'GridHelper';
  28295. return _this;
  28296. }
  28297. return GridHelper;
  28298. }(LineSegments);
  28299. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28300. _inheritsLoose(PolarGridHelper, _LineSegments);
  28301. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28302. var _this;
  28303. if (radius === void 0) {
  28304. radius = 10;
  28305. }
  28306. if (radials === void 0) {
  28307. radials = 16;
  28308. }
  28309. if (circles === void 0) {
  28310. circles = 8;
  28311. }
  28312. if (divisions === void 0) {
  28313. divisions = 64;
  28314. }
  28315. if (color1 === void 0) {
  28316. color1 = 0x444444;
  28317. }
  28318. if (color2 === void 0) {
  28319. color2 = 0x888888;
  28320. }
  28321. color1 = new Color(color1);
  28322. color2 = new Color(color2);
  28323. var vertices = [];
  28324. var colors = []; // create the radials
  28325. for (var i = 0; i <= radials; i++) {
  28326. var v = i / radials * (Math.PI * 2);
  28327. var x = Math.sin(v) * radius;
  28328. var z = Math.cos(v) * radius;
  28329. vertices.push(0, 0, 0);
  28330. vertices.push(x, 0, z);
  28331. var color = i & 1 ? color1 : color2;
  28332. colors.push(color.r, color.g, color.b);
  28333. colors.push(color.r, color.g, color.b);
  28334. } // create the circles
  28335. for (var _i = 0; _i <= circles; _i++) {
  28336. var _color = _i & 1 ? color1 : color2;
  28337. var r = radius - radius / circles * _i;
  28338. for (var j = 0; j < divisions; j++) {
  28339. // first vertex
  28340. var _v = j / divisions * (Math.PI * 2);
  28341. var _x = Math.sin(_v) * r;
  28342. var _z = Math.cos(_v) * r;
  28343. vertices.push(_x, 0, _z);
  28344. colors.push(_color.r, _color.g, _color.b); // second vertex
  28345. _v = (j + 1) / divisions * (Math.PI * 2);
  28346. _x = Math.sin(_v) * r;
  28347. _z = Math.cos(_v) * r;
  28348. vertices.push(_x, 0, _z);
  28349. colors.push(_color.r, _color.g, _color.b);
  28350. }
  28351. }
  28352. var geometry = new BufferGeometry();
  28353. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28354. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28355. var material = new LineBasicMaterial({
  28356. vertexColors: true,
  28357. toneMapped: false
  28358. });
  28359. _this = _LineSegments.call(this, geometry, material) || this;
  28360. _this.type = 'PolarGridHelper';
  28361. return _this;
  28362. }
  28363. return PolarGridHelper;
  28364. }(LineSegments);
  28365. var _v1$6 = /*@__PURE__*/new Vector3();
  28366. var _v2$3 = /*@__PURE__*/new Vector3();
  28367. var _v3$1 = /*@__PURE__*/new Vector3();
  28368. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28369. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28370. function DirectionalLightHelper(light, size, color) {
  28371. var _this;
  28372. _this = _Object3D.call(this) || this;
  28373. _this.light = light;
  28374. _this.light.updateMatrixWorld();
  28375. _this.matrix = light.matrixWorld;
  28376. _this.matrixAutoUpdate = false;
  28377. _this.color = color;
  28378. if (size === undefined) size = 1;
  28379. var geometry = new BufferGeometry();
  28380. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28381. var material = new LineBasicMaterial({
  28382. fog: false,
  28383. toneMapped: false
  28384. });
  28385. _this.lightPlane = new Line(geometry, material);
  28386. _this.add(_this.lightPlane);
  28387. geometry = new BufferGeometry();
  28388. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28389. _this.targetLine = new Line(geometry, material);
  28390. _this.add(_this.targetLine);
  28391. _this.update();
  28392. return _this;
  28393. }
  28394. var _proto = DirectionalLightHelper.prototype;
  28395. _proto.dispose = function dispose() {
  28396. this.lightPlane.geometry.dispose();
  28397. this.lightPlane.material.dispose();
  28398. this.targetLine.geometry.dispose();
  28399. this.targetLine.material.dispose();
  28400. };
  28401. _proto.update = function update() {
  28402. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28403. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28404. _v3$1.subVectors(_v2$3, _v1$6);
  28405. this.lightPlane.lookAt(_v2$3);
  28406. if (this.color !== undefined) {
  28407. this.lightPlane.material.color.set(this.color);
  28408. this.targetLine.material.color.set(this.color);
  28409. } else {
  28410. this.lightPlane.material.color.copy(this.light.color);
  28411. this.targetLine.material.color.copy(this.light.color);
  28412. }
  28413. this.targetLine.lookAt(_v2$3);
  28414. this.targetLine.scale.z = _v3$1.length();
  28415. };
  28416. return DirectionalLightHelper;
  28417. }(Object3D);
  28418. var _vector$c = /*@__PURE__*/new Vector3();
  28419. var _camera = /*@__PURE__*/new Camera();
  28420. /**
  28421. * - shows frustum, line of sight and up of the camera
  28422. * - suitable for fast updates
  28423. * - based on frustum visualization in lightgl.js shadowmap example
  28424. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28425. */
  28426. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28427. _inheritsLoose(CameraHelper, _LineSegments);
  28428. function CameraHelper(camera) {
  28429. var _this;
  28430. var geometry = new BufferGeometry();
  28431. var material = new LineBasicMaterial({
  28432. color: 0xffffff,
  28433. vertexColors: true,
  28434. toneMapped: false
  28435. });
  28436. var vertices = [];
  28437. var colors = [];
  28438. var pointMap = {}; // colors
  28439. var colorFrustum = new Color(0xffaa00);
  28440. var colorCone = new Color(0xff0000);
  28441. var colorUp = new Color(0x00aaff);
  28442. var colorTarget = new Color(0xffffff);
  28443. var colorCross = new Color(0x333333); // near
  28444. addLine('n1', 'n2', colorFrustum);
  28445. addLine('n2', 'n4', colorFrustum);
  28446. addLine('n4', 'n3', colorFrustum);
  28447. addLine('n3', 'n1', colorFrustum); // far
  28448. addLine('f1', 'f2', colorFrustum);
  28449. addLine('f2', 'f4', colorFrustum);
  28450. addLine('f4', 'f3', colorFrustum);
  28451. addLine('f3', 'f1', colorFrustum); // sides
  28452. addLine('n1', 'f1', colorFrustum);
  28453. addLine('n2', 'f2', colorFrustum);
  28454. addLine('n3', 'f3', colorFrustum);
  28455. addLine('n4', 'f4', colorFrustum); // cone
  28456. addLine('p', 'n1', colorCone);
  28457. addLine('p', 'n2', colorCone);
  28458. addLine('p', 'n3', colorCone);
  28459. addLine('p', 'n4', colorCone); // up
  28460. addLine('u1', 'u2', colorUp);
  28461. addLine('u2', 'u3', colorUp);
  28462. addLine('u3', 'u1', colorUp); // target
  28463. addLine('c', 't', colorTarget);
  28464. addLine('p', 'c', colorCross); // cross
  28465. addLine('cn1', 'cn2', colorCross);
  28466. addLine('cn3', 'cn4', colorCross);
  28467. addLine('cf1', 'cf2', colorCross);
  28468. addLine('cf3', 'cf4', colorCross);
  28469. function addLine(a, b, color) {
  28470. addPoint(a, color);
  28471. addPoint(b, color);
  28472. }
  28473. function addPoint(id, color) {
  28474. vertices.push(0, 0, 0);
  28475. colors.push(color.r, color.g, color.b);
  28476. if (pointMap[id] === undefined) {
  28477. pointMap[id] = [];
  28478. }
  28479. pointMap[id].push(vertices.length / 3 - 1);
  28480. }
  28481. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28482. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28483. _this = _LineSegments.call(this, geometry, material) || this;
  28484. _this.type = 'CameraHelper';
  28485. _this.camera = camera;
  28486. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28487. _this.matrix = camera.matrixWorld;
  28488. _this.matrixAutoUpdate = false;
  28489. _this.pointMap = pointMap;
  28490. _this.update();
  28491. return _this;
  28492. }
  28493. var _proto = CameraHelper.prototype;
  28494. _proto.update = function update() {
  28495. var geometry = this.geometry;
  28496. var pointMap = this.pointMap;
  28497. var w = 1,
  28498. h = 1; // we need just camera projection matrix inverse
  28499. // world matrix must be identity
  28500. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28501. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28502. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28503. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28504. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28505. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28506. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28507. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28508. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28509. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28510. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28511. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28512. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28513. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28514. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28515. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28516. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28517. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28518. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28519. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28520. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28521. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28522. geometry.getAttribute('position').needsUpdate = true;
  28523. };
  28524. return CameraHelper;
  28525. }(LineSegments);
  28526. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28527. _vector$c.set(x, y, z).unproject(camera);
  28528. var points = pointMap[point];
  28529. if (points !== undefined) {
  28530. var position = geometry.getAttribute('position');
  28531. for (var i = 0, l = points.length; i < l; i++) {
  28532. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28533. }
  28534. }
  28535. }
  28536. var _box$3 = /*@__PURE__*/new Box3();
  28537. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28538. _inheritsLoose(BoxHelper, _LineSegments);
  28539. function BoxHelper(object, color) {
  28540. var _this;
  28541. if (color === void 0) {
  28542. color = 0xffff00;
  28543. }
  28544. 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]);
  28545. var positions = new Float32Array(8 * 3);
  28546. var geometry = new BufferGeometry();
  28547. geometry.setIndex(new BufferAttribute(indices, 1));
  28548. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28549. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28550. color: color,
  28551. toneMapped: false
  28552. })) || this;
  28553. _this.object = object;
  28554. _this.type = 'BoxHelper';
  28555. _this.matrixAutoUpdate = false;
  28556. _this.update();
  28557. return _this;
  28558. }
  28559. var _proto = BoxHelper.prototype;
  28560. _proto.update = function update(object) {
  28561. if (object !== undefined) {
  28562. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28563. }
  28564. if (this.object !== undefined) {
  28565. _box$3.setFromObject(this.object);
  28566. }
  28567. if (_box$3.isEmpty()) return;
  28568. var min = _box$3.min;
  28569. var max = _box$3.max;
  28570. /*
  28571. 5____4
  28572. 1/___0/|
  28573. | 6__|_7
  28574. 2/___3/
  28575. 0: max.x, max.y, max.z
  28576. 1: min.x, max.y, max.z
  28577. 2: min.x, min.y, max.z
  28578. 3: max.x, min.y, max.z
  28579. 4: max.x, max.y, min.z
  28580. 5: min.x, max.y, min.z
  28581. 6: min.x, min.y, min.z
  28582. 7: max.x, min.y, min.z
  28583. */
  28584. var position = this.geometry.attributes.position;
  28585. var array = position.array;
  28586. array[0] = max.x;
  28587. array[1] = max.y;
  28588. array[2] = max.z;
  28589. array[3] = min.x;
  28590. array[4] = max.y;
  28591. array[5] = max.z;
  28592. array[6] = min.x;
  28593. array[7] = min.y;
  28594. array[8] = max.z;
  28595. array[9] = max.x;
  28596. array[10] = min.y;
  28597. array[11] = max.z;
  28598. array[12] = max.x;
  28599. array[13] = max.y;
  28600. array[14] = min.z;
  28601. array[15] = min.x;
  28602. array[16] = max.y;
  28603. array[17] = min.z;
  28604. array[18] = min.x;
  28605. array[19] = min.y;
  28606. array[20] = min.z;
  28607. array[21] = max.x;
  28608. array[22] = min.y;
  28609. array[23] = min.z;
  28610. position.needsUpdate = true;
  28611. this.geometry.computeBoundingSphere();
  28612. };
  28613. _proto.setFromObject = function setFromObject(object) {
  28614. this.object = object;
  28615. this.update();
  28616. return this;
  28617. };
  28618. _proto.copy = function copy(source) {
  28619. LineSegments.prototype.copy.call(this, source);
  28620. this.object = source.object;
  28621. return this;
  28622. };
  28623. return BoxHelper;
  28624. }(LineSegments);
  28625. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28626. _inheritsLoose(Box3Helper, _LineSegments);
  28627. function Box3Helper(box, color) {
  28628. var _this;
  28629. if (color === void 0) {
  28630. color = 0xffff00;
  28631. }
  28632. 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]);
  28633. 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];
  28634. var geometry = new BufferGeometry();
  28635. geometry.setIndex(new BufferAttribute(indices, 1));
  28636. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28637. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28638. color: color,
  28639. toneMapped: false
  28640. })) || this;
  28641. _this.box = box;
  28642. _this.type = 'Box3Helper';
  28643. _this.geometry.computeBoundingSphere();
  28644. return _this;
  28645. }
  28646. var _proto = Box3Helper.prototype;
  28647. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28648. var box = this.box;
  28649. if (box.isEmpty()) return;
  28650. box.getCenter(this.position);
  28651. box.getSize(this.scale);
  28652. this.scale.multiplyScalar(0.5);
  28653. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28654. };
  28655. return Box3Helper;
  28656. }(LineSegments);
  28657. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28658. _inheritsLoose(PlaneHelper, _Line);
  28659. function PlaneHelper(plane, size, hex) {
  28660. var _this;
  28661. if (size === void 0) {
  28662. size = 1;
  28663. }
  28664. if (hex === void 0) {
  28665. hex = 0xffff00;
  28666. }
  28667. var color = hex;
  28668. 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];
  28669. var geometry = new BufferGeometry();
  28670. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28671. geometry.computeBoundingSphere();
  28672. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28673. color: color,
  28674. toneMapped: false
  28675. })) || this;
  28676. _this.type = 'PlaneHelper';
  28677. _this.plane = plane;
  28678. _this.size = size;
  28679. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28680. var geometry2 = new BufferGeometry();
  28681. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28682. geometry2.computeBoundingSphere();
  28683. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28684. color: color,
  28685. opacity: 0.2,
  28686. transparent: true,
  28687. depthWrite: false,
  28688. toneMapped: false
  28689. })));
  28690. return _this;
  28691. }
  28692. var _proto = PlaneHelper.prototype;
  28693. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28694. var scale = -this.plane.constant;
  28695. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28696. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28697. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28698. this.lookAt(this.plane.normal);
  28699. _Line.prototype.updateMatrixWorld.call(this, force);
  28700. };
  28701. return PlaneHelper;
  28702. }(Line);
  28703. var _axis = /*@__PURE__*/new Vector3();
  28704. var _lineGeometry, _coneGeometry;
  28705. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28706. _inheritsLoose(ArrowHelper, _Object3D);
  28707. // dir is assumed to be normalized
  28708. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28709. var _this;
  28710. if (dir === void 0) {
  28711. dir = new Vector3(0, 0, 1);
  28712. }
  28713. if (origin === void 0) {
  28714. origin = new Vector3(0, 0, 0);
  28715. }
  28716. if (length === void 0) {
  28717. length = 1;
  28718. }
  28719. if (color === void 0) {
  28720. color = 0xffff00;
  28721. }
  28722. if (headLength === void 0) {
  28723. headLength = length * 0.2;
  28724. }
  28725. if (headWidth === void 0) {
  28726. headWidth = headLength * 0.2;
  28727. }
  28728. _this = _Object3D.call(this) || this;
  28729. _this.type = 'ArrowHelper';
  28730. if (_lineGeometry === undefined) {
  28731. _lineGeometry = new BufferGeometry();
  28732. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28733. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28734. _coneGeometry.translate(0, -0.5, 0);
  28735. }
  28736. _this.position.copy(origin);
  28737. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28738. color: color,
  28739. toneMapped: false
  28740. }));
  28741. _this.line.matrixAutoUpdate = false;
  28742. _this.add(_this.line);
  28743. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28744. color: color,
  28745. toneMapped: false
  28746. }));
  28747. _this.cone.matrixAutoUpdate = false;
  28748. _this.add(_this.cone);
  28749. _this.setDirection(dir);
  28750. _this.setLength(length, headLength, headWidth);
  28751. return _this;
  28752. }
  28753. var _proto = ArrowHelper.prototype;
  28754. _proto.setDirection = function setDirection(dir) {
  28755. // dir is assumed to be normalized
  28756. if (dir.y > 0.99999) {
  28757. this.quaternion.set(0, 0, 0, 1);
  28758. } else if (dir.y < -0.99999) {
  28759. this.quaternion.set(1, 0, 0, 0);
  28760. } else {
  28761. _axis.set(dir.z, 0, -dir.x).normalize();
  28762. var radians = Math.acos(dir.y);
  28763. this.quaternion.setFromAxisAngle(_axis, radians);
  28764. }
  28765. };
  28766. _proto.setLength = function setLength(length, headLength, headWidth) {
  28767. if (headLength === void 0) {
  28768. headLength = length * 0.2;
  28769. }
  28770. if (headWidth === void 0) {
  28771. headWidth = headLength * 0.2;
  28772. }
  28773. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28774. this.line.updateMatrix();
  28775. this.cone.scale.set(headWidth, headLength, headWidth);
  28776. this.cone.position.y = length;
  28777. this.cone.updateMatrix();
  28778. };
  28779. _proto.setColor = function setColor(color) {
  28780. this.line.material.color.set(color);
  28781. this.cone.material.color.set(color);
  28782. };
  28783. _proto.copy = function copy(source) {
  28784. _Object3D.prototype.copy.call(this, source, false);
  28785. this.line.copy(source.line);
  28786. this.cone.copy(source.cone);
  28787. return this;
  28788. };
  28789. return ArrowHelper;
  28790. }(Object3D);
  28791. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28792. _inheritsLoose(AxesHelper, _LineSegments);
  28793. function AxesHelper(size) {
  28794. var _this;
  28795. if (size === void 0) {
  28796. size = 1;
  28797. }
  28798. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28799. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28800. var geometry = new BufferGeometry();
  28801. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28802. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28803. var material = new LineBasicMaterial({
  28804. vertexColors: true,
  28805. toneMapped: false
  28806. });
  28807. _this = _LineSegments.call(this, geometry, material) || this;
  28808. _this.type = 'AxesHelper';
  28809. return _this;
  28810. }
  28811. return AxesHelper;
  28812. }(LineSegments);
  28813. var _floatView = new Float32Array(1);
  28814. var _int32View = new Int32Array(_floatView.buffer);
  28815. var DataUtils = {
  28816. // Converts float32 to float16 (stored as uint16 value).
  28817. toHalfFloat: function toHalfFloat(val) {
  28818. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28819. /* This method is faster than the OpenEXR implementation (very often
  28820. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28821. * by James Tursa?s half-precision code. */
  28822. _floatView[0] = val;
  28823. var x = _int32View[0];
  28824. var bits = x >> 16 & 0x8000;
  28825. /* Get the sign */
  28826. var m = x >> 12 & 0x07ff;
  28827. /* Keep one extra bit for rounding */
  28828. var e = x >> 23 & 0xff;
  28829. /* Using int is faster here */
  28830. /* If zero, or denormal, or exponent underflows too much for a denormal
  28831. * half, return signed zero. */
  28832. if (e < 103) return bits;
  28833. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28834. if (e > 142) {
  28835. bits |= 0x7c00;
  28836. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28837. * not Inf, so make sure we set one mantissa bit too. */
  28838. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28839. return bits;
  28840. }
  28841. /* If exponent underflows but not too much, return a denormal */
  28842. if (e < 113) {
  28843. m |= 0x0800;
  28844. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28845. * to 1, which is OK. */
  28846. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28847. return bits;
  28848. }
  28849. bits |= e - 112 << 10 | m >> 1;
  28850. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28851. * the exponent, which is OK. */
  28852. bits += m & 1;
  28853. return bits;
  28854. }
  28855. };
  28856. var _ENCODINGS;
  28857. var LOD_MIN = 4;
  28858. var LOD_MAX = 8;
  28859. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28860. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28861. // geometric shadowing function. These sigma values squared must match the
  28862. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28863. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28864. 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
  28865. // samples and exit early, but not recompile the shader.
  28866. var MAX_SAMPLES = 20;
  28867. 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);
  28868. var backgroundMaterial = new MeshBasicMaterial({
  28869. side: BackSide,
  28870. depthWrite: false,
  28871. depthTest: false
  28872. });
  28873. var backgroundBox = new Mesh(new BoxGeometry(), backgroundMaterial);
  28874. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28875. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28876. _lodPlanes = _createPlanes2._lodPlanes,
  28877. _sizeLods = _createPlanes2._sizeLods,
  28878. _sigmas = _createPlanes2._sigmas;
  28879. var _clearColor = /*@__PURE__*/new Color();
  28880. var _oldTarget = null; // Golden Ratio
  28881. var PHI = (1 + Math.sqrt(5)) / 2;
  28882. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28883. // same axis), used as axis directions evenly spread on a sphere.
  28884. 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)];
  28885. /**
  28886. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28887. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28888. * blur to be quickly accessed based on material roughness. It is packed into a
  28889. * special CubeUV format that allows us to perform custom interpolation so that
  28890. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28891. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28892. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28893. * higher roughness levels. In this way we maintain resolution to smoothly
  28894. * interpolate diffuse lighting while limiting sampling computation.
  28895. */
  28896. function convertLinearToRGBE(color) {
  28897. var maxComponent = Math.max(color.r, color.g, color.b);
  28898. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28899. color.multiplyScalar(Math.pow(2.0, -fExp));
  28900. var alpha = (fExp + 128.0) / 255.0;
  28901. return alpha;
  28902. }
  28903. var PMREMGenerator = /*#__PURE__*/function () {
  28904. function PMREMGenerator(renderer) {
  28905. this._renderer = renderer;
  28906. this._pingPongRenderTarget = null;
  28907. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28908. this._equirectShader = null;
  28909. this._cubemapShader = null;
  28910. this._compileMaterial(this._blurMaterial);
  28911. }
  28912. /**
  28913. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28914. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28915. * in radians to be applied to the scene before PMREM generation. Optional near
  28916. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28917. * is placed at the origin).
  28918. */
  28919. var _proto = PMREMGenerator.prototype;
  28920. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28921. if (sigma === void 0) {
  28922. sigma = 0;
  28923. }
  28924. if (near === void 0) {
  28925. near = 0.1;
  28926. }
  28927. if (far === void 0) {
  28928. far = 100;
  28929. }
  28930. _oldTarget = this._renderer.getRenderTarget();
  28931. var cubeUVRenderTarget = this._allocateTargets();
  28932. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28933. if (sigma > 0) {
  28934. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28935. }
  28936. this._applyPMREM(cubeUVRenderTarget);
  28937. this._cleanup(cubeUVRenderTarget);
  28938. return cubeUVRenderTarget;
  28939. }
  28940. /**
  28941. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28942. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28943. * as this matches best with the 256 x 256 cubemap output.
  28944. */
  28945. ;
  28946. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28947. return this._fromTexture(equirectangular);
  28948. }
  28949. /**
  28950. * Generates a PMREM from an cubemap texture, which can be either LDR
  28951. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28952. * as this matches best with the 256 x 256 cubemap output.
  28953. */
  28954. ;
  28955. _proto.fromCubemap = function fromCubemap(cubemap) {
  28956. return this._fromTexture(cubemap);
  28957. }
  28958. /**
  28959. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28960. * your texture's network fetch for increased concurrency.
  28961. */
  28962. ;
  28963. _proto.compileCubemapShader = function compileCubemapShader() {
  28964. if (this._cubemapShader === null) {
  28965. this._cubemapShader = _getCubemapShader();
  28966. this._compileMaterial(this._cubemapShader);
  28967. }
  28968. }
  28969. /**
  28970. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28971. * your texture's network fetch for increased concurrency.
  28972. */
  28973. ;
  28974. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28975. if (this._equirectShader === null) {
  28976. this._equirectShader = _getEquirectShader();
  28977. this._compileMaterial(this._equirectShader);
  28978. }
  28979. }
  28980. /**
  28981. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28982. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28983. * one of them will cause any others to also become unusable.
  28984. */
  28985. ;
  28986. _proto.dispose = function dispose() {
  28987. this._blurMaterial.dispose();
  28988. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28989. if (this._equirectShader !== null) this._equirectShader.dispose();
  28990. for (var i = 0; i < _lodPlanes.length; i++) {
  28991. _lodPlanes[i].dispose();
  28992. }
  28993. } // private interface
  28994. ;
  28995. _proto._cleanup = function _cleanup(outputTarget) {
  28996. this._pingPongRenderTarget.dispose();
  28997. this._renderer.setRenderTarget(_oldTarget);
  28998. outputTarget.scissorTest = false;
  28999. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  29000. };
  29001. _proto._fromTexture = function _fromTexture(texture) {
  29002. _oldTarget = this._renderer.getRenderTarget();
  29003. var cubeUVRenderTarget = this._allocateTargets(texture);
  29004. this._textureToCubeUV(texture, cubeUVRenderTarget);
  29005. this._applyPMREM(cubeUVRenderTarget);
  29006. this._cleanup(cubeUVRenderTarget);
  29007. return cubeUVRenderTarget;
  29008. };
  29009. _proto._allocateTargets = function _allocateTargets(texture) {
  29010. // warning: null texture is valid
  29011. var params = {
  29012. magFilter: NearestFilter,
  29013. minFilter: NearestFilter,
  29014. generateMipmaps: false,
  29015. type: UnsignedByteType,
  29016. format: RGBEFormat,
  29017. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  29018. depthBuffer: false
  29019. };
  29020. var cubeUVRenderTarget = _createRenderTarget(params);
  29021. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  29022. this._pingPongRenderTarget = _createRenderTarget(params);
  29023. return cubeUVRenderTarget;
  29024. };
  29025. _proto._compileMaterial = function _compileMaterial(material) {
  29026. var tmpMesh = new Mesh(_lodPlanes[0], material);
  29027. this._renderer.compile(tmpMesh, _flatCamera);
  29028. };
  29029. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  29030. var fov = 90;
  29031. var aspect = 1;
  29032. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  29033. var upSign = [1, -1, 1, 1, 1, 1];
  29034. var forwardSign = [1, 1, 1, -1, -1, -1];
  29035. var renderer = this._renderer;
  29036. var originalAutoClear = renderer.autoClear;
  29037. var outputEncoding = renderer.outputEncoding;
  29038. var toneMapping = renderer.toneMapping;
  29039. renderer.getClearColor(_clearColor);
  29040. renderer.toneMapping = NoToneMapping;
  29041. renderer.outputEncoding = LinearEncoding;
  29042. renderer.autoClear = false;
  29043. var useSolidColor = false;
  29044. var background = scene.background;
  29045. if (background) {
  29046. if (background.isColor) {
  29047. backgroundMaterial.color.copy(background).convertSRGBToLinear();
  29048. scene.background = null;
  29049. var alpha = convertLinearToRGBE(backgroundMaterial.color);
  29050. backgroundMaterial.opacity = alpha;
  29051. useSolidColor = true;
  29052. }
  29053. } else {
  29054. backgroundMaterial.color.copy(_clearColor).convertSRGBToLinear();
  29055. var _alpha = convertLinearToRGBE(backgroundMaterial.color);
  29056. backgroundMaterial.opacity = _alpha;
  29057. useSolidColor = true;
  29058. }
  29059. for (var i = 0; i < 6; i++) {
  29060. var col = i % 3;
  29061. if (col == 0) {
  29062. cubeCamera.up.set(0, upSign[i], 0);
  29063. cubeCamera.lookAt(forwardSign[i], 0, 0);
  29064. } else if (col == 1) {
  29065. cubeCamera.up.set(0, 0, upSign[i]);
  29066. cubeCamera.lookAt(0, forwardSign[i], 0);
  29067. } else {
  29068. cubeCamera.up.set(0, upSign[i], 0);
  29069. cubeCamera.lookAt(0, 0, forwardSign[i]);
  29070. }
  29071. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  29072. renderer.setRenderTarget(cubeUVRenderTarget);
  29073. if (useSolidColor) {
  29074. renderer.render(backgroundBox, cubeCamera);
  29075. }
  29076. renderer.render(scene, cubeCamera);
  29077. }
  29078. renderer.toneMapping = toneMapping;
  29079. renderer.outputEncoding = outputEncoding;
  29080. renderer.autoClear = originalAutoClear;
  29081. };
  29082. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  29083. var renderer = this._renderer;
  29084. if (texture.isCubeTexture) {
  29085. if (this._cubemapShader == null) {
  29086. this._cubemapShader = _getCubemapShader();
  29087. }
  29088. } else {
  29089. if (this._equirectShader == null) {
  29090. this._equirectShader = _getEquirectShader();
  29091. }
  29092. }
  29093. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  29094. var mesh = new Mesh(_lodPlanes[0], material);
  29095. var uniforms = material.uniforms;
  29096. uniforms['envMap'].value = texture;
  29097. if (!texture.isCubeTexture) {
  29098. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  29099. }
  29100. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  29101. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  29102. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  29103. renderer.setRenderTarget(cubeUVRenderTarget);
  29104. renderer.render(mesh, _flatCamera);
  29105. };
  29106. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  29107. var renderer = this._renderer;
  29108. var autoClear = renderer.autoClear;
  29109. renderer.autoClear = false;
  29110. for (var i = 1; i < TOTAL_LODS; i++) {
  29111. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  29112. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  29113. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  29114. }
  29115. renderer.autoClear = autoClear;
  29116. }
  29117. /**
  29118. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  29119. * vertically and horizontally, but this breaks down on a cube. Here we apply
  29120. * the blur latitudinally (around the poles), and then longitudinally (towards
  29121. * the poles) to approximate the orthogonally-separable blur. It is least
  29122. * accurate at the poles, but still does a decent job.
  29123. */
  29124. ;
  29125. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  29126. var pingPongRenderTarget = this._pingPongRenderTarget;
  29127. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  29128. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  29129. };
  29130. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  29131. var renderer = this._renderer;
  29132. var blurMaterial = this._blurMaterial;
  29133. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  29134. console.error('blur direction must be either latitudinal or longitudinal!');
  29135. } // Number of standard deviations at which to cut off the discrete approximation.
  29136. var STANDARD_DEVIATIONS = 3;
  29137. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  29138. var blurUniforms = blurMaterial.uniforms;
  29139. var pixels = _sizeLods[lodIn] - 1;
  29140. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  29141. var sigmaPixels = sigmaRadians / radiansPerPixel;
  29142. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  29143. if (samples > MAX_SAMPLES) {
  29144. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  29145. }
  29146. var weights = [];
  29147. var sum = 0;
  29148. for (var i = 0; i < MAX_SAMPLES; ++i) {
  29149. var _x = i / sigmaPixels;
  29150. var weight = Math.exp(-_x * _x / 2);
  29151. weights.push(weight);
  29152. if (i == 0) {
  29153. sum += weight;
  29154. } else if (i < samples) {
  29155. sum += 2 * weight;
  29156. }
  29157. }
  29158. for (var _i = 0; _i < weights.length; _i++) {
  29159. weights[_i] = weights[_i] / sum;
  29160. }
  29161. blurUniforms['envMap'].value = targetIn.texture;
  29162. blurUniforms['samples'].value = samples;
  29163. blurUniforms['weights'].value = weights;
  29164. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  29165. if (poleAxis) {
  29166. blurUniforms['poleAxis'].value = poleAxis;
  29167. }
  29168. blurUniforms['dTheta'].value = radiansPerPixel;
  29169. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  29170. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29171. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29172. var outputSize = _sizeLods[lodOut];
  29173. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  29174. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  29175. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  29176. renderer.setRenderTarget(targetOut);
  29177. renderer.render(blurMesh, _flatCamera);
  29178. };
  29179. return PMREMGenerator;
  29180. }();
  29181. function _isLDR(texture) {
  29182. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  29183. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29184. }
  29185. function _createPlanes() {
  29186. var _lodPlanes = [];
  29187. var _sizeLods = [];
  29188. var _sigmas = [];
  29189. var lod = LOD_MAX;
  29190. for (var i = 0; i < TOTAL_LODS; i++) {
  29191. var sizeLod = Math.pow(2, lod);
  29192. _sizeLods.push(sizeLod);
  29193. var sigma = 1.0 / sizeLod;
  29194. if (i > LOD_MAX - LOD_MIN) {
  29195. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  29196. } else if (i == 0) {
  29197. sigma = 0;
  29198. }
  29199. _sigmas.push(sigma);
  29200. var texelSize = 1.0 / (sizeLod - 1);
  29201. var min = -texelSize / 2;
  29202. var max = 1 + texelSize / 2;
  29203. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  29204. var cubeFaces = 6;
  29205. var vertices = 6;
  29206. var positionSize = 3;
  29207. var uvSize = 2;
  29208. var faceIndexSize = 1;
  29209. var position = new Float32Array(positionSize * vertices * cubeFaces);
  29210. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  29211. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  29212. for (var face = 0; face < cubeFaces; face++) {
  29213. var x = face % 3 * 2 / 3 - 1;
  29214. var y = face > 2 ? 0 : -1;
  29215. 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];
  29216. position.set(coordinates, positionSize * vertices * face);
  29217. uv.set(uv1, uvSize * vertices * face);
  29218. var fill = [face, face, face, face, face, face];
  29219. faceIndex.set(fill, faceIndexSize * vertices * face);
  29220. }
  29221. var planes = new BufferGeometry();
  29222. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  29223. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  29224. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  29225. _lodPlanes.push(planes);
  29226. if (lod > LOD_MIN) {
  29227. lod--;
  29228. }
  29229. }
  29230. return {
  29231. _lodPlanes: _lodPlanes,
  29232. _sizeLods: _sizeLods,
  29233. _sigmas: _sigmas
  29234. };
  29235. }
  29236. function _createRenderTarget(params) {
  29237. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  29238. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29239. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29240. cubeUVRenderTarget.scissorTest = true;
  29241. return cubeUVRenderTarget;
  29242. }
  29243. function _setViewport(target, x, y, width, height) {
  29244. target.viewport.set(x, y, width, height);
  29245. target.scissor.set(x, y, width, height);
  29246. }
  29247. function _getBlurShader(maxSamples) {
  29248. var weights = new Float32Array(maxSamples);
  29249. var poleAxis = new Vector3(0, 1, 0);
  29250. var shaderMaterial = new RawShaderMaterial({
  29251. name: 'SphericalGaussianBlur',
  29252. defines: {
  29253. 'n': maxSamples
  29254. },
  29255. uniforms: {
  29256. 'envMap': {
  29257. value: null
  29258. },
  29259. 'samples': {
  29260. value: 1
  29261. },
  29262. 'weights': {
  29263. value: weights
  29264. },
  29265. 'latitudinal': {
  29266. value: false
  29267. },
  29268. 'dTheta': {
  29269. value: 0
  29270. },
  29271. 'mipInt': {
  29272. value: 0
  29273. },
  29274. 'poleAxis': {
  29275. value: poleAxis
  29276. },
  29277. 'inputEncoding': {
  29278. value: ENCODINGS[LinearEncoding]
  29279. },
  29280. 'outputEncoding': {
  29281. value: ENCODINGS[LinearEncoding]
  29282. }
  29283. },
  29284. vertexShader: _getCommonVertexShader(),
  29285. fragmentShader:
  29286. /* glsl */
  29287. "\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",
  29288. blending: NoBlending,
  29289. depthTest: false,
  29290. depthWrite: false
  29291. });
  29292. return shaderMaterial;
  29293. }
  29294. function _getEquirectShader() {
  29295. var texelSize = new Vector2(1, 1);
  29296. var shaderMaterial = new RawShaderMaterial({
  29297. name: 'EquirectangularToCubeUV',
  29298. uniforms: {
  29299. 'envMap': {
  29300. value: null
  29301. },
  29302. 'texelSize': {
  29303. value: texelSize
  29304. },
  29305. 'inputEncoding': {
  29306. value: ENCODINGS[LinearEncoding]
  29307. },
  29308. 'outputEncoding': {
  29309. value: ENCODINGS[LinearEncoding]
  29310. }
  29311. },
  29312. vertexShader: _getCommonVertexShader(),
  29313. fragmentShader:
  29314. /* glsl */
  29315. "\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",
  29316. blending: NoBlending,
  29317. depthTest: false,
  29318. depthWrite: false
  29319. });
  29320. return shaderMaterial;
  29321. }
  29322. function _getCubemapShader() {
  29323. var shaderMaterial = new RawShaderMaterial({
  29324. name: 'CubemapToCubeUV',
  29325. uniforms: {
  29326. 'envMap': {
  29327. value: null
  29328. },
  29329. 'inputEncoding': {
  29330. value: ENCODINGS[LinearEncoding]
  29331. },
  29332. 'outputEncoding': {
  29333. value: ENCODINGS[LinearEncoding]
  29334. }
  29335. },
  29336. vertexShader: _getCommonVertexShader(),
  29337. fragmentShader:
  29338. /* glsl */
  29339. "\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",
  29340. blending: NoBlending,
  29341. depthTest: false,
  29342. depthWrite: false
  29343. });
  29344. return shaderMaterial;
  29345. }
  29346. function _getCommonVertexShader() {
  29347. return (
  29348. /* glsl */
  29349. "\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"
  29350. );
  29351. }
  29352. function _getEncodings() {
  29353. return (
  29354. /* glsl */
  29355. "\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"
  29356. );
  29357. }
  29358. var LineStrip = 0;
  29359. var LinePieces = 1;
  29360. var NoColors = 0;
  29361. var FaceColors = 1;
  29362. var VertexColors = 2;
  29363. function MeshFaceMaterial(materials) {
  29364. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29365. return materials;
  29366. }
  29367. function MultiMaterial(materials) {
  29368. if (materials === void 0) {
  29369. materials = [];
  29370. }
  29371. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29372. materials.isMultiMaterial = true;
  29373. materials.materials = materials;
  29374. materials.clone = function () {
  29375. return materials.slice();
  29376. };
  29377. return materials;
  29378. }
  29379. function PointCloud(geometry, material) {
  29380. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29381. return new Points(geometry, material);
  29382. }
  29383. function Particle(material) {
  29384. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29385. return new Sprite(material);
  29386. }
  29387. function ParticleSystem(geometry, material) {
  29388. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29389. return new Points(geometry, material);
  29390. }
  29391. function PointCloudMaterial(parameters) {
  29392. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29393. return new PointsMaterial(parameters);
  29394. }
  29395. function ParticleBasicMaterial(parameters) {
  29396. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29397. return new PointsMaterial(parameters);
  29398. }
  29399. function ParticleSystemMaterial(parameters) {
  29400. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29401. return new PointsMaterial(parameters);
  29402. }
  29403. function Vertex(x, y, z) {
  29404. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29405. return new Vector3(x, y, z);
  29406. } //
  29407. function DynamicBufferAttribute(array, itemSize) {
  29408. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29409. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29410. }
  29411. function Int8Attribute(array, itemSize) {
  29412. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29413. return new Int8BufferAttribute(array, itemSize);
  29414. }
  29415. function Uint8Attribute(array, itemSize) {
  29416. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29417. return new Uint8BufferAttribute(array, itemSize);
  29418. }
  29419. function Uint8ClampedAttribute(array, itemSize) {
  29420. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29421. return new Uint8ClampedBufferAttribute(array, itemSize);
  29422. }
  29423. function Int16Attribute(array, itemSize) {
  29424. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29425. return new Int16BufferAttribute(array, itemSize);
  29426. }
  29427. function Uint16Attribute(array, itemSize) {
  29428. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29429. return new Uint16BufferAttribute(array, itemSize);
  29430. }
  29431. function Int32Attribute(array, itemSize) {
  29432. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29433. return new Int32BufferAttribute(array, itemSize);
  29434. }
  29435. function Uint32Attribute(array, itemSize) {
  29436. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29437. return new Uint32BufferAttribute(array, itemSize);
  29438. }
  29439. function Float32Attribute(array, itemSize) {
  29440. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29441. return new Float32BufferAttribute(array, itemSize);
  29442. }
  29443. function Float64Attribute(array, itemSize) {
  29444. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29445. return new Float64BufferAttribute(array, itemSize);
  29446. } //
  29447. Curve.create = function (construct, getPoint) {
  29448. console.log('THREE.Curve.create() has been deprecated');
  29449. construct.prototype = Object.create(Curve.prototype);
  29450. construct.prototype.constructor = construct;
  29451. construct.prototype.getPoint = getPoint;
  29452. return construct;
  29453. }; //
  29454. Object.assign(Path.prototype, {
  29455. fromPoints: function fromPoints(points) {
  29456. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29457. return this.setFromPoints(points);
  29458. }
  29459. }); //
  29460. function AxisHelper(size) {
  29461. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29462. return new AxesHelper(size);
  29463. }
  29464. function BoundingBoxHelper(object, color) {
  29465. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29466. return new BoxHelper(object, color);
  29467. }
  29468. function EdgesHelper(object, hex) {
  29469. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29470. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29471. color: hex !== undefined ? hex : 0xffffff
  29472. }));
  29473. }
  29474. GridHelper.prototype.setColors = function () {
  29475. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29476. };
  29477. SkeletonHelper.prototype.update = function () {
  29478. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29479. };
  29480. function WireframeHelper(object, hex) {
  29481. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29482. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29483. color: hex !== undefined ? hex : 0xffffff
  29484. }));
  29485. } //
  29486. Object.assign(Loader.prototype, {
  29487. extractUrlBase: function extractUrlBase(url) {
  29488. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29489. return LoaderUtils.extractUrlBase(url);
  29490. }
  29491. });
  29492. Loader.Handlers = {
  29493. add: function add()
  29494. /* regex, loader */
  29495. {
  29496. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29497. },
  29498. get: function get()
  29499. /* file */
  29500. {
  29501. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29502. }
  29503. };
  29504. function XHRLoader(manager) {
  29505. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29506. return new FileLoader(manager);
  29507. }
  29508. function BinaryTextureLoader(manager) {
  29509. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29510. return new DataTextureLoader(manager);
  29511. } //
  29512. Object.assign(Box2.prototype, {
  29513. center: function center(optionalTarget) {
  29514. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29515. return this.getCenter(optionalTarget);
  29516. },
  29517. empty: function empty() {
  29518. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29519. return this.isEmpty();
  29520. },
  29521. isIntersectionBox: function isIntersectionBox(box) {
  29522. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29523. return this.intersectsBox(box);
  29524. },
  29525. size: function size(optionalTarget) {
  29526. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29527. return this.getSize(optionalTarget);
  29528. }
  29529. });
  29530. Object.assign(Box3.prototype, {
  29531. center: function center(optionalTarget) {
  29532. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29533. return this.getCenter(optionalTarget);
  29534. },
  29535. empty: function empty() {
  29536. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29537. return this.isEmpty();
  29538. },
  29539. isIntersectionBox: function isIntersectionBox(box) {
  29540. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29541. return this.intersectsBox(box);
  29542. },
  29543. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29544. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29545. return this.intersectsSphere(sphere);
  29546. },
  29547. size: function size(optionalTarget) {
  29548. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29549. return this.getSize(optionalTarget);
  29550. }
  29551. });
  29552. Object.assign(Sphere.prototype, {
  29553. empty: function empty() {
  29554. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29555. return this.isEmpty();
  29556. }
  29557. });
  29558. Frustum.prototype.setFromMatrix = function (m) {
  29559. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29560. return this.setFromProjectionMatrix(m);
  29561. };
  29562. Line3.prototype.center = function (optionalTarget) {
  29563. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29564. return this.getCenter(optionalTarget);
  29565. };
  29566. Object.assign(MathUtils, {
  29567. random16: function random16() {
  29568. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29569. return Math.random();
  29570. },
  29571. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29572. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29573. return MathUtils.floorPowerOfTwo(value);
  29574. },
  29575. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29576. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29577. return MathUtils.ceilPowerOfTwo(value);
  29578. }
  29579. });
  29580. Object.assign(Matrix3.prototype, {
  29581. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29582. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29583. return this.toArray(array, offset);
  29584. },
  29585. multiplyVector3: function multiplyVector3(vector) {
  29586. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29587. return vector.applyMatrix3(this);
  29588. },
  29589. multiplyVector3Array: function multiplyVector3Array()
  29590. /* a */
  29591. {
  29592. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29593. },
  29594. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29595. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29596. return attribute.applyMatrix3(this);
  29597. },
  29598. applyToVector3Array: function applyToVector3Array()
  29599. /* array, offset, length */
  29600. {
  29601. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29602. },
  29603. getInverse: function getInverse(matrix) {
  29604. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29605. return this.copy(matrix).invert();
  29606. }
  29607. });
  29608. Object.assign(Matrix4.prototype, {
  29609. extractPosition: function extractPosition(m) {
  29610. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29611. return this.copyPosition(m);
  29612. },
  29613. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29614. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29615. return this.toArray(array, offset);
  29616. },
  29617. getPosition: function getPosition() {
  29618. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29619. return new Vector3().setFromMatrixColumn(this, 3);
  29620. },
  29621. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29622. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29623. return this.makeRotationFromQuaternion(q);
  29624. },
  29625. multiplyToArray: function multiplyToArray() {
  29626. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29627. },
  29628. multiplyVector3: function multiplyVector3(vector) {
  29629. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29630. return vector.applyMatrix4(this);
  29631. },
  29632. multiplyVector4: function multiplyVector4(vector) {
  29633. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29634. return vector.applyMatrix4(this);
  29635. },
  29636. multiplyVector3Array: function multiplyVector3Array()
  29637. /* a */
  29638. {
  29639. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29640. },
  29641. rotateAxis: function rotateAxis(v) {
  29642. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29643. v.transformDirection(this);
  29644. },
  29645. crossVector: function crossVector(vector) {
  29646. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29647. return vector.applyMatrix4(this);
  29648. },
  29649. translate: function translate() {
  29650. console.error('THREE.Matrix4: .translate() has been removed.');
  29651. },
  29652. rotateX: function rotateX() {
  29653. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29654. },
  29655. rotateY: function rotateY() {
  29656. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29657. },
  29658. rotateZ: function rotateZ() {
  29659. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29660. },
  29661. rotateByAxis: function rotateByAxis() {
  29662. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29663. },
  29664. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29665. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29666. return attribute.applyMatrix4(this);
  29667. },
  29668. applyToVector3Array: function applyToVector3Array()
  29669. /* array, offset, length */
  29670. {
  29671. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29672. },
  29673. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29674. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29675. return this.makePerspective(left, right, top, bottom, near, far);
  29676. },
  29677. getInverse: function getInverse(matrix) {
  29678. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29679. return this.copy(matrix).invert();
  29680. }
  29681. });
  29682. Plane.prototype.isIntersectionLine = function (line) {
  29683. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29684. return this.intersectsLine(line);
  29685. };
  29686. Object.assign(Quaternion.prototype, {
  29687. multiplyVector3: function multiplyVector3(vector) {
  29688. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29689. return vector.applyQuaternion(this);
  29690. },
  29691. inverse: function inverse() {
  29692. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29693. return this.invert();
  29694. }
  29695. });
  29696. Object.assign(Ray.prototype, {
  29697. isIntersectionBox: function isIntersectionBox(box) {
  29698. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29699. return this.intersectsBox(box);
  29700. },
  29701. isIntersectionPlane: function isIntersectionPlane(plane) {
  29702. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29703. return this.intersectsPlane(plane);
  29704. },
  29705. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29706. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29707. return this.intersectsSphere(sphere);
  29708. }
  29709. });
  29710. Object.assign(Triangle.prototype, {
  29711. area: function area() {
  29712. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29713. return this.getArea();
  29714. },
  29715. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29716. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29717. return this.getBarycoord(point, target);
  29718. },
  29719. midpoint: function midpoint(target) {
  29720. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29721. return this.getMidpoint(target);
  29722. },
  29723. normal: function normal(target) {
  29724. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29725. return this.getNormal(target);
  29726. },
  29727. plane: function plane(target) {
  29728. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29729. return this.getPlane(target);
  29730. }
  29731. });
  29732. Object.assign(Triangle, {
  29733. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29734. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29735. return Triangle.getBarycoord(point, a, b, c, target);
  29736. },
  29737. normal: function normal(a, b, c, target) {
  29738. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29739. return Triangle.getNormal(a, b, c, target);
  29740. }
  29741. });
  29742. Object.assign(Shape.prototype, {
  29743. extractAllPoints: function extractAllPoints(divisions) {
  29744. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29745. return this.extractPoints(divisions);
  29746. },
  29747. extrude: function extrude(options) {
  29748. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29749. return new ExtrudeGeometry(this, options);
  29750. },
  29751. makeGeometry: function makeGeometry(options) {
  29752. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29753. return new ShapeGeometry(this, options);
  29754. }
  29755. });
  29756. Object.assign(Vector2.prototype, {
  29757. fromAttribute: function fromAttribute(attribute, index, offset) {
  29758. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29759. return this.fromBufferAttribute(attribute, index, offset);
  29760. },
  29761. distanceToManhattan: function distanceToManhattan(v) {
  29762. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29763. return this.manhattanDistanceTo(v);
  29764. },
  29765. lengthManhattan: function lengthManhattan() {
  29766. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29767. return this.manhattanLength();
  29768. }
  29769. });
  29770. Object.assign(Vector3.prototype, {
  29771. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29772. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29773. },
  29774. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29775. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29776. },
  29777. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29778. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29779. return this.setFromMatrixPosition(m);
  29780. },
  29781. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29782. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29783. return this.setFromMatrixScale(m);
  29784. },
  29785. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29786. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29787. return this.setFromMatrixColumn(matrix, index);
  29788. },
  29789. applyProjection: function applyProjection(m) {
  29790. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29791. return this.applyMatrix4(m);
  29792. },
  29793. fromAttribute: function fromAttribute(attribute, index, offset) {
  29794. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29795. return this.fromBufferAttribute(attribute, index, offset);
  29796. },
  29797. distanceToManhattan: function distanceToManhattan(v) {
  29798. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29799. return this.manhattanDistanceTo(v);
  29800. },
  29801. lengthManhattan: function lengthManhattan() {
  29802. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29803. return this.manhattanLength();
  29804. }
  29805. });
  29806. Object.assign(Vector4.prototype, {
  29807. fromAttribute: function fromAttribute(attribute, index, offset) {
  29808. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29809. return this.fromBufferAttribute(attribute, index, offset);
  29810. },
  29811. lengthManhattan: function lengthManhattan() {
  29812. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29813. return this.manhattanLength();
  29814. }
  29815. }); //
  29816. Object.assign(Object3D.prototype, {
  29817. getChildByName: function getChildByName(name) {
  29818. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29819. return this.getObjectByName(name);
  29820. },
  29821. renderDepth: function renderDepth() {
  29822. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29823. },
  29824. translate: function translate(distance, axis) {
  29825. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29826. return this.translateOnAxis(axis, distance);
  29827. },
  29828. getWorldRotation: function getWorldRotation() {
  29829. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29830. },
  29831. applyMatrix: function applyMatrix(matrix) {
  29832. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29833. return this.applyMatrix4(matrix);
  29834. }
  29835. });
  29836. Object.defineProperties(Object3D.prototype, {
  29837. eulerOrder: {
  29838. get: function get() {
  29839. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29840. return this.rotation.order;
  29841. },
  29842. set: function set(value) {
  29843. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29844. this.rotation.order = value;
  29845. }
  29846. },
  29847. useQuaternion: {
  29848. get: function get() {
  29849. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29850. },
  29851. set: function set() {
  29852. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29853. }
  29854. }
  29855. });
  29856. Object.assign(Mesh.prototype, {
  29857. setDrawMode: function setDrawMode() {
  29858. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29859. }
  29860. });
  29861. Object.defineProperties(Mesh.prototype, {
  29862. drawMode: {
  29863. get: function get() {
  29864. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29865. return TrianglesDrawMode;
  29866. },
  29867. set: function set() {
  29868. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29869. }
  29870. }
  29871. });
  29872. Object.defineProperties(LOD.prototype, {
  29873. objects: {
  29874. get: function get() {
  29875. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29876. return this.levels;
  29877. }
  29878. }
  29879. });
  29880. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29881. get: function get() {
  29882. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29883. },
  29884. set: function set() {
  29885. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29886. }
  29887. });
  29888. SkinnedMesh.prototype.initBones = function () {
  29889. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29890. };
  29891. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29892. get: function get() {
  29893. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29894. return this.arcLengthDivisions;
  29895. },
  29896. set: function set(value) {
  29897. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29898. this.arcLengthDivisions = value;
  29899. }
  29900. }); //
  29901. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29902. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29903. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29904. this.setFocalLength(focalLength);
  29905. }; //
  29906. Object.defineProperties(Light.prototype, {
  29907. onlyShadow: {
  29908. set: function set() {
  29909. console.warn('THREE.Light: .onlyShadow has been removed.');
  29910. }
  29911. },
  29912. shadowCameraFov: {
  29913. set: function set(value) {
  29914. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29915. this.shadow.camera.fov = value;
  29916. }
  29917. },
  29918. shadowCameraLeft: {
  29919. set: function set(value) {
  29920. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29921. this.shadow.camera.left = value;
  29922. }
  29923. },
  29924. shadowCameraRight: {
  29925. set: function set(value) {
  29926. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29927. this.shadow.camera.right = value;
  29928. }
  29929. },
  29930. shadowCameraTop: {
  29931. set: function set(value) {
  29932. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29933. this.shadow.camera.top = value;
  29934. }
  29935. },
  29936. shadowCameraBottom: {
  29937. set: function set(value) {
  29938. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29939. this.shadow.camera.bottom = value;
  29940. }
  29941. },
  29942. shadowCameraNear: {
  29943. set: function set(value) {
  29944. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29945. this.shadow.camera.near = value;
  29946. }
  29947. },
  29948. shadowCameraFar: {
  29949. set: function set(value) {
  29950. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29951. this.shadow.camera.far = value;
  29952. }
  29953. },
  29954. shadowCameraVisible: {
  29955. set: function set() {
  29956. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29957. }
  29958. },
  29959. shadowBias: {
  29960. set: function set(value) {
  29961. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29962. this.shadow.bias = value;
  29963. }
  29964. },
  29965. shadowDarkness: {
  29966. set: function set() {
  29967. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29968. }
  29969. },
  29970. shadowMapWidth: {
  29971. set: function set(value) {
  29972. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29973. this.shadow.mapSize.width = value;
  29974. }
  29975. },
  29976. shadowMapHeight: {
  29977. set: function set(value) {
  29978. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29979. this.shadow.mapSize.height = value;
  29980. }
  29981. }
  29982. }); //
  29983. Object.defineProperties(BufferAttribute.prototype, {
  29984. length: {
  29985. get: function get() {
  29986. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29987. return this.array.length;
  29988. }
  29989. },
  29990. dynamic: {
  29991. get: function get() {
  29992. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29993. return this.usage === DynamicDrawUsage;
  29994. },
  29995. set: function set()
  29996. /* value */
  29997. {
  29998. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29999. this.setUsage(DynamicDrawUsage);
  30000. }
  30001. }
  30002. });
  30003. Object.assign(BufferAttribute.prototype, {
  30004. setDynamic: function setDynamic(value) {
  30005. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30006. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30007. return this;
  30008. },
  30009. copyIndicesArray: function copyIndicesArray()
  30010. /* indices */
  30011. {
  30012. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  30013. },
  30014. setArray: function setArray()
  30015. /* array */
  30016. {
  30017. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30018. }
  30019. });
  30020. Object.assign(BufferGeometry.prototype, {
  30021. addIndex: function addIndex(index) {
  30022. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  30023. this.setIndex(index);
  30024. },
  30025. addAttribute: function addAttribute(name, attribute) {
  30026. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  30027. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  30028. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  30029. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  30030. }
  30031. if (name === 'index') {
  30032. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  30033. this.setIndex(attribute);
  30034. return this;
  30035. }
  30036. return this.setAttribute(name, attribute);
  30037. },
  30038. addDrawCall: function addDrawCall(start, count, indexOffset) {
  30039. if (indexOffset !== undefined) {
  30040. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  30041. }
  30042. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  30043. this.addGroup(start, count);
  30044. },
  30045. clearDrawCalls: function clearDrawCalls() {
  30046. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  30047. this.clearGroups();
  30048. },
  30049. computeOffsets: function computeOffsets() {
  30050. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  30051. },
  30052. removeAttribute: function removeAttribute(name) {
  30053. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  30054. return this.deleteAttribute(name);
  30055. },
  30056. applyMatrix: function applyMatrix(matrix) {
  30057. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30058. return this.applyMatrix4(matrix);
  30059. }
  30060. });
  30061. Object.defineProperties(BufferGeometry.prototype, {
  30062. drawcalls: {
  30063. get: function get() {
  30064. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  30065. return this.groups;
  30066. }
  30067. },
  30068. offsets: {
  30069. get: function get() {
  30070. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  30071. return this.groups;
  30072. }
  30073. }
  30074. });
  30075. Object.defineProperties(InstancedBufferGeometry.prototype, {
  30076. maxInstancedCount: {
  30077. get: function get() {
  30078. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30079. return this.instanceCount;
  30080. },
  30081. set: function set(value) {
  30082. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30083. this.instanceCount = value;
  30084. }
  30085. }
  30086. });
  30087. Object.defineProperties(Raycaster.prototype, {
  30088. linePrecision: {
  30089. get: function get() {
  30090. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30091. return this.params.Line.threshold;
  30092. },
  30093. set: function set(value) {
  30094. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30095. this.params.Line.threshold = value;
  30096. }
  30097. }
  30098. });
  30099. Object.defineProperties(InterleavedBuffer.prototype, {
  30100. dynamic: {
  30101. get: function get() {
  30102. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30103. return this.usage === DynamicDrawUsage;
  30104. },
  30105. set: function set(value) {
  30106. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30107. this.setUsage(value);
  30108. }
  30109. }
  30110. });
  30111. Object.assign(InterleavedBuffer.prototype, {
  30112. setDynamic: function setDynamic(value) {
  30113. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30114. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30115. return this;
  30116. },
  30117. setArray: function setArray()
  30118. /* array */
  30119. {
  30120. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30121. }
  30122. }); //
  30123. Object.assign(ExtrudeGeometry.prototype, {
  30124. getArrays: function getArrays() {
  30125. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  30126. },
  30127. addShapeList: function addShapeList() {
  30128. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  30129. },
  30130. addShape: function addShape() {
  30131. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  30132. }
  30133. }); //
  30134. Object.assign(Scene.prototype, {
  30135. dispose: function dispose() {
  30136. console.error('THREE.Scene: .dispose() has been removed.');
  30137. }
  30138. }); //
  30139. Object.defineProperties(Uniform.prototype, {
  30140. dynamic: {
  30141. set: function set() {
  30142. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  30143. }
  30144. },
  30145. onUpdate: {
  30146. value: function value() {
  30147. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  30148. return this;
  30149. }
  30150. }
  30151. }); //
  30152. Object.defineProperties(Material.prototype, {
  30153. wrapAround: {
  30154. get: function get() {
  30155. console.warn('THREE.Material: .wrapAround has been removed.');
  30156. },
  30157. set: function set() {
  30158. console.warn('THREE.Material: .wrapAround has been removed.');
  30159. }
  30160. },
  30161. overdraw: {
  30162. get: function get() {
  30163. console.warn('THREE.Material: .overdraw has been removed.');
  30164. },
  30165. set: function set() {
  30166. console.warn('THREE.Material: .overdraw has been removed.');
  30167. }
  30168. },
  30169. wrapRGB: {
  30170. get: function get() {
  30171. console.warn('THREE.Material: .wrapRGB has been removed.');
  30172. return new Color();
  30173. }
  30174. },
  30175. shading: {
  30176. get: function get() {
  30177. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30178. },
  30179. set: function set(value) {
  30180. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30181. this.flatShading = value === FlatShading;
  30182. }
  30183. },
  30184. stencilMask: {
  30185. get: function get() {
  30186. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30187. return this.stencilFuncMask;
  30188. },
  30189. set: function set(value) {
  30190. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30191. this.stencilFuncMask = value;
  30192. }
  30193. }
  30194. });
  30195. Object.defineProperties(MeshPhongMaterial.prototype, {
  30196. metal: {
  30197. get: function get() {
  30198. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30199. return false;
  30200. },
  30201. set: function set() {
  30202. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30203. }
  30204. }
  30205. });
  30206. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30207. transparency: {
  30208. get: function get() {
  30209. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30210. return this.transmission;
  30211. },
  30212. set: function set(value) {
  30213. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30214. this.transmission = value;
  30215. }
  30216. }
  30217. });
  30218. Object.defineProperties(ShaderMaterial.prototype, {
  30219. derivatives: {
  30220. get: function get() {
  30221. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30222. return this.extensions.derivatives;
  30223. },
  30224. set: function set(value) {
  30225. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30226. this.extensions.derivatives = value;
  30227. }
  30228. }
  30229. }); //
  30230. Object.assign(WebGLRenderer.prototype, {
  30231. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  30232. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30233. this.setRenderTarget(renderTarget);
  30234. this.clear(color, depth, stencil);
  30235. },
  30236. animate: function animate(callback) {
  30237. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30238. this.setAnimationLoop(callback);
  30239. },
  30240. getCurrentRenderTarget: function getCurrentRenderTarget() {
  30241. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30242. return this.getRenderTarget();
  30243. },
  30244. getMaxAnisotropy: function getMaxAnisotropy() {
  30245. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30246. return this.capabilities.getMaxAnisotropy();
  30247. },
  30248. getPrecision: function getPrecision() {
  30249. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30250. return this.capabilities.precision;
  30251. },
  30252. resetGLState: function resetGLState() {
  30253. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30254. return this.state.reset();
  30255. },
  30256. supportsFloatTextures: function supportsFloatTextures() {
  30257. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30258. return this.extensions.get('OES_texture_float');
  30259. },
  30260. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30261. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30262. return this.extensions.get('OES_texture_half_float');
  30263. },
  30264. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30265. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30266. return this.extensions.get('OES_standard_derivatives');
  30267. },
  30268. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30269. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30270. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30271. },
  30272. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30273. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30274. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30275. },
  30276. supportsBlendMinMax: function supportsBlendMinMax() {
  30277. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30278. return this.extensions.get('EXT_blend_minmax');
  30279. },
  30280. supportsVertexTextures: function supportsVertexTextures() {
  30281. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30282. return this.capabilities.vertexTextures;
  30283. },
  30284. supportsInstancedArrays: function supportsInstancedArrays() {
  30285. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30286. return this.extensions.get('ANGLE_instanced_arrays');
  30287. },
  30288. enableScissorTest: function enableScissorTest(boolean) {
  30289. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30290. this.setScissorTest(boolean);
  30291. },
  30292. initMaterial: function initMaterial() {
  30293. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30294. },
  30295. addPrePlugin: function addPrePlugin() {
  30296. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30297. },
  30298. addPostPlugin: function addPostPlugin() {
  30299. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30300. },
  30301. updateShadowMap: function updateShadowMap() {
  30302. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30303. },
  30304. setFaceCulling: function setFaceCulling() {
  30305. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30306. },
  30307. allocTextureUnit: function allocTextureUnit() {
  30308. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30309. },
  30310. setTexture: function setTexture() {
  30311. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30312. },
  30313. setTexture2D: function setTexture2D() {
  30314. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30315. },
  30316. setTextureCube: function setTextureCube() {
  30317. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30318. },
  30319. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30320. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30321. return this.getActiveMipmapLevel();
  30322. }
  30323. });
  30324. Object.defineProperties(WebGLRenderer.prototype, {
  30325. shadowMapEnabled: {
  30326. get: function get() {
  30327. return this.shadowMap.enabled;
  30328. },
  30329. set: function set(value) {
  30330. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30331. this.shadowMap.enabled = value;
  30332. }
  30333. },
  30334. shadowMapType: {
  30335. get: function get() {
  30336. return this.shadowMap.type;
  30337. },
  30338. set: function set(value) {
  30339. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30340. this.shadowMap.type = value;
  30341. }
  30342. },
  30343. shadowMapCullFace: {
  30344. get: function get() {
  30345. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30346. return undefined;
  30347. },
  30348. set: function set()
  30349. /* value */
  30350. {
  30351. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30352. }
  30353. },
  30354. context: {
  30355. get: function get() {
  30356. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30357. return this.getContext();
  30358. }
  30359. },
  30360. vr: {
  30361. get: function get() {
  30362. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30363. return this.xr;
  30364. }
  30365. },
  30366. gammaInput: {
  30367. get: function get() {
  30368. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30369. return false;
  30370. },
  30371. set: function set() {
  30372. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30373. }
  30374. },
  30375. gammaOutput: {
  30376. get: function get() {
  30377. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30378. return false;
  30379. },
  30380. set: function set(value) {
  30381. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30382. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30383. }
  30384. },
  30385. toneMappingWhitePoint: {
  30386. get: function get() {
  30387. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30388. return 1.0;
  30389. },
  30390. set: function set() {
  30391. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30392. }
  30393. }
  30394. });
  30395. Object.defineProperties(WebGLShadowMap.prototype, {
  30396. cullFace: {
  30397. get: function get() {
  30398. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30399. return undefined;
  30400. },
  30401. set: function set()
  30402. /* cullFace */
  30403. {
  30404. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30405. }
  30406. },
  30407. renderReverseSided: {
  30408. get: function get() {
  30409. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30410. return undefined;
  30411. },
  30412. set: function set() {
  30413. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30414. }
  30415. },
  30416. renderSingleSided: {
  30417. get: function get() {
  30418. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30419. return undefined;
  30420. },
  30421. set: function set() {
  30422. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30423. }
  30424. }
  30425. });
  30426. function WebGLRenderTargetCube(width, height, options) {
  30427. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30428. return new WebGLCubeRenderTarget(width, options);
  30429. } //
  30430. Object.defineProperties(WebGLRenderTarget.prototype, {
  30431. wrapS: {
  30432. get: function get() {
  30433. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30434. return this.texture.wrapS;
  30435. },
  30436. set: function set(value) {
  30437. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30438. this.texture.wrapS = value;
  30439. }
  30440. },
  30441. wrapT: {
  30442. get: function get() {
  30443. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30444. return this.texture.wrapT;
  30445. },
  30446. set: function set(value) {
  30447. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30448. this.texture.wrapT = value;
  30449. }
  30450. },
  30451. magFilter: {
  30452. get: function get() {
  30453. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30454. return this.texture.magFilter;
  30455. },
  30456. set: function set(value) {
  30457. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30458. this.texture.magFilter = value;
  30459. }
  30460. },
  30461. minFilter: {
  30462. get: function get() {
  30463. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30464. return this.texture.minFilter;
  30465. },
  30466. set: function set(value) {
  30467. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30468. this.texture.minFilter = value;
  30469. }
  30470. },
  30471. anisotropy: {
  30472. get: function get() {
  30473. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30474. return this.texture.anisotropy;
  30475. },
  30476. set: function set(value) {
  30477. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30478. this.texture.anisotropy = value;
  30479. }
  30480. },
  30481. offset: {
  30482. get: function get() {
  30483. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30484. return this.texture.offset;
  30485. },
  30486. set: function set(value) {
  30487. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30488. this.texture.offset = value;
  30489. }
  30490. },
  30491. repeat: {
  30492. get: function get() {
  30493. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30494. return this.texture.repeat;
  30495. },
  30496. set: function set(value) {
  30497. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30498. this.texture.repeat = value;
  30499. }
  30500. },
  30501. format: {
  30502. get: function get() {
  30503. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30504. return this.texture.format;
  30505. },
  30506. set: function set(value) {
  30507. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30508. this.texture.format = value;
  30509. }
  30510. },
  30511. type: {
  30512. get: function get() {
  30513. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30514. return this.texture.type;
  30515. },
  30516. set: function set(value) {
  30517. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30518. this.texture.type = value;
  30519. }
  30520. },
  30521. generateMipmaps: {
  30522. get: function get() {
  30523. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30524. return this.texture.generateMipmaps;
  30525. },
  30526. set: function set(value) {
  30527. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30528. this.texture.generateMipmaps = value;
  30529. }
  30530. }
  30531. }); //
  30532. Object.defineProperties(Audio.prototype, {
  30533. load: {
  30534. value: function value(file) {
  30535. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30536. var scope = this;
  30537. var audioLoader = new AudioLoader();
  30538. audioLoader.load(file, function (buffer) {
  30539. scope.setBuffer(buffer);
  30540. });
  30541. return this;
  30542. }
  30543. },
  30544. startTime: {
  30545. set: function set() {
  30546. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30547. }
  30548. }
  30549. });
  30550. AudioAnalyser.prototype.getData = function () {
  30551. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30552. return this.getFrequencyData();
  30553. }; //
  30554. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30555. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30556. return this.update(renderer, scene);
  30557. };
  30558. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30559. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30560. return this.renderTarget.clear(renderer, color, depth, stencil);
  30561. };
  30562. ImageUtils.crossOrigin = undefined;
  30563. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30564. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30565. var loader = new TextureLoader();
  30566. loader.setCrossOrigin(this.crossOrigin);
  30567. var texture = loader.load(url, onLoad, undefined, onError);
  30568. if (mapping) texture.mapping = mapping;
  30569. return texture;
  30570. };
  30571. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30572. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30573. var loader = new CubeTextureLoader();
  30574. loader.setCrossOrigin(this.crossOrigin);
  30575. var texture = loader.load(urls, onLoad, undefined, onError);
  30576. if (mapping) texture.mapping = mapping;
  30577. return texture;
  30578. };
  30579. ImageUtils.loadCompressedTexture = function () {
  30580. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30581. };
  30582. ImageUtils.loadCompressedTextureCube = function () {
  30583. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30584. }; //
  30585. function CanvasRenderer() {
  30586. console.error('THREE.CanvasRenderer has been removed');
  30587. } //
  30588. function JSONLoader() {
  30589. console.error('THREE.JSONLoader has been removed.');
  30590. } //
  30591. var SceneUtils = {
  30592. createMultiMaterialObject: function createMultiMaterialObject()
  30593. /* geometry, materials */
  30594. {
  30595. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30596. },
  30597. detach: function detach()
  30598. /* child, parent, scene */
  30599. {
  30600. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30601. },
  30602. attach: function attach()
  30603. /* child, scene, parent */
  30604. {
  30605. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30606. }
  30607. }; //
  30608. function LensFlare() {
  30609. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30610. }
  30611. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30612. /* eslint-disable no-undef */
  30613. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30614. detail: {
  30615. revision: REVISION
  30616. }
  30617. }));
  30618. /* eslint-enable no-undef */
  30619. }
  30620. if (typeof window !== 'undefined') {
  30621. if (window.__THREE__) {
  30622. console.warn('WARNING: Multiple instances of Three.js being imported.');
  30623. } else {
  30624. window.__THREE__ = REVISION;
  30625. }
  30626. }
  30627. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30628. exports.AddEquation = AddEquation;
  30629. exports.AddOperation = AddOperation;
  30630. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30631. exports.AdditiveBlending = AdditiveBlending;
  30632. exports.AlphaFormat = AlphaFormat;
  30633. exports.AlwaysDepth = AlwaysDepth;
  30634. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30635. exports.AmbientLight = AmbientLight;
  30636. exports.AmbientLightProbe = AmbientLightProbe;
  30637. exports.AnimationClip = AnimationClip;
  30638. exports.AnimationLoader = AnimationLoader;
  30639. exports.AnimationMixer = AnimationMixer;
  30640. exports.AnimationObjectGroup = AnimationObjectGroup;
  30641. exports.AnimationUtils = AnimationUtils;
  30642. exports.ArcCurve = ArcCurve;
  30643. exports.ArrayCamera = ArrayCamera;
  30644. exports.ArrowHelper = ArrowHelper;
  30645. exports.Audio = Audio;
  30646. exports.AudioAnalyser = AudioAnalyser;
  30647. exports.AudioContext = AudioContext;
  30648. exports.AudioListener = AudioListener;
  30649. exports.AudioLoader = AudioLoader;
  30650. exports.AxesHelper = AxesHelper;
  30651. exports.AxisHelper = AxisHelper;
  30652. exports.BackSide = BackSide;
  30653. exports.BasicDepthPacking = BasicDepthPacking;
  30654. exports.BasicShadowMap = BasicShadowMap;
  30655. exports.BinaryTextureLoader = BinaryTextureLoader;
  30656. exports.Bone = Bone;
  30657. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30658. exports.BoundingBoxHelper = BoundingBoxHelper;
  30659. exports.Box2 = Box2;
  30660. exports.Box3 = Box3;
  30661. exports.Box3Helper = Box3Helper;
  30662. exports.BoxBufferGeometry = BoxGeometry;
  30663. exports.BoxGeometry = BoxGeometry;
  30664. exports.BoxHelper = BoxHelper;
  30665. exports.BufferAttribute = BufferAttribute;
  30666. exports.BufferGeometry = BufferGeometry;
  30667. exports.BufferGeometryLoader = BufferGeometryLoader;
  30668. exports.ByteType = ByteType;
  30669. exports.Cache = Cache;
  30670. exports.Camera = Camera;
  30671. exports.CameraHelper = CameraHelper;
  30672. exports.CanvasRenderer = CanvasRenderer;
  30673. exports.CanvasTexture = CanvasTexture;
  30674. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30675. exports.CineonToneMapping = CineonToneMapping;
  30676. exports.CircleBufferGeometry = CircleGeometry;
  30677. exports.CircleGeometry = CircleGeometry;
  30678. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30679. exports.Clock = Clock;
  30680. exports.Color = Color;
  30681. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30682. exports.CompressedTexture = CompressedTexture;
  30683. exports.CompressedTextureLoader = CompressedTextureLoader;
  30684. exports.ConeBufferGeometry = ConeGeometry;
  30685. exports.ConeGeometry = ConeGeometry;
  30686. exports.CubeCamera = CubeCamera;
  30687. exports.CubeReflectionMapping = CubeReflectionMapping;
  30688. exports.CubeRefractionMapping = CubeRefractionMapping;
  30689. exports.CubeTexture = CubeTexture;
  30690. exports.CubeTextureLoader = CubeTextureLoader;
  30691. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30692. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30693. exports.CubicBezierCurve = CubicBezierCurve;
  30694. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30695. exports.CubicInterpolant = CubicInterpolant;
  30696. exports.CullFaceBack = CullFaceBack;
  30697. exports.CullFaceFront = CullFaceFront;
  30698. exports.CullFaceFrontBack = CullFaceFrontBack;
  30699. exports.CullFaceNone = CullFaceNone;
  30700. exports.Curve = Curve;
  30701. exports.CurvePath = CurvePath;
  30702. exports.CustomBlending = CustomBlending;
  30703. exports.CustomToneMapping = CustomToneMapping;
  30704. exports.CylinderBufferGeometry = CylinderGeometry;
  30705. exports.CylinderGeometry = CylinderGeometry;
  30706. exports.Cylindrical = Cylindrical;
  30707. exports.DataTexture = DataTexture;
  30708. exports.DataTexture2DArray = DataTexture2DArray;
  30709. exports.DataTexture3D = DataTexture3D;
  30710. exports.DataTextureLoader = DataTextureLoader;
  30711. exports.DataUtils = DataUtils;
  30712. exports.DecrementStencilOp = DecrementStencilOp;
  30713. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30714. exports.DefaultLoadingManager = DefaultLoadingManager;
  30715. exports.DepthFormat = DepthFormat;
  30716. exports.DepthStencilFormat = DepthStencilFormat;
  30717. exports.DepthTexture = DepthTexture;
  30718. exports.DirectionalLight = DirectionalLight;
  30719. exports.DirectionalLightHelper = DirectionalLightHelper;
  30720. exports.DiscreteInterpolant = DiscreteInterpolant;
  30721. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30722. exports.DodecahedronGeometry = DodecahedronGeometry;
  30723. exports.DoubleSide = DoubleSide;
  30724. exports.DstAlphaFactor = DstAlphaFactor;
  30725. exports.DstColorFactor = DstColorFactor;
  30726. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30727. exports.DynamicCopyUsage = DynamicCopyUsage;
  30728. exports.DynamicDrawUsage = DynamicDrawUsage;
  30729. exports.DynamicReadUsage = DynamicReadUsage;
  30730. exports.EdgesGeometry = EdgesGeometry;
  30731. exports.EdgesHelper = EdgesHelper;
  30732. exports.EllipseCurve = EllipseCurve;
  30733. exports.EqualDepth = EqualDepth;
  30734. exports.EqualStencilFunc = EqualStencilFunc;
  30735. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30736. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30737. exports.Euler = Euler;
  30738. exports.EventDispatcher = EventDispatcher;
  30739. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30740. exports.ExtrudeGeometry = ExtrudeGeometry;
  30741. exports.FaceColors = FaceColors;
  30742. exports.FileLoader = FileLoader;
  30743. exports.FlatShading = FlatShading;
  30744. exports.Float16BufferAttribute = Float16BufferAttribute;
  30745. exports.Float32Attribute = Float32Attribute;
  30746. exports.Float32BufferAttribute = Float32BufferAttribute;
  30747. exports.Float64Attribute = Float64Attribute;
  30748. exports.Float64BufferAttribute = Float64BufferAttribute;
  30749. exports.FloatType = FloatType;
  30750. exports.Fog = Fog;
  30751. exports.FogExp2 = FogExp2;
  30752. exports.Font = Font;
  30753. exports.FontLoader = FontLoader;
  30754. exports.FrontSide = FrontSide;
  30755. exports.Frustum = Frustum;
  30756. exports.GLBufferAttribute = GLBufferAttribute;
  30757. exports.GLSL1 = GLSL1;
  30758. exports.GLSL3 = GLSL3;
  30759. exports.GammaEncoding = GammaEncoding;
  30760. exports.GreaterDepth = GreaterDepth;
  30761. exports.GreaterEqualDepth = GreaterEqualDepth;
  30762. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30763. exports.GreaterStencilFunc = GreaterStencilFunc;
  30764. exports.GridHelper = GridHelper;
  30765. exports.Group = Group;
  30766. exports.HalfFloatType = HalfFloatType;
  30767. exports.HemisphereLight = HemisphereLight;
  30768. exports.HemisphereLightHelper = HemisphereLightHelper;
  30769. exports.HemisphereLightProbe = HemisphereLightProbe;
  30770. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30771. exports.IcosahedronGeometry = IcosahedronGeometry;
  30772. exports.ImageBitmapLoader = ImageBitmapLoader;
  30773. exports.ImageLoader = ImageLoader;
  30774. exports.ImageUtils = ImageUtils;
  30775. exports.ImmediateRenderObject = ImmediateRenderObject;
  30776. exports.IncrementStencilOp = IncrementStencilOp;
  30777. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30778. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30779. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30780. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30781. exports.InstancedMesh = InstancedMesh;
  30782. exports.Int16Attribute = Int16Attribute;
  30783. exports.Int16BufferAttribute = Int16BufferAttribute;
  30784. exports.Int32Attribute = Int32Attribute;
  30785. exports.Int32BufferAttribute = Int32BufferAttribute;
  30786. exports.Int8Attribute = Int8Attribute;
  30787. exports.Int8BufferAttribute = Int8BufferAttribute;
  30788. exports.IntType = IntType;
  30789. exports.InterleavedBuffer = InterleavedBuffer;
  30790. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30791. exports.Interpolant = Interpolant;
  30792. exports.InterpolateDiscrete = InterpolateDiscrete;
  30793. exports.InterpolateLinear = InterpolateLinear;
  30794. exports.InterpolateSmooth = InterpolateSmooth;
  30795. exports.InvertStencilOp = InvertStencilOp;
  30796. exports.JSONLoader = JSONLoader;
  30797. exports.KeepStencilOp = KeepStencilOp;
  30798. exports.KeyframeTrack = KeyframeTrack;
  30799. exports.LOD = LOD;
  30800. exports.LatheBufferGeometry = LatheGeometry;
  30801. exports.LatheGeometry = LatheGeometry;
  30802. exports.Layers = Layers;
  30803. exports.LensFlare = LensFlare;
  30804. exports.LessDepth = LessDepth;
  30805. exports.LessEqualDepth = LessEqualDepth;
  30806. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30807. exports.LessStencilFunc = LessStencilFunc;
  30808. exports.Light = Light;
  30809. exports.LightProbe = LightProbe;
  30810. exports.Line = Line;
  30811. exports.Line3 = Line3;
  30812. exports.LineBasicMaterial = LineBasicMaterial;
  30813. exports.LineCurve = LineCurve;
  30814. exports.LineCurve3 = LineCurve3;
  30815. exports.LineDashedMaterial = LineDashedMaterial;
  30816. exports.LineLoop = LineLoop;
  30817. exports.LinePieces = LinePieces;
  30818. exports.LineSegments = LineSegments;
  30819. exports.LineStrip = LineStrip;
  30820. exports.LinearEncoding = LinearEncoding;
  30821. exports.LinearFilter = LinearFilter;
  30822. exports.LinearInterpolant = LinearInterpolant;
  30823. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30824. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30825. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30826. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30827. exports.LinearToneMapping = LinearToneMapping;
  30828. exports.Loader = Loader;
  30829. exports.LoaderUtils = LoaderUtils;
  30830. exports.LoadingManager = LoadingManager;
  30831. exports.LogLuvEncoding = LogLuvEncoding;
  30832. exports.LoopOnce = LoopOnce;
  30833. exports.LoopPingPong = LoopPingPong;
  30834. exports.LoopRepeat = LoopRepeat;
  30835. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30836. exports.LuminanceFormat = LuminanceFormat;
  30837. exports.MOUSE = MOUSE;
  30838. exports.Material = Material;
  30839. exports.MaterialLoader = MaterialLoader;
  30840. exports.Math = MathUtils;
  30841. exports.MathUtils = MathUtils;
  30842. exports.Matrix3 = Matrix3;
  30843. exports.Matrix4 = Matrix4;
  30844. exports.MaxEquation = MaxEquation;
  30845. exports.Mesh = Mesh;
  30846. exports.MeshBasicMaterial = MeshBasicMaterial;
  30847. exports.MeshDepthMaterial = MeshDepthMaterial;
  30848. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30849. exports.MeshFaceMaterial = MeshFaceMaterial;
  30850. exports.MeshLambertMaterial = MeshLambertMaterial;
  30851. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30852. exports.MeshNormalMaterial = MeshNormalMaterial;
  30853. exports.MeshPhongMaterial = MeshPhongMaterial;
  30854. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30855. exports.MeshStandardMaterial = MeshStandardMaterial;
  30856. exports.MeshToonMaterial = MeshToonMaterial;
  30857. exports.MinEquation = MinEquation;
  30858. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30859. exports.MixOperation = MixOperation;
  30860. exports.MultiMaterial = MultiMaterial;
  30861. exports.MultiplyBlending = MultiplyBlending;
  30862. exports.MultiplyOperation = MultiplyOperation;
  30863. exports.NearestFilter = NearestFilter;
  30864. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30865. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30866. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30867. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30868. exports.NeverDepth = NeverDepth;
  30869. exports.NeverStencilFunc = NeverStencilFunc;
  30870. exports.NoBlending = NoBlending;
  30871. exports.NoColors = NoColors;
  30872. exports.NoToneMapping = NoToneMapping;
  30873. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30874. exports.NormalBlending = NormalBlending;
  30875. exports.NotEqualDepth = NotEqualDepth;
  30876. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30877. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30878. exports.Object3D = Object3D;
  30879. exports.ObjectLoader = ObjectLoader;
  30880. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30881. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30882. exports.OctahedronGeometry = OctahedronGeometry;
  30883. exports.OneFactor = OneFactor;
  30884. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30885. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30886. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30887. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30888. exports.OrthographicCamera = OrthographicCamera;
  30889. exports.PCFShadowMap = PCFShadowMap;
  30890. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30891. exports.PMREMGenerator = PMREMGenerator;
  30892. exports.ParametricBufferGeometry = ParametricGeometry;
  30893. exports.ParametricGeometry = ParametricGeometry;
  30894. exports.Particle = Particle;
  30895. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30896. exports.ParticleSystem = ParticleSystem;
  30897. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30898. exports.Path = Path;
  30899. exports.PerspectiveCamera = PerspectiveCamera;
  30900. exports.Plane = Plane;
  30901. exports.PlaneBufferGeometry = PlaneGeometry;
  30902. exports.PlaneGeometry = PlaneGeometry;
  30903. exports.PlaneHelper = PlaneHelper;
  30904. exports.PointCloud = PointCloud;
  30905. exports.PointCloudMaterial = PointCloudMaterial;
  30906. exports.PointLight = PointLight;
  30907. exports.PointLightHelper = PointLightHelper;
  30908. exports.Points = Points;
  30909. exports.PointsMaterial = PointsMaterial;
  30910. exports.PolarGridHelper = PolarGridHelper;
  30911. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30912. exports.PolyhedronGeometry = PolyhedronGeometry;
  30913. exports.PositionalAudio = PositionalAudio;
  30914. exports.PropertyBinding = PropertyBinding;
  30915. exports.PropertyMixer = PropertyMixer;
  30916. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30917. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30918. exports.Quaternion = Quaternion;
  30919. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30920. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30921. exports.REVISION = REVISION;
  30922. exports.RGBADepthPacking = RGBADepthPacking;
  30923. exports.RGBAFormat = RGBAFormat;
  30924. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30925. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30926. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30927. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30928. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30929. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30930. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30931. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30932. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30933. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30934. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30935. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30936. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30937. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30938. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30939. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30940. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30941. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30942. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30943. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30944. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30945. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30946. exports.RGBDEncoding = RGBDEncoding;
  30947. exports.RGBEEncoding = RGBEEncoding;
  30948. exports.RGBEFormat = RGBEFormat;
  30949. exports.RGBFormat = RGBFormat;
  30950. exports.RGBIntegerFormat = RGBIntegerFormat;
  30951. exports.RGBM16Encoding = RGBM16Encoding;
  30952. exports.RGBM7Encoding = RGBM7Encoding;
  30953. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30954. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30955. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30956. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30957. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30958. exports.RGFormat = RGFormat;
  30959. exports.RGIntegerFormat = RGIntegerFormat;
  30960. exports.RawShaderMaterial = RawShaderMaterial;
  30961. exports.Ray = Ray;
  30962. exports.Raycaster = Raycaster;
  30963. exports.RectAreaLight = RectAreaLight;
  30964. exports.RedFormat = RedFormat;
  30965. exports.RedIntegerFormat = RedIntegerFormat;
  30966. exports.ReinhardToneMapping = ReinhardToneMapping;
  30967. exports.RepeatWrapping = RepeatWrapping;
  30968. exports.ReplaceStencilOp = ReplaceStencilOp;
  30969. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30970. exports.RingBufferGeometry = RingGeometry;
  30971. exports.RingGeometry = RingGeometry;
  30972. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30973. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30974. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30975. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30976. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30977. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30978. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30979. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30980. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30981. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30982. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30983. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30984. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30985. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30986. exports.Scene = Scene;
  30987. exports.SceneUtils = SceneUtils;
  30988. exports.ShaderChunk = ShaderChunk;
  30989. exports.ShaderLib = ShaderLib;
  30990. exports.ShaderMaterial = ShaderMaterial;
  30991. exports.ShadowMaterial = ShadowMaterial;
  30992. exports.Shape = Shape;
  30993. exports.ShapeBufferGeometry = ShapeGeometry;
  30994. exports.ShapeGeometry = ShapeGeometry;
  30995. exports.ShapePath = ShapePath;
  30996. exports.ShapeUtils = ShapeUtils;
  30997. exports.ShortType = ShortType;
  30998. exports.Skeleton = Skeleton;
  30999. exports.SkeletonHelper = SkeletonHelper;
  31000. exports.SkinnedMesh = SkinnedMesh;
  31001. exports.SmoothShading = SmoothShading;
  31002. exports.Sphere = Sphere;
  31003. exports.SphereBufferGeometry = SphereGeometry;
  31004. exports.SphereGeometry = SphereGeometry;
  31005. exports.Spherical = Spherical;
  31006. exports.SphericalHarmonics3 = SphericalHarmonics3;
  31007. exports.SplineCurve = SplineCurve;
  31008. exports.SpotLight = SpotLight;
  31009. exports.SpotLightHelper = SpotLightHelper;
  31010. exports.Sprite = Sprite;
  31011. exports.SpriteMaterial = SpriteMaterial;
  31012. exports.SrcAlphaFactor = SrcAlphaFactor;
  31013. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  31014. exports.SrcColorFactor = SrcColorFactor;
  31015. exports.StaticCopyUsage = StaticCopyUsage;
  31016. exports.StaticDrawUsage = StaticDrawUsage;
  31017. exports.StaticReadUsage = StaticReadUsage;
  31018. exports.StereoCamera = StereoCamera;
  31019. exports.StreamCopyUsage = StreamCopyUsage;
  31020. exports.StreamDrawUsage = StreamDrawUsage;
  31021. exports.StreamReadUsage = StreamReadUsage;
  31022. exports.StringKeyframeTrack = StringKeyframeTrack;
  31023. exports.SubtractEquation = SubtractEquation;
  31024. exports.SubtractiveBlending = SubtractiveBlending;
  31025. exports.TOUCH = TOUCH;
  31026. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  31027. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  31028. exports.TetrahedronGeometry = TetrahedronGeometry;
  31029. exports.TextBufferGeometry = TextGeometry;
  31030. exports.TextGeometry = TextGeometry;
  31031. exports.Texture = Texture;
  31032. exports.TextureLoader = TextureLoader;
  31033. exports.TorusBufferGeometry = TorusGeometry;
  31034. exports.TorusGeometry = TorusGeometry;
  31035. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  31036. exports.TorusKnotGeometry = TorusKnotGeometry;
  31037. exports.Triangle = Triangle;
  31038. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  31039. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  31040. exports.TrianglesDrawMode = TrianglesDrawMode;
  31041. exports.TubeBufferGeometry = TubeGeometry;
  31042. exports.TubeGeometry = TubeGeometry;
  31043. exports.UVMapping = UVMapping;
  31044. exports.Uint16Attribute = Uint16Attribute;
  31045. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  31046. exports.Uint32Attribute = Uint32Attribute;
  31047. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  31048. exports.Uint8Attribute = Uint8Attribute;
  31049. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  31050. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  31051. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  31052. exports.Uniform = Uniform;
  31053. exports.UniformsLib = UniformsLib;
  31054. exports.UniformsUtils = UniformsUtils;
  31055. exports.UnsignedByteType = UnsignedByteType;
  31056. exports.UnsignedInt248Type = UnsignedInt248Type;
  31057. exports.UnsignedIntType = UnsignedIntType;
  31058. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  31059. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  31060. exports.UnsignedShort565Type = UnsignedShort565Type;
  31061. exports.UnsignedShortType = UnsignedShortType;
  31062. exports.VSMShadowMap = VSMShadowMap;
  31063. exports.Vector2 = Vector2;
  31064. exports.Vector3 = Vector3;
  31065. exports.Vector4 = Vector4;
  31066. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  31067. exports.Vertex = Vertex;
  31068. exports.VertexColors = VertexColors;
  31069. exports.VideoTexture = VideoTexture;
  31070. exports.WebGL1Renderer = WebGL1Renderer;
  31071. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  31072. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  31073. exports.WebGLRenderTarget = WebGLRenderTarget;
  31074. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  31075. exports.WebGLRenderer = WebGLRenderer;
  31076. exports.WebGLUtils = WebGLUtils;
  31077. exports.WireframeGeometry = WireframeGeometry;
  31078. exports.WireframeHelper = WireframeHelper;
  31079. exports.WrapAroundEnding = WrapAroundEnding;
  31080. exports.XHRLoader = XHRLoader;
  31081. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  31082. exports.ZeroFactor = ZeroFactor;
  31083. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  31084. exports.ZeroStencilOp = ZeroStencilOp;
  31085. exports.sRGBEncoding = sRGBEncoding;
  31086. Object.defineProperty(exports, '__esModule', { value: true });
  31087. })));
粤ICP备19079148号