three.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565
  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. var REVISION = '123dev';
  55. var MOUSE = {
  56. LEFT: 0,
  57. MIDDLE: 1,
  58. RIGHT: 2,
  59. ROTATE: 0,
  60. DOLLY: 1,
  61. PAN: 2
  62. };
  63. var TOUCH = {
  64. ROTATE: 0,
  65. PAN: 1,
  66. DOLLY_PAN: 2,
  67. DOLLY_ROTATE: 3
  68. };
  69. var CullFaceNone = 0;
  70. var CullFaceBack = 1;
  71. var CullFaceFront = 2;
  72. var CullFaceFrontBack = 3;
  73. var BasicShadowMap = 0;
  74. var PCFShadowMap = 1;
  75. var PCFSoftShadowMap = 2;
  76. var VSMShadowMap = 3;
  77. var FrontSide = 0;
  78. var BackSide = 1;
  79. var DoubleSide = 2;
  80. var FlatShading = 1;
  81. var SmoothShading = 2;
  82. var NoBlending = 0;
  83. var NormalBlending = 1;
  84. var AdditiveBlending = 2;
  85. var SubtractiveBlending = 3;
  86. var MultiplyBlending = 4;
  87. var CustomBlending = 5;
  88. var AddEquation = 100;
  89. var SubtractEquation = 101;
  90. var ReverseSubtractEquation = 102;
  91. var MinEquation = 103;
  92. var MaxEquation = 104;
  93. var ZeroFactor = 200;
  94. var OneFactor = 201;
  95. var SrcColorFactor = 202;
  96. var OneMinusSrcColorFactor = 203;
  97. var SrcAlphaFactor = 204;
  98. var OneMinusSrcAlphaFactor = 205;
  99. var DstAlphaFactor = 206;
  100. var OneMinusDstAlphaFactor = 207;
  101. var DstColorFactor = 208;
  102. var OneMinusDstColorFactor = 209;
  103. var SrcAlphaSaturateFactor = 210;
  104. var NeverDepth = 0;
  105. var AlwaysDepth = 1;
  106. var LessDepth = 2;
  107. var LessEqualDepth = 3;
  108. var EqualDepth = 4;
  109. var GreaterEqualDepth = 5;
  110. var GreaterDepth = 6;
  111. var NotEqualDepth = 7;
  112. var MultiplyOperation = 0;
  113. var MixOperation = 1;
  114. var AddOperation = 2;
  115. var NoToneMapping = 0;
  116. var LinearToneMapping = 1;
  117. var ReinhardToneMapping = 2;
  118. var CineonToneMapping = 3;
  119. var ACESFilmicToneMapping = 4;
  120. var CustomToneMapping = 5;
  121. var UVMapping = 300;
  122. var CubeReflectionMapping = 301;
  123. var CubeRefractionMapping = 302;
  124. var EquirectangularReflectionMapping = 303;
  125. var EquirectangularRefractionMapping = 304;
  126. var CubeUVReflectionMapping = 306;
  127. var CubeUVRefractionMapping = 307;
  128. var RepeatWrapping = 1000;
  129. var ClampToEdgeWrapping = 1001;
  130. var MirroredRepeatWrapping = 1002;
  131. var NearestFilter = 1003;
  132. var NearestMipmapNearestFilter = 1004;
  133. var NearestMipMapNearestFilter = 1004;
  134. var NearestMipmapLinearFilter = 1005;
  135. var NearestMipMapLinearFilter = 1005;
  136. var LinearFilter = 1006;
  137. var LinearMipmapNearestFilter = 1007;
  138. var LinearMipMapNearestFilter = 1007;
  139. var LinearMipmapLinearFilter = 1008;
  140. var LinearMipMapLinearFilter = 1008;
  141. var UnsignedByteType = 1009;
  142. var ByteType = 1010;
  143. var ShortType = 1011;
  144. var UnsignedShortType = 1012;
  145. var IntType = 1013;
  146. var UnsignedIntType = 1014;
  147. var FloatType = 1015;
  148. var HalfFloatType = 1016;
  149. var UnsignedShort4444Type = 1017;
  150. var UnsignedShort5551Type = 1018;
  151. var UnsignedShort565Type = 1019;
  152. var UnsignedInt248Type = 1020;
  153. var AlphaFormat = 1021;
  154. var RGBFormat = 1022;
  155. var RGBAFormat = 1023;
  156. var LuminanceFormat = 1024;
  157. var LuminanceAlphaFormat = 1025;
  158. var RGBEFormat = RGBAFormat;
  159. var DepthFormat = 1026;
  160. var DepthStencilFormat = 1027;
  161. var RedFormat = 1028;
  162. var RedIntegerFormat = 1029;
  163. var RGFormat = 1030;
  164. var RGIntegerFormat = 1031;
  165. var RGBIntegerFormat = 1032;
  166. var RGBAIntegerFormat = 1033;
  167. var RGB_S3TC_DXT1_Format = 33776;
  168. var RGBA_S3TC_DXT1_Format = 33777;
  169. var RGBA_S3TC_DXT3_Format = 33778;
  170. var RGBA_S3TC_DXT5_Format = 33779;
  171. var RGB_PVRTC_4BPPV1_Format = 35840;
  172. var RGB_PVRTC_2BPPV1_Format = 35841;
  173. var RGBA_PVRTC_4BPPV1_Format = 35842;
  174. var RGBA_PVRTC_2BPPV1_Format = 35843;
  175. var RGB_ETC1_Format = 36196;
  176. var RGB_ETC2_Format = 37492;
  177. var RGBA_ETC2_EAC_Format = 37496;
  178. var RGBA_ASTC_4x4_Format = 37808;
  179. var RGBA_ASTC_5x4_Format = 37809;
  180. var RGBA_ASTC_5x5_Format = 37810;
  181. var RGBA_ASTC_6x5_Format = 37811;
  182. var RGBA_ASTC_6x6_Format = 37812;
  183. var RGBA_ASTC_8x5_Format = 37813;
  184. var RGBA_ASTC_8x6_Format = 37814;
  185. var RGBA_ASTC_8x8_Format = 37815;
  186. var RGBA_ASTC_10x5_Format = 37816;
  187. var RGBA_ASTC_10x6_Format = 37817;
  188. var RGBA_ASTC_10x8_Format = 37818;
  189. var RGBA_ASTC_10x10_Format = 37819;
  190. var RGBA_ASTC_12x10_Format = 37820;
  191. var RGBA_ASTC_12x12_Format = 37821;
  192. var RGBA_BPTC_Format = 36492;
  193. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  194. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  195. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  196. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  197. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  198. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  199. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  200. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  201. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  202. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  203. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  204. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  205. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  206. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  207. var LoopOnce = 2200;
  208. var LoopRepeat = 2201;
  209. var LoopPingPong = 2202;
  210. var InterpolateDiscrete = 2300;
  211. var InterpolateLinear = 2301;
  212. var InterpolateSmooth = 2302;
  213. var ZeroCurvatureEnding = 2400;
  214. var ZeroSlopeEnding = 2401;
  215. var WrapAroundEnding = 2402;
  216. var NormalAnimationBlendMode = 2500;
  217. var AdditiveAnimationBlendMode = 2501;
  218. var TrianglesDrawMode = 0;
  219. var TriangleStripDrawMode = 1;
  220. var TriangleFanDrawMode = 2;
  221. var LinearEncoding = 3000;
  222. var sRGBEncoding = 3001;
  223. var GammaEncoding = 3007;
  224. var RGBEEncoding = 3002;
  225. var LogLuvEncoding = 3003;
  226. var RGBM7Encoding = 3004;
  227. var RGBM16Encoding = 3005;
  228. var RGBDEncoding = 3006;
  229. var BasicDepthPacking = 3200;
  230. var RGBADepthPacking = 3201;
  231. var TangentSpaceNormalMap = 0;
  232. var ObjectSpaceNormalMap = 1;
  233. var ZeroStencilOp = 0;
  234. var KeepStencilOp = 7680;
  235. var ReplaceStencilOp = 7681;
  236. var IncrementStencilOp = 7682;
  237. var DecrementStencilOp = 7683;
  238. var IncrementWrapStencilOp = 34055;
  239. var DecrementWrapStencilOp = 34056;
  240. var InvertStencilOp = 5386;
  241. var NeverStencilFunc = 512;
  242. var LessStencilFunc = 513;
  243. var EqualStencilFunc = 514;
  244. var LessEqualStencilFunc = 515;
  245. var GreaterStencilFunc = 516;
  246. var NotEqualStencilFunc = 517;
  247. var GreaterEqualStencilFunc = 518;
  248. var AlwaysStencilFunc = 519;
  249. var StaticDrawUsage = 35044;
  250. var DynamicDrawUsage = 35048;
  251. var StreamDrawUsage = 35040;
  252. var StaticReadUsage = 35045;
  253. var DynamicReadUsage = 35049;
  254. var StreamReadUsage = 35041;
  255. var StaticCopyUsage = 35046;
  256. var DynamicCopyUsage = 35050;
  257. var StreamCopyUsage = 35042;
  258. var GLSL1 = "100";
  259. var GLSL3 = "300 es";
  260. /**
  261. * https://github.com/mrdoob/eventdispatcher.js/
  262. */
  263. function EventDispatcher() {}
  264. Object.assign(EventDispatcher.prototype, {
  265. addEventListener: function addEventListener(type, listener) {
  266. if (this._listeners === undefined) this._listeners = {};
  267. var listeners = this._listeners;
  268. if (listeners[type] === undefined) {
  269. listeners[type] = [];
  270. }
  271. if (listeners[type].indexOf(listener) === -1) {
  272. listeners[type].push(listener);
  273. }
  274. },
  275. hasEventListener: function hasEventListener(type, listener) {
  276. if (this._listeners === undefined) return false;
  277. var listeners = this._listeners;
  278. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  279. },
  280. removeEventListener: function removeEventListener(type, listener) {
  281. if (this._listeners === undefined) return;
  282. var listeners = this._listeners;
  283. var listenerArray = listeners[type];
  284. if (listenerArray !== undefined) {
  285. var index = listenerArray.indexOf(listener);
  286. if (index !== -1) {
  287. listenerArray.splice(index, 1);
  288. }
  289. }
  290. },
  291. dispatchEvent: function dispatchEvent(event) {
  292. if (this._listeners === undefined) return;
  293. var listeners = this._listeners;
  294. var listenerArray = listeners[event.type];
  295. if (listenerArray !== undefined) {
  296. event.target = this; // Make a copy, in case listeners are removed while iterating.
  297. var array = listenerArray.slice(0);
  298. for (var i = 0, l = array.length; i < l; i++) {
  299. array[i].call(this, event);
  300. }
  301. }
  302. }
  303. });
  304. var _lut = [];
  305. for (var i = 0; i < 256; i++) {
  306. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  307. }
  308. var _seed = 1234567;
  309. var MathUtils = {
  310. DEG2RAD: Math.PI / 180,
  311. RAD2DEG: 180 / Math.PI,
  312. generateUUID: function generateUUID() {
  313. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  314. var d0 = Math.random() * 0xffffffff | 0;
  315. var d1 = Math.random() * 0xffffffff | 0;
  316. var d2 = Math.random() * 0xffffffff | 0;
  317. var d3 = Math.random() * 0xffffffff | 0;
  318. 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.
  319. return uuid.toUpperCase();
  320. },
  321. clamp: function clamp(value, min, max) {
  322. return Math.max(min, Math.min(max, value));
  323. },
  324. // compute euclidian modulo of m % n
  325. // https://en.wikipedia.org/wiki/Modulo_operation
  326. euclideanModulo: function euclideanModulo(n, m) {
  327. return (n % m + m) % m;
  328. },
  329. // Linear mapping from range <a1, a2> to range <b1, b2>
  330. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  331. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  332. },
  333. // https://en.wikipedia.org/wiki/Linear_interpolation
  334. lerp: function lerp(x, y, t) {
  335. return (1 - t) * x + t * y;
  336. },
  337. // http://en.wikipedia.org/wiki/Smoothstep
  338. smoothstep: function smoothstep(x, min, max) {
  339. if (x <= min) return 0;
  340. if (x >= max) return 1;
  341. x = (x - min) / (max - min);
  342. return x * x * (3 - 2 * x);
  343. },
  344. smootherstep: function smootherstep(x, min, max) {
  345. if (x <= min) return 0;
  346. if (x >= max) return 1;
  347. x = (x - min) / (max - min);
  348. return x * x * x * (x * (x * 6 - 15) + 10);
  349. },
  350. // Random integer from <low, high> interval
  351. randInt: function randInt(low, high) {
  352. return low + Math.floor(Math.random() * (high - low + 1));
  353. },
  354. // Random float from <low, high> interval
  355. randFloat: function randFloat(low, high) {
  356. return low + Math.random() * (high - low);
  357. },
  358. // Random float from <-range/2, range/2> interval
  359. randFloatSpread: function randFloatSpread(range) {
  360. return range * (0.5 - Math.random());
  361. },
  362. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  363. seededRandom: function seededRandom(s) {
  364. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  365. _seed = _seed * 16807 % 2147483647;
  366. return (_seed - 1) / 2147483646;
  367. },
  368. degToRad: function degToRad(degrees) {
  369. return degrees * MathUtils.DEG2RAD;
  370. },
  371. radToDeg: function radToDeg(radians) {
  372. return radians * MathUtils.RAD2DEG;
  373. },
  374. isPowerOfTwo: function isPowerOfTwo(value) {
  375. return (value & value - 1) === 0 && value !== 0;
  376. },
  377. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  378. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  379. },
  380. floorPowerOfTwo: function floorPowerOfTwo(value) {
  381. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  382. },
  383. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  384. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  385. // rotations are applied to the axes in the order specified by 'order'
  386. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  387. // angles are in radians
  388. var cos = Math.cos;
  389. var sin = Math.sin;
  390. var c2 = cos(b / 2);
  391. var s2 = sin(b / 2);
  392. var c13 = cos((a + c) / 2);
  393. var s13 = sin((a + c) / 2);
  394. var c1_3 = cos((a - c) / 2);
  395. var s1_3 = sin((a - c) / 2);
  396. var c3_1 = cos((c - a) / 2);
  397. var s3_1 = sin((c - a) / 2);
  398. switch (order) {
  399. case 'XYX':
  400. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  401. break;
  402. case 'YZY':
  403. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  404. break;
  405. case 'ZXZ':
  406. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  407. break;
  408. case 'XZX':
  409. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  410. break;
  411. case 'YXY':
  412. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  413. break;
  414. case 'ZYZ':
  415. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  416. break;
  417. default:
  418. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  419. }
  420. }
  421. };
  422. function _defineProperties(target, props) {
  423. for (var i = 0; i < props.length; i++) {
  424. var descriptor = props[i];
  425. descriptor.enumerable = descriptor.enumerable || false;
  426. descriptor.configurable = true;
  427. if ("value" in descriptor) descriptor.writable = true;
  428. Object.defineProperty(target, descriptor.key, descriptor);
  429. }
  430. }
  431. function _createClass(Constructor, protoProps, staticProps) {
  432. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  433. if (staticProps) _defineProperties(Constructor, staticProps);
  434. return Constructor;
  435. }
  436. function _inheritsLoose(subClass, superClass) {
  437. subClass.prototype = Object.create(superClass.prototype);
  438. subClass.prototype.constructor = subClass;
  439. subClass.__proto__ = superClass;
  440. }
  441. function _assertThisInitialized(self) {
  442. if (self === void 0) {
  443. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  444. }
  445. return self;
  446. }
  447. var Vector2 = /*#__PURE__*/function () {
  448. function Vector2(x, y) {
  449. if (x === void 0) {
  450. x = 0;
  451. }
  452. if (y === void 0) {
  453. y = 0;
  454. }
  455. Object.defineProperty(this, 'isVector2', {
  456. value: true
  457. });
  458. this.x = x;
  459. this.y = y;
  460. }
  461. var _proto = Vector2.prototype;
  462. _proto.set = function set(x, y) {
  463. this.x = x;
  464. this.y = y;
  465. return this;
  466. };
  467. _proto.setScalar = function setScalar(scalar) {
  468. this.x = scalar;
  469. this.y = scalar;
  470. return this;
  471. };
  472. _proto.setX = function setX(x) {
  473. this.x = x;
  474. return this;
  475. };
  476. _proto.setY = function setY(y) {
  477. this.y = y;
  478. return this;
  479. };
  480. _proto.setComponent = function setComponent(index, value) {
  481. switch (index) {
  482. case 0:
  483. this.x = value;
  484. break;
  485. case 1:
  486. this.y = value;
  487. break;
  488. default:
  489. throw new Error('index is out of range: ' + index);
  490. }
  491. return this;
  492. };
  493. _proto.getComponent = function getComponent(index) {
  494. switch (index) {
  495. case 0:
  496. return this.x;
  497. case 1:
  498. return this.y;
  499. default:
  500. throw new Error('index is out of range: ' + index);
  501. }
  502. };
  503. _proto.clone = function clone() {
  504. return new this.constructor(this.x, this.y);
  505. };
  506. _proto.copy = function copy(v) {
  507. this.x = v.x;
  508. this.y = v.y;
  509. return this;
  510. };
  511. _proto.add = function add(v, w) {
  512. if (w !== undefined) {
  513. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  514. return this.addVectors(v, w);
  515. }
  516. this.x += v.x;
  517. this.y += v.y;
  518. return this;
  519. };
  520. _proto.addScalar = function addScalar(s) {
  521. this.x += s;
  522. this.y += s;
  523. return this;
  524. };
  525. _proto.addVectors = function addVectors(a, b) {
  526. this.x = a.x + b.x;
  527. this.y = a.y + b.y;
  528. return this;
  529. };
  530. _proto.addScaledVector = function addScaledVector(v, s) {
  531. this.x += v.x * s;
  532. this.y += v.y * s;
  533. return this;
  534. };
  535. _proto.sub = function sub(v, w) {
  536. if (w !== undefined) {
  537. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  538. return this.subVectors(v, w);
  539. }
  540. this.x -= v.x;
  541. this.y -= v.y;
  542. return this;
  543. };
  544. _proto.subScalar = function subScalar(s) {
  545. this.x -= s;
  546. this.y -= s;
  547. return this;
  548. };
  549. _proto.subVectors = function subVectors(a, b) {
  550. this.x = a.x - b.x;
  551. this.y = a.y - b.y;
  552. return this;
  553. };
  554. _proto.multiply = function multiply(v) {
  555. this.x *= v.x;
  556. this.y *= v.y;
  557. return this;
  558. };
  559. _proto.multiplyScalar = function multiplyScalar(scalar) {
  560. this.x *= scalar;
  561. this.y *= scalar;
  562. return this;
  563. };
  564. _proto.divide = function divide(v) {
  565. this.x /= v.x;
  566. this.y /= v.y;
  567. return this;
  568. };
  569. _proto.divideScalar = function divideScalar(scalar) {
  570. return this.multiplyScalar(1 / scalar);
  571. };
  572. _proto.applyMatrix3 = function applyMatrix3(m) {
  573. var x = this.x,
  574. y = this.y;
  575. var e = m.elements;
  576. this.x = e[0] * x + e[3] * y + e[6];
  577. this.y = e[1] * x + e[4] * y + e[7];
  578. return this;
  579. };
  580. _proto.min = function min(v) {
  581. this.x = Math.min(this.x, v.x);
  582. this.y = Math.min(this.y, v.y);
  583. return this;
  584. };
  585. _proto.max = function max(v) {
  586. this.x = Math.max(this.x, v.x);
  587. this.y = Math.max(this.y, v.y);
  588. return this;
  589. };
  590. _proto.clamp = function clamp(min, max) {
  591. // assumes min < max, componentwise
  592. this.x = Math.max(min.x, Math.min(max.x, this.x));
  593. this.y = Math.max(min.y, Math.min(max.y, this.y));
  594. return this;
  595. };
  596. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  597. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  598. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  599. return this;
  600. };
  601. _proto.clampLength = function clampLength(min, max) {
  602. var length = this.length();
  603. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  604. };
  605. _proto.floor = function floor() {
  606. this.x = Math.floor(this.x);
  607. this.y = Math.floor(this.y);
  608. return this;
  609. };
  610. _proto.ceil = function ceil() {
  611. this.x = Math.ceil(this.x);
  612. this.y = Math.ceil(this.y);
  613. return this;
  614. };
  615. _proto.round = function round() {
  616. this.x = Math.round(this.x);
  617. this.y = Math.round(this.y);
  618. return this;
  619. };
  620. _proto.roundToZero = function roundToZero() {
  621. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  622. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  623. return this;
  624. };
  625. _proto.negate = function negate() {
  626. this.x = -this.x;
  627. this.y = -this.y;
  628. return this;
  629. };
  630. _proto.dot = function dot(v) {
  631. return this.x * v.x + this.y * v.y;
  632. };
  633. _proto.cross = function cross(v) {
  634. return this.x * v.y - this.y * v.x;
  635. };
  636. _proto.lengthSq = function lengthSq() {
  637. return this.x * this.x + this.y * this.y;
  638. };
  639. _proto.length = function length() {
  640. return Math.sqrt(this.x * this.x + this.y * this.y);
  641. };
  642. _proto.manhattanLength = function manhattanLength() {
  643. return Math.abs(this.x) + Math.abs(this.y);
  644. };
  645. _proto.normalize = function normalize() {
  646. return this.divideScalar(this.length() || 1);
  647. };
  648. _proto.angle = function angle() {
  649. // computes the angle in radians with respect to the positive x-axis
  650. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  651. return angle;
  652. };
  653. _proto.distanceTo = function distanceTo(v) {
  654. return Math.sqrt(this.distanceToSquared(v));
  655. };
  656. _proto.distanceToSquared = function distanceToSquared(v) {
  657. var dx = this.x - v.x,
  658. dy = this.y - v.y;
  659. return dx * dx + dy * dy;
  660. };
  661. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  662. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  663. };
  664. _proto.setLength = function setLength(length) {
  665. return this.normalize().multiplyScalar(length);
  666. };
  667. _proto.lerp = function lerp(v, alpha) {
  668. this.x += (v.x - this.x) * alpha;
  669. this.y += (v.y - this.y) * alpha;
  670. return this;
  671. };
  672. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  673. this.x = v1.x + (v2.x - v1.x) * alpha;
  674. this.y = v1.y + (v2.y - v1.y) * alpha;
  675. return this;
  676. };
  677. _proto.equals = function equals(v) {
  678. return v.x === this.x && v.y === this.y;
  679. };
  680. _proto.fromArray = function fromArray(array, offset) {
  681. if (offset === void 0) {
  682. offset = 0;
  683. }
  684. this.x = array[offset];
  685. this.y = array[offset + 1];
  686. return this;
  687. };
  688. _proto.toArray = function toArray(array, offset) {
  689. if (array === void 0) {
  690. array = [];
  691. }
  692. if (offset === void 0) {
  693. offset = 0;
  694. }
  695. array[offset] = this.x;
  696. array[offset + 1] = this.y;
  697. return array;
  698. };
  699. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  700. if (offset !== undefined) {
  701. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  702. }
  703. this.x = attribute.getX(index);
  704. this.y = attribute.getY(index);
  705. return this;
  706. };
  707. _proto.rotateAround = function rotateAround(center, angle) {
  708. var c = Math.cos(angle),
  709. s = Math.sin(angle);
  710. var x = this.x - center.x;
  711. var y = this.y - center.y;
  712. this.x = x * c - y * s + center.x;
  713. this.y = x * s + y * c + center.y;
  714. return this;
  715. };
  716. _proto.random = function random() {
  717. this.x = Math.random();
  718. this.y = Math.random();
  719. return this;
  720. };
  721. _createClass(Vector2, [{
  722. key: "width",
  723. get: function get() {
  724. return this.x;
  725. },
  726. set: function set(value) {
  727. this.x = value;
  728. }
  729. }, {
  730. key: "height",
  731. get: function get() {
  732. return this.y;
  733. },
  734. set: function set(value) {
  735. this.y = value;
  736. }
  737. }]);
  738. return Vector2;
  739. }();
  740. var Matrix3 = /*#__PURE__*/function () {
  741. function Matrix3() {
  742. Object.defineProperty(this, 'isMatrix3', {
  743. value: true
  744. });
  745. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  746. if (arguments.length > 0) {
  747. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  748. }
  749. }
  750. var _proto = Matrix3.prototype;
  751. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  752. var te = this.elements;
  753. te[0] = n11;
  754. te[1] = n21;
  755. te[2] = n31;
  756. te[3] = n12;
  757. te[4] = n22;
  758. te[5] = n32;
  759. te[6] = n13;
  760. te[7] = n23;
  761. te[8] = n33;
  762. return this;
  763. };
  764. _proto.identity = function identity() {
  765. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  766. return this;
  767. };
  768. _proto.clone = function clone() {
  769. return new this.constructor().fromArray(this.elements);
  770. };
  771. _proto.copy = function copy(m) {
  772. var te = this.elements;
  773. var me = m.elements;
  774. te[0] = me[0];
  775. te[1] = me[1];
  776. te[2] = me[2];
  777. te[3] = me[3];
  778. te[4] = me[4];
  779. te[5] = me[5];
  780. te[6] = me[6];
  781. te[7] = me[7];
  782. te[8] = me[8];
  783. return this;
  784. };
  785. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  786. xAxis.setFromMatrix3Column(this, 0);
  787. yAxis.setFromMatrix3Column(this, 1);
  788. zAxis.setFromMatrix3Column(this, 2);
  789. return this;
  790. };
  791. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  792. var me = m.elements;
  793. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  794. return this;
  795. };
  796. _proto.multiply = function multiply(m) {
  797. return this.multiplyMatrices(this, m);
  798. };
  799. _proto.premultiply = function premultiply(m) {
  800. return this.multiplyMatrices(m, this);
  801. };
  802. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  803. var ae = a.elements;
  804. var be = b.elements;
  805. var te = this.elements;
  806. var a11 = ae[0],
  807. a12 = ae[3],
  808. a13 = ae[6];
  809. var a21 = ae[1],
  810. a22 = ae[4],
  811. a23 = ae[7];
  812. var a31 = ae[2],
  813. a32 = ae[5],
  814. a33 = ae[8];
  815. var b11 = be[0],
  816. b12 = be[3],
  817. b13 = be[6];
  818. var b21 = be[1],
  819. b22 = be[4],
  820. b23 = be[7];
  821. var b31 = be[2],
  822. b32 = be[5],
  823. b33 = be[8];
  824. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  825. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  826. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  827. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  828. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  829. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  830. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  831. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  832. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  833. return this;
  834. };
  835. _proto.multiplyScalar = function multiplyScalar(s) {
  836. var te = this.elements;
  837. te[0] *= s;
  838. te[3] *= s;
  839. te[6] *= s;
  840. te[1] *= s;
  841. te[4] *= s;
  842. te[7] *= s;
  843. te[2] *= s;
  844. te[5] *= s;
  845. te[8] *= s;
  846. return this;
  847. };
  848. _proto.determinant = function determinant() {
  849. var te = this.elements;
  850. var a = te[0],
  851. b = te[1],
  852. c = te[2],
  853. d = te[3],
  854. e = te[4],
  855. f = te[5],
  856. g = te[6],
  857. h = te[7],
  858. i = te[8];
  859. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  860. };
  861. _proto.invert = function invert() {
  862. var te = this.elements,
  863. n11 = te[0],
  864. n21 = te[1],
  865. n31 = te[2],
  866. n12 = te[3],
  867. n22 = te[4],
  868. n32 = te[5],
  869. n13 = te[6],
  870. n23 = te[7],
  871. n33 = te[8],
  872. t11 = n33 * n22 - n32 * n23,
  873. t12 = n32 * n13 - n33 * n12,
  874. t13 = n23 * n12 - n22 * n13,
  875. det = n11 * t11 + n21 * t12 + n31 * t13;
  876. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  877. var detInv = 1 / det;
  878. te[0] = t11 * detInv;
  879. te[1] = (n31 * n23 - n33 * n21) * detInv;
  880. te[2] = (n32 * n21 - n31 * n22) * detInv;
  881. te[3] = t12 * detInv;
  882. te[4] = (n33 * n11 - n31 * n13) * detInv;
  883. te[5] = (n31 * n12 - n32 * n11) * detInv;
  884. te[6] = t13 * detInv;
  885. te[7] = (n21 * n13 - n23 * n11) * detInv;
  886. te[8] = (n22 * n11 - n21 * n12) * detInv;
  887. return this;
  888. };
  889. _proto.transpose = function transpose() {
  890. var tmp;
  891. var m = this.elements;
  892. tmp = m[1];
  893. m[1] = m[3];
  894. m[3] = tmp;
  895. tmp = m[2];
  896. m[2] = m[6];
  897. m[6] = tmp;
  898. tmp = m[5];
  899. m[5] = m[7];
  900. m[7] = tmp;
  901. return this;
  902. };
  903. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  904. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  905. };
  906. _proto.transposeIntoArray = function transposeIntoArray(r) {
  907. var m = this.elements;
  908. r[0] = m[0];
  909. r[1] = m[3];
  910. r[2] = m[6];
  911. r[3] = m[1];
  912. r[4] = m[4];
  913. r[5] = m[7];
  914. r[6] = m[2];
  915. r[7] = m[5];
  916. r[8] = m[8];
  917. return this;
  918. };
  919. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  920. var c = Math.cos(rotation);
  921. var s = Math.sin(rotation);
  922. 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);
  923. };
  924. _proto.scale = function scale(sx, sy) {
  925. var te = this.elements;
  926. te[0] *= sx;
  927. te[3] *= sx;
  928. te[6] *= sx;
  929. te[1] *= sy;
  930. te[4] *= sy;
  931. te[7] *= sy;
  932. return this;
  933. };
  934. _proto.rotate = function rotate(theta) {
  935. var c = Math.cos(theta);
  936. var s = Math.sin(theta);
  937. var te = this.elements;
  938. var a11 = te[0],
  939. a12 = te[3],
  940. a13 = te[6];
  941. var a21 = te[1],
  942. a22 = te[4],
  943. a23 = te[7];
  944. te[0] = c * a11 + s * a21;
  945. te[3] = c * a12 + s * a22;
  946. te[6] = c * a13 + s * a23;
  947. te[1] = -s * a11 + c * a21;
  948. te[4] = -s * a12 + c * a22;
  949. te[7] = -s * a13 + c * a23;
  950. return this;
  951. };
  952. _proto.translate = function translate(tx, ty) {
  953. var te = this.elements;
  954. te[0] += tx * te[2];
  955. te[3] += tx * te[5];
  956. te[6] += tx * te[8];
  957. te[1] += ty * te[2];
  958. te[4] += ty * te[5];
  959. te[7] += ty * te[8];
  960. return this;
  961. };
  962. _proto.equals = function equals(matrix) {
  963. var te = this.elements;
  964. var me = matrix.elements;
  965. for (var i = 0; i < 9; i++) {
  966. if (te[i] !== me[i]) return false;
  967. }
  968. return true;
  969. };
  970. _proto.fromArray = function fromArray(array, offset) {
  971. if (offset === void 0) {
  972. offset = 0;
  973. }
  974. for (var i = 0; i < 9; i++) {
  975. this.elements[i] = array[i + offset];
  976. }
  977. return this;
  978. };
  979. _proto.toArray = function toArray(array, offset) {
  980. if (array === void 0) {
  981. array = [];
  982. }
  983. if (offset === void 0) {
  984. offset = 0;
  985. }
  986. var te = this.elements;
  987. array[offset] = te[0];
  988. array[offset + 1] = te[1];
  989. array[offset + 2] = te[2];
  990. array[offset + 3] = te[3];
  991. array[offset + 4] = te[4];
  992. array[offset + 5] = te[5];
  993. array[offset + 6] = te[6];
  994. array[offset + 7] = te[7];
  995. array[offset + 8] = te[8];
  996. return array;
  997. };
  998. return Matrix3;
  999. }();
  1000. var _canvas;
  1001. var ImageUtils = {
  1002. getDataURL: function getDataURL(image) {
  1003. if (/^data:/i.test(image.src)) {
  1004. return image.src;
  1005. }
  1006. if (typeof HTMLCanvasElement == 'undefined') {
  1007. return image.src;
  1008. }
  1009. var canvas;
  1010. if (image instanceof HTMLCanvasElement) {
  1011. canvas = image;
  1012. } else {
  1013. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1014. _canvas.width = image.width;
  1015. _canvas.height = image.height;
  1016. var context = _canvas.getContext('2d');
  1017. if (image instanceof ImageData) {
  1018. context.putImageData(image, 0, 0);
  1019. } else {
  1020. context.drawImage(image, 0, 0, image.width, image.height);
  1021. }
  1022. canvas = _canvas;
  1023. }
  1024. if (canvas.width > 2048 || canvas.height > 2048) {
  1025. return canvas.toDataURL('image/jpeg', 0.6);
  1026. } else {
  1027. return canvas.toDataURL('image/png');
  1028. }
  1029. }
  1030. };
  1031. var textureId = 0;
  1032. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1033. Object.defineProperty(this, 'id', {
  1034. value: textureId++
  1035. });
  1036. this.uuid = MathUtils.generateUUID();
  1037. this.name = '';
  1038. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1039. this.mipmaps = [];
  1040. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1041. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1042. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1043. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1044. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1045. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1046. this.format = format !== undefined ? format : RGBAFormat;
  1047. this.internalFormat = null;
  1048. this.type = type !== undefined ? type : UnsignedByteType;
  1049. this.offset = new Vector2(0, 0);
  1050. this.repeat = new Vector2(1, 1);
  1051. this.center = new Vector2(0, 0);
  1052. this.rotation = 0;
  1053. this.matrixAutoUpdate = true;
  1054. this.matrix = new Matrix3();
  1055. this.generateMipmaps = true;
  1056. this.premultiplyAlpha = false;
  1057. this.flipY = true;
  1058. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1059. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1060. //
  1061. // Also changing the encoding after already used by a Material will not automatically make the Material
  1062. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1063. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1064. this.version = 0;
  1065. this.onUpdate = null;
  1066. }
  1067. Texture.DEFAULT_IMAGE = undefined;
  1068. Texture.DEFAULT_MAPPING = UVMapping;
  1069. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1070. constructor: Texture,
  1071. isTexture: true,
  1072. updateMatrix: function updateMatrix() {
  1073. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1074. },
  1075. clone: function clone() {
  1076. return new this.constructor().copy(this);
  1077. },
  1078. copy: function copy(source) {
  1079. this.name = source.name;
  1080. this.image = source.image;
  1081. this.mipmaps = source.mipmaps.slice(0);
  1082. this.mapping = source.mapping;
  1083. this.wrapS = source.wrapS;
  1084. this.wrapT = source.wrapT;
  1085. this.magFilter = source.magFilter;
  1086. this.minFilter = source.minFilter;
  1087. this.anisotropy = source.anisotropy;
  1088. this.format = source.format;
  1089. this.internalFormat = source.internalFormat;
  1090. this.type = source.type;
  1091. this.offset.copy(source.offset);
  1092. this.repeat.copy(source.repeat);
  1093. this.center.copy(source.center);
  1094. this.rotation = source.rotation;
  1095. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1096. this.matrix.copy(source.matrix);
  1097. this.generateMipmaps = source.generateMipmaps;
  1098. this.premultiplyAlpha = source.premultiplyAlpha;
  1099. this.flipY = source.flipY;
  1100. this.unpackAlignment = source.unpackAlignment;
  1101. this.encoding = source.encoding;
  1102. return this;
  1103. },
  1104. toJSON: function toJSON(meta) {
  1105. var isRootObject = meta === undefined || typeof meta === 'string';
  1106. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1107. return meta.textures[this.uuid];
  1108. }
  1109. var output = {
  1110. metadata: {
  1111. version: 4.5,
  1112. type: 'Texture',
  1113. generator: 'Texture.toJSON'
  1114. },
  1115. uuid: this.uuid,
  1116. name: this.name,
  1117. mapping: this.mapping,
  1118. repeat: [this.repeat.x, this.repeat.y],
  1119. offset: [this.offset.x, this.offset.y],
  1120. center: [this.center.x, this.center.y],
  1121. rotation: this.rotation,
  1122. wrap: [this.wrapS, this.wrapT],
  1123. format: this.format,
  1124. type: this.type,
  1125. encoding: this.encoding,
  1126. minFilter: this.minFilter,
  1127. magFilter: this.magFilter,
  1128. anisotropy: this.anisotropy,
  1129. flipY: this.flipY,
  1130. premultiplyAlpha: this.premultiplyAlpha,
  1131. unpackAlignment: this.unpackAlignment
  1132. };
  1133. if (this.image !== undefined) {
  1134. // TODO: Move to THREE.Image
  1135. var image = this.image;
  1136. if (image.uuid === undefined) {
  1137. image.uuid = MathUtils.generateUUID(); // UGH
  1138. }
  1139. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1140. var url;
  1141. if (Array.isArray(image)) {
  1142. // process array of images e.g. CubeTexture
  1143. url = [];
  1144. for (var i = 0, l = image.length; i < l; i++) {
  1145. url.push(ImageUtils.getDataURL(image[i]));
  1146. }
  1147. } else {
  1148. // process single image
  1149. url = ImageUtils.getDataURL(image);
  1150. }
  1151. meta.images[image.uuid] = {
  1152. uuid: image.uuid,
  1153. url: url
  1154. };
  1155. }
  1156. output.image = image.uuid;
  1157. }
  1158. if (!isRootObject) {
  1159. meta.textures[this.uuid] = output;
  1160. }
  1161. return output;
  1162. },
  1163. dispose: function dispose() {
  1164. this.dispatchEvent({
  1165. type: 'dispose'
  1166. });
  1167. },
  1168. transformUv: function transformUv(uv) {
  1169. if (this.mapping !== UVMapping) return uv;
  1170. uv.applyMatrix3(this.matrix);
  1171. if (uv.x < 0 || uv.x > 1) {
  1172. switch (this.wrapS) {
  1173. case RepeatWrapping:
  1174. uv.x = uv.x - Math.floor(uv.x);
  1175. break;
  1176. case ClampToEdgeWrapping:
  1177. uv.x = uv.x < 0 ? 0 : 1;
  1178. break;
  1179. case MirroredRepeatWrapping:
  1180. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1181. uv.x = Math.ceil(uv.x) - uv.x;
  1182. } else {
  1183. uv.x = uv.x - Math.floor(uv.x);
  1184. }
  1185. break;
  1186. }
  1187. }
  1188. if (uv.y < 0 || uv.y > 1) {
  1189. switch (this.wrapT) {
  1190. case RepeatWrapping:
  1191. uv.y = uv.y - Math.floor(uv.y);
  1192. break;
  1193. case ClampToEdgeWrapping:
  1194. uv.y = uv.y < 0 ? 0 : 1;
  1195. break;
  1196. case MirroredRepeatWrapping:
  1197. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1198. uv.y = Math.ceil(uv.y) - uv.y;
  1199. } else {
  1200. uv.y = uv.y - Math.floor(uv.y);
  1201. }
  1202. break;
  1203. }
  1204. }
  1205. if (this.flipY) {
  1206. uv.y = 1 - uv.y;
  1207. }
  1208. return uv;
  1209. }
  1210. });
  1211. Object.defineProperty(Texture.prototype, "needsUpdate", {
  1212. set: function set(value) {
  1213. if (value === true) this.version++;
  1214. }
  1215. });
  1216. var Vector4 = /*#__PURE__*/function () {
  1217. function Vector4(x, y, z, w) {
  1218. if (x === void 0) {
  1219. x = 0;
  1220. }
  1221. if (y === void 0) {
  1222. y = 0;
  1223. }
  1224. if (z === void 0) {
  1225. z = 0;
  1226. }
  1227. if (w === void 0) {
  1228. w = 1;
  1229. }
  1230. Object.defineProperty(this, 'isVector4', {
  1231. value: true
  1232. });
  1233. this.x = x;
  1234. this.y = y;
  1235. this.z = z;
  1236. this.w = w;
  1237. }
  1238. var _proto = Vector4.prototype;
  1239. _proto.set = function set(x, y, z, w) {
  1240. this.x = x;
  1241. this.y = y;
  1242. this.z = z;
  1243. this.w = w;
  1244. return this;
  1245. };
  1246. _proto.setScalar = function setScalar(scalar) {
  1247. this.x = scalar;
  1248. this.y = scalar;
  1249. this.z = scalar;
  1250. this.w = scalar;
  1251. return this;
  1252. };
  1253. _proto.setX = function setX(x) {
  1254. this.x = x;
  1255. return this;
  1256. };
  1257. _proto.setY = function setY(y) {
  1258. this.y = y;
  1259. return this;
  1260. };
  1261. _proto.setZ = function setZ(z) {
  1262. this.z = z;
  1263. return this;
  1264. };
  1265. _proto.setW = function setW(w) {
  1266. this.w = w;
  1267. return this;
  1268. };
  1269. _proto.setComponent = function setComponent(index, value) {
  1270. switch (index) {
  1271. case 0:
  1272. this.x = value;
  1273. break;
  1274. case 1:
  1275. this.y = value;
  1276. break;
  1277. case 2:
  1278. this.z = value;
  1279. break;
  1280. case 3:
  1281. this.w = value;
  1282. break;
  1283. default:
  1284. throw new Error('index is out of range: ' + index);
  1285. }
  1286. return this;
  1287. };
  1288. _proto.getComponent = function getComponent(index) {
  1289. switch (index) {
  1290. case 0:
  1291. return this.x;
  1292. case 1:
  1293. return this.y;
  1294. case 2:
  1295. return this.z;
  1296. case 3:
  1297. return this.w;
  1298. default:
  1299. throw new Error('index is out of range: ' + index);
  1300. }
  1301. };
  1302. _proto.clone = function clone() {
  1303. return new this.constructor(this.x, this.y, this.z, this.w);
  1304. };
  1305. _proto.copy = function copy(v) {
  1306. this.x = v.x;
  1307. this.y = v.y;
  1308. this.z = v.z;
  1309. this.w = v.w !== undefined ? v.w : 1;
  1310. return this;
  1311. };
  1312. _proto.add = function add(v, w) {
  1313. if (w !== undefined) {
  1314. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1315. return this.addVectors(v, w);
  1316. }
  1317. this.x += v.x;
  1318. this.y += v.y;
  1319. this.z += v.z;
  1320. this.w += v.w;
  1321. return this;
  1322. };
  1323. _proto.addScalar = function addScalar(s) {
  1324. this.x += s;
  1325. this.y += s;
  1326. this.z += s;
  1327. this.w += s;
  1328. return this;
  1329. };
  1330. _proto.addVectors = function addVectors(a, b) {
  1331. this.x = a.x + b.x;
  1332. this.y = a.y + b.y;
  1333. this.z = a.z + b.z;
  1334. this.w = a.w + b.w;
  1335. return this;
  1336. };
  1337. _proto.addScaledVector = function addScaledVector(v, s) {
  1338. this.x += v.x * s;
  1339. this.y += v.y * s;
  1340. this.z += v.z * s;
  1341. this.w += v.w * s;
  1342. return this;
  1343. };
  1344. _proto.sub = function sub(v, w) {
  1345. if (w !== undefined) {
  1346. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1347. return this.subVectors(v, w);
  1348. }
  1349. this.x -= v.x;
  1350. this.y -= v.y;
  1351. this.z -= v.z;
  1352. this.w -= v.w;
  1353. return this;
  1354. };
  1355. _proto.subScalar = function subScalar(s) {
  1356. this.x -= s;
  1357. this.y -= s;
  1358. this.z -= s;
  1359. this.w -= s;
  1360. return this;
  1361. };
  1362. _proto.subVectors = function subVectors(a, b) {
  1363. this.x = a.x - b.x;
  1364. this.y = a.y - b.y;
  1365. this.z = a.z - b.z;
  1366. this.w = a.w - b.w;
  1367. return this;
  1368. };
  1369. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1370. this.x *= scalar;
  1371. this.y *= scalar;
  1372. this.z *= scalar;
  1373. this.w *= scalar;
  1374. return this;
  1375. };
  1376. _proto.applyMatrix4 = function applyMatrix4(m) {
  1377. var x = this.x,
  1378. y = this.y,
  1379. z = this.z,
  1380. w = this.w;
  1381. var e = m.elements;
  1382. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1383. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1384. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1385. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1386. return this;
  1387. };
  1388. _proto.divideScalar = function divideScalar(scalar) {
  1389. return this.multiplyScalar(1 / scalar);
  1390. };
  1391. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1392. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1393. // q is assumed to be normalized
  1394. this.w = 2 * Math.acos(q.w);
  1395. var s = Math.sqrt(1 - q.w * q.w);
  1396. if (s < 0.0001) {
  1397. this.x = 1;
  1398. this.y = 0;
  1399. this.z = 0;
  1400. } else {
  1401. this.x = q.x / s;
  1402. this.y = q.y / s;
  1403. this.z = q.z / s;
  1404. }
  1405. return this;
  1406. };
  1407. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1408. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1409. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1410. var angle, x, y, z; // variables for result
  1411. var epsilon = 0.01,
  1412. // margin to allow for rounding errors
  1413. epsilon2 = 0.1,
  1414. // margin to distinguish between 0 and 180 degrees
  1415. te = m.elements,
  1416. m11 = te[0],
  1417. m12 = te[4],
  1418. m13 = te[8],
  1419. m21 = te[1],
  1420. m22 = te[5],
  1421. m23 = te[9],
  1422. m31 = te[2],
  1423. m32 = te[6],
  1424. m33 = te[10];
  1425. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1426. // singularity found
  1427. // first check for identity matrix which must have +1 for all terms
  1428. // in leading diagonal and zero in other terms
  1429. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1430. // this singularity is identity matrix so angle = 0
  1431. this.set(1, 0, 0, 0);
  1432. return this; // zero angle, arbitrary axis
  1433. } // otherwise this singularity is angle = 180
  1434. angle = Math.PI;
  1435. var xx = (m11 + 1) / 2;
  1436. var yy = (m22 + 1) / 2;
  1437. var zz = (m33 + 1) / 2;
  1438. var xy = (m12 + m21) / 4;
  1439. var xz = (m13 + m31) / 4;
  1440. var yz = (m23 + m32) / 4;
  1441. if (xx > yy && xx > zz) {
  1442. // m11 is the largest diagonal term
  1443. if (xx < epsilon) {
  1444. x = 0;
  1445. y = 0.707106781;
  1446. z = 0.707106781;
  1447. } else {
  1448. x = Math.sqrt(xx);
  1449. y = xy / x;
  1450. z = xz / x;
  1451. }
  1452. } else if (yy > zz) {
  1453. // m22 is the largest diagonal term
  1454. if (yy < epsilon) {
  1455. x = 0.707106781;
  1456. y = 0;
  1457. z = 0.707106781;
  1458. } else {
  1459. y = Math.sqrt(yy);
  1460. x = xy / y;
  1461. z = yz / y;
  1462. }
  1463. } else {
  1464. // m33 is the largest diagonal term so base result on this
  1465. if (zz < epsilon) {
  1466. x = 0.707106781;
  1467. y = 0.707106781;
  1468. z = 0;
  1469. } else {
  1470. z = Math.sqrt(zz);
  1471. x = xz / z;
  1472. y = yz / z;
  1473. }
  1474. }
  1475. this.set(x, y, z, angle);
  1476. return this; // return 180 deg rotation
  1477. } // as we have reached here there are no singularities so we can handle normally
  1478. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1479. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1480. // caught by singularity test above, but I've left it in just in case
  1481. this.x = (m32 - m23) / s;
  1482. this.y = (m13 - m31) / s;
  1483. this.z = (m21 - m12) / s;
  1484. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1485. return this;
  1486. };
  1487. _proto.min = function min(v) {
  1488. this.x = Math.min(this.x, v.x);
  1489. this.y = Math.min(this.y, v.y);
  1490. this.z = Math.min(this.z, v.z);
  1491. this.w = Math.min(this.w, v.w);
  1492. return this;
  1493. };
  1494. _proto.max = function max(v) {
  1495. this.x = Math.max(this.x, v.x);
  1496. this.y = Math.max(this.y, v.y);
  1497. this.z = Math.max(this.z, v.z);
  1498. this.w = Math.max(this.w, v.w);
  1499. return this;
  1500. };
  1501. _proto.clamp = function clamp(min, max) {
  1502. // assumes min < max, componentwise
  1503. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1504. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1505. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1506. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1507. return this;
  1508. };
  1509. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1510. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1511. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1512. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1513. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1514. return this;
  1515. };
  1516. _proto.clampLength = function clampLength(min, max) {
  1517. var length = this.length();
  1518. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1519. };
  1520. _proto.floor = function floor() {
  1521. this.x = Math.floor(this.x);
  1522. this.y = Math.floor(this.y);
  1523. this.z = Math.floor(this.z);
  1524. this.w = Math.floor(this.w);
  1525. return this;
  1526. };
  1527. _proto.ceil = function ceil() {
  1528. this.x = Math.ceil(this.x);
  1529. this.y = Math.ceil(this.y);
  1530. this.z = Math.ceil(this.z);
  1531. this.w = Math.ceil(this.w);
  1532. return this;
  1533. };
  1534. _proto.round = function round() {
  1535. this.x = Math.round(this.x);
  1536. this.y = Math.round(this.y);
  1537. this.z = Math.round(this.z);
  1538. this.w = Math.round(this.w);
  1539. return this;
  1540. };
  1541. _proto.roundToZero = function roundToZero() {
  1542. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1543. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1544. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1545. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1546. return this;
  1547. };
  1548. _proto.negate = function negate() {
  1549. this.x = -this.x;
  1550. this.y = -this.y;
  1551. this.z = -this.z;
  1552. this.w = -this.w;
  1553. return this;
  1554. };
  1555. _proto.dot = function dot(v) {
  1556. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1557. };
  1558. _proto.lengthSq = function lengthSq() {
  1559. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1560. };
  1561. _proto.length = function length() {
  1562. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1563. };
  1564. _proto.manhattanLength = function manhattanLength() {
  1565. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1566. };
  1567. _proto.normalize = function normalize() {
  1568. return this.divideScalar(this.length() || 1);
  1569. };
  1570. _proto.setLength = function setLength(length) {
  1571. return this.normalize().multiplyScalar(length);
  1572. };
  1573. _proto.lerp = function lerp(v, alpha) {
  1574. this.x += (v.x - this.x) * alpha;
  1575. this.y += (v.y - this.y) * alpha;
  1576. this.z += (v.z - this.z) * alpha;
  1577. this.w += (v.w - this.w) * alpha;
  1578. return this;
  1579. };
  1580. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1581. this.x = v1.x + (v2.x - v1.x) * alpha;
  1582. this.y = v1.y + (v2.y - v1.y) * alpha;
  1583. this.z = v1.z + (v2.z - v1.z) * alpha;
  1584. this.w = v1.w + (v2.w - v1.w) * alpha;
  1585. return this;
  1586. };
  1587. _proto.equals = function equals(v) {
  1588. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1589. };
  1590. _proto.fromArray = function fromArray(array, offset) {
  1591. if (offset === void 0) {
  1592. offset = 0;
  1593. }
  1594. this.x = array[offset];
  1595. this.y = array[offset + 1];
  1596. this.z = array[offset + 2];
  1597. this.w = array[offset + 3];
  1598. return this;
  1599. };
  1600. _proto.toArray = function toArray(array, offset) {
  1601. if (array === void 0) {
  1602. array = [];
  1603. }
  1604. if (offset === void 0) {
  1605. offset = 0;
  1606. }
  1607. array[offset] = this.x;
  1608. array[offset + 1] = this.y;
  1609. array[offset + 2] = this.z;
  1610. array[offset + 3] = this.w;
  1611. return array;
  1612. };
  1613. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1614. if (offset !== undefined) {
  1615. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1616. }
  1617. this.x = attribute.getX(index);
  1618. this.y = attribute.getY(index);
  1619. this.z = attribute.getZ(index);
  1620. this.w = attribute.getW(index);
  1621. return this;
  1622. };
  1623. _proto.random = function random() {
  1624. this.x = Math.random();
  1625. this.y = Math.random();
  1626. this.z = Math.random();
  1627. this.w = Math.random();
  1628. return this;
  1629. };
  1630. _createClass(Vector4, [{
  1631. key: "width",
  1632. get: function get() {
  1633. return this.z;
  1634. },
  1635. set: function set(value) {
  1636. this.z = value;
  1637. }
  1638. }, {
  1639. key: "height",
  1640. get: function get() {
  1641. return this.w;
  1642. },
  1643. set: function set(value) {
  1644. this.w = value;
  1645. }
  1646. }]);
  1647. return Vector4;
  1648. }();
  1649. /*
  1650. In options, we can specify:
  1651. * Texture parameters for an auto-generated target texture
  1652. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1653. */
  1654. function WebGLRenderTarget(width, height, options) {
  1655. this.width = width;
  1656. this.height = height;
  1657. this.scissor = new Vector4(0, 0, width, height);
  1658. this.scissorTest = false;
  1659. this.viewport = new Vector4(0, 0, width, height);
  1660. options = options || {};
  1661. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1662. this.texture.image = {};
  1663. this.texture.image.width = width;
  1664. this.texture.image.height = height;
  1665. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1666. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1667. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1668. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1669. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1670. }
  1671. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1672. constructor: WebGLRenderTarget,
  1673. isWebGLRenderTarget: true,
  1674. setSize: function setSize(width, height) {
  1675. if (this.width !== width || this.height !== height) {
  1676. this.width = width;
  1677. this.height = height;
  1678. this.texture.image.width = width;
  1679. this.texture.image.height = height;
  1680. this.dispose();
  1681. }
  1682. this.viewport.set(0, 0, width, height);
  1683. this.scissor.set(0, 0, width, height);
  1684. },
  1685. clone: function clone() {
  1686. return new this.constructor().copy(this);
  1687. },
  1688. copy: function copy(source) {
  1689. this.width = source.width;
  1690. this.height = source.height;
  1691. this.viewport.copy(source.viewport);
  1692. this.texture = source.texture.clone();
  1693. this.depthBuffer = source.depthBuffer;
  1694. this.stencilBuffer = source.stencilBuffer;
  1695. this.depthTexture = source.depthTexture;
  1696. return this;
  1697. },
  1698. dispose: function dispose() {
  1699. this.dispatchEvent({
  1700. type: 'dispose'
  1701. });
  1702. }
  1703. });
  1704. function WebGLMultisampleRenderTarget(width, height, options) {
  1705. WebGLRenderTarget.call(this, width, height, options);
  1706. this.samples = 4;
  1707. }
  1708. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1709. constructor: WebGLMultisampleRenderTarget,
  1710. isWebGLMultisampleRenderTarget: true,
  1711. copy: function copy(source) {
  1712. WebGLRenderTarget.prototype.copy.call(this, source);
  1713. this.samples = source.samples;
  1714. return this;
  1715. }
  1716. });
  1717. var Quaternion = /*#__PURE__*/function () {
  1718. function Quaternion(x, y, z, w) {
  1719. if (x === void 0) {
  1720. x = 0;
  1721. }
  1722. if (y === void 0) {
  1723. y = 0;
  1724. }
  1725. if (z === void 0) {
  1726. z = 0;
  1727. }
  1728. if (w === void 0) {
  1729. w = 1;
  1730. }
  1731. Object.defineProperty(this, 'isQuaternion', {
  1732. value: true
  1733. });
  1734. this._x = x;
  1735. this._y = y;
  1736. this._z = z;
  1737. this._w = w;
  1738. }
  1739. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1740. return qm.copy(qa).slerp(qb, t);
  1741. };
  1742. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1743. // fuzz-free, array-based Quaternion SLERP operation
  1744. var x0 = src0[srcOffset0 + 0],
  1745. y0 = src0[srcOffset0 + 1],
  1746. z0 = src0[srcOffset0 + 2],
  1747. w0 = src0[srcOffset0 + 3];
  1748. var x1 = src1[srcOffset1 + 0],
  1749. y1 = src1[srcOffset1 + 1],
  1750. z1 = src1[srcOffset1 + 2],
  1751. w1 = src1[srcOffset1 + 3];
  1752. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1753. var s = 1 - t;
  1754. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1755. dir = cos >= 0 ? 1 : -1,
  1756. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1757. if (sqrSin > Number.EPSILON) {
  1758. var sin = Math.sqrt(sqrSin),
  1759. len = Math.atan2(sin, cos * dir);
  1760. s = Math.sin(s * len) / sin;
  1761. t = Math.sin(t * len) / sin;
  1762. }
  1763. var tDir = t * dir;
  1764. x0 = x0 * s + x1 * tDir;
  1765. y0 = y0 * s + y1 * tDir;
  1766. z0 = z0 * s + z1 * tDir;
  1767. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1768. if (s === 1 - t) {
  1769. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1770. x0 *= f;
  1771. y0 *= f;
  1772. z0 *= f;
  1773. w0 *= f;
  1774. }
  1775. }
  1776. dst[dstOffset] = x0;
  1777. dst[dstOffset + 1] = y0;
  1778. dst[dstOffset + 2] = z0;
  1779. dst[dstOffset + 3] = w0;
  1780. };
  1781. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1782. var x0 = src0[srcOffset0];
  1783. var y0 = src0[srcOffset0 + 1];
  1784. var z0 = src0[srcOffset0 + 2];
  1785. var w0 = src0[srcOffset0 + 3];
  1786. var x1 = src1[srcOffset1];
  1787. var y1 = src1[srcOffset1 + 1];
  1788. var z1 = src1[srcOffset1 + 2];
  1789. var w1 = src1[srcOffset1 + 3];
  1790. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1791. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1792. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1793. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1794. return dst;
  1795. };
  1796. var _proto = Quaternion.prototype;
  1797. _proto.set = function set(x, y, z, w) {
  1798. this._x = x;
  1799. this._y = y;
  1800. this._z = z;
  1801. this._w = w;
  1802. this._onChangeCallback();
  1803. return this;
  1804. };
  1805. _proto.clone = function clone() {
  1806. return new this.constructor(this._x, this._y, this._z, this._w);
  1807. };
  1808. _proto.copy = function copy(quaternion) {
  1809. this._x = quaternion.x;
  1810. this._y = quaternion.y;
  1811. this._z = quaternion.z;
  1812. this._w = quaternion.w;
  1813. this._onChangeCallback();
  1814. return this;
  1815. };
  1816. _proto.setFromEuler = function setFromEuler(euler, update) {
  1817. if (!(euler && euler.isEuler)) {
  1818. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1819. }
  1820. var x = euler._x,
  1821. y = euler._y,
  1822. z = euler._z,
  1823. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1824. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1825. // content/SpinCalc.m
  1826. var cos = Math.cos;
  1827. var sin = Math.sin;
  1828. var c1 = cos(x / 2);
  1829. var c2 = cos(y / 2);
  1830. var c3 = cos(z / 2);
  1831. var s1 = sin(x / 2);
  1832. var s2 = sin(y / 2);
  1833. var s3 = sin(z / 2);
  1834. switch (order) {
  1835. case 'XYZ':
  1836. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1837. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1838. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1839. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1840. break;
  1841. case 'YXZ':
  1842. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1843. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1844. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1845. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1846. break;
  1847. case 'ZXY':
  1848. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1849. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1850. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1851. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1852. break;
  1853. case 'ZYX':
  1854. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1855. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1856. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1857. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1858. break;
  1859. case 'YZX':
  1860. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1861. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1862. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1863. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1864. break;
  1865. case 'XZY':
  1866. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1867. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1868. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1869. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1870. break;
  1871. default:
  1872. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1873. }
  1874. if (update !== false) this._onChangeCallback();
  1875. return this;
  1876. };
  1877. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1878. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1879. // assumes axis is normalized
  1880. var halfAngle = angle / 2,
  1881. s = Math.sin(halfAngle);
  1882. this._x = axis.x * s;
  1883. this._y = axis.y * s;
  1884. this._z = axis.z * s;
  1885. this._w = Math.cos(halfAngle);
  1886. this._onChangeCallback();
  1887. return this;
  1888. };
  1889. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1890. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1891. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1892. var te = m.elements,
  1893. m11 = te[0],
  1894. m12 = te[4],
  1895. m13 = te[8],
  1896. m21 = te[1],
  1897. m22 = te[5],
  1898. m23 = te[9],
  1899. m31 = te[2],
  1900. m32 = te[6],
  1901. m33 = te[10],
  1902. trace = m11 + m22 + m33;
  1903. if (trace > 0) {
  1904. var s = 0.5 / Math.sqrt(trace + 1.0);
  1905. this._w = 0.25 / s;
  1906. this._x = (m32 - m23) * s;
  1907. this._y = (m13 - m31) * s;
  1908. this._z = (m21 - m12) * s;
  1909. } else if (m11 > m22 && m11 > m33) {
  1910. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1911. this._w = (m32 - m23) / _s;
  1912. this._x = 0.25 * _s;
  1913. this._y = (m12 + m21) / _s;
  1914. this._z = (m13 + m31) / _s;
  1915. } else if (m22 > m33) {
  1916. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1917. this._w = (m13 - m31) / _s2;
  1918. this._x = (m12 + m21) / _s2;
  1919. this._y = 0.25 * _s2;
  1920. this._z = (m23 + m32) / _s2;
  1921. } else {
  1922. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1923. this._w = (m21 - m12) / _s3;
  1924. this._x = (m13 + m31) / _s3;
  1925. this._y = (m23 + m32) / _s3;
  1926. this._z = 0.25 * _s3;
  1927. }
  1928. this._onChangeCallback();
  1929. return this;
  1930. };
  1931. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1932. // assumes direction vectors vFrom and vTo are normalized
  1933. var EPS = 0.000001;
  1934. var r = vFrom.dot(vTo) + 1;
  1935. if (r < EPS) {
  1936. r = 0;
  1937. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1938. this._x = -vFrom.y;
  1939. this._y = vFrom.x;
  1940. this._z = 0;
  1941. this._w = r;
  1942. } else {
  1943. this._x = 0;
  1944. this._y = -vFrom.z;
  1945. this._z = vFrom.y;
  1946. this._w = r;
  1947. }
  1948. } else {
  1949. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1950. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1951. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1952. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1953. this._w = r;
  1954. }
  1955. return this.normalize();
  1956. };
  1957. _proto.angleTo = function angleTo(q) {
  1958. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  1959. };
  1960. _proto.rotateTowards = function rotateTowards(q, step) {
  1961. var angle = this.angleTo(q);
  1962. if (angle === 0) return this;
  1963. var t = Math.min(1, step / angle);
  1964. this.slerp(q, t);
  1965. return this;
  1966. };
  1967. _proto.identity = function identity() {
  1968. return this.set(0, 0, 0, 1);
  1969. };
  1970. _proto.invert = function invert() {
  1971. // quaternion is assumed to have unit length
  1972. return this.conjugate();
  1973. };
  1974. _proto.conjugate = function conjugate() {
  1975. this._x *= -1;
  1976. this._y *= -1;
  1977. this._z *= -1;
  1978. this._onChangeCallback();
  1979. return this;
  1980. };
  1981. _proto.dot = function dot(v) {
  1982. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1983. };
  1984. _proto.lengthSq = function lengthSq() {
  1985. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1986. };
  1987. _proto.length = function length() {
  1988. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  1989. };
  1990. _proto.normalize = function normalize() {
  1991. var l = this.length();
  1992. if (l === 0) {
  1993. this._x = 0;
  1994. this._y = 0;
  1995. this._z = 0;
  1996. this._w = 1;
  1997. } else {
  1998. l = 1 / l;
  1999. this._x = this._x * l;
  2000. this._y = this._y * l;
  2001. this._z = this._z * l;
  2002. this._w = this._w * l;
  2003. }
  2004. this._onChangeCallback();
  2005. return this;
  2006. };
  2007. _proto.multiply = function multiply(q, p) {
  2008. if (p !== undefined) {
  2009. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2010. return this.multiplyQuaternions(q, p);
  2011. }
  2012. return this.multiplyQuaternions(this, q);
  2013. };
  2014. _proto.premultiply = function premultiply(q) {
  2015. return this.multiplyQuaternions(q, this);
  2016. };
  2017. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2018. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2019. var qax = a._x,
  2020. qay = a._y,
  2021. qaz = a._z,
  2022. qaw = a._w;
  2023. var qbx = b._x,
  2024. qby = b._y,
  2025. qbz = b._z,
  2026. qbw = b._w;
  2027. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2028. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2029. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2030. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2031. this._onChangeCallback();
  2032. return this;
  2033. };
  2034. _proto.slerp = function slerp(qb, t) {
  2035. if (t === 0) return this;
  2036. if (t === 1) return this.copy(qb);
  2037. var x = this._x,
  2038. y = this._y,
  2039. z = this._z,
  2040. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2041. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2042. if (cosHalfTheta < 0) {
  2043. this._w = -qb._w;
  2044. this._x = -qb._x;
  2045. this._y = -qb._y;
  2046. this._z = -qb._z;
  2047. cosHalfTheta = -cosHalfTheta;
  2048. } else {
  2049. this.copy(qb);
  2050. }
  2051. if (cosHalfTheta >= 1.0) {
  2052. this._w = w;
  2053. this._x = x;
  2054. this._y = y;
  2055. this._z = z;
  2056. return this;
  2057. }
  2058. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2059. if (sqrSinHalfTheta <= Number.EPSILON) {
  2060. var s = 1 - t;
  2061. this._w = s * w + t * this._w;
  2062. this._x = s * x + t * this._x;
  2063. this._y = s * y + t * this._y;
  2064. this._z = s * z + t * this._z;
  2065. this.normalize();
  2066. this._onChangeCallback();
  2067. return this;
  2068. }
  2069. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2070. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2071. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2072. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2073. this._w = w * ratioA + this._w * ratioB;
  2074. this._x = x * ratioA + this._x * ratioB;
  2075. this._y = y * ratioA + this._y * ratioB;
  2076. this._z = z * ratioA + this._z * ratioB;
  2077. this._onChangeCallback();
  2078. return this;
  2079. };
  2080. _proto.equals = function equals(quaternion) {
  2081. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2082. };
  2083. _proto.fromArray = function fromArray(array, offset) {
  2084. if (offset === void 0) {
  2085. offset = 0;
  2086. }
  2087. this._x = array[offset];
  2088. this._y = array[offset + 1];
  2089. this._z = array[offset + 2];
  2090. this._w = array[offset + 3];
  2091. this._onChangeCallback();
  2092. return this;
  2093. };
  2094. _proto.toArray = function toArray(array, offset) {
  2095. if (array === void 0) {
  2096. array = [];
  2097. }
  2098. if (offset === void 0) {
  2099. offset = 0;
  2100. }
  2101. array[offset] = this._x;
  2102. array[offset + 1] = this._y;
  2103. array[offset + 2] = this._z;
  2104. array[offset + 3] = this._w;
  2105. return array;
  2106. };
  2107. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2108. this._x = attribute.getX(index);
  2109. this._y = attribute.getY(index);
  2110. this._z = attribute.getZ(index);
  2111. this._w = attribute.getW(index);
  2112. return this;
  2113. };
  2114. _proto._onChange = function _onChange(callback) {
  2115. this._onChangeCallback = callback;
  2116. return this;
  2117. };
  2118. _proto._onChangeCallback = function _onChangeCallback() {};
  2119. _createClass(Quaternion, [{
  2120. key: "x",
  2121. get: function get() {
  2122. return this._x;
  2123. },
  2124. set: function set(value) {
  2125. this._x = value;
  2126. this._onChangeCallback();
  2127. }
  2128. }, {
  2129. key: "y",
  2130. get: function get() {
  2131. return this._y;
  2132. },
  2133. set: function set(value) {
  2134. this._y = value;
  2135. this._onChangeCallback();
  2136. }
  2137. }, {
  2138. key: "z",
  2139. get: function get() {
  2140. return this._z;
  2141. },
  2142. set: function set(value) {
  2143. this._z = value;
  2144. this._onChangeCallback();
  2145. }
  2146. }, {
  2147. key: "w",
  2148. get: function get() {
  2149. return this._w;
  2150. },
  2151. set: function set(value) {
  2152. this._w = value;
  2153. this._onChangeCallback();
  2154. }
  2155. }]);
  2156. return Quaternion;
  2157. }();
  2158. var Vector3 = /*#__PURE__*/function () {
  2159. function Vector3(x, y, z) {
  2160. if (x === void 0) {
  2161. x = 0;
  2162. }
  2163. if (y === void 0) {
  2164. y = 0;
  2165. }
  2166. if (z === void 0) {
  2167. z = 0;
  2168. }
  2169. Object.defineProperty(this, 'isVector3', {
  2170. value: true
  2171. });
  2172. this.x = x;
  2173. this.y = y;
  2174. this.z = z;
  2175. }
  2176. var _proto = Vector3.prototype;
  2177. _proto.set = function set(x, y, z) {
  2178. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2179. this.x = x;
  2180. this.y = y;
  2181. this.z = z;
  2182. return this;
  2183. };
  2184. _proto.setScalar = function setScalar(scalar) {
  2185. this.x = scalar;
  2186. this.y = scalar;
  2187. this.z = scalar;
  2188. return this;
  2189. };
  2190. _proto.setX = function setX(x) {
  2191. this.x = x;
  2192. return this;
  2193. };
  2194. _proto.setY = function setY(y) {
  2195. this.y = y;
  2196. return this;
  2197. };
  2198. _proto.setZ = function setZ(z) {
  2199. this.z = z;
  2200. return this;
  2201. };
  2202. _proto.setComponent = function setComponent(index, value) {
  2203. switch (index) {
  2204. case 0:
  2205. this.x = value;
  2206. break;
  2207. case 1:
  2208. this.y = value;
  2209. break;
  2210. case 2:
  2211. this.z = value;
  2212. break;
  2213. default:
  2214. throw new Error('index is out of range: ' + index);
  2215. }
  2216. return this;
  2217. };
  2218. _proto.getComponent = function getComponent(index) {
  2219. switch (index) {
  2220. case 0:
  2221. return this.x;
  2222. case 1:
  2223. return this.y;
  2224. case 2:
  2225. return this.z;
  2226. default:
  2227. throw new Error('index is out of range: ' + index);
  2228. }
  2229. };
  2230. _proto.clone = function clone() {
  2231. return new this.constructor(this.x, this.y, this.z);
  2232. };
  2233. _proto.copy = function copy(v) {
  2234. this.x = v.x;
  2235. this.y = v.y;
  2236. this.z = v.z;
  2237. return this;
  2238. };
  2239. _proto.add = function add(v, w) {
  2240. if (w !== undefined) {
  2241. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2242. return this.addVectors(v, w);
  2243. }
  2244. this.x += v.x;
  2245. this.y += v.y;
  2246. this.z += v.z;
  2247. return this;
  2248. };
  2249. _proto.addScalar = function addScalar(s) {
  2250. this.x += s;
  2251. this.y += s;
  2252. this.z += s;
  2253. return this;
  2254. };
  2255. _proto.addVectors = function addVectors(a, b) {
  2256. this.x = a.x + b.x;
  2257. this.y = a.y + b.y;
  2258. this.z = a.z + b.z;
  2259. return this;
  2260. };
  2261. _proto.addScaledVector = function addScaledVector(v, s) {
  2262. this.x += v.x * s;
  2263. this.y += v.y * s;
  2264. this.z += v.z * s;
  2265. return this;
  2266. };
  2267. _proto.sub = function sub(v, w) {
  2268. if (w !== undefined) {
  2269. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2270. return this.subVectors(v, w);
  2271. }
  2272. this.x -= v.x;
  2273. this.y -= v.y;
  2274. this.z -= v.z;
  2275. return this;
  2276. };
  2277. _proto.subScalar = function subScalar(s) {
  2278. this.x -= s;
  2279. this.y -= s;
  2280. this.z -= s;
  2281. return this;
  2282. };
  2283. _proto.subVectors = function subVectors(a, b) {
  2284. this.x = a.x - b.x;
  2285. this.y = a.y - b.y;
  2286. this.z = a.z - b.z;
  2287. return this;
  2288. };
  2289. _proto.multiply = function multiply(v, w) {
  2290. if (w !== undefined) {
  2291. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2292. return this.multiplyVectors(v, w);
  2293. }
  2294. this.x *= v.x;
  2295. this.y *= v.y;
  2296. this.z *= v.z;
  2297. return this;
  2298. };
  2299. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2300. this.x *= scalar;
  2301. this.y *= scalar;
  2302. this.z *= scalar;
  2303. return this;
  2304. };
  2305. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2306. this.x = a.x * b.x;
  2307. this.y = a.y * b.y;
  2308. this.z = a.z * b.z;
  2309. return this;
  2310. };
  2311. _proto.applyEuler = function applyEuler(euler) {
  2312. if (!(euler && euler.isEuler)) {
  2313. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2314. }
  2315. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2316. };
  2317. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2318. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2319. };
  2320. _proto.applyMatrix3 = function applyMatrix3(m) {
  2321. var x = this.x,
  2322. y = this.y,
  2323. z = this.z;
  2324. var e = m.elements;
  2325. this.x = e[0] * x + e[3] * y + e[6] * z;
  2326. this.y = e[1] * x + e[4] * y + e[7] * z;
  2327. this.z = e[2] * x + e[5] * y + e[8] * z;
  2328. return this;
  2329. };
  2330. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2331. return this.applyMatrix3(m).normalize();
  2332. };
  2333. _proto.applyMatrix4 = function applyMatrix4(m) {
  2334. var x = this.x,
  2335. y = this.y,
  2336. z = this.z;
  2337. var e = m.elements;
  2338. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2339. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2340. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2341. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2342. return this;
  2343. };
  2344. _proto.applyQuaternion = function applyQuaternion(q) {
  2345. var x = this.x,
  2346. y = this.y,
  2347. z = this.z;
  2348. var qx = q.x,
  2349. qy = q.y,
  2350. qz = q.z,
  2351. qw = q.w; // calculate quat * vector
  2352. var ix = qw * x + qy * z - qz * y;
  2353. var iy = qw * y + qz * x - qx * z;
  2354. var iz = qw * z + qx * y - qy * x;
  2355. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2356. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2357. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2358. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2359. return this;
  2360. };
  2361. _proto.project = function project(camera) {
  2362. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2363. };
  2364. _proto.unproject = function unproject(camera) {
  2365. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2366. };
  2367. _proto.transformDirection = function transformDirection(m) {
  2368. // input: THREE.Matrix4 affine matrix
  2369. // vector interpreted as a direction
  2370. var x = this.x,
  2371. y = this.y,
  2372. z = this.z;
  2373. var e = m.elements;
  2374. this.x = e[0] * x + e[4] * y + e[8] * z;
  2375. this.y = e[1] * x + e[5] * y + e[9] * z;
  2376. this.z = e[2] * x + e[6] * y + e[10] * z;
  2377. return this.normalize();
  2378. };
  2379. _proto.divide = function divide(v) {
  2380. this.x /= v.x;
  2381. this.y /= v.y;
  2382. this.z /= v.z;
  2383. return this;
  2384. };
  2385. _proto.divideScalar = function divideScalar(scalar) {
  2386. return this.multiplyScalar(1 / scalar);
  2387. };
  2388. _proto.min = function min(v) {
  2389. this.x = Math.min(this.x, v.x);
  2390. this.y = Math.min(this.y, v.y);
  2391. this.z = Math.min(this.z, v.z);
  2392. return this;
  2393. };
  2394. _proto.max = function max(v) {
  2395. this.x = Math.max(this.x, v.x);
  2396. this.y = Math.max(this.y, v.y);
  2397. this.z = Math.max(this.z, v.z);
  2398. return this;
  2399. };
  2400. _proto.clamp = function clamp(min, max) {
  2401. // assumes min < max, componentwise
  2402. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2403. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2404. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2405. return this;
  2406. };
  2407. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2408. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2409. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2410. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2411. return this;
  2412. };
  2413. _proto.clampLength = function clampLength(min, max) {
  2414. var length = this.length();
  2415. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2416. };
  2417. _proto.floor = function floor() {
  2418. this.x = Math.floor(this.x);
  2419. this.y = Math.floor(this.y);
  2420. this.z = Math.floor(this.z);
  2421. return this;
  2422. };
  2423. _proto.ceil = function ceil() {
  2424. this.x = Math.ceil(this.x);
  2425. this.y = Math.ceil(this.y);
  2426. this.z = Math.ceil(this.z);
  2427. return this;
  2428. };
  2429. _proto.round = function round() {
  2430. this.x = Math.round(this.x);
  2431. this.y = Math.round(this.y);
  2432. this.z = Math.round(this.z);
  2433. return this;
  2434. };
  2435. _proto.roundToZero = function roundToZero() {
  2436. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2437. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2438. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2439. return this;
  2440. };
  2441. _proto.negate = function negate() {
  2442. this.x = -this.x;
  2443. this.y = -this.y;
  2444. this.z = -this.z;
  2445. return this;
  2446. };
  2447. _proto.dot = function dot(v) {
  2448. return this.x * v.x + this.y * v.y + this.z * v.z;
  2449. } // TODO lengthSquared?
  2450. ;
  2451. _proto.lengthSq = function lengthSq() {
  2452. return this.x * this.x + this.y * this.y + this.z * this.z;
  2453. };
  2454. _proto.length = function length() {
  2455. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2456. };
  2457. _proto.manhattanLength = function manhattanLength() {
  2458. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2459. };
  2460. _proto.normalize = function normalize() {
  2461. return this.divideScalar(this.length() || 1);
  2462. };
  2463. _proto.setLength = function setLength(length) {
  2464. return this.normalize().multiplyScalar(length);
  2465. };
  2466. _proto.lerp = function lerp(v, alpha) {
  2467. this.x += (v.x - this.x) * alpha;
  2468. this.y += (v.y - this.y) * alpha;
  2469. this.z += (v.z - this.z) * alpha;
  2470. return this;
  2471. };
  2472. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2473. this.x = v1.x + (v2.x - v1.x) * alpha;
  2474. this.y = v1.y + (v2.y - v1.y) * alpha;
  2475. this.z = v1.z + (v2.z - v1.z) * alpha;
  2476. return this;
  2477. };
  2478. _proto.cross = function cross(v, w) {
  2479. if (w !== undefined) {
  2480. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2481. return this.crossVectors(v, w);
  2482. }
  2483. return this.crossVectors(this, v);
  2484. };
  2485. _proto.crossVectors = function crossVectors(a, b) {
  2486. var ax = a.x,
  2487. ay = a.y,
  2488. az = a.z;
  2489. var bx = b.x,
  2490. by = b.y,
  2491. bz = b.z;
  2492. this.x = ay * bz - az * by;
  2493. this.y = az * bx - ax * bz;
  2494. this.z = ax * by - ay * bx;
  2495. return this;
  2496. };
  2497. _proto.projectOnVector = function projectOnVector(v) {
  2498. var denominator = v.lengthSq();
  2499. if (denominator === 0) return this.set(0, 0, 0);
  2500. var scalar = v.dot(this) / denominator;
  2501. return this.copy(v).multiplyScalar(scalar);
  2502. };
  2503. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2504. _vector.copy(this).projectOnVector(planeNormal);
  2505. return this.sub(_vector);
  2506. };
  2507. _proto.reflect = function reflect(normal) {
  2508. // reflect incident vector off plane orthogonal to normal
  2509. // normal is assumed to have unit length
  2510. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2511. };
  2512. _proto.angleTo = function angleTo(v) {
  2513. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2514. if (denominator === 0) return Math.PI / 2;
  2515. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2516. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2517. };
  2518. _proto.distanceTo = function distanceTo(v) {
  2519. return Math.sqrt(this.distanceToSquared(v));
  2520. };
  2521. _proto.distanceToSquared = function distanceToSquared(v) {
  2522. var dx = this.x - v.x,
  2523. dy = this.y - v.y,
  2524. dz = this.z - v.z;
  2525. return dx * dx + dy * dy + dz * dz;
  2526. };
  2527. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2528. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2529. };
  2530. _proto.setFromSpherical = function setFromSpherical(s) {
  2531. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2532. };
  2533. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2534. var sinPhiRadius = Math.sin(phi) * radius;
  2535. this.x = sinPhiRadius * Math.sin(theta);
  2536. this.y = Math.cos(phi) * radius;
  2537. this.z = sinPhiRadius * Math.cos(theta);
  2538. return this;
  2539. };
  2540. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2541. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2542. };
  2543. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2544. this.x = radius * Math.sin(theta);
  2545. this.y = y;
  2546. this.z = radius * Math.cos(theta);
  2547. return this;
  2548. };
  2549. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2550. var e = m.elements;
  2551. this.x = e[12];
  2552. this.y = e[13];
  2553. this.z = e[14];
  2554. return this;
  2555. };
  2556. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2557. var sx = this.setFromMatrixColumn(m, 0).length();
  2558. var sy = this.setFromMatrixColumn(m, 1).length();
  2559. var sz = this.setFromMatrixColumn(m, 2).length();
  2560. this.x = sx;
  2561. this.y = sy;
  2562. this.z = sz;
  2563. return this;
  2564. };
  2565. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2566. return this.fromArray(m.elements, index * 4);
  2567. };
  2568. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2569. return this.fromArray(m.elements, index * 3);
  2570. };
  2571. _proto.equals = function equals(v) {
  2572. return v.x === this.x && v.y === this.y && v.z === this.z;
  2573. };
  2574. _proto.fromArray = function fromArray(array, offset) {
  2575. if (offset === void 0) {
  2576. offset = 0;
  2577. }
  2578. this.x = array[offset];
  2579. this.y = array[offset + 1];
  2580. this.z = array[offset + 2];
  2581. return this;
  2582. };
  2583. _proto.toArray = function toArray(array, offset) {
  2584. if (array === void 0) {
  2585. array = [];
  2586. }
  2587. if (offset === void 0) {
  2588. offset = 0;
  2589. }
  2590. array[offset] = this.x;
  2591. array[offset + 1] = this.y;
  2592. array[offset + 2] = this.z;
  2593. return array;
  2594. };
  2595. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2596. if (offset !== undefined) {
  2597. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2598. }
  2599. this.x = attribute.getX(index);
  2600. this.y = attribute.getY(index);
  2601. this.z = attribute.getZ(index);
  2602. return this;
  2603. };
  2604. _proto.random = function random() {
  2605. this.x = Math.random();
  2606. this.y = Math.random();
  2607. this.z = Math.random();
  2608. return this;
  2609. };
  2610. return Vector3;
  2611. }();
  2612. var _vector = /*@__PURE__*/new Vector3();
  2613. var _quaternion = /*@__PURE__*/new Quaternion();
  2614. var Box3 = /*#__PURE__*/function () {
  2615. function Box3(min, max) {
  2616. Object.defineProperty(this, 'isBox3', {
  2617. value: true
  2618. });
  2619. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2620. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2621. }
  2622. var _proto = Box3.prototype;
  2623. _proto.set = function set(min, max) {
  2624. this.min.copy(min);
  2625. this.max.copy(max);
  2626. return this;
  2627. };
  2628. _proto.setFromArray = function setFromArray(array) {
  2629. var minX = +Infinity;
  2630. var minY = +Infinity;
  2631. var minZ = +Infinity;
  2632. var maxX = -Infinity;
  2633. var maxY = -Infinity;
  2634. var maxZ = -Infinity;
  2635. for (var i = 0, l = array.length; i < l; i += 3) {
  2636. var x = array[i];
  2637. var y = array[i + 1];
  2638. var z = array[i + 2];
  2639. if (x < minX) minX = x;
  2640. if (y < minY) minY = y;
  2641. if (z < minZ) minZ = z;
  2642. if (x > maxX) maxX = x;
  2643. if (y > maxY) maxY = y;
  2644. if (z > maxZ) maxZ = z;
  2645. }
  2646. this.min.set(minX, minY, minZ);
  2647. this.max.set(maxX, maxY, maxZ);
  2648. return this;
  2649. };
  2650. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2651. var minX = +Infinity;
  2652. var minY = +Infinity;
  2653. var minZ = +Infinity;
  2654. var maxX = -Infinity;
  2655. var maxY = -Infinity;
  2656. var maxZ = -Infinity;
  2657. for (var i = 0, l = attribute.count; i < l; i++) {
  2658. var x = attribute.getX(i);
  2659. var y = attribute.getY(i);
  2660. var z = attribute.getZ(i);
  2661. if (x < minX) minX = x;
  2662. if (y < minY) minY = y;
  2663. if (z < minZ) minZ = z;
  2664. if (x > maxX) maxX = x;
  2665. if (y > maxY) maxY = y;
  2666. if (z > maxZ) maxZ = z;
  2667. }
  2668. this.min.set(minX, minY, minZ);
  2669. this.max.set(maxX, maxY, maxZ);
  2670. return this;
  2671. };
  2672. _proto.setFromPoints = function setFromPoints(points) {
  2673. this.makeEmpty();
  2674. for (var i = 0, il = points.length; i < il; i++) {
  2675. this.expandByPoint(points[i]);
  2676. }
  2677. return this;
  2678. };
  2679. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2680. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2681. this.min.copy(center).sub(halfSize);
  2682. this.max.copy(center).add(halfSize);
  2683. return this;
  2684. };
  2685. _proto.setFromObject = function setFromObject(object) {
  2686. this.makeEmpty();
  2687. return this.expandByObject(object);
  2688. };
  2689. _proto.clone = function clone() {
  2690. return new this.constructor().copy(this);
  2691. };
  2692. _proto.copy = function copy(box) {
  2693. this.min.copy(box.min);
  2694. this.max.copy(box.max);
  2695. return this;
  2696. };
  2697. _proto.makeEmpty = function makeEmpty() {
  2698. this.min.x = this.min.y = this.min.z = +Infinity;
  2699. this.max.x = this.max.y = this.max.z = -Infinity;
  2700. return this;
  2701. };
  2702. _proto.isEmpty = function isEmpty() {
  2703. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2704. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2705. };
  2706. _proto.getCenter = function getCenter(target) {
  2707. if (target === undefined) {
  2708. console.warn('THREE.Box3: .getCenter() target is now required');
  2709. target = new Vector3();
  2710. }
  2711. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2712. };
  2713. _proto.getSize = function getSize(target) {
  2714. if (target === undefined) {
  2715. console.warn('THREE.Box3: .getSize() target is now required');
  2716. target = new Vector3();
  2717. }
  2718. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2719. };
  2720. _proto.expandByPoint = function expandByPoint(point) {
  2721. this.min.min(point);
  2722. this.max.max(point);
  2723. return this;
  2724. };
  2725. _proto.expandByVector = function expandByVector(vector) {
  2726. this.min.sub(vector);
  2727. this.max.add(vector);
  2728. return this;
  2729. };
  2730. _proto.expandByScalar = function expandByScalar(scalar) {
  2731. this.min.addScalar(-scalar);
  2732. this.max.addScalar(scalar);
  2733. return this;
  2734. };
  2735. _proto.expandByObject = function expandByObject(object) {
  2736. // Computes the world-axis-aligned bounding box of an object (including its children),
  2737. // accounting for both the object's, and children's, world transforms
  2738. object.updateWorldMatrix(false, false);
  2739. var geometry = object.geometry;
  2740. if (geometry !== undefined) {
  2741. if (geometry.boundingBox === null) {
  2742. geometry.computeBoundingBox();
  2743. }
  2744. _box.copy(geometry.boundingBox);
  2745. _box.applyMatrix4(object.matrixWorld);
  2746. this.union(_box);
  2747. }
  2748. var children = object.children;
  2749. for (var i = 0, l = children.length; i < l; i++) {
  2750. this.expandByObject(children[i]);
  2751. }
  2752. return this;
  2753. };
  2754. _proto.containsPoint = function containsPoint(point) {
  2755. 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;
  2756. };
  2757. _proto.containsBox = function containsBox(box) {
  2758. 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;
  2759. };
  2760. _proto.getParameter = function getParameter(point, target) {
  2761. // This can potentially have a divide by zero if the box
  2762. // has a size dimension of 0.
  2763. if (target === undefined) {
  2764. console.warn('THREE.Box3: .getParameter() target is now required');
  2765. target = new Vector3();
  2766. }
  2767. 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));
  2768. };
  2769. _proto.intersectsBox = function intersectsBox(box) {
  2770. // using 6 splitting planes to rule out intersections.
  2771. 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;
  2772. };
  2773. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2774. // Find the point on the AABB closest to the sphere center.
  2775. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2776. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2777. };
  2778. _proto.intersectsPlane = function intersectsPlane(plane) {
  2779. // We compute the minimum and maximum dot product values. If those values
  2780. // are on the same side (back or front) of the plane, then there is no intersection.
  2781. var min, max;
  2782. if (plane.normal.x > 0) {
  2783. min = plane.normal.x * this.min.x;
  2784. max = plane.normal.x * this.max.x;
  2785. } else {
  2786. min = plane.normal.x * this.max.x;
  2787. max = plane.normal.x * this.min.x;
  2788. }
  2789. if (plane.normal.y > 0) {
  2790. min += plane.normal.y * this.min.y;
  2791. max += plane.normal.y * this.max.y;
  2792. } else {
  2793. min += plane.normal.y * this.max.y;
  2794. max += plane.normal.y * this.min.y;
  2795. }
  2796. if (plane.normal.z > 0) {
  2797. min += plane.normal.z * this.min.z;
  2798. max += plane.normal.z * this.max.z;
  2799. } else {
  2800. min += plane.normal.z * this.max.z;
  2801. max += plane.normal.z * this.min.z;
  2802. }
  2803. return min <= -plane.constant && max >= -plane.constant;
  2804. };
  2805. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2806. if (this.isEmpty()) {
  2807. return false;
  2808. } // compute box center and extents
  2809. this.getCenter(_center);
  2810. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2811. _v0.subVectors(triangle.a, _center);
  2812. _v1.subVectors(triangle.b, _center);
  2813. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2814. _f0.subVectors(_v1, _v0);
  2815. _f1.subVectors(_v2, _v1);
  2816. _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
  2817. // 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
  2818. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2819. 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];
  2820. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2821. return false;
  2822. } // test 3 face normals from the aabb
  2823. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2824. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2825. return false;
  2826. } // finally testing the face normal of the triangle
  2827. // use already existing triangle edge vectors here
  2828. _triangleNormal.crossVectors(_f0, _f1);
  2829. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2830. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2831. };
  2832. _proto.clampPoint = function clampPoint(point, target) {
  2833. if (target === undefined) {
  2834. console.warn('THREE.Box3: .clampPoint() target is now required');
  2835. target = new Vector3();
  2836. }
  2837. return target.copy(point).clamp(this.min, this.max);
  2838. };
  2839. _proto.distanceToPoint = function distanceToPoint(point) {
  2840. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2841. return clampedPoint.sub(point).length();
  2842. };
  2843. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2844. if (target === undefined) {
  2845. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2846. }
  2847. this.getCenter(target.center);
  2848. target.radius = this.getSize(_vector$1).length() * 0.5;
  2849. return target;
  2850. };
  2851. _proto.intersect = function intersect(box) {
  2852. this.min.max(box.min);
  2853. 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.
  2854. if (this.isEmpty()) this.makeEmpty();
  2855. return this;
  2856. };
  2857. _proto.union = function union(box) {
  2858. this.min.min(box.min);
  2859. this.max.max(box.max);
  2860. return this;
  2861. };
  2862. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2863. // transform of empty box is an empty box.
  2864. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2865. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2866. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2867. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2868. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2869. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2870. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2871. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2872. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2873. this.setFromPoints(_points);
  2874. return this;
  2875. };
  2876. _proto.translate = function translate(offset) {
  2877. this.min.add(offset);
  2878. this.max.add(offset);
  2879. return this;
  2880. };
  2881. _proto.equals = function equals(box) {
  2882. return box.min.equals(this.min) && box.max.equals(this.max);
  2883. };
  2884. return Box3;
  2885. }();
  2886. function satForAxes(axes, v0, v1, v2, extents) {
  2887. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2888. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2889. 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
  2890. var p0 = v0.dot(_testAxis);
  2891. var p1 = v1.dot(_testAxis);
  2892. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2893. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2894. // points of the projected triangle are outside the projected half-length of the aabb
  2895. // the axis is seperating and we can exit
  2896. return false;
  2897. }
  2898. }
  2899. return true;
  2900. }
  2901. 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()];
  2902. var _vector$1 = /*@__PURE__*/new Vector3();
  2903. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2904. var _v0 = /*@__PURE__*/new Vector3();
  2905. var _v1 = /*@__PURE__*/new Vector3();
  2906. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2907. var _f0 = /*@__PURE__*/new Vector3();
  2908. var _f1 = /*@__PURE__*/new Vector3();
  2909. var _f2 = /*@__PURE__*/new Vector3();
  2910. var _center = /*@__PURE__*/new Vector3();
  2911. var _extents = /*@__PURE__*/new Vector3();
  2912. var _triangleNormal = /*@__PURE__*/new Vector3();
  2913. var _testAxis = /*@__PURE__*/new Vector3();
  2914. var _box$1 = /*@__PURE__*/new Box3();
  2915. var Sphere = /*#__PURE__*/function () {
  2916. function Sphere(center, radius) {
  2917. this.center = center !== undefined ? center : new Vector3();
  2918. this.radius = radius !== undefined ? radius : -1;
  2919. }
  2920. var _proto = Sphere.prototype;
  2921. _proto.set = function set(center, radius) {
  2922. this.center.copy(center);
  2923. this.radius = radius;
  2924. return this;
  2925. };
  2926. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2927. var center = this.center;
  2928. if (optionalCenter !== undefined) {
  2929. center.copy(optionalCenter);
  2930. } else {
  2931. _box$1.setFromPoints(points).getCenter(center);
  2932. }
  2933. var maxRadiusSq = 0;
  2934. for (var i = 0, il = points.length; i < il; i++) {
  2935. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2936. }
  2937. this.radius = Math.sqrt(maxRadiusSq);
  2938. return this;
  2939. };
  2940. _proto.clone = function clone() {
  2941. return new this.constructor().copy(this);
  2942. };
  2943. _proto.copy = function copy(sphere) {
  2944. this.center.copy(sphere.center);
  2945. this.radius = sphere.radius;
  2946. return this;
  2947. };
  2948. _proto.isEmpty = function isEmpty() {
  2949. return this.radius < 0;
  2950. };
  2951. _proto.makeEmpty = function makeEmpty() {
  2952. this.center.set(0, 0, 0);
  2953. this.radius = -1;
  2954. return this;
  2955. };
  2956. _proto.containsPoint = function containsPoint(point) {
  2957. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  2958. };
  2959. _proto.distanceToPoint = function distanceToPoint(point) {
  2960. return point.distanceTo(this.center) - this.radius;
  2961. };
  2962. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2963. var radiusSum = this.radius + sphere.radius;
  2964. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  2965. };
  2966. _proto.intersectsBox = function intersectsBox(box) {
  2967. return box.intersectsSphere(this);
  2968. };
  2969. _proto.intersectsPlane = function intersectsPlane(plane) {
  2970. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  2971. };
  2972. _proto.clampPoint = function clampPoint(point, target) {
  2973. var deltaLengthSq = this.center.distanceToSquared(point);
  2974. if (target === undefined) {
  2975. console.warn('THREE.Sphere: .clampPoint() target is now required');
  2976. target = new Vector3();
  2977. }
  2978. target.copy(point);
  2979. if (deltaLengthSq > this.radius * this.radius) {
  2980. target.sub(this.center).normalize();
  2981. target.multiplyScalar(this.radius).add(this.center);
  2982. }
  2983. return target;
  2984. };
  2985. _proto.getBoundingBox = function getBoundingBox(target) {
  2986. if (target === undefined) {
  2987. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  2988. target = new Box3();
  2989. }
  2990. if (this.isEmpty()) {
  2991. // Empty sphere produces empty bounding box
  2992. target.makeEmpty();
  2993. return target;
  2994. }
  2995. target.set(this.center, this.center);
  2996. target.expandByScalar(this.radius);
  2997. return target;
  2998. };
  2999. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3000. this.center.applyMatrix4(matrix);
  3001. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3002. return this;
  3003. };
  3004. _proto.translate = function translate(offset) {
  3005. this.center.add(offset);
  3006. return this;
  3007. };
  3008. _proto.equals = function equals(sphere) {
  3009. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3010. };
  3011. return Sphere;
  3012. }();
  3013. var _vector$2 = /*@__PURE__*/new Vector3();
  3014. var _segCenter = /*@__PURE__*/new Vector3();
  3015. var _segDir = /*@__PURE__*/new Vector3();
  3016. var _diff = /*@__PURE__*/new Vector3();
  3017. var _edge1 = /*@__PURE__*/new Vector3();
  3018. var _edge2 = /*@__PURE__*/new Vector3();
  3019. var _normal = /*@__PURE__*/new Vector3();
  3020. var Ray = /*#__PURE__*/function () {
  3021. function Ray(origin, direction) {
  3022. this.origin = origin !== undefined ? origin : new Vector3();
  3023. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3024. }
  3025. var _proto = Ray.prototype;
  3026. _proto.set = function set(origin, direction) {
  3027. this.origin.copy(origin);
  3028. this.direction.copy(direction);
  3029. return this;
  3030. };
  3031. _proto.clone = function clone() {
  3032. return new this.constructor().copy(this);
  3033. };
  3034. _proto.copy = function copy(ray) {
  3035. this.origin.copy(ray.origin);
  3036. this.direction.copy(ray.direction);
  3037. return this;
  3038. };
  3039. _proto.at = function at(t, target) {
  3040. if (target === undefined) {
  3041. console.warn('THREE.Ray: .at() target is now required');
  3042. target = new Vector3();
  3043. }
  3044. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3045. };
  3046. _proto.lookAt = function lookAt(v) {
  3047. this.direction.copy(v).sub(this.origin).normalize();
  3048. return this;
  3049. };
  3050. _proto.recast = function recast(t) {
  3051. this.origin.copy(this.at(t, _vector$2));
  3052. return this;
  3053. };
  3054. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3055. if (target === undefined) {
  3056. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3057. target = new Vector3();
  3058. }
  3059. target.subVectors(point, this.origin);
  3060. var directionDistance = target.dot(this.direction);
  3061. if (directionDistance < 0) {
  3062. return target.copy(this.origin);
  3063. }
  3064. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3065. };
  3066. _proto.distanceToPoint = function distanceToPoint(point) {
  3067. return Math.sqrt(this.distanceSqToPoint(point));
  3068. };
  3069. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3070. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3071. if (directionDistance < 0) {
  3072. return this.origin.distanceToSquared(point);
  3073. }
  3074. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3075. return _vector$2.distanceToSquared(point);
  3076. };
  3077. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3078. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3079. // It returns the min distance between the ray and the segment
  3080. // defined by v0 and v1
  3081. // It can also set two optional targets :
  3082. // - The closest point on the ray
  3083. // - The closest point on the segment
  3084. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3085. _segDir.copy(v1).sub(v0).normalize();
  3086. _diff.copy(this.origin).sub(_segCenter);
  3087. var segExtent = v0.distanceTo(v1) * 0.5;
  3088. var a01 = -this.direction.dot(_segDir);
  3089. var b0 = _diff.dot(this.direction);
  3090. var b1 = -_diff.dot(_segDir);
  3091. var c = _diff.lengthSq();
  3092. var det = Math.abs(1 - a01 * a01);
  3093. var s0, s1, sqrDist, extDet;
  3094. if (det > 0) {
  3095. // The ray and segment are not parallel.
  3096. s0 = a01 * b1 - b0;
  3097. s1 = a01 * b0 - b1;
  3098. extDet = segExtent * det;
  3099. if (s0 >= 0) {
  3100. if (s1 >= -extDet) {
  3101. if (s1 <= extDet) {
  3102. // region 0
  3103. // Minimum at interior points of ray and segment.
  3104. var invDet = 1 / det;
  3105. s0 *= invDet;
  3106. s1 *= invDet;
  3107. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3108. } else {
  3109. // region 1
  3110. s1 = segExtent;
  3111. s0 = Math.max(0, -(a01 * s1 + b0));
  3112. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3113. }
  3114. } else {
  3115. // region 5
  3116. s1 = -segExtent;
  3117. s0 = Math.max(0, -(a01 * s1 + b0));
  3118. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3119. }
  3120. } else {
  3121. if (s1 <= -extDet) {
  3122. // region 4
  3123. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3124. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3125. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3126. } else if (s1 <= extDet) {
  3127. // region 3
  3128. s0 = 0;
  3129. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3130. sqrDist = s1 * (s1 + 2 * b1) + c;
  3131. } else {
  3132. // region 2
  3133. s0 = Math.max(0, -(a01 * segExtent + b0));
  3134. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3135. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3136. }
  3137. }
  3138. } else {
  3139. // Ray and segment are parallel.
  3140. s1 = a01 > 0 ? -segExtent : segExtent;
  3141. s0 = Math.max(0, -(a01 * s1 + b0));
  3142. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3143. }
  3144. if (optionalPointOnRay) {
  3145. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3146. }
  3147. if (optionalPointOnSegment) {
  3148. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3149. }
  3150. return sqrDist;
  3151. };
  3152. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3153. _vector$2.subVectors(sphere.center, this.origin);
  3154. var tca = _vector$2.dot(this.direction);
  3155. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3156. var radius2 = sphere.radius * sphere.radius;
  3157. if (d2 > radius2) return null;
  3158. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3159. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3160. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3161. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3162. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3163. // in order to always return an intersect point that is in front of the ray.
  3164. 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
  3165. return this.at(t0, target);
  3166. };
  3167. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3168. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3169. };
  3170. _proto.distanceToPlane = function distanceToPlane(plane) {
  3171. var denominator = plane.normal.dot(this.direction);
  3172. if (denominator === 0) {
  3173. // line is coplanar, return origin
  3174. if (plane.distanceToPoint(this.origin) === 0) {
  3175. return 0;
  3176. } // Null is preferable to undefined since undefined means.... it is undefined
  3177. return null;
  3178. }
  3179. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3180. return t >= 0 ? t : null;
  3181. };
  3182. _proto.intersectPlane = function intersectPlane(plane, target) {
  3183. var t = this.distanceToPlane(plane);
  3184. if (t === null) {
  3185. return null;
  3186. }
  3187. return this.at(t, target);
  3188. };
  3189. _proto.intersectsPlane = function intersectsPlane(plane) {
  3190. // check if the ray lies on the plane first
  3191. var distToPoint = plane.distanceToPoint(this.origin);
  3192. if (distToPoint === 0) {
  3193. return true;
  3194. }
  3195. var denominator = plane.normal.dot(this.direction);
  3196. if (denominator * distToPoint < 0) {
  3197. return true;
  3198. } // ray origin is behind the plane (and is pointing behind it)
  3199. return false;
  3200. };
  3201. _proto.intersectBox = function intersectBox(box, target) {
  3202. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3203. var invdirx = 1 / this.direction.x,
  3204. invdiry = 1 / this.direction.y,
  3205. invdirz = 1 / this.direction.z;
  3206. var origin = this.origin;
  3207. if (invdirx >= 0) {
  3208. tmin = (box.min.x - origin.x) * invdirx;
  3209. tmax = (box.max.x - origin.x) * invdirx;
  3210. } else {
  3211. tmin = (box.max.x - origin.x) * invdirx;
  3212. tmax = (box.min.x - origin.x) * invdirx;
  3213. }
  3214. if (invdiry >= 0) {
  3215. tymin = (box.min.y - origin.y) * invdiry;
  3216. tymax = (box.max.y - origin.y) * invdiry;
  3217. } else {
  3218. tymin = (box.max.y - origin.y) * invdiry;
  3219. tymax = (box.min.y - origin.y) * invdiry;
  3220. }
  3221. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3222. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3223. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3224. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3225. if (invdirz >= 0) {
  3226. tzmin = (box.min.z - origin.z) * invdirz;
  3227. tzmax = (box.max.z - origin.z) * invdirz;
  3228. } else {
  3229. tzmin = (box.max.z - origin.z) * invdirz;
  3230. tzmax = (box.min.z - origin.z) * invdirz;
  3231. }
  3232. if (tmin > tzmax || tzmin > tmax) return null;
  3233. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3234. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3235. if (tmax < 0) return null;
  3236. return this.at(tmin >= 0 ? tmin : tmax, target);
  3237. };
  3238. _proto.intersectsBox = function intersectsBox(box) {
  3239. return this.intersectBox(box, _vector$2) !== null;
  3240. };
  3241. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3242. // Compute the offset origin, edges, and normal.
  3243. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3244. _edge1.subVectors(b, a);
  3245. _edge2.subVectors(c, a);
  3246. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3247. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3248. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3249. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3250. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3251. var DdN = this.direction.dot(_normal);
  3252. var sign;
  3253. if (DdN > 0) {
  3254. if (backfaceCulling) return null;
  3255. sign = 1;
  3256. } else if (DdN < 0) {
  3257. sign = -1;
  3258. DdN = -DdN;
  3259. } else {
  3260. return null;
  3261. }
  3262. _diff.subVectors(this.origin, a);
  3263. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3264. if (DdQxE2 < 0) {
  3265. return null;
  3266. }
  3267. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3268. if (DdE1xQ < 0) {
  3269. return null;
  3270. } // b1+b2 > 1, no intersection
  3271. if (DdQxE2 + DdE1xQ > DdN) {
  3272. return null;
  3273. } // Line intersects triangle, check if ray does.
  3274. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3275. if (QdN < 0) {
  3276. return null;
  3277. } // Ray intersects triangle.
  3278. return this.at(QdN / DdN, target);
  3279. };
  3280. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3281. this.origin.applyMatrix4(matrix4);
  3282. this.direction.transformDirection(matrix4);
  3283. return this;
  3284. };
  3285. _proto.equals = function equals(ray) {
  3286. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3287. };
  3288. return Ray;
  3289. }();
  3290. var Matrix4 = /*#__PURE__*/function () {
  3291. function Matrix4() {
  3292. Object.defineProperty(this, 'isMatrix4', {
  3293. value: true
  3294. });
  3295. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3296. if (arguments.length > 0) {
  3297. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3298. }
  3299. }
  3300. var _proto = Matrix4.prototype;
  3301. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3302. var te = this.elements;
  3303. te[0] = n11;
  3304. te[4] = n12;
  3305. te[8] = n13;
  3306. te[12] = n14;
  3307. te[1] = n21;
  3308. te[5] = n22;
  3309. te[9] = n23;
  3310. te[13] = n24;
  3311. te[2] = n31;
  3312. te[6] = n32;
  3313. te[10] = n33;
  3314. te[14] = n34;
  3315. te[3] = n41;
  3316. te[7] = n42;
  3317. te[11] = n43;
  3318. te[15] = n44;
  3319. return this;
  3320. };
  3321. _proto.identity = function identity() {
  3322. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3323. return this;
  3324. };
  3325. _proto.clone = function clone() {
  3326. return new Matrix4().fromArray(this.elements);
  3327. };
  3328. _proto.copy = function copy(m) {
  3329. var te = this.elements;
  3330. var me = m.elements;
  3331. te[0] = me[0];
  3332. te[1] = me[1];
  3333. te[2] = me[2];
  3334. te[3] = me[3];
  3335. te[4] = me[4];
  3336. te[5] = me[5];
  3337. te[6] = me[6];
  3338. te[7] = me[7];
  3339. te[8] = me[8];
  3340. te[9] = me[9];
  3341. te[10] = me[10];
  3342. te[11] = me[11];
  3343. te[12] = me[12];
  3344. te[13] = me[13];
  3345. te[14] = me[14];
  3346. te[15] = me[15];
  3347. return this;
  3348. };
  3349. _proto.copyPosition = function copyPosition(m) {
  3350. var te = this.elements,
  3351. me = m.elements;
  3352. te[12] = me[12];
  3353. te[13] = me[13];
  3354. te[14] = me[14];
  3355. return this;
  3356. };
  3357. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3358. xAxis.setFromMatrixColumn(this, 0);
  3359. yAxis.setFromMatrixColumn(this, 1);
  3360. zAxis.setFromMatrixColumn(this, 2);
  3361. return this;
  3362. };
  3363. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3364. 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);
  3365. return this;
  3366. };
  3367. _proto.extractRotation = function extractRotation(m) {
  3368. // this method does not support reflection matrices
  3369. var te = this.elements;
  3370. var me = m.elements;
  3371. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3372. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3373. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3374. te[0] = me[0] * scaleX;
  3375. te[1] = me[1] * scaleX;
  3376. te[2] = me[2] * scaleX;
  3377. te[3] = 0;
  3378. te[4] = me[4] * scaleY;
  3379. te[5] = me[5] * scaleY;
  3380. te[6] = me[6] * scaleY;
  3381. te[7] = 0;
  3382. te[8] = me[8] * scaleZ;
  3383. te[9] = me[9] * scaleZ;
  3384. te[10] = me[10] * scaleZ;
  3385. te[11] = 0;
  3386. te[12] = 0;
  3387. te[13] = 0;
  3388. te[14] = 0;
  3389. te[15] = 1;
  3390. return this;
  3391. };
  3392. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3393. if (!(euler && euler.isEuler)) {
  3394. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3395. }
  3396. var te = this.elements;
  3397. var x = euler.x,
  3398. y = euler.y,
  3399. z = euler.z;
  3400. var a = Math.cos(x),
  3401. b = Math.sin(x);
  3402. var c = Math.cos(y),
  3403. d = Math.sin(y);
  3404. var e = Math.cos(z),
  3405. f = Math.sin(z);
  3406. if (euler.order === 'XYZ') {
  3407. var ae = a * e,
  3408. af = a * f,
  3409. be = b * e,
  3410. bf = b * f;
  3411. te[0] = c * e;
  3412. te[4] = -c * f;
  3413. te[8] = d;
  3414. te[1] = af + be * d;
  3415. te[5] = ae - bf * d;
  3416. te[9] = -b * c;
  3417. te[2] = bf - ae * d;
  3418. te[6] = be + af * d;
  3419. te[10] = a * c;
  3420. } else if (euler.order === 'YXZ') {
  3421. var ce = c * e,
  3422. cf = c * f,
  3423. de = d * e,
  3424. df = d * f;
  3425. te[0] = ce + df * b;
  3426. te[4] = de * b - cf;
  3427. te[8] = a * d;
  3428. te[1] = a * f;
  3429. te[5] = a * e;
  3430. te[9] = -b;
  3431. te[2] = cf * b - de;
  3432. te[6] = df + ce * b;
  3433. te[10] = a * c;
  3434. } else if (euler.order === 'ZXY') {
  3435. var _ce = c * e,
  3436. _cf = c * f,
  3437. _de = d * e,
  3438. _df = d * f;
  3439. te[0] = _ce - _df * b;
  3440. te[4] = -a * f;
  3441. te[8] = _de + _cf * b;
  3442. te[1] = _cf + _de * b;
  3443. te[5] = a * e;
  3444. te[9] = _df - _ce * b;
  3445. te[2] = -a * d;
  3446. te[6] = b;
  3447. te[10] = a * c;
  3448. } else if (euler.order === 'ZYX') {
  3449. var _ae = a * e,
  3450. _af = a * f,
  3451. _be = b * e,
  3452. _bf = b * f;
  3453. te[0] = c * e;
  3454. te[4] = _be * d - _af;
  3455. te[8] = _ae * d + _bf;
  3456. te[1] = c * f;
  3457. te[5] = _bf * d + _ae;
  3458. te[9] = _af * d - _be;
  3459. te[2] = -d;
  3460. te[6] = b * c;
  3461. te[10] = a * c;
  3462. } else if (euler.order === 'YZX') {
  3463. var ac = a * c,
  3464. ad = a * d,
  3465. bc = b * c,
  3466. bd = b * d;
  3467. te[0] = c * e;
  3468. te[4] = bd - ac * f;
  3469. te[8] = bc * f + ad;
  3470. te[1] = f;
  3471. te[5] = a * e;
  3472. te[9] = -b * e;
  3473. te[2] = -d * e;
  3474. te[6] = ad * f + bc;
  3475. te[10] = ac - bd * f;
  3476. } else if (euler.order === 'XZY') {
  3477. var _ac = a * c,
  3478. _ad = a * d,
  3479. _bc = b * c,
  3480. _bd = b * d;
  3481. te[0] = c * e;
  3482. te[4] = -f;
  3483. te[8] = d * e;
  3484. te[1] = _ac * f + _bd;
  3485. te[5] = a * e;
  3486. te[9] = _ad * f - _bc;
  3487. te[2] = _bc * f - _ad;
  3488. te[6] = b * e;
  3489. te[10] = _bd * f + _ac;
  3490. } // bottom row
  3491. te[3] = 0;
  3492. te[7] = 0;
  3493. te[11] = 0; // last column
  3494. te[12] = 0;
  3495. te[13] = 0;
  3496. te[14] = 0;
  3497. te[15] = 1;
  3498. return this;
  3499. };
  3500. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3501. return this.compose(_zero, q, _one);
  3502. };
  3503. _proto.lookAt = function lookAt(eye, target, up) {
  3504. var te = this.elements;
  3505. _z.subVectors(eye, target);
  3506. if (_z.lengthSq() === 0) {
  3507. // eye and target are in the same position
  3508. _z.z = 1;
  3509. }
  3510. _z.normalize();
  3511. _x.crossVectors(up, _z);
  3512. if (_x.lengthSq() === 0) {
  3513. // up and z are parallel
  3514. if (Math.abs(up.z) === 1) {
  3515. _z.x += 0.0001;
  3516. } else {
  3517. _z.z += 0.0001;
  3518. }
  3519. _z.normalize();
  3520. _x.crossVectors(up, _z);
  3521. }
  3522. _x.normalize();
  3523. _y.crossVectors(_z, _x);
  3524. te[0] = _x.x;
  3525. te[4] = _y.x;
  3526. te[8] = _z.x;
  3527. te[1] = _x.y;
  3528. te[5] = _y.y;
  3529. te[9] = _z.y;
  3530. te[2] = _x.z;
  3531. te[6] = _y.z;
  3532. te[10] = _z.z;
  3533. return this;
  3534. };
  3535. _proto.multiply = function multiply(m, n) {
  3536. if (n !== undefined) {
  3537. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3538. return this.multiplyMatrices(m, n);
  3539. }
  3540. return this.multiplyMatrices(this, m);
  3541. };
  3542. _proto.premultiply = function premultiply(m) {
  3543. return this.multiplyMatrices(m, this);
  3544. };
  3545. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3546. var ae = a.elements;
  3547. var be = b.elements;
  3548. var te = this.elements;
  3549. var a11 = ae[0],
  3550. a12 = ae[4],
  3551. a13 = ae[8],
  3552. a14 = ae[12];
  3553. var a21 = ae[1],
  3554. a22 = ae[5],
  3555. a23 = ae[9],
  3556. a24 = ae[13];
  3557. var a31 = ae[2],
  3558. a32 = ae[6],
  3559. a33 = ae[10],
  3560. a34 = ae[14];
  3561. var a41 = ae[3],
  3562. a42 = ae[7],
  3563. a43 = ae[11],
  3564. a44 = ae[15];
  3565. var b11 = be[0],
  3566. b12 = be[4],
  3567. b13 = be[8],
  3568. b14 = be[12];
  3569. var b21 = be[1],
  3570. b22 = be[5],
  3571. b23 = be[9],
  3572. b24 = be[13];
  3573. var b31 = be[2],
  3574. b32 = be[6],
  3575. b33 = be[10],
  3576. b34 = be[14];
  3577. var b41 = be[3],
  3578. b42 = be[7],
  3579. b43 = be[11],
  3580. b44 = be[15];
  3581. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3582. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3583. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3584. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3585. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3586. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3587. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3588. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3589. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3590. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3591. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3592. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3593. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3594. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3595. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3596. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3597. return this;
  3598. };
  3599. _proto.multiplyScalar = function multiplyScalar(s) {
  3600. var te = this.elements;
  3601. te[0] *= s;
  3602. te[4] *= s;
  3603. te[8] *= s;
  3604. te[12] *= s;
  3605. te[1] *= s;
  3606. te[5] *= s;
  3607. te[9] *= s;
  3608. te[13] *= s;
  3609. te[2] *= s;
  3610. te[6] *= s;
  3611. te[10] *= s;
  3612. te[14] *= s;
  3613. te[3] *= s;
  3614. te[7] *= s;
  3615. te[11] *= s;
  3616. te[15] *= s;
  3617. return this;
  3618. };
  3619. _proto.determinant = function determinant() {
  3620. var te = this.elements;
  3621. var n11 = te[0],
  3622. n12 = te[4],
  3623. n13 = te[8],
  3624. n14 = te[12];
  3625. var n21 = te[1],
  3626. n22 = te[5],
  3627. n23 = te[9],
  3628. n24 = te[13];
  3629. var n31 = te[2],
  3630. n32 = te[6],
  3631. n33 = te[10],
  3632. n34 = te[14];
  3633. var n41 = te[3],
  3634. n42 = te[7],
  3635. n43 = te[11],
  3636. n44 = te[15]; //TODO: make this more efficient
  3637. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3638. 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);
  3639. };
  3640. _proto.transpose = function transpose() {
  3641. var te = this.elements;
  3642. var tmp;
  3643. tmp = te[1];
  3644. te[1] = te[4];
  3645. te[4] = tmp;
  3646. tmp = te[2];
  3647. te[2] = te[8];
  3648. te[8] = tmp;
  3649. tmp = te[6];
  3650. te[6] = te[9];
  3651. te[9] = tmp;
  3652. tmp = te[3];
  3653. te[3] = te[12];
  3654. te[12] = tmp;
  3655. tmp = te[7];
  3656. te[7] = te[13];
  3657. te[13] = tmp;
  3658. tmp = te[11];
  3659. te[11] = te[14];
  3660. te[14] = tmp;
  3661. return this;
  3662. };
  3663. _proto.setPosition = function setPosition(x, y, z) {
  3664. var te = this.elements;
  3665. if (x.isVector3) {
  3666. te[12] = x.x;
  3667. te[13] = x.y;
  3668. te[14] = x.z;
  3669. } else {
  3670. te[12] = x;
  3671. te[13] = y;
  3672. te[14] = z;
  3673. }
  3674. return this;
  3675. };
  3676. _proto.invert = function invert() {
  3677. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3678. var te = this.elements,
  3679. n11 = te[0],
  3680. n21 = te[1],
  3681. n31 = te[2],
  3682. n41 = te[3],
  3683. n12 = te[4],
  3684. n22 = te[5],
  3685. n32 = te[6],
  3686. n42 = te[7],
  3687. n13 = te[8],
  3688. n23 = te[9],
  3689. n33 = te[10],
  3690. n43 = te[11],
  3691. n14 = te[12],
  3692. n24 = te[13],
  3693. n34 = te[14],
  3694. n44 = te[15],
  3695. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3696. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3697. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3698. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3699. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3700. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3701. var detInv = 1 / det;
  3702. te[0] = t11 * detInv;
  3703. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3704. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3705. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3706. te[4] = t12 * detInv;
  3707. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3708. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3709. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3710. te[8] = t13 * detInv;
  3711. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3712. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3713. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3714. te[12] = t14 * detInv;
  3715. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3716. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3717. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3718. return this;
  3719. };
  3720. _proto.scale = function scale(v) {
  3721. var te = this.elements;
  3722. var x = v.x,
  3723. y = v.y,
  3724. z = v.z;
  3725. te[0] *= x;
  3726. te[4] *= y;
  3727. te[8] *= z;
  3728. te[1] *= x;
  3729. te[5] *= y;
  3730. te[9] *= z;
  3731. te[2] *= x;
  3732. te[6] *= y;
  3733. te[10] *= z;
  3734. te[3] *= x;
  3735. te[7] *= y;
  3736. te[11] *= z;
  3737. return this;
  3738. };
  3739. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3740. var te = this.elements;
  3741. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3742. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3743. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3744. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3745. };
  3746. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3747. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3748. return this;
  3749. };
  3750. _proto.makeRotationX = function makeRotationX(theta) {
  3751. var c = Math.cos(theta),
  3752. s = Math.sin(theta);
  3753. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3754. return this;
  3755. };
  3756. _proto.makeRotationY = function makeRotationY(theta) {
  3757. var c = Math.cos(theta),
  3758. s = Math.sin(theta);
  3759. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3760. return this;
  3761. };
  3762. _proto.makeRotationZ = function makeRotationZ(theta) {
  3763. var c = Math.cos(theta),
  3764. s = Math.sin(theta);
  3765. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3766. return this;
  3767. };
  3768. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3769. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3770. var c = Math.cos(angle);
  3771. var s = Math.sin(angle);
  3772. var t = 1 - c;
  3773. var x = axis.x,
  3774. y = axis.y,
  3775. z = axis.z;
  3776. var tx = t * x,
  3777. ty = t * y;
  3778. 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);
  3779. return this;
  3780. };
  3781. _proto.makeScale = function makeScale(x, y, z) {
  3782. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3783. return this;
  3784. };
  3785. _proto.makeShear = function makeShear(x, y, z) {
  3786. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3787. return this;
  3788. };
  3789. _proto.compose = function compose(position, quaternion, scale) {
  3790. var te = this.elements;
  3791. var x = quaternion._x,
  3792. y = quaternion._y,
  3793. z = quaternion._z,
  3794. w = quaternion._w;
  3795. var x2 = x + x,
  3796. y2 = y + y,
  3797. z2 = z + z;
  3798. var xx = x * x2,
  3799. xy = x * y2,
  3800. xz = x * z2;
  3801. var yy = y * y2,
  3802. yz = y * z2,
  3803. zz = z * z2;
  3804. var wx = w * x2,
  3805. wy = w * y2,
  3806. wz = w * z2;
  3807. var sx = scale.x,
  3808. sy = scale.y,
  3809. sz = scale.z;
  3810. te[0] = (1 - (yy + zz)) * sx;
  3811. te[1] = (xy + wz) * sx;
  3812. te[2] = (xz - wy) * sx;
  3813. te[3] = 0;
  3814. te[4] = (xy - wz) * sy;
  3815. te[5] = (1 - (xx + zz)) * sy;
  3816. te[6] = (yz + wx) * sy;
  3817. te[7] = 0;
  3818. te[8] = (xz + wy) * sz;
  3819. te[9] = (yz - wx) * sz;
  3820. te[10] = (1 - (xx + yy)) * sz;
  3821. te[11] = 0;
  3822. te[12] = position.x;
  3823. te[13] = position.y;
  3824. te[14] = position.z;
  3825. te[15] = 1;
  3826. return this;
  3827. };
  3828. _proto.decompose = function decompose(position, quaternion, scale) {
  3829. var te = this.elements;
  3830. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3831. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3832. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3833. var det = this.determinant();
  3834. if (det < 0) sx = -sx;
  3835. position.x = te[12];
  3836. position.y = te[13];
  3837. position.z = te[14]; // scale the rotation part
  3838. _m1.copy(this);
  3839. var invSX = 1 / sx;
  3840. var invSY = 1 / sy;
  3841. var invSZ = 1 / sz;
  3842. _m1.elements[0] *= invSX;
  3843. _m1.elements[1] *= invSX;
  3844. _m1.elements[2] *= invSX;
  3845. _m1.elements[4] *= invSY;
  3846. _m1.elements[5] *= invSY;
  3847. _m1.elements[6] *= invSY;
  3848. _m1.elements[8] *= invSZ;
  3849. _m1.elements[9] *= invSZ;
  3850. _m1.elements[10] *= invSZ;
  3851. quaternion.setFromRotationMatrix(_m1);
  3852. scale.x = sx;
  3853. scale.y = sy;
  3854. scale.z = sz;
  3855. return this;
  3856. };
  3857. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3858. if (far === undefined) {
  3859. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3860. }
  3861. var te = this.elements;
  3862. var x = 2 * near / (right - left);
  3863. var y = 2 * near / (top - bottom);
  3864. var a = (right + left) / (right - left);
  3865. var b = (top + bottom) / (top - bottom);
  3866. var c = -(far + near) / (far - near);
  3867. var d = -2 * far * near / (far - near);
  3868. te[0] = x;
  3869. te[4] = 0;
  3870. te[8] = a;
  3871. te[12] = 0;
  3872. te[1] = 0;
  3873. te[5] = y;
  3874. te[9] = b;
  3875. te[13] = 0;
  3876. te[2] = 0;
  3877. te[6] = 0;
  3878. te[10] = c;
  3879. te[14] = d;
  3880. te[3] = 0;
  3881. te[7] = 0;
  3882. te[11] = -1;
  3883. te[15] = 0;
  3884. return this;
  3885. };
  3886. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3887. var te = this.elements;
  3888. var w = 1.0 / (right - left);
  3889. var h = 1.0 / (top - bottom);
  3890. var p = 1.0 / (far - near);
  3891. var x = (right + left) * w;
  3892. var y = (top + bottom) * h;
  3893. var z = (far + near) * p;
  3894. te[0] = 2 * w;
  3895. te[4] = 0;
  3896. te[8] = 0;
  3897. te[12] = -x;
  3898. te[1] = 0;
  3899. te[5] = 2 * h;
  3900. te[9] = 0;
  3901. te[13] = -y;
  3902. te[2] = 0;
  3903. te[6] = 0;
  3904. te[10] = -2 * p;
  3905. te[14] = -z;
  3906. te[3] = 0;
  3907. te[7] = 0;
  3908. te[11] = 0;
  3909. te[15] = 1;
  3910. return this;
  3911. };
  3912. _proto.equals = function equals(matrix) {
  3913. var te = this.elements;
  3914. var me = matrix.elements;
  3915. for (var i = 0; i < 16; i++) {
  3916. if (te[i] !== me[i]) return false;
  3917. }
  3918. return true;
  3919. };
  3920. _proto.fromArray = function fromArray(array, offset) {
  3921. if (offset === void 0) {
  3922. offset = 0;
  3923. }
  3924. for (var i = 0; i < 16; i++) {
  3925. this.elements[i] = array[i + offset];
  3926. }
  3927. return this;
  3928. };
  3929. _proto.toArray = function toArray(array, offset) {
  3930. if (array === void 0) {
  3931. array = [];
  3932. }
  3933. if (offset === void 0) {
  3934. offset = 0;
  3935. }
  3936. var te = this.elements;
  3937. array[offset] = te[0];
  3938. array[offset + 1] = te[1];
  3939. array[offset + 2] = te[2];
  3940. array[offset + 3] = te[3];
  3941. array[offset + 4] = te[4];
  3942. array[offset + 5] = te[5];
  3943. array[offset + 6] = te[6];
  3944. array[offset + 7] = te[7];
  3945. array[offset + 8] = te[8];
  3946. array[offset + 9] = te[9];
  3947. array[offset + 10] = te[10];
  3948. array[offset + 11] = te[11];
  3949. array[offset + 12] = te[12];
  3950. array[offset + 13] = te[13];
  3951. array[offset + 14] = te[14];
  3952. array[offset + 15] = te[15];
  3953. return array;
  3954. };
  3955. return Matrix4;
  3956. }();
  3957. var _v1$1 = /*@__PURE__*/new Vector3();
  3958. var _m1 = /*@__PURE__*/new Matrix4();
  3959. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  3960. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  3961. var _x = /*@__PURE__*/new Vector3();
  3962. var _y = /*@__PURE__*/new Vector3();
  3963. var _z = /*@__PURE__*/new Vector3();
  3964. var Euler = /*#__PURE__*/function () {
  3965. function Euler(x, y, z, order) {
  3966. if (x === void 0) {
  3967. x = 0;
  3968. }
  3969. if (y === void 0) {
  3970. y = 0;
  3971. }
  3972. if (z === void 0) {
  3973. z = 0;
  3974. }
  3975. if (order === void 0) {
  3976. order = Euler.DefaultOrder;
  3977. }
  3978. Object.defineProperty(this, 'isEuler', {
  3979. value: true
  3980. });
  3981. this._x = x;
  3982. this._y = y;
  3983. this._z = z;
  3984. this._order = order;
  3985. }
  3986. var _proto = Euler.prototype;
  3987. _proto.set = function set(x, y, z, order) {
  3988. this._x = x;
  3989. this._y = y;
  3990. this._z = z;
  3991. this._order = order || this._order;
  3992. this._onChangeCallback();
  3993. return this;
  3994. };
  3995. _proto.clone = function clone() {
  3996. return new this.constructor(this._x, this._y, this._z, this._order);
  3997. };
  3998. _proto.copy = function copy(euler) {
  3999. this._x = euler._x;
  4000. this._y = euler._y;
  4001. this._z = euler._z;
  4002. this._order = euler._order;
  4003. this._onChangeCallback();
  4004. return this;
  4005. };
  4006. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4007. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4008. var te = m.elements;
  4009. var m11 = te[0],
  4010. m12 = te[4],
  4011. m13 = te[8];
  4012. var m21 = te[1],
  4013. m22 = te[5],
  4014. m23 = te[9];
  4015. var m31 = te[2],
  4016. m32 = te[6],
  4017. m33 = te[10];
  4018. order = order || this._order;
  4019. switch (order) {
  4020. case 'XYZ':
  4021. this._y = Math.asin(clamp(m13, -1, 1));
  4022. if (Math.abs(m13) < 0.9999999) {
  4023. this._x = Math.atan2(-m23, m33);
  4024. this._z = Math.atan2(-m12, m11);
  4025. } else {
  4026. this._x = Math.atan2(m32, m22);
  4027. this._z = 0;
  4028. }
  4029. break;
  4030. case 'YXZ':
  4031. this._x = Math.asin(-clamp(m23, -1, 1));
  4032. if (Math.abs(m23) < 0.9999999) {
  4033. this._y = Math.atan2(m13, m33);
  4034. this._z = Math.atan2(m21, m22);
  4035. } else {
  4036. this._y = Math.atan2(-m31, m11);
  4037. this._z = 0;
  4038. }
  4039. break;
  4040. case 'ZXY':
  4041. this._x = Math.asin(clamp(m32, -1, 1));
  4042. if (Math.abs(m32) < 0.9999999) {
  4043. this._y = Math.atan2(-m31, m33);
  4044. this._z = Math.atan2(-m12, m22);
  4045. } else {
  4046. this._y = 0;
  4047. this._z = Math.atan2(m21, m11);
  4048. }
  4049. break;
  4050. case 'ZYX':
  4051. this._y = Math.asin(-clamp(m31, -1, 1));
  4052. if (Math.abs(m31) < 0.9999999) {
  4053. this._x = Math.atan2(m32, m33);
  4054. this._z = Math.atan2(m21, m11);
  4055. } else {
  4056. this._x = 0;
  4057. this._z = Math.atan2(-m12, m22);
  4058. }
  4059. break;
  4060. case 'YZX':
  4061. this._z = Math.asin(clamp(m21, -1, 1));
  4062. if (Math.abs(m21) < 0.9999999) {
  4063. this._x = Math.atan2(-m23, m22);
  4064. this._y = Math.atan2(-m31, m11);
  4065. } else {
  4066. this._x = 0;
  4067. this._y = Math.atan2(m13, m33);
  4068. }
  4069. break;
  4070. case 'XZY':
  4071. this._z = Math.asin(-clamp(m12, -1, 1));
  4072. if (Math.abs(m12) < 0.9999999) {
  4073. this._x = Math.atan2(m32, m22);
  4074. this._y = Math.atan2(m13, m11);
  4075. } else {
  4076. this._x = Math.atan2(-m23, m33);
  4077. this._y = 0;
  4078. }
  4079. break;
  4080. default:
  4081. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4082. }
  4083. this._order = order;
  4084. if (update !== false) this._onChangeCallback();
  4085. return this;
  4086. };
  4087. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4088. _matrix.makeRotationFromQuaternion(q);
  4089. return this.setFromRotationMatrix(_matrix, order, update);
  4090. };
  4091. _proto.setFromVector3 = function setFromVector3(v, order) {
  4092. return this.set(v.x, v.y, v.z, order || this._order);
  4093. };
  4094. _proto.reorder = function reorder(newOrder) {
  4095. // WARNING: this discards revolution information -bhouston
  4096. _quaternion$1.setFromEuler(this);
  4097. return this.setFromQuaternion(_quaternion$1, newOrder);
  4098. };
  4099. _proto.equals = function equals(euler) {
  4100. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4101. };
  4102. _proto.fromArray = function fromArray(array) {
  4103. this._x = array[0];
  4104. this._y = array[1];
  4105. this._z = array[2];
  4106. if (array[3] !== undefined) this._order = array[3];
  4107. this._onChangeCallback();
  4108. return this;
  4109. };
  4110. _proto.toArray = function toArray(array, offset) {
  4111. if (array === void 0) {
  4112. array = [];
  4113. }
  4114. if (offset === void 0) {
  4115. offset = 0;
  4116. }
  4117. array[offset] = this._x;
  4118. array[offset + 1] = this._y;
  4119. array[offset + 2] = this._z;
  4120. array[offset + 3] = this._order;
  4121. return array;
  4122. };
  4123. _proto.toVector3 = function toVector3(optionalResult) {
  4124. if (optionalResult) {
  4125. return optionalResult.set(this._x, this._y, this._z);
  4126. } else {
  4127. return new Vector3(this._x, this._y, this._z);
  4128. }
  4129. };
  4130. _proto._onChange = function _onChange(callback) {
  4131. this._onChangeCallback = callback;
  4132. return this;
  4133. };
  4134. _proto._onChangeCallback = function _onChangeCallback() {};
  4135. _createClass(Euler, [{
  4136. key: "x",
  4137. get: function get() {
  4138. return this._x;
  4139. },
  4140. set: function set(value) {
  4141. this._x = value;
  4142. this._onChangeCallback();
  4143. }
  4144. }, {
  4145. key: "y",
  4146. get: function get() {
  4147. return this._y;
  4148. },
  4149. set: function set(value) {
  4150. this._y = value;
  4151. this._onChangeCallback();
  4152. }
  4153. }, {
  4154. key: "z",
  4155. get: function get() {
  4156. return this._z;
  4157. },
  4158. set: function set(value) {
  4159. this._z = value;
  4160. this._onChangeCallback();
  4161. }
  4162. }, {
  4163. key: "order",
  4164. get: function get() {
  4165. return this._order;
  4166. },
  4167. set: function set(value) {
  4168. this._order = value;
  4169. this._onChangeCallback();
  4170. }
  4171. }]);
  4172. return Euler;
  4173. }();
  4174. Euler.DefaultOrder = 'XYZ';
  4175. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4176. var _matrix = /*@__PURE__*/new Matrix4();
  4177. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4178. var Layers = /*#__PURE__*/function () {
  4179. function Layers() {
  4180. this.mask = 1 | 0;
  4181. }
  4182. var _proto = Layers.prototype;
  4183. _proto.set = function set(channel) {
  4184. this.mask = 1 << channel | 0;
  4185. };
  4186. _proto.enable = function enable(channel) {
  4187. this.mask |= 1 << channel | 0;
  4188. };
  4189. _proto.enableAll = function enableAll() {
  4190. this.mask = 0xffffffff | 0;
  4191. };
  4192. _proto.toggle = function toggle(channel) {
  4193. this.mask ^= 1 << channel | 0;
  4194. };
  4195. _proto.disable = function disable(channel) {
  4196. this.mask &= ~(1 << channel | 0);
  4197. };
  4198. _proto.disableAll = function disableAll() {
  4199. this.mask = 0;
  4200. };
  4201. _proto.test = function test(layers) {
  4202. return (this.mask & layers.mask) !== 0;
  4203. };
  4204. return Layers;
  4205. }();
  4206. var _object3DId = 0;
  4207. var _v1$2 = new Vector3();
  4208. var _q1 = new Quaternion();
  4209. var _m1$1 = new Matrix4();
  4210. var _target = new Vector3();
  4211. var _position = new Vector3();
  4212. var _scale = new Vector3();
  4213. var _quaternion$2 = new Quaternion();
  4214. var _xAxis = new Vector3(1, 0, 0);
  4215. var _yAxis = new Vector3(0, 1, 0);
  4216. var _zAxis = new Vector3(0, 0, 1);
  4217. var _addedEvent = {
  4218. type: 'added'
  4219. };
  4220. var _removedEvent = {
  4221. type: 'removed'
  4222. };
  4223. function Object3D() {
  4224. Object.defineProperty(this, 'id', {
  4225. value: _object3DId++
  4226. });
  4227. this.uuid = MathUtils.generateUUID();
  4228. this.name = '';
  4229. this.type = 'Object3D';
  4230. this.parent = null;
  4231. this.children = [];
  4232. this.up = Object3D.DefaultUp.clone();
  4233. var position = new Vector3();
  4234. var rotation = new Euler();
  4235. var quaternion = new Quaternion();
  4236. var scale = new Vector3(1, 1, 1);
  4237. function onRotationChange() {
  4238. quaternion.setFromEuler(rotation, false);
  4239. }
  4240. function onQuaternionChange() {
  4241. rotation.setFromQuaternion(quaternion, undefined, false);
  4242. }
  4243. rotation._onChange(onRotationChange);
  4244. quaternion._onChange(onQuaternionChange);
  4245. Object.defineProperties(this, {
  4246. position: {
  4247. configurable: true,
  4248. enumerable: true,
  4249. value: position
  4250. },
  4251. rotation: {
  4252. configurable: true,
  4253. enumerable: true,
  4254. value: rotation
  4255. },
  4256. quaternion: {
  4257. configurable: true,
  4258. enumerable: true,
  4259. value: quaternion
  4260. },
  4261. scale: {
  4262. configurable: true,
  4263. enumerable: true,
  4264. value: scale
  4265. },
  4266. modelViewMatrix: {
  4267. value: new Matrix4()
  4268. },
  4269. normalMatrix: {
  4270. value: new Matrix3()
  4271. }
  4272. });
  4273. this.matrix = new Matrix4();
  4274. this.matrixWorld = new Matrix4();
  4275. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4276. this.matrixWorldNeedsUpdate = false;
  4277. this.layers = new Layers();
  4278. this.visible = true;
  4279. this.castShadow = false;
  4280. this.receiveShadow = false;
  4281. this.frustumCulled = true;
  4282. this.renderOrder = 0;
  4283. this.userData = {};
  4284. }
  4285. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4286. Object3D.DefaultMatrixAutoUpdate = true;
  4287. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4288. constructor: Object3D,
  4289. isObject3D: true,
  4290. onBeforeRender: function onBeforeRender() {},
  4291. onAfterRender: function onAfterRender() {},
  4292. applyMatrix4: function applyMatrix4(matrix) {
  4293. if (this.matrixAutoUpdate) this.updateMatrix();
  4294. this.matrix.premultiply(matrix);
  4295. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4296. },
  4297. applyQuaternion: function applyQuaternion(q) {
  4298. this.quaternion.premultiply(q);
  4299. return this;
  4300. },
  4301. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4302. // assumes axis is normalized
  4303. this.quaternion.setFromAxisAngle(axis, angle);
  4304. },
  4305. setRotationFromEuler: function setRotationFromEuler(euler) {
  4306. this.quaternion.setFromEuler(euler, true);
  4307. },
  4308. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4309. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4310. this.quaternion.setFromRotationMatrix(m);
  4311. },
  4312. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4313. // assumes q is normalized
  4314. this.quaternion.copy(q);
  4315. },
  4316. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4317. // rotate object on axis in object space
  4318. // axis is assumed to be normalized
  4319. _q1.setFromAxisAngle(axis, angle);
  4320. this.quaternion.multiply(_q1);
  4321. return this;
  4322. },
  4323. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4324. // rotate object on axis in world space
  4325. // axis is assumed to be normalized
  4326. // method assumes no rotated parent
  4327. _q1.setFromAxisAngle(axis, angle);
  4328. this.quaternion.premultiply(_q1);
  4329. return this;
  4330. },
  4331. rotateX: function rotateX(angle) {
  4332. return this.rotateOnAxis(_xAxis, angle);
  4333. },
  4334. rotateY: function rotateY(angle) {
  4335. return this.rotateOnAxis(_yAxis, angle);
  4336. },
  4337. rotateZ: function rotateZ(angle) {
  4338. return this.rotateOnAxis(_zAxis, angle);
  4339. },
  4340. translateOnAxis: function translateOnAxis(axis, distance) {
  4341. // translate object by distance along axis in object space
  4342. // axis is assumed to be normalized
  4343. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4344. this.position.add(_v1$2.multiplyScalar(distance));
  4345. return this;
  4346. },
  4347. translateX: function translateX(distance) {
  4348. return this.translateOnAxis(_xAxis, distance);
  4349. },
  4350. translateY: function translateY(distance) {
  4351. return this.translateOnAxis(_yAxis, distance);
  4352. },
  4353. translateZ: function translateZ(distance) {
  4354. return this.translateOnAxis(_zAxis, distance);
  4355. },
  4356. localToWorld: function localToWorld(vector) {
  4357. return vector.applyMatrix4(this.matrixWorld);
  4358. },
  4359. worldToLocal: function worldToLocal(vector) {
  4360. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  4361. },
  4362. lookAt: function lookAt(x, y, z) {
  4363. // This method does not support objects having non-uniformly-scaled parent(s)
  4364. if (x.isVector3) {
  4365. _target.copy(x);
  4366. } else {
  4367. _target.set(x, y, z);
  4368. }
  4369. var parent = this.parent;
  4370. this.updateWorldMatrix(true, false);
  4371. _position.setFromMatrixPosition(this.matrixWorld);
  4372. if (this.isCamera || this.isLight) {
  4373. _m1$1.lookAt(_position, _target, this.up);
  4374. } else {
  4375. _m1$1.lookAt(_target, _position, this.up);
  4376. }
  4377. this.quaternion.setFromRotationMatrix(_m1$1);
  4378. if (parent) {
  4379. _m1$1.extractRotation(parent.matrixWorld);
  4380. _q1.setFromRotationMatrix(_m1$1);
  4381. this.quaternion.premultiply(_q1.invert());
  4382. }
  4383. },
  4384. add: function add(object) {
  4385. if (arguments.length > 1) {
  4386. for (var i = 0; i < arguments.length; i++) {
  4387. this.add(arguments[i]);
  4388. }
  4389. return this;
  4390. }
  4391. if (object === this) {
  4392. console.error("THREE.Object3D.add: object can't be added as a child of itself.", object);
  4393. return this;
  4394. }
  4395. if (object && object.isObject3D) {
  4396. if (object.parent !== null) {
  4397. object.parent.remove(object);
  4398. }
  4399. object.parent = this;
  4400. this.children.push(object);
  4401. object.dispatchEvent(_addedEvent);
  4402. } else {
  4403. console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object);
  4404. }
  4405. return this;
  4406. },
  4407. remove: function remove(object) {
  4408. if (arguments.length > 1) {
  4409. for (var i = 0; i < arguments.length; i++) {
  4410. this.remove(arguments[i]);
  4411. }
  4412. return this;
  4413. }
  4414. var index = this.children.indexOf(object);
  4415. if (index !== -1) {
  4416. object.parent = null;
  4417. this.children.splice(index, 1);
  4418. object.dispatchEvent(_removedEvent);
  4419. }
  4420. return this;
  4421. },
  4422. clear: function clear() {
  4423. for (var i = 0; i < this.children.length; i++) {
  4424. var object = this.children[i];
  4425. object.parent = null;
  4426. object.dispatchEvent(_removedEvent);
  4427. }
  4428. this.children.length = 0;
  4429. return this;
  4430. },
  4431. attach: function attach(object) {
  4432. // adds object as a child of this, while maintaining the object's world transform
  4433. this.updateWorldMatrix(true, false);
  4434. _m1$1.copy(this.matrixWorld).invert();
  4435. if (object.parent !== null) {
  4436. object.parent.updateWorldMatrix(true, false);
  4437. _m1$1.multiply(object.parent.matrixWorld);
  4438. }
  4439. object.applyMatrix4(_m1$1);
  4440. object.updateWorldMatrix(false, false);
  4441. this.add(object);
  4442. return this;
  4443. },
  4444. getObjectById: function getObjectById(id) {
  4445. return this.getObjectByProperty('id', id);
  4446. },
  4447. getObjectByName: function getObjectByName(name) {
  4448. return this.getObjectByProperty('name', name);
  4449. },
  4450. getObjectByProperty: function getObjectByProperty(name, value) {
  4451. if (this[name] === value) return this;
  4452. for (var i = 0, l = this.children.length; i < l; i++) {
  4453. var child = this.children[i];
  4454. var object = child.getObjectByProperty(name, value);
  4455. if (object !== undefined) {
  4456. return object;
  4457. }
  4458. }
  4459. return undefined;
  4460. },
  4461. getWorldPosition: function getWorldPosition(target) {
  4462. if (target === undefined) {
  4463. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4464. target = new Vector3();
  4465. }
  4466. this.updateWorldMatrix(true, false);
  4467. return target.setFromMatrixPosition(this.matrixWorld);
  4468. },
  4469. getWorldQuaternion: function getWorldQuaternion(target) {
  4470. if (target === undefined) {
  4471. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4472. target = new Quaternion();
  4473. }
  4474. this.updateWorldMatrix(true, false);
  4475. this.matrixWorld.decompose(_position, target, _scale);
  4476. return target;
  4477. },
  4478. getWorldScale: function getWorldScale(target) {
  4479. if (target === undefined) {
  4480. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4481. target = new Vector3();
  4482. }
  4483. this.updateWorldMatrix(true, false);
  4484. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4485. return target;
  4486. },
  4487. getWorldDirection: function getWorldDirection(target) {
  4488. if (target === undefined) {
  4489. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4490. target = new Vector3();
  4491. }
  4492. this.updateWorldMatrix(true, false);
  4493. var e = this.matrixWorld.elements;
  4494. return target.set(e[8], e[9], e[10]).normalize();
  4495. },
  4496. raycast: function raycast() {},
  4497. traverse: function traverse(callback) {
  4498. callback(this);
  4499. var children = this.children;
  4500. for (var i = 0, l = children.length; i < l; i++) {
  4501. children[i].traverse(callback);
  4502. }
  4503. },
  4504. traverseVisible: function traverseVisible(callback) {
  4505. if (this.visible === false) return;
  4506. callback(this);
  4507. var children = this.children;
  4508. for (var i = 0, l = children.length; i < l; i++) {
  4509. children[i].traverseVisible(callback);
  4510. }
  4511. },
  4512. traverseAncestors: function traverseAncestors(callback) {
  4513. var parent = this.parent;
  4514. if (parent !== null) {
  4515. callback(parent);
  4516. parent.traverseAncestors(callback);
  4517. }
  4518. },
  4519. updateMatrix: function updateMatrix() {
  4520. this.matrix.compose(this.position, this.quaternion, this.scale);
  4521. this.matrixWorldNeedsUpdate = true;
  4522. },
  4523. updateMatrixWorld: function updateMatrixWorld(force) {
  4524. if (this.matrixAutoUpdate) this.updateMatrix();
  4525. if (this.matrixWorldNeedsUpdate || force) {
  4526. if (this.parent === null) {
  4527. this.matrixWorld.copy(this.matrix);
  4528. } else {
  4529. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4530. }
  4531. this.matrixWorldNeedsUpdate = false;
  4532. force = true;
  4533. } // update children
  4534. var children = this.children;
  4535. for (var i = 0, l = children.length; i < l; i++) {
  4536. children[i].updateMatrixWorld(force);
  4537. }
  4538. },
  4539. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4540. var parent = this.parent;
  4541. if (updateParents === true && parent !== null) {
  4542. parent.updateWorldMatrix(true, false);
  4543. }
  4544. if (this.matrixAutoUpdate) this.updateMatrix();
  4545. if (this.parent === null) {
  4546. this.matrixWorld.copy(this.matrix);
  4547. } else {
  4548. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4549. } // update children
  4550. if (updateChildren === true) {
  4551. var children = this.children;
  4552. for (var i = 0, l = children.length; i < l; i++) {
  4553. children[i].updateWorldMatrix(false, true);
  4554. }
  4555. }
  4556. },
  4557. toJSON: function toJSON(meta) {
  4558. // meta is a string when called from JSON.stringify
  4559. var isRootObject = meta === undefined || typeof meta === 'string';
  4560. var output = {}; // meta is a hash used to collect geometries, materials.
  4561. // not providing it implies that this is the root object
  4562. // being serialized.
  4563. if (isRootObject) {
  4564. // initialize meta obj
  4565. meta = {
  4566. geometries: {},
  4567. materials: {},
  4568. textures: {},
  4569. images: {},
  4570. shapes: {},
  4571. skeletons: {}
  4572. };
  4573. output.metadata = {
  4574. version: 4.5,
  4575. type: 'Object',
  4576. generator: 'Object3D.toJSON'
  4577. };
  4578. } // standard Object3D serialization
  4579. var object = {};
  4580. object.uuid = this.uuid;
  4581. object.type = this.type;
  4582. if (this.name !== '') object.name = this.name;
  4583. if (this.castShadow === true) object.castShadow = true;
  4584. if (this.receiveShadow === true) object.receiveShadow = true;
  4585. if (this.visible === false) object.visible = false;
  4586. if (this.frustumCulled === false) object.frustumCulled = false;
  4587. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4588. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4589. object.layers = this.layers.mask;
  4590. object.matrix = this.matrix.toArray();
  4591. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4592. if (this.isInstancedMesh) {
  4593. object.type = 'InstancedMesh';
  4594. object.count = this.count;
  4595. object.instanceMatrix = this.instanceMatrix.toJSON();
  4596. } //
  4597. function serialize(library, element) {
  4598. if (library[element.uuid] === undefined) {
  4599. library[element.uuid] = element.toJSON(meta);
  4600. }
  4601. return element.uuid;
  4602. }
  4603. if (this.isMesh || this.isLine || this.isPoints) {
  4604. object.geometry = serialize(meta.geometries, this.geometry);
  4605. var parameters = this.geometry.parameters;
  4606. if (parameters !== undefined && parameters.shapes !== undefined) {
  4607. var shapes = parameters.shapes;
  4608. if (Array.isArray(shapes)) {
  4609. for (var i = 0, l = shapes.length; i < l; i++) {
  4610. var shape = shapes[i];
  4611. serialize(meta.shapes, shape);
  4612. }
  4613. } else {
  4614. serialize(meta.shapes, shapes);
  4615. }
  4616. }
  4617. }
  4618. if (this.isSkinnedMesh) {
  4619. object.bindMode = this.bindMode;
  4620. object.bindMatrix = this.bindMatrix.toArray();
  4621. if (this.skeleton !== undefined) {
  4622. serialize(meta.skeletons, this.skeleton);
  4623. object.skeleton = this.skeleton.uuid;
  4624. }
  4625. }
  4626. if (this.material !== undefined) {
  4627. if (Array.isArray(this.material)) {
  4628. var uuids = [];
  4629. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4630. uuids.push(serialize(meta.materials, this.material[_i]));
  4631. }
  4632. object.material = uuids;
  4633. } else {
  4634. object.material = serialize(meta.materials, this.material);
  4635. }
  4636. } //
  4637. if (this.children.length > 0) {
  4638. object.children = [];
  4639. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4640. object.children.push(this.children[_i2].toJSON(meta).object);
  4641. }
  4642. }
  4643. if (isRootObject) {
  4644. var geometries = extractFromCache(meta.geometries);
  4645. var materials = extractFromCache(meta.materials);
  4646. var textures = extractFromCache(meta.textures);
  4647. var images = extractFromCache(meta.images);
  4648. var _shapes = extractFromCache(meta.shapes);
  4649. var skeletons = extractFromCache(meta.skeletons);
  4650. if (geometries.length > 0) output.geometries = geometries;
  4651. if (materials.length > 0) output.materials = materials;
  4652. if (textures.length > 0) output.textures = textures;
  4653. if (images.length > 0) output.images = images;
  4654. if (_shapes.length > 0) output.shapes = _shapes;
  4655. if (skeletons.length > 0) output.skeletons = skeletons;
  4656. }
  4657. output.object = object;
  4658. return output; // extract data from the cache hash
  4659. // remove metadata on each item
  4660. // and return as array
  4661. function extractFromCache(cache) {
  4662. var values = [];
  4663. for (var key in cache) {
  4664. var data = cache[key];
  4665. delete data.metadata;
  4666. values.push(data);
  4667. }
  4668. return values;
  4669. }
  4670. },
  4671. clone: function clone(recursive) {
  4672. return new this.constructor().copy(this, recursive);
  4673. },
  4674. copy: function copy(source, recursive) {
  4675. if (recursive === void 0) {
  4676. recursive = true;
  4677. }
  4678. this.name = source.name;
  4679. this.up.copy(source.up);
  4680. this.position.copy(source.position);
  4681. this.rotation.order = source.rotation.order;
  4682. this.quaternion.copy(source.quaternion);
  4683. this.scale.copy(source.scale);
  4684. this.matrix.copy(source.matrix);
  4685. this.matrixWorld.copy(source.matrixWorld);
  4686. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4687. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4688. this.layers.mask = source.layers.mask;
  4689. this.visible = source.visible;
  4690. this.castShadow = source.castShadow;
  4691. this.receiveShadow = source.receiveShadow;
  4692. this.frustumCulled = source.frustumCulled;
  4693. this.renderOrder = source.renderOrder;
  4694. this.userData = JSON.parse(JSON.stringify(source.userData));
  4695. if (recursive === true) {
  4696. for (var i = 0; i < source.children.length; i++) {
  4697. var child = source.children[i];
  4698. this.add(child.clone());
  4699. }
  4700. }
  4701. return this;
  4702. }
  4703. });
  4704. var _vector1 = /*@__PURE__*/new Vector3();
  4705. var _vector2 = /*@__PURE__*/new Vector3();
  4706. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4707. var Plane = /*#__PURE__*/function () {
  4708. function Plane(normal, constant) {
  4709. Object.defineProperty(this, 'isPlane', {
  4710. value: true
  4711. }); // normal is assumed to be normalized
  4712. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4713. this.constant = constant !== undefined ? constant : 0;
  4714. }
  4715. var _proto = Plane.prototype;
  4716. _proto.set = function set(normal, constant) {
  4717. this.normal.copy(normal);
  4718. this.constant = constant;
  4719. return this;
  4720. };
  4721. _proto.setComponents = function setComponents(x, y, z, w) {
  4722. this.normal.set(x, y, z);
  4723. this.constant = w;
  4724. return this;
  4725. };
  4726. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4727. this.normal.copy(normal);
  4728. this.constant = -point.dot(this.normal);
  4729. return this;
  4730. };
  4731. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4732. 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)?
  4733. this.setFromNormalAndCoplanarPoint(normal, a);
  4734. return this;
  4735. };
  4736. _proto.clone = function clone() {
  4737. return new this.constructor().copy(this);
  4738. };
  4739. _proto.copy = function copy(plane) {
  4740. this.normal.copy(plane.normal);
  4741. this.constant = plane.constant;
  4742. return this;
  4743. };
  4744. _proto.normalize = function normalize() {
  4745. // Note: will lead to a divide by zero if the plane is invalid.
  4746. var inverseNormalLength = 1.0 / this.normal.length();
  4747. this.normal.multiplyScalar(inverseNormalLength);
  4748. this.constant *= inverseNormalLength;
  4749. return this;
  4750. };
  4751. _proto.negate = function negate() {
  4752. this.constant *= -1;
  4753. this.normal.negate();
  4754. return this;
  4755. };
  4756. _proto.distanceToPoint = function distanceToPoint(point) {
  4757. return this.normal.dot(point) + this.constant;
  4758. };
  4759. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4760. return this.distanceToPoint(sphere.center) - sphere.radius;
  4761. };
  4762. _proto.projectPoint = function projectPoint(point, target) {
  4763. if (target === undefined) {
  4764. console.warn('THREE.Plane: .projectPoint() target is now required');
  4765. target = new Vector3();
  4766. }
  4767. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4768. };
  4769. _proto.intersectLine = function intersectLine(line, target) {
  4770. if (target === undefined) {
  4771. console.warn('THREE.Plane: .intersectLine() target is now required');
  4772. target = new Vector3();
  4773. }
  4774. var direction = line.delta(_vector1);
  4775. var denominator = this.normal.dot(direction);
  4776. if (denominator === 0) {
  4777. // line is coplanar, return origin
  4778. if (this.distanceToPoint(line.start) === 0) {
  4779. return target.copy(line.start);
  4780. } // Unsure if this is the correct method to handle this case.
  4781. return undefined;
  4782. }
  4783. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4784. if (t < 0 || t > 1) {
  4785. return undefined;
  4786. }
  4787. return target.copy(direction).multiplyScalar(t).add(line.start);
  4788. };
  4789. _proto.intersectsLine = function intersectsLine(line) {
  4790. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4791. var startSign = this.distanceToPoint(line.start);
  4792. var endSign = this.distanceToPoint(line.end);
  4793. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4794. };
  4795. _proto.intersectsBox = function intersectsBox(box) {
  4796. return box.intersectsPlane(this);
  4797. };
  4798. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4799. return sphere.intersectsPlane(this);
  4800. };
  4801. _proto.coplanarPoint = function coplanarPoint(target) {
  4802. if (target === undefined) {
  4803. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4804. target = new Vector3();
  4805. }
  4806. return target.copy(this.normal).multiplyScalar(-this.constant);
  4807. };
  4808. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4809. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4810. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4811. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4812. this.constant = -referencePoint.dot(normal);
  4813. return this;
  4814. };
  4815. _proto.translate = function translate(offset) {
  4816. this.constant -= offset.dot(this.normal);
  4817. return this;
  4818. };
  4819. _proto.equals = function equals(plane) {
  4820. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4821. };
  4822. return Plane;
  4823. }();
  4824. var _v0$1 = /*@__PURE__*/new Vector3();
  4825. var _v1$3 = /*@__PURE__*/new Vector3();
  4826. var _v2$1 = /*@__PURE__*/new Vector3();
  4827. var _v3 = /*@__PURE__*/new Vector3();
  4828. var _vab = /*@__PURE__*/new Vector3();
  4829. var _vac = /*@__PURE__*/new Vector3();
  4830. var _vbc = /*@__PURE__*/new Vector3();
  4831. var _vap = /*@__PURE__*/new Vector3();
  4832. var _vbp = /*@__PURE__*/new Vector3();
  4833. var _vcp = /*@__PURE__*/new Vector3();
  4834. var Triangle = /*#__PURE__*/function () {
  4835. function Triangle(a, b, c) {
  4836. this.a = a !== undefined ? a : new Vector3();
  4837. this.b = b !== undefined ? b : new Vector3();
  4838. this.c = c !== undefined ? c : new Vector3();
  4839. }
  4840. Triangle.getNormal = function getNormal(a, b, c, target) {
  4841. if (target === undefined) {
  4842. console.warn('THREE.Triangle: .getNormal() target is now required');
  4843. target = new Vector3();
  4844. }
  4845. target.subVectors(c, b);
  4846. _v0$1.subVectors(a, b);
  4847. target.cross(_v0$1);
  4848. var targetLengthSq = target.lengthSq();
  4849. if (targetLengthSq > 0) {
  4850. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4851. }
  4852. return target.set(0, 0, 0);
  4853. } // static/instance method to calculate barycentric coordinates
  4854. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4855. ;
  4856. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4857. _v0$1.subVectors(c, a);
  4858. _v1$3.subVectors(b, a);
  4859. _v2$1.subVectors(point, a);
  4860. var dot00 = _v0$1.dot(_v0$1);
  4861. var dot01 = _v0$1.dot(_v1$3);
  4862. var dot02 = _v0$1.dot(_v2$1);
  4863. var dot11 = _v1$3.dot(_v1$3);
  4864. var dot12 = _v1$3.dot(_v2$1);
  4865. var denom = dot00 * dot11 - dot01 * dot01;
  4866. if (target === undefined) {
  4867. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4868. target = new Vector3();
  4869. } // collinear or singular triangle
  4870. if (denom === 0) {
  4871. // arbitrary location outside of triangle?
  4872. // not sure if this is the best idea, maybe should be returning undefined
  4873. return target.set(-2, -1, -1);
  4874. }
  4875. var invDenom = 1 / denom;
  4876. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4877. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4878. return target.set(1 - u - v, v, u);
  4879. };
  4880. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4881. this.getBarycoord(point, a, b, c, _v3);
  4882. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4883. };
  4884. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4885. this.getBarycoord(point, p1, p2, p3, _v3);
  4886. target.set(0, 0);
  4887. target.addScaledVector(uv1, _v3.x);
  4888. target.addScaledVector(uv2, _v3.y);
  4889. target.addScaledVector(uv3, _v3.z);
  4890. return target;
  4891. };
  4892. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4893. _v0$1.subVectors(c, b);
  4894. _v1$3.subVectors(a, b); // strictly front facing
  4895. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4896. };
  4897. var _proto = Triangle.prototype;
  4898. _proto.set = function set(a, b, c) {
  4899. this.a.copy(a);
  4900. this.b.copy(b);
  4901. this.c.copy(c);
  4902. return this;
  4903. };
  4904. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4905. this.a.copy(points[i0]);
  4906. this.b.copy(points[i1]);
  4907. this.c.copy(points[i2]);
  4908. return this;
  4909. };
  4910. _proto.clone = function clone() {
  4911. return new this.constructor().copy(this);
  4912. };
  4913. _proto.copy = function copy(triangle) {
  4914. this.a.copy(triangle.a);
  4915. this.b.copy(triangle.b);
  4916. this.c.copy(triangle.c);
  4917. return this;
  4918. };
  4919. _proto.getArea = function getArea() {
  4920. _v0$1.subVectors(this.c, this.b);
  4921. _v1$3.subVectors(this.a, this.b);
  4922. return _v0$1.cross(_v1$3).length() * 0.5;
  4923. };
  4924. _proto.getMidpoint = function getMidpoint(target) {
  4925. if (target === undefined) {
  4926. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4927. target = new Vector3();
  4928. }
  4929. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  4930. };
  4931. _proto.getNormal = function getNormal(target) {
  4932. return Triangle.getNormal(this.a, this.b, this.c, target);
  4933. };
  4934. _proto.getPlane = function getPlane(target) {
  4935. if (target === undefined) {
  4936. console.warn('THREE.Triangle: .getPlane() target is now required');
  4937. target = new Plane();
  4938. }
  4939. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  4940. };
  4941. _proto.getBarycoord = function getBarycoord(point, target) {
  4942. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  4943. };
  4944. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  4945. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  4946. };
  4947. _proto.containsPoint = function containsPoint(point) {
  4948. return Triangle.containsPoint(point, this.a, this.b, this.c);
  4949. };
  4950. _proto.isFrontFacing = function isFrontFacing(direction) {
  4951. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  4952. };
  4953. _proto.intersectsBox = function intersectsBox(box) {
  4954. return box.intersectsTriangle(this);
  4955. };
  4956. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  4957. if (target === undefined) {
  4958. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  4959. target = new Vector3();
  4960. }
  4961. var a = this.a,
  4962. b = this.b,
  4963. c = this.c;
  4964. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4965. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4966. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4967. // basically, we're distinguishing which of the voronoi regions of the triangle
  4968. // the point lies in with the minimum amount of redundant computation.
  4969. _vab.subVectors(b, a);
  4970. _vac.subVectors(c, a);
  4971. _vap.subVectors(p, a);
  4972. var d1 = _vab.dot(_vap);
  4973. var d2 = _vac.dot(_vap);
  4974. if (d1 <= 0 && d2 <= 0) {
  4975. // vertex region of A; barycentric coords (1, 0, 0)
  4976. return target.copy(a);
  4977. }
  4978. _vbp.subVectors(p, b);
  4979. var d3 = _vab.dot(_vbp);
  4980. var d4 = _vac.dot(_vbp);
  4981. if (d3 >= 0 && d4 <= d3) {
  4982. // vertex region of B; barycentric coords (0, 1, 0)
  4983. return target.copy(b);
  4984. }
  4985. var vc = d1 * d4 - d3 * d2;
  4986. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  4987. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  4988. return target.copy(a).addScaledVector(_vab, v);
  4989. }
  4990. _vcp.subVectors(p, c);
  4991. var d5 = _vab.dot(_vcp);
  4992. var d6 = _vac.dot(_vcp);
  4993. if (d6 >= 0 && d5 <= d6) {
  4994. // vertex region of C; barycentric coords (0, 0, 1)
  4995. return target.copy(c);
  4996. }
  4997. var vb = d5 * d2 - d1 * d6;
  4998. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  4999. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5000. return target.copy(a).addScaledVector(_vac, w);
  5001. }
  5002. var va = d3 * d6 - d5 * d4;
  5003. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5004. _vbc.subVectors(c, b);
  5005. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5006. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5007. } // face region
  5008. var denom = 1 / (va + vb + vc); // u = va * denom
  5009. v = vb * denom;
  5010. w = vc * denom;
  5011. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5012. };
  5013. _proto.equals = function equals(triangle) {
  5014. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5015. };
  5016. return Triangle;
  5017. }();
  5018. var _colorKeywords = {
  5019. 'aliceblue': 0xF0F8FF,
  5020. 'antiquewhite': 0xFAEBD7,
  5021. 'aqua': 0x00FFFF,
  5022. 'aquamarine': 0x7FFFD4,
  5023. 'azure': 0xF0FFFF,
  5024. 'beige': 0xF5F5DC,
  5025. 'bisque': 0xFFE4C4,
  5026. 'black': 0x000000,
  5027. 'blanchedalmond': 0xFFEBCD,
  5028. 'blue': 0x0000FF,
  5029. 'blueviolet': 0x8A2BE2,
  5030. 'brown': 0xA52A2A,
  5031. 'burlywood': 0xDEB887,
  5032. 'cadetblue': 0x5F9EA0,
  5033. 'chartreuse': 0x7FFF00,
  5034. 'chocolate': 0xD2691E,
  5035. 'coral': 0xFF7F50,
  5036. 'cornflowerblue': 0x6495ED,
  5037. 'cornsilk': 0xFFF8DC,
  5038. 'crimson': 0xDC143C,
  5039. 'cyan': 0x00FFFF,
  5040. 'darkblue': 0x00008B,
  5041. 'darkcyan': 0x008B8B,
  5042. 'darkgoldenrod': 0xB8860B,
  5043. 'darkgray': 0xA9A9A9,
  5044. 'darkgreen': 0x006400,
  5045. 'darkgrey': 0xA9A9A9,
  5046. 'darkkhaki': 0xBDB76B,
  5047. 'darkmagenta': 0x8B008B,
  5048. 'darkolivegreen': 0x556B2F,
  5049. 'darkorange': 0xFF8C00,
  5050. 'darkorchid': 0x9932CC,
  5051. 'darkred': 0x8B0000,
  5052. 'darksalmon': 0xE9967A,
  5053. 'darkseagreen': 0x8FBC8F,
  5054. 'darkslateblue': 0x483D8B,
  5055. 'darkslategray': 0x2F4F4F,
  5056. 'darkslategrey': 0x2F4F4F,
  5057. 'darkturquoise': 0x00CED1,
  5058. 'darkviolet': 0x9400D3,
  5059. 'deeppink': 0xFF1493,
  5060. 'deepskyblue': 0x00BFFF,
  5061. 'dimgray': 0x696969,
  5062. 'dimgrey': 0x696969,
  5063. 'dodgerblue': 0x1E90FF,
  5064. 'firebrick': 0xB22222,
  5065. 'floralwhite': 0xFFFAF0,
  5066. 'forestgreen': 0x228B22,
  5067. 'fuchsia': 0xFF00FF,
  5068. 'gainsboro': 0xDCDCDC,
  5069. 'ghostwhite': 0xF8F8FF,
  5070. 'gold': 0xFFD700,
  5071. 'goldenrod': 0xDAA520,
  5072. 'gray': 0x808080,
  5073. 'green': 0x008000,
  5074. 'greenyellow': 0xADFF2F,
  5075. 'grey': 0x808080,
  5076. 'honeydew': 0xF0FFF0,
  5077. 'hotpink': 0xFF69B4,
  5078. 'indianred': 0xCD5C5C,
  5079. 'indigo': 0x4B0082,
  5080. 'ivory': 0xFFFFF0,
  5081. 'khaki': 0xF0E68C,
  5082. 'lavender': 0xE6E6FA,
  5083. 'lavenderblush': 0xFFF0F5,
  5084. 'lawngreen': 0x7CFC00,
  5085. 'lemonchiffon': 0xFFFACD,
  5086. 'lightblue': 0xADD8E6,
  5087. 'lightcoral': 0xF08080,
  5088. 'lightcyan': 0xE0FFFF,
  5089. 'lightgoldenrodyellow': 0xFAFAD2,
  5090. 'lightgray': 0xD3D3D3,
  5091. 'lightgreen': 0x90EE90,
  5092. 'lightgrey': 0xD3D3D3,
  5093. 'lightpink': 0xFFB6C1,
  5094. 'lightsalmon': 0xFFA07A,
  5095. 'lightseagreen': 0x20B2AA,
  5096. 'lightskyblue': 0x87CEFA,
  5097. 'lightslategray': 0x778899,
  5098. 'lightslategrey': 0x778899,
  5099. 'lightsteelblue': 0xB0C4DE,
  5100. 'lightyellow': 0xFFFFE0,
  5101. 'lime': 0x00FF00,
  5102. 'limegreen': 0x32CD32,
  5103. 'linen': 0xFAF0E6,
  5104. 'magenta': 0xFF00FF,
  5105. 'maroon': 0x800000,
  5106. 'mediumaquamarine': 0x66CDAA,
  5107. 'mediumblue': 0x0000CD,
  5108. 'mediumorchid': 0xBA55D3,
  5109. 'mediumpurple': 0x9370DB,
  5110. 'mediumseagreen': 0x3CB371,
  5111. 'mediumslateblue': 0x7B68EE,
  5112. 'mediumspringgreen': 0x00FA9A,
  5113. 'mediumturquoise': 0x48D1CC,
  5114. 'mediumvioletred': 0xC71585,
  5115. 'midnightblue': 0x191970,
  5116. 'mintcream': 0xF5FFFA,
  5117. 'mistyrose': 0xFFE4E1,
  5118. 'moccasin': 0xFFE4B5,
  5119. 'navajowhite': 0xFFDEAD,
  5120. 'navy': 0x000080,
  5121. 'oldlace': 0xFDF5E6,
  5122. 'olive': 0x808000,
  5123. 'olivedrab': 0x6B8E23,
  5124. 'orange': 0xFFA500,
  5125. 'orangered': 0xFF4500,
  5126. 'orchid': 0xDA70D6,
  5127. 'palegoldenrod': 0xEEE8AA,
  5128. 'palegreen': 0x98FB98,
  5129. 'paleturquoise': 0xAFEEEE,
  5130. 'palevioletred': 0xDB7093,
  5131. 'papayawhip': 0xFFEFD5,
  5132. 'peachpuff': 0xFFDAB9,
  5133. 'peru': 0xCD853F,
  5134. 'pink': 0xFFC0CB,
  5135. 'plum': 0xDDA0DD,
  5136. 'powderblue': 0xB0E0E6,
  5137. 'purple': 0x800080,
  5138. 'rebeccapurple': 0x663399,
  5139. 'red': 0xFF0000,
  5140. 'rosybrown': 0xBC8F8F,
  5141. 'royalblue': 0x4169E1,
  5142. 'saddlebrown': 0x8B4513,
  5143. 'salmon': 0xFA8072,
  5144. 'sandybrown': 0xF4A460,
  5145. 'seagreen': 0x2E8B57,
  5146. 'seashell': 0xFFF5EE,
  5147. 'sienna': 0xA0522D,
  5148. 'silver': 0xC0C0C0,
  5149. 'skyblue': 0x87CEEB,
  5150. 'slateblue': 0x6A5ACD,
  5151. 'slategray': 0x708090,
  5152. 'slategrey': 0x708090,
  5153. 'snow': 0xFFFAFA,
  5154. 'springgreen': 0x00FF7F,
  5155. 'steelblue': 0x4682B4,
  5156. 'tan': 0xD2B48C,
  5157. 'teal': 0x008080,
  5158. 'thistle': 0xD8BFD8,
  5159. 'tomato': 0xFF6347,
  5160. 'turquoise': 0x40E0D0,
  5161. 'violet': 0xEE82EE,
  5162. 'wheat': 0xF5DEB3,
  5163. 'white': 0xFFFFFF,
  5164. 'whitesmoke': 0xF5F5F5,
  5165. 'yellow': 0xFFFF00,
  5166. 'yellowgreen': 0x9ACD32
  5167. };
  5168. var _hslA = {
  5169. h: 0,
  5170. s: 0,
  5171. l: 0
  5172. };
  5173. var _hslB = {
  5174. h: 0,
  5175. s: 0,
  5176. l: 0
  5177. };
  5178. function hue2rgb(p, q, t) {
  5179. if (t < 0) t += 1;
  5180. if (t > 1) t -= 1;
  5181. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5182. if (t < 1 / 2) return q;
  5183. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5184. return p;
  5185. }
  5186. function SRGBToLinear(c) {
  5187. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5188. }
  5189. function LinearToSRGB(c) {
  5190. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5191. }
  5192. var Color = /*#__PURE__*/function () {
  5193. function Color(r, g, b) {
  5194. Object.defineProperty(this, 'isColor', {
  5195. value: true
  5196. });
  5197. if (g === undefined && b === undefined) {
  5198. // r is THREE.Color, hex or string
  5199. return this.set(r);
  5200. }
  5201. return this.setRGB(r, g, b);
  5202. }
  5203. var _proto = Color.prototype;
  5204. _proto.set = function set(value) {
  5205. if (value && value.isColor) {
  5206. this.copy(value);
  5207. } else if (typeof value === 'number') {
  5208. this.setHex(value);
  5209. } else if (typeof value === 'string') {
  5210. this.setStyle(value);
  5211. }
  5212. return this;
  5213. };
  5214. _proto.setScalar = function setScalar(scalar) {
  5215. this.r = scalar;
  5216. this.g = scalar;
  5217. this.b = scalar;
  5218. return this;
  5219. };
  5220. _proto.setHex = function setHex(hex) {
  5221. hex = Math.floor(hex);
  5222. this.r = (hex >> 16 & 255) / 255;
  5223. this.g = (hex >> 8 & 255) / 255;
  5224. this.b = (hex & 255) / 255;
  5225. return this;
  5226. };
  5227. _proto.setRGB = function setRGB(r, g, b) {
  5228. this.r = r;
  5229. this.g = g;
  5230. this.b = b;
  5231. return this;
  5232. };
  5233. _proto.setHSL = function setHSL(h, s, l) {
  5234. // h,s,l ranges are in 0.0 - 1.0
  5235. h = MathUtils.euclideanModulo(h, 1);
  5236. s = MathUtils.clamp(s, 0, 1);
  5237. l = MathUtils.clamp(l, 0, 1);
  5238. if (s === 0) {
  5239. this.r = this.g = this.b = l;
  5240. } else {
  5241. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5242. var q = 2 * l - p;
  5243. this.r = hue2rgb(q, p, h + 1 / 3);
  5244. this.g = hue2rgb(q, p, h);
  5245. this.b = hue2rgb(q, p, h - 1 / 3);
  5246. }
  5247. return this;
  5248. };
  5249. _proto.setStyle = function setStyle(style) {
  5250. function handleAlpha(string) {
  5251. if (string === undefined) return;
  5252. if (parseFloat(string) < 1) {
  5253. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5254. }
  5255. }
  5256. var m;
  5257. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5258. // rgb / hsl
  5259. var color;
  5260. var name = m[1];
  5261. var components = m[2];
  5262. switch (name) {
  5263. case 'rgb':
  5264. case 'rgba':
  5265. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5266. // rgb(255,0,0) rgba(255,0,0,0.5)
  5267. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5268. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5269. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5270. handleAlpha(color[5]);
  5271. return this;
  5272. }
  5273. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5274. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5275. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5276. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5277. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5278. handleAlpha(color[5]);
  5279. return this;
  5280. }
  5281. break;
  5282. case 'hsl':
  5283. case 'hsla':
  5284. if (color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5285. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5286. var h = parseFloat(color[1]) / 360;
  5287. var s = parseInt(color[2], 10) / 100;
  5288. var l = parseInt(color[3], 10) / 100;
  5289. handleAlpha(color[5]);
  5290. return this.setHSL(h, s, l);
  5291. }
  5292. break;
  5293. }
  5294. } else if (m = /^\#([A-Fa-f0-9]+)$/.exec(style)) {
  5295. // hex color
  5296. var hex = m[1];
  5297. var size = hex.length;
  5298. if (size === 3) {
  5299. // #ff0
  5300. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5301. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5302. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5303. return this;
  5304. } else if (size === 6) {
  5305. // #ff0000
  5306. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5307. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5308. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5309. return this;
  5310. }
  5311. }
  5312. if (style && style.length > 0) {
  5313. return this.setColorName(style);
  5314. }
  5315. return this;
  5316. };
  5317. _proto.setColorName = function setColorName(style) {
  5318. // color keywords
  5319. var hex = _colorKeywords[style];
  5320. if (hex !== undefined) {
  5321. // red
  5322. this.setHex(hex);
  5323. } else {
  5324. // unknown color
  5325. console.warn('THREE.Color: Unknown color ' + style);
  5326. }
  5327. return this;
  5328. };
  5329. _proto.clone = function clone() {
  5330. return new this.constructor(this.r, this.g, this.b);
  5331. };
  5332. _proto.copy = function copy(color) {
  5333. this.r = color.r;
  5334. this.g = color.g;
  5335. this.b = color.b;
  5336. return this;
  5337. };
  5338. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5339. if (gammaFactor === void 0) {
  5340. gammaFactor = 2.0;
  5341. }
  5342. this.r = Math.pow(color.r, gammaFactor);
  5343. this.g = Math.pow(color.g, gammaFactor);
  5344. this.b = Math.pow(color.b, gammaFactor);
  5345. return this;
  5346. };
  5347. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5348. if (gammaFactor === void 0) {
  5349. gammaFactor = 2.0;
  5350. }
  5351. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5352. this.r = Math.pow(color.r, safeInverse);
  5353. this.g = Math.pow(color.g, safeInverse);
  5354. this.b = Math.pow(color.b, safeInverse);
  5355. return this;
  5356. };
  5357. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5358. this.copyGammaToLinear(this, gammaFactor);
  5359. return this;
  5360. };
  5361. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5362. this.copyLinearToGamma(this, gammaFactor);
  5363. return this;
  5364. };
  5365. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5366. this.r = SRGBToLinear(color.r);
  5367. this.g = SRGBToLinear(color.g);
  5368. this.b = SRGBToLinear(color.b);
  5369. return this;
  5370. };
  5371. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5372. this.r = LinearToSRGB(color.r);
  5373. this.g = LinearToSRGB(color.g);
  5374. this.b = LinearToSRGB(color.b);
  5375. return this;
  5376. };
  5377. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5378. this.copySRGBToLinear(this);
  5379. return this;
  5380. };
  5381. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5382. this.copyLinearToSRGB(this);
  5383. return this;
  5384. };
  5385. _proto.getHex = function getHex() {
  5386. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5387. };
  5388. _proto.getHexString = function getHexString() {
  5389. return ('000000' + this.getHex().toString(16)).slice(-6);
  5390. };
  5391. _proto.getHSL = function getHSL(target) {
  5392. // h,s,l ranges are in 0.0 - 1.0
  5393. if (target === undefined) {
  5394. console.warn('THREE.Color: .getHSL() target is now required');
  5395. target = {
  5396. h: 0,
  5397. s: 0,
  5398. l: 0
  5399. };
  5400. }
  5401. var r = this.r,
  5402. g = this.g,
  5403. b = this.b;
  5404. var max = Math.max(r, g, b);
  5405. var min = Math.min(r, g, b);
  5406. var hue, saturation;
  5407. var lightness = (min + max) / 2.0;
  5408. if (min === max) {
  5409. hue = 0;
  5410. saturation = 0;
  5411. } else {
  5412. var delta = max - min;
  5413. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5414. switch (max) {
  5415. case r:
  5416. hue = (g - b) / delta + (g < b ? 6 : 0);
  5417. break;
  5418. case g:
  5419. hue = (b - r) / delta + 2;
  5420. break;
  5421. case b:
  5422. hue = (r - g) / delta + 4;
  5423. break;
  5424. }
  5425. hue /= 6;
  5426. }
  5427. target.h = hue;
  5428. target.s = saturation;
  5429. target.l = lightness;
  5430. return target;
  5431. };
  5432. _proto.getStyle = function getStyle() {
  5433. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5434. };
  5435. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5436. this.getHSL(_hslA);
  5437. _hslA.h += h;
  5438. _hslA.s += s;
  5439. _hslA.l += l;
  5440. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5441. return this;
  5442. };
  5443. _proto.add = function add(color) {
  5444. this.r += color.r;
  5445. this.g += color.g;
  5446. this.b += color.b;
  5447. return this;
  5448. };
  5449. _proto.addColors = function addColors(color1, color2) {
  5450. this.r = color1.r + color2.r;
  5451. this.g = color1.g + color2.g;
  5452. this.b = color1.b + color2.b;
  5453. return this;
  5454. };
  5455. _proto.addScalar = function addScalar(s) {
  5456. this.r += s;
  5457. this.g += s;
  5458. this.b += s;
  5459. return this;
  5460. };
  5461. _proto.sub = function sub(color) {
  5462. this.r = Math.max(0, this.r - color.r);
  5463. this.g = Math.max(0, this.g - color.g);
  5464. this.b = Math.max(0, this.b - color.b);
  5465. return this;
  5466. };
  5467. _proto.multiply = function multiply(color) {
  5468. this.r *= color.r;
  5469. this.g *= color.g;
  5470. this.b *= color.b;
  5471. return this;
  5472. };
  5473. _proto.multiplyScalar = function multiplyScalar(s) {
  5474. this.r *= s;
  5475. this.g *= s;
  5476. this.b *= s;
  5477. return this;
  5478. };
  5479. _proto.lerp = function lerp(color, alpha) {
  5480. this.r += (color.r - this.r) * alpha;
  5481. this.g += (color.g - this.g) * alpha;
  5482. this.b += (color.b - this.b) * alpha;
  5483. return this;
  5484. };
  5485. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5486. this.getHSL(_hslA);
  5487. color.getHSL(_hslB);
  5488. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5489. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5490. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5491. this.setHSL(h, s, l);
  5492. return this;
  5493. };
  5494. _proto.equals = function equals(c) {
  5495. return c.r === this.r && c.g === this.g && c.b === this.b;
  5496. };
  5497. _proto.fromArray = function fromArray(array, offset) {
  5498. if (offset === void 0) {
  5499. offset = 0;
  5500. }
  5501. this.r = array[offset];
  5502. this.g = array[offset + 1];
  5503. this.b = array[offset + 2];
  5504. return this;
  5505. };
  5506. _proto.toArray = function toArray(array, offset) {
  5507. if (array === void 0) {
  5508. array = [];
  5509. }
  5510. if (offset === void 0) {
  5511. offset = 0;
  5512. }
  5513. array[offset] = this.r;
  5514. array[offset + 1] = this.g;
  5515. array[offset + 2] = this.b;
  5516. return array;
  5517. };
  5518. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5519. this.r = attribute.getX(index);
  5520. this.g = attribute.getY(index);
  5521. this.b = attribute.getZ(index);
  5522. if (attribute.normalized === true) {
  5523. // assuming Uint8Array
  5524. this.r /= 255;
  5525. this.g /= 255;
  5526. this.b /= 255;
  5527. }
  5528. return this;
  5529. };
  5530. _proto.toJSON = function toJSON() {
  5531. return this.getHex();
  5532. };
  5533. return Color;
  5534. }();
  5535. Color.NAMES = _colorKeywords;
  5536. Color.prototype.r = 1;
  5537. Color.prototype.g = 1;
  5538. Color.prototype.b = 1;
  5539. var Face3 = /*#__PURE__*/function () {
  5540. function Face3(a, b, c, normal, color, materialIndex) {
  5541. this.a = a;
  5542. this.b = b;
  5543. this.c = c;
  5544. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5545. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5546. this.color = color && color.isColor ? color : new Color();
  5547. this.vertexColors = Array.isArray(color) ? color : [];
  5548. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5549. }
  5550. var _proto = Face3.prototype;
  5551. _proto.clone = function clone() {
  5552. return new this.constructor().copy(this);
  5553. };
  5554. _proto.copy = function copy(source) {
  5555. this.a = source.a;
  5556. this.b = source.b;
  5557. this.c = source.c;
  5558. this.normal.copy(source.normal);
  5559. this.color.copy(source.color);
  5560. this.materialIndex = source.materialIndex;
  5561. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5562. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5563. }
  5564. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5565. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5566. }
  5567. return this;
  5568. };
  5569. return Face3;
  5570. }();
  5571. var materialId = 0;
  5572. function Material() {
  5573. Object.defineProperty(this, 'id', {
  5574. value: materialId++
  5575. });
  5576. this.uuid = MathUtils.generateUUID();
  5577. this.name = '';
  5578. this.type = 'Material';
  5579. this.fog = true;
  5580. this.blending = NormalBlending;
  5581. this.side = FrontSide;
  5582. this.flatShading = false;
  5583. this.vertexColors = false;
  5584. this.opacity = 1;
  5585. this.transparent = false;
  5586. this.blendSrc = SrcAlphaFactor;
  5587. this.blendDst = OneMinusSrcAlphaFactor;
  5588. this.blendEquation = AddEquation;
  5589. this.blendSrcAlpha = null;
  5590. this.blendDstAlpha = null;
  5591. this.blendEquationAlpha = null;
  5592. this.depthFunc = LessEqualDepth;
  5593. this.depthTest = true;
  5594. this.depthWrite = true;
  5595. this.stencilWriteMask = 0xff;
  5596. this.stencilFunc = AlwaysStencilFunc;
  5597. this.stencilRef = 0;
  5598. this.stencilFuncMask = 0xff;
  5599. this.stencilFail = KeepStencilOp;
  5600. this.stencilZFail = KeepStencilOp;
  5601. this.stencilZPass = KeepStencilOp;
  5602. this.stencilWrite = false;
  5603. this.clippingPlanes = null;
  5604. this.clipIntersection = false;
  5605. this.clipShadows = false;
  5606. this.shadowSide = null;
  5607. this.colorWrite = true;
  5608. this.precision = null; // override the renderer's default precision for this material
  5609. this.polygonOffset = false;
  5610. this.polygonOffsetFactor = 0;
  5611. this.polygonOffsetUnits = 0;
  5612. this.dithering = false;
  5613. this.alphaTest = 0;
  5614. this.premultipliedAlpha = false;
  5615. this.visible = true;
  5616. this.toneMapped = true;
  5617. this.userData = {};
  5618. this.version = 0;
  5619. }
  5620. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5621. constructor: Material,
  5622. isMaterial: true,
  5623. onBeforeCompile: function onBeforeCompile()
  5624. /* shaderobject, renderer */
  5625. {},
  5626. customProgramCacheKey: function customProgramCacheKey() {
  5627. return this.onBeforeCompile.toString();
  5628. },
  5629. setValues: function setValues(values) {
  5630. if (values === undefined) return;
  5631. for (var key in values) {
  5632. var newValue = values[key];
  5633. if (newValue === undefined) {
  5634. console.warn("THREE.Material: '" + key + "' parameter is undefined.");
  5635. continue;
  5636. } // for backward compatability if shading is set in the constructor
  5637. if (key === 'shading') {
  5638. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5639. this.flatShading = newValue === FlatShading ? true : false;
  5640. continue;
  5641. }
  5642. var currentValue = this[key];
  5643. if (currentValue === undefined) {
  5644. console.warn("THREE." + this.type + ": '" + key + "' is not a property of this material.");
  5645. continue;
  5646. }
  5647. if (currentValue && currentValue.isColor) {
  5648. currentValue.set(newValue);
  5649. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5650. currentValue.copy(newValue);
  5651. } else {
  5652. this[key] = newValue;
  5653. }
  5654. }
  5655. },
  5656. toJSON: function toJSON(meta) {
  5657. var isRoot = meta === undefined || typeof meta === 'string';
  5658. if (isRoot) {
  5659. meta = {
  5660. textures: {},
  5661. images: {}
  5662. };
  5663. }
  5664. var data = {
  5665. metadata: {
  5666. version: 4.5,
  5667. type: 'Material',
  5668. generator: 'Material.toJSON'
  5669. }
  5670. }; // standard Material serialization
  5671. data.uuid = this.uuid;
  5672. data.type = this.type;
  5673. if (this.name !== '') data.name = this.name;
  5674. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5675. if (this.roughness !== undefined) data.roughness = this.roughness;
  5676. if (this.metalness !== undefined) data.metalness = this.metalness;
  5677. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5678. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5679. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5680. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5681. if (this.shininess !== undefined) data.shininess = this.shininess;
  5682. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5683. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5684. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5685. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5686. }
  5687. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5688. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5689. }
  5690. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5691. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5692. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5693. }
  5694. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5695. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5696. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5697. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5698. if (this.aoMap && this.aoMap.isTexture) {
  5699. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5700. data.aoMapIntensity = this.aoMapIntensity;
  5701. }
  5702. if (this.bumpMap && this.bumpMap.isTexture) {
  5703. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5704. data.bumpScale = this.bumpScale;
  5705. }
  5706. if (this.normalMap && this.normalMap.isTexture) {
  5707. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5708. data.normalMapType = this.normalMapType;
  5709. data.normalScale = this.normalScale.toArray();
  5710. }
  5711. if (this.displacementMap && this.displacementMap.isTexture) {
  5712. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5713. data.displacementScale = this.displacementScale;
  5714. data.displacementBias = this.displacementBias;
  5715. }
  5716. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5717. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5718. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5719. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5720. if (this.envMap && this.envMap.isTexture) {
  5721. data.envMap = this.envMap.toJSON(meta).uuid;
  5722. data.reflectivity = this.reflectivity; // Scale behind envMap
  5723. data.refractionRatio = this.refractionRatio;
  5724. if (this.combine !== undefined) data.combine = this.combine;
  5725. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5726. }
  5727. if (this.gradientMap && this.gradientMap.isTexture) {
  5728. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5729. }
  5730. if (this.size !== undefined) data.size = this.size;
  5731. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5732. if (this.blending !== NormalBlending) data.blending = this.blending;
  5733. if (this.flatShading === true) data.flatShading = this.flatShading;
  5734. if (this.side !== FrontSide) data.side = this.side;
  5735. if (this.vertexColors) data.vertexColors = true;
  5736. if (this.opacity < 1) data.opacity = this.opacity;
  5737. if (this.transparent === true) data.transparent = this.transparent;
  5738. data.depthFunc = this.depthFunc;
  5739. data.depthTest = this.depthTest;
  5740. data.depthWrite = this.depthWrite;
  5741. data.stencilWrite = this.stencilWrite;
  5742. data.stencilWriteMask = this.stencilWriteMask;
  5743. data.stencilFunc = this.stencilFunc;
  5744. data.stencilRef = this.stencilRef;
  5745. data.stencilFuncMask = this.stencilFuncMask;
  5746. data.stencilFail = this.stencilFail;
  5747. data.stencilZFail = this.stencilZFail;
  5748. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5749. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5750. if (this.polygonOffset === true) data.polygonOffset = true;
  5751. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5752. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5753. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5754. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5755. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5756. if (this.scale !== undefined) data.scale = this.scale;
  5757. if (this.dithering === true) data.dithering = true;
  5758. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5759. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5760. if (this.wireframe === true) data.wireframe = this.wireframe;
  5761. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5762. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5763. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5764. if (this.morphTargets === true) data.morphTargets = true;
  5765. if (this.morphNormals === true) data.morphNormals = true;
  5766. if (this.skinning === true) data.skinning = true;
  5767. if (this.visible === false) data.visible = false;
  5768. if (this.toneMapped === false) data.toneMapped = false;
  5769. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5770. function extractFromCache(cache) {
  5771. var values = [];
  5772. for (var key in cache) {
  5773. var _data = cache[key];
  5774. delete _data.metadata;
  5775. values.push(_data);
  5776. }
  5777. return values;
  5778. }
  5779. if (isRoot) {
  5780. var textures = extractFromCache(meta.textures);
  5781. var images = extractFromCache(meta.images);
  5782. if (textures.length > 0) data.textures = textures;
  5783. if (images.length > 0) data.images = images;
  5784. }
  5785. return data;
  5786. },
  5787. clone: function clone() {
  5788. return new this.constructor().copy(this);
  5789. },
  5790. copy: function copy(source) {
  5791. this.name = source.name;
  5792. this.fog = source.fog;
  5793. this.blending = source.blending;
  5794. this.side = source.side;
  5795. this.flatShading = source.flatShading;
  5796. this.vertexColors = source.vertexColors;
  5797. this.opacity = source.opacity;
  5798. this.transparent = source.transparent;
  5799. this.blendSrc = source.blendSrc;
  5800. this.blendDst = source.blendDst;
  5801. this.blendEquation = source.blendEquation;
  5802. this.blendSrcAlpha = source.blendSrcAlpha;
  5803. this.blendDstAlpha = source.blendDstAlpha;
  5804. this.blendEquationAlpha = source.blendEquationAlpha;
  5805. this.depthFunc = source.depthFunc;
  5806. this.depthTest = source.depthTest;
  5807. this.depthWrite = source.depthWrite;
  5808. this.stencilWriteMask = source.stencilWriteMask;
  5809. this.stencilFunc = source.stencilFunc;
  5810. this.stencilRef = source.stencilRef;
  5811. this.stencilFuncMask = source.stencilFuncMask;
  5812. this.stencilFail = source.stencilFail;
  5813. this.stencilZFail = source.stencilZFail;
  5814. this.stencilZPass = source.stencilZPass;
  5815. this.stencilWrite = source.stencilWrite;
  5816. var srcPlanes = source.clippingPlanes;
  5817. var dstPlanes = null;
  5818. if (srcPlanes !== null) {
  5819. var n = srcPlanes.length;
  5820. dstPlanes = new Array(n);
  5821. for (var i = 0; i !== n; ++i) {
  5822. dstPlanes[i] = srcPlanes[i].clone();
  5823. }
  5824. }
  5825. this.clippingPlanes = dstPlanes;
  5826. this.clipIntersection = source.clipIntersection;
  5827. this.clipShadows = source.clipShadows;
  5828. this.shadowSide = source.shadowSide;
  5829. this.colorWrite = source.colorWrite;
  5830. this.precision = source.precision;
  5831. this.polygonOffset = source.polygonOffset;
  5832. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5833. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5834. this.dithering = source.dithering;
  5835. this.alphaTest = source.alphaTest;
  5836. this.premultipliedAlpha = source.premultipliedAlpha;
  5837. this.visible = source.visible;
  5838. this.toneMapped = source.toneMapped;
  5839. this.userData = JSON.parse(JSON.stringify(source.userData));
  5840. return this;
  5841. },
  5842. dispose: function dispose() {
  5843. this.dispatchEvent({
  5844. type: 'dispose'
  5845. });
  5846. }
  5847. });
  5848. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5849. set: function set(value) {
  5850. if (value === true) this.version++;
  5851. }
  5852. });
  5853. /**
  5854. * parameters = {
  5855. * color: <hex>,
  5856. * opacity: <float>,
  5857. * map: new THREE.Texture( <Image> ),
  5858. *
  5859. * lightMap: new THREE.Texture( <Image> ),
  5860. * lightMapIntensity: <float>
  5861. *
  5862. * aoMap: new THREE.Texture( <Image> ),
  5863. * aoMapIntensity: <float>
  5864. *
  5865. * specularMap: new THREE.Texture( <Image> ),
  5866. *
  5867. * alphaMap: new THREE.Texture( <Image> ),
  5868. *
  5869. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5870. * combine: THREE.Multiply,
  5871. * reflectivity: <float>,
  5872. * refractionRatio: <float>,
  5873. *
  5874. * depthTest: <bool>,
  5875. * depthWrite: <bool>,
  5876. *
  5877. * wireframe: <boolean>,
  5878. * wireframeLinewidth: <float>,
  5879. *
  5880. * skinning: <bool>,
  5881. * morphTargets: <bool>
  5882. * }
  5883. */
  5884. function MeshBasicMaterial(parameters) {
  5885. Material.call(this);
  5886. this.type = 'MeshBasicMaterial';
  5887. this.color = new Color(0xffffff); // emissive
  5888. this.map = null;
  5889. this.lightMap = null;
  5890. this.lightMapIntensity = 1.0;
  5891. this.aoMap = null;
  5892. this.aoMapIntensity = 1.0;
  5893. this.specularMap = null;
  5894. this.alphaMap = null;
  5895. this.envMap = null;
  5896. this.combine = MultiplyOperation;
  5897. this.reflectivity = 1;
  5898. this.refractionRatio = 0.98;
  5899. this.wireframe = false;
  5900. this.wireframeLinewidth = 1;
  5901. this.wireframeLinecap = 'round';
  5902. this.wireframeLinejoin = 'round';
  5903. this.skinning = false;
  5904. this.morphTargets = false;
  5905. this.setValues(parameters);
  5906. }
  5907. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5908. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5909. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5910. MeshBasicMaterial.prototype.copy = function (source) {
  5911. Material.prototype.copy.call(this, source);
  5912. this.color.copy(source.color);
  5913. this.map = source.map;
  5914. this.lightMap = source.lightMap;
  5915. this.lightMapIntensity = source.lightMapIntensity;
  5916. this.aoMap = source.aoMap;
  5917. this.aoMapIntensity = source.aoMapIntensity;
  5918. this.specularMap = source.specularMap;
  5919. this.alphaMap = source.alphaMap;
  5920. this.envMap = source.envMap;
  5921. this.combine = source.combine;
  5922. this.reflectivity = source.reflectivity;
  5923. this.refractionRatio = source.refractionRatio;
  5924. this.wireframe = source.wireframe;
  5925. this.wireframeLinewidth = source.wireframeLinewidth;
  5926. this.wireframeLinecap = source.wireframeLinecap;
  5927. this.wireframeLinejoin = source.wireframeLinejoin;
  5928. this.skinning = source.skinning;
  5929. this.morphTargets = source.morphTargets;
  5930. return this;
  5931. };
  5932. var _vector$3 = new Vector3();
  5933. var _vector2$1 = new Vector2();
  5934. function BufferAttribute(array, itemSize, normalized) {
  5935. if (Array.isArray(array)) {
  5936. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  5937. }
  5938. this.name = '';
  5939. this.array = array;
  5940. this.itemSize = itemSize;
  5941. this.count = array !== undefined ? array.length / itemSize : 0;
  5942. this.normalized = normalized === true;
  5943. this.usage = StaticDrawUsage;
  5944. this.updateRange = {
  5945. offset: 0,
  5946. count: -1
  5947. };
  5948. this.version = 0;
  5949. }
  5950. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  5951. set: function set(value) {
  5952. if (value === true) this.version++;
  5953. }
  5954. });
  5955. Object.assign(BufferAttribute.prototype, {
  5956. isBufferAttribute: true,
  5957. onUploadCallback: function onUploadCallback() {},
  5958. setUsage: function setUsage(value) {
  5959. this.usage = value;
  5960. return this;
  5961. },
  5962. copy: function copy(source) {
  5963. this.name = source.name;
  5964. this.array = new source.array.constructor(source.array);
  5965. this.itemSize = source.itemSize;
  5966. this.count = source.count;
  5967. this.normalized = source.normalized;
  5968. this.usage = source.usage;
  5969. return this;
  5970. },
  5971. copyAt: function copyAt(index1, attribute, index2) {
  5972. index1 *= this.itemSize;
  5973. index2 *= attribute.itemSize;
  5974. for (var i = 0, l = this.itemSize; i < l; i++) {
  5975. this.array[index1 + i] = attribute.array[index2 + i];
  5976. }
  5977. return this;
  5978. },
  5979. copyArray: function copyArray(array) {
  5980. this.array.set(array);
  5981. return this;
  5982. },
  5983. copyColorsArray: function copyColorsArray(colors) {
  5984. var array = this.array;
  5985. var offset = 0;
  5986. for (var i = 0, l = colors.length; i < l; i++) {
  5987. var color = colors[i];
  5988. if (color === undefined) {
  5989. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  5990. color = new Color();
  5991. }
  5992. array[offset++] = color.r;
  5993. array[offset++] = color.g;
  5994. array[offset++] = color.b;
  5995. }
  5996. return this;
  5997. },
  5998. copyVector2sArray: function copyVector2sArray(vectors) {
  5999. var array = this.array;
  6000. var offset = 0;
  6001. for (var i = 0, l = vectors.length; i < l; i++) {
  6002. var vector = vectors[i];
  6003. if (vector === undefined) {
  6004. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6005. vector = new Vector2();
  6006. }
  6007. array[offset++] = vector.x;
  6008. array[offset++] = vector.y;
  6009. }
  6010. return this;
  6011. },
  6012. copyVector3sArray: function copyVector3sArray(vectors) {
  6013. var array = this.array;
  6014. var offset = 0;
  6015. for (var i = 0, l = vectors.length; i < l; i++) {
  6016. var vector = vectors[i];
  6017. if (vector === undefined) {
  6018. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6019. vector = new Vector3();
  6020. }
  6021. array[offset++] = vector.x;
  6022. array[offset++] = vector.y;
  6023. array[offset++] = vector.z;
  6024. }
  6025. return this;
  6026. },
  6027. copyVector4sArray: function copyVector4sArray(vectors) {
  6028. var array = this.array;
  6029. var offset = 0;
  6030. for (var i = 0, l = vectors.length; i < l; i++) {
  6031. var vector = vectors[i];
  6032. if (vector === undefined) {
  6033. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6034. vector = new Vector4();
  6035. }
  6036. array[offset++] = vector.x;
  6037. array[offset++] = vector.y;
  6038. array[offset++] = vector.z;
  6039. array[offset++] = vector.w;
  6040. }
  6041. return this;
  6042. },
  6043. applyMatrix3: function applyMatrix3(m) {
  6044. if (this.itemSize === 2) {
  6045. for (var i = 0, l = this.count; i < l; i++) {
  6046. _vector2$1.fromBufferAttribute(this, i);
  6047. _vector2$1.applyMatrix3(m);
  6048. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6049. }
  6050. } else if (this.itemSize === 3) {
  6051. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6052. _vector$3.fromBufferAttribute(this, _i);
  6053. _vector$3.applyMatrix3(m);
  6054. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6055. }
  6056. }
  6057. return this;
  6058. },
  6059. applyMatrix4: function applyMatrix4(m) {
  6060. for (var i = 0, l = this.count; i < l; i++) {
  6061. _vector$3.x = this.getX(i);
  6062. _vector$3.y = this.getY(i);
  6063. _vector$3.z = this.getZ(i);
  6064. _vector$3.applyMatrix4(m);
  6065. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6066. }
  6067. return this;
  6068. },
  6069. applyNormalMatrix: function applyNormalMatrix(m) {
  6070. for (var i = 0, l = this.count; i < l; i++) {
  6071. _vector$3.x = this.getX(i);
  6072. _vector$3.y = this.getY(i);
  6073. _vector$3.z = this.getZ(i);
  6074. _vector$3.applyNormalMatrix(m);
  6075. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6076. }
  6077. return this;
  6078. },
  6079. transformDirection: function transformDirection(m) {
  6080. for (var i = 0, l = this.count; i < l; i++) {
  6081. _vector$3.x = this.getX(i);
  6082. _vector$3.y = this.getY(i);
  6083. _vector$3.z = this.getZ(i);
  6084. _vector$3.transformDirection(m);
  6085. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6086. }
  6087. return this;
  6088. },
  6089. set: function set(value, offset) {
  6090. if (offset === void 0) {
  6091. offset = 0;
  6092. }
  6093. this.array.set(value, offset);
  6094. return this;
  6095. },
  6096. getX: function getX(index) {
  6097. return this.array[index * this.itemSize];
  6098. },
  6099. setX: function setX(index, x) {
  6100. this.array[index * this.itemSize] = x;
  6101. return this;
  6102. },
  6103. getY: function getY(index) {
  6104. return this.array[index * this.itemSize + 1];
  6105. },
  6106. setY: function setY(index, y) {
  6107. this.array[index * this.itemSize + 1] = y;
  6108. return this;
  6109. },
  6110. getZ: function getZ(index) {
  6111. return this.array[index * this.itemSize + 2];
  6112. },
  6113. setZ: function setZ(index, z) {
  6114. this.array[index * this.itemSize + 2] = z;
  6115. return this;
  6116. },
  6117. getW: function getW(index) {
  6118. return this.array[index * this.itemSize + 3];
  6119. },
  6120. setW: function setW(index, w) {
  6121. this.array[index * this.itemSize + 3] = w;
  6122. return this;
  6123. },
  6124. setXY: function setXY(index, x, y) {
  6125. index *= this.itemSize;
  6126. this.array[index + 0] = x;
  6127. this.array[index + 1] = y;
  6128. return this;
  6129. },
  6130. setXYZ: function setXYZ(index, x, y, z) {
  6131. index *= this.itemSize;
  6132. this.array[index + 0] = x;
  6133. this.array[index + 1] = y;
  6134. this.array[index + 2] = z;
  6135. return this;
  6136. },
  6137. setXYZW: function setXYZW(index, x, y, z, w) {
  6138. index *= this.itemSize;
  6139. this.array[index + 0] = x;
  6140. this.array[index + 1] = y;
  6141. this.array[index + 2] = z;
  6142. this.array[index + 3] = w;
  6143. return this;
  6144. },
  6145. onUpload: function onUpload(callback) {
  6146. this.onUploadCallback = callback;
  6147. return this;
  6148. },
  6149. clone: function clone() {
  6150. return new this.constructor(this.array, this.itemSize).copy(this);
  6151. },
  6152. toJSON: function toJSON() {
  6153. return {
  6154. itemSize: this.itemSize,
  6155. type: this.array.constructor.name,
  6156. array: Array.prototype.slice.call(this.array),
  6157. normalized: this.normalized
  6158. };
  6159. }
  6160. }); //
  6161. function Int8BufferAttribute(array, itemSize, normalized) {
  6162. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6163. }
  6164. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6165. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6166. function Uint8BufferAttribute(array, itemSize, normalized) {
  6167. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6168. }
  6169. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6170. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6171. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6172. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6173. }
  6174. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6175. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6176. function Int16BufferAttribute(array, itemSize, normalized) {
  6177. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6178. }
  6179. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6180. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6181. function Uint16BufferAttribute(array, itemSize, normalized) {
  6182. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6183. }
  6184. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6185. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6186. function Int32BufferAttribute(array, itemSize, normalized) {
  6187. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6188. }
  6189. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6190. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6191. function Uint32BufferAttribute(array, itemSize, normalized) {
  6192. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6193. }
  6194. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6195. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6196. function Float16BufferAttribute(array, itemSize, normalized) {
  6197. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6198. }
  6199. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6200. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6201. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6202. function Float32BufferAttribute(array, itemSize, normalized) {
  6203. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6204. }
  6205. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6206. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6207. function Float64BufferAttribute(array, itemSize, normalized) {
  6208. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6209. }
  6210. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6211. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6212. var DirectGeometry = /*#__PURE__*/function () {
  6213. function DirectGeometry() {
  6214. this.vertices = [];
  6215. this.normals = [];
  6216. this.colors = [];
  6217. this.uvs = [];
  6218. this.uvs2 = [];
  6219. this.groups = [];
  6220. this.morphTargets = {};
  6221. this.skinWeights = [];
  6222. this.skinIndices = []; // this.lineDistances = [];
  6223. this.boundingBox = null;
  6224. this.boundingSphere = null; // update flags
  6225. this.verticesNeedUpdate = false;
  6226. this.normalsNeedUpdate = false;
  6227. this.colorsNeedUpdate = false;
  6228. this.uvsNeedUpdate = false;
  6229. this.groupsNeedUpdate = false;
  6230. }
  6231. var _proto = DirectGeometry.prototype;
  6232. _proto.computeGroups = function computeGroups(geometry) {
  6233. var groups = [];
  6234. var group, i;
  6235. var materialIndex = undefined;
  6236. var faces = geometry.faces;
  6237. for (i = 0; i < faces.length; i++) {
  6238. var face = faces[i]; // materials
  6239. if (face.materialIndex !== materialIndex) {
  6240. materialIndex = face.materialIndex;
  6241. if (group !== undefined) {
  6242. group.count = i * 3 - group.start;
  6243. groups.push(group);
  6244. }
  6245. group = {
  6246. start: i * 3,
  6247. materialIndex: materialIndex
  6248. };
  6249. }
  6250. }
  6251. if (group !== undefined) {
  6252. group.count = i * 3 - group.start;
  6253. groups.push(group);
  6254. }
  6255. this.groups = groups;
  6256. };
  6257. _proto.fromGeometry = function fromGeometry(geometry) {
  6258. var faces = geometry.faces;
  6259. var vertices = geometry.vertices;
  6260. var faceVertexUvs = geometry.faceVertexUvs;
  6261. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6262. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6263. var morphTargets = geometry.morphTargets;
  6264. var morphTargetsLength = morphTargets.length;
  6265. var morphTargetsPosition;
  6266. if (morphTargetsLength > 0) {
  6267. morphTargetsPosition = [];
  6268. for (var i = 0; i < morphTargetsLength; i++) {
  6269. morphTargetsPosition[i] = {
  6270. name: morphTargets[i].name,
  6271. data: []
  6272. };
  6273. }
  6274. this.morphTargets.position = morphTargetsPosition;
  6275. }
  6276. var morphNormals = geometry.morphNormals;
  6277. var morphNormalsLength = morphNormals.length;
  6278. var morphTargetsNormal;
  6279. if (morphNormalsLength > 0) {
  6280. morphTargetsNormal = [];
  6281. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6282. morphTargetsNormal[_i] = {
  6283. name: morphNormals[_i].name,
  6284. data: []
  6285. };
  6286. }
  6287. this.morphTargets.normal = morphTargetsNormal;
  6288. } // skins
  6289. var skinIndices = geometry.skinIndices;
  6290. var skinWeights = geometry.skinWeights;
  6291. var hasSkinIndices = skinIndices.length === vertices.length;
  6292. var hasSkinWeights = skinWeights.length === vertices.length; //
  6293. if (vertices.length > 0 && faces.length === 0) {
  6294. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6295. }
  6296. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6297. var face = faces[_i2];
  6298. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6299. var vertexNormals = face.vertexNormals;
  6300. if (vertexNormals.length === 3) {
  6301. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6302. } else {
  6303. var normal = face.normal;
  6304. this.normals.push(normal, normal, normal);
  6305. }
  6306. var vertexColors = face.vertexColors;
  6307. if (vertexColors.length === 3) {
  6308. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6309. } else {
  6310. var color = face.color;
  6311. this.colors.push(color, color, color);
  6312. }
  6313. if (hasFaceVertexUv === true) {
  6314. var vertexUvs = faceVertexUvs[0][_i2];
  6315. if (vertexUvs !== undefined) {
  6316. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6317. } else {
  6318. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6319. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6320. }
  6321. }
  6322. if (hasFaceVertexUv2 === true) {
  6323. var _vertexUvs = faceVertexUvs[1][_i2];
  6324. if (_vertexUvs !== undefined) {
  6325. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6326. } else {
  6327. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6328. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6329. }
  6330. } // morphs
  6331. for (var j = 0; j < morphTargetsLength; j++) {
  6332. var morphTarget = morphTargets[j].vertices;
  6333. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6334. }
  6335. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6336. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6337. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6338. } // skins
  6339. if (hasSkinIndices) {
  6340. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6341. }
  6342. if (hasSkinWeights) {
  6343. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6344. }
  6345. }
  6346. this.computeGroups(geometry);
  6347. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6348. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6349. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6350. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6351. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6352. if (geometry.boundingSphere !== null) {
  6353. this.boundingSphere = geometry.boundingSphere.clone();
  6354. }
  6355. if (geometry.boundingBox !== null) {
  6356. this.boundingBox = geometry.boundingBox.clone();
  6357. }
  6358. return this;
  6359. };
  6360. return DirectGeometry;
  6361. }();
  6362. function arrayMax(array) {
  6363. if (array.length === 0) return -Infinity;
  6364. var max = array[0];
  6365. for (var i = 1, l = array.length; i < l; ++i) {
  6366. if (array[i] > max) max = array[i];
  6367. }
  6368. return max;
  6369. }
  6370. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6371. var _m1$2 = new Matrix4();
  6372. var _obj = new Object3D();
  6373. var _offset = new Vector3();
  6374. var _box$2 = new Box3();
  6375. var _boxMorphTargets = new Box3();
  6376. var _vector$4 = new Vector3();
  6377. function BufferGeometry() {
  6378. Object.defineProperty(this, 'id', {
  6379. value: _bufferGeometryId += 2
  6380. });
  6381. this.uuid = MathUtils.generateUUID();
  6382. this.name = '';
  6383. this.type = 'BufferGeometry';
  6384. this.index = null;
  6385. this.attributes = {};
  6386. this.morphAttributes = {};
  6387. this.morphTargetsRelative = false;
  6388. this.groups = [];
  6389. this.boundingBox = null;
  6390. this.boundingSphere = null;
  6391. this.drawRange = {
  6392. start: 0,
  6393. count: Infinity
  6394. };
  6395. this.userData = {};
  6396. }
  6397. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6398. constructor: BufferGeometry,
  6399. isBufferGeometry: true,
  6400. getIndex: function getIndex() {
  6401. return this.index;
  6402. },
  6403. setIndex: function setIndex(index) {
  6404. if (Array.isArray(index)) {
  6405. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6406. } else {
  6407. this.index = index;
  6408. }
  6409. return this;
  6410. },
  6411. getAttribute: function getAttribute(name) {
  6412. return this.attributes[name];
  6413. },
  6414. setAttribute: function setAttribute(name, attribute) {
  6415. this.attributes[name] = attribute;
  6416. return this;
  6417. },
  6418. deleteAttribute: function deleteAttribute(name) {
  6419. delete this.attributes[name];
  6420. return this;
  6421. },
  6422. addGroup: function addGroup(start, count, materialIndex) {
  6423. this.groups.push({
  6424. start: start,
  6425. count: count,
  6426. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6427. });
  6428. },
  6429. clearGroups: function clearGroups() {
  6430. this.groups = [];
  6431. },
  6432. setDrawRange: function setDrawRange(start, count) {
  6433. this.drawRange.start = start;
  6434. this.drawRange.count = count;
  6435. },
  6436. applyMatrix4: function applyMatrix4(matrix) {
  6437. var position = this.attributes.position;
  6438. if (position !== undefined) {
  6439. position.applyMatrix4(matrix);
  6440. position.needsUpdate = true;
  6441. }
  6442. var normal = this.attributes.normal;
  6443. if (normal !== undefined) {
  6444. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6445. normal.applyNormalMatrix(normalMatrix);
  6446. normal.needsUpdate = true;
  6447. }
  6448. var tangent = this.attributes.tangent;
  6449. if (tangent !== undefined) {
  6450. tangent.transformDirection(matrix);
  6451. tangent.needsUpdate = true;
  6452. }
  6453. if (this.boundingBox !== null) {
  6454. this.computeBoundingBox();
  6455. }
  6456. if (this.boundingSphere !== null) {
  6457. this.computeBoundingSphere();
  6458. }
  6459. return this;
  6460. },
  6461. rotateX: function rotateX(angle) {
  6462. // rotate geometry around world x-axis
  6463. _m1$2.makeRotationX(angle);
  6464. this.applyMatrix4(_m1$2);
  6465. return this;
  6466. },
  6467. rotateY: function rotateY(angle) {
  6468. // rotate geometry around world y-axis
  6469. _m1$2.makeRotationY(angle);
  6470. this.applyMatrix4(_m1$2);
  6471. return this;
  6472. },
  6473. rotateZ: function rotateZ(angle) {
  6474. // rotate geometry around world z-axis
  6475. _m1$2.makeRotationZ(angle);
  6476. this.applyMatrix4(_m1$2);
  6477. return this;
  6478. },
  6479. translate: function translate(x, y, z) {
  6480. // translate geometry
  6481. _m1$2.makeTranslation(x, y, z);
  6482. this.applyMatrix4(_m1$2);
  6483. return this;
  6484. },
  6485. scale: function scale(x, y, z) {
  6486. // scale geometry
  6487. _m1$2.makeScale(x, y, z);
  6488. this.applyMatrix4(_m1$2);
  6489. return this;
  6490. },
  6491. lookAt: function lookAt(vector) {
  6492. _obj.lookAt(vector);
  6493. _obj.updateMatrix();
  6494. this.applyMatrix4(_obj.matrix);
  6495. return this;
  6496. },
  6497. center: function center() {
  6498. this.computeBoundingBox();
  6499. this.boundingBox.getCenter(_offset).negate();
  6500. this.translate(_offset.x, _offset.y, _offset.z);
  6501. return this;
  6502. },
  6503. setFromObject: function setFromObject(object) {
  6504. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6505. var geometry = object.geometry;
  6506. if (object.isPoints || object.isLine) {
  6507. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6508. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6509. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6510. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6511. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6512. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6513. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6514. }
  6515. if (geometry.boundingSphere !== null) {
  6516. this.boundingSphere = geometry.boundingSphere.clone();
  6517. }
  6518. if (geometry.boundingBox !== null) {
  6519. this.boundingBox = geometry.boundingBox.clone();
  6520. }
  6521. } else if (object.isMesh) {
  6522. if (geometry && geometry.isGeometry) {
  6523. this.fromGeometry(geometry);
  6524. }
  6525. }
  6526. return this;
  6527. },
  6528. setFromPoints: function setFromPoints(points) {
  6529. var position = [];
  6530. for (var i = 0, l = points.length; i < l; i++) {
  6531. var point = points[i];
  6532. position.push(point.x, point.y, point.z || 0);
  6533. }
  6534. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6535. return this;
  6536. },
  6537. updateFromObject: function updateFromObject(object) {
  6538. var geometry = object.geometry;
  6539. if (object.isMesh) {
  6540. var direct = geometry.__directGeometry;
  6541. if (geometry.elementsNeedUpdate === true) {
  6542. direct = undefined;
  6543. geometry.elementsNeedUpdate = false;
  6544. }
  6545. if (direct === undefined) {
  6546. return this.fromGeometry(geometry);
  6547. }
  6548. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6549. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6550. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6551. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6552. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6553. geometry.verticesNeedUpdate = false;
  6554. geometry.normalsNeedUpdate = false;
  6555. geometry.colorsNeedUpdate = false;
  6556. geometry.uvsNeedUpdate = false;
  6557. geometry.groupsNeedUpdate = false;
  6558. geometry = direct;
  6559. }
  6560. if (geometry.verticesNeedUpdate === true) {
  6561. var attribute = this.attributes.position;
  6562. if (attribute !== undefined) {
  6563. attribute.copyVector3sArray(geometry.vertices);
  6564. attribute.needsUpdate = true;
  6565. }
  6566. geometry.verticesNeedUpdate = false;
  6567. }
  6568. if (geometry.normalsNeedUpdate === true) {
  6569. var _attribute = this.attributes.normal;
  6570. if (_attribute !== undefined) {
  6571. _attribute.copyVector3sArray(geometry.normals);
  6572. _attribute.needsUpdate = true;
  6573. }
  6574. geometry.normalsNeedUpdate = false;
  6575. }
  6576. if (geometry.colorsNeedUpdate === true) {
  6577. var _attribute2 = this.attributes.color;
  6578. if (_attribute2 !== undefined) {
  6579. _attribute2.copyColorsArray(geometry.colors);
  6580. _attribute2.needsUpdate = true;
  6581. }
  6582. geometry.colorsNeedUpdate = false;
  6583. }
  6584. if (geometry.uvsNeedUpdate) {
  6585. var _attribute3 = this.attributes.uv;
  6586. if (_attribute3 !== undefined) {
  6587. _attribute3.copyVector2sArray(geometry.uvs);
  6588. _attribute3.needsUpdate = true;
  6589. }
  6590. geometry.uvsNeedUpdate = false;
  6591. }
  6592. if (geometry.lineDistancesNeedUpdate) {
  6593. var _attribute4 = this.attributes.lineDistance;
  6594. if (_attribute4 !== undefined) {
  6595. _attribute4.copyArray(geometry.lineDistances);
  6596. _attribute4.needsUpdate = true;
  6597. }
  6598. geometry.lineDistancesNeedUpdate = false;
  6599. }
  6600. if (geometry.groupsNeedUpdate) {
  6601. geometry.computeGroups(object.geometry);
  6602. this.groups = geometry.groups;
  6603. geometry.groupsNeedUpdate = false;
  6604. }
  6605. return this;
  6606. },
  6607. fromGeometry: function fromGeometry(geometry) {
  6608. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6609. return this.fromDirectGeometry(geometry.__directGeometry);
  6610. },
  6611. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6612. var positions = new Float32Array(geometry.vertices.length * 3);
  6613. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6614. if (geometry.normals.length > 0) {
  6615. var normals = new Float32Array(geometry.normals.length * 3);
  6616. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6617. }
  6618. if (geometry.colors.length > 0) {
  6619. var colors = new Float32Array(geometry.colors.length * 3);
  6620. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6621. }
  6622. if (geometry.uvs.length > 0) {
  6623. var uvs = new Float32Array(geometry.uvs.length * 2);
  6624. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6625. }
  6626. if (geometry.uvs2.length > 0) {
  6627. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6628. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6629. } // groups
  6630. this.groups = geometry.groups; // morphs
  6631. for (var name in geometry.morphTargets) {
  6632. var array = [];
  6633. var morphTargets = geometry.morphTargets[name];
  6634. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6635. var morphTarget = morphTargets[i];
  6636. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6637. attribute.name = morphTarget.name;
  6638. array.push(attribute.copyVector3sArray(morphTarget.data));
  6639. }
  6640. this.morphAttributes[name] = array;
  6641. } // skinning
  6642. if (geometry.skinIndices.length > 0) {
  6643. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6644. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6645. }
  6646. if (geometry.skinWeights.length > 0) {
  6647. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6648. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6649. } //
  6650. if (geometry.boundingSphere !== null) {
  6651. this.boundingSphere = geometry.boundingSphere.clone();
  6652. }
  6653. if (geometry.boundingBox !== null) {
  6654. this.boundingBox = geometry.boundingBox.clone();
  6655. }
  6656. return this;
  6657. },
  6658. computeBoundingBox: function computeBoundingBox() {
  6659. if (this.boundingBox === null) {
  6660. this.boundingBox = new Box3();
  6661. }
  6662. var position = this.attributes.position;
  6663. var morphAttributesPosition = this.morphAttributes.position;
  6664. if (position && position.isGLBufferAttribute) {
  6665. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6666. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6667. return;
  6668. }
  6669. if (position !== undefined) {
  6670. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6671. if (morphAttributesPosition) {
  6672. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6673. var morphAttribute = morphAttributesPosition[i];
  6674. _box$2.setFromBufferAttribute(morphAttribute);
  6675. if (this.morphTargetsRelative) {
  6676. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6677. this.boundingBox.expandByPoint(_vector$4);
  6678. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6679. this.boundingBox.expandByPoint(_vector$4);
  6680. } else {
  6681. this.boundingBox.expandByPoint(_box$2.min);
  6682. this.boundingBox.expandByPoint(_box$2.max);
  6683. }
  6684. }
  6685. }
  6686. } else {
  6687. this.boundingBox.makeEmpty();
  6688. }
  6689. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6690. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6691. }
  6692. },
  6693. computeBoundingSphere: function computeBoundingSphere() {
  6694. if (this.boundingSphere === null) {
  6695. this.boundingSphere = new Sphere();
  6696. }
  6697. var position = this.attributes.position;
  6698. var morphAttributesPosition = this.morphAttributes.position;
  6699. if (position && position.isGLBufferAttribute) {
  6700. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6701. this.boundingSphere.set(new Vector3(), Infinity);
  6702. return;
  6703. }
  6704. if (position) {
  6705. // first, find the center of the bounding sphere
  6706. var center = this.boundingSphere.center;
  6707. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6708. if (morphAttributesPosition) {
  6709. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6710. var morphAttribute = morphAttributesPosition[i];
  6711. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6712. if (this.morphTargetsRelative) {
  6713. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6714. _box$2.expandByPoint(_vector$4);
  6715. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6716. _box$2.expandByPoint(_vector$4);
  6717. } else {
  6718. _box$2.expandByPoint(_boxMorphTargets.min);
  6719. _box$2.expandByPoint(_boxMorphTargets.max);
  6720. }
  6721. }
  6722. }
  6723. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6724. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6725. var maxRadiusSq = 0;
  6726. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6727. _vector$4.fromBufferAttribute(position, _i);
  6728. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6729. } // process morph attributes if present
  6730. if (morphAttributesPosition) {
  6731. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6732. var _morphAttribute = morphAttributesPosition[_i2];
  6733. var morphTargetsRelative = this.morphTargetsRelative;
  6734. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6735. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6736. if (morphTargetsRelative) {
  6737. _offset.fromBufferAttribute(position, j);
  6738. _vector$4.add(_offset);
  6739. }
  6740. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6741. }
  6742. }
  6743. }
  6744. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6745. if (isNaN(this.boundingSphere.radius)) {
  6746. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6747. }
  6748. }
  6749. },
  6750. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6751. },
  6752. computeVertexNormals: function computeVertexNormals() {
  6753. var index = this.index;
  6754. var positionAttribute = this.getAttribute('position');
  6755. if (positionAttribute !== undefined) {
  6756. var normalAttribute = this.getAttribute('normal');
  6757. if (normalAttribute === undefined) {
  6758. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6759. this.setAttribute('normal', normalAttribute);
  6760. } else {
  6761. // reset existing normals to zero
  6762. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6763. normalAttribute.setXYZ(i, 0, 0, 0);
  6764. }
  6765. }
  6766. var pA = new Vector3(),
  6767. pB = new Vector3(),
  6768. pC = new Vector3();
  6769. var nA = new Vector3(),
  6770. nB = new Vector3(),
  6771. nC = new Vector3();
  6772. var cb = new Vector3(),
  6773. ab = new Vector3(); // indexed elements
  6774. if (index) {
  6775. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6776. var vA = index.getX(_i3 + 0);
  6777. var vB = index.getX(_i3 + 1);
  6778. var vC = index.getX(_i3 + 2);
  6779. pA.fromBufferAttribute(positionAttribute, vA);
  6780. pB.fromBufferAttribute(positionAttribute, vB);
  6781. pC.fromBufferAttribute(positionAttribute, vC);
  6782. cb.subVectors(pC, pB);
  6783. ab.subVectors(pA, pB);
  6784. cb.cross(ab);
  6785. nA.fromBufferAttribute(normalAttribute, vA);
  6786. nB.fromBufferAttribute(normalAttribute, vB);
  6787. nC.fromBufferAttribute(normalAttribute, vC);
  6788. nA.add(cb);
  6789. nB.add(cb);
  6790. nC.add(cb);
  6791. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6792. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6793. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6794. }
  6795. } else {
  6796. // non-indexed elements (unconnected triangle soup)
  6797. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6798. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6799. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6800. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6801. cb.subVectors(pC, pB);
  6802. ab.subVectors(pA, pB);
  6803. cb.cross(ab);
  6804. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6805. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6806. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6807. }
  6808. }
  6809. this.normalizeNormals();
  6810. normalAttribute.needsUpdate = true;
  6811. }
  6812. },
  6813. merge: function merge(geometry, offset) {
  6814. if (!(geometry && geometry.isBufferGeometry)) {
  6815. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6816. return;
  6817. }
  6818. if (offset === undefined) {
  6819. offset = 0;
  6820. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6821. }
  6822. var attributes = this.attributes;
  6823. for (var key in attributes) {
  6824. if (geometry.attributes[key] === undefined) continue;
  6825. var attribute1 = attributes[key];
  6826. var attributeArray1 = attribute1.array;
  6827. var attribute2 = geometry.attributes[key];
  6828. var attributeArray2 = attribute2.array;
  6829. var attributeOffset = attribute2.itemSize * offset;
  6830. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6831. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6832. attributeArray1[j] = attributeArray2[i];
  6833. }
  6834. }
  6835. return this;
  6836. },
  6837. normalizeNormals: function normalizeNormals() {
  6838. var normals = this.attributes.normal;
  6839. for (var i = 0, il = normals.count; i < il; i++) {
  6840. _vector$4.fromBufferAttribute(normals, i);
  6841. _vector$4.normalize();
  6842. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6843. }
  6844. },
  6845. toNonIndexed: function toNonIndexed() {
  6846. function convertBufferAttribute(attribute, indices) {
  6847. var array = attribute.array;
  6848. var itemSize = attribute.itemSize;
  6849. var normalized = attribute.normalized;
  6850. var array2 = new array.constructor(indices.length * itemSize);
  6851. var index = 0,
  6852. index2 = 0;
  6853. for (var i = 0, l = indices.length; i < l; i++) {
  6854. index = indices[i] * itemSize;
  6855. for (var j = 0; j < itemSize; j++) {
  6856. array2[index2++] = array[index++];
  6857. }
  6858. }
  6859. return new BufferAttribute(array2, itemSize, normalized);
  6860. } //
  6861. if (this.index === null) {
  6862. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6863. return this;
  6864. }
  6865. var geometry2 = new BufferGeometry();
  6866. var indices = this.index.array;
  6867. var attributes = this.attributes; // attributes
  6868. for (var name in attributes) {
  6869. var attribute = attributes[name];
  6870. var newAttribute = convertBufferAttribute(attribute, indices);
  6871. geometry2.setAttribute(name, newAttribute);
  6872. } // morph attributes
  6873. var morphAttributes = this.morphAttributes;
  6874. for (var _name in morphAttributes) {
  6875. var morphArray = [];
  6876. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6877. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6878. var _attribute5 = morphAttribute[i];
  6879. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6880. morphArray.push(_newAttribute);
  6881. }
  6882. geometry2.morphAttributes[_name] = morphArray;
  6883. }
  6884. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6885. var groups = this.groups;
  6886. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6887. var group = groups[_i5];
  6888. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6889. }
  6890. return geometry2;
  6891. },
  6892. toJSON: function toJSON() {
  6893. var data = {
  6894. metadata: {
  6895. version: 4.5,
  6896. type: 'BufferGeometry',
  6897. generator: 'BufferGeometry.toJSON'
  6898. }
  6899. }; // standard BufferGeometry serialization
  6900. data.uuid = this.uuid;
  6901. data.type = this.type;
  6902. if (this.name !== '') data.name = this.name;
  6903. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6904. if (this.parameters !== undefined) {
  6905. var parameters = this.parameters;
  6906. for (var key in parameters) {
  6907. if (parameters[key] !== undefined) data[key] = parameters[key];
  6908. }
  6909. return data;
  6910. }
  6911. data.data = {
  6912. attributes: {}
  6913. };
  6914. var index = this.index;
  6915. if (index !== null) {
  6916. data.data.index = {
  6917. type: index.array.constructor.name,
  6918. array: Array.prototype.slice.call(index.array)
  6919. };
  6920. }
  6921. var attributes = this.attributes;
  6922. for (var _key in attributes) {
  6923. var attribute = attributes[_key];
  6924. var attributeData = attribute.toJSON(data.data);
  6925. if (attribute.name !== '') attributeData.name = attribute.name;
  6926. data.data.attributes[_key] = attributeData;
  6927. }
  6928. var morphAttributes = {};
  6929. var hasMorphAttributes = false;
  6930. for (var _key2 in this.morphAttributes) {
  6931. var attributeArray = this.morphAttributes[_key2];
  6932. var array = [];
  6933. for (var i = 0, il = attributeArray.length; i < il; i++) {
  6934. var _attribute6 = attributeArray[i];
  6935. var _attributeData = _attribute6.toJSON(data.data);
  6936. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  6937. array.push(_attributeData);
  6938. }
  6939. if (array.length > 0) {
  6940. morphAttributes[_key2] = array;
  6941. hasMorphAttributes = true;
  6942. }
  6943. }
  6944. if (hasMorphAttributes) {
  6945. data.data.morphAttributes = morphAttributes;
  6946. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6947. }
  6948. var groups = this.groups;
  6949. if (groups.length > 0) {
  6950. data.data.groups = JSON.parse(JSON.stringify(groups));
  6951. }
  6952. var boundingSphere = this.boundingSphere;
  6953. if (boundingSphere !== null) {
  6954. data.data.boundingSphere = {
  6955. center: boundingSphere.center.toArray(),
  6956. radius: boundingSphere.radius
  6957. };
  6958. }
  6959. return data;
  6960. },
  6961. clone: function clone() {
  6962. /*
  6963. // Handle primitives
  6964. const parameters = this.parameters;
  6965. if ( parameters !== undefined ) {
  6966. const values = [];
  6967. for ( const key in parameters ) {
  6968. values.push( parameters[ key ] );
  6969. }
  6970. const geometry = Object.create( this.constructor.prototype );
  6971. this.constructor.apply( geometry, values );
  6972. return geometry;
  6973. }
  6974. return new this.constructor().copy( this );
  6975. */
  6976. return new BufferGeometry().copy(this);
  6977. },
  6978. copy: function copy(source) {
  6979. // reset
  6980. this.index = null;
  6981. this.attributes = {};
  6982. this.morphAttributes = {};
  6983. this.groups = [];
  6984. this.boundingBox = null;
  6985. this.boundingSphere = null; // used for storing cloned, shared data
  6986. var data = {}; // name
  6987. this.name = source.name; // index
  6988. var index = source.index;
  6989. if (index !== null) {
  6990. this.setIndex(index.clone(data));
  6991. } // attributes
  6992. var attributes = source.attributes;
  6993. for (var name in attributes) {
  6994. var attribute = attributes[name];
  6995. this.setAttribute(name, attribute.clone(data));
  6996. } // morph attributes
  6997. var morphAttributes = source.morphAttributes;
  6998. for (var _name2 in morphAttributes) {
  6999. var array = [];
  7000. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7001. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7002. array.push(morphAttribute[i].clone(data));
  7003. }
  7004. this.morphAttributes[_name2] = array;
  7005. }
  7006. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7007. var groups = source.groups;
  7008. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  7009. var group = groups[_i6];
  7010. this.addGroup(group.start, group.count, group.materialIndex);
  7011. } // bounding box
  7012. var boundingBox = source.boundingBox;
  7013. if (boundingBox !== null) {
  7014. this.boundingBox = boundingBox.clone();
  7015. } // bounding sphere
  7016. var boundingSphere = source.boundingSphere;
  7017. if (boundingSphere !== null) {
  7018. this.boundingSphere = boundingSphere.clone();
  7019. } // draw range
  7020. this.drawRange.start = source.drawRange.start;
  7021. this.drawRange.count = source.drawRange.count; // user data
  7022. this.userData = source.userData;
  7023. return this;
  7024. },
  7025. dispose: function dispose() {
  7026. this.dispatchEvent({
  7027. type: 'dispose'
  7028. });
  7029. }
  7030. });
  7031. var _inverseMatrix = new Matrix4();
  7032. var _ray = new Ray();
  7033. var _sphere = new Sphere();
  7034. var _vA = new Vector3();
  7035. var _vB = new Vector3();
  7036. var _vC = new Vector3();
  7037. var _tempA = new Vector3();
  7038. var _tempB = new Vector3();
  7039. var _tempC = new Vector3();
  7040. var _morphA = new Vector3();
  7041. var _morphB = new Vector3();
  7042. var _morphC = new Vector3();
  7043. var _uvA = new Vector2();
  7044. var _uvB = new Vector2();
  7045. var _uvC = new Vector2();
  7046. var _intersectionPoint = new Vector3();
  7047. var _intersectionPointWorld = new Vector3();
  7048. function Mesh(geometry, material) {
  7049. Object3D.call(this);
  7050. this.type = 'Mesh';
  7051. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  7052. this.material = material !== undefined ? material : new MeshBasicMaterial();
  7053. this.updateMorphTargets();
  7054. }
  7055. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7056. constructor: Mesh,
  7057. isMesh: true,
  7058. copy: function copy(source) {
  7059. Object3D.prototype.copy.call(this, source);
  7060. if (source.morphTargetInfluences !== undefined) {
  7061. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7062. }
  7063. if (source.morphTargetDictionary !== undefined) {
  7064. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7065. }
  7066. this.material = source.material;
  7067. this.geometry = source.geometry;
  7068. return this;
  7069. },
  7070. updateMorphTargets: function updateMorphTargets() {
  7071. var geometry = this.geometry;
  7072. if (geometry.isBufferGeometry) {
  7073. var morphAttributes = geometry.morphAttributes;
  7074. var keys = Object.keys(morphAttributes);
  7075. if (keys.length > 0) {
  7076. var morphAttribute = morphAttributes[keys[0]];
  7077. if (morphAttribute !== undefined) {
  7078. this.morphTargetInfluences = [];
  7079. this.morphTargetDictionary = {};
  7080. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7081. var name = morphAttribute[m].name || String(m);
  7082. this.morphTargetInfluences.push(0);
  7083. this.morphTargetDictionary[name] = m;
  7084. }
  7085. }
  7086. }
  7087. } else {
  7088. var morphTargets = geometry.morphTargets;
  7089. if (morphTargets !== undefined && morphTargets.length > 0) {
  7090. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7091. }
  7092. }
  7093. },
  7094. raycast: function raycast(raycaster, intersects) {
  7095. var geometry = this.geometry;
  7096. var material = this.material;
  7097. var matrixWorld = this.matrixWorld;
  7098. if (material === undefined) return; // Checking boundingSphere distance to ray
  7099. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7100. _sphere.copy(geometry.boundingSphere);
  7101. _sphere.applyMatrix4(matrixWorld);
  7102. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7103. _inverseMatrix.copy(matrixWorld).invert();
  7104. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7105. if (geometry.boundingBox !== null) {
  7106. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7107. }
  7108. var intersection;
  7109. if (geometry.isBufferGeometry) {
  7110. var index = geometry.index;
  7111. var position = geometry.attributes.position;
  7112. var morphPosition = geometry.morphAttributes.position;
  7113. var morphTargetsRelative = geometry.morphTargetsRelative;
  7114. var uv = geometry.attributes.uv;
  7115. var uv2 = geometry.attributes.uv2;
  7116. var groups = geometry.groups;
  7117. var drawRange = geometry.drawRange;
  7118. if (index !== null) {
  7119. // indexed buffer geometry
  7120. if (Array.isArray(material)) {
  7121. for (var i = 0, il = groups.length; i < il; i++) {
  7122. var group = groups[i];
  7123. var groupMaterial = material[group.materialIndex];
  7124. var start = Math.max(group.start, drawRange.start);
  7125. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7126. for (var j = start, jl = end; j < jl; j += 3) {
  7127. var a = index.getX(j);
  7128. var b = index.getX(j + 1);
  7129. var c = index.getX(j + 2);
  7130. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7131. if (intersection) {
  7132. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7133. intersection.face.materialIndex = group.materialIndex;
  7134. intersects.push(intersection);
  7135. }
  7136. }
  7137. }
  7138. } else {
  7139. var _start = Math.max(0, drawRange.start);
  7140. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7141. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7142. var _a = index.getX(_i);
  7143. var _b = index.getX(_i + 1);
  7144. var _c = index.getX(_i + 2);
  7145. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7146. if (intersection) {
  7147. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7148. intersects.push(intersection);
  7149. }
  7150. }
  7151. }
  7152. } else if (position !== undefined) {
  7153. // non-indexed buffer geometry
  7154. if (Array.isArray(material)) {
  7155. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7156. var _group = groups[_i2];
  7157. var _groupMaterial = material[_group.materialIndex];
  7158. var _start2 = Math.max(_group.start, drawRange.start);
  7159. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7160. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7161. var _a2 = _j;
  7162. var _b2 = _j + 1;
  7163. var _c2 = _j + 2;
  7164. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7165. if (intersection) {
  7166. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7167. intersection.face.materialIndex = _group.materialIndex;
  7168. intersects.push(intersection);
  7169. }
  7170. }
  7171. }
  7172. } else {
  7173. var _start3 = Math.max(0, drawRange.start);
  7174. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7175. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7176. var _a3 = _i3;
  7177. var _b3 = _i3 + 1;
  7178. var _c3 = _i3 + 2;
  7179. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7180. if (intersection) {
  7181. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7182. intersects.push(intersection);
  7183. }
  7184. }
  7185. }
  7186. }
  7187. } else if (geometry.isGeometry) {
  7188. var isMultiMaterial = Array.isArray(material);
  7189. var vertices = geometry.vertices;
  7190. var faces = geometry.faces;
  7191. var uvs;
  7192. var faceVertexUvs = geometry.faceVertexUvs[0];
  7193. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7194. for (var f = 0, fl = faces.length; f < fl; f++) {
  7195. var face = faces[f];
  7196. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7197. if (faceMaterial === undefined) continue;
  7198. var fvA = vertices[face.a];
  7199. var fvB = vertices[face.b];
  7200. var fvC = vertices[face.c];
  7201. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7202. if (intersection) {
  7203. if (uvs && uvs[f]) {
  7204. var uvs_f = uvs[f];
  7205. _uvA.copy(uvs_f[0]);
  7206. _uvB.copy(uvs_f[1]);
  7207. _uvC.copy(uvs_f[2]);
  7208. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7209. }
  7210. intersection.face = face;
  7211. intersection.faceIndex = f;
  7212. intersects.push(intersection);
  7213. }
  7214. }
  7215. }
  7216. }
  7217. });
  7218. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7219. var intersect;
  7220. if (material.side === BackSide) {
  7221. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7222. } else {
  7223. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7224. }
  7225. if (intersect === null) return null;
  7226. _intersectionPointWorld.copy(point);
  7227. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7228. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7229. if (distance < raycaster.near || distance > raycaster.far) return null;
  7230. return {
  7231. distance: distance,
  7232. point: _intersectionPointWorld.clone(),
  7233. object: object
  7234. };
  7235. }
  7236. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7237. _vA.fromBufferAttribute(position, a);
  7238. _vB.fromBufferAttribute(position, b);
  7239. _vC.fromBufferAttribute(position, c);
  7240. var morphInfluences = object.morphTargetInfluences;
  7241. if (material.morphTargets && morphPosition && morphInfluences) {
  7242. _morphA.set(0, 0, 0);
  7243. _morphB.set(0, 0, 0);
  7244. _morphC.set(0, 0, 0);
  7245. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7246. var influence = morphInfluences[i];
  7247. var morphAttribute = morphPosition[i];
  7248. if (influence === 0) continue;
  7249. _tempA.fromBufferAttribute(morphAttribute, a);
  7250. _tempB.fromBufferAttribute(morphAttribute, b);
  7251. _tempC.fromBufferAttribute(morphAttribute, c);
  7252. if (morphTargetsRelative) {
  7253. _morphA.addScaledVector(_tempA, influence);
  7254. _morphB.addScaledVector(_tempB, influence);
  7255. _morphC.addScaledVector(_tempC, influence);
  7256. } else {
  7257. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7258. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7259. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7260. }
  7261. }
  7262. _vA.add(_morphA);
  7263. _vB.add(_morphB);
  7264. _vC.add(_morphC);
  7265. }
  7266. if (object.isSkinnedMesh) {
  7267. object.boneTransform(a, _vA);
  7268. object.boneTransform(b, _vB);
  7269. object.boneTransform(c, _vC);
  7270. }
  7271. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7272. if (intersection) {
  7273. if (uv) {
  7274. _uvA.fromBufferAttribute(uv, a);
  7275. _uvB.fromBufferAttribute(uv, b);
  7276. _uvC.fromBufferAttribute(uv, c);
  7277. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7278. }
  7279. if (uv2) {
  7280. _uvA.fromBufferAttribute(uv2, a);
  7281. _uvB.fromBufferAttribute(uv2, b);
  7282. _uvC.fromBufferAttribute(uv2, c);
  7283. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7284. }
  7285. var face = new Face3(a, b, c);
  7286. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7287. intersection.face = face;
  7288. }
  7289. return intersection;
  7290. }
  7291. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7292. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7293. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7294. var _this;
  7295. if (width === void 0) {
  7296. width = 1;
  7297. }
  7298. if (height === void 0) {
  7299. height = 1;
  7300. }
  7301. if (depth === void 0) {
  7302. depth = 1;
  7303. }
  7304. if (widthSegments === void 0) {
  7305. widthSegments = 1;
  7306. }
  7307. if (heightSegments === void 0) {
  7308. heightSegments = 1;
  7309. }
  7310. if (depthSegments === void 0) {
  7311. depthSegments = 1;
  7312. }
  7313. _this = _BufferGeometry.call(this) || this;
  7314. _this.type = 'BoxBufferGeometry';
  7315. _this.parameters = {
  7316. width: width,
  7317. height: height,
  7318. depth: depth,
  7319. widthSegments: widthSegments,
  7320. heightSegments: heightSegments,
  7321. depthSegments: depthSegments
  7322. };
  7323. var scope = _assertThisInitialized(_this); // segments
  7324. widthSegments = Math.floor(widthSegments);
  7325. heightSegments = Math.floor(heightSegments);
  7326. depthSegments = Math.floor(depthSegments); // buffers
  7327. var indices = [];
  7328. var vertices = [];
  7329. var normals = [];
  7330. var uvs = []; // helper variables
  7331. var numberOfVertices = 0;
  7332. var groupStart = 0; // build each side of the box geometry
  7333. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7334. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7335. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7336. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7337. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7338. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7339. // build geometry
  7340. _this.setIndex(indices);
  7341. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7342. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7343. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7344. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7345. var segmentWidth = width / gridX;
  7346. var segmentHeight = height / gridY;
  7347. var widthHalf = width / 2;
  7348. var heightHalf = height / 2;
  7349. var depthHalf = depth / 2;
  7350. var gridX1 = gridX + 1;
  7351. var gridY1 = gridY + 1;
  7352. var vertexCounter = 0;
  7353. var groupCount = 0;
  7354. var vector = new Vector3(); // generate vertices, normals and uvs
  7355. for (var iy = 0; iy < gridY1; iy++) {
  7356. var y = iy * segmentHeight - heightHalf;
  7357. for (var ix = 0; ix < gridX1; ix++) {
  7358. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7359. vector[u] = x * udir;
  7360. vector[v] = y * vdir;
  7361. vector[w] = depthHalf; // now apply vector to vertex buffer
  7362. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7363. vector[u] = 0;
  7364. vector[v] = 0;
  7365. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7366. normals.push(vector.x, vector.y, vector.z); // uvs
  7367. uvs.push(ix / gridX);
  7368. uvs.push(1 - iy / gridY); // counters
  7369. vertexCounter += 1;
  7370. }
  7371. } // indices
  7372. // 1. you need three indices to draw a single face
  7373. // 2. a single segment consists of two faces
  7374. // 3. so we need to generate six (2*3) indices per segment
  7375. for (var _iy = 0; _iy < gridY; _iy++) {
  7376. for (var _ix = 0; _ix < gridX; _ix++) {
  7377. var a = numberOfVertices + _ix + gridX1 * _iy;
  7378. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7379. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7380. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7381. indices.push(a, b, d);
  7382. indices.push(b, c, d); // increase counter
  7383. groupCount += 6;
  7384. }
  7385. } // add a group to the geometry. this will ensure multi material support
  7386. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7387. groupStart += groupCount; // update total number of vertices
  7388. numberOfVertices += vertexCounter;
  7389. }
  7390. return _this;
  7391. }
  7392. return BoxBufferGeometry;
  7393. }(BufferGeometry);
  7394. /**
  7395. * Uniform Utilities
  7396. */
  7397. function cloneUniforms(src) {
  7398. var dst = {};
  7399. for (var u in src) {
  7400. dst[u] = {};
  7401. for (var p in src[u]) {
  7402. var property = src[u][p];
  7403. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7404. dst[u][p] = property.clone();
  7405. } else if (Array.isArray(property)) {
  7406. dst[u][p] = property.slice();
  7407. } else {
  7408. dst[u][p] = property;
  7409. }
  7410. }
  7411. }
  7412. return dst;
  7413. }
  7414. function mergeUniforms(uniforms) {
  7415. var merged = {};
  7416. for (var u = 0; u < uniforms.length; u++) {
  7417. var tmp = cloneUniforms(uniforms[u]);
  7418. for (var p in tmp) {
  7419. merged[p] = tmp[p];
  7420. }
  7421. }
  7422. return merged;
  7423. } // Legacy
  7424. var UniformsUtils = {
  7425. clone: cloneUniforms,
  7426. merge: mergeUniforms
  7427. };
  7428. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7429. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7430. /**
  7431. * parameters = {
  7432. * defines: { "label" : "value" },
  7433. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7434. *
  7435. * fragmentShader: <string>,
  7436. * vertexShader: <string>,
  7437. *
  7438. * wireframe: <boolean>,
  7439. * wireframeLinewidth: <float>,
  7440. *
  7441. * lights: <bool>,
  7442. *
  7443. * skinning: <bool>,
  7444. * morphTargets: <bool>,
  7445. * morphNormals: <bool>
  7446. * }
  7447. */
  7448. function ShaderMaterial(parameters) {
  7449. Material.call(this);
  7450. this.type = 'ShaderMaterial';
  7451. this.defines = {};
  7452. this.uniforms = {};
  7453. this.vertexShader = default_vertex;
  7454. this.fragmentShader = default_fragment;
  7455. this.linewidth = 1;
  7456. this.wireframe = false;
  7457. this.wireframeLinewidth = 1;
  7458. this.fog = false; // set to use scene fog
  7459. this.lights = false; // set to use scene lights
  7460. this.clipping = false; // set to use user-defined clipping planes
  7461. this.skinning = false; // set to use skinning attribute streams
  7462. this.morphTargets = false; // set to use morph targets
  7463. this.morphNormals = false; // set to use morph normals
  7464. this.extensions = {
  7465. derivatives: false,
  7466. // set to use derivatives
  7467. fragDepth: false,
  7468. // set to use fragment depth values
  7469. drawBuffers: false,
  7470. // set to use draw buffers
  7471. shaderTextureLOD: false // set to use shader texture LOD
  7472. }; // When rendered geometry doesn't include these attributes but the material does,
  7473. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7474. this.defaultAttributeValues = {
  7475. 'color': [1, 1, 1],
  7476. 'uv': [0, 0],
  7477. 'uv2': [0, 0]
  7478. };
  7479. this.index0AttributeName = undefined;
  7480. this.uniformsNeedUpdate = false;
  7481. this.glslVersion = null;
  7482. if (parameters !== undefined) {
  7483. if (parameters.attributes !== undefined) {
  7484. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7485. }
  7486. this.setValues(parameters);
  7487. }
  7488. }
  7489. ShaderMaterial.prototype = Object.create(Material.prototype);
  7490. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7491. ShaderMaterial.prototype.isShaderMaterial = true;
  7492. ShaderMaterial.prototype.copy = function (source) {
  7493. Material.prototype.copy.call(this, source);
  7494. this.fragmentShader = source.fragmentShader;
  7495. this.vertexShader = source.vertexShader;
  7496. this.uniforms = cloneUniforms(source.uniforms);
  7497. this.defines = Object.assign({}, source.defines);
  7498. this.wireframe = source.wireframe;
  7499. this.wireframeLinewidth = source.wireframeLinewidth;
  7500. this.lights = source.lights;
  7501. this.clipping = source.clipping;
  7502. this.skinning = source.skinning;
  7503. this.morphTargets = source.morphTargets;
  7504. this.morphNormals = source.morphNormals;
  7505. this.extensions = Object.assign({}, source.extensions);
  7506. this.glslVersion = source.glslVersion;
  7507. return this;
  7508. };
  7509. ShaderMaterial.prototype.toJSON = function (meta) {
  7510. var data = Material.prototype.toJSON.call(this, meta);
  7511. data.glslVersion = this.glslVersion;
  7512. data.uniforms = {};
  7513. for (var name in this.uniforms) {
  7514. var uniform = this.uniforms[name];
  7515. var value = uniform.value;
  7516. if (value && value.isTexture) {
  7517. data.uniforms[name] = {
  7518. type: 't',
  7519. value: value.toJSON(meta).uuid
  7520. };
  7521. } else if (value && value.isColor) {
  7522. data.uniforms[name] = {
  7523. type: 'c',
  7524. value: value.getHex()
  7525. };
  7526. } else if (value && value.isVector2) {
  7527. data.uniforms[name] = {
  7528. type: 'v2',
  7529. value: value.toArray()
  7530. };
  7531. } else if (value && value.isVector3) {
  7532. data.uniforms[name] = {
  7533. type: 'v3',
  7534. value: value.toArray()
  7535. };
  7536. } else if (value && value.isVector4) {
  7537. data.uniforms[name] = {
  7538. type: 'v4',
  7539. value: value.toArray()
  7540. };
  7541. } else if (value && value.isMatrix3) {
  7542. data.uniforms[name] = {
  7543. type: 'm3',
  7544. value: value.toArray()
  7545. };
  7546. } else if (value && value.isMatrix4) {
  7547. data.uniforms[name] = {
  7548. type: 'm4',
  7549. value: value.toArray()
  7550. };
  7551. } else {
  7552. data.uniforms[name] = {
  7553. value: value
  7554. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7555. }
  7556. }
  7557. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7558. data.vertexShader = this.vertexShader;
  7559. data.fragmentShader = this.fragmentShader;
  7560. var extensions = {};
  7561. for (var key in this.extensions) {
  7562. if (this.extensions[key] === true) extensions[key] = true;
  7563. }
  7564. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7565. return data;
  7566. };
  7567. function Camera() {
  7568. Object3D.call(this);
  7569. this.type = 'Camera';
  7570. this.matrixWorldInverse = new Matrix4();
  7571. this.projectionMatrix = new Matrix4();
  7572. this.projectionMatrixInverse = new Matrix4();
  7573. }
  7574. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7575. constructor: Camera,
  7576. isCamera: true,
  7577. copy: function copy(source, recursive) {
  7578. Object3D.prototype.copy.call(this, source, recursive);
  7579. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7580. this.projectionMatrix.copy(source.projectionMatrix);
  7581. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7582. return this;
  7583. },
  7584. getWorldDirection: function getWorldDirection(target) {
  7585. if (target === undefined) {
  7586. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7587. target = new Vector3();
  7588. }
  7589. this.updateWorldMatrix(true, false);
  7590. var e = this.matrixWorld.elements;
  7591. return target.set(-e[8], -e[9], -e[10]).normalize();
  7592. },
  7593. updateMatrixWorld: function updateMatrixWorld(force) {
  7594. Object3D.prototype.updateMatrixWorld.call(this, force);
  7595. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7596. },
  7597. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7598. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7599. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7600. },
  7601. clone: function clone() {
  7602. return new this.constructor().copy(this);
  7603. }
  7604. });
  7605. function PerspectiveCamera(fov, aspect, near, far) {
  7606. Camera.call(this);
  7607. this.type = 'PerspectiveCamera';
  7608. this.fov = fov !== undefined ? fov : 50;
  7609. this.zoom = 1;
  7610. this.near = near !== undefined ? near : 0.1;
  7611. this.far = far !== undefined ? far : 2000;
  7612. this.focus = 10;
  7613. this.aspect = aspect !== undefined ? aspect : 1;
  7614. this.view = null;
  7615. this.filmGauge = 35; // width of the film (default in millimeters)
  7616. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7617. this.updateProjectionMatrix();
  7618. }
  7619. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7620. constructor: PerspectiveCamera,
  7621. isPerspectiveCamera: true,
  7622. copy: function copy(source, recursive) {
  7623. Camera.prototype.copy.call(this, source, recursive);
  7624. this.fov = source.fov;
  7625. this.zoom = source.zoom;
  7626. this.near = source.near;
  7627. this.far = source.far;
  7628. this.focus = source.focus;
  7629. this.aspect = source.aspect;
  7630. this.view = source.view === null ? null : Object.assign({}, source.view);
  7631. this.filmGauge = source.filmGauge;
  7632. this.filmOffset = source.filmOffset;
  7633. return this;
  7634. },
  7635. /**
  7636. * Sets the FOV by focal length in respect to the current .filmGauge.
  7637. *
  7638. * The default film gauge is 35, so that the focal length can be specified for
  7639. * a 35mm (full frame) camera.
  7640. *
  7641. * Values for focal length and film gauge must have the same unit.
  7642. */
  7643. setFocalLength: function setFocalLength(focalLength) {
  7644. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7645. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7646. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7647. this.updateProjectionMatrix();
  7648. },
  7649. /**
  7650. * Calculates the focal length from the current .fov and .filmGauge.
  7651. */
  7652. getFocalLength: function getFocalLength() {
  7653. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7654. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7655. },
  7656. getEffectiveFOV: function getEffectiveFOV() {
  7657. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7658. },
  7659. getFilmWidth: function getFilmWidth() {
  7660. // film not completely covered in portrait format (aspect < 1)
  7661. return this.filmGauge * Math.min(this.aspect, 1);
  7662. },
  7663. getFilmHeight: function getFilmHeight() {
  7664. // film not completely covered in landscape format (aspect > 1)
  7665. return this.filmGauge / Math.max(this.aspect, 1);
  7666. },
  7667. /**
  7668. * Sets an offset in a larger frustum. This is useful for multi-window or
  7669. * multi-monitor/multi-machine setups.
  7670. *
  7671. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7672. * the monitors are in grid like this
  7673. *
  7674. * +---+---+---+
  7675. * | A | B | C |
  7676. * +---+---+---+
  7677. * | D | E | F |
  7678. * +---+---+---+
  7679. *
  7680. * then for each monitor you would call it like this
  7681. *
  7682. * const w = 1920;
  7683. * const h = 1080;
  7684. * const fullWidth = w * 3;
  7685. * const fullHeight = h * 2;
  7686. *
  7687. * --A--
  7688. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7689. * --B--
  7690. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7691. * --C--
  7692. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7693. * --D--
  7694. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7695. * --E--
  7696. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7697. * --F--
  7698. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7699. *
  7700. * Note there is no reason monitors have to be the same size or in a grid.
  7701. */
  7702. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7703. this.aspect = fullWidth / fullHeight;
  7704. if (this.view === null) {
  7705. this.view = {
  7706. enabled: true,
  7707. fullWidth: 1,
  7708. fullHeight: 1,
  7709. offsetX: 0,
  7710. offsetY: 0,
  7711. width: 1,
  7712. height: 1
  7713. };
  7714. }
  7715. this.view.enabled = true;
  7716. this.view.fullWidth = fullWidth;
  7717. this.view.fullHeight = fullHeight;
  7718. this.view.offsetX = x;
  7719. this.view.offsetY = y;
  7720. this.view.width = width;
  7721. this.view.height = height;
  7722. this.updateProjectionMatrix();
  7723. },
  7724. clearViewOffset: function clearViewOffset() {
  7725. if (this.view !== null) {
  7726. this.view.enabled = false;
  7727. }
  7728. this.updateProjectionMatrix();
  7729. },
  7730. updateProjectionMatrix: function updateProjectionMatrix() {
  7731. var near = this.near;
  7732. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7733. var height = 2 * top;
  7734. var width = this.aspect * height;
  7735. var left = -0.5 * width;
  7736. var view = this.view;
  7737. if (this.view !== null && this.view.enabled) {
  7738. var fullWidth = view.fullWidth,
  7739. fullHeight = view.fullHeight;
  7740. left += view.offsetX * width / fullWidth;
  7741. top -= view.offsetY * height / fullHeight;
  7742. width *= view.width / fullWidth;
  7743. height *= view.height / fullHeight;
  7744. }
  7745. var skew = this.filmOffset;
  7746. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7747. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7748. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  7749. },
  7750. toJSON: function toJSON(meta) {
  7751. var data = Object3D.prototype.toJSON.call(this, meta);
  7752. data.object.fov = this.fov;
  7753. data.object.zoom = this.zoom;
  7754. data.object.near = this.near;
  7755. data.object.far = this.far;
  7756. data.object.focus = this.focus;
  7757. data.object.aspect = this.aspect;
  7758. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7759. data.object.filmGauge = this.filmGauge;
  7760. data.object.filmOffset = this.filmOffset;
  7761. return data;
  7762. }
  7763. });
  7764. var fov = 90,
  7765. aspect = 1;
  7766. function CubeCamera(near, far, renderTarget) {
  7767. Object3D.call(this);
  7768. this.type = 'CubeCamera';
  7769. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7770. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7771. return;
  7772. }
  7773. this.renderTarget = renderTarget;
  7774. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7775. cameraPX.layers = this.layers;
  7776. cameraPX.up.set(0, -1, 0);
  7777. cameraPX.lookAt(new Vector3(1, 0, 0));
  7778. this.add(cameraPX);
  7779. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7780. cameraNX.layers = this.layers;
  7781. cameraNX.up.set(0, -1, 0);
  7782. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7783. this.add(cameraNX);
  7784. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7785. cameraPY.layers = this.layers;
  7786. cameraPY.up.set(0, 0, 1);
  7787. cameraPY.lookAt(new Vector3(0, 1, 0));
  7788. this.add(cameraPY);
  7789. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7790. cameraNY.layers = this.layers;
  7791. cameraNY.up.set(0, 0, -1);
  7792. cameraNY.lookAt(new Vector3(0, -1, 0));
  7793. this.add(cameraNY);
  7794. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7795. cameraPZ.layers = this.layers;
  7796. cameraPZ.up.set(0, -1, 0);
  7797. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7798. this.add(cameraPZ);
  7799. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7800. cameraNZ.layers = this.layers;
  7801. cameraNZ.up.set(0, -1, 0);
  7802. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7803. this.add(cameraNZ);
  7804. this.update = function (renderer, scene) {
  7805. if (this.parent === null) this.updateMatrixWorld();
  7806. var currentXrEnabled = renderer.xr.enabled;
  7807. var currentRenderTarget = renderer.getRenderTarget();
  7808. renderer.xr.enabled = false;
  7809. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7810. renderTarget.texture.generateMipmaps = false;
  7811. renderer.setRenderTarget(renderTarget, 0);
  7812. renderer.render(scene, cameraPX);
  7813. renderer.setRenderTarget(renderTarget, 1);
  7814. renderer.render(scene, cameraNX);
  7815. renderer.setRenderTarget(renderTarget, 2);
  7816. renderer.render(scene, cameraPY);
  7817. renderer.setRenderTarget(renderTarget, 3);
  7818. renderer.render(scene, cameraNY);
  7819. renderer.setRenderTarget(renderTarget, 4);
  7820. renderer.render(scene, cameraPZ);
  7821. renderTarget.texture.generateMipmaps = generateMipmaps;
  7822. renderer.setRenderTarget(renderTarget, 5);
  7823. renderer.render(scene, cameraNZ);
  7824. renderer.setRenderTarget(currentRenderTarget);
  7825. renderer.xr.enabled = currentXrEnabled;
  7826. };
  7827. }
  7828. CubeCamera.prototype = Object.create(Object3D.prototype);
  7829. CubeCamera.prototype.constructor = CubeCamera;
  7830. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7831. images = images !== undefined ? images : [];
  7832. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7833. format = format !== undefined ? format : RGBFormat;
  7834. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7835. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  7836. //
  7837. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7838. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7839. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7840. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7841. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7842. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7843. this._needsFlipEnvMap = true;
  7844. }
  7845. CubeTexture.prototype = Object.create(Texture.prototype);
  7846. CubeTexture.prototype.constructor = CubeTexture;
  7847. CubeTexture.prototype.isCubeTexture = true;
  7848. Object.defineProperty(CubeTexture.prototype, 'images', {
  7849. get: function get() {
  7850. return this.image;
  7851. },
  7852. set: function set(value) {
  7853. this.image = value;
  7854. }
  7855. });
  7856. function WebGLCubeRenderTarget(size, options, dummy) {
  7857. if (Number.isInteger(options)) {
  7858. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7859. options = dummy;
  7860. }
  7861. WebGLRenderTarget.call(this, size, size, options);
  7862. options = options || {};
  7863. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7864. this.texture._needsFlipEnvMap = false;
  7865. }
  7866. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7867. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7868. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7869. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7870. this.texture.type = texture.type;
  7871. this.texture.format = RGBAFormat; // see #18859
  7872. this.texture.encoding = texture.encoding;
  7873. this.texture.generateMipmaps = texture.generateMipmaps;
  7874. this.texture.minFilter = texture.minFilter;
  7875. this.texture.magFilter = texture.magFilter;
  7876. var shader = {
  7877. uniforms: {
  7878. tEquirect: {
  7879. value: null
  7880. }
  7881. },
  7882. vertexShader:
  7883. /* glsl */
  7884. "\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t#include <begin_vertex>\n\t\t\t\t#include <project_vertex>\n\n\t\t\t}\n\t\t",
  7885. fragmentShader:
  7886. /* glsl */
  7887. "\n\n\t\t\tuniform sampler2D tEquirect;\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t}\n\t\t"
  7888. };
  7889. var geometry = new BoxBufferGeometry(5, 5, 5);
  7890. var material = new ShaderMaterial({
  7891. name: 'CubemapFromEquirect',
  7892. uniforms: cloneUniforms(shader.uniforms),
  7893. vertexShader: shader.vertexShader,
  7894. fragmentShader: shader.fragmentShader,
  7895. side: BackSide,
  7896. blending: NoBlending
  7897. });
  7898. material.uniforms.tEquirect.value = texture;
  7899. var mesh = new Mesh(geometry, material);
  7900. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  7901. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  7902. var camera = new CubeCamera(1, 10, this);
  7903. camera.update(renderer, mesh);
  7904. texture.minFilter = currentMinFilter;
  7905. mesh.geometry.dispose();
  7906. mesh.material.dispose();
  7907. return this;
  7908. };
  7909. WebGLCubeRenderTarget.prototype.clear = function (renderer, color, depth, stencil) {
  7910. var currentRenderTarget = renderer.getRenderTarget();
  7911. for (var i = 0; i < 6; i++) {
  7912. renderer.setRenderTarget(this, i);
  7913. renderer.clear(color, depth, stencil);
  7914. }
  7915. renderer.setRenderTarget(currentRenderTarget);
  7916. };
  7917. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  7918. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7919. this.image = {
  7920. data: data || null,
  7921. width: width || 1,
  7922. height: height || 1
  7923. };
  7924. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  7925. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  7926. this.generateMipmaps = false;
  7927. this.flipY = false;
  7928. this.unpackAlignment = 1;
  7929. this.needsUpdate = true;
  7930. }
  7931. DataTexture.prototype = Object.create(Texture.prototype);
  7932. DataTexture.prototype.constructor = DataTexture;
  7933. DataTexture.prototype.isDataTexture = true;
  7934. var _sphere$1 = /*@__PURE__*/new Sphere();
  7935. var _vector$5 = /*@__PURE__*/new Vector3();
  7936. var Frustum = /*#__PURE__*/function () {
  7937. function Frustum(p0, p1, p2, p3, p4, p5) {
  7938. this.planes = [p0 !== undefined ? p0 : new Plane(), p1 !== undefined ? p1 : new Plane(), p2 !== undefined ? p2 : new Plane(), p3 !== undefined ? p3 : new Plane(), p4 !== undefined ? p4 : new Plane(), p5 !== undefined ? p5 : new Plane()];
  7939. }
  7940. var _proto = Frustum.prototype;
  7941. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  7942. var planes = this.planes;
  7943. planes[0].copy(p0);
  7944. planes[1].copy(p1);
  7945. planes[2].copy(p2);
  7946. planes[3].copy(p3);
  7947. planes[4].copy(p4);
  7948. planes[5].copy(p5);
  7949. return this;
  7950. };
  7951. _proto.clone = function clone() {
  7952. return new this.constructor().copy(this);
  7953. };
  7954. _proto.copy = function copy(frustum) {
  7955. var planes = this.planes;
  7956. for (var i = 0; i < 6; i++) {
  7957. planes[i].copy(frustum.planes[i]);
  7958. }
  7959. return this;
  7960. };
  7961. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  7962. var planes = this.planes;
  7963. var me = m.elements;
  7964. var me0 = me[0],
  7965. me1 = me[1],
  7966. me2 = me[2],
  7967. me3 = me[3];
  7968. var me4 = me[4],
  7969. me5 = me[5],
  7970. me6 = me[6],
  7971. me7 = me[7];
  7972. var me8 = me[8],
  7973. me9 = me[9],
  7974. me10 = me[10],
  7975. me11 = me[11];
  7976. var me12 = me[12],
  7977. me13 = me[13],
  7978. me14 = me[14],
  7979. me15 = me[15];
  7980. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  7981. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  7982. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  7983. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  7984. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  7985. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  7986. return this;
  7987. };
  7988. _proto.intersectsObject = function intersectsObject(object) {
  7989. var geometry = object.geometry;
  7990. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7991. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  7992. return this.intersectsSphere(_sphere$1);
  7993. };
  7994. _proto.intersectsSprite = function intersectsSprite(sprite) {
  7995. _sphere$1.center.set(0, 0, 0);
  7996. _sphere$1.radius = 0.7071067811865476;
  7997. _sphere$1.applyMatrix4(sprite.matrixWorld);
  7998. return this.intersectsSphere(_sphere$1);
  7999. };
  8000. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8001. var planes = this.planes;
  8002. var center = sphere.center;
  8003. var negRadius = -sphere.radius;
  8004. for (var i = 0; i < 6; i++) {
  8005. var distance = planes[i].distanceToPoint(center);
  8006. if (distance < negRadius) {
  8007. return false;
  8008. }
  8009. }
  8010. return true;
  8011. };
  8012. _proto.intersectsBox = function intersectsBox(box) {
  8013. var planes = this.planes;
  8014. for (var i = 0; i < 6; i++) {
  8015. var plane = planes[i]; // corner at max distance
  8016. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8017. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8018. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8019. if (plane.distanceToPoint(_vector$5) < 0) {
  8020. return false;
  8021. }
  8022. }
  8023. return true;
  8024. };
  8025. _proto.containsPoint = function containsPoint(point) {
  8026. var planes = this.planes;
  8027. for (var i = 0; i < 6; i++) {
  8028. if (planes[i].distanceToPoint(point) < 0) {
  8029. return false;
  8030. }
  8031. }
  8032. return true;
  8033. };
  8034. return Frustum;
  8035. }();
  8036. function WebGLAnimation() {
  8037. var context = null;
  8038. var isAnimating = false;
  8039. var animationLoop = null;
  8040. var requestId = null;
  8041. function onAnimationFrame(time, frame) {
  8042. animationLoop(time, frame);
  8043. requestId = context.requestAnimationFrame(onAnimationFrame);
  8044. }
  8045. return {
  8046. start: function start() {
  8047. if (isAnimating === true) return;
  8048. if (animationLoop === null) return;
  8049. requestId = context.requestAnimationFrame(onAnimationFrame);
  8050. isAnimating = true;
  8051. },
  8052. stop: function stop() {
  8053. context.cancelAnimationFrame(requestId);
  8054. isAnimating = false;
  8055. },
  8056. setAnimationLoop: function setAnimationLoop(callback) {
  8057. animationLoop = callback;
  8058. },
  8059. setContext: function setContext(value) {
  8060. context = value;
  8061. }
  8062. };
  8063. }
  8064. function WebGLAttributes(gl, capabilities) {
  8065. var isWebGL2 = capabilities.isWebGL2;
  8066. var buffers = new WeakMap();
  8067. function createBuffer(attribute, bufferType) {
  8068. var array = attribute.array;
  8069. var usage = attribute.usage;
  8070. var buffer = gl.createBuffer();
  8071. gl.bindBuffer(bufferType, buffer);
  8072. gl.bufferData(bufferType, array, usage);
  8073. attribute.onUploadCallback();
  8074. var type = 5126;
  8075. if (array instanceof Float32Array) {
  8076. type = 5126;
  8077. } else if (array instanceof Float64Array) {
  8078. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8079. } else if (array instanceof Uint16Array) {
  8080. if (attribute.isFloat16BufferAttribute) {
  8081. if (isWebGL2) {
  8082. type = 5131;
  8083. } else {
  8084. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8085. }
  8086. } else {
  8087. type = 5123;
  8088. }
  8089. } else if (array instanceof Int16Array) {
  8090. type = 5122;
  8091. } else if (array instanceof Uint32Array) {
  8092. type = 5125;
  8093. } else if (array instanceof Int32Array) {
  8094. type = 5124;
  8095. } else if (array instanceof Int8Array) {
  8096. type = 5120;
  8097. } else if (array instanceof Uint8Array) {
  8098. type = 5121;
  8099. }
  8100. return {
  8101. buffer: buffer,
  8102. type: type,
  8103. bytesPerElement: array.BYTES_PER_ELEMENT,
  8104. version: attribute.version
  8105. };
  8106. }
  8107. function updateBuffer(buffer, attribute, bufferType) {
  8108. var array = attribute.array;
  8109. var updateRange = attribute.updateRange;
  8110. gl.bindBuffer(bufferType, buffer);
  8111. if (updateRange.count === -1) {
  8112. // Not using update ranges
  8113. gl.bufferSubData(bufferType, 0, array);
  8114. } else {
  8115. if (isWebGL2) {
  8116. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8117. } else {
  8118. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8119. }
  8120. updateRange.count = -1; // reset range
  8121. }
  8122. } //
  8123. function get(attribute) {
  8124. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8125. return buffers.get(attribute);
  8126. }
  8127. function remove(attribute) {
  8128. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8129. var data = buffers.get(attribute);
  8130. if (data) {
  8131. gl.deleteBuffer(data.buffer);
  8132. buffers.delete(attribute);
  8133. }
  8134. }
  8135. function update(attribute, bufferType) {
  8136. if (attribute.isGLBufferAttribute) {
  8137. var cached = buffers.get(attribute);
  8138. if (!cached || cached.version < attribute.version) {
  8139. buffers.set(attribute, {
  8140. buffer: attribute.buffer,
  8141. type: attribute.type,
  8142. bytesPerElement: attribute.elementSize,
  8143. version: attribute.version
  8144. });
  8145. }
  8146. return;
  8147. }
  8148. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8149. var data = buffers.get(attribute);
  8150. if (data === undefined) {
  8151. buffers.set(attribute, createBuffer(attribute, bufferType));
  8152. } else if (data.version < attribute.version) {
  8153. updateBuffer(data.buffer, attribute, bufferType);
  8154. data.version = attribute.version;
  8155. }
  8156. }
  8157. return {
  8158. get: get,
  8159. remove: remove,
  8160. update: update
  8161. };
  8162. }
  8163. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8164. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8165. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8166. var _this;
  8167. _this = _BufferGeometry.call(this) || this;
  8168. _this.type = 'PlaneBufferGeometry';
  8169. _this.parameters = {
  8170. width: width,
  8171. height: height,
  8172. widthSegments: widthSegments,
  8173. heightSegments: heightSegments
  8174. };
  8175. width = width || 1;
  8176. height = height || 1;
  8177. var width_half = width / 2;
  8178. var height_half = height / 2;
  8179. var gridX = Math.floor(widthSegments) || 1;
  8180. var gridY = Math.floor(heightSegments) || 1;
  8181. var gridX1 = gridX + 1;
  8182. var gridY1 = gridY + 1;
  8183. var segment_width = width / gridX;
  8184. var segment_height = height / gridY; // buffers
  8185. var indices = [];
  8186. var vertices = [];
  8187. var normals = [];
  8188. var uvs = []; // generate vertices, normals and uvs
  8189. for (var iy = 0; iy < gridY1; iy++) {
  8190. var y = iy * segment_height - height_half;
  8191. for (var ix = 0; ix < gridX1; ix++) {
  8192. var x = ix * segment_width - width_half;
  8193. vertices.push(x, -y, 0);
  8194. normals.push(0, 0, 1);
  8195. uvs.push(ix / gridX);
  8196. uvs.push(1 - iy / gridY);
  8197. }
  8198. } // indices
  8199. for (var _iy = 0; _iy < gridY; _iy++) {
  8200. for (var _ix = 0; _ix < gridX; _ix++) {
  8201. var a = _ix + gridX1 * _iy;
  8202. var b = _ix + gridX1 * (_iy + 1);
  8203. var c = _ix + 1 + gridX1 * (_iy + 1);
  8204. var d = _ix + 1 + gridX1 * _iy; // faces
  8205. indices.push(a, b, d);
  8206. indices.push(b, c, d);
  8207. }
  8208. } // build geometry
  8209. _this.setIndex(indices);
  8210. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8211. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8212. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8213. return _this;
  8214. }
  8215. return PlaneBufferGeometry;
  8216. }(BufferGeometry);
  8217. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8218. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8219. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8220. 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";
  8221. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8222. var begin_vertex = "vec3 transformed = vec3( position );";
  8223. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8224. 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";
  8225. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  8226. 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";
  8227. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8228. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8229. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8230. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8231. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8232. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8233. 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";
  8234. 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}";
  8235. 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";
  8236. 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";
  8237. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8238. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8239. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8240. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8241. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8242. 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}";
  8243. 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";
  8244. 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";
  8245. 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";
  8246. 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";
  8247. 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";
  8248. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8249. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8250. 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";
  8251. 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";
  8252. 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}";
  8253. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8254. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8255. 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";
  8256. 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";
  8257. 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";
  8258. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8259. 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)";
  8260. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8261. 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)";
  8262. 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";
  8263. 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}";
  8264. 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";
  8265. 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";
  8266. 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";
  8267. 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";
  8268. 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";
  8269. 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";
  8270. 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";
  8271. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8272. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8273. 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";
  8274. 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";
  8275. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8276. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8277. 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";
  8278. 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";
  8279. 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";
  8280. var normal_fragment_begin = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  8281. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  8282. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8283. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8284. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN );\n\t#endif\n#endif";
  8285. 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";
  8286. 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}";
  8287. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8288. 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;";
  8289. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8290. 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";
  8291. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8292. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8293. 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";
  8294. 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";
  8295. 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";
  8296. 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}";
  8297. 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";
  8298. 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";
  8299. 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";
  8300. 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";
  8301. 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";
  8302. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8303. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8304. 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; }";
  8305. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8306. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8307. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8308. 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";
  8309. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8310. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8311. 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";
  8312. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8313. 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";
  8314. 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}";
  8315. 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}";
  8316. 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}";
  8317. 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}";
  8318. 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}";
  8319. 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}";
  8320. 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}";
  8321. 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}";
  8322. 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}";
  8323. 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}";
  8324. 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}";
  8325. 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}";
  8326. 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}";
  8327. 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}";
  8328. 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}";
  8329. 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}";
  8330. 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}";
  8331. 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}";
  8332. 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}";
  8333. 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}";
  8334. 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}";
  8335. 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}";
  8336. 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}";
  8337. 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}";
  8338. 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}";
  8339. 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}";
  8340. 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}";
  8341. 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}";
  8342. 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}";
  8343. 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}";
  8344. 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}";
  8345. 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}";
  8346. var ShaderChunk = {
  8347. alphamap_fragment: alphamap_fragment,
  8348. alphamap_pars_fragment: alphamap_pars_fragment,
  8349. alphatest_fragment: alphatest_fragment,
  8350. aomap_fragment: aomap_fragment,
  8351. aomap_pars_fragment: aomap_pars_fragment,
  8352. begin_vertex: begin_vertex,
  8353. beginnormal_vertex: beginnormal_vertex,
  8354. bsdfs: bsdfs,
  8355. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8356. clipping_planes_fragment: clipping_planes_fragment,
  8357. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8358. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8359. clipping_planes_vertex: clipping_planes_vertex,
  8360. color_fragment: color_fragment,
  8361. color_pars_fragment: color_pars_fragment,
  8362. color_pars_vertex: color_pars_vertex,
  8363. color_vertex: color_vertex,
  8364. common: common,
  8365. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8366. defaultnormal_vertex: defaultnormal_vertex,
  8367. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8368. displacementmap_vertex: displacementmap_vertex,
  8369. emissivemap_fragment: emissivemap_fragment,
  8370. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8371. encodings_fragment: encodings_fragment,
  8372. encodings_pars_fragment: encodings_pars_fragment,
  8373. envmap_fragment: envmap_fragment,
  8374. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8375. envmap_pars_fragment: envmap_pars_fragment,
  8376. envmap_pars_vertex: envmap_pars_vertex,
  8377. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8378. envmap_vertex: envmap_vertex,
  8379. fog_vertex: fog_vertex,
  8380. fog_pars_vertex: fog_pars_vertex,
  8381. fog_fragment: fog_fragment,
  8382. fog_pars_fragment: fog_pars_fragment,
  8383. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8384. lightmap_fragment: lightmap_fragment,
  8385. lightmap_pars_fragment: lightmap_pars_fragment,
  8386. lights_lambert_vertex: lights_lambert_vertex,
  8387. lights_pars_begin: lights_pars_begin,
  8388. lights_toon_fragment: lights_toon_fragment,
  8389. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8390. lights_phong_fragment: lights_phong_fragment,
  8391. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8392. lights_physical_fragment: lights_physical_fragment,
  8393. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8394. lights_fragment_begin: lights_fragment_begin,
  8395. lights_fragment_maps: lights_fragment_maps,
  8396. lights_fragment_end: lights_fragment_end,
  8397. logdepthbuf_fragment: logdepthbuf_fragment,
  8398. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8399. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8400. logdepthbuf_vertex: logdepthbuf_vertex,
  8401. map_fragment: map_fragment,
  8402. map_pars_fragment: map_pars_fragment,
  8403. map_particle_fragment: map_particle_fragment,
  8404. map_particle_pars_fragment: map_particle_pars_fragment,
  8405. metalnessmap_fragment: metalnessmap_fragment,
  8406. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8407. morphnormal_vertex: morphnormal_vertex,
  8408. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8409. morphtarget_vertex: morphtarget_vertex,
  8410. normal_fragment_begin: normal_fragment_begin,
  8411. normal_fragment_maps: normal_fragment_maps,
  8412. normalmap_pars_fragment: normalmap_pars_fragment,
  8413. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8414. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8415. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8416. packing: packing,
  8417. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8418. project_vertex: project_vertex,
  8419. dithering_fragment: dithering_fragment,
  8420. dithering_pars_fragment: dithering_pars_fragment,
  8421. roughnessmap_fragment: roughnessmap_fragment,
  8422. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8423. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8424. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8425. shadowmap_vertex: shadowmap_vertex,
  8426. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8427. skinbase_vertex: skinbase_vertex,
  8428. skinning_pars_vertex: skinning_pars_vertex,
  8429. skinning_vertex: skinning_vertex,
  8430. skinnormal_vertex: skinnormal_vertex,
  8431. specularmap_fragment: specularmap_fragment,
  8432. specularmap_pars_fragment: specularmap_pars_fragment,
  8433. tonemapping_fragment: tonemapping_fragment,
  8434. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8435. transmissionmap_fragment: transmissionmap_fragment,
  8436. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8437. uv_pars_fragment: uv_pars_fragment,
  8438. uv_pars_vertex: uv_pars_vertex,
  8439. uv_vertex: uv_vertex,
  8440. uv2_pars_fragment: uv2_pars_fragment,
  8441. uv2_pars_vertex: uv2_pars_vertex,
  8442. uv2_vertex: uv2_vertex,
  8443. worldpos_vertex: worldpos_vertex,
  8444. background_frag: background_frag,
  8445. background_vert: background_vert,
  8446. cube_frag: cube_frag,
  8447. cube_vert: cube_vert,
  8448. depth_frag: depth_frag,
  8449. depth_vert: depth_vert,
  8450. distanceRGBA_frag: distanceRGBA_frag,
  8451. distanceRGBA_vert: distanceRGBA_vert,
  8452. equirect_frag: equirect_frag,
  8453. equirect_vert: equirect_vert,
  8454. linedashed_frag: linedashed_frag,
  8455. linedashed_vert: linedashed_vert,
  8456. meshbasic_frag: meshbasic_frag,
  8457. meshbasic_vert: meshbasic_vert,
  8458. meshlambert_frag: meshlambert_frag,
  8459. meshlambert_vert: meshlambert_vert,
  8460. meshmatcap_frag: meshmatcap_frag,
  8461. meshmatcap_vert: meshmatcap_vert,
  8462. meshtoon_frag: meshtoon_frag,
  8463. meshtoon_vert: meshtoon_vert,
  8464. meshphong_frag: meshphong_frag,
  8465. meshphong_vert: meshphong_vert,
  8466. meshphysical_frag: meshphysical_frag,
  8467. meshphysical_vert: meshphysical_vert,
  8468. normal_frag: normal_frag,
  8469. normal_vert: normal_vert,
  8470. points_frag: points_frag,
  8471. points_vert: points_vert,
  8472. shadow_frag: shadow_frag,
  8473. shadow_vert: shadow_vert,
  8474. sprite_frag: sprite_frag,
  8475. sprite_vert: sprite_vert
  8476. };
  8477. /**
  8478. * Uniforms library for shared webgl shaders
  8479. */
  8480. var UniformsLib = {
  8481. common: {
  8482. diffuse: {
  8483. value: new Color(0xeeeeee)
  8484. },
  8485. opacity: {
  8486. value: 1.0
  8487. },
  8488. map: {
  8489. value: null
  8490. },
  8491. uvTransform: {
  8492. value: new Matrix3()
  8493. },
  8494. uv2Transform: {
  8495. value: new Matrix3()
  8496. },
  8497. alphaMap: {
  8498. value: null
  8499. }
  8500. },
  8501. specularmap: {
  8502. specularMap: {
  8503. value: null
  8504. }
  8505. },
  8506. envmap: {
  8507. envMap: {
  8508. value: null
  8509. },
  8510. flipEnvMap: {
  8511. value: -1
  8512. },
  8513. reflectivity: {
  8514. value: 1.0
  8515. },
  8516. refractionRatio: {
  8517. value: 0.98
  8518. },
  8519. maxMipLevel: {
  8520. value: 0
  8521. }
  8522. },
  8523. aomap: {
  8524. aoMap: {
  8525. value: null
  8526. },
  8527. aoMapIntensity: {
  8528. value: 1
  8529. }
  8530. },
  8531. lightmap: {
  8532. lightMap: {
  8533. value: null
  8534. },
  8535. lightMapIntensity: {
  8536. value: 1
  8537. }
  8538. },
  8539. emissivemap: {
  8540. emissiveMap: {
  8541. value: null
  8542. }
  8543. },
  8544. bumpmap: {
  8545. bumpMap: {
  8546. value: null
  8547. },
  8548. bumpScale: {
  8549. value: 1
  8550. }
  8551. },
  8552. normalmap: {
  8553. normalMap: {
  8554. value: null
  8555. },
  8556. normalScale: {
  8557. value: new Vector2(1, 1)
  8558. }
  8559. },
  8560. displacementmap: {
  8561. displacementMap: {
  8562. value: null
  8563. },
  8564. displacementScale: {
  8565. value: 1
  8566. },
  8567. displacementBias: {
  8568. value: 0
  8569. }
  8570. },
  8571. roughnessmap: {
  8572. roughnessMap: {
  8573. value: null
  8574. }
  8575. },
  8576. metalnessmap: {
  8577. metalnessMap: {
  8578. value: null
  8579. }
  8580. },
  8581. gradientmap: {
  8582. gradientMap: {
  8583. value: null
  8584. }
  8585. },
  8586. fog: {
  8587. fogDensity: {
  8588. value: 0.00025
  8589. },
  8590. fogNear: {
  8591. value: 1
  8592. },
  8593. fogFar: {
  8594. value: 2000
  8595. },
  8596. fogColor: {
  8597. value: new Color(0xffffff)
  8598. }
  8599. },
  8600. lights: {
  8601. ambientLightColor: {
  8602. value: []
  8603. },
  8604. lightProbe: {
  8605. value: []
  8606. },
  8607. directionalLights: {
  8608. value: [],
  8609. properties: {
  8610. direction: {},
  8611. color: {}
  8612. }
  8613. },
  8614. directionalLightShadows: {
  8615. value: [],
  8616. properties: {
  8617. shadowBias: {},
  8618. shadowNormalBias: {},
  8619. shadowRadius: {},
  8620. shadowMapSize: {}
  8621. }
  8622. },
  8623. directionalShadowMap: {
  8624. value: []
  8625. },
  8626. directionalShadowMatrix: {
  8627. value: []
  8628. },
  8629. spotLights: {
  8630. value: [],
  8631. properties: {
  8632. color: {},
  8633. position: {},
  8634. direction: {},
  8635. distance: {},
  8636. coneCos: {},
  8637. penumbraCos: {},
  8638. decay: {}
  8639. }
  8640. },
  8641. spotLightShadows: {
  8642. value: [],
  8643. properties: {
  8644. shadowBias: {},
  8645. shadowNormalBias: {},
  8646. shadowRadius: {},
  8647. shadowMapSize: {}
  8648. }
  8649. },
  8650. spotShadowMap: {
  8651. value: []
  8652. },
  8653. spotShadowMatrix: {
  8654. value: []
  8655. },
  8656. pointLights: {
  8657. value: [],
  8658. properties: {
  8659. color: {},
  8660. position: {},
  8661. decay: {},
  8662. distance: {}
  8663. }
  8664. },
  8665. pointLightShadows: {
  8666. value: [],
  8667. properties: {
  8668. shadowBias: {},
  8669. shadowNormalBias: {},
  8670. shadowRadius: {},
  8671. shadowMapSize: {},
  8672. shadowCameraNear: {},
  8673. shadowCameraFar: {}
  8674. }
  8675. },
  8676. pointShadowMap: {
  8677. value: []
  8678. },
  8679. pointShadowMatrix: {
  8680. value: []
  8681. },
  8682. hemisphereLights: {
  8683. value: [],
  8684. properties: {
  8685. direction: {},
  8686. skyColor: {},
  8687. groundColor: {}
  8688. }
  8689. },
  8690. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8691. rectAreaLights: {
  8692. value: [],
  8693. properties: {
  8694. color: {},
  8695. position: {},
  8696. width: {},
  8697. height: {}
  8698. }
  8699. },
  8700. ltc_1: {
  8701. value: null
  8702. },
  8703. ltc_2: {
  8704. value: null
  8705. }
  8706. },
  8707. points: {
  8708. diffuse: {
  8709. value: new Color(0xeeeeee)
  8710. },
  8711. opacity: {
  8712. value: 1.0
  8713. },
  8714. size: {
  8715. value: 1.0
  8716. },
  8717. scale: {
  8718. value: 1.0
  8719. },
  8720. map: {
  8721. value: null
  8722. },
  8723. alphaMap: {
  8724. value: null
  8725. },
  8726. uvTransform: {
  8727. value: new Matrix3()
  8728. }
  8729. },
  8730. sprite: {
  8731. diffuse: {
  8732. value: new Color(0xeeeeee)
  8733. },
  8734. opacity: {
  8735. value: 1.0
  8736. },
  8737. center: {
  8738. value: new Vector2(0.5, 0.5)
  8739. },
  8740. rotation: {
  8741. value: 0.0
  8742. },
  8743. map: {
  8744. value: null
  8745. },
  8746. alphaMap: {
  8747. value: null
  8748. },
  8749. uvTransform: {
  8750. value: new Matrix3()
  8751. }
  8752. }
  8753. };
  8754. var ShaderLib = {
  8755. basic: {
  8756. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8757. vertexShader: ShaderChunk.meshbasic_vert,
  8758. fragmentShader: ShaderChunk.meshbasic_frag
  8759. },
  8760. lambert: {
  8761. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8762. emissive: {
  8763. value: new Color(0x000000)
  8764. }
  8765. }]),
  8766. vertexShader: ShaderChunk.meshlambert_vert,
  8767. fragmentShader: ShaderChunk.meshlambert_frag
  8768. },
  8769. phong: {
  8770. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8771. emissive: {
  8772. value: new Color(0x000000)
  8773. },
  8774. specular: {
  8775. value: new Color(0x111111)
  8776. },
  8777. shininess: {
  8778. value: 30
  8779. }
  8780. }]),
  8781. vertexShader: ShaderChunk.meshphong_vert,
  8782. fragmentShader: ShaderChunk.meshphong_frag
  8783. },
  8784. standard: {
  8785. 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, {
  8786. emissive: {
  8787. value: new Color(0x000000)
  8788. },
  8789. roughness: {
  8790. value: 1.0
  8791. },
  8792. metalness: {
  8793. value: 0.0
  8794. },
  8795. envMapIntensity: {
  8796. value: 1
  8797. } // temporary
  8798. }]),
  8799. vertexShader: ShaderChunk.meshphysical_vert,
  8800. fragmentShader: ShaderChunk.meshphysical_frag
  8801. },
  8802. toon: {
  8803. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8804. emissive: {
  8805. value: new Color(0x000000)
  8806. }
  8807. }]),
  8808. vertexShader: ShaderChunk.meshtoon_vert,
  8809. fragmentShader: ShaderChunk.meshtoon_frag
  8810. },
  8811. matcap: {
  8812. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8813. matcap: {
  8814. value: null
  8815. }
  8816. }]),
  8817. vertexShader: ShaderChunk.meshmatcap_vert,
  8818. fragmentShader: ShaderChunk.meshmatcap_frag
  8819. },
  8820. points: {
  8821. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8822. vertexShader: ShaderChunk.points_vert,
  8823. fragmentShader: ShaderChunk.points_frag
  8824. },
  8825. dashed: {
  8826. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8827. scale: {
  8828. value: 1
  8829. },
  8830. dashSize: {
  8831. value: 1
  8832. },
  8833. totalSize: {
  8834. value: 2
  8835. }
  8836. }]),
  8837. vertexShader: ShaderChunk.linedashed_vert,
  8838. fragmentShader: ShaderChunk.linedashed_frag
  8839. },
  8840. depth: {
  8841. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8842. vertexShader: ShaderChunk.depth_vert,
  8843. fragmentShader: ShaderChunk.depth_frag
  8844. },
  8845. normal: {
  8846. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8847. opacity: {
  8848. value: 1.0
  8849. }
  8850. }]),
  8851. vertexShader: ShaderChunk.normal_vert,
  8852. fragmentShader: ShaderChunk.normal_frag
  8853. },
  8854. sprite: {
  8855. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8856. vertexShader: ShaderChunk.sprite_vert,
  8857. fragmentShader: ShaderChunk.sprite_frag
  8858. },
  8859. background: {
  8860. uniforms: {
  8861. uvTransform: {
  8862. value: new Matrix3()
  8863. },
  8864. t2D: {
  8865. value: null
  8866. }
  8867. },
  8868. vertexShader: ShaderChunk.background_vert,
  8869. fragmentShader: ShaderChunk.background_frag
  8870. },
  8871. /* -------------------------------------------------------------------------
  8872. // Cube map shader
  8873. ------------------------------------------------------------------------- */
  8874. cube: {
  8875. uniforms: mergeUniforms([UniformsLib.envmap, {
  8876. opacity: {
  8877. value: 1.0
  8878. }
  8879. }]),
  8880. vertexShader: ShaderChunk.cube_vert,
  8881. fragmentShader: ShaderChunk.cube_frag
  8882. },
  8883. equirect: {
  8884. uniforms: {
  8885. tEquirect: {
  8886. value: null
  8887. }
  8888. },
  8889. vertexShader: ShaderChunk.equirect_vert,
  8890. fragmentShader: ShaderChunk.equirect_frag
  8891. },
  8892. distanceRGBA: {
  8893. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  8894. referencePosition: {
  8895. value: new Vector3()
  8896. },
  8897. nearDistance: {
  8898. value: 1
  8899. },
  8900. farDistance: {
  8901. value: 1000
  8902. }
  8903. }]),
  8904. vertexShader: ShaderChunk.distanceRGBA_vert,
  8905. fragmentShader: ShaderChunk.distanceRGBA_frag
  8906. },
  8907. shadow: {
  8908. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  8909. color: {
  8910. value: new Color(0x00000)
  8911. },
  8912. opacity: {
  8913. value: 1.0
  8914. }
  8915. }]),
  8916. vertexShader: ShaderChunk.shadow_vert,
  8917. fragmentShader: ShaderChunk.shadow_frag
  8918. }
  8919. };
  8920. ShaderLib.physical = {
  8921. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  8922. clearcoat: {
  8923. value: 0
  8924. },
  8925. clearcoatMap: {
  8926. value: null
  8927. },
  8928. clearcoatRoughness: {
  8929. value: 0
  8930. },
  8931. clearcoatRoughnessMap: {
  8932. value: null
  8933. },
  8934. clearcoatNormalScale: {
  8935. value: new Vector2(1, 1)
  8936. },
  8937. clearcoatNormalMap: {
  8938. value: null
  8939. },
  8940. sheen: {
  8941. value: new Color(0x000000)
  8942. },
  8943. transmission: {
  8944. value: 0
  8945. },
  8946. transmissionMap: {
  8947. value: null
  8948. }
  8949. }]),
  8950. vertexShader: ShaderChunk.meshphysical_vert,
  8951. fragmentShader: ShaderChunk.meshphysical_frag
  8952. };
  8953. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  8954. var clearColor = new Color(0x000000);
  8955. var clearAlpha = 0;
  8956. var planeMesh;
  8957. var boxMesh;
  8958. var currentBackground = null;
  8959. var currentBackgroundVersion = 0;
  8960. var currentTonemapping = null;
  8961. function render(renderList, scene, camera, forceClear) {
  8962. var background = scene.isScene === true ? scene.background : null;
  8963. if (background && background.isTexture) {
  8964. background = cubemaps.get(background);
  8965. } // Ignore background in AR
  8966. // TODO: Reconsider this.
  8967. var xr = renderer.xr;
  8968. var session = xr.getSession && xr.getSession();
  8969. if (session && session.environmentBlendMode === 'additive') {
  8970. background = null;
  8971. }
  8972. if (background === null) {
  8973. setClear(clearColor, clearAlpha);
  8974. } else if (background && background.isColor) {
  8975. setClear(background, 1);
  8976. forceClear = true;
  8977. }
  8978. if (renderer.autoClear || forceClear) {
  8979. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  8980. }
  8981. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  8982. if (boxMesh === undefined) {
  8983. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  8984. name: 'BackgroundCubeMaterial',
  8985. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  8986. vertexShader: ShaderLib.cube.vertexShader,
  8987. fragmentShader: ShaderLib.cube.fragmentShader,
  8988. side: BackSide,
  8989. depthTest: false,
  8990. depthWrite: false,
  8991. fog: false
  8992. }));
  8993. boxMesh.geometry.deleteAttribute('normal');
  8994. boxMesh.geometry.deleteAttribute('uv');
  8995. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  8996. this.matrixWorld.copyPosition(camera.matrixWorld);
  8997. }; // enable code injection for non-built-in material
  8998. Object.defineProperty(boxMesh.material, 'envMap', {
  8999. get: function get() {
  9000. return this.uniforms.envMap.value;
  9001. }
  9002. });
  9003. objects.update(boxMesh);
  9004. }
  9005. if (background.isWebGLCubeRenderTarget) {
  9006. // TODO Deprecate
  9007. background = background.texture;
  9008. }
  9009. boxMesh.material.uniforms.envMap.value = background;
  9010. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9011. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9012. boxMesh.material.needsUpdate = true;
  9013. currentBackground = background;
  9014. currentBackgroundVersion = background.version;
  9015. currentTonemapping = renderer.toneMapping;
  9016. } // push to the pre-sorted opaque render list
  9017. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9018. } else if (background && background.isTexture) {
  9019. if (planeMesh === undefined) {
  9020. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  9021. name: 'BackgroundMaterial',
  9022. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9023. vertexShader: ShaderLib.background.vertexShader,
  9024. fragmentShader: ShaderLib.background.fragmentShader,
  9025. side: FrontSide,
  9026. depthTest: false,
  9027. depthWrite: false,
  9028. fog: false
  9029. }));
  9030. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9031. Object.defineProperty(planeMesh.material, 'map', {
  9032. get: function get() {
  9033. return this.uniforms.t2D.value;
  9034. }
  9035. });
  9036. objects.update(planeMesh);
  9037. }
  9038. planeMesh.material.uniforms.t2D.value = background;
  9039. if (background.matrixAutoUpdate === true) {
  9040. background.updateMatrix();
  9041. }
  9042. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9043. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9044. planeMesh.material.needsUpdate = true;
  9045. currentBackground = background;
  9046. currentBackgroundVersion = background.version;
  9047. currentTonemapping = renderer.toneMapping;
  9048. } // push to the pre-sorted opaque render list
  9049. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9050. }
  9051. }
  9052. function setClear(color, alpha) {
  9053. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9054. }
  9055. return {
  9056. getClearColor: function getClearColor() {
  9057. return clearColor;
  9058. },
  9059. setClearColor: function setClearColor(color, alpha) {
  9060. clearColor.set(color);
  9061. clearAlpha = alpha !== undefined ? alpha : 1;
  9062. setClear(clearColor, clearAlpha);
  9063. },
  9064. getClearAlpha: function getClearAlpha() {
  9065. return clearAlpha;
  9066. },
  9067. setClearAlpha: function setClearAlpha(alpha) {
  9068. clearAlpha = alpha;
  9069. setClear(clearColor, clearAlpha);
  9070. },
  9071. render: render
  9072. };
  9073. }
  9074. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9075. var maxVertexAttributes = gl.getParameter(34921);
  9076. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9077. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9078. var bindingStates = {};
  9079. var defaultState = createBindingState(null);
  9080. var currentState = defaultState;
  9081. function setup(object, material, program, geometry, index) {
  9082. var updateBuffers = false;
  9083. if (vaoAvailable) {
  9084. var state = getBindingState(geometry, program, material);
  9085. if (currentState !== state) {
  9086. currentState = state;
  9087. bindVertexArrayObject(currentState.object);
  9088. }
  9089. updateBuffers = needsUpdate(geometry, index);
  9090. if (updateBuffers) saveCache(geometry, index);
  9091. } else {
  9092. var wireframe = material.wireframe === true;
  9093. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9094. currentState.geometry = geometry.id;
  9095. currentState.program = program.id;
  9096. currentState.wireframe = wireframe;
  9097. updateBuffers = true;
  9098. }
  9099. }
  9100. if (object.isInstancedMesh === true) {
  9101. updateBuffers = true;
  9102. }
  9103. if (index !== null) {
  9104. attributes.update(index, 34963);
  9105. }
  9106. if (updateBuffers) {
  9107. setupVertexAttributes(object, material, program, geometry);
  9108. if (index !== null) {
  9109. gl.bindBuffer(34963, attributes.get(index).buffer);
  9110. }
  9111. }
  9112. }
  9113. function createVertexArrayObject() {
  9114. if (capabilities.isWebGL2) return gl.createVertexArray();
  9115. return extension.createVertexArrayOES();
  9116. }
  9117. function bindVertexArrayObject(vao) {
  9118. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9119. return extension.bindVertexArrayOES(vao);
  9120. }
  9121. function deleteVertexArrayObject(vao) {
  9122. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9123. return extension.deleteVertexArrayOES(vao);
  9124. }
  9125. function getBindingState(geometry, program, material) {
  9126. var wireframe = material.wireframe === true;
  9127. var programMap = bindingStates[geometry.id];
  9128. if (programMap === undefined) {
  9129. programMap = {};
  9130. bindingStates[geometry.id] = programMap;
  9131. }
  9132. var stateMap = programMap[program.id];
  9133. if (stateMap === undefined) {
  9134. stateMap = {};
  9135. programMap[program.id] = stateMap;
  9136. }
  9137. var state = stateMap[wireframe];
  9138. if (state === undefined) {
  9139. state = createBindingState(createVertexArrayObject());
  9140. stateMap[wireframe] = state;
  9141. }
  9142. return state;
  9143. }
  9144. function createBindingState(vao) {
  9145. var newAttributes = [];
  9146. var enabledAttributes = [];
  9147. var attributeDivisors = [];
  9148. for (var i = 0; i < maxVertexAttributes; i++) {
  9149. newAttributes[i] = 0;
  9150. enabledAttributes[i] = 0;
  9151. attributeDivisors[i] = 0;
  9152. }
  9153. return {
  9154. // for backward compatibility on non-VAO support browser
  9155. geometry: null,
  9156. program: null,
  9157. wireframe: false,
  9158. newAttributes: newAttributes,
  9159. enabledAttributes: enabledAttributes,
  9160. attributeDivisors: attributeDivisors,
  9161. object: vao,
  9162. attributes: {},
  9163. index: null
  9164. };
  9165. }
  9166. function needsUpdate(geometry, index) {
  9167. var cachedAttributes = currentState.attributes;
  9168. var geometryAttributes = geometry.attributes;
  9169. var attributesNum = 0;
  9170. for (var key in geometryAttributes) {
  9171. var cachedAttribute = cachedAttributes[key];
  9172. var geometryAttribute = geometryAttributes[key];
  9173. if (cachedAttribute === undefined) return true;
  9174. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9175. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9176. attributesNum++;
  9177. }
  9178. if (currentState.attributesNum !== attributesNum) return true;
  9179. if (currentState.index !== index) return true;
  9180. return false;
  9181. }
  9182. function saveCache(geometry, index) {
  9183. var cache = {};
  9184. var attributes = geometry.attributes;
  9185. var attributesNum = 0;
  9186. for (var key in attributes) {
  9187. var attribute = attributes[key];
  9188. var data = {};
  9189. data.attribute = attribute;
  9190. if (attribute.data) {
  9191. data.data = attribute.data;
  9192. }
  9193. cache[key] = data;
  9194. attributesNum++;
  9195. }
  9196. currentState.attributes = cache;
  9197. currentState.attributesNum = attributesNum;
  9198. currentState.index = index;
  9199. }
  9200. function initAttributes() {
  9201. var newAttributes = currentState.newAttributes;
  9202. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9203. newAttributes[i] = 0;
  9204. }
  9205. }
  9206. function enableAttribute(attribute) {
  9207. enableAttributeAndDivisor(attribute, 0);
  9208. }
  9209. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9210. var newAttributes = currentState.newAttributes;
  9211. var enabledAttributes = currentState.enabledAttributes;
  9212. var attributeDivisors = currentState.attributeDivisors;
  9213. newAttributes[attribute] = 1;
  9214. if (enabledAttributes[attribute] === 0) {
  9215. gl.enableVertexAttribArray(attribute);
  9216. enabledAttributes[attribute] = 1;
  9217. }
  9218. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9219. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9220. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9221. attributeDivisors[attribute] = meshPerAttribute;
  9222. }
  9223. }
  9224. function disableUnusedAttributes() {
  9225. var newAttributes = currentState.newAttributes;
  9226. var enabledAttributes = currentState.enabledAttributes;
  9227. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9228. if (enabledAttributes[i] !== newAttributes[i]) {
  9229. gl.disableVertexAttribArray(i);
  9230. enabledAttributes[i] = 0;
  9231. }
  9232. }
  9233. }
  9234. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9235. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9236. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9237. } else {
  9238. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9239. }
  9240. }
  9241. function setupVertexAttributes(object, material, program, geometry) {
  9242. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9243. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9244. }
  9245. initAttributes();
  9246. var geometryAttributes = geometry.attributes;
  9247. var programAttributes = program.getAttributes();
  9248. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9249. for (var name in programAttributes) {
  9250. var programAttribute = programAttributes[name];
  9251. if (programAttribute >= 0) {
  9252. var geometryAttribute = geometryAttributes[name];
  9253. if (geometryAttribute !== undefined) {
  9254. var normalized = geometryAttribute.normalized;
  9255. var size = geometryAttribute.itemSize;
  9256. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9257. if (attribute === undefined) continue;
  9258. var buffer = attribute.buffer;
  9259. var type = attribute.type;
  9260. var bytesPerElement = attribute.bytesPerElement;
  9261. if (geometryAttribute.isInterleavedBufferAttribute) {
  9262. var data = geometryAttribute.data;
  9263. var stride = data.stride;
  9264. var offset = geometryAttribute.offset;
  9265. if (data && data.isInstancedInterleavedBuffer) {
  9266. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9267. if (geometry._maxInstanceCount === undefined) {
  9268. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9269. }
  9270. } else {
  9271. enableAttribute(programAttribute);
  9272. }
  9273. gl.bindBuffer(34962, buffer);
  9274. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9275. } else {
  9276. if (geometryAttribute.isInstancedBufferAttribute) {
  9277. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9278. if (geometry._maxInstanceCount === undefined) {
  9279. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9280. }
  9281. } else {
  9282. enableAttribute(programAttribute);
  9283. }
  9284. gl.bindBuffer(34962, buffer);
  9285. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9286. }
  9287. } else if (name === 'instanceMatrix') {
  9288. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9289. if (_attribute === undefined) continue;
  9290. var _buffer = _attribute.buffer;
  9291. var _type = _attribute.type;
  9292. enableAttributeAndDivisor(programAttribute + 0, 1);
  9293. enableAttributeAndDivisor(programAttribute + 1, 1);
  9294. enableAttributeAndDivisor(programAttribute + 2, 1);
  9295. enableAttributeAndDivisor(programAttribute + 3, 1);
  9296. gl.bindBuffer(34962, _buffer);
  9297. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9298. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9299. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9300. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9301. } else if (name === 'instanceColor') {
  9302. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9303. if (_attribute2 === undefined) continue;
  9304. var _buffer2 = _attribute2.buffer;
  9305. var _type2 = _attribute2.type;
  9306. enableAttributeAndDivisor(programAttribute, 1);
  9307. gl.bindBuffer(34962, _buffer2);
  9308. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9309. } else if (materialDefaultAttributeValues !== undefined) {
  9310. var value = materialDefaultAttributeValues[name];
  9311. if (value !== undefined) {
  9312. switch (value.length) {
  9313. case 2:
  9314. gl.vertexAttrib2fv(programAttribute, value);
  9315. break;
  9316. case 3:
  9317. gl.vertexAttrib3fv(programAttribute, value);
  9318. break;
  9319. case 4:
  9320. gl.vertexAttrib4fv(programAttribute, value);
  9321. break;
  9322. default:
  9323. gl.vertexAttrib1fv(programAttribute, value);
  9324. }
  9325. }
  9326. }
  9327. }
  9328. }
  9329. disableUnusedAttributes();
  9330. }
  9331. function dispose() {
  9332. reset();
  9333. for (var geometryId in bindingStates) {
  9334. var programMap = bindingStates[geometryId];
  9335. for (var programId in programMap) {
  9336. var stateMap = programMap[programId];
  9337. for (var wireframe in stateMap) {
  9338. deleteVertexArrayObject(stateMap[wireframe].object);
  9339. delete stateMap[wireframe];
  9340. }
  9341. delete programMap[programId];
  9342. }
  9343. delete bindingStates[geometryId];
  9344. }
  9345. }
  9346. function releaseStatesOfGeometry(geometry) {
  9347. if (bindingStates[geometry.id] === undefined) return;
  9348. var programMap = bindingStates[geometry.id];
  9349. for (var programId in programMap) {
  9350. var stateMap = programMap[programId];
  9351. for (var wireframe in stateMap) {
  9352. deleteVertexArrayObject(stateMap[wireframe].object);
  9353. delete stateMap[wireframe];
  9354. }
  9355. delete programMap[programId];
  9356. }
  9357. delete bindingStates[geometry.id];
  9358. }
  9359. function releaseStatesOfProgram(program) {
  9360. for (var geometryId in bindingStates) {
  9361. var programMap = bindingStates[geometryId];
  9362. if (programMap[program.id] === undefined) continue;
  9363. var stateMap = programMap[program.id];
  9364. for (var wireframe in stateMap) {
  9365. deleteVertexArrayObject(stateMap[wireframe].object);
  9366. delete stateMap[wireframe];
  9367. }
  9368. delete programMap[program.id];
  9369. }
  9370. }
  9371. function reset() {
  9372. resetDefaultState();
  9373. if (currentState === defaultState) return;
  9374. currentState = defaultState;
  9375. bindVertexArrayObject(currentState.object);
  9376. } // for backward-compatilibity
  9377. function resetDefaultState() {
  9378. defaultState.geometry = null;
  9379. defaultState.program = null;
  9380. defaultState.wireframe = false;
  9381. }
  9382. return {
  9383. setup: setup,
  9384. reset: reset,
  9385. resetDefaultState: resetDefaultState,
  9386. dispose: dispose,
  9387. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9388. releaseStatesOfProgram: releaseStatesOfProgram,
  9389. initAttributes: initAttributes,
  9390. enableAttribute: enableAttribute,
  9391. disableUnusedAttributes: disableUnusedAttributes
  9392. };
  9393. }
  9394. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9395. var isWebGL2 = capabilities.isWebGL2;
  9396. var mode;
  9397. function setMode(value) {
  9398. mode = value;
  9399. }
  9400. function render(start, count) {
  9401. gl.drawArrays(mode, start, count);
  9402. info.update(count, mode, 1);
  9403. }
  9404. function renderInstances(start, count, primcount) {
  9405. if (primcount === 0) return;
  9406. var extension, methodName;
  9407. if (isWebGL2) {
  9408. extension = gl;
  9409. methodName = 'drawArraysInstanced';
  9410. } else {
  9411. extension = extensions.get('ANGLE_instanced_arrays');
  9412. methodName = 'drawArraysInstancedANGLE';
  9413. if (extension === null) {
  9414. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9415. return;
  9416. }
  9417. }
  9418. extension[methodName](mode, start, count, primcount);
  9419. info.update(count, mode, primcount);
  9420. } //
  9421. this.setMode = setMode;
  9422. this.render = render;
  9423. this.renderInstances = renderInstances;
  9424. }
  9425. function WebGLCapabilities(gl, extensions, parameters) {
  9426. var maxAnisotropy;
  9427. function getMaxAnisotropy() {
  9428. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9429. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9430. if (extension !== null) {
  9431. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9432. } else {
  9433. maxAnisotropy = 0;
  9434. }
  9435. return maxAnisotropy;
  9436. }
  9437. function getMaxPrecision(precision) {
  9438. if (precision === 'highp') {
  9439. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9440. return 'highp';
  9441. }
  9442. precision = 'mediump';
  9443. }
  9444. if (precision === 'mediump') {
  9445. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9446. return 'mediump';
  9447. }
  9448. }
  9449. return 'lowp';
  9450. }
  9451. /* eslint-disable no-undef */
  9452. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9453. /* eslint-enable no-undef */
  9454. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9455. var maxPrecision = getMaxPrecision(precision);
  9456. if (maxPrecision !== precision) {
  9457. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9458. precision = maxPrecision;
  9459. }
  9460. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9461. var maxTextures = gl.getParameter(34930);
  9462. var maxVertexTextures = gl.getParameter(35660);
  9463. var maxTextureSize = gl.getParameter(3379);
  9464. var maxCubemapSize = gl.getParameter(34076);
  9465. var maxAttributes = gl.getParameter(34921);
  9466. var maxVertexUniforms = gl.getParameter(36347);
  9467. var maxVaryings = gl.getParameter(36348);
  9468. var maxFragmentUniforms = gl.getParameter(36349);
  9469. var vertexTextures = maxVertexTextures > 0;
  9470. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9471. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9472. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9473. return {
  9474. isWebGL2: isWebGL2,
  9475. getMaxAnisotropy: getMaxAnisotropy,
  9476. getMaxPrecision: getMaxPrecision,
  9477. precision: precision,
  9478. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9479. maxTextures: maxTextures,
  9480. maxVertexTextures: maxVertexTextures,
  9481. maxTextureSize: maxTextureSize,
  9482. maxCubemapSize: maxCubemapSize,
  9483. maxAttributes: maxAttributes,
  9484. maxVertexUniforms: maxVertexUniforms,
  9485. maxVaryings: maxVaryings,
  9486. maxFragmentUniforms: maxFragmentUniforms,
  9487. vertexTextures: vertexTextures,
  9488. floatFragmentTextures: floatFragmentTextures,
  9489. floatVertexTextures: floatVertexTextures,
  9490. maxSamples: maxSamples
  9491. };
  9492. }
  9493. function WebGLClipping(properties) {
  9494. var scope = this;
  9495. var globalState = null,
  9496. numGlobalPlanes = 0,
  9497. localClippingEnabled = false,
  9498. renderingShadows = false;
  9499. var plane = new Plane(),
  9500. viewNormalMatrix = new Matrix3(),
  9501. uniform = {
  9502. value: null,
  9503. needsUpdate: false
  9504. };
  9505. this.uniform = uniform;
  9506. this.numPlanes = 0;
  9507. this.numIntersection = 0;
  9508. this.init = function (planes, enableLocalClipping, camera) {
  9509. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9510. // run another frame in order to reset the state:
  9511. numGlobalPlanes !== 0 || localClippingEnabled;
  9512. localClippingEnabled = enableLocalClipping;
  9513. globalState = projectPlanes(planes, camera, 0);
  9514. numGlobalPlanes = planes.length;
  9515. return enabled;
  9516. };
  9517. this.beginShadows = function () {
  9518. renderingShadows = true;
  9519. projectPlanes(null);
  9520. };
  9521. this.endShadows = function () {
  9522. renderingShadows = false;
  9523. resetGlobalState();
  9524. };
  9525. this.setState = function (material, camera, useCache) {
  9526. var planes = material.clippingPlanes,
  9527. clipIntersection = material.clipIntersection,
  9528. clipShadows = material.clipShadows;
  9529. var materialProperties = properties.get(material);
  9530. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9531. // there's no local clipping
  9532. if (renderingShadows) {
  9533. // there's no global clipping
  9534. projectPlanes(null);
  9535. } else {
  9536. resetGlobalState();
  9537. }
  9538. } else {
  9539. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9540. lGlobal = nGlobal * 4;
  9541. var dstArray = materialProperties.clippingState || null;
  9542. uniform.value = dstArray; // ensure unique state
  9543. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9544. for (var i = 0; i !== lGlobal; ++i) {
  9545. dstArray[i] = globalState[i];
  9546. }
  9547. materialProperties.clippingState = dstArray;
  9548. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9549. this.numPlanes += nGlobal;
  9550. }
  9551. };
  9552. function resetGlobalState() {
  9553. if (uniform.value !== globalState) {
  9554. uniform.value = globalState;
  9555. uniform.needsUpdate = numGlobalPlanes > 0;
  9556. }
  9557. scope.numPlanes = numGlobalPlanes;
  9558. scope.numIntersection = 0;
  9559. }
  9560. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9561. var nPlanes = planes !== null ? planes.length : 0;
  9562. var dstArray = null;
  9563. if (nPlanes !== 0) {
  9564. dstArray = uniform.value;
  9565. if (skipTransform !== true || dstArray === null) {
  9566. var flatSize = dstOffset + nPlanes * 4,
  9567. viewMatrix = camera.matrixWorldInverse;
  9568. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9569. if (dstArray === null || dstArray.length < flatSize) {
  9570. dstArray = new Float32Array(flatSize);
  9571. }
  9572. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9573. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9574. plane.normal.toArray(dstArray, i4);
  9575. dstArray[i4 + 3] = plane.constant;
  9576. }
  9577. }
  9578. uniform.value = dstArray;
  9579. uniform.needsUpdate = true;
  9580. }
  9581. scope.numPlanes = nPlanes;
  9582. scope.numIntersection = 0;
  9583. return dstArray;
  9584. }
  9585. }
  9586. function WebGLCubeMaps(renderer) {
  9587. var cubemaps = new WeakMap();
  9588. function mapTextureMapping(texture, mapping) {
  9589. if (mapping === EquirectangularReflectionMapping) {
  9590. texture.mapping = CubeReflectionMapping;
  9591. } else if (mapping === EquirectangularRefractionMapping) {
  9592. texture.mapping = CubeRefractionMapping;
  9593. }
  9594. return texture;
  9595. }
  9596. function get(texture) {
  9597. if (texture && texture.isTexture) {
  9598. var mapping = texture.mapping;
  9599. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9600. if (cubemaps.has(texture)) {
  9601. var cubemap = cubemaps.get(texture).texture;
  9602. return mapTextureMapping(cubemap, texture.mapping);
  9603. } else {
  9604. var image = texture.image;
  9605. if (image && image.height > 0) {
  9606. var currentRenderList = renderer.getRenderList();
  9607. var currentRenderTarget = renderer.getRenderTarget();
  9608. var currentRenderState = renderer.getRenderState();
  9609. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9610. renderTarget.fromEquirectangularTexture(renderer, texture);
  9611. cubemaps.set(texture, renderTarget);
  9612. renderer.setRenderTarget(currentRenderTarget);
  9613. renderer.setRenderList(currentRenderList);
  9614. renderer.setRenderState(currentRenderState);
  9615. texture.addEventListener('dispose', onTextureDispose);
  9616. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9617. } else {
  9618. // image not yet ready. try the conversion next frame
  9619. return null;
  9620. }
  9621. }
  9622. }
  9623. }
  9624. return texture;
  9625. }
  9626. function onTextureDispose(event) {
  9627. var texture = event.target;
  9628. texture.removeEventListener('dispose', onTextureDispose);
  9629. var cubemap = cubemaps.get(texture);
  9630. if (cubemap !== undefined) {
  9631. cubemaps.delete(texture);
  9632. cubemap.dispose();
  9633. }
  9634. }
  9635. function dispose() {
  9636. cubemaps = new WeakMap();
  9637. }
  9638. return {
  9639. get: get,
  9640. dispose: dispose
  9641. };
  9642. }
  9643. function WebGLExtensions(gl) {
  9644. var extensions = {};
  9645. return {
  9646. has: function has(name) {
  9647. if (extensions[name] !== undefined) {
  9648. return extensions[name] !== null;
  9649. }
  9650. var extension;
  9651. switch (name) {
  9652. case 'WEBGL_depth_texture':
  9653. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9654. break;
  9655. case 'EXT_texture_filter_anisotropic':
  9656. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9657. break;
  9658. case 'WEBGL_compressed_texture_s3tc':
  9659. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9660. break;
  9661. case 'WEBGL_compressed_texture_pvrtc':
  9662. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9663. break;
  9664. default:
  9665. extension = gl.getExtension(name);
  9666. }
  9667. extensions[name] = extension;
  9668. return extension !== null;
  9669. },
  9670. get: function get(name) {
  9671. if (!this.has(name)) {
  9672. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9673. }
  9674. return extensions[name];
  9675. }
  9676. };
  9677. }
  9678. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9679. var geometries = new WeakMap();
  9680. var wireframeAttributes = new WeakMap();
  9681. function onGeometryDispose(event) {
  9682. var geometry = event.target;
  9683. var buffergeometry = geometries.get(geometry);
  9684. if (buffergeometry.index !== null) {
  9685. attributes.remove(buffergeometry.index);
  9686. }
  9687. for (var name in buffergeometry.attributes) {
  9688. attributes.remove(buffergeometry.attributes[name]);
  9689. }
  9690. geometry.removeEventListener('dispose', onGeometryDispose);
  9691. geometries.delete(geometry);
  9692. var attribute = wireframeAttributes.get(buffergeometry);
  9693. if (attribute) {
  9694. attributes.remove(attribute);
  9695. wireframeAttributes.delete(buffergeometry);
  9696. }
  9697. bindingStates.releaseStatesOfGeometry(buffergeometry);
  9698. if (geometry.isInstancedBufferGeometry === true) {
  9699. delete geometry._maxInstanceCount;
  9700. } //
  9701. info.memory.geometries--;
  9702. }
  9703. function get(object, geometry) {
  9704. var buffergeometry = geometries.get(geometry);
  9705. if (buffergeometry) return buffergeometry;
  9706. geometry.addEventListener('dispose', onGeometryDispose);
  9707. if (geometry.isBufferGeometry) {
  9708. buffergeometry = geometry;
  9709. } else if (geometry.isGeometry) {
  9710. if (geometry._bufferGeometry === undefined) {
  9711. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9712. }
  9713. buffergeometry = geometry._bufferGeometry;
  9714. }
  9715. geometries.set(geometry, buffergeometry);
  9716. info.memory.geometries++;
  9717. return buffergeometry;
  9718. }
  9719. function update(geometry) {
  9720. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9721. for (var name in geometryAttributes) {
  9722. attributes.update(geometryAttributes[name], 34962);
  9723. } // morph targets
  9724. var morphAttributes = geometry.morphAttributes;
  9725. for (var _name in morphAttributes) {
  9726. var array = morphAttributes[_name];
  9727. for (var i = 0, l = array.length; i < l; i++) {
  9728. attributes.update(array[i], 34962);
  9729. }
  9730. }
  9731. }
  9732. function updateWireframeAttribute(geometry) {
  9733. var indices = [];
  9734. var geometryIndex = geometry.index;
  9735. var geometryPosition = geometry.attributes.position;
  9736. var version = 0;
  9737. if (geometryIndex !== null) {
  9738. var array = geometryIndex.array;
  9739. version = geometryIndex.version;
  9740. for (var i = 0, l = array.length; i < l; i += 3) {
  9741. var a = array[i + 0];
  9742. var b = array[i + 1];
  9743. var c = array[i + 2];
  9744. indices.push(a, b, b, c, c, a);
  9745. }
  9746. } else {
  9747. var _array = geometryPosition.array;
  9748. version = geometryPosition.version;
  9749. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9750. var _a = _i + 0;
  9751. var _b = _i + 1;
  9752. var _c = _i + 2;
  9753. indices.push(_a, _b, _b, _c, _c, _a);
  9754. }
  9755. }
  9756. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9757. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9758. //
  9759. var previousAttribute = wireframeAttributes.get(geometry);
  9760. if (previousAttribute) attributes.remove(previousAttribute); //
  9761. wireframeAttributes.set(geometry, attribute);
  9762. }
  9763. function getWireframeAttribute(geometry) {
  9764. var currentAttribute = wireframeAttributes.get(geometry);
  9765. if (currentAttribute) {
  9766. var geometryIndex = geometry.index;
  9767. if (geometryIndex !== null) {
  9768. // if the attribute is obsolete, create a new one
  9769. if (currentAttribute.version < geometryIndex.version) {
  9770. updateWireframeAttribute(geometry);
  9771. }
  9772. }
  9773. } else {
  9774. updateWireframeAttribute(geometry);
  9775. }
  9776. return wireframeAttributes.get(geometry);
  9777. }
  9778. return {
  9779. get: get,
  9780. update: update,
  9781. getWireframeAttribute: getWireframeAttribute
  9782. };
  9783. }
  9784. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9785. var isWebGL2 = capabilities.isWebGL2;
  9786. var mode;
  9787. function setMode(value) {
  9788. mode = value;
  9789. }
  9790. var type, bytesPerElement;
  9791. function setIndex(value) {
  9792. type = value.type;
  9793. bytesPerElement = value.bytesPerElement;
  9794. }
  9795. function render(start, count) {
  9796. gl.drawElements(mode, count, type, start * bytesPerElement);
  9797. info.update(count, mode, 1);
  9798. }
  9799. function renderInstances(start, count, primcount) {
  9800. if (primcount === 0) return;
  9801. var extension, methodName;
  9802. if (isWebGL2) {
  9803. extension = gl;
  9804. methodName = 'drawElementsInstanced';
  9805. } else {
  9806. extension = extensions.get('ANGLE_instanced_arrays');
  9807. methodName = 'drawElementsInstancedANGLE';
  9808. if (extension === null) {
  9809. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9810. return;
  9811. }
  9812. }
  9813. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9814. info.update(count, mode, primcount);
  9815. } //
  9816. this.setMode = setMode;
  9817. this.setIndex = setIndex;
  9818. this.render = render;
  9819. this.renderInstances = renderInstances;
  9820. }
  9821. function WebGLInfo(gl) {
  9822. var memory = {
  9823. geometries: 0,
  9824. textures: 0
  9825. };
  9826. var render = {
  9827. frame: 0,
  9828. calls: 0,
  9829. triangles: 0,
  9830. points: 0,
  9831. lines: 0
  9832. };
  9833. function update(count, mode, instanceCount) {
  9834. render.calls++;
  9835. switch (mode) {
  9836. case 4:
  9837. render.triangles += instanceCount * (count / 3);
  9838. break;
  9839. case 1:
  9840. render.lines += instanceCount * (count / 2);
  9841. break;
  9842. case 3:
  9843. render.lines += instanceCount * (count - 1);
  9844. break;
  9845. case 2:
  9846. render.lines += instanceCount * count;
  9847. break;
  9848. case 0:
  9849. render.points += instanceCount * count;
  9850. break;
  9851. default:
  9852. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9853. break;
  9854. }
  9855. }
  9856. function reset() {
  9857. render.frame++;
  9858. render.calls = 0;
  9859. render.triangles = 0;
  9860. render.points = 0;
  9861. render.lines = 0;
  9862. }
  9863. return {
  9864. memory: memory,
  9865. render: render,
  9866. programs: null,
  9867. autoReset: true,
  9868. reset: reset,
  9869. update: update
  9870. };
  9871. }
  9872. function numericalSort(a, b) {
  9873. return a[0] - b[0];
  9874. }
  9875. function absNumericalSort(a, b) {
  9876. return Math.abs(b[1]) - Math.abs(a[1]);
  9877. }
  9878. function WebGLMorphtargets(gl) {
  9879. var influencesList = {};
  9880. var morphInfluences = new Float32Array(8);
  9881. var workInfluences = [];
  9882. for (var i = 0; i < 8; i++) {
  9883. workInfluences[i] = [i, 0];
  9884. }
  9885. function update(object, geometry, material, program) {
  9886. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9887. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9888. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9889. var influences = influencesList[geometry.id];
  9890. if (influences === undefined) {
  9891. // initialise list
  9892. influences = [];
  9893. for (var _i = 0; _i < length; _i++) {
  9894. influences[_i] = [_i, 0];
  9895. }
  9896. influencesList[geometry.id] = influences;
  9897. } // Collect influences
  9898. for (var _i2 = 0; _i2 < length; _i2++) {
  9899. var influence = influences[_i2];
  9900. influence[0] = _i2;
  9901. influence[1] = objectInfluences[_i2];
  9902. }
  9903. influences.sort(absNumericalSort);
  9904. for (var _i3 = 0; _i3 < 8; _i3++) {
  9905. if (_i3 < length && influences[_i3][1]) {
  9906. workInfluences[_i3][0] = influences[_i3][0];
  9907. workInfluences[_i3][1] = influences[_i3][1];
  9908. } else {
  9909. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  9910. workInfluences[_i3][1] = 0;
  9911. }
  9912. }
  9913. workInfluences.sort(numericalSort);
  9914. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9915. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9916. var morphInfluencesSum = 0;
  9917. for (var _i4 = 0; _i4 < 8; _i4++) {
  9918. var _influence = workInfluences[_i4];
  9919. var index = _influence[0];
  9920. var value = _influence[1];
  9921. if (index !== Number.MAX_SAFE_INTEGER && value) {
  9922. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  9923. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  9924. }
  9925. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  9926. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  9927. }
  9928. morphInfluences[_i4] = value;
  9929. morphInfluencesSum += value;
  9930. } else {
  9931. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== undefined) {
  9932. geometry.deleteAttribute('morphTarget' + _i4);
  9933. }
  9934. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== undefined) {
  9935. geometry.deleteAttribute('morphNormal' + _i4);
  9936. }
  9937. morphInfluences[_i4] = 0;
  9938. }
  9939. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9940. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9941. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9942. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9943. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  9944. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  9945. }
  9946. return {
  9947. update: update
  9948. };
  9949. }
  9950. function WebGLObjects(gl, geometries, attributes, info) {
  9951. var updateMap = new WeakMap();
  9952. function update(object) {
  9953. var frame = info.render.frame;
  9954. var geometry = object.geometry;
  9955. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  9956. if (updateMap.get(buffergeometry) !== frame) {
  9957. if (geometry.isGeometry) {
  9958. buffergeometry.updateFromObject(object);
  9959. }
  9960. geometries.update(buffergeometry);
  9961. updateMap.set(buffergeometry, frame);
  9962. }
  9963. if (object.isInstancedMesh) {
  9964. attributes.update(object.instanceMatrix, 34962);
  9965. if (object.instanceColor !== null) {
  9966. attributes.update(object.instanceColor, 34962);
  9967. }
  9968. }
  9969. return buffergeometry;
  9970. }
  9971. function dispose() {
  9972. updateMap = new WeakMap();
  9973. }
  9974. return {
  9975. update: update,
  9976. dispose: dispose
  9977. };
  9978. }
  9979. function DataTexture2DArray(data, width, height, depth) {
  9980. Texture.call(this, null);
  9981. this.image = {
  9982. data: data || null,
  9983. width: width || 1,
  9984. height: height || 1,
  9985. depth: depth || 1
  9986. };
  9987. this.magFilter = NearestFilter;
  9988. this.minFilter = NearestFilter;
  9989. this.wrapR = ClampToEdgeWrapping;
  9990. this.generateMipmaps = false;
  9991. this.flipY = false;
  9992. this.needsUpdate = true;
  9993. }
  9994. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  9995. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9996. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9997. function DataTexture3D(data, width, height, depth) {
  9998. // We're going to add .setXXX() methods for setting properties later.
  9999. // Users can still set in DataTexture3D directly.
  10000. //
  10001. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10002. // texture.anisotropy = 16;
  10003. //
  10004. // See #14839
  10005. Texture.call(this, null);
  10006. this.image = {
  10007. data: data || null,
  10008. width: width || 1,
  10009. height: height || 1,
  10010. depth: depth || 1
  10011. };
  10012. this.magFilter = NearestFilter;
  10013. this.minFilter = NearestFilter;
  10014. this.wrapR = ClampToEdgeWrapping;
  10015. this.generateMipmaps = false;
  10016. this.flipY = false;
  10017. this.needsUpdate = true;
  10018. }
  10019. DataTexture3D.prototype = Object.create(Texture.prototype);
  10020. DataTexture3D.prototype.constructor = DataTexture3D;
  10021. DataTexture3D.prototype.isDataTexture3D = true;
  10022. /**
  10023. * Uniforms of a program.
  10024. * Those form a tree structure with a special top-level container for the root,
  10025. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10026. *
  10027. *
  10028. * Properties of inner nodes including the top-level container:
  10029. *
  10030. * .seq - array of nested uniforms
  10031. * .map - nested uniforms by name
  10032. *
  10033. *
  10034. * Methods of all nodes except the top-level container:
  10035. *
  10036. * .setValue( gl, value, [textures] )
  10037. *
  10038. * uploads a uniform value(s)
  10039. * the 'textures' parameter is needed for sampler uniforms
  10040. *
  10041. *
  10042. * Static methods of the top-level container (textures factorizations):
  10043. *
  10044. * .upload( gl, seq, values, textures )
  10045. *
  10046. * sets uniforms in 'seq' to 'values[id].value'
  10047. *
  10048. * .seqWithValue( seq, values ) : filteredSeq
  10049. *
  10050. * filters 'seq' entries with corresponding entry in values
  10051. *
  10052. *
  10053. * Methods of the top-level container (textures factorizations):
  10054. *
  10055. * .setValue( gl, name, value, textures )
  10056. *
  10057. * sets uniform with name 'name' to 'value'
  10058. *
  10059. * .setOptional( gl, obj, prop )
  10060. *
  10061. * like .set for an optional property of the object
  10062. *
  10063. */
  10064. var emptyTexture = new Texture();
  10065. var emptyTexture2dArray = new DataTexture2DArray();
  10066. var emptyTexture3d = new DataTexture3D();
  10067. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10068. // Array Caches (provide typed arrays for temporary by size)
  10069. var arrayCacheF32 = [];
  10070. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10071. var mat4array = new Float32Array(16);
  10072. var mat3array = new Float32Array(9);
  10073. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10074. function flatten(array, nBlocks, blockSize) {
  10075. var firstElem = array[0];
  10076. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10077. // see http://jacksondunstan.com/articles/983
  10078. var n = nBlocks * blockSize;
  10079. var r = arrayCacheF32[n];
  10080. if (r === undefined) {
  10081. r = new Float32Array(n);
  10082. arrayCacheF32[n] = r;
  10083. }
  10084. if (nBlocks !== 0) {
  10085. firstElem.toArray(r, 0);
  10086. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10087. offset += blockSize;
  10088. array[i].toArray(r, offset);
  10089. }
  10090. }
  10091. return r;
  10092. }
  10093. function arraysEqual(a, b) {
  10094. if (a.length !== b.length) return false;
  10095. for (var i = 0, l = a.length; i < l; i++) {
  10096. if (a[i] !== b[i]) return false;
  10097. }
  10098. return true;
  10099. }
  10100. function copyArray(a, b) {
  10101. for (var i = 0, l = b.length; i < l; i++) {
  10102. a[i] = b[i];
  10103. }
  10104. } // Texture unit allocation
  10105. function allocTexUnits(textures, n) {
  10106. var r = arrayCacheI32[n];
  10107. if (r === undefined) {
  10108. r = new Int32Array(n);
  10109. arrayCacheI32[n] = r;
  10110. }
  10111. for (var i = 0; i !== n; ++i) {
  10112. r[i] = textures.allocateTextureUnit();
  10113. }
  10114. return r;
  10115. } // --- Setters ---
  10116. // Note: Defining these methods externally, because they come in a bunch
  10117. // and this way their names minify.
  10118. // Single scalar
  10119. function setValueV1f(gl, v) {
  10120. var cache = this.cache;
  10121. if (cache[0] === v) return;
  10122. gl.uniform1f(this.addr, v);
  10123. cache[0] = v;
  10124. } // Single float vector (from flat array or THREE.VectorN)
  10125. function setValueV2f(gl, v) {
  10126. var cache = this.cache;
  10127. if (v.x !== undefined) {
  10128. if (cache[0] !== v.x || cache[1] !== v.y) {
  10129. gl.uniform2f(this.addr, v.x, v.y);
  10130. cache[0] = v.x;
  10131. cache[1] = v.y;
  10132. }
  10133. } else {
  10134. if (arraysEqual(cache, v)) return;
  10135. gl.uniform2fv(this.addr, v);
  10136. copyArray(cache, v);
  10137. }
  10138. }
  10139. function setValueV3f(gl, v) {
  10140. var cache = this.cache;
  10141. if (v.x !== undefined) {
  10142. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10143. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10144. cache[0] = v.x;
  10145. cache[1] = v.y;
  10146. cache[2] = v.z;
  10147. }
  10148. } else if (v.r !== undefined) {
  10149. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10150. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10151. cache[0] = v.r;
  10152. cache[1] = v.g;
  10153. cache[2] = v.b;
  10154. }
  10155. } else {
  10156. if (arraysEqual(cache, v)) return;
  10157. gl.uniform3fv(this.addr, v);
  10158. copyArray(cache, v);
  10159. }
  10160. }
  10161. function setValueV4f(gl, v) {
  10162. var cache = this.cache;
  10163. if (v.x !== undefined) {
  10164. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10165. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10166. cache[0] = v.x;
  10167. cache[1] = v.y;
  10168. cache[2] = v.z;
  10169. cache[3] = v.w;
  10170. }
  10171. } else {
  10172. if (arraysEqual(cache, v)) return;
  10173. gl.uniform4fv(this.addr, v);
  10174. copyArray(cache, v);
  10175. }
  10176. } // Single matrix (from flat array or MatrixN)
  10177. function setValueM2(gl, v) {
  10178. var cache = this.cache;
  10179. var elements = v.elements;
  10180. if (elements === undefined) {
  10181. if (arraysEqual(cache, v)) return;
  10182. gl.uniformMatrix2fv(this.addr, false, v);
  10183. copyArray(cache, v);
  10184. } else {
  10185. if (arraysEqual(cache, elements)) return;
  10186. mat2array.set(elements);
  10187. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10188. copyArray(cache, elements);
  10189. }
  10190. }
  10191. function setValueM3(gl, v) {
  10192. var cache = this.cache;
  10193. var elements = v.elements;
  10194. if (elements === undefined) {
  10195. if (arraysEqual(cache, v)) return;
  10196. gl.uniformMatrix3fv(this.addr, false, v);
  10197. copyArray(cache, v);
  10198. } else {
  10199. if (arraysEqual(cache, elements)) return;
  10200. mat3array.set(elements);
  10201. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10202. copyArray(cache, elements);
  10203. }
  10204. }
  10205. function setValueM4(gl, v) {
  10206. var cache = this.cache;
  10207. var elements = v.elements;
  10208. if (elements === undefined) {
  10209. if (arraysEqual(cache, v)) return;
  10210. gl.uniformMatrix4fv(this.addr, false, v);
  10211. copyArray(cache, v);
  10212. } else {
  10213. if (arraysEqual(cache, elements)) return;
  10214. mat4array.set(elements);
  10215. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10216. copyArray(cache, elements);
  10217. }
  10218. } // Single texture (2D / Cube)
  10219. function setValueT1(gl, v, textures) {
  10220. var cache = this.cache;
  10221. var unit = textures.allocateTextureUnit();
  10222. if (cache[0] !== unit) {
  10223. gl.uniform1i(this.addr, unit);
  10224. cache[0] = unit;
  10225. }
  10226. textures.safeSetTexture2D(v || emptyTexture, unit);
  10227. }
  10228. function setValueT2DArray1(gl, v, textures) {
  10229. var cache = this.cache;
  10230. var unit = textures.allocateTextureUnit();
  10231. if (cache[0] !== unit) {
  10232. gl.uniform1i(this.addr, unit);
  10233. cache[0] = unit;
  10234. }
  10235. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10236. }
  10237. function setValueT3D1(gl, v, textures) {
  10238. var cache = this.cache;
  10239. var unit = textures.allocateTextureUnit();
  10240. if (cache[0] !== unit) {
  10241. gl.uniform1i(this.addr, unit);
  10242. cache[0] = unit;
  10243. }
  10244. textures.setTexture3D(v || emptyTexture3d, unit);
  10245. }
  10246. function setValueT6(gl, v, textures) {
  10247. var cache = this.cache;
  10248. var unit = textures.allocateTextureUnit();
  10249. if (cache[0] !== unit) {
  10250. gl.uniform1i(this.addr, unit);
  10251. cache[0] = unit;
  10252. }
  10253. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10254. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10255. function setValueV1i(gl, v) {
  10256. var cache = this.cache;
  10257. if (cache[0] === v) return;
  10258. gl.uniform1i(this.addr, v);
  10259. cache[0] = v;
  10260. }
  10261. function setValueV2i(gl, v) {
  10262. var cache = this.cache;
  10263. if (arraysEqual(cache, v)) return;
  10264. gl.uniform2iv(this.addr, v);
  10265. copyArray(cache, v);
  10266. }
  10267. function setValueV3i(gl, v) {
  10268. var cache = this.cache;
  10269. if (arraysEqual(cache, v)) return;
  10270. gl.uniform3iv(this.addr, v);
  10271. copyArray(cache, v);
  10272. }
  10273. function setValueV4i(gl, v) {
  10274. var cache = this.cache;
  10275. if (arraysEqual(cache, v)) return;
  10276. gl.uniform4iv(this.addr, v);
  10277. copyArray(cache, v);
  10278. } // uint
  10279. function setValueV1ui(gl, v) {
  10280. var cache = this.cache;
  10281. if (cache[0] === v) return;
  10282. gl.uniform1ui(this.addr, v);
  10283. cache[0] = v;
  10284. } // Helper to pick the right setter for the singular case
  10285. function getSingularSetter(type) {
  10286. switch (type) {
  10287. case 0x1406:
  10288. return setValueV1f;
  10289. // FLOAT
  10290. case 0x8b50:
  10291. return setValueV2f;
  10292. // _VEC2
  10293. case 0x8b51:
  10294. return setValueV3f;
  10295. // _VEC3
  10296. case 0x8b52:
  10297. return setValueV4f;
  10298. // _VEC4
  10299. case 0x8b5a:
  10300. return setValueM2;
  10301. // _MAT2
  10302. case 0x8b5b:
  10303. return setValueM3;
  10304. // _MAT3
  10305. case 0x8b5c:
  10306. return setValueM4;
  10307. // _MAT4
  10308. case 0x1404:
  10309. case 0x8b56:
  10310. return setValueV1i;
  10311. // INT, BOOL
  10312. case 0x8b53:
  10313. case 0x8b57:
  10314. return setValueV2i;
  10315. // _VEC2
  10316. case 0x8b54:
  10317. case 0x8b58:
  10318. return setValueV3i;
  10319. // _VEC3
  10320. case 0x8b55:
  10321. case 0x8b59:
  10322. return setValueV4i;
  10323. // _VEC4
  10324. case 0x1405:
  10325. return setValueV1ui;
  10326. // UINT
  10327. case 0x8b5e: // SAMPLER_2D
  10328. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10329. case 0x8dca: // INT_SAMPLER_2D
  10330. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10331. case 0x8b62:
  10332. // SAMPLER_2D_SHADOW
  10333. return setValueT1;
  10334. case 0x8b5f: // SAMPLER_3D
  10335. case 0x8dcb: // INT_SAMPLER_3D
  10336. case 0x8dd3:
  10337. // UNSIGNED_INT_SAMPLER_3D
  10338. return setValueT3D1;
  10339. case 0x8b60: // SAMPLER_CUBE
  10340. case 0x8dcc: // INT_SAMPLER_CUBE
  10341. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10342. case 0x8dc5:
  10343. // SAMPLER_CUBE_SHADOW
  10344. return setValueT6;
  10345. case 0x8dc1: // SAMPLER_2D_ARRAY
  10346. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10347. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10348. case 0x8dc4:
  10349. // SAMPLER_2D_ARRAY_SHADOW
  10350. return setValueT2DArray1;
  10351. }
  10352. } // Array of scalars
  10353. function setValueV1fArray(gl, v) {
  10354. gl.uniform1fv(this.addr, v);
  10355. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10356. function setValueV1iArray(gl, v) {
  10357. gl.uniform1iv(this.addr, v);
  10358. }
  10359. function setValueV2iArray(gl, v) {
  10360. gl.uniform2iv(this.addr, v);
  10361. }
  10362. function setValueV3iArray(gl, v) {
  10363. gl.uniform3iv(this.addr, v);
  10364. }
  10365. function setValueV4iArray(gl, v) {
  10366. gl.uniform4iv(this.addr, v);
  10367. } // Array of vectors (flat or from THREE classes)
  10368. function setValueV2fArray(gl, v) {
  10369. var data = flatten(v, this.size, 2);
  10370. gl.uniform2fv(this.addr, data);
  10371. }
  10372. function setValueV3fArray(gl, v) {
  10373. var data = flatten(v, this.size, 3);
  10374. gl.uniform3fv(this.addr, data);
  10375. }
  10376. function setValueV4fArray(gl, v) {
  10377. var data = flatten(v, this.size, 4);
  10378. gl.uniform4fv(this.addr, data);
  10379. } // Array of matrices (flat or from THREE clases)
  10380. function setValueM2Array(gl, v) {
  10381. var data = flatten(v, this.size, 4);
  10382. gl.uniformMatrix2fv(this.addr, false, data);
  10383. }
  10384. function setValueM3Array(gl, v) {
  10385. var data = flatten(v, this.size, 9);
  10386. gl.uniformMatrix3fv(this.addr, false, data);
  10387. }
  10388. function setValueM4Array(gl, v) {
  10389. var data = flatten(v, this.size, 16);
  10390. gl.uniformMatrix4fv(this.addr, false, data);
  10391. } // Array of textures (2D / Cube)
  10392. function setValueT1Array(gl, v, textures) {
  10393. var n = v.length;
  10394. var units = allocTexUnits(textures, n);
  10395. gl.uniform1iv(this.addr, units);
  10396. for (var i = 0; i !== n; ++i) {
  10397. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10398. }
  10399. }
  10400. function setValueT6Array(gl, v, textures) {
  10401. var n = v.length;
  10402. var units = allocTexUnits(textures, n);
  10403. gl.uniform1iv(this.addr, units);
  10404. for (var i = 0; i !== n; ++i) {
  10405. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10406. }
  10407. } // Helper to pick the right setter for a pure (bottom-level) array
  10408. function getPureArraySetter(type) {
  10409. switch (type) {
  10410. case 0x1406:
  10411. return setValueV1fArray;
  10412. // FLOAT
  10413. case 0x8b50:
  10414. return setValueV2fArray;
  10415. // _VEC2
  10416. case 0x8b51:
  10417. return setValueV3fArray;
  10418. // _VEC3
  10419. case 0x8b52:
  10420. return setValueV4fArray;
  10421. // _VEC4
  10422. case 0x8b5a:
  10423. return setValueM2Array;
  10424. // _MAT2
  10425. case 0x8b5b:
  10426. return setValueM3Array;
  10427. // _MAT3
  10428. case 0x8b5c:
  10429. return setValueM4Array;
  10430. // _MAT4
  10431. case 0x1404:
  10432. case 0x8b56:
  10433. return setValueV1iArray;
  10434. // INT, BOOL
  10435. case 0x8b53:
  10436. case 0x8b57:
  10437. return setValueV2iArray;
  10438. // _VEC2
  10439. case 0x8b54:
  10440. case 0x8b58:
  10441. return setValueV3iArray;
  10442. // _VEC3
  10443. case 0x8b55:
  10444. case 0x8b59:
  10445. return setValueV4iArray;
  10446. // _VEC4
  10447. case 0x8b5e: // SAMPLER_2D
  10448. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10449. case 0x8dca: // INT_SAMPLER_2D
  10450. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10451. case 0x8b62:
  10452. // SAMPLER_2D_SHADOW
  10453. return setValueT1Array;
  10454. case 0x8b60: // SAMPLER_CUBE
  10455. case 0x8dcc: // INT_SAMPLER_CUBE
  10456. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10457. case 0x8dc5:
  10458. // SAMPLER_CUBE_SHADOW
  10459. return setValueT6Array;
  10460. }
  10461. } // --- Uniform Classes ---
  10462. function SingleUniform(id, activeInfo, addr) {
  10463. this.id = id;
  10464. this.addr = addr;
  10465. this.cache = [];
  10466. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10467. }
  10468. function PureArrayUniform(id, activeInfo, addr) {
  10469. this.id = id;
  10470. this.addr = addr;
  10471. this.cache = [];
  10472. this.size = activeInfo.size;
  10473. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10474. }
  10475. PureArrayUniform.prototype.updateCache = function (data) {
  10476. var cache = this.cache;
  10477. if (data instanceof Float32Array && cache.length !== data.length) {
  10478. this.cache = new Float32Array(data.length);
  10479. }
  10480. copyArray(cache, data);
  10481. };
  10482. function StructuredUniform(id) {
  10483. this.id = id;
  10484. this.seq = [];
  10485. this.map = {};
  10486. }
  10487. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10488. var seq = this.seq;
  10489. for (var i = 0, n = seq.length; i !== n; ++i) {
  10490. var u = seq[i];
  10491. u.setValue(gl, value[u.id], textures);
  10492. }
  10493. }; // --- Top-level ---
  10494. // Parser - builds up the property tree from the path strings
  10495. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; // extracts
  10496. // - the identifier (member name or array index)
  10497. // - followed by an optional right bracket (found when array index)
  10498. // - followed by an optional left bracket or dot (type of subscript)
  10499. //
  10500. // Note: These portions can be read in a non-overlapping fashion and
  10501. // allow straightforward parsing of the hierarchy that WebGL encodes
  10502. // in the uniform names.
  10503. function addUniform(container, uniformObject) {
  10504. container.seq.push(uniformObject);
  10505. container.map[uniformObject.id] = uniformObject;
  10506. }
  10507. function parseUniform(activeInfo, addr, container) {
  10508. var path = activeInfo.name,
  10509. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10510. RePathPart.lastIndex = 0;
  10511. while (true) {
  10512. var match = RePathPart.exec(path),
  10513. matchEnd = RePathPart.lastIndex;
  10514. var id = match[1];
  10515. var idIsIndex = match[2] === ']',
  10516. subscript = match[3];
  10517. if (idIsIndex) id = id | 0; // convert to integer
  10518. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10519. // bare name or "pure" bottom-level array "[0]" suffix
  10520. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10521. break;
  10522. } else {
  10523. // step into inner node / create it in case it doesn't exist
  10524. var map = container.map;
  10525. var next = map[id];
  10526. if (next === undefined) {
  10527. next = new StructuredUniform(id);
  10528. addUniform(container, next);
  10529. }
  10530. container = next;
  10531. }
  10532. }
  10533. } // Root Container
  10534. function WebGLUniforms(gl, program) {
  10535. this.seq = [];
  10536. this.map = {};
  10537. var n = gl.getProgramParameter(program, 35718);
  10538. for (var i = 0; i < n; ++i) {
  10539. var info = gl.getActiveUniform(program, i),
  10540. addr = gl.getUniformLocation(program, info.name);
  10541. parseUniform(info, addr, this);
  10542. }
  10543. }
  10544. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10545. var u = this.map[name];
  10546. if (u !== undefined) u.setValue(gl, value, textures);
  10547. };
  10548. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10549. var v = object[name];
  10550. if (v !== undefined) this.setValue(gl, name, v);
  10551. }; // Static interface
  10552. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10553. for (var i = 0, n = seq.length; i !== n; ++i) {
  10554. var u = seq[i],
  10555. v = values[u.id];
  10556. if (v.needsUpdate !== false) {
  10557. // note: always updating when .needsUpdate is undefined
  10558. u.setValue(gl, v.value, textures);
  10559. }
  10560. }
  10561. };
  10562. WebGLUniforms.seqWithValue = function (seq, values) {
  10563. var r = [];
  10564. for (var i = 0, n = seq.length; i !== n; ++i) {
  10565. var u = seq[i];
  10566. if (u.id in values) r.push(u);
  10567. }
  10568. return r;
  10569. };
  10570. function WebGLShader(gl, type, string) {
  10571. var shader = gl.createShader(type);
  10572. gl.shaderSource(shader, string);
  10573. gl.compileShader(shader);
  10574. return shader;
  10575. }
  10576. var programIdCount = 0;
  10577. function addLineNumbers(string) {
  10578. var lines = string.split('\n');
  10579. for (var i = 0; i < lines.length; i++) {
  10580. lines[i] = i + 1 + ': ' + lines[i];
  10581. }
  10582. return lines.join('\n');
  10583. }
  10584. function getEncodingComponents(encoding) {
  10585. switch (encoding) {
  10586. case LinearEncoding:
  10587. return ['Linear', '( value )'];
  10588. case sRGBEncoding:
  10589. return ['sRGB', '( value )'];
  10590. case RGBEEncoding:
  10591. return ['RGBE', '( value )'];
  10592. case RGBM7Encoding:
  10593. return ['RGBM', '( value, 7.0 )'];
  10594. case RGBM16Encoding:
  10595. return ['RGBM', '( value, 16.0 )'];
  10596. case RGBDEncoding:
  10597. return ['RGBD', '( value, 256.0 )'];
  10598. case GammaEncoding:
  10599. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10600. case LogLuvEncoding:
  10601. return ['LogLuv', '( value )'];
  10602. default:
  10603. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10604. return ['Linear', '( value )'];
  10605. }
  10606. }
  10607. function getShaderErrors(gl, shader, type) {
  10608. var status = gl.getShaderParameter(shader, 35713);
  10609. var log = gl.getShaderInfoLog(shader).trim();
  10610. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10611. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10612. var source = gl.getShaderSource(shader);
  10613. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10614. }
  10615. function getTexelDecodingFunction(functionName, encoding) {
  10616. var components = getEncodingComponents(encoding);
  10617. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10618. }
  10619. function getTexelEncodingFunction(functionName, encoding) {
  10620. var components = getEncodingComponents(encoding);
  10621. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10622. }
  10623. function getToneMappingFunction(functionName, toneMapping) {
  10624. var toneMappingName;
  10625. switch (toneMapping) {
  10626. case LinearToneMapping:
  10627. toneMappingName = 'Linear';
  10628. break;
  10629. case ReinhardToneMapping:
  10630. toneMappingName = 'Reinhard';
  10631. break;
  10632. case CineonToneMapping:
  10633. toneMappingName = 'OptimizedCineon';
  10634. break;
  10635. case ACESFilmicToneMapping:
  10636. toneMappingName = 'ACESFilmic';
  10637. break;
  10638. case CustomToneMapping:
  10639. toneMappingName = 'Custom';
  10640. break;
  10641. default:
  10642. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10643. toneMappingName = 'Linear';
  10644. }
  10645. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10646. }
  10647. function generateExtensions(parameters) {
  10648. 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' : ''];
  10649. return chunks.filter(filterEmptyLine).join('\n');
  10650. }
  10651. function generateDefines(defines) {
  10652. var chunks = [];
  10653. for (var name in defines) {
  10654. var value = defines[name];
  10655. if (value === false) continue;
  10656. chunks.push('#define ' + name + ' ' + value);
  10657. }
  10658. return chunks.join('\n');
  10659. }
  10660. function fetchAttributeLocations(gl, program) {
  10661. var attributes = {};
  10662. var n = gl.getProgramParameter(program, 35721);
  10663. for (var i = 0; i < n; i++) {
  10664. var info = gl.getActiveAttrib(program, i);
  10665. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10666. attributes[name] = gl.getAttribLocation(program, name);
  10667. }
  10668. return attributes;
  10669. }
  10670. function filterEmptyLine(string) {
  10671. return string !== '';
  10672. }
  10673. function replaceLightNums(string, parameters) {
  10674. 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);
  10675. }
  10676. function replaceClippingPlaneNums(string, parameters) {
  10677. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10678. } // Resolve Includes
  10679. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10680. function resolveIncludes(string) {
  10681. return string.replace(includePattern, includeReplacer);
  10682. }
  10683. function includeReplacer(match, include) {
  10684. var string = ShaderChunk[include];
  10685. if (string === undefined) {
  10686. throw new Error('Can not resolve #include <' + include + '>');
  10687. }
  10688. return resolveIncludes(string);
  10689. } // Unroll Loops
  10690. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10691. 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;
  10692. function unrollLoops(string) {
  10693. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10694. }
  10695. function deprecatedLoopReplacer(match, start, end, snippet) {
  10696. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10697. return loopReplacer(match, start, end, snippet);
  10698. }
  10699. function loopReplacer(match, start, end, snippet) {
  10700. var string = '';
  10701. for (var i = parseInt(start); i < parseInt(end); i++) {
  10702. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10703. }
  10704. return string;
  10705. } //
  10706. function generatePrecision(parameters) {
  10707. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  10708. if (parameters.precision === "highp") {
  10709. precisionstring += "\n#define HIGH_PRECISION";
  10710. } else if (parameters.precision === "mediump") {
  10711. precisionstring += "\n#define MEDIUM_PRECISION";
  10712. } else if (parameters.precision === "lowp") {
  10713. precisionstring += "\n#define LOW_PRECISION";
  10714. }
  10715. return precisionstring;
  10716. }
  10717. function generateShadowMapTypeDefine(parameters) {
  10718. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10719. if (parameters.shadowMapType === PCFShadowMap) {
  10720. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10721. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10722. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10723. } else if (parameters.shadowMapType === VSMShadowMap) {
  10724. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10725. }
  10726. return shadowMapTypeDefine;
  10727. }
  10728. function generateEnvMapTypeDefine(parameters) {
  10729. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10730. if (parameters.envMap) {
  10731. switch (parameters.envMapMode) {
  10732. case CubeReflectionMapping:
  10733. case CubeRefractionMapping:
  10734. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10735. break;
  10736. case CubeUVReflectionMapping:
  10737. case CubeUVRefractionMapping:
  10738. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10739. break;
  10740. }
  10741. }
  10742. return envMapTypeDefine;
  10743. }
  10744. function generateEnvMapModeDefine(parameters) {
  10745. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10746. if (parameters.envMap) {
  10747. switch (parameters.envMapMode) {
  10748. case CubeRefractionMapping:
  10749. case CubeUVRefractionMapping:
  10750. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10751. break;
  10752. }
  10753. }
  10754. return envMapModeDefine;
  10755. }
  10756. function generateEnvMapBlendingDefine(parameters) {
  10757. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10758. if (parameters.envMap) {
  10759. switch (parameters.combine) {
  10760. case MultiplyOperation:
  10761. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10762. break;
  10763. case MixOperation:
  10764. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10765. break;
  10766. case AddOperation:
  10767. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10768. break;
  10769. }
  10770. }
  10771. return envMapBlendingDefine;
  10772. }
  10773. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10774. var gl = renderer.getContext();
  10775. var defines = parameters.defines;
  10776. var vertexShader = parameters.vertexShader;
  10777. var fragmentShader = parameters.fragmentShader;
  10778. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10779. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10780. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10781. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10782. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10783. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10784. var customDefines = generateDefines(defines);
  10785. var program = gl.createProgram();
  10786. var prefixVertex, prefixFragment;
  10787. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + "\n" : '';
  10788. if (parameters.isRawShaderMaterial) {
  10789. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10790. if (prefixVertex.length > 0) {
  10791. prefixVertex += '\n';
  10792. }
  10793. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10794. if (prefixFragment.length > 0) {
  10795. prefixFragment += '\n';
  10796. }
  10797. } else {
  10798. 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');
  10799. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10800. '#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
  10801. 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
  10802. 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');
  10803. }
  10804. vertexShader = resolveIncludes(vertexShader);
  10805. vertexShader = replaceLightNums(vertexShader, parameters);
  10806. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10807. fragmentShader = resolveIncludes(fragmentShader);
  10808. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10809. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10810. vertexShader = unrollLoops(vertexShader);
  10811. fragmentShader = unrollLoops(fragmentShader);
  10812. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10813. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10814. versionString = '#version 300 es\n';
  10815. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10816. 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;
  10817. }
  10818. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10819. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10820. // console.log( '*FRAGMENT*', fragmentGlsl );
  10821. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10822. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10823. gl.attachShader(program, glVertexShader);
  10824. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10825. if (parameters.index0AttributeName !== undefined) {
  10826. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10827. } else if (parameters.morphTargets === true) {
  10828. // programs with morphTargets displace position out of attribute 0
  10829. gl.bindAttribLocation(program, 0, 'position');
  10830. }
  10831. gl.linkProgram(program); // check for link errors
  10832. if (renderer.debug.checkShaderErrors) {
  10833. var programLog = gl.getProgramInfoLog(program).trim();
  10834. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10835. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10836. var runnable = true;
  10837. var haveDiagnostics = true;
  10838. if (gl.getProgramParameter(program, 35714) === false) {
  10839. runnable = false;
  10840. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10841. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10842. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10843. } else if (programLog !== '') {
  10844. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10845. } else if (vertexLog === '' || fragmentLog === '') {
  10846. haveDiagnostics = false;
  10847. }
  10848. if (haveDiagnostics) {
  10849. this.diagnostics = {
  10850. runnable: runnable,
  10851. programLog: programLog,
  10852. vertexShader: {
  10853. log: vertexLog,
  10854. prefix: prefixVertex
  10855. },
  10856. fragmentShader: {
  10857. log: fragmentLog,
  10858. prefix: prefixFragment
  10859. }
  10860. };
  10861. }
  10862. } // Clean up
  10863. // Crashes in iOS9 and iOS10. #18402
  10864. // gl.detachShader( program, glVertexShader );
  10865. // gl.detachShader( program, glFragmentShader );
  10866. gl.deleteShader(glVertexShader);
  10867. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  10868. var cachedUniforms;
  10869. this.getUniforms = function () {
  10870. if (cachedUniforms === undefined) {
  10871. cachedUniforms = new WebGLUniforms(gl, program);
  10872. }
  10873. return cachedUniforms;
  10874. }; // set up caching for attribute locations
  10875. var cachedAttributes;
  10876. this.getAttributes = function () {
  10877. if (cachedAttributes === undefined) {
  10878. cachedAttributes = fetchAttributeLocations(gl, program);
  10879. }
  10880. return cachedAttributes;
  10881. }; // free resource
  10882. this.destroy = function () {
  10883. bindingStates.releaseStatesOfProgram(this);
  10884. gl.deleteProgram(program);
  10885. this.program = undefined;
  10886. }; //
  10887. this.name = parameters.shaderName;
  10888. this.id = programIdCount++;
  10889. this.cacheKey = cacheKey;
  10890. this.usedTimes = 1;
  10891. this.program = program;
  10892. this.vertexShader = glVertexShader;
  10893. this.fragmentShader = glFragmentShader;
  10894. return this;
  10895. }
  10896. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  10897. var programs = [];
  10898. var isWebGL2 = capabilities.isWebGL2;
  10899. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10900. var floatVertexTextures = capabilities.floatVertexTextures;
  10901. var maxVertexUniforms = capabilities.maxVertexUniforms;
  10902. var vertexTextures = capabilities.vertexTextures;
  10903. var precision = capabilities.precision;
  10904. var shaderIDs = {
  10905. MeshDepthMaterial: 'depth',
  10906. MeshDistanceMaterial: 'distanceRGBA',
  10907. MeshNormalMaterial: 'normal',
  10908. MeshBasicMaterial: 'basic',
  10909. MeshLambertMaterial: 'lambert',
  10910. MeshPhongMaterial: 'phong',
  10911. MeshToonMaterial: 'toon',
  10912. MeshStandardMaterial: 'physical',
  10913. MeshPhysicalMaterial: 'physical',
  10914. MeshMatcapMaterial: 'matcap',
  10915. LineBasicMaterial: 'basic',
  10916. LineDashedMaterial: 'dashed',
  10917. PointsMaterial: 'points',
  10918. ShadowMaterial: 'shadow',
  10919. SpriteMaterial: 'sprite'
  10920. };
  10921. 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"];
  10922. function getMaxBones(object) {
  10923. var skeleton = object.skeleton;
  10924. var bones = skeleton.bones;
  10925. if (floatVertexTextures) {
  10926. return 1024;
  10927. } else {
  10928. // default for when object is not specified
  10929. // ( for example when prebuilding shader to be used with multiple objects )
  10930. //
  10931. // - leave some extra space for other uniforms
  10932. // - limit here is ANGLE's 254 max uniform vectors
  10933. // (up to 54 should be safe)
  10934. var nVertexUniforms = maxVertexUniforms;
  10935. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  10936. var maxBones = Math.min(nVertexMatrices, bones.length);
  10937. if (maxBones < bones.length) {
  10938. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  10939. return 0;
  10940. }
  10941. return maxBones;
  10942. }
  10943. }
  10944. function getTextureEncodingFromMap(map) {
  10945. var encoding;
  10946. if (!map) {
  10947. encoding = LinearEncoding;
  10948. } else if (map.isTexture) {
  10949. encoding = map.encoding;
  10950. } else if (map.isWebGLRenderTarget) {
  10951. console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
  10952. encoding = map.texture.encoding;
  10953. }
  10954. return encoding;
  10955. }
  10956. function getParameters(material, lights, shadows, scene, object) {
  10957. var fog = scene.fog;
  10958. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  10959. var envMap = cubemaps.get(material.envMap || environment);
  10960. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  10961. // (not to blow over maxLights budget)
  10962. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  10963. if (material.precision !== null) {
  10964. precision = capabilities.getMaxPrecision(material.precision);
  10965. if (precision !== material.precision) {
  10966. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  10967. }
  10968. }
  10969. var vertexShader, fragmentShader;
  10970. if (shaderID) {
  10971. var shader = ShaderLib[shaderID];
  10972. vertexShader = shader.vertexShader;
  10973. fragmentShader = shader.fragmentShader;
  10974. } else {
  10975. vertexShader = material.vertexShader;
  10976. fragmentShader = material.fragmentShader;
  10977. }
  10978. var currentRenderTarget = renderer.getRenderTarget();
  10979. var parameters = {
  10980. isWebGL2: isWebGL2,
  10981. shaderID: shaderID,
  10982. shaderName: material.type,
  10983. vertexShader: vertexShader,
  10984. fragmentShader: fragmentShader,
  10985. defines: material.defines,
  10986. isRawShaderMaterial: material.isRawShaderMaterial === true,
  10987. glslVersion: material.glslVersion,
  10988. precision: precision,
  10989. instancing: object.isInstancedMesh === true,
  10990. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  10991. supportsVertexTextures: vertexTextures,
  10992. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  10993. map: !!material.map,
  10994. mapEncoding: getTextureEncodingFromMap(material.map),
  10995. matcap: !!material.matcap,
  10996. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  10997. envMap: !!envMap,
  10998. envMapMode: envMap && envMap.mapping,
  10999. envMapEncoding: getTextureEncodingFromMap(envMap),
  11000. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11001. lightMap: !!material.lightMap,
  11002. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11003. aoMap: !!material.aoMap,
  11004. emissiveMap: !!material.emissiveMap,
  11005. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11006. bumpMap: !!material.bumpMap,
  11007. normalMap: !!material.normalMap,
  11008. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11009. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11010. clearcoatMap: !!material.clearcoatMap,
  11011. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11012. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11013. displacementMap: !!material.displacementMap,
  11014. roughnessMap: !!material.roughnessMap,
  11015. metalnessMap: !!material.metalnessMap,
  11016. specularMap: !!material.specularMap,
  11017. alphaMap: !!material.alphaMap,
  11018. gradientMap: !!material.gradientMap,
  11019. sheen: !!material.sheen,
  11020. transmissionMap: !!material.transmissionMap,
  11021. combine: material.combine,
  11022. vertexTangents: material.normalMap && material.vertexTangents,
  11023. vertexColors: material.vertexColors,
  11024. 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,
  11025. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11026. fog: !!fog,
  11027. useFog: material.fog,
  11028. fogExp2: fog && fog.isFogExp2,
  11029. flatShading: material.flatShading,
  11030. sizeAttenuation: material.sizeAttenuation,
  11031. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11032. skinning: material.skinning && maxBones > 0,
  11033. maxBones: maxBones,
  11034. useVertexTexture: floatVertexTextures,
  11035. morphTargets: material.morphTargets,
  11036. morphNormals: material.morphNormals,
  11037. maxMorphTargets: renderer.maxMorphTargets,
  11038. maxMorphNormals: renderer.maxMorphNormals,
  11039. numDirLights: lights.directional.length,
  11040. numPointLights: lights.point.length,
  11041. numSpotLights: lights.spot.length,
  11042. numRectAreaLights: lights.rectArea.length,
  11043. numHemiLights: lights.hemi.length,
  11044. numDirLightShadows: lights.directionalShadowMap.length,
  11045. numPointLightShadows: lights.pointShadowMap.length,
  11046. numSpotLightShadows: lights.spotShadowMap.length,
  11047. numClippingPlanes: clipping.numPlanes,
  11048. numClipIntersection: clipping.numIntersection,
  11049. dithering: material.dithering,
  11050. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11051. shadowMapType: renderer.shadowMap.type,
  11052. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11053. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11054. premultipliedAlpha: material.premultipliedAlpha,
  11055. alphaTest: material.alphaTest,
  11056. doubleSided: material.side === DoubleSide,
  11057. flipSided: material.side === BackSide,
  11058. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11059. index0AttributeName: material.index0AttributeName,
  11060. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11061. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11062. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11063. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11064. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11065. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11066. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11067. customProgramCacheKey: material.customProgramCacheKey()
  11068. };
  11069. return parameters;
  11070. }
  11071. function getProgramCacheKey(parameters) {
  11072. var array = [];
  11073. if (parameters.shaderID) {
  11074. array.push(parameters.shaderID);
  11075. } else {
  11076. array.push(parameters.fragmentShader);
  11077. array.push(parameters.vertexShader);
  11078. }
  11079. if (parameters.defines !== undefined) {
  11080. for (var name in parameters.defines) {
  11081. array.push(name);
  11082. array.push(parameters.defines[name]);
  11083. }
  11084. }
  11085. if (parameters.isRawShaderMaterial === false) {
  11086. for (var i = 0; i < parameterNames.length; i++) {
  11087. array.push(parameters[parameterNames[i]]);
  11088. }
  11089. array.push(renderer.outputEncoding);
  11090. array.push(renderer.gammaFactor);
  11091. }
  11092. array.push(parameters.customProgramCacheKey);
  11093. return array.join();
  11094. }
  11095. function getUniforms(material) {
  11096. var shaderID = shaderIDs[material.type];
  11097. var uniforms;
  11098. if (shaderID) {
  11099. var shader = ShaderLib[shaderID];
  11100. uniforms = UniformsUtils.clone(shader.uniforms);
  11101. } else {
  11102. uniforms = material.uniforms;
  11103. }
  11104. return uniforms;
  11105. }
  11106. function acquireProgram(parameters, cacheKey) {
  11107. var program; // Check if code has been already compiled
  11108. for (var p = 0, pl = programs.length; p < pl; p++) {
  11109. var preexistingProgram = programs[p];
  11110. if (preexistingProgram.cacheKey === cacheKey) {
  11111. program = preexistingProgram;
  11112. ++program.usedTimes;
  11113. break;
  11114. }
  11115. }
  11116. if (program === undefined) {
  11117. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11118. programs.push(program);
  11119. }
  11120. return program;
  11121. }
  11122. function releaseProgram(program) {
  11123. if (--program.usedTimes === 0) {
  11124. // Remove from unordered set
  11125. var i = programs.indexOf(program);
  11126. programs[i] = programs[programs.length - 1];
  11127. programs.pop(); // Free WebGL resources
  11128. program.destroy();
  11129. }
  11130. }
  11131. return {
  11132. getParameters: getParameters,
  11133. getProgramCacheKey: getProgramCacheKey,
  11134. getUniforms: getUniforms,
  11135. acquireProgram: acquireProgram,
  11136. releaseProgram: releaseProgram,
  11137. // Exposed for resource monitoring & error feedback via renderer.info:
  11138. programs: programs
  11139. };
  11140. }
  11141. function WebGLProperties() {
  11142. var properties = new WeakMap();
  11143. function get(object) {
  11144. var map = properties.get(object);
  11145. if (map === undefined) {
  11146. map = {};
  11147. properties.set(object, map);
  11148. }
  11149. return map;
  11150. }
  11151. function remove(object) {
  11152. properties.delete(object);
  11153. }
  11154. function update(object, key, value) {
  11155. properties.get(object)[key] = value;
  11156. }
  11157. function dispose() {
  11158. properties = new WeakMap();
  11159. }
  11160. return {
  11161. get: get,
  11162. remove: remove,
  11163. update: update,
  11164. dispose: dispose
  11165. };
  11166. }
  11167. function painterSortStable(a, b) {
  11168. if (a.groupOrder !== b.groupOrder) {
  11169. return a.groupOrder - b.groupOrder;
  11170. } else if (a.renderOrder !== b.renderOrder) {
  11171. return a.renderOrder - b.renderOrder;
  11172. } else if (a.program !== b.program) {
  11173. return a.program.id - b.program.id;
  11174. } else if (a.material.id !== b.material.id) {
  11175. return a.material.id - b.material.id;
  11176. } else if (a.z !== b.z) {
  11177. return a.z - b.z;
  11178. } else {
  11179. return a.id - b.id;
  11180. }
  11181. }
  11182. function reversePainterSortStable(a, b) {
  11183. if (a.groupOrder !== b.groupOrder) {
  11184. return a.groupOrder - b.groupOrder;
  11185. } else if (a.renderOrder !== b.renderOrder) {
  11186. return a.renderOrder - b.renderOrder;
  11187. } else if (a.z !== b.z) {
  11188. return b.z - a.z;
  11189. } else {
  11190. return a.id - b.id;
  11191. }
  11192. }
  11193. function WebGLRenderList(properties) {
  11194. var renderItems = [];
  11195. var renderItemsIndex = 0;
  11196. var opaque = [];
  11197. var transparent = [];
  11198. var defaultProgram = {
  11199. id: -1
  11200. };
  11201. function init() {
  11202. renderItemsIndex = 0;
  11203. opaque.length = 0;
  11204. transparent.length = 0;
  11205. }
  11206. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11207. var renderItem = renderItems[renderItemsIndex];
  11208. var materialProperties = properties.get(material);
  11209. if (renderItem === undefined) {
  11210. renderItem = {
  11211. id: object.id,
  11212. object: object,
  11213. geometry: geometry,
  11214. material: material,
  11215. program: materialProperties.program || defaultProgram,
  11216. groupOrder: groupOrder,
  11217. renderOrder: object.renderOrder,
  11218. z: z,
  11219. group: group
  11220. };
  11221. renderItems[renderItemsIndex] = renderItem;
  11222. } else {
  11223. renderItem.id = object.id;
  11224. renderItem.object = object;
  11225. renderItem.geometry = geometry;
  11226. renderItem.material = material;
  11227. renderItem.program = materialProperties.program || defaultProgram;
  11228. renderItem.groupOrder = groupOrder;
  11229. renderItem.renderOrder = object.renderOrder;
  11230. renderItem.z = z;
  11231. renderItem.group = group;
  11232. }
  11233. renderItemsIndex++;
  11234. return renderItem;
  11235. }
  11236. function push(object, geometry, material, groupOrder, z, group) {
  11237. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11238. (material.transparent === true ? transparent : opaque).push(renderItem);
  11239. }
  11240. function unshift(object, geometry, material, groupOrder, z, group) {
  11241. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11242. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11243. }
  11244. function sort(customOpaqueSort, customTransparentSort) {
  11245. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11246. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11247. }
  11248. function finish() {
  11249. // Clear references from inactive renderItems in the list
  11250. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11251. var renderItem = renderItems[i];
  11252. if (renderItem.id === null) break;
  11253. renderItem.id = null;
  11254. renderItem.object = null;
  11255. renderItem.geometry = null;
  11256. renderItem.material = null;
  11257. renderItem.program = null;
  11258. renderItem.group = null;
  11259. }
  11260. }
  11261. return {
  11262. opaque: opaque,
  11263. transparent: transparent,
  11264. init: init,
  11265. push: push,
  11266. unshift: unshift,
  11267. finish: finish,
  11268. sort: sort
  11269. };
  11270. }
  11271. function WebGLRenderLists(properties) {
  11272. var lists = new WeakMap();
  11273. function get(scene, camera) {
  11274. var cameras = lists.get(scene);
  11275. var list;
  11276. if (cameras === undefined) {
  11277. list = new WebGLRenderList(properties);
  11278. lists.set(scene, new WeakMap());
  11279. lists.get(scene).set(camera, list);
  11280. } else {
  11281. list = cameras.get(camera);
  11282. if (list === undefined) {
  11283. list = new WebGLRenderList(properties);
  11284. cameras.set(camera, list);
  11285. }
  11286. }
  11287. return list;
  11288. }
  11289. function dispose() {
  11290. lists = new WeakMap();
  11291. }
  11292. return {
  11293. get: get,
  11294. dispose: dispose
  11295. };
  11296. }
  11297. function UniformsCache() {
  11298. var lights = {};
  11299. return {
  11300. get: function get(light) {
  11301. if (lights[light.id] !== undefined) {
  11302. return lights[light.id];
  11303. }
  11304. var uniforms;
  11305. switch (light.type) {
  11306. case 'DirectionalLight':
  11307. uniforms = {
  11308. direction: new Vector3(),
  11309. color: new Color()
  11310. };
  11311. break;
  11312. case 'SpotLight':
  11313. uniforms = {
  11314. position: new Vector3(),
  11315. direction: new Vector3(),
  11316. color: new Color(),
  11317. distance: 0,
  11318. coneCos: 0,
  11319. penumbraCos: 0,
  11320. decay: 0
  11321. };
  11322. break;
  11323. case 'PointLight':
  11324. uniforms = {
  11325. position: new Vector3(),
  11326. color: new Color(),
  11327. distance: 0,
  11328. decay: 0
  11329. };
  11330. break;
  11331. case 'HemisphereLight':
  11332. uniforms = {
  11333. direction: new Vector3(),
  11334. skyColor: new Color(),
  11335. groundColor: new Color()
  11336. };
  11337. break;
  11338. case 'RectAreaLight':
  11339. uniforms = {
  11340. color: new Color(),
  11341. position: new Vector3(),
  11342. halfWidth: new Vector3(),
  11343. halfHeight: new Vector3()
  11344. };
  11345. break;
  11346. }
  11347. lights[light.id] = uniforms;
  11348. return uniforms;
  11349. }
  11350. };
  11351. }
  11352. function ShadowUniformsCache() {
  11353. var lights = {};
  11354. return {
  11355. get: function get(light) {
  11356. if (lights[light.id] !== undefined) {
  11357. return lights[light.id];
  11358. }
  11359. var uniforms;
  11360. switch (light.type) {
  11361. case 'DirectionalLight':
  11362. uniforms = {
  11363. shadowBias: 0,
  11364. shadowNormalBias: 0,
  11365. shadowRadius: 1,
  11366. shadowMapSize: new Vector2()
  11367. };
  11368. break;
  11369. case 'SpotLight':
  11370. uniforms = {
  11371. shadowBias: 0,
  11372. shadowNormalBias: 0,
  11373. shadowRadius: 1,
  11374. shadowMapSize: new Vector2()
  11375. };
  11376. break;
  11377. case 'PointLight':
  11378. uniforms = {
  11379. shadowBias: 0,
  11380. shadowNormalBias: 0,
  11381. shadowRadius: 1,
  11382. shadowMapSize: new Vector2(),
  11383. shadowCameraNear: 1,
  11384. shadowCameraFar: 1000
  11385. };
  11386. break;
  11387. // TODO (abelnation): set RectAreaLight shadow uniforms
  11388. }
  11389. lights[light.id] = uniforms;
  11390. return uniforms;
  11391. }
  11392. };
  11393. }
  11394. var nextVersion = 0;
  11395. function shadowCastingLightsFirst(lightA, lightB) {
  11396. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11397. }
  11398. function WebGLLights(extensions, capabilities) {
  11399. var cache = new UniformsCache();
  11400. var shadowCache = ShadowUniformsCache();
  11401. var state = {
  11402. version: 0,
  11403. hash: {
  11404. directionalLength: -1,
  11405. pointLength: -1,
  11406. spotLength: -1,
  11407. rectAreaLength: -1,
  11408. hemiLength: -1,
  11409. numDirectionalShadows: -1,
  11410. numPointShadows: -1,
  11411. numSpotShadows: -1
  11412. },
  11413. ambient: [0, 0, 0],
  11414. probe: [],
  11415. directional: [],
  11416. directionalShadow: [],
  11417. directionalShadowMap: [],
  11418. directionalShadowMatrix: [],
  11419. spot: [],
  11420. spotShadow: [],
  11421. spotShadowMap: [],
  11422. spotShadowMatrix: [],
  11423. rectArea: [],
  11424. rectAreaLTC1: null,
  11425. rectAreaLTC2: null,
  11426. point: [],
  11427. pointShadow: [],
  11428. pointShadowMap: [],
  11429. pointShadowMatrix: [],
  11430. hemi: []
  11431. };
  11432. for (var i = 0; i < 9; i++) {
  11433. state.probe.push(new Vector3());
  11434. }
  11435. var vector3 = new Vector3();
  11436. var matrix4 = new Matrix4();
  11437. var matrix42 = new Matrix4();
  11438. function setup(lights, shadows, camera) {
  11439. var r = 0,
  11440. g = 0,
  11441. b = 0;
  11442. for (var _i = 0; _i < 9; _i++) {
  11443. state.probe[_i].set(0, 0, 0);
  11444. }
  11445. var directionalLength = 0;
  11446. var pointLength = 0;
  11447. var spotLength = 0;
  11448. var rectAreaLength = 0;
  11449. var hemiLength = 0;
  11450. var numDirectionalShadows = 0;
  11451. var numPointShadows = 0;
  11452. var numSpotShadows = 0;
  11453. var viewMatrix = camera.matrixWorldInverse;
  11454. lights.sort(shadowCastingLightsFirst);
  11455. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11456. var light = lights[_i2];
  11457. var color = light.color;
  11458. var intensity = light.intensity;
  11459. var distance = light.distance;
  11460. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11461. if (light.isAmbientLight) {
  11462. r += color.r * intensity;
  11463. g += color.g * intensity;
  11464. b += color.b * intensity;
  11465. } else if (light.isLightProbe) {
  11466. for (var j = 0; j < 9; j++) {
  11467. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11468. }
  11469. } else if (light.isDirectionalLight) {
  11470. var uniforms = cache.get(light);
  11471. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11472. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11473. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11474. uniforms.direction.sub(vector3);
  11475. uniforms.direction.transformDirection(viewMatrix);
  11476. if (light.castShadow) {
  11477. var shadow = light.shadow;
  11478. var shadowUniforms = shadowCache.get(light);
  11479. shadowUniforms.shadowBias = shadow.bias;
  11480. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11481. shadowUniforms.shadowRadius = shadow.radius;
  11482. shadowUniforms.shadowMapSize = shadow.mapSize;
  11483. state.directionalShadow[directionalLength] = shadowUniforms;
  11484. state.directionalShadowMap[directionalLength] = shadowMap;
  11485. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11486. numDirectionalShadows++;
  11487. }
  11488. state.directional[directionalLength] = uniforms;
  11489. directionalLength++;
  11490. } else if (light.isSpotLight) {
  11491. var _uniforms = cache.get(light);
  11492. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11493. _uniforms.position.applyMatrix4(viewMatrix);
  11494. _uniforms.color.copy(color).multiplyScalar(intensity);
  11495. _uniforms.distance = distance;
  11496. _uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11497. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11498. _uniforms.direction.sub(vector3);
  11499. _uniforms.direction.transformDirection(viewMatrix);
  11500. _uniforms.coneCos = Math.cos(light.angle);
  11501. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11502. _uniforms.decay = light.decay;
  11503. if (light.castShadow) {
  11504. var _shadow = light.shadow;
  11505. var _shadowUniforms = shadowCache.get(light);
  11506. _shadowUniforms.shadowBias = _shadow.bias;
  11507. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11508. _shadowUniforms.shadowRadius = _shadow.radius;
  11509. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11510. state.spotShadow[spotLength] = _shadowUniforms;
  11511. state.spotShadowMap[spotLength] = shadowMap;
  11512. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11513. numSpotShadows++;
  11514. }
  11515. state.spot[spotLength] = _uniforms;
  11516. spotLength++;
  11517. } else if (light.isRectAreaLight) {
  11518. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11519. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11520. // (b) intensity is the brightness of the light
  11521. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11522. _uniforms2.position.setFromMatrixPosition(light.matrixWorld);
  11523. _uniforms2.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11524. matrix42.identity();
  11525. matrix4.copy(light.matrixWorld);
  11526. matrix4.premultiply(viewMatrix);
  11527. matrix42.extractRotation(matrix4);
  11528. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11529. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11530. _uniforms2.halfWidth.applyMatrix4(matrix42);
  11531. _uniforms2.halfHeight.applyMatrix4(matrix42); // TODO (abelnation): RectAreaLight distance?
  11532. // uniforms.distance = distance;
  11533. state.rectArea[rectAreaLength] = _uniforms2;
  11534. rectAreaLength++;
  11535. } else if (light.isPointLight) {
  11536. var _uniforms3 = cache.get(light);
  11537. _uniforms3.position.setFromMatrixPosition(light.matrixWorld);
  11538. _uniforms3.position.applyMatrix4(viewMatrix);
  11539. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11540. _uniforms3.distance = light.distance;
  11541. _uniforms3.decay = light.decay;
  11542. if (light.castShadow) {
  11543. var _shadow2 = light.shadow;
  11544. var _shadowUniforms2 = shadowCache.get(light);
  11545. _shadowUniforms2.shadowBias = _shadow2.bias;
  11546. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11547. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11548. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11549. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11550. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11551. state.pointShadow[pointLength] = _shadowUniforms2;
  11552. state.pointShadowMap[pointLength] = shadowMap;
  11553. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11554. numPointShadows++;
  11555. }
  11556. state.point[pointLength] = _uniforms3;
  11557. pointLength++;
  11558. } else if (light.isHemisphereLight) {
  11559. var _uniforms4 = cache.get(light);
  11560. _uniforms4.direction.setFromMatrixPosition(light.matrixWorld);
  11561. _uniforms4.direction.transformDirection(viewMatrix);
  11562. _uniforms4.direction.normalize();
  11563. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11564. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11565. state.hemi[hemiLength] = _uniforms4;
  11566. hemiLength++;
  11567. }
  11568. }
  11569. if (rectAreaLength > 0) {
  11570. if (capabilities.isWebGL2) {
  11571. // WebGL 2
  11572. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11573. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11574. } else {
  11575. // WebGL 1
  11576. if (extensions.has('OES_texture_float_linear') === true) {
  11577. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11578. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11579. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  11580. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11581. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11582. } else {
  11583. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  11584. }
  11585. }
  11586. }
  11587. state.ambient[0] = r;
  11588. state.ambient[1] = g;
  11589. state.ambient[2] = b;
  11590. var hash = state.hash;
  11591. 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) {
  11592. state.directional.length = directionalLength;
  11593. state.spot.length = spotLength;
  11594. state.rectArea.length = rectAreaLength;
  11595. state.point.length = pointLength;
  11596. state.hemi.length = hemiLength;
  11597. state.directionalShadow.length = numDirectionalShadows;
  11598. state.directionalShadowMap.length = numDirectionalShadows;
  11599. state.pointShadow.length = numPointShadows;
  11600. state.pointShadowMap.length = numPointShadows;
  11601. state.spotShadow.length = numSpotShadows;
  11602. state.spotShadowMap.length = numSpotShadows;
  11603. state.directionalShadowMatrix.length = numDirectionalShadows;
  11604. state.pointShadowMatrix.length = numPointShadows;
  11605. state.spotShadowMatrix.length = numSpotShadows;
  11606. hash.directionalLength = directionalLength;
  11607. hash.pointLength = pointLength;
  11608. hash.spotLength = spotLength;
  11609. hash.rectAreaLength = rectAreaLength;
  11610. hash.hemiLength = hemiLength;
  11611. hash.numDirectionalShadows = numDirectionalShadows;
  11612. hash.numPointShadows = numPointShadows;
  11613. hash.numSpotShadows = numSpotShadows;
  11614. state.version = nextVersion++;
  11615. }
  11616. }
  11617. return {
  11618. setup: setup,
  11619. state: state
  11620. };
  11621. }
  11622. function WebGLRenderState(extensions, capabilities) {
  11623. var lights = new WebGLLights(extensions, capabilities);
  11624. var lightsArray = [];
  11625. var shadowsArray = [];
  11626. function init() {
  11627. lightsArray.length = 0;
  11628. shadowsArray.length = 0;
  11629. }
  11630. function pushLight(light) {
  11631. lightsArray.push(light);
  11632. }
  11633. function pushShadow(shadowLight) {
  11634. shadowsArray.push(shadowLight);
  11635. }
  11636. function setupLights(camera) {
  11637. lights.setup(lightsArray, shadowsArray, camera);
  11638. }
  11639. var state = {
  11640. lightsArray: lightsArray,
  11641. shadowsArray: shadowsArray,
  11642. lights: lights
  11643. };
  11644. return {
  11645. init: init,
  11646. state: state,
  11647. setupLights: setupLights,
  11648. pushLight: pushLight,
  11649. pushShadow: pushShadow
  11650. };
  11651. }
  11652. function WebGLRenderStates(extensions, capabilities) {
  11653. var renderStates = new WeakMap();
  11654. function get(scene, camera) {
  11655. var renderState;
  11656. if (renderStates.has(scene) === false) {
  11657. renderState = new WebGLRenderState(extensions, capabilities);
  11658. renderStates.set(scene, new WeakMap());
  11659. renderStates.get(scene).set(camera, renderState);
  11660. } else {
  11661. if (renderStates.get(scene).has(camera) === false) {
  11662. renderState = new WebGLRenderState(extensions, capabilities);
  11663. renderStates.get(scene).set(camera, renderState);
  11664. } else {
  11665. renderState = renderStates.get(scene).get(camera);
  11666. }
  11667. }
  11668. return renderState;
  11669. }
  11670. function dispose() {
  11671. renderStates = new WeakMap();
  11672. }
  11673. return {
  11674. get: get,
  11675. dispose: dispose
  11676. };
  11677. }
  11678. /**
  11679. * parameters = {
  11680. *
  11681. * opacity: <float>,
  11682. *
  11683. * map: new THREE.Texture( <Image> ),
  11684. *
  11685. * alphaMap: new THREE.Texture( <Image> ),
  11686. *
  11687. * displacementMap: new THREE.Texture( <Image> ),
  11688. * displacementScale: <float>,
  11689. * displacementBias: <float>,
  11690. *
  11691. * wireframe: <boolean>,
  11692. * wireframeLinewidth: <float>
  11693. * }
  11694. */
  11695. function MeshDepthMaterial(parameters) {
  11696. Material.call(this);
  11697. this.type = 'MeshDepthMaterial';
  11698. this.depthPacking = BasicDepthPacking;
  11699. this.skinning = false;
  11700. this.morphTargets = false;
  11701. this.map = null;
  11702. this.alphaMap = null;
  11703. this.displacementMap = null;
  11704. this.displacementScale = 1;
  11705. this.displacementBias = 0;
  11706. this.wireframe = false;
  11707. this.wireframeLinewidth = 1;
  11708. this.fog = false;
  11709. this.setValues(parameters);
  11710. }
  11711. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11712. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11713. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11714. MeshDepthMaterial.prototype.copy = function (source) {
  11715. Material.prototype.copy.call(this, source);
  11716. this.depthPacking = source.depthPacking;
  11717. this.skinning = source.skinning;
  11718. this.morphTargets = source.morphTargets;
  11719. this.map = source.map;
  11720. this.alphaMap = source.alphaMap;
  11721. this.displacementMap = source.displacementMap;
  11722. this.displacementScale = source.displacementScale;
  11723. this.displacementBias = source.displacementBias;
  11724. this.wireframe = source.wireframe;
  11725. this.wireframeLinewidth = source.wireframeLinewidth;
  11726. return this;
  11727. };
  11728. /**
  11729. * parameters = {
  11730. *
  11731. * referencePosition: <float>,
  11732. * nearDistance: <float>,
  11733. * farDistance: <float>,
  11734. *
  11735. * skinning: <bool>,
  11736. * morphTargets: <bool>,
  11737. *
  11738. * map: new THREE.Texture( <Image> ),
  11739. *
  11740. * alphaMap: new THREE.Texture( <Image> ),
  11741. *
  11742. * displacementMap: new THREE.Texture( <Image> ),
  11743. * displacementScale: <float>,
  11744. * displacementBias: <float>
  11745. *
  11746. * }
  11747. */
  11748. function MeshDistanceMaterial(parameters) {
  11749. Material.call(this);
  11750. this.type = 'MeshDistanceMaterial';
  11751. this.referencePosition = new Vector3();
  11752. this.nearDistance = 1;
  11753. this.farDistance = 1000;
  11754. this.skinning = false;
  11755. this.morphTargets = false;
  11756. this.map = null;
  11757. this.alphaMap = null;
  11758. this.displacementMap = null;
  11759. this.displacementScale = 1;
  11760. this.displacementBias = 0;
  11761. this.fog = false;
  11762. this.setValues(parameters);
  11763. }
  11764. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11765. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11766. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11767. MeshDistanceMaterial.prototype.copy = function (source) {
  11768. Material.prototype.copy.call(this, source);
  11769. this.referencePosition.copy(source.referencePosition);
  11770. this.nearDistance = source.nearDistance;
  11771. this.farDistance = source.farDistance;
  11772. this.skinning = source.skinning;
  11773. this.morphTargets = source.morphTargets;
  11774. this.map = source.map;
  11775. this.alphaMap = source.alphaMap;
  11776. this.displacementMap = source.displacementMap;
  11777. this.displacementScale = source.displacementScale;
  11778. this.displacementBias = source.displacementBias;
  11779. return this;
  11780. };
  11781. 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 HORIZONAL_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}";
  11782. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11783. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11784. var _frustum = new Frustum();
  11785. var _shadowMapSize = new Vector2(),
  11786. _viewportSize = new Vector2(),
  11787. _viewport = new Vector4(),
  11788. _depthMaterials = [],
  11789. _distanceMaterials = [],
  11790. _materialCache = {};
  11791. var shadowSide = {
  11792. 0: BackSide,
  11793. 1: FrontSide,
  11794. 2: DoubleSide
  11795. };
  11796. var shadowMaterialVertical = new ShaderMaterial({
  11797. defines: {
  11798. SAMPLE_RATE: 2.0 / 8.0,
  11799. HALF_SAMPLE_RATE: 1.0 / 8.0
  11800. },
  11801. uniforms: {
  11802. shadow_pass: {
  11803. value: null
  11804. },
  11805. resolution: {
  11806. value: new Vector2()
  11807. },
  11808. radius: {
  11809. value: 4.0
  11810. }
  11811. },
  11812. vertexShader: vsm_vert,
  11813. fragmentShader: vsm_frag
  11814. });
  11815. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  11816. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  11817. var fullScreenTri = new BufferGeometry();
  11818. fullScreenTri.setAttribute("position", new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  11819. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  11820. var scope = this;
  11821. this.enabled = false;
  11822. this.autoUpdate = true;
  11823. this.needsUpdate = false;
  11824. this.type = PCFShadowMap;
  11825. this.render = function (lights, scene, camera) {
  11826. if (scope.enabled === false) return;
  11827. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  11828. if (lights.length === 0) return;
  11829. var currentRenderTarget = _renderer.getRenderTarget();
  11830. var activeCubeFace = _renderer.getActiveCubeFace();
  11831. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11832. var _state = _renderer.state; // Set GL state for depth map.
  11833. _state.setBlending(NoBlending);
  11834. _state.buffers.color.setClear(1, 1, 1, 1);
  11835. _state.buffers.depth.setTest(true);
  11836. _state.setScissorTest(false); // render depth map
  11837. for (var i = 0, il = lights.length; i < il; i++) {
  11838. var light = lights[i];
  11839. var shadow = light.shadow;
  11840. if (shadow === undefined) {
  11841. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  11842. continue;
  11843. }
  11844. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  11845. _shadowMapSize.copy(shadow.mapSize);
  11846. var shadowFrameExtents = shadow.getFrameExtents();
  11847. _shadowMapSize.multiply(shadowFrameExtents);
  11848. _viewportSize.copy(shadow.mapSize);
  11849. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  11850. if (_shadowMapSize.x > maxTextureSize) {
  11851. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  11852. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11853. shadow.mapSize.x = _viewportSize.x;
  11854. }
  11855. if (_shadowMapSize.y > maxTextureSize) {
  11856. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  11857. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11858. shadow.mapSize.y = _viewportSize.y;
  11859. }
  11860. }
  11861. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11862. var pars = {
  11863. minFilter: LinearFilter,
  11864. magFilter: LinearFilter,
  11865. format: RGBAFormat
  11866. };
  11867. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11868. shadow.map.texture.name = light.name + ".shadowMap";
  11869. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11870. shadow.camera.updateProjectionMatrix();
  11871. }
  11872. if (shadow.map === null) {
  11873. var _pars = {
  11874. minFilter: NearestFilter,
  11875. magFilter: NearestFilter,
  11876. format: RGBAFormat
  11877. };
  11878. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  11879. shadow.map.texture.name = light.name + ".shadowMap";
  11880. shadow.camera.updateProjectionMatrix();
  11881. }
  11882. _renderer.setRenderTarget(shadow.map);
  11883. _renderer.clear();
  11884. var viewportCount = shadow.getViewportCount();
  11885. for (var vp = 0; vp < viewportCount; vp++) {
  11886. var viewport = shadow.getViewport(vp);
  11887. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  11888. _state.viewport(_viewport);
  11889. shadow.updateMatrices(light, vp);
  11890. _frustum = shadow.getFrustum();
  11891. renderObject(scene, camera, shadow.camera, light, this.type);
  11892. } // do blur pass for VSM
  11893. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11894. VSMPass(shadow, camera);
  11895. }
  11896. shadow.needsUpdate = false;
  11897. }
  11898. scope.needsUpdate = false;
  11899. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  11900. };
  11901. function VSMPass(shadow, camera) {
  11902. var geometry = _objects.update(fullScreenMesh); // vertical pass
  11903. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11904. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11905. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11906. _renderer.setRenderTarget(shadow.mapPass);
  11907. _renderer.clear();
  11908. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizonal pass
  11909. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11910. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  11911. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  11912. _renderer.setRenderTarget(shadow.map);
  11913. _renderer.clear();
  11914. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null);
  11915. }
  11916. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11917. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11918. var material = _depthMaterials[index];
  11919. if (material === undefined) {
  11920. material = new MeshDepthMaterial({
  11921. depthPacking: RGBADepthPacking,
  11922. morphTargets: useMorphing,
  11923. skinning: useSkinning
  11924. });
  11925. _depthMaterials[index] = material;
  11926. }
  11927. return material;
  11928. }
  11929. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11930. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11931. var material = _distanceMaterials[index];
  11932. if (material === undefined) {
  11933. material = new MeshDistanceMaterial({
  11934. morphTargets: useMorphing,
  11935. skinning: useSkinning
  11936. });
  11937. _distanceMaterials[index] = material;
  11938. }
  11939. return material;
  11940. }
  11941. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  11942. var result = null;
  11943. var getMaterialVariant = getDepthMaterialVariant;
  11944. var customMaterial = object.customDepthMaterial;
  11945. if (light.isPointLight === true) {
  11946. getMaterialVariant = getDistanceMaterialVariant;
  11947. customMaterial = object.customDistanceMaterial;
  11948. }
  11949. if (customMaterial === undefined) {
  11950. var useMorphing = false;
  11951. if (material.morphTargets === true) {
  11952. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11953. }
  11954. var useSkinning = false;
  11955. if (object.isSkinnedMesh === true) {
  11956. if (material.skinning === true) {
  11957. useSkinning = true;
  11958. } else {
  11959. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  11960. }
  11961. }
  11962. var useInstancing = object.isInstancedMesh === true;
  11963. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  11964. } else {
  11965. result = customMaterial;
  11966. }
  11967. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  11968. // in this case we need a unique material instance reflecting the
  11969. // appropriate state
  11970. var keyA = result.uuid,
  11971. keyB = material.uuid;
  11972. var materialsForVariant = _materialCache[keyA];
  11973. if (materialsForVariant === undefined) {
  11974. materialsForVariant = {};
  11975. _materialCache[keyA] = materialsForVariant;
  11976. }
  11977. var cachedMaterial = materialsForVariant[keyB];
  11978. if (cachedMaterial === undefined) {
  11979. cachedMaterial = result.clone();
  11980. materialsForVariant[keyB] = cachedMaterial;
  11981. }
  11982. result = cachedMaterial;
  11983. }
  11984. result.visible = material.visible;
  11985. result.wireframe = material.wireframe;
  11986. if (type === VSMShadowMap) {
  11987. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  11988. } else {
  11989. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  11990. }
  11991. result.clipShadows = material.clipShadows;
  11992. result.clippingPlanes = material.clippingPlanes;
  11993. result.clipIntersection = material.clipIntersection;
  11994. result.wireframeLinewidth = material.wireframeLinewidth;
  11995. result.linewidth = material.linewidth;
  11996. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  11997. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  11998. result.nearDistance = shadowCameraNear;
  11999. result.farDistance = shadowCameraFar;
  12000. }
  12001. return result;
  12002. }
  12003. function renderObject(object, camera, shadowCamera, light, type) {
  12004. if (object.visible === false) return;
  12005. var visible = object.layers.test(camera.layers);
  12006. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12007. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12008. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12009. var geometry = _objects.update(object);
  12010. var material = object.material;
  12011. if (Array.isArray(material)) {
  12012. var groups = geometry.groups;
  12013. for (var k = 0, kl = groups.length; k < kl; k++) {
  12014. var group = groups[k];
  12015. var groupMaterial = material[group.materialIndex];
  12016. if (groupMaterial && groupMaterial.visible) {
  12017. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12018. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12019. }
  12020. }
  12021. } else if (material.visible) {
  12022. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12023. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12024. }
  12025. }
  12026. }
  12027. var children = object.children;
  12028. for (var i = 0, l = children.length; i < l; i++) {
  12029. renderObject(children[i], camera, shadowCamera, light, type);
  12030. }
  12031. }
  12032. }
  12033. function WebGLState(gl, extensions, capabilities) {
  12034. var _equationToGL, _factorToGL;
  12035. var isWebGL2 = capabilities.isWebGL2;
  12036. function ColorBuffer() {
  12037. var locked = false;
  12038. var color = new Vector4();
  12039. var currentColorMask = null;
  12040. var currentColorClear = new Vector4(0, 0, 0, 0);
  12041. return {
  12042. setMask: function setMask(colorMask) {
  12043. if (currentColorMask !== colorMask && !locked) {
  12044. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12045. currentColorMask = colorMask;
  12046. }
  12047. },
  12048. setLocked: function setLocked(lock) {
  12049. locked = lock;
  12050. },
  12051. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12052. if (premultipliedAlpha === true) {
  12053. r *= a;
  12054. g *= a;
  12055. b *= a;
  12056. }
  12057. color.set(r, g, b, a);
  12058. if (currentColorClear.equals(color) === false) {
  12059. gl.clearColor(r, g, b, a);
  12060. currentColorClear.copy(color);
  12061. }
  12062. },
  12063. reset: function reset() {
  12064. locked = false;
  12065. currentColorMask = null;
  12066. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12067. }
  12068. };
  12069. }
  12070. function DepthBuffer() {
  12071. var locked = false;
  12072. var currentDepthMask = null;
  12073. var currentDepthFunc = null;
  12074. var currentDepthClear = null;
  12075. return {
  12076. setTest: function setTest(depthTest) {
  12077. if (depthTest) {
  12078. enable(2929);
  12079. } else {
  12080. disable(2929);
  12081. }
  12082. },
  12083. setMask: function setMask(depthMask) {
  12084. if (currentDepthMask !== depthMask && !locked) {
  12085. gl.depthMask(depthMask);
  12086. currentDepthMask = depthMask;
  12087. }
  12088. },
  12089. setFunc: function setFunc(depthFunc) {
  12090. if (currentDepthFunc !== depthFunc) {
  12091. if (depthFunc) {
  12092. switch (depthFunc) {
  12093. case NeverDepth:
  12094. gl.depthFunc(512);
  12095. break;
  12096. case AlwaysDepth:
  12097. gl.depthFunc(519);
  12098. break;
  12099. case LessDepth:
  12100. gl.depthFunc(513);
  12101. break;
  12102. case LessEqualDepth:
  12103. gl.depthFunc(515);
  12104. break;
  12105. case EqualDepth:
  12106. gl.depthFunc(514);
  12107. break;
  12108. case GreaterEqualDepth:
  12109. gl.depthFunc(518);
  12110. break;
  12111. case GreaterDepth:
  12112. gl.depthFunc(516);
  12113. break;
  12114. case NotEqualDepth:
  12115. gl.depthFunc(517);
  12116. break;
  12117. default:
  12118. gl.depthFunc(515);
  12119. }
  12120. } else {
  12121. gl.depthFunc(515);
  12122. }
  12123. currentDepthFunc = depthFunc;
  12124. }
  12125. },
  12126. setLocked: function setLocked(lock) {
  12127. locked = lock;
  12128. },
  12129. setClear: function setClear(depth) {
  12130. if (currentDepthClear !== depth) {
  12131. gl.clearDepth(depth);
  12132. currentDepthClear = depth;
  12133. }
  12134. },
  12135. reset: function reset() {
  12136. locked = false;
  12137. currentDepthMask = null;
  12138. currentDepthFunc = null;
  12139. currentDepthClear = null;
  12140. }
  12141. };
  12142. }
  12143. function StencilBuffer() {
  12144. var locked = false;
  12145. var currentStencilMask = null;
  12146. var currentStencilFunc = null;
  12147. var currentStencilRef = null;
  12148. var currentStencilFuncMask = null;
  12149. var currentStencilFail = null;
  12150. var currentStencilZFail = null;
  12151. var currentStencilZPass = null;
  12152. var currentStencilClear = null;
  12153. return {
  12154. setTest: function setTest(stencilTest) {
  12155. if (!locked) {
  12156. if (stencilTest) {
  12157. enable(2960);
  12158. } else {
  12159. disable(2960);
  12160. }
  12161. }
  12162. },
  12163. setMask: function setMask(stencilMask) {
  12164. if (currentStencilMask !== stencilMask && !locked) {
  12165. gl.stencilMask(stencilMask);
  12166. currentStencilMask = stencilMask;
  12167. }
  12168. },
  12169. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12170. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12171. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12172. currentStencilFunc = stencilFunc;
  12173. currentStencilRef = stencilRef;
  12174. currentStencilFuncMask = stencilMask;
  12175. }
  12176. },
  12177. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12178. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12179. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12180. currentStencilFail = stencilFail;
  12181. currentStencilZFail = stencilZFail;
  12182. currentStencilZPass = stencilZPass;
  12183. }
  12184. },
  12185. setLocked: function setLocked(lock) {
  12186. locked = lock;
  12187. },
  12188. setClear: function setClear(stencil) {
  12189. if (currentStencilClear !== stencil) {
  12190. gl.clearStencil(stencil);
  12191. currentStencilClear = stencil;
  12192. }
  12193. },
  12194. reset: function reset() {
  12195. locked = false;
  12196. currentStencilMask = null;
  12197. currentStencilFunc = null;
  12198. currentStencilRef = null;
  12199. currentStencilFuncMask = null;
  12200. currentStencilFail = null;
  12201. currentStencilZFail = null;
  12202. currentStencilZPass = null;
  12203. currentStencilClear = null;
  12204. }
  12205. };
  12206. } //
  12207. var colorBuffer = new ColorBuffer();
  12208. var depthBuffer = new DepthBuffer();
  12209. var stencilBuffer = new StencilBuffer();
  12210. var enabledCapabilities = {};
  12211. var currentProgram = null;
  12212. var currentBlendingEnabled = null;
  12213. var currentBlending = null;
  12214. var currentBlendEquation = null;
  12215. var currentBlendSrc = null;
  12216. var currentBlendDst = null;
  12217. var currentBlendEquationAlpha = null;
  12218. var currentBlendSrcAlpha = null;
  12219. var currentBlendDstAlpha = null;
  12220. var currentPremultipledAlpha = false;
  12221. var currentFlipSided = null;
  12222. var currentCullFace = null;
  12223. var currentLineWidth = null;
  12224. var currentPolygonOffsetFactor = null;
  12225. var currentPolygonOffsetUnits = null;
  12226. var maxTextures = gl.getParameter(35661);
  12227. var lineWidthAvailable = false;
  12228. var version = 0;
  12229. var glVersion = gl.getParameter(7938);
  12230. if (glVersion.indexOf('WebGL') !== -1) {
  12231. version = parseFloat(/^WebGL\ ([0-9])/.exec(glVersion)[1]);
  12232. lineWidthAvailable = version >= 1.0;
  12233. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12234. version = parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(glVersion)[1]);
  12235. lineWidthAvailable = version >= 2.0;
  12236. }
  12237. var currentTextureSlot = null;
  12238. var currentBoundTextures = {};
  12239. var currentScissor = new Vector4();
  12240. var currentViewport = new Vector4();
  12241. function createTexture(type, target, count) {
  12242. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12243. var texture = gl.createTexture();
  12244. gl.bindTexture(type, texture);
  12245. gl.texParameteri(type, 10241, 9728);
  12246. gl.texParameteri(type, 10240, 9728);
  12247. for (var i = 0; i < count; i++) {
  12248. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12249. }
  12250. return texture;
  12251. }
  12252. var emptyTextures = {};
  12253. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12254. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12255. colorBuffer.setClear(0, 0, 0, 1);
  12256. depthBuffer.setClear(1);
  12257. stencilBuffer.setClear(0);
  12258. enable(2929);
  12259. depthBuffer.setFunc(LessEqualDepth);
  12260. setFlipSided(false);
  12261. setCullFace(CullFaceBack);
  12262. enable(2884);
  12263. setBlending(NoBlending); //
  12264. function enable(id) {
  12265. if (enabledCapabilities[id] !== true) {
  12266. gl.enable(id);
  12267. enabledCapabilities[id] = true;
  12268. }
  12269. }
  12270. function disable(id) {
  12271. if (enabledCapabilities[id] !== false) {
  12272. gl.disable(id);
  12273. enabledCapabilities[id] = false;
  12274. }
  12275. }
  12276. function useProgram(program) {
  12277. if (currentProgram !== program) {
  12278. gl.useProgram(program);
  12279. currentProgram = program;
  12280. return true;
  12281. }
  12282. return false;
  12283. }
  12284. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12285. if (isWebGL2) {
  12286. equationToGL[MinEquation] = 32775;
  12287. equationToGL[MaxEquation] = 32776;
  12288. } else {
  12289. var extension = extensions.get('EXT_blend_minmax');
  12290. if (extension !== null) {
  12291. equationToGL[MinEquation] = extension.MIN_EXT;
  12292. equationToGL[MaxEquation] = extension.MAX_EXT;
  12293. }
  12294. }
  12295. 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);
  12296. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12297. if (blending === NoBlending) {
  12298. if (currentBlendingEnabled) {
  12299. disable(3042);
  12300. currentBlendingEnabled = false;
  12301. }
  12302. return;
  12303. }
  12304. if (!currentBlendingEnabled) {
  12305. enable(3042);
  12306. currentBlendingEnabled = true;
  12307. }
  12308. if (blending !== CustomBlending) {
  12309. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12310. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12311. gl.blendEquation(32774);
  12312. currentBlendEquation = AddEquation;
  12313. currentBlendEquationAlpha = AddEquation;
  12314. }
  12315. if (premultipliedAlpha) {
  12316. switch (blending) {
  12317. case NormalBlending:
  12318. gl.blendFuncSeparate(1, 771, 1, 771);
  12319. break;
  12320. case AdditiveBlending:
  12321. gl.blendFunc(1, 1);
  12322. break;
  12323. case SubtractiveBlending:
  12324. gl.blendFuncSeparate(0, 0, 769, 771);
  12325. break;
  12326. case MultiplyBlending:
  12327. gl.blendFuncSeparate(0, 768, 0, 770);
  12328. break;
  12329. default:
  12330. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12331. break;
  12332. }
  12333. } else {
  12334. switch (blending) {
  12335. case NormalBlending:
  12336. gl.blendFuncSeparate(770, 771, 1, 771);
  12337. break;
  12338. case AdditiveBlending:
  12339. gl.blendFunc(770, 1);
  12340. break;
  12341. case SubtractiveBlending:
  12342. gl.blendFunc(0, 769);
  12343. break;
  12344. case MultiplyBlending:
  12345. gl.blendFunc(0, 768);
  12346. break;
  12347. default:
  12348. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12349. break;
  12350. }
  12351. }
  12352. currentBlendSrc = null;
  12353. currentBlendDst = null;
  12354. currentBlendSrcAlpha = null;
  12355. currentBlendDstAlpha = null;
  12356. currentBlending = blending;
  12357. currentPremultipledAlpha = premultipliedAlpha;
  12358. }
  12359. return;
  12360. } // custom blending
  12361. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12362. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12363. blendDstAlpha = blendDstAlpha || blendDst;
  12364. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12365. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12366. currentBlendEquation = blendEquation;
  12367. currentBlendEquationAlpha = blendEquationAlpha;
  12368. }
  12369. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12370. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12371. currentBlendSrc = blendSrc;
  12372. currentBlendDst = blendDst;
  12373. currentBlendSrcAlpha = blendSrcAlpha;
  12374. currentBlendDstAlpha = blendDstAlpha;
  12375. }
  12376. currentBlending = blending;
  12377. currentPremultipledAlpha = null;
  12378. }
  12379. function setMaterial(material, frontFaceCW) {
  12380. material.side === DoubleSide ? disable(2884) : enable(2884);
  12381. var flipSided = material.side === BackSide;
  12382. if (frontFaceCW) flipSided = !flipSided;
  12383. setFlipSided(flipSided);
  12384. 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);
  12385. depthBuffer.setFunc(material.depthFunc);
  12386. depthBuffer.setTest(material.depthTest);
  12387. depthBuffer.setMask(material.depthWrite);
  12388. colorBuffer.setMask(material.colorWrite);
  12389. var stencilWrite = material.stencilWrite;
  12390. stencilBuffer.setTest(stencilWrite);
  12391. if (stencilWrite) {
  12392. stencilBuffer.setMask(material.stencilWriteMask);
  12393. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12394. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12395. }
  12396. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12397. } //
  12398. function setFlipSided(flipSided) {
  12399. if (currentFlipSided !== flipSided) {
  12400. if (flipSided) {
  12401. gl.frontFace(2304);
  12402. } else {
  12403. gl.frontFace(2305);
  12404. }
  12405. currentFlipSided = flipSided;
  12406. }
  12407. }
  12408. function setCullFace(cullFace) {
  12409. if (cullFace !== CullFaceNone) {
  12410. enable(2884);
  12411. if (cullFace !== currentCullFace) {
  12412. if (cullFace === CullFaceBack) {
  12413. gl.cullFace(1029);
  12414. } else if (cullFace === CullFaceFront) {
  12415. gl.cullFace(1028);
  12416. } else {
  12417. gl.cullFace(1032);
  12418. }
  12419. }
  12420. } else {
  12421. disable(2884);
  12422. }
  12423. currentCullFace = cullFace;
  12424. }
  12425. function setLineWidth(width) {
  12426. if (width !== currentLineWidth) {
  12427. if (lineWidthAvailable) gl.lineWidth(width);
  12428. currentLineWidth = width;
  12429. }
  12430. }
  12431. function setPolygonOffset(polygonOffset, factor, units) {
  12432. if (polygonOffset) {
  12433. enable(32823);
  12434. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12435. gl.polygonOffset(factor, units);
  12436. currentPolygonOffsetFactor = factor;
  12437. currentPolygonOffsetUnits = units;
  12438. }
  12439. } else {
  12440. disable(32823);
  12441. }
  12442. }
  12443. function setScissorTest(scissorTest) {
  12444. if (scissorTest) {
  12445. enable(3089);
  12446. } else {
  12447. disable(3089);
  12448. }
  12449. } // texture
  12450. function activeTexture(webglSlot) {
  12451. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12452. if (currentTextureSlot !== webglSlot) {
  12453. gl.activeTexture(webglSlot);
  12454. currentTextureSlot = webglSlot;
  12455. }
  12456. }
  12457. function bindTexture(webglType, webglTexture) {
  12458. if (currentTextureSlot === null) {
  12459. activeTexture();
  12460. }
  12461. var boundTexture = currentBoundTextures[currentTextureSlot];
  12462. if (boundTexture === undefined) {
  12463. boundTexture = {
  12464. type: undefined,
  12465. texture: undefined
  12466. };
  12467. currentBoundTextures[currentTextureSlot] = boundTexture;
  12468. }
  12469. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12470. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12471. boundTexture.type = webglType;
  12472. boundTexture.texture = webglTexture;
  12473. }
  12474. }
  12475. function unbindTexture() {
  12476. var boundTexture = currentBoundTextures[currentTextureSlot];
  12477. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12478. gl.bindTexture(boundTexture.type, null);
  12479. boundTexture.type = undefined;
  12480. boundTexture.texture = undefined;
  12481. }
  12482. }
  12483. function compressedTexImage2D() {
  12484. try {
  12485. gl.compressedTexImage2D.apply(gl, arguments);
  12486. } catch (error) {
  12487. console.error('THREE.WebGLState:', error);
  12488. }
  12489. }
  12490. function texImage2D() {
  12491. try {
  12492. gl.texImage2D.apply(gl, arguments);
  12493. } catch (error) {
  12494. console.error('THREE.WebGLState:', error);
  12495. }
  12496. }
  12497. function texImage3D() {
  12498. try {
  12499. gl.texImage3D.apply(gl, arguments);
  12500. } catch (error) {
  12501. console.error('THREE.WebGLState:', error);
  12502. }
  12503. } //
  12504. function scissor(scissor) {
  12505. if (currentScissor.equals(scissor) === false) {
  12506. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12507. currentScissor.copy(scissor);
  12508. }
  12509. }
  12510. function viewport(viewport) {
  12511. if (currentViewport.equals(viewport) === false) {
  12512. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12513. currentViewport.copy(viewport);
  12514. }
  12515. } //
  12516. function reset() {
  12517. enabledCapabilities = {};
  12518. currentTextureSlot = null;
  12519. currentBoundTextures = {};
  12520. currentProgram = null;
  12521. currentBlending = null;
  12522. currentFlipSided = null;
  12523. currentCullFace = null;
  12524. colorBuffer.reset();
  12525. depthBuffer.reset();
  12526. stencilBuffer.reset();
  12527. }
  12528. return {
  12529. buffers: {
  12530. color: colorBuffer,
  12531. depth: depthBuffer,
  12532. stencil: stencilBuffer
  12533. },
  12534. enable: enable,
  12535. disable: disable,
  12536. useProgram: useProgram,
  12537. setBlending: setBlending,
  12538. setMaterial: setMaterial,
  12539. setFlipSided: setFlipSided,
  12540. setCullFace: setCullFace,
  12541. setLineWidth: setLineWidth,
  12542. setPolygonOffset: setPolygonOffset,
  12543. setScissorTest: setScissorTest,
  12544. activeTexture: activeTexture,
  12545. bindTexture: bindTexture,
  12546. unbindTexture: unbindTexture,
  12547. compressedTexImage2D: compressedTexImage2D,
  12548. texImage2D: texImage2D,
  12549. texImage3D: texImage3D,
  12550. scissor: scissor,
  12551. viewport: viewport,
  12552. reset: reset
  12553. };
  12554. }
  12555. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12556. var _wrappingToGL, _filterToGL;
  12557. var isWebGL2 = capabilities.isWebGL2;
  12558. var maxTextures = capabilities.maxTextures;
  12559. var maxCubemapSize = capabilities.maxCubemapSize;
  12560. var maxTextureSize = capabilities.maxTextureSize;
  12561. var maxSamples = capabilities.maxSamples;
  12562. var _videoTextures = new WeakMap();
  12563. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12564. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12565. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12566. var useOffscreenCanvas = false;
  12567. try {
  12568. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext("2d") !== null;
  12569. } catch (err) {// Ignore any errors
  12570. }
  12571. function createCanvas(width, height) {
  12572. // Use OffscreenCanvas when available. Specially needed in web workers
  12573. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12574. }
  12575. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12576. var scale = 1; // handle case if texture exceeds max size
  12577. if (image.width > maxSize || image.height > maxSize) {
  12578. scale = maxSize / Math.max(image.width, image.height);
  12579. } // only perform resize if necessary
  12580. if (scale < 1 || needsPowerOfTwo === true) {
  12581. // only perform resize for certain image types
  12582. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12583. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12584. var width = floor(scale * image.width);
  12585. var height = floor(scale * image.height);
  12586. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12587. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12588. canvas.width = width;
  12589. canvas.height = height;
  12590. var context = canvas.getContext('2d');
  12591. context.drawImage(image, 0, 0, width, height);
  12592. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12593. return canvas;
  12594. } else {
  12595. if ('data' in image) {
  12596. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12597. }
  12598. return image;
  12599. }
  12600. }
  12601. return image;
  12602. }
  12603. function isPowerOfTwo(image) {
  12604. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12605. }
  12606. function textureNeedsPowerOfTwo(texture) {
  12607. if (isWebGL2) return false;
  12608. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12609. }
  12610. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12611. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12612. }
  12613. function generateMipmap(target, texture, width, height) {
  12614. _gl.generateMipmap(target);
  12615. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12616. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12617. }
  12618. function getInternalFormat(internalFormatName, glFormat, glType) {
  12619. if (isWebGL2 === false) return glFormat;
  12620. if (internalFormatName !== null) {
  12621. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12622. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12623. }
  12624. var internalFormat = glFormat;
  12625. if (glFormat === 6403) {
  12626. if (glType === 5126) internalFormat = 33326;
  12627. if (glType === 5131) internalFormat = 33325;
  12628. if (glType === 5121) internalFormat = 33321;
  12629. }
  12630. if (glFormat === 6407) {
  12631. if (glType === 5126) internalFormat = 34837;
  12632. if (glType === 5131) internalFormat = 34843;
  12633. if (glType === 5121) internalFormat = 32849;
  12634. }
  12635. if (glFormat === 6408) {
  12636. if (glType === 5126) internalFormat = 34836;
  12637. if (glType === 5131) internalFormat = 34842;
  12638. if (glType === 5121) internalFormat = 32856;
  12639. }
  12640. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12641. extensions.get('EXT_color_buffer_float');
  12642. }
  12643. return internalFormat;
  12644. } // Fallback filters for non-power-of-2 textures
  12645. function filterFallback(f) {
  12646. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12647. return 9728;
  12648. }
  12649. return 9729;
  12650. } //
  12651. function onTextureDispose(event) {
  12652. var texture = event.target;
  12653. texture.removeEventListener('dispose', onTextureDispose);
  12654. deallocateTexture(texture);
  12655. if (texture.isVideoTexture) {
  12656. _videoTextures.delete(texture);
  12657. }
  12658. info.memory.textures--;
  12659. }
  12660. function onRenderTargetDispose(event) {
  12661. var renderTarget = event.target;
  12662. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12663. deallocateRenderTarget(renderTarget);
  12664. info.memory.textures--;
  12665. } //
  12666. function deallocateTexture(texture) {
  12667. var textureProperties = properties.get(texture);
  12668. if (textureProperties.__webglInit === undefined) return;
  12669. _gl.deleteTexture(textureProperties.__webglTexture);
  12670. properties.remove(texture);
  12671. }
  12672. function deallocateRenderTarget(renderTarget) {
  12673. var renderTargetProperties = properties.get(renderTarget);
  12674. var textureProperties = properties.get(renderTarget.texture);
  12675. if (!renderTarget) return;
  12676. if (textureProperties.__webglTexture !== undefined) {
  12677. _gl.deleteTexture(textureProperties.__webglTexture);
  12678. }
  12679. if (renderTarget.depthTexture) {
  12680. renderTarget.depthTexture.dispose();
  12681. }
  12682. if (renderTarget.isWebGLCubeRenderTarget) {
  12683. for (var i = 0; i < 6; i++) {
  12684. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12685. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12686. }
  12687. } else {
  12688. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12689. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12690. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12691. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12692. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12693. }
  12694. properties.remove(renderTarget.texture);
  12695. properties.remove(renderTarget);
  12696. } //
  12697. var textureUnits = 0;
  12698. function resetTextureUnits() {
  12699. textureUnits = 0;
  12700. }
  12701. function allocateTextureUnit() {
  12702. var textureUnit = textureUnits;
  12703. if (textureUnit >= maxTextures) {
  12704. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12705. }
  12706. textureUnits += 1;
  12707. return textureUnit;
  12708. } //
  12709. function setTexture2D(texture, slot) {
  12710. var textureProperties = properties.get(texture);
  12711. if (texture.isVideoTexture) updateVideoTexture(texture);
  12712. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12713. var image = texture.image;
  12714. if (image === undefined) {
  12715. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12716. } else if (image.complete === false) {
  12717. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12718. } else {
  12719. uploadTexture(textureProperties, texture, slot);
  12720. return;
  12721. }
  12722. }
  12723. state.activeTexture(33984 + slot);
  12724. state.bindTexture(3553, textureProperties.__webglTexture);
  12725. }
  12726. function setTexture2DArray(texture, slot) {
  12727. var textureProperties = properties.get(texture);
  12728. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12729. uploadTexture(textureProperties, texture, slot);
  12730. return;
  12731. }
  12732. state.activeTexture(33984 + slot);
  12733. state.bindTexture(35866, textureProperties.__webglTexture);
  12734. }
  12735. function setTexture3D(texture, slot) {
  12736. var textureProperties = properties.get(texture);
  12737. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12738. uploadTexture(textureProperties, texture, slot);
  12739. return;
  12740. }
  12741. state.activeTexture(33984 + slot);
  12742. state.bindTexture(32879, textureProperties.__webglTexture);
  12743. }
  12744. function setTextureCube(texture, slot) {
  12745. var textureProperties = properties.get(texture);
  12746. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12747. uploadCubeTexture(textureProperties, texture, slot);
  12748. return;
  12749. }
  12750. state.activeTexture(33984 + slot);
  12751. state.bindTexture(34067, textureProperties.__webglTexture);
  12752. }
  12753. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12754. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12755. function setTextureParameters(textureType, texture, supportsMips) {
  12756. if (supportsMips) {
  12757. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12758. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12759. if (textureType === 32879 || textureType === 35866) {
  12760. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12761. }
  12762. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12763. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12764. } else {
  12765. _gl.texParameteri(textureType, 10242, 33071);
  12766. _gl.texParameteri(textureType, 10243, 33071);
  12767. if (textureType === 32879 || textureType === 35866) {
  12768. _gl.texParameteri(textureType, 32882, 33071);
  12769. }
  12770. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12771. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12772. }
  12773. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12774. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12775. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12776. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12777. }
  12778. }
  12779. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12780. if (extension) {
  12781. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12782. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12783. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12784. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12785. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12786. }
  12787. }
  12788. }
  12789. function initTexture(textureProperties, texture) {
  12790. if (textureProperties.__webglInit === undefined) {
  12791. textureProperties.__webglInit = true;
  12792. texture.addEventListener('dispose', onTextureDispose);
  12793. textureProperties.__webglTexture = _gl.createTexture();
  12794. info.memory.textures++;
  12795. }
  12796. }
  12797. function uploadTexture(textureProperties, texture, slot) {
  12798. var textureType = 3553;
  12799. if (texture.isDataTexture2DArray) textureType = 35866;
  12800. if (texture.isDataTexture3D) textureType = 32879;
  12801. initTexture(textureProperties, texture);
  12802. state.activeTexture(33984 + slot);
  12803. state.bindTexture(textureType, textureProperties.__webglTexture);
  12804. _gl.pixelStorei(37440, texture.flipY);
  12805. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  12806. _gl.pixelStorei(3317, texture.unpackAlignment);
  12807. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  12808. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  12809. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  12810. glFormat = utils.convert(texture.format);
  12811. var glType = utils.convert(texture.type),
  12812. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12813. setTextureParameters(textureType, texture, supportsMips);
  12814. var mipmap;
  12815. var mipmaps = texture.mipmaps;
  12816. if (texture.isDepthTexture) {
  12817. // populate depth texture with dummy data
  12818. glInternalFormat = 6402;
  12819. if (isWebGL2) {
  12820. if (texture.type === FloatType) {
  12821. glInternalFormat = 36012;
  12822. } else if (texture.type === UnsignedIntType) {
  12823. glInternalFormat = 33190;
  12824. } else if (texture.type === UnsignedInt248Type) {
  12825. glInternalFormat = 35056;
  12826. } else {
  12827. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12828. }
  12829. } else {
  12830. if (texture.type === FloatType) {
  12831. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  12832. }
  12833. } // validation checks for WebGL 1
  12834. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  12835. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12836. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12837. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12838. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  12839. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  12840. texture.type = UnsignedShortType;
  12841. glType = utils.convert(texture.type);
  12842. }
  12843. }
  12844. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  12845. // Depth stencil textures need the DEPTH_STENCIL internal format
  12846. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12847. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12848. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12849. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12850. if (texture.type !== UnsignedInt248Type) {
  12851. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  12852. texture.type = UnsignedInt248Type;
  12853. glType = utils.convert(texture.type);
  12854. }
  12855. } //
  12856. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  12857. } else if (texture.isDataTexture) {
  12858. // use manually created mipmaps if available
  12859. // if there are no manual mipmaps
  12860. // set 0 level mipmap and then use GL to generate other mipmap levels
  12861. if (mipmaps.length > 0 && supportsMips) {
  12862. for (var i = 0, il = mipmaps.length; i < il; i++) {
  12863. mipmap = mipmaps[i];
  12864. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12865. }
  12866. texture.generateMipmaps = false;
  12867. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12868. } else {
  12869. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  12870. textureProperties.__maxMipLevel = 0;
  12871. }
  12872. } else if (texture.isCompressedTexture) {
  12873. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  12874. mipmap = mipmaps[_i];
  12875. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12876. if (glFormat !== null) {
  12877. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12878. } else {
  12879. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  12880. }
  12881. } else {
  12882. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12883. }
  12884. }
  12885. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12886. } else if (texture.isDataTexture2DArray) {
  12887. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12888. textureProperties.__maxMipLevel = 0;
  12889. } else if (texture.isDataTexture3D) {
  12890. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12891. textureProperties.__maxMipLevel = 0;
  12892. } else {
  12893. // regular Texture (image, video, canvas)
  12894. // use manually created mipmaps if available
  12895. // if there are no manual mipmaps
  12896. // set 0 level mipmap and then use GL to generate other mipmap levels
  12897. if (mipmaps.length > 0 && supportsMips) {
  12898. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  12899. mipmap = mipmaps[_i2];
  12900. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  12901. }
  12902. texture.generateMipmaps = false;
  12903. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12904. } else {
  12905. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  12906. textureProperties.__maxMipLevel = 0;
  12907. }
  12908. }
  12909. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12910. generateMipmap(textureType, texture, image.width, image.height);
  12911. }
  12912. textureProperties.__version = texture.version;
  12913. if (texture.onUpdate) texture.onUpdate(texture);
  12914. }
  12915. function uploadCubeTexture(textureProperties, texture, slot) {
  12916. if (texture.image.length !== 6) return;
  12917. initTexture(textureProperties, texture);
  12918. state.activeTexture(33984 + slot);
  12919. state.bindTexture(34067, textureProperties.__webglTexture);
  12920. _gl.pixelStorei(37440, texture.flipY);
  12921. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  12922. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  12923. var cubeImage = [];
  12924. for (var i = 0; i < 6; i++) {
  12925. if (!isCompressed && !isDataTexture) {
  12926. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  12927. } else {
  12928. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  12929. }
  12930. }
  12931. var image = cubeImage[0],
  12932. supportsMips = isPowerOfTwo(image) || isWebGL2,
  12933. glFormat = utils.convert(texture.format),
  12934. glType = utils.convert(texture.type),
  12935. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12936. setTextureParameters(34067, texture, supportsMips);
  12937. var mipmaps;
  12938. if (isCompressed) {
  12939. for (var _i3 = 0; _i3 < 6; _i3++) {
  12940. mipmaps = cubeImage[_i3].mipmaps;
  12941. for (var j = 0; j < mipmaps.length; j++) {
  12942. var mipmap = mipmaps[j];
  12943. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12944. if (glFormat !== null) {
  12945. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12946. } else {
  12947. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  12948. }
  12949. } else {
  12950. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12951. }
  12952. }
  12953. }
  12954. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12955. } else {
  12956. mipmaps = texture.mipmaps;
  12957. for (var _i4 = 0; _i4 < 6; _i4++) {
  12958. if (isDataTexture) {
  12959. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  12960. for (var _j = 0; _j < mipmaps.length; _j++) {
  12961. var _mipmap = mipmaps[_j];
  12962. var mipmapImage = _mipmap.image[_i4].image;
  12963. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  12964. }
  12965. } else {
  12966. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  12967. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  12968. var _mipmap2 = mipmaps[_j2];
  12969. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  12970. }
  12971. }
  12972. }
  12973. textureProperties.__maxMipLevel = mipmaps.length;
  12974. }
  12975. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12976. // We assume images for cube map have the same size.
  12977. generateMipmap(34067, texture, image.width, image.height);
  12978. }
  12979. textureProperties.__version = texture.version;
  12980. if (texture.onUpdate) texture.onUpdate(texture);
  12981. } // Render targets
  12982. // Setup storage for target texture and bind it to correct framebuffer
  12983. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  12984. var glFormat = utils.convert(renderTarget.texture.format);
  12985. var glType = utils.convert(renderTarget.texture.type);
  12986. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12987. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  12988. _gl.bindFramebuffer(36160, framebuffer);
  12989. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  12990. _gl.bindFramebuffer(36160, null);
  12991. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12992. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  12993. _gl.bindRenderbuffer(36161, renderbuffer);
  12994. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  12995. var glInternalFormat = 33189;
  12996. if (isMultisample) {
  12997. var depthTexture = renderTarget.depthTexture;
  12998. if (depthTexture && depthTexture.isDepthTexture) {
  12999. if (depthTexture.type === FloatType) {
  13000. glInternalFormat = 36012;
  13001. } else if (depthTexture.type === UnsignedIntType) {
  13002. glInternalFormat = 33190;
  13003. }
  13004. }
  13005. var samples = getRenderTargetSamples(renderTarget);
  13006. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13007. } else {
  13008. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13009. }
  13010. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13011. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13012. if (isMultisample) {
  13013. var _samples = getRenderTargetSamples(renderTarget);
  13014. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13015. } else {
  13016. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13017. }
  13018. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13019. } else {
  13020. var glFormat = utils.convert(renderTarget.texture.format);
  13021. var glType = utils.convert(renderTarget.texture.type);
  13022. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13023. if (isMultisample) {
  13024. var _samples2 = getRenderTargetSamples(renderTarget);
  13025. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13026. } else {
  13027. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13028. }
  13029. }
  13030. _gl.bindRenderbuffer(36161, null);
  13031. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13032. function setupDepthTexture(framebuffer, renderTarget) {
  13033. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13034. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13035. _gl.bindFramebuffer(36160, framebuffer);
  13036. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13037. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13038. } // upload an empty depth texture with framebuffer size
  13039. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13040. renderTarget.depthTexture.image.width = renderTarget.width;
  13041. renderTarget.depthTexture.image.height = renderTarget.height;
  13042. renderTarget.depthTexture.needsUpdate = true;
  13043. }
  13044. setTexture2D(renderTarget.depthTexture, 0);
  13045. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13046. if (renderTarget.depthTexture.format === DepthFormat) {
  13047. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13048. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13049. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13050. } else {
  13051. throw new Error('Unknown depthTexture format');
  13052. }
  13053. } // Setup GL resources for a non-texture depth buffer
  13054. function setupDepthRenderbuffer(renderTarget) {
  13055. var renderTargetProperties = properties.get(renderTarget);
  13056. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13057. if (renderTarget.depthTexture) {
  13058. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13059. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13060. } else {
  13061. if (isCube) {
  13062. renderTargetProperties.__webglDepthbuffer = [];
  13063. for (var i = 0; i < 6; i++) {
  13064. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13065. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13066. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13067. }
  13068. } else {
  13069. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13070. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13071. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13072. }
  13073. }
  13074. _gl.bindFramebuffer(36160, null);
  13075. } // Set up GL resources for the render target
  13076. function setupRenderTarget(renderTarget) {
  13077. var renderTargetProperties = properties.get(renderTarget);
  13078. var textureProperties = properties.get(renderTarget.texture);
  13079. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13080. textureProperties.__webglTexture = _gl.createTexture();
  13081. info.memory.textures++;
  13082. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13083. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13084. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13085. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13086. renderTarget.texture.format = RGBAFormat;
  13087. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13088. } // Setup framebuffer
  13089. if (isCube) {
  13090. renderTargetProperties.__webglFramebuffer = [];
  13091. for (var i = 0; i < 6; i++) {
  13092. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13093. }
  13094. } else {
  13095. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13096. if (isMultisample) {
  13097. if (isWebGL2) {
  13098. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13099. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13100. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13101. var glFormat = utils.convert(renderTarget.texture.format);
  13102. var glType = utils.convert(renderTarget.texture.type);
  13103. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13104. var samples = getRenderTargetSamples(renderTarget);
  13105. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13106. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13107. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13108. _gl.bindRenderbuffer(36161, null);
  13109. if (renderTarget.depthBuffer) {
  13110. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13111. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13112. }
  13113. _gl.bindFramebuffer(36160, null);
  13114. } else {
  13115. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13116. }
  13117. }
  13118. } // Setup color buffer
  13119. if (isCube) {
  13120. state.bindTexture(34067, textureProperties.__webglTexture);
  13121. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13122. for (var _i5 = 0; _i5 < 6; _i5++) {
  13123. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13124. }
  13125. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13126. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13127. }
  13128. state.bindTexture(34067, null);
  13129. } else {
  13130. state.bindTexture(3553, textureProperties.__webglTexture);
  13131. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13132. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13133. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13134. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13135. }
  13136. state.bindTexture(3553, null);
  13137. } // Setup depth and stencil buffers
  13138. if (renderTarget.depthBuffer) {
  13139. setupDepthRenderbuffer(renderTarget);
  13140. }
  13141. }
  13142. function updateRenderTargetMipmap(renderTarget) {
  13143. var texture = renderTarget.texture;
  13144. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13145. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13146. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13147. var webglTexture = properties.get(texture).__webglTexture;
  13148. state.bindTexture(target, webglTexture);
  13149. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13150. state.bindTexture(target, null);
  13151. }
  13152. }
  13153. function updateMultisampleRenderTarget(renderTarget) {
  13154. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13155. if (isWebGL2) {
  13156. var renderTargetProperties = properties.get(renderTarget);
  13157. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13158. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13159. var width = renderTarget.width;
  13160. var height = renderTarget.height;
  13161. var mask = 16384;
  13162. if (renderTarget.depthBuffer) mask |= 256;
  13163. if (renderTarget.stencilBuffer) mask |= 1024;
  13164. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13165. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13166. } else {
  13167. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13168. }
  13169. }
  13170. }
  13171. function getRenderTargetSamples(renderTarget) {
  13172. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13173. }
  13174. function updateVideoTexture(texture) {
  13175. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13176. if (_videoTextures.get(texture) !== frame) {
  13177. _videoTextures.set(texture, frame);
  13178. texture.update();
  13179. }
  13180. } // backwards compatibility
  13181. var warnedTexture2D = false;
  13182. var warnedTextureCube = false;
  13183. function safeSetTexture2D(texture, slot) {
  13184. if (texture && texture.isWebGLRenderTarget) {
  13185. if (warnedTexture2D === false) {
  13186. console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.");
  13187. warnedTexture2D = true;
  13188. }
  13189. texture = texture.texture;
  13190. }
  13191. setTexture2D(texture, slot);
  13192. }
  13193. function safeSetTextureCube(texture, slot) {
  13194. if (texture && texture.isWebGLCubeRenderTarget) {
  13195. if (warnedTextureCube === false) {
  13196. console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.");
  13197. warnedTextureCube = true;
  13198. }
  13199. texture = texture.texture;
  13200. }
  13201. setTextureCube(texture, slot);
  13202. } //
  13203. this.allocateTextureUnit = allocateTextureUnit;
  13204. this.resetTextureUnits = resetTextureUnits;
  13205. this.setTexture2D = setTexture2D;
  13206. this.setTexture2DArray = setTexture2DArray;
  13207. this.setTexture3D = setTexture3D;
  13208. this.setTextureCube = setTextureCube;
  13209. this.setupRenderTarget = setupRenderTarget;
  13210. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13211. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13212. this.safeSetTexture2D = safeSetTexture2D;
  13213. this.safeSetTextureCube = safeSetTextureCube;
  13214. }
  13215. function WebGLUtils(gl, extensions, capabilities) {
  13216. var isWebGL2 = capabilities.isWebGL2;
  13217. function convert(p) {
  13218. var extension;
  13219. if (p === UnsignedByteType) return 5121;
  13220. if (p === UnsignedShort4444Type) return 32819;
  13221. if (p === UnsignedShort5551Type) return 32820;
  13222. if (p === UnsignedShort565Type) return 33635;
  13223. if (p === ByteType) return 5120;
  13224. if (p === ShortType) return 5122;
  13225. if (p === UnsignedShortType) return 5123;
  13226. if (p === IntType) return 5124;
  13227. if (p === UnsignedIntType) return 5125;
  13228. if (p === FloatType) return 5126;
  13229. if (p === HalfFloatType) {
  13230. if (isWebGL2) return 5131;
  13231. extension = extensions.get('OES_texture_half_float');
  13232. if (extension !== null) {
  13233. return extension.HALF_FLOAT_OES;
  13234. } else {
  13235. return null;
  13236. }
  13237. }
  13238. if (p === AlphaFormat) return 6406;
  13239. if (p === RGBFormat) return 6407;
  13240. if (p === RGBAFormat) return 6408;
  13241. if (p === LuminanceFormat) return 6409;
  13242. if (p === LuminanceAlphaFormat) return 6410;
  13243. if (p === DepthFormat) return 6402;
  13244. if (p === DepthStencilFormat) return 34041;
  13245. if (p === RedFormat) return 6403; // WebGL2 formats.
  13246. if (p === RedIntegerFormat) return 36244;
  13247. if (p === RGFormat) return 33319;
  13248. if (p === RGIntegerFormat) return 33320;
  13249. if (p === RGBIntegerFormat) return 36248;
  13250. if (p === RGBAIntegerFormat) return 36249;
  13251. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13252. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13253. if (extension !== null) {
  13254. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13255. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13256. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13257. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13258. } else {
  13259. return null;
  13260. }
  13261. }
  13262. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13263. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13264. if (extension !== null) {
  13265. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13266. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13267. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13268. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13269. } else {
  13270. return null;
  13271. }
  13272. }
  13273. if (p === RGB_ETC1_Format) {
  13274. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13275. if (extension !== null) {
  13276. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13277. } else {
  13278. return null;
  13279. }
  13280. }
  13281. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13282. extension = extensions.get('WEBGL_compressed_texture_etc');
  13283. if (extension !== null) {
  13284. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13285. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13286. }
  13287. }
  13288. 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) {
  13289. extension = extensions.get('WEBGL_compressed_texture_astc');
  13290. if (extension !== null) {
  13291. // TODO Complete?
  13292. return p;
  13293. } else {
  13294. return null;
  13295. }
  13296. }
  13297. if (p === RGBA_BPTC_Format) {
  13298. extension = extensions.get('EXT_texture_compression_bptc');
  13299. if (extension !== null) {
  13300. // TODO Complete?
  13301. return p;
  13302. } else {
  13303. return null;
  13304. }
  13305. }
  13306. if (p === UnsignedInt248Type) {
  13307. if (isWebGL2) return 34042;
  13308. extension = extensions.get('WEBGL_depth_texture');
  13309. if (extension !== null) {
  13310. return extension.UNSIGNED_INT_24_8_WEBGL;
  13311. } else {
  13312. return null;
  13313. }
  13314. }
  13315. }
  13316. return {
  13317. convert: convert
  13318. };
  13319. }
  13320. function ArrayCamera(array) {
  13321. PerspectiveCamera.call(this);
  13322. this.cameras = array || [];
  13323. }
  13324. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13325. constructor: ArrayCamera,
  13326. isArrayCamera: true
  13327. });
  13328. function Group() {
  13329. Object3D.call(this);
  13330. this.type = 'Group';
  13331. }
  13332. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13333. constructor: Group,
  13334. isGroup: true
  13335. });
  13336. function WebXRController() {
  13337. this._targetRay = null;
  13338. this._grip = null;
  13339. this._hand = null;
  13340. }
  13341. Object.assign(WebXRController.prototype, {
  13342. constructor: WebXRController,
  13343. getHandSpace: function getHandSpace() {
  13344. if (this._hand === null) {
  13345. this._hand = new Group();
  13346. this._hand.matrixAutoUpdate = false;
  13347. this._hand.visible = false;
  13348. this._hand.joints = [];
  13349. this._hand.inputState = {
  13350. pinching: false
  13351. };
  13352. if (window.XRHand) {
  13353. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13354. // The transform of this joint will be updated with the joint pose on each frame
  13355. var joint = new Group();
  13356. joint.matrixAutoUpdate = false;
  13357. joint.visible = false;
  13358. this._hand.joints.push(joint); // ??
  13359. this._hand.add(joint);
  13360. }
  13361. }
  13362. }
  13363. return this._hand;
  13364. },
  13365. getTargetRaySpace: function getTargetRaySpace() {
  13366. if (this._targetRay === null) {
  13367. this._targetRay = new Group();
  13368. this._targetRay.matrixAutoUpdate = false;
  13369. this._targetRay.visible = false;
  13370. }
  13371. return this._targetRay;
  13372. },
  13373. getGripSpace: function getGripSpace() {
  13374. if (this._grip === null) {
  13375. this._grip = new Group();
  13376. this._grip.matrixAutoUpdate = false;
  13377. this._grip.visible = false;
  13378. }
  13379. return this._grip;
  13380. },
  13381. dispatchEvent: function dispatchEvent(event) {
  13382. if (this._targetRay !== null) {
  13383. this._targetRay.dispatchEvent(event);
  13384. }
  13385. if (this._grip !== null) {
  13386. this._grip.dispatchEvent(event);
  13387. }
  13388. if (this._hand !== null) {
  13389. this._hand.dispatchEvent(event);
  13390. }
  13391. return this;
  13392. },
  13393. disconnect: function disconnect(inputSource) {
  13394. this.dispatchEvent({
  13395. type: 'disconnected',
  13396. data: inputSource
  13397. });
  13398. if (this._targetRay !== null) {
  13399. this._targetRay.visible = false;
  13400. }
  13401. if (this._grip !== null) {
  13402. this._grip.visible = false;
  13403. }
  13404. if (this._hand !== null) {
  13405. this._hand.visible = false;
  13406. }
  13407. return this;
  13408. },
  13409. update: function update(inputSource, frame, referenceSpace) {
  13410. var inputPose = null;
  13411. var gripPose = null;
  13412. var handPose = null;
  13413. var targetRay = this._targetRay;
  13414. var grip = this._grip;
  13415. var hand = this._hand;
  13416. if (inputSource) {
  13417. if (hand && inputSource.hand) {
  13418. handPose = true;
  13419. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13420. if (inputSource.hand[i]) {
  13421. // Update the joints groups with the XRJoint poses
  13422. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13423. var joint = hand.joints[i];
  13424. if (jointPose !== null) {
  13425. joint.matrix.fromArray(jointPose.transform.matrix);
  13426. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13427. joint.jointRadius = jointPose.radius;
  13428. }
  13429. joint.visible = jointPose !== null; // Custom events
  13430. // Check pinch
  13431. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13432. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13433. var distance = indexTip.position.distanceTo(thumbTip.position);
  13434. var distanceToPinch = 0.02;
  13435. var threshold = 0.005;
  13436. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13437. hand.inputState.pinching = false;
  13438. this.dispatchEvent({
  13439. type: "pinchend",
  13440. handedness: inputSource.handedness,
  13441. target: this
  13442. });
  13443. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13444. hand.inputState.pinching = true;
  13445. this.dispatchEvent({
  13446. type: "pinchstart",
  13447. handedness: inputSource.handedness,
  13448. target: this
  13449. });
  13450. }
  13451. }
  13452. }
  13453. } else {
  13454. if (targetRay !== null) {
  13455. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13456. if (inputPose !== null) {
  13457. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13458. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13459. }
  13460. }
  13461. if (grip !== null && inputSource.gripSpace) {
  13462. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13463. if (gripPose !== null) {
  13464. grip.matrix.fromArray(gripPose.transform.matrix);
  13465. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13466. }
  13467. }
  13468. }
  13469. }
  13470. if (targetRay !== null) {
  13471. targetRay.visible = inputPose !== null;
  13472. }
  13473. if (grip !== null) {
  13474. grip.visible = gripPose !== null;
  13475. }
  13476. if (hand !== null) {
  13477. hand.visible = handPose !== null;
  13478. }
  13479. return this;
  13480. }
  13481. });
  13482. function WebXRManager(renderer, gl) {
  13483. var scope = this;
  13484. var session = null;
  13485. var framebufferScaleFactor = 1.0;
  13486. var referenceSpace = null;
  13487. var referenceSpaceType = 'local-floor';
  13488. var pose = null;
  13489. var controllers = [];
  13490. var inputSourcesMap = new Map(); //
  13491. var cameraL = new PerspectiveCamera();
  13492. cameraL.layers.enable(1);
  13493. cameraL.viewport = new Vector4();
  13494. var cameraR = new PerspectiveCamera();
  13495. cameraR.layers.enable(2);
  13496. cameraR.viewport = new Vector4();
  13497. var cameras = [cameraL, cameraR];
  13498. var cameraVR = new ArrayCamera();
  13499. cameraVR.layers.enable(1);
  13500. cameraVR.layers.enable(2);
  13501. var _currentDepthNear = null;
  13502. var _currentDepthFar = null; //
  13503. this.enabled = false;
  13504. this.isPresenting = false;
  13505. this.getController = function (index) {
  13506. var controller = controllers[index];
  13507. if (controller === undefined) {
  13508. controller = new WebXRController();
  13509. controllers[index] = controller;
  13510. }
  13511. return controller.getTargetRaySpace();
  13512. };
  13513. this.getControllerGrip = function (index) {
  13514. var controller = controllers[index];
  13515. if (controller === undefined) {
  13516. controller = new WebXRController();
  13517. controllers[index] = controller;
  13518. }
  13519. return controller.getGripSpace();
  13520. };
  13521. this.getHand = function (index) {
  13522. var controller = controllers[index];
  13523. if (controller === undefined) {
  13524. controller = new WebXRController();
  13525. controllers[index] = controller;
  13526. }
  13527. return controller.getHandSpace();
  13528. }; //
  13529. function onSessionEvent(event) {
  13530. var controller = inputSourcesMap.get(event.inputSource);
  13531. if (controller) {
  13532. controller.dispatchEvent({
  13533. type: event.type,
  13534. data: event.inputSource
  13535. });
  13536. }
  13537. }
  13538. function onSessionEnd() {
  13539. inputSourcesMap.forEach(function (controller, inputSource) {
  13540. controller.disconnect(inputSource);
  13541. });
  13542. inputSourcesMap.clear(); //
  13543. renderer.setFramebuffer(null);
  13544. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13545. animation.stop();
  13546. scope.isPresenting = false;
  13547. scope.dispatchEvent({
  13548. type: 'sessionend'
  13549. });
  13550. }
  13551. function onRequestReferenceSpace(value) {
  13552. referenceSpace = value;
  13553. animation.setContext(session);
  13554. animation.start();
  13555. scope.isPresenting = true;
  13556. scope.dispatchEvent({
  13557. type: 'sessionstart'
  13558. });
  13559. }
  13560. this.setFramebufferScaleFactor = function (value) {
  13561. framebufferScaleFactor = value;
  13562. if (scope.isPresenting === true) {
  13563. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13564. }
  13565. };
  13566. this.setReferenceSpaceType = function (value) {
  13567. referenceSpaceType = value;
  13568. if (scope.isPresenting === true) {
  13569. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13570. }
  13571. };
  13572. this.getReferenceSpace = function () {
  13573. return referenceSpace;
  13574. };
  13575. this.getSession = function () {
  13576. return session;
  13577. };
  13578. this.setSession = function (value) {
  13579. session = value;
  13580. if (session !== null) {
  13581. session.addEventListener('select', onSessionEvent);
  13582. session.addEventListener('selectstart', onSessionEvent);
  13583. session.addEventListener('selectend', onSessionEvent);
  13584. session.addEventListener('squeeze', onSessionEvent);
  13585. session.addEventListener('squeezestart', onSessionEvent);
  13586. session.addEventListener('squeezeend', onSessionEvent);
  13587. session.addEventListener('end', onSessionEnd);
  13588. var attributes = gl.getContextAttributes();
  13589. if (attributes.xrCompatible !== true) {
  13590. gl.makeXRCompatible();
  13591. }
  13592. var layerInit = {
  13593. antialias: attributes.antialias,
  13594. alpha: attributes.alpha,
  13595. depth: attributes.depth,
  13596. stencil: attributes.stencil,
  13597. framebufferScaleFactor: framebufferScaleFactor
  13598. }; // eslint-disable-next-line no-undef
  13599. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13600. session.updateRenderState({
  13601. baseLayer: baseLayer
  13602. });
  13603. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13604. session.addEventListener('inputsourceschange', updateInputSources);
  13605. }
  13606. };
  13607. function updateInputSources(event) {
  13608. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13609. for (var i = 0; i < controllers.length; i++) {
  13610. inputSourcesMap.set(inputSources[i], controllers[i]);
  13611. } // Notify disconnected
  13612. for (var _i = 0; _i < event.removed.length; _i++) {
  13613. var inputSource = event.removed[_i];
  13614. var controller = inputSourcesMap.get(inputSource);
  13615. if (controller) {
  13616. controller.dispatchEvent({
  13617. type: 'disconnected',
  13618. data: inputSource
  13619. });
  13620. inputSourcesMap.delete(inputSource);
  13621. }
  13622. } // Notify connected
  13623. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13624. var _inputSource = event.added[_i2];
  13625. var _controller = inputSourcesMap.get(_inputSource);
  13626. if (_controller) {
  13627. _controller.dispatchEvent({
  13628. type: 'connected',
  13629. data: _inputSource
  13630. });
  13631. }
  13632. }
  13633. } //
  13634. var cameraLPos = new Vector3();
  13635. var cameraRPos = new Vector3();
  13636. /**
  13637. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13638. * the cameras' projection and world matrices have already been set.
  13639. * And that near and far planes are identical for both cameras.
  13640. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13641. */
  13642. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13643. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13644. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13645. var ipd = cameraLPos.distanceTo(cameraRPos);
  13646. var projL = cameraL.projectionMatrix.elements;
  13647. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13648. // most likely identical top and bottom frustum extents.
  13649. // Use the left camera for these values.
  13650. var near = projL[14] / (projL[10] - 1);
  13651. var far = projL[14] / (projL[10] + 1);
  13652. var topFov = (projL[9] + 1) / projL[5];
  13653. var bottomFov = (projL[9] - 1) / projL[5];
  13654. var leftFov = (projL[8] - 1) / projL[0];
  13655. var rightFov = (projR[8] + 1) / projR[0];
  13656. var left = near * leftFov;
  13657. var right = near * rightFov; // Calculate the new camera's position offset from the
  13658. // left camera. xOffset should be roughly half `ipd`.
  13659. var zOffset = ipd / (-leftFov + rightFov);
  13660. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13661. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13662. camera.translateX(xOffset);
  13663. camera.translateZ(zOffset);
  13664. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13665. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  13666. // the values so that the near plane's position does not change in world space,
  13667. // although must now be relative to the new union camera.
  13668. var near2 = near + zOffset;
  13669. var far2 = far + zOffset;
  13670. var left2 = left - xOffset;
  13671. var right2 = right + (ipd - xOffset);
  13672. var top2 = topFov * far / far2 * near2;
  13673. var bottom2 = bottomFov * far / far2 * near2;
  13674. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13675. }
  13676. function updateCamera(camera, parent) {
  13677. if (parent === null) {
  13678. camera.matrixWorld.copy(camera.matrix);
  13679. } else {
  13680. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13681. }
  13682. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  13683. }
  13684. this.getCamera = function (camera) {
  13685. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13686. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13687. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13688. // Note that the new renderState won't apply until the next frame. See #18320
  13689. session.updateRenderState({
  13690. depthNear: cameraVR.near,
  13691. depthFar: cameraVR.far
  13692. });
  13693. _currentDepthNear = cameraVR.near;
  13694. _currentDepthFar = cameraVR.far;
  13695. }
  13696. var parent = camera.parent;
  13697. var cameras = cameraVR.cameras;
  13698. updateCamera(cameraVR, parent);
  13699. for (var i = 0; i < cameras.length; i++) {
  13700. updateCamera(cameras[i], parent);
  13701. } // update camera and its children
  13702. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13703. var children = camera.children;
  13704. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13705. children[_i3].updateMatrixWorld(true);
  13706. } // update projection matrix for proper view frustum culling
  13707. if (cameras.length === 2) {
  13708. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13709. } else {
  13710. // assume single camera setup (AR)
  13711. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13712. }
  13713. return cameraVR;
  13714. }; // Animation Loop
  13715. var onAnimationFrameCallback = null;
  13716. function onAnimationFrame(time, frame) {
  13717. pose = frame.getViewerPose(referenceSpace);
  13718. if (pose !== null) {
  13719. var views = pose.views;
  13720. var baseLayer = session.renderState.baseLayer;
  13721. renderer.setFramebuffer(baseLayer.framebuffer);
  13722. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13723. if (views.length !== cameraVR.cameras.length) {
  13724. cameraVR.cameras.length = 0;
  13725. cameraVRNeedsUpdate = true;
  13726. }
  13727. for (var i = 0; i < views.length; i++) {
  13728. var view = views[i];
  13729. var viewport = baseLayer.getViewport(view);
  13730. var camera = cameras[i];
  13731. camera.matrix.fromArray(view.transform.matrix);
  13732. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13733. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13734. if (i === 0) {
  13735. cameraVR.matrix.copy(camera.matrix);
  13736. }
  13737. if (cameraVRNeedsUpdate === true) {
  13738. cameraVR.cameras.push(camera);
  13739. }
  13740. }
  13741. } //
  13742. var inputSources = session.inputSources;
  13743. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13744. var controller = controllers[_i4];
  13745. var inputSource = inputSources[_i4];
  13746. controller.update(inputSource, frame, referenceSpace);
  13747. }
  13748. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13749. }
  13750. var animation = new WebGLAnimation();
  13751. animation.setAnimationLoop(onAnimationFrame);
  13752. this.setAnimationLoop = function (callback) {
  13753. onAnimationFrameCallback = callback;
  13754. };
  13755. this.dispose = function () {};
  13756. }
  13757. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13758. function WebGLMaterials(properties) {
  13759. function refreshFogUniforms(uniforms, fog) {
  13760. uniforms.fogColor.value.copy(fog.color);
  13761. if (fog.isFog) {
  13762. uniforms.fogNear.value = fog.near;
  13763. uniforms.fogFar.value = fog.far;
  13764. } else if (fog.isFogExp2) {
  13765. uniforms.fogDensity.value = fog.density;
  13766. }
  13767. }
  13768. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13769. if (material.isMeshBasicMaterial) {
  13770. refreshUniformsCommon(uniforms, material);
  13771. } else if (material.isMeshLambertMaterial) {
  13772. refreshUniformsCommon(uniforms, material);
  13773. refreshUniformsLambert(uniforms, material);
  13774. } else if (material.isMeshToonMaterial) {
  13775. refreshUniformsCommon(uniforms, material);
  13776. refreshUniformsToon(uniforms, material);
  13777. } else if (material.isMeshPhongMaterial) {
  13778. refreshUniformsCommon(uniforms, material);
  13779. refreshUniformsPhong(uniforms, material);
  13780. } else if (material.isMeshStandardMaterial) {
  13781. refreshUniformsCommon(uniforms, material);
  13782. if (material.isMeshPhysicalMaterial) {
  13783. refreshUniformsPhysical(uniforms, material);
  13784. } else {
  13785. refreshUniformsStandard(uniforms, material);
  13786. }
  13787. } else if (material.isMeshMatcapMaterial) {
  13788. refreshUniformsCommon(uniforms, material);
  13789. refreshUniformsMatcap(uniforms, material);
  13790. } else if (material.isMeshDepthMaterial) {
  13791. refreshUniformsCommon(uniforms, material);
  13792. refreshUniformsDepth(uniforms, material);
  13793. } else if (material.isMeshDistanceMaterial) {
  13794. refreshUniformsCommon(uniforms, material);
  13795. refreshUniformsDistance(uniforms, material);
  13796. } else if (material.isMeshNormalMaterial) {
  13797. refreshUniformsCommon(uniforms, material);
  13798. refreshUniformsNormal(uniforms, material);
  13799. } else if (material.isLineBasicMaterial) {
  13800. refreshUniformsLine(uniforms, material);
  13801. if (material.isLineDashedMaterial) {
  13802. refreshUniformsDash(uniforms, material);
  13803. }
  13804. } else if (material.isPointsMaterial) {
  13805. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  13806. } else if (material.isSpriteMaterial) {
  13807. refreshUniformsSprites(uniforms, material);
  13808. } else if (material.isShadowMaterial) {
  13809. uniforms.color.value.copy(material.color);
  13810. uniforms.opacity.value = material.opacity;
  13811. } else if (material.isShaderMaterial) {
  13812. material.uniformsNeedUpdate = false; // #15581
  13813. }
  13814. }
  13815. function refreshUniformsCommon(uniforms, material) {
  13816. uniforms.opacity.value = material.opacity;
  13817. if (material.color) {
  13818. uniforms.diffuse.value.copy(material.color);
  13819. }
  13820. if (material.emissive) {
  13821. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  13822. }
  13823. if (material.map) {
  13824. uniforms.map.value = material.map;
  13825. }
  13826. if (material.alphaMap) {
  13827. uniforms.alphaMap.value = material.alphaMap;
  13828. }
  13829. if (material.specularMap) {
  13830. uniforms.specularMap.value = material.specularMap;
  13831. }
  13832. var envMap = properties.get(material).envMap;
  13833. if (envMap) {
  13834. uniforms.envMap.value = envMap;
  13835. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  13836. uniforms.reflectivity.value = material.reflectivity;
  13837. uniforms.refractionRatio.value = material.refractionRatio;
  13838. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  13839. if (maxMipLevel !== undefined) {
  13840. uniforms.maxMipLevel.value = maxMipLevel;
  13841. }
  13842. }
  13843. if (material.lightMap) {
  13844. uniforms.lightMap.value = material.lightMap;
  13845. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13846. }
  13847. if (material.aoMap) {
  13848. uniforms.aoMap.value = material.aoMap;
  13849. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13850. } // uv repeat and offset setting priorities
  13851. // 1. color map
  13852. // 2. specular map
  13853. // 3. displacementMap map
  13854. // 4. normal map
  13855. // 5. bump map
  13856. // 6. roughnessMap map
  13857. // 7. metalnessMap map
  13858. // 8. alphaMap map
  13859. // 9. emissiveMap map
  13860. // 10. clearcoat map
  13861. // 11. clearcoat normal map
  13862. // 12. clearcoat roughnessMap map
  13863. var uvScaleMap;
  13864. if (material.map) {
  13865. uvScaleMap = material.map;
  13866. } else if (material.specularMap) {
  13867. uvScaleMap = material.specularMap;
  13868. } else if (material.displacementMap) {
  13869. uvScaleMap = material.displacementMap;
  13870. } else if (material.normalMap) {
  13871. uvScaleMap = material.normalMap;
  13872. } else if (material.bumpMap) {
  13873. uvScaleMap = material.bumpMap;
  13874. } else if (material.roughnessMap) {
  13875. uvScaleMap = material.roughnessMap;
  13876. } else if (material.metalnessMap) {
  13877. uvScaleMap = material.metalnessMap;
  13878. } else if (material.alphaMap) {
  13879. uvScaleMap = material.alphaMap;
  13880. } else if (material.emissiveMap) {
  13881. uvScaleMap = material.emissiveMap;
  13882. } else if (material.clearcoatMap) {
  13883. uvScaleMap = material.clearcoatMap;
  13884. } else if (material.clearcoatNormalMap) {
  13885. uvScaleMap = material.clearcoatNormalMap;
  13886. } else if (material.clearcoatRoughnessMap) {
  13887. uvScaleMap = material.clearcoatRoughnessMap;
  13888. }
  13889. if (uvScaleMap !== undefined) {
  13890. // backwards compatibility
  13891. if (uvScaleMap.isWebGLRenderTarget) {
  13892. uvScaleMap = uvScaleMap.texture;
  13893. }
  13894. if (uvScaleMap.matrixAutoUpdate === true) {
  13895. uvScaleMap.updateMatrix();
  13896. }
  13897. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13898. } // uv repeat and offset setting priorities for uv2
  13899. // 1. ao map
  13900. // 2. light map
  13901. var uv2ScaleMap;
  13902. if (material.aoMap) {
  13903. uv2ScaleMap = material.aoMap;
  13904. } else if (material.lightMap) {
  13905. uv2ScaleMap = material.lightMap;
  13906. }
  13907. if (uv2ScaleMap !== undefined) {
  13908. // backwards compatibility
  13909. if (uv2ScaleMap.isWebGLRenderTarget) {
  13910. uv2ScaleMap = uv2ScaleMap.texture;
  13911. }
  13912. if (uv2ScaleMap.matrixAutoUpdate === true) {
  13913. uv2ScaleMap.updateMatrix();
  13914. }
  13915. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  13916. }
  13917. }
  13918. function refreshUniformsLine(uniforms, material) {
  13919. uniforms.diffuse.value.copy(material.color);
  13920. uniforms.opacity.value = material.opacity;
  13921. }
  13922. function refreshUniformsDash(uniforms, material) {
  13923. uniforms.dashSize.value = material.dashSize;
  13924. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13925. uniforms.scale.value = material.scale;
  13926. }
  13927. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  13928. uniforms.diffuse.value.copy(material.color);
  13929. uniforms.opacity.value = material.opacity;
  13930. uniforms.size.value = material.size * pixelRatio;
  13931. uniforms.scale.value = height * 0.5;
  13932. if (material.map) {
  13933. uniforms.map.value = material.map;
  13934. }
  13935. if (material.alphaMap) {
  13936. uniforms.alphaMap.value = material.alphaMap;
  13937. } // uv repeat and offset setting priorities
  13938. // 1. color map
  13939. // 2. alpha map
  13940. var uvScaleMap;
  13941. if (material.map) {
  13942. uvScaleMap = material.map;
  13943. } else if (material.alphaMap) {
  13944. uvScaleMap = material.alphaMap;
  13945. }
  13946. if (uvScaleMap !== undefined) {
  13947. if (uvScaleMap.matrixAutoUpdate === true) {
  13948. uvScaleMap.updateMatrix();
  13949. }
  13950. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13951. }
  13952. }
  13953. function refreshUniformsSprites(uniforms, material) {
  13954. uniforms.diffuse.value.copy(material.color);
  13955. uniforms.opacity.value = material.opacity;
  13956. uniforms.rotation.value = material.rotation;
  13957. if (material.map) {
  13958. uniforms.map.value = material.map;
  13959. }
  13960. if (material.alphaMap) {
  13961. uniforms.alphaMap.value = material.alphaMap;
  13962. } // uv repeat and offset setting priorities
  13963. // 1. color map
  13964. // 2. alpha map
  13965. var uvScaleMap;
  13966. if (material.map) {
  13967. uvScaleMap = material.map;
  13968. } else if (material.alphaMap) {
  13969. uvScaleMap = material.alphaMap;
  13970. }
  13971. if (uvScaleMap !== undefined) {
  13972. if (uvScaleMap.matrixAutoUpdate === true) {
  13973. uvScaleMap.updateMatrix();
  13974. }
  13975. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13976. }
  13977. }
  13978. function refreshUniformsLambert(uniforms, material) {
  13979. if (material.emissiveMap) {
  13980. uniforms.emissiveMap.value = material.emissiveMap;
  13981. }
  13982. }
  13983. function refreshUniformsPhong(uniforms, material) {
  13984. uniforms.specular.value.copy(material.specular);
  13985. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  13986. if (material.emissiveMap) {
  13987. uniforms.emissiveMap.value = material.emissiveMap;
  13988. }
  13989. if (material.bumpMap) {
  13990. uniforms.bumpMap.value = material.bumpMap;
  13991. uniforms.bumpScale.value = material.bumpScale;
  13992. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13993. }
  13994. if (material.normalMap) {
  13995. uniforms.normalMap.value = material.normalMap;
  13996. uniforms.normalScale.value.copy(material.normalScale);
  13997. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13998. }
  13999. if (material.displacementMap) {
  14000. uniforms.displacementMap.value = material.displacementMap;
  14001. uniforms.displacementScale.value = material.displacementScale;
  14002. uniforms.displacementBias.value = material.displacementBias;
  14003. }
  14004. }
  14005. function refreshUniformsToon(uniforms, material) {
  14006. if (material.gradientMap) {
  14007. uniforms.gradientMap.value = material.gradientMap;
  14008. }
  14009. if (material.emissiveMap) {
  14010. uniforms.emissiveMap.value = material.emissiveMap;
  14011. }
  14012. if (material.bumpMap) {
  14013. uniforms.bumpMap.value = material.bumpMap;
  14014. uniforms.bumpScale.value = material.bumpScale;
  14015. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14016. }
  14017. if (material.normalMap) {
  14018. uniforms.normalMap.value = material.normalMap;
  14019. uniforms.normalScale.value.copy(material.normalScale);
  14020. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14021. }
  14022. if (material.displacementMap) {
  14023. uniforms.displacementMap.value = material.displacementMap;
  14024. uniforms.displacementScale.value = material.displacementScale;
  14025. uniforms.displacementBias.value = material.displacementBias;
  14026. }
  14027. }
  14028. function refreshUniformsStandard(uniforms, material) {
  14029. uniforms.roughness.value = material.roughness;
  14030. uniforms.metalness.value = material.metalness;
  14031. if (material.roughnessMap) {
  14032. uniforms.roughnessMap.value = material.roughnessMap;
  14033. }
  14034. if (material.metalnessMap) {
  14035. uniforms.metalnessMap.value = material.metalnessMap;
  14036. }
  14037. if (material.emissiveMap) {
  14038. uniforms.emissiveMap.value = material.emissiveMap;
  14039. }
  14040. if (material.bumpMap) {
  14041. uniforms.bumpMap.value = material.bumpMap;
  14042. uniforms.bumpScale.value = material.bumpScale;
  14043. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14044. }
  14045. if (material.normalMap) {
  14046. uniforms.normalMap.value = material.normalMap;
  14047. uniforms.normalScale.value.copy(material.normalScale);
  14048. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14049. }
  14050. if (material.displacementMap) {
  14051. uniforms.displacementMap.value = material.displacementMap;
  14052. uniforms.displacementScale.value = material.displacementScale;
  14053. uniforms.displacementBias.value = material.displacementBias;
  14054. }
  14055. var envMap = properties.get(material).envMap;
  14056. if (envMap) {
  14057. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14058. uniforms.envMapIntensity.value = material.envMapIntensity;
  14059. }
  14060. }
  14061. function refreshUniformsPhysical(uniforms, material) {
  14062. refreshUniformsStandard(uniforms, material);
  14063. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14064. uniforms.clearcoat.value = material.clearcoat;
  14065. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14066. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14067. if (material.clearcoatMap) {
  14068. uniforms.clearcoatMap.value = material.clearcoatMap;
  14069. }
  14070. if (material.clearcoatRoughnessMap) {
  14071. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14072. }
  14073. if (material.clearcoatNormalMap) {
  14074. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14075. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14076. if (material.side === BackSide) {
  14077. uniforms.clearcoatNormalScale.value.negate();
  14078. }
  14079. }
  14080. uniforms.transmission.value = material.transmission;
  14081. if (material.transmissionMap) {
  14082. uniforms.transmissionMap.value = material.transmissionMap;
  14083. }
  14084. }
  14085. function refreshUniformsMatcap(uniforms, material) {
  14086. if (material.matcap) {
  14087. uniforms.matcap.value = material.matcap;
  14088. }
  14089. if (material.bumpMap) {
  14090. uniforms.bumpMap.value = material.bumpMap;
  14091. uniforms.bumpScale.value = material.bumpScale;
  14092. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14093. }
  14094. if (material.normalMap) {
  14095. uniforms.normalMap.value = material.normalMap;
  14096. uniforms.normalScale.value.copy(material.normalScale);
  14097. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14098. }
  14099. if (material.displacementMap) {
  14100. uniforms.displacementMap.value = material.displacementMap;
  14101. uniforms.displacementScale.value = material.displacementScale;
  14102. uniforms.displacementBias.value = material.displacementBias;
  14103. }
  14104. }
  14105. function refreshUniformsDepth(uniforms, material) {
  14106. if (material.displacementMap) {
  14107. uniforms.displacementMap.value = material.displacementMap;
  14108. uniforms.displacementScale.value = material.displacementScale;
  14109. uniforms.displacementBias.value = material.displacementBias;
  14110. }
  14111. }
  14112. function refreshUniformsDistance(uniforms, material) {
  14113. if (material.displacementMap) {
  14114. uniforms.displacementMap.value = material.displacementMap;
  14115. uniforms.displacementScale.value = material.displacementScale;
  14116. uniforms.displacementBias.value = material.displacementBias;
  14117. }
  14118. uniforms.referencePosition.value.copy(material.referencePosition);
  14119. uniforms.nearDistance.value = material.nearDistance;
  14120. uniforms.farDistance.value = material.farDistance;
  14121. }
  14122. function refreshUniformsNormal(uniforms, material) {
  14123. if (material.bumpMap) {
  14124. uniforms.bumpMap.value = material.bumpMap;
  14125. uniforms.bumpScale.value = material.bumpScale;
  14126. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14127. }
  14128. if (material.normalMap) {
  14129. uniforms.normalMap.value = material.normalMap;
  14130. uniforms.normalScale.value.copy(material.normalScale);
  14131. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14132. }
  14133. if (material.displacementMap) {
  14134. uniforms.displacementMap.value = material.displacementMap;
  14135. uniforms.displacementScale.value = material.displacementScale;
  14136. uniforms.displacementBias.value = material.displacementBias;
  14137. }
  14138. }
  14139. return {
  14140. refreshFogUniforms: refreshFogUniforms,
  14141. refreshMaterialUniforms: refreshMaterialUniforms
  14142. };
  14143. }
  14144. function createCanvasElement() {
  14145. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14146. canvas.style.display = 'block';
  14147. return canvas;
  14148. }
  14149. function WebGLRenderer(parameters) {
  14150. parameters = parameters || {};
  14151. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14152. _context = parameters.context !== undefined ? parameters.context : null,
  14153. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14154. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14155. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14156. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14157. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14158. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14159. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14160. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14161. var currentRenderList = null;
  14162. var currentRenderState = null; // public properties
  14163. this.domElement = _canvas; // Debug configuration container
  14164. this.debug = {
  14165. /**
  14166. * Enables error checking and reporting when shader programs are being compiled
  14167. * @type {boolean}
  14168. */
  14169. checkShaderErrors: true
  14170. }; // clearing
  14171. this.autoClear = true;
  14172. this.autoClearColor = true;
  14173. this.autoClearDepth = true;
  14174. this.autoClearStencil = true; // scene graph
  14175. this.sortObjects = true; // user-defined clipping
  14176. this.clippingPlanes = [];
  14177. this.localClippingEnabled = false; // physically based shading
  14178. this.gammaFactor = 2.0; // for backwards compatibility
  14179. this.outputEncoding = LinearEncoding; // physical lights
  14180. this.physicallyCorrectLights = false; // tone mapping
  14181. this.toneMapping = NoToneMapping;
  14182. this.toneMappingExposure = 1.0; // morphs
  14183. this.maxMorphTargets = 8;
  14184. this.maxMorphNormals = 4; // internal properties
  14185. var _this = this;
  14186. var _isContextLost = false; // internal state cache
  14187. var _framebuffer = null;
  14188. var _currentActiveCubeFace = 0;
  14189. var _currentActiveMipmapLevel = 0;
  14190. var _currentRenderTarget = null;
  14191. var _currentFramebuffer = null;
  14192. var _currentMaterialId = -1;
  14193. var _currentCamera = null;
  14194. var _currentArrayCamera = null;
  14195. var _currentViewport = new Vector4();
  14196. var _currentScissor = new Vector4();
  14197. var _currentScissorTest = null; //
  14198. var _width = _canvas.width;
  14199. var _height = _canvas.height;
  14200. var _pixelRatio = 1;
  14201. var _opaqueSort = null;
  14202. var _transparentSort = null;
  14203. var _viewport = new Vector4(0, 0, _width, _height);
  14204. var _scissor = new Vector4(0, 0, _width, _height);
  14205. var _scissorTest = false; // frustum
  14206. var _frustum = new Frustum(); // clipping
  14207. var _clippingEnabled = false;
  14208. var _localClippingEnabled = false; // camera matrices cache
  14209. var _projScreenMatrix = new Matrix4();
  14210. var _vector3 = new Vector3();
  14211. var _emptyScene = {
  14212. background: null,
  14213. fog: null,
  14214. environment: null,
  14215. overrideMaterial: null,
  14216. isScene: true
  14217. };
  14218. function getTargetPixelRatio() {
  14219. return _currentRenderTarget === null ? _pixelRatio : 1;
  14220. } // initialize
  14221. var _gl = _context;
  14222. function getContext(contextNames, contextAttributes) {
  14223. for (var i = 0; i < contextNames.length; i++) {
  14224. var contextName = contextNames[i];
  14225. var context = _canvas.getContext(contextName, contextAttributes);
  14226. if (context !== null) return context;
  14227. }
  14228. return null;
  14229. }
  14230. try {
  14231. var contextAttributes = {
  14232. alpha: _alpha,
  14233. depth: _depth,
  14234. stencil: _stencil,
  14235. antialias: _antialias,
  14236. premultipliedAlpha: _premultipliedAlpha,
  14237. preserveDrawingBuffer: _preserveDrawingBuffer,
  14238. powerPreference: _powerPreference,
  14239. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14240. }; // event listeners must be registered before WebGL context is created, see #12753
  14241. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14242. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14243. if (_gl === null) {
  14244. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14245. if (_this.isWebGL1Renderer === true) {
  14246. contextNames.shift();
  14247. }
  14248. _gl = getContext(contextNames, contextAttributes);
  14249. if (_gl === null) {
  14250. if (getContext(contextNames)) {
  14251. throw new Error('Error creating WebGL context with your selected attributes.');
  14252. } else {
  14253. throw new Error('Error creating WebGL context.');
  14254. }
  14255. }
  14256. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14257. if (_gl.getShaderPrecisionFormat === undefined) {
  14258. _gl.getShaderPrecisionFormat = function () {
  14259. return {
  14260. 'rangeMin': 1,
  14261. 'rangeMax': 1,
  14262. 'precision': 1
  14263. };
  14264. };
  14265. }
  14266. } catch (error) {
  14267. console.error('THREE.WebGLRenderer: ' + error.message);
  14268. throw error;
  14269. }
  14270. var extensions, capabilities, state, info;
  14271. var properties, textures, cubemaps, attributes, geometries, objects;
  14272. var programCache, materials, renderLists, renderStates, clipping;
  14273. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14274. var utils, bindingStates;
  14275. function initGLContext() {
  14276. extensions = new WebGLExtensions(_gl);
  14277. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14278. if (capabilities.isWebGL2 === false) {
  14279. extensions.get('WEBGL_depth_texture');
  14280. extensions.get('OES_texture_float');
  14281. extensions.get('OES_texture_half_float');
  14282. extensions.get('OES_texture_half_float_linear');
  14283. extensions.get('OES_standard_derivatives');
  14284. extensions.get('OES_element_index_uint');
  14285. extensions.get('OES_vertex_array_object');
  14286. extensions.get('ANGLE_instanced_arrays');
  14287. }
  14288. extensions.get('OES_texture_float_linear');
  14289. utils = new WebGLUtils(_gl, extensions, capabilities);
  14290. state = new WebGLState(_gl, extensions, capabilities);
  14291. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14292. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14293. info = new WebGLInfo(_gl);
  14294. properties = new WebGLProperties();
  14295. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14296. cubemaps = new WebGLCubeMaps(_this);
  14297. attributes = new WebGLAttributes(_gl, capabilities);
  14298. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14299. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14300. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14301. morphtargets = new WebGLMorphtargets(_gl);
  14302. clipping = new WebGLClipping(properties);
  14303. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14304. materials = new WebGLMaterials(properties);
  14305. renderLists = new WebGLRenderLists(properties);
  14306. renderStates = new WebGLRenderStates(extensions, capabilities);
  14307. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14308. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14309. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14310. info.programs = programCache.programs;
  14311. _this.capabilities = capabilities;
  14312. _this.extensions = extensions;
  14313. _this.properties = properties;
  14314. _this.renderLists = renderLists;
  14315. _this.state = state;
  14316. _this.info = info;
  14317. }
  14318. initGLContext(); // xr
  14319. var xr = new WebXRManager(_this, _gl);
  14320. this.xr = xr; // shadow map
  14321. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14322. this.shadowMap = shadowMap; // API
  14323. this.getContext = function () {
  14324. return _gl;
  14325. };
  14326. this.getContextAttributes = function () {
  14327. return _gl.getContextAttributes();
  14328. };
  14329. this.forceContextLoss = function () {
  14330. var extension = extensions.get('WEBGL_lose_context');
  14331. if (extension) extension.loseContext();
  14332. };
  14333. this.forceContextRestore = function () {
  14334. var extension = extensions.get('WEBGL_lose_context');
  14335. if (extension) extension.restoreContext();
  14336. };
  14337. this.getPixelRatio = function () {
  14338. return _pixelRatio;
  14339. };
  14340. this.setPixelRatio = function (value) {
  14341. if (value === undefined) return;
  14342. _pixelRatio = value;
  14343. this.setSize(_width, _height, false);
  14344. };
  14345. this.getSize = function (target) {
  14346. if (target === undefined) {
  14347. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14348. target = new Vector2();
  14349. }
  14350. return target.set(_width, _height);
  14351. };
  14352. this.setSize = function (width, height, updateStyle) {
  14353. if (xr.isPresenting) {
  14354. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14355. return;
  14356. }
  14357. _width = width;
  14358. _height = height;
  14359. _canvas.width = Math.floor(width * _pixelRatio);
  14360. _canvas.height = Math.floor(height * _pixelRatio);
  14361. if (updateStyle !== false) {
  14362. _canvas.style.width = width + 'px';
  14363. _canvas.style.height = height + 'px';
  14364. }
  14365. this.setViewport(0, 0, width, height);
  14366. };
  14367. this.getDrawingBufferSize = function (target) {
  14368. if (target === undefined) {
  14369. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14370. target = new Vector2();
  14371. }
  14372. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14373. };
  14374. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14375. _width = width;
  14376. _height = height;
  14377. _pixelRatio = pixelRatio;
  14378. _canvas.width = Math.floor(width * pixelRatio);
  14379. _canvas.height = Math.floor(height * pixelRatio);
  14380. this.setViewport(0, 0, width, height);
  14381. };
  14382. this.getCurrentViewport = function (target) {
  14383. if (target === undefined) {
  14384. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14385. target = new Vector4();
  14386. }
  14387. return target.copy(_currentViewport);
  14388. };
  14389. this.getViewport = function (target) {
  14390. return target.copy(_viewport);
  14391. };
  14392. this.setViewport = function (x, y, width, height) {
  14393. if (x.isVector4) {
  14394. _viewport.set(x.x, x.y, x.z, x.w);
  14395. } else {
  14396. _viewport.set(x, y, width, height);
  14397. }
  14398. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14399. };
  14400. this.getScissor = function (target) {
  14401. return target.copy(_scissor);
  14402. };
  14403. this.setScissor = function (x, y, width, height) {
  14404. if (x.isVector4) {
  14405. _scissor.set(x.x, x.y, x.z, x.w);
  14406. } else {
  14407. _scissor.set(x, y, width, height);
  14408. }
  14409. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14410. };
  14411. this.getScissorTest = function () {
  14412. return _scissorTest;
  14413. };
  14414. this.setScissorTest = function (boolean) {
  14415. state.setScissorTest(_scissorTest = boolean);
  14416. };
  14417. this.setOpaqueSort = function (method) {
  14418. _opaqueSort = method;
  14419. };
  14420. this.setTransparentSort = function (method) {
  14421. _transparentSort = method;
  14422. }; // Clearing
  14423. this.getClearColor = function () {
  14424. return background.getClearColor();
  14425. };
  14426. this.setClearColor = function () {
  14427. background.setClearColor.apply(background, arguments);
  14428. };
  14429. this.getClearAlpha = function () {
  14430. return background.getClearAlpha();
  14431. };
  14432. this.setClearAlpha = function () {
  14433. background.setClearAlpha.apply(background, arguments);
  14434. };
  14435. this.clear = function (color, depth, stencil) {
  14436. var bits = 0;
  14437. if (color === undefined || color) bits |= 16384;
  14438. if (depth === undefined || depth) bits |= 256;
  14439. if (stencil === undefined || stencil) bits |= 1024;
  14440. _gl.clear(bits);
  14441. };
  14442. this.clearColor = function () {
  14443. this.clear(true, false, false);
  14444. };
  14445. this.clearDepth = function () {
  14446. this.clear(false, true, false);
  14447. };
  14448. this.clearStencil = function () {
  14449. this.clear(false, false, true);
  14450. }; //
  14451. this.dispose = function () {
  14452. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14453. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14454. renderLists.dispose();
  14455. renderStates.dispose();
  14456. properties.dispose();
  14457. cubemaps.dispose();
  14458. objects.dispose();
  14459. bindingStates.dispose();
  14460. xr.dispose();
  14461. animation.stop();
  14462. }; // Events
  14463. function onContextLost(event) {
  14464. event.preventDefault();
  14465. console.log('THREE.WebGLRenderer: Context Lost.');
  14466. _isContextLost = true;
  14467. }
  14468. function onContextRestore()
  14469. /* event */
  14470. {
  14471. console.log('THREE.WebGLRenderer: Context Restored.');
  14472. _isContextLost = false;
  14473. initGLContext();
  14474. }
  14475. function onMaterialDispose(event) {
  14476. var material = event.target;
  14477. material.removeEventListener('dispose', onMaterialDispose);
  14478. deallocateMaterial(material);
  14479. } // Buffer deallocation
  14480. function deallocateMaterial(material) {
  14481. releaseMaterialProgramReference(material);
  14482. properties.remove(material);
  14483. }
  14484. function releaseMaterialProgramReference(material) {
  14485. var programInfo = properties.get(material).program;
  14486. if (programInfo !== undefined) {
  14487. programCache.releaseProgram(programInfo);
  14488. }
  14489. } // Buffer rendering
  14490. function renderObjectImmediate(object, program) {
  14491. object.render(function (object) {
  14492. _this.renderBufferImmediate(object, program);
  14493. });
  14494. }
  14495. this.renderBufferImmediate = function (object, program) {
  14496. bindingStates.initAttributes();
  14497. var buffers = properties.get(object);
  14498. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14499. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14500. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14501. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14502. var programAttributes = program.getAttributes();
  14503. if (object.hasPositions) {
  14504. _gl.bindBuffer(34962, buffers.position);
  14505. _gl.bufferData(34962, object.positionArray, 35048);
  14506. bindingStates.enableAttribute(programAttributes.position);
  14507. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14508. }
  14509. if (object.hasNormals) {
  14510. _gl.bindBuffer(34962, buffers.normal);
  14511. _gl.bufferData(34962, object.normalArray, 35048);
  14512. bindingStates.enableAttribute(programAttributes.normal);
  14513. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14514. }
  14515. if (object.hasUvs) {
  14516. _gl.bindBuffer(34962, buffers.uv);
  14517. _gl.bufferData(34962, object.uvArray, 35048);
  14518. bindingStates.enableAttribute(programAttributes.uv);
  14519. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14520. }
  14521. if (object.hasColors) {
  14522. _gl.bindBuffer(34962, buffers.color);
  14523. _gl.bufferData(34962, object.colorArray, 35048);
  14524. bindingStates.enableAttribute(programAttributes.color);
  14525. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14526. }
  14527. bindingStates.disableUnusedAttributes();
  14528. _gl.drawArrays(4, 0, object.count);
  14529. object.count = 0;
  14530. };
  14531. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14532. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14533. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14534. var program = setProgram(camera, scene, material, object);
  14535. state.setMaterial(material, frontFaceCW); //
  14536. var index = geometry.index;
  14537. var position = geometry.attributes.position; //
  14538. if (index === null) {
  14539. if (position === undefined || position.count === 0) return;
  14540. } else if (index.count === 0) {
  14541. return;
  14542. } //
  14543. var rangeFactor = 1;
  14544. if (material.wireframe === true) {
  14545. index = geometries.getWireframeAttribute(geometry);
  14546. rangeFactor = 2;
  14547. }
  14548. if (material.morphTargets || material.morphNormals) {
  14549. morphtargets.update(object, geometry, material, program);
  14550. }
  14551. bindingStates.setup(object, material, program, geometry, index);
  14552. var attribute;
  14553. var renderer = bufferRenderer;
  14554. if (index !== null) {
  14555. attribute = attributes.get(index);
  14556. renderer = indexedBufferRenderer;
  14557. renderer.setIndex(attribute);
  14558. } //
  14559. var dataCount = index !== null ? index.count : position.count;
  14560. var rangeStart = geometry.drawRange.start * rangeFactor;
  14561. var rangeCount = geometry.drawRange.count * rangeFactor;
  14562. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14563. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14564. var drawStart = Math.max(rangeStart, groupStart);
  14565. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14566. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14567. if (drawCount === 0) return; //
  14568. if (object.isMesh) {
  14569. if (material.wireframe === true) {
  14570. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14571. renderer.setMode(1);
  14572. } else {
  14573. renderer.setMode(4);
  14574. }
  14575. } else if (object.isLine) {
  14576. var lineWidth = material.linewidth;
  14577. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14578. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14579. if (object.isLineSegments) {
  14580. renderer.setMode(1);
  14581. } else if (object.isLineLoop) {
  14582. renderer.setMode(2);
  14583. } else {
  14584. renderer.setMode(3);
  14585. }
  14586. } else if (object.isPoints) {
  14587. renderer.setMode(0);
  14588. } else if (object.isSprite) {
  14589. renderer.setMode(4);
  14590. }
  14591. if (object.isInstancedMesh) {
  14592. renderer.renderInstances(drawStart, drawCount, object.count);
  14593. } else if (geometry.isInstancedBufferGeometry) {
  14594. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14595. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14596. } else {
  14597. renderer.render(drawStart, drawCount);
  14598. }
  14599. }; // Compile
  14600. this.compile = function (scene, camera) {
  14601. currentRenderState = renderStates.get(scene, camera);
  14602. currentRenderState.init();
  14603. scene.traverseVisible(function (object) {
  14604. if (object.isLight && object.layers.test(camera.layers)) {
  14605. currentRenderState.pushLight(object);
  14606. if (object.castShadow) {
  14607. currentRenderState.pushShadow(object);
  14608. }
  14609. }
  14610. });
  14611. currentRenderState.setupLights(camera);
  14612. var compiled = new WeakMap();
  14613. scene.traverse(function (object) {
  14614. var material = object.material;
  14615. if (material) {
  14616. if (Array.isArray(material)) {
  14617. for (var i = 0; i < material.length; i++) {
  14618. var material2 = material[i];
  14619. if (compiled.has(material2) === false) {
  14620. initMaterial(material2, scene, object);
  14621. compiled.set(material2);
  14622. }
  14623. }
  14624. } else if (compiled.has(material) === false) {
  14625. initMaterial(material, scene, object);
  14626. compiled.set(material);
  14627. }
  14628. }
  14629. });
  14630. }; // Animation Loop
  14631. var onAnimationFrameCallback = null;
  14632. function onAnimationFrame(time) {
  14633. if (xr.isPresenting) return;
  14634. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14635. }
  14636. var animation = new WebGLAnimation();
  14637. animation.setAnimationLoop(onAnimationFrame);
  14638. if (typeof window !== 'undefined') animation.setContext(window);
  14639. this.setAnimationLoop = function (callback) {
  14640. onAnimationFrameCallback = callback;
  14641. xr.setAnimationLoop(callback);
  14642. callback === null ? animation.stop() : animation.start();
  14643. }; // Rendering
  14644. this.render = function (scene, camera) {
  14645. var renderTarget, forceClear;
  14646. if (arguments[2] !== undefined) {
  14647. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14648. renderTarget = arguments[2];
  14649. }
  14650. if (arguments[3] !== undefined) {
  14651. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14652. forceClear = arguments[3];
  14653. }
  14654. if (camera !== undefined && camera.isCamera !== true) {
  14655. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14656. return;
  14657. }
  14658. if (_isContextLost === true) return; // reset caching for this frame
  14659. bindingStates.resetDefaultState();
  14660. _currentMaterialId = -1;
  14661. _currentCamera = null; // update scene graph
  14662. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14663. if (camera.parent === null) camera.updateMatrixWorld();
  14664. if (xr.enabled === true && xr.isPresenting === true) {
  14665. camera = xr.getCamera(camera);
  14666. } //
  14667. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14668. currentRenderState = renderStates.get(scene, camera);
  14669. currentRenderState.init();
  14670. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14671. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14672. _localClippingEnabled = this.localClippingEnabled;
  14673. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14674. currentRenderList = renderLists.get(scene, camera);
  14675. currentRenderList.init();
  14676. projectObject(scene, camera, 0, _this.sortObjects);
  14677. currentRenderList.finish();
  14678. if (_this.sortObjects === true) {
  14679. currentRenderList.sort(_opaqueSort, _transparentSort);
  14680. } //
  14681. if (_clippingEnabled === true) clipping.beginShadows();
  14682. var shadowsArray = currentRenderState.state.shadowsArray;
  14683. shadowMap.render(shadowsArray, scene, camera);
  14684. currentRenderState.setupLights(camera);
  14685. if (_clippingEnabled === true) clipping.endShadows(); //
  14686. if (this.info.autoReset === true) this.info.reset();
  14687. if (renderTarget !== undefined) {
  14688. this.setRenderTarget(renderTarget);
  14689. } //
  14690. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14691. var opaqueObjects = currentRenderList.opaque;
  14692. var transparentObjects = currentRenderList.transparent;
  14693. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14694. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14695. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14696. if (_currentRenderTarget !== null) {
  14697. // Generate mipmap if we're using any kind of mipmap filtering
  14698. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14699. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14700. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14701. state.buffers.depth.setTest(true);
  14702. state.buffers.depth.setMask(true);
  14703. state.buffers.color.setMask(true);
  14704. state.setPolygonOffset(false); // _gl.finish();
  14705. currentRenderList = null;
  14706. currentRenderState = null;
  14707. };
  14708. function projectObject(object, camera, groupOrder, sortObjects) {
  14709. if (object.visible === false) return;
  14710. var visible = object.layers.test(camera.layers);
  14711. if (visible) {
  14712. if (object.isGroup) {
  14713. groupOrder = object.renderOrder;
  14714. } else if (object.isLOD) {
  14715. if (object.autoUpdate === true) object.update(camera);
  14716. } else if (object.isLight) {
  14717. currentRenderState.pushLight(object);
  14718. if (object.castShadow) {
  14719. currentRenderState.pushShadow(object);
  14720. }
  14721. } else if (object.isSprite) {
  14722. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14723. if (sortObjects) {
  14724. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14725. }
  14726. var geometry = objects.update(object);
  14727. var material = object.material;
  14728. if (material.visible) {
  14729. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14730. }
  14731. }
  14732. } else if (object.isImmediateRenderObject) {
  14733. if (sortObjects) {
  14734. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14735. }
  14736. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14737. } else if (object.isMesh || object.isLine || object.isPoints) {
  14738. if (object.isSkinnedMesh) {
  14739. // update skeleton only once in a frame
  14740. if (object.skeleton.frame !== info.render.frame) {
  14741. object.skeleton.update();
  14742. object.skeleton.frame = info.render.frame;
  14743. }
  14744. }
  14745. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14746. if (sortObjects) {
  14747. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14748. }
  14749. var _geometry = objects.update(object);
  14750. var _material = object.material;
  14751. if (Array.isArray(_material)) {
  14752. var groups = _geometry.groups;
  14753. for (var i = 0, l = groups.length; i < l; i++) {
  14754. var group = groups[i];
  14755. var groupMaterial = _material[group.materialIndex];
  14756. if (groupMaterial && groupMaterial.visible) {
  14757. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14758. }
  14759. }
  14760. } else if (_material.visible) {
  14761. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14762. }
  14763. }
  14764. }
  14765. }
  14766. var children = object.children;
  14767. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14768. projectObject(children[_i], camera, groupOrder, sortObjects);
  14769. }
  14770. }
  14771. function renderObjects(renderList, scene, camera) {
  14772. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14773. for (var i = 0, l = renderList.length; i < l; i++) {
  14774. var renderItem = renderList[i];
  14775. var object = renderItem.object;
  14776. var geometry = renderItem.geometry;
  14777. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14778. var group = renderItem.group;
  14779. if (camera.isArrayCamera) {
  14780. _currentArrayCamera = camera;
  14781. var cameras = camera.cameras;
  14782. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14783. var camera2 = cameras[j];
  14784. if (object.layers.test(camera2.layers)) {
  14785. state.viewport(_currentViewport.copy(camera2.viewport));
  14786. currentRenderState.setupLights(camera2);
  14787. renderObject(object, scene, camera2, geometry, material, group);
  14788. }
  14789. }
  14790. } else {
  14791. _currentArrayCamera = null;
  14792. renderObject(object, scene, camera, geometry, material, group);
  14793. }
  14794. }
  14795. }
  14796. function renderObject(object, scene, camera, geometry, material, group) {
  14797. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  14798. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14799. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  14800. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  14801. if (object.isImmediateRenderObject) {
  14802. var program = setProgram(camera, scene, material, object);
  14803. state.setMaterial(material);
  14804. bindingStates.reset();
  14805. renderObjectImmediate(object, program);
  14806. } else {
  14807. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  14808. }
  14809. object.onAfterRender(_this, scene, camera, geometry, material, group);
  14810. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14811. }
  14812. function initMaterial(material, scene, object) {
  14813. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14814. var materialProperties = properties.get(material);
  14815. var lights = currentRenderState.state.lights;
  14816. var shadowsArray = currentRenderState.state.shadowsArray;
  14817. var lightsStateVersion = lights.state.version;
  14818. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  14819. var programCacheKey = programCache.getProgramCacheKey(parameters);
  14820. var program = materialProperties.program;
  14821. var programChange = true;
  14822. if (program === undefined) {
  14823. // new material
  14824. material.addEventListener('dispose', onMaterialDispose);
  14825. } else if (program.cacheKey !== programCacheKey) {
  14826. // changed glsl or parameters
  14827. releaseMaterialProgramReference(material);
  14828. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  14829. programChange = false;
  14830. } else if (parameters.shaderID !== undefined) {
  14831. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  14832. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14833. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  14834. return;
  14835. } else {
  14836. // only rebuild uniform list
  14837. programChange = false;
  14838. }
  14839. if (programChange) {
  14840. parameters.uniforms = programCache.getUniforms(material);
  14841. material.onBeforeCompile(parameters, _this);
  14842. program = programCache.acquireProgram(parameters, programCacheKey);
  14843. materialProperties.program = program;
  14844. materialProperties.uniforms = parameters.uniforms;
  14845. materialProperties.outputEncoding = parameters.outputEncoding;
  14846. }
  14847. var uniforms = materialProperties.uniforms;
  14848. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  14849. materialProperties.numClippingPlanes = clipping.numPlanes;
  14850. materialProperties.numIntersection = clipping.numIntersection;
  14851. uniforms.clippingPlanes = clipping.uniform;
  14852. }
  14853. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  14854. materialProperties.fog = scene.fog;
  14855. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  14856. materialProperties.needsLights = materialNeedsLights(material);
  14857. materialProperties.lightsStateVersion = lightsStateVersion;
  14858. if (materialProperties.needsLights) {
  14859. // wire up the material to this renderer's lighting state
  14860. uniforms.ambientLightColor.value = lights.state.ambient;
  14861. uniforms.lightProbe.value = lights.state.probe;
  14862. uniforms.directionalLights.value = lights.state.directional;
  14863. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  14864. uniforms.spotLights.value = lights.state.spot;
  14865. uniforms.spotLightShadows.value = lights.state.spotShadow;
  14866. uniforms.rectAreaLights.value = lights.state.rectArea;
  14867. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  14868. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  14869. uniforms.pointLights.value = lights.state.point;
  14870. uniforms.pointLightShadows.value = lights.state.pointShadow;
  14871. uniforms.hemisphereLights.value = lights.state.hemi;
  14872. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14873. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14874. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14875. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14876. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14877. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  14878. }
  14879. var progUniforms = materialProperties.program.getUniforms();
  14880. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  14881. materialProperties.uniformsList = uniformsList;
  14882. }
  14883. function setProgram(camera, scene, material, object) {
  14884. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14885. textures.resetTextureUnits();
  14886. var fog = scene.fog;
  14887. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14888. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  14889. var envMap = cubemaps.get(material.envMap || environment);
  14890. var materialProperties = properties.get(material);
  14891. var lights = currentRenderState.state.lights;
  14892. if (_clippingEnabled === true) {
  14893. if (_localClippingEnabled === true || camera !== _currentCamera) {
  14894. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  14895. // object instead of the material, once it becomes feasible
  14896. // (#8465, #8379)
  14897. clipping.setState(material, camera, useCache);
  14898. }
  14899. }
  14900. if (material.version === materialProperties.__version) {
  14901. if (material.fog && materialProperties.fog !== fog) {
  14902. initMaterial(material, scene, object);
  14903. } else if (materialProperties.environment !== environment) {
  14904. initMaterial(material, scene, object);
  14905. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  14906. initMaterial(material, scene, object);
  14907. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  14908. initMaterial(material, scene, object);
  14909. } else if (materialProperties.outputEncoding !== encoding) {
  14910. initMaterial(material, scene, object);
  14911. } else if (materialProperties.envMap !== envMap) {
  14912. initMaterial(material, scene, object);
  14913. }
  14914. } else {
  14915. initMaterial(material, scene, object);
  14916. materialProperties.__version = material.version;
  14917. }
  14918. var refreshProgram = false;
  14919. var refreshMaterial = false;
  14920. var refreshLights = false;
  14921. var program = materialProperties.program,
  14922. p_uniforms = program.getUniforms(),
  14923. m_uniforms = materialProperties.uniforms;
  14924. if (state.useProgram(program.program)) {
  14925. refreshProgram = true;
  14926. refreshMaterial = true;
  14927. refreshLights = true;
  14928. }
  14929. if (material.id !== _currentMaterialId) {
  14930. _currentMaterialId = material.id;
  14931. refreshMaterial = true;
  14932. }
  14933. if (refreshProgram || _currentCamera !== camera) {
  14934. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  14935. if (capabilities.logarithmicDepthBuffer) {
  14936. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  14937. }
  14938. if (_currentCamera !== camera) {
  14939. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  14940. // now, in case this material supports lights - or later, when
  14941. // the next material that does gets activated:
  14942. refreshMaterial = true; // set to true on material change
  14943. refreshLights = true; // remains set until update done
  14944. } // load material specific uniforms
  14945. // (shader material also gets them for the sake of genericity)
  14946. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  14947. var uCamPos = p_uniforms.map.cameraPosition;
  14948. if (uCamPos !== undefined) {
  14949. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  14950. }
  14951. }
  14952. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  14953. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  14954. }
  14955. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  14956. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  14957. }
  14958. } // skinning uniforms must be set even if material didn't change
  14959. // auto-setting of texture unit for bone texture must go before other textures
  14960. // otherwise textures used for skinning can take over texture units reserved for other material textures
  14961. if (material.skinning) {
  14962. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  14963. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  14964. var skeleton = object.skeleton;
  14965. if (skeleton) {
  14966. var bones = skeleton.bones;
  14967. if (capabilities.floatVertexTextures) {
  14968. if (skeleton.boneTexture === null) {
  14969. // layout (1 matrix = 4 pixels)
  14970. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14971. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14972. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14973. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14974. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14975. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  14976. size = MathUtils.ceilPowerOfTwo(size);
  14977. size = Math.max(size, 4);
  14978. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  14979. boneMatrices.set(skeleton.boneMatrices); // copy current values
  14980. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  14981. skeleton.boneMatrices = boneMatrices;
  14982. skeleton.boneTexture = boneTexture;
  14983. skeleton.boneTextureSize = size;
  14984. }
  14985. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  14986. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  14987. } else {
  14988. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  14989. }
  14990. }
  14991. }
  14992. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  14993. materialProperties.receiveShadow = object.receiveShadow;
  14994. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  14995. }
  14996. if (refreshMaterial) {
  14997. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  14998. if (materialProperties.needsLights) {
  14999. // the current material requires lighting info
  15000. // note: all lighting uniforms are always set correctly
  15001. // they simply reference the renderer's state for their
  15002. // values
  15003. //
  15004. // use the current material's .needsUpdate flags to set
  15005. // the GL state when required
  15006. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15007. } // refresh uniforms common to several materials
  15008. if (fog && material.fog) {
  15009. materials.refreshFogUniforms(m_uniforms, fog);
  15010. }
  15011. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15012. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15013. }
  15014. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15015. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15016. material.uniformsNeedUpdate = false;
  15017. }
  15018. if (material.isSpriteMaterial) {
  15019. p_uniforms.setValue(_gl, 'center', object.center);
  15020. } // common matrices
  15021. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15022. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15023. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15024. return program;
  15025. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15026. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15027. uniforms.ambientLightColor.needsUpdate = value;
  15028. uniforms.lightProbe.needsUpdate = value;
  15029. uniforms.directionalLights.needsUpdate = value;
  15030. uniforms.directionalLightShadows.needsUpdate = value;
  15031. uniforms.pointLights.needsUpdate = value;
  15032. uniforms.pointLightShadows.needsUpdate = value;
  15033. uniforms.spotLights.needsUpdate = value;
  15034. uniforms.spotLightShadows.needsUpdate = value;
  15035. uniforms.rectAreaLights.needsUpdate = value;
  15036. uniforms.hemisphereLights.needsUpdate = value;
  15037. }
  15038. function materialNeedsLights(material) {
  15039. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15040. } //
  15041. this.setFramebuffer = function (value) {
  15042. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15043. _framebuffer = value;
  15044. };
  15045. this.getActiveCubeFace = function () {
  15046. return _currentActiveCubeFace;
  15047. };
  15048. this.getActiveMipmapLevel = function () {
  15049. return _currentActiveMipmapLevel;
  15050. };
  15051. this.getRenderList = function () {
  15052. return currentRenderList;
  15053. };
  15054. this.setRenderList = function (renderList) {
  15055. currentRenderList = renderList;
  15056. };
  15057. this.getRenderState = function () {
  15058. return currentRenderState;
  15059. };
  15060. this.setRenderState = function (renderState) {
  15061. currentRenderState = renderState;
  15062. };
  15063. this.getRenderTarget = function () {
  15064. return _currentRenderTarget;
  15065. };
  15066. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15067. if (activeCubeFace === void 0) {
  15068. activeCubeFace = 0;
  15069. }
  15070. if (activeMipmapLevel === void 0) {
  15071. activeMipmapLevel = 0;
  15072. }
  15073. _currentRenderTarget = renderTarget;
  15074. _currentActiveCubeFace = activeCubeFace;
  15075. _currentActiveMipmapLevel = activeMipmapLevel;
  15076. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15077. textures.setupRenderTarget(renderTarget);
  15078. }
  15079. var framebuffer = _framebuffer;
  15080. var isCube = false;
  15081. if (renderTarget) {
  15082. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15083. if (renderTarget.isWebGLCubeRenderTarget) {
  15084. framebuffer = __webglFramebuffer[activeCubeFace];
  15085. isCube = true;
  15086. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15087. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15088. } else {
  15089. framebuffer = __webglFramebuffer;
  15090. }
  15091. _currentViewport.copy(renderTarget.viewport);
  15092. _currentScissor.copy(renderTarget.scissor);
  15093. _currentScissorTest = renderTarget.scissorTest;
  15094. } else {
  15095. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15096. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15097. _currentScissorTest = _scissorTest;
  15098. }
  15099. if (_currentFramebuffer !== framebuffer) {
  15100. _gl.bindFramebuffer(36160, framebuffer);
  15101. _currentFramebuffer = framebuffer;
  15102. }
  15103. state.viewport(_currentViewport);
  15104. state.scissor(_currentScissor);
  15105. state.setScissorTest(_currentScissorTest);
  15106. if (isCube) {
  15107. var textureProperties = properties.get(renderTarget.texture);
  15108. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15109. }
  15110. };
  15111. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15112. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15113. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15114. return;
  15115. }
  15116. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15117. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15118. framebuffer = framebuffer[activeCubeFaceIndex];
  15119. }
  15120. if (framebuffer) {
  15121. var restore = false;
  15122. if (framebuffer !== _currentFramebuffer) {
  15123. _gl.bindFramebuffer(36160, framebuffer);
  15124. restore = true;
  15125. }
  15126. try {
  15127. var texture = renderTarget.texture;
  15128. var textureFormat = texture.format;
  15129. var textureType = texture.type;
  15130. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15131. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15132. return;
  15133. }
  15134. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15135. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15136. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15137. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15138. return;
  15139. }
  15140. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15141. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15142. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15143. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15144. }
  15145. } else {
  15146. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15147. }
  15148. } finally {
  15149. if (restore) {
  15150. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15151. }
  15152. }
  15153. }
  15154. };
  15155. this.copyFramebufferToTexture = function (position, texture, level) {
  15156. if (level === void 0) {
  15157. level = 0;
  15158. }
  15159. var levelScale = Math.pow(2, -level);
  15160. var width = Math.floor(texture.image.width * levelScale);
  15161. var height = Math.floor(texture.image.height * levelScale);
  15162. var glFormat = utils.convert(texture.format);
  15163. textures.setTexture2D(texture, 0);
  15164. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15165. state.unbindTexture();
  15166. };
  15167. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15168. if (level === void 0) {
  15169. level = 0;
  15170. }
  15171. var width = srcTexture.image.width;
  15172. var height = srcTexture.image.height;
  15173. var glFormat = utils.convert(dstTexture.format);
  15174. var glType = utils.convert(dstTexture.type);
  15175. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15176. // parameters, make sure they are correct for the dstTexture
  15177. _gl.pixelStorei(37440, dstTexture.flipY);
  15178. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15179. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15180. if (srcTexture.isDataTexture) {
  15181. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15182. } else {
  15183. if (srcTexture.isCompressedTexture) {
  15184. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15185. } else {
  15186. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15187. }
  15188. } // Generate mipmaps only when copying level 0
  15189. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15190. state.unbindTexture();
  15191. };
  15192. this.initTexture = function (texture) {
  15193. textures.setTexture2D(texture, 0);
  15194. state.unbindTexture();
  15195. };
  15196. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15197. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15198. detail: this
  15199. })); // eslint-disable-line no-undef
  15200. }
  15201. }
  15202. function WebGL1Renderer(parameters) {
  15203. WebGLRenderer.call(this, parameters);
  15204. }
  15205. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15206. constructor: WebGL1Renderer,
  15207. isWebGL1Renderer: true
  15208. });
  15209. var FogExp2 = /*#__PURE__*/function () {
  15210. function FogExp2(color, density) {
  15211. Object.defineProperty(this, 'isFogExp2', {
  15212. value: true
  15213. });
  15214. this.name = '';
  15215. this.color = new Color(color);
  15216. this.density = density !== undefined ? density : 0.00025;
  15217. }
  15218. var _proto = FogExp2.prototype;
  15219. _proto.clone = function clone() {
  15220. return new FogExp2(this.color, this.density);
  15221. };
  15222. _proto.toJSON = function toJSON()
  15223. /* meta */
  15224. {
  15225. return {
  15226. type: 'FogExp2',
  15227. color: this.color.getHex(),
  15228. density: this.density
  15229. };
  15230. };
  15231. return FogExp2;
  15232. }();
  15233. var Fog = /*#__PURE__*/function () {
  15234. function Fog(color, near, far) {
  15235. Object.defineProperty(this, 'isFog', {
  15236. value: true
  15237. });
  15238. this.name = '';
  15239. this.color = new Color(color);
  15240. this.near = near !== undefined ? near : 1;
  15241. this.far = far !== undefined ? far : 1000;
  15242. }
  15243. var _proto = Fog.prototype;
  15244. _proto.clone = function clone() {
  15245. return new Fog(this.color, this.near, this.far);
  15246. };
  15247. _proto.toJSON = function toJSON()
  15248. /* meta */
  15249. {
  15250. return {
  15251. type: 'Fog',
  15252. color: this.color.getHex(),
  15253. near: this.near,
  15254. far: this.far
  15255. };
  15256. };
  15257. return Fog;
  15258. }();
  15259. var Scene = /*#__PURE__*/function (_Object3D) {
  15260. _inheritsLoose(Scene, _Object3D);
  15261. function Scene() {
  15262. var _this;
  15263. _this = _Object3D.call(this) || this;
  15264. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15265. value: true
  15266. });
  15267. _this.type = 'Scene';
  15268. _this.background = null;
  15269. _this.environment = null;
  15270. _this.fog = null;
  15271. _this.overrideMaterial = null;
  15272. _this.autoUpdate = true; // checked by the renderer
  15273. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15274. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15275. detail: _assertThisInitialized(_this)
  15276. })); // eslint-disable-line no-undef
  15277. }
  15278. return _this;
  15279. }
  15280. var _proto = Scene.prototype;
  15281. _proto.copy = function copy(source, recursive) {
  15282. _Object3D.prototype.copy.call(this, source, recursive);
  15283. if (source.background !== null) this.background = source.background.clone();
  15284. if (source.environment !== null) this.environment = source.environment.clone();
  15285. if (source.fog !== null) this.fog = source.fog.clone();
  15286. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15287. this.autoUpdate = source.autoUpdate;
  15288. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15289. return this;
  15290. };
  15291. _proto.toJSON = function toJSON(meta) {
  15292. var data = _Object3D.prototype.toJSON.call(this, meta);
  15293. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15294. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15295. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15296. return data;
  15297. };
  15298. return Scene;
  15299. }(Object3D);
  15300. function InterleavedBuffer(array, stride) {
  15301. this.array = array;
  15302. this.stride = stride;
  15303. this.count = array !== undefined ? array.length / stride : 0;
  15304. this.usage = StaticDrawUsage;
  15305. this.updateRange = {
  15306. offset: 0,
  15307. count: -1
  15308. };
  15309. this.version = 0;
  15310. this.uuid = MathUtils.generateUUID();
  15311. }
  15312. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15313. set: function set(value) {
  15314. if (value === true) this.version++;
  15315. }
  15316. });
  15317. Object.assign(InterleavedBuffer.prototype, {
  15318. isInterleavedBuffer: true,
  15319. onUploadCallback: function onUploadCallback() {},
  15320. setUsage: function setUsage(value) {
  15321. this.usage = value;
  15322. return this;
  15323. },
  15324. copy: function copy(source) {
  15325. this.array = new source.array.constructor(source.array);
  15326. this.count = source.count;
  15327. this.stride = source.stride;
  15328. this.usage = source.usage;
  15329. return this;
  15330. },
  15331. copyAt: function copyAt(index1, attribute, index2) {
  15332. index1 *= this.stride;
  15333. index2 *= attribute.stride;
  15334. for (var i = 0, l = this.stride; i < l; i++) {
  15335. this.array[index1 + i] = attribute.array[index2 + i];
  15336. }
  15337. return this;
  15338. },
  15339. set: function set(value, offset) {
  15340. if (offset === void 0) {
  15341. offset = 0;
  15342. }
  15343. this.array.set(value, offset);
  15344. return this;
  15345. },
  15346. clone: function clone(data) {
  15347. if (data.arrayBuffers === undefined) {
  15348. data.arrayBuffers = {};
  15349. }
  15350. if (this.array.buffer._uuid === undefined) {
  15351. this.array.buffer._uuid = MathUtils.generateUUID();
  15352. }
  15353. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15354. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15355. }
  15356. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15357. var ib = new InterleavedBuffer(array, this.stride);
  15358. ib.setUsage(this.usage);
  15359. return ib;
  15360. },
  15361. onUpload: function onUpload(callback) {
  15362. this.onUploadCallback = callback;
  15363. return this;
  15364. },
  15365. toJSON: function toJSON(data) {
  15366. if (data.arrayBuffers === undefined) {
  15367. data.arrayBuffers = {};
  15368. } // generate UUID for array buffer if necessary
  15369. if (this.array.buffer._uuid === undefined) {
  15370. this.array.buffer._uuid = MathUtils.generateUUID();
  15371. }
  15372. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15373. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15374. } //
  15375. return {
  15376. uuid: this.uuid,
  15377. buffer: this.array.buffer._uuid,
  15378. type: this.array.constructor.name,
  15379. stride: this.stride
  15380. };
  15381. }
  15382. });
  15383. var _vector$6 = new Vector3();
  15384. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15385. this.name = '';
  15386. this.data = interleavedBuffer;
  15387. this.itemSize = itemSize;
  15388. this.offset = offset;
  15389. this.normalized = normalized === true;
  15390. }
  15391. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15392. count: {
  15393. get: function get() {
  15394. return this.data.count;
  15395. }
  15396. },
  15397. array: {
  15398. get: function get() {
  15399. return this.data.array;
  15400. }
  15401. },
  15402. needsUpdate: {
  15403. set: function set(value) {
  15404. this.data.needsUpdate = value;
  15405. }
  15406. }
  15407. });
  15408. Object.assign(InterleavedBufferAttribute.prototype, {
  15409. isInterleavedBufferAttribute: true,
  15410. applyMatrix4: function applyMatrix4(m) {
  15411. for (var i = 0, l = this.data.count; i < l; i++) {
  15412. _vector$6.x = this.getX(i);
  15413. _vector$6.y = this.getY(i);
  15414. _vector$6.z = this.getZ(i);
  15415. _vector$6.applyMatrix4(m);
  15416. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15417. }
  15418. return this;
  15419. },
  15420. setX: function setX(index, x) {
  15421. this.data.array[index * this.data.stride + this.offset] = x;
  15422. return this;
  15423. },
  15424. setY: function setY(index, y) {
  15425. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15426. return this;
  15427. },
  15428. setZ: function setZ(index, z) {
  15429. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15430. return this;
  15431. },
  15432. setW: function setW(index, w) {
  15433. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15434. return this;
  15435. },
  15436. getX: function getX(index) {
  15437. return this.data.array[index * this.data.stride + this.offset];
  15438. },
  15439. getY: function getY(index) {
  15440. return this.data.array[index * this.data.stride + this.offset + 1];
  15441. },
  15442. getZ: function getZ(index) {
  15443. return this.data.array[index * this.data.stride + this.offset + 2];
  15444. },
  15445. getW: function getW(index) {
  15446. return this.data.array[index * this.data.stride + this.offset + 3];
  15447. },
  15448. setXY: function setXY(index, x, y) {
  15449. index = index * this.data.stride + this.offset;
  15450. this.data.array[index + 0] = x;
  15451. this.data.array[index + 1] = y;
  15452. return this;
  15453. },
  15454. setXYZ: function setXYZ(index, x, y, z) {
  15455. index = index * this.data.stride + this.offset;
  15456. this.data.array[index + 0] = x;
  15457. this.data.array[index + 1] = y;
  15458. this.data.array[index + 2] = z;
  15459. return this;
  15460. },
  15461. setXYZW: function setXYZW(index, x, y, z, w) {
  15462. index = index * this.data.stride + this.offset;
  15463. this.data.array[index + 0] = x;
  15464. this.data.array[index + 1] = y;
  15465. this.data.array[index + 2] = z;
  15466. this.data.array[index + 3] = w;
  15467. return this;
  15468. },
  15469. clone: function clone(data) {
  15470. if (data === undefined) {
  15471. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15472. var array = [];
  15473. for (var i = 0; i < this.count; i++) {
  15474. var index = i * this.data.stride + this.offset;
  15475. for (var j = 0; j < this.itemSize; j++) {
  15476. array.push(this.data.array[index + j]);
  15477. }
  15478. }
  15479. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15480. } else {
  15481. if (data.interleavedBuffers === undefined) {
  15482. data.interleavedBuffers = {};
  15483. }
  15484. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15485. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15486. }
  15487. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15488. }
  15489. },
  15490. toJSON: function toJSON(data) {
  15491. if (data === undefined) {
  15492. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15493. var array = [];
  15494. for (var i = 0; i < this.count; i++) {
  15495. var index = i * this.data.stride + this.offset;
  15496. for (var j = 0; j < this.itemSize; j++) {
  15497. array.push(this.data.array[index + j]);
  15498. }
  15499. } // deinterleave data and save it as an ordinary buffer attribute for now
  15500. return {
  15501. itemSize: this.itemSize,
  15502. type: this.array.constructor.name,
  15503. array: array,
  15504. normalized: this.normalized
  15505. };
  15506. } else {
  15507. // save as true interlaved attribtue
  15508. if (data.interleavedBuffers === undefined) {
  15509. data.interleavedBuffers = {};
  15510. }
  15511. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15512. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15513. }
  15514. return {
  15515. isInterleavedBufferAttribute: true,
  15516. itemSize: this.itemSize,
  15517. data: this.data.uuid,
  15518. offset: this.offset,
  15519. normalized: this.normalized
  15520. };
  15521. }
  15522. }
  15523. });
  15524. /**
  15525. * parameters = {
  15526. * color: <hex>,
  15527. * map: new THREE.Texture( <Image> ),
  15528. * alphaMap: new THREE.Texture( <Image> ),
  15529. * rotation: <float>,
  15530. * sizeAttenuation: <bool>
  15531. * }
  15532. */
  15533. function SpriteMaterial(parameters) {
  15534. Material.call(this);
  15535. this.type = 'SpriteMaterial';
  15536. this.color = new Color(0xffffff);
  15537. this.map = null;
  15538. this.alphaMap = null;
  15539. this.rotation = 0;
  15540. this.sizeAttenuation = true;
  15541. this.transparent = true;
  15542. this.setValues(parameters);
  15543. }
  15544. SpriteMaterial.prototype = Object.create(Material.prototype);
  15545. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15546. SpriteMaterial.prototype.isSpriteMaterial = true;
  15547. SpriteMaterial.prototype.copy = function (source) {
  15548. Material.prototype.copy.call(this, source);
  15549. this.color.copy(source.color);
  15550. this.map = source.map;
  15551. this.alphaMap = source.alphaMap;
  15552. this.rotation = source.rotation;
  15553. this.sizeAttenuation = source.sizeAttenuation;
  15554. return this;
  15555. };
  15556. var _geometry;
  15557. var _intersectPoint = new Vector3();
  15558. var _worldScale = new Vector3();
  15559. var _mvPosition = new Vector3();
  15560. var _alignedPosition = new Vector2();
  15561. var _rotatedPosition = new Vector2();
  15562. var _viewWorldMatrix = new Matrix4();
  15563. var _vA$1 = new Vector3();
  15564. var _vB$1 = new Vector3();
  15565. var _vC$1 = new Vector3();
  15566. var _uvA$1 = new Vector2();
  15567. var _uvB$1 = new Vector2();
  15568. var _uvC$1 = new Vector2();
  15569. function Sprite(material) {
  15570. Object3D.call(this);
  15571. this.type = 'Sprite';
  15572. if (_geometry === undefined) {
  15573. _geometry = new BufferGeometry();
  15574. 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]);
  15575. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15576. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15577. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15578. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15579. }
  15580. this.geometry = _geometry;
  15581. this.material = material !== undefined ? material : new SpriteMaterial();
  15582. this.center = new Vector2(0.5, 0.5);
  15583. }
  15584. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15585. constructor: Sprite,
  15586. isSprite: true,
  15587. raycast: function raycast(raycaster, intersects) {
  15588. if (raycaster.camera === null) {
  15589. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15590. }
  15591. _worldScale.setFromMatrixScale(this.matrixWorld);
  15592. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15593. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15594. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15595. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15596. _worldScale.multiplyScalar(-_mvPosition.z);
  15597. }
  15598. var rotation = this.material.rotation;
  15599. var sin, cos;
  15600. if (rotation !== 0) {
  15601. cos = Math.cos(rotation);
  15602. sin = Math.sin(rotation);
  15603. }
  15604. var center = this.center;
  15605. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15606. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15607. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15608. _uvA$1.set(0, 0);
  15609. _uvB$1.set(1, 0);
  15610. _uvC$1.set(1, 1); // check first triangle
  15611. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15612. if (intersect === null) {
  15613. // check second triangle
  15614. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15615. _uvB$1.set(0, 1);
  15616. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15617. if (intersect === null) {
  15618. return;
  15619. }
  15620. }
  15621. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15622. if (distance < raycaster.near || distance > raycaster.far) return;
  15623. intersects.push({
  15624. distance: distance,
  15625. point: _intersectPoint.clone(),
  15626. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15627. face: null,
  15628. object: this
  15629. });
  15630. },
  15631. copy: function copy(source) {
  15632. Object3D.prototype.copy.call(this, source);
  15633. if (source.center !== undefined) this.center.copy(source.center);
  15634. this.material = source.material;
  15635. return this;
  15636. }
  15637. });
  15638. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15639. // compute position in camera space
  15640. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15641. if (sin !== undefined) {
  15642. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15643. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15644. } else {
  15645. _rotatedPosition.copy(_alignedPosition);
  15646. }
  15647. vertexPosition.copy(mvPosition);
  15648. vertexPosition.x += _rotatedPosition.x;
  15649. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15650. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15651. }
  15652. var _v1$4 = new Vector3();
  15653. var _v2$2 = new Vector3();
  15654. function LOD() {
  15655. Object3D.call(this);
  15656. this._currentLevel = 0;
  15657. this.type = 'LOD';
  15658. Object.defineProperties(this, {
  15659. levels: {
  15660. enumerable: true,
  15661. value: []
  15662. }
  15663. });
  15664. this.autoUpdate = true;
  15665. }
  15666. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15667. constructor: LOD,
  15668. isLOD: true,
  15669. copy: function copy(source) {
  15670. Object3D.prototype.copy.call(this, source, false);
  15671. var levels = source.levels;
  15672. for (var i = 0, l = levels.length; i < l; i++) {
  15673. var level = levels[i];
  15674. this.addLevel(level.object.clone(), level.distance);
  15675. }
  15676. this.autoUpdate = source.autoUpdate;
  15677. return this;
  15678. },
  15679. addLevel: function addLevel(object, distance) {
  15680. if (distance === void 0) {
  15681. distance = 0;
  15682. }
  15683. distance = Math.abs(distance);
  15684. var levels = this.levels;
  15685. var l;
  15686. for (l = 0; l < levels.length; l++) {
  15687. if (distance < levels[l].distance) {
  15688. break;
  15689. }
  15690. }
  15691. levels.splice(l, 0, {
  15692. distance: distance,
  15693. object: object
  15694. });
  15695. this.add(object);
  15696. return this;
  15697. },
  15698. getCurrentLevel: function getCurrentLevel() {
  15699. return this._currentLevel;
  15700. },
  15701. getObjectForDistance: function getObjectForDistance(distance) {
  15702. var levels = this.levels;
  15703. if (levels.length > 0) {
  15704. var i, l;
  15705. for (i = 1, l = levels.length; i < l; i++) {
  15706. if (distance < levels[i].distance) {
  15707. break;
  15708. }
  15709. }
  15710. return levels[i - 1].object;
  15711. }
  15712. return null;
  15713. },
  15714. raycast: function raycast(raycaster, intersects) {
  15715. var levels = this.levels;
  15716. if (levels.length > 0) {
  15717. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15718. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15719. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15720. }
  15721. },
  15722. update: function update(camera) {
  15723. var levels = this.levels;
  15724. if (levels.length > 1) {
  15725. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15726. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15727. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15728. levels[0].object.visible = true;
  15729. var i, l;
  15730. for (i = 1, l = levels.length; i < l; i++) {
  15731. if (distance >= levels[i].distance) {
  15732. levels[i - 1].object.visible = false;
  15733. levels[i].object.visible = true;
  15734. } else {
  15735. break;
  15736. }
  15737. }
  15738. this._currentLevel = i - 1;
  15739. for (; i < l; i++) {
  15740. levels[i].object.visible = false;
  15741. }
  15742. }
  15743. },
  15744. toJSON: function toJSON(meta) {
  15745. var data = Object3D.prototype.toJSON.call(this, meta);
  15746. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15747. data.object.levels = [];
  15748. var levels = this.levels;
  15749. for (var i = 0, l = levels.length; i < l; i++) {
  15750. var level = levels[i];
  15751. data.object.levels.push({
  15752. object: level.object.uuid,
  15753. distance: level.distance
  15754. });
  15755. }
  15756. return data;
  15757. }
  15758. });
  15759. function SkinnedMesh(geometry, material) {
  15760. if (geometry && geometry.isGeometry) {
  15761. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15762. }
  15763. Mesh.call(this, geometry, material);
  15764. this.type = 'SkinnedMesh';
  15765. this.bindMode = 'attached';
  15766. this.bindMatrix = new Matrix4();
  15767. this.bindMatrixInverse = new Matrix4();
  15768. }
  15769. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15770. constructor: SkinnedMesh,
  15771. isSkinnedMesh: true,
  15772. copy: function copy(source) {
  15773. Mesh.prototype.copy.call(this, source);
  15774. this.bindMode = source.bindMode;
  15775. this.bindMatrix.copy(source.bindMatrix);
  15776. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15777. this.skeleton = source.skeleton;
  15778. return this;
  15779. },
  15780. bind: function bind(skeleton, bindMatrix) {
  15781. this.skeleton = skeleton;
  15782. if (bindMatrix === undefined) {
  15783. this.updateMatrixWorld(true);
  15784. this.skeleton.calculateInverses();
  15785. bindMatrix = this.matrixWorld;
  15786. }
  15787. this.bindMatrix.copy(bindMatrix);
  15788. this.bindMatrixInverse.copy(bindMatrix).invert();
  15789. },
  15790. pose: function pose() {
  15791. this.skeleton.pose();
  15792. },
  15793. normalizeSkinWeights: function normalizeSkinWeights() {
  15794. var vector = new Vector4();
  15795. var skinWeight = this.geometry.attributes.skinWeight;
  15796. for (var i = 0, l = skinWeight.count; i < l; i++) {
  15797. vector.x = skinWeight.getX(i);
  15798. vector.y = skinWeight.getY(i);
  15799. vector.z = skinWeight.getZ(i);
  15800. vector.w = skinWeight.getW(i);
  15801. var scale = 1.0 / vector.manhattanLength();
  15802. if (scale !== Infinity) {
  15803. vector.multiplyScalar(scale);
  15804. } else {
  15805. vector.set(1, 0, 0, 0); // do something reasonable
  15806. }
  15807. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  15808. }
  15809. },
  15810. updateMatrixWorld: function updateMatrixWorld(force) {
  15811. Mesh.prototype.updateMatrixWorld.call(this, force);
  15812. if (this.bindMode === 'attached') {
  15813. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  15814. } else if (this.bindMode === 'detached') {
  15815. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  15816. } else {
  15817. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  15818. }
  15819. },
  15820. boneTransform: function () {
  15821. var basePosition = new Vector3();
  15822. var skinIndex = new Vector4();
  15823. var skinWeight = new Vector4();
  15824. var vector = new Vector3();
  15825. var matrix = new Matrix4();
  15826. return function (index, target) {
  15827. var skeleton = this.skeleton;
  15828. var geometry = this.geometry;
  15829. skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  15830. skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  15831. basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  15832. target.set(0, 0, 0);
  15833. for (var i = 0; i < 4; i++) {
  15834. var weight = skinWeight.getComponent(i);
  15835. if (weight !== 0) {
  15836. var boneIndex = skinIndex.getComponent(i);
  15837. matrix.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  15838. target.addScaledVector(vector.copy(basePosition).applyMatrix4(matrix), weight);
  15839. }
  15840. }
  15841. return target.applyMatrix4(this.bindMatrixInverse);
  15842. };
  15843. }()
  15844. });
  15845. function Bone() {
  15846. Object3D.call(this);
  15847. this.type = 'Bone';
  15848. }
  15849. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  15850. constructor: Bone,
  15851. isBone: true
  15852. });
  15853. var _offsetMatrix = new Matrix4();
  15854. var _identityMatrix = new Matrix4();
  15855. function Skeleton(bones, boneInverses) {
  15856. if (bones === void 0) {
  15857. bones = [];
  15858. }
  15859. if (boneInverses === void 0) {
  15860. boneInverses = [];
  15861. }
  15862. this.uuid = MathUtils.generateUUID();
  15863. this.bones = bones.slice(0);
  15864. this.boneInverses = boneInverses;
  15865. this.boneMatrices = null;
  15866. this.boneTexture = null;
  15867. this.boneTextureSize = 0;
  15868. this.frame = -1;
  15869. this.init();
  15870. }
  15871. Object.assign(Skeleton.prototype, {
  15872. init: function init() {
  15873. var bones = this.bones;
  15874. var boneInverses = this.boneInverses;
  15875. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  15876. if (boneInverses.length === 0) {
  15877. this.calculateInverses();
  15878. } else {
  15879. // handle special case
  15880. if (bones.length !== boneInverses.length) {
  15881. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  15882. this.boneInverses = [];
  15883. for (var i = 0, il = this.bones.length; i < il; i++) {
  15884. this.boneInverses.push(new Matrix4());
  15885. }
  15886. }
  15887. }
  15888. },
  15889. calculateInverses: function calculateInverses() {
  15890. this.boneInverses.length = 0;
  15891. for (var i = 0, il = this.bones.length; i < il; i++) {
  15892. var inverse = new Matrix4();
  15893. if (this.bones[i]) {
  15894. inverse.copy(this.bones[i].matrixWorld).invert();
  15895. }
  15896. this.boneInverses.push(inverse);
  15897. }
  15898. },
  15899. pose: function pose() {
  15900. // recover the bind-time world matrices
  15901. for (var i = 0, il = this.bones.length; i < il; i++) {
  15902. var bone = this.bones[i];
  15903. if (bone) {
  15904. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  15905. }
  15906. } // compute the local matrices, positions, rotations and scales
  15907. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  15908. var _bone = this.bones[_i];
  15909. if (_bone) {
  15910. if (_bone.parent && _bone.parent.isBone) {
  15911. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  15912. _bone.matrix.multiply(_bone.matrixWorld);
  15913. } else {
  15914. _bone.matrix.copy(_bone.matrixWorld);
  15915. }
  15916. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  15917. }
  15918. }
  15919. },
  15920. update: function update() {
  15921. var bones = this.bones;
  15922. var boneInverses = this.boneInverses;
  15923. var boneMatrices = this.boneMatrices;
  15924. var boneTexture = this.boneTexture; // flatten bone matrices to array
  15925. for (var i = 0, il = bones.length; i < il; i++) {
  15926. // compute the offset between the current and the original transform
  15927. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  15928. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  15929. _offsetMatrix.toArray(boneMatrices, i * 16);
  15930. }
  15931. if (boneTexture !== null) {
  15932. boneTexture.needsUpdate = true;
  15933. }
  15934. },
  15935. clone: function clone() {
  15936. return new Skeleton(this.bones, this.boneInverses);
  15937. },
  15938. getBoneByName: function getBoneByName(name) {
  15939. for (var i = 0, il = this.bones.length; i < il; i++) {
  15940. var bone = this.bones[i];
  15941. if (bone.name === name) {
  15942. return bone;
  15943. }
  15944. }
  15945. return undefined;
  15946. },
  15947. dispose: function dispose() {
  15948. if (this.boneTexture !== null) {
  15949. this.boneTexture.dispose();
  15950. this.boneTexture = null;
  15951. }
  15952. },
  15953. fromJSON: function fromJSON(json, bones) {
  15954. this.uuid = json.uuid;
  15955. for (var i = 0, l = json.bones.length; i < l; i++) {
  15956. var uuid = json.bones[i];
  15957. var bone = bones[uuid];
  15958. if (bone === undefined) {
  15959. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  15960. bone = new Bone();
  15961. }
  15962. this.bones.push(bone);
  15963. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  15964. }
  15965. this.init();
  15966. return this;
  15967. },
  15968. toJSON: function toJSON() {
  15969. var data = {
  15970. metadata: {
  15971. version: 4.5,
  15972. type: 'Skeleton',
  15973. generator: 'Skeleton.toJSON'
  15974. },
  15975. bones: [],
  15976. boneInverses: []
  15977. };
  15978. data.uuid = this.uuid;
  15979. var bones = this.bones;
  15980. var boneInverses = this.boneInverses;
  15981. for (var i = 0, l = bones.length; i < l; i++) {
  15982. var bone = bones[i];
  15983. data.bones.push(bone.uuid);
  15984. var boneInverse = boneInverses[i];
  15985. data.boneInverses.push(boneInverse.toArray());
  15986. }
  15987. return data;
  15988. }
  15989. });
  15990. var _instanceLocalMatrix = new Matrix4();
  15991. var _instanceWorldMatrix = new Matrix4();
  15992. var _instanceIntersects = [];
  15993. var _mesh = new Mesh();
  15994. function InstancedMesh(geometry, material, count) {
  15995. Mesh.call(this, geometry, material);
  15996. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  15997. this.instanceColor = null;
  15998. this.count = count;
  15999. this.frustumCulled = false;
  16000. }
  16001. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16002. constructor: InstancedMesh,
  16003. isInstancedMesh: true,
  16004. copy: function copy(source) {
  16005. Mesh.prototype.copy.call(this, source);
  16006. this.instanceMatrix.copy(source.instanceMatrix);
  16007. this.count = source.count;
  16008. return this;
  16009. },
  16010. getColorAt: function getColorAt(index, color) {
  16011. color.fromArray(this.instanceColor.array, index * 3);
  16012. },
  16013. getMatrixAt: function getMatrixAt(index, matrix) {
  16014. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16015. },
  16016. raycast: function raycast(raycaster, intersects) {
  16017. var matrixWorld = this.matrixWorld;
  16018. var raycastTimes = this.count;
  16019. _mesh.geometry = this.geometry;
  16020. _mesh.material = this.material;
  16021. if (_mesh.material === undefined) return;
  16022. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16023. // calculate the world matrix for each instance
  16024. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16025. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16026. _mesh.matrixWorld = _instanceWorldMatrix;
  16027. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16028. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16029. var intersect = _instanceIntersects[i];
  16030. intersect.instanceId = instanceId;
  16031. intersect.object = this;
  16032. intersects.push(intersect);
  16033. }
  16034. _instanceIntersects.length = 0;
  16035. }
  16036. },
  16037. setColorAt: function setColorAt(index, color) {
  16038. if (this.instanceColor === null) {
  16039. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16040. }
  16041. color.toArray(this.instanceColor.array, index * 3);
  16042. },
  16043. setMatrixAt: function setMatrixAt(index, matrix) {
  16044. matrix.toArray(this.instanceMatrix.array, index * 16);
  16045. },
  16046. updateMorphTargets: function updateMorphTargets() {}
  16047. });
  16048. /**
  16049. * parameters = {
  16050. * color: <hex>,
  16051. * opacity: <float>,
  16052. *
  16053. * linewidth: <float>,
  16054. * linecap: "round",
  16055. * linejoin: "round"
  16056. * }
  16057. */
  16058. function LineBasicMaterial(parameters) {
  16059. Material.call(this);
  16060. this.type = 'LineBasicMaterial';
  16061. this.color = new Color(0xffffff);
  16062. this.linewidth = 1;
  16063. this.linecap = 'round';
  16064. this.linejoin = 'round';
  16065. this.morphTargets = false;
  16066. this.setValues(parameters);
  16067. }
  16068. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16069. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16070. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16071. LineBasicMaterial.prototype.copy = function (source) {
  16072. Material.prototype.copy.call(this, source);
  16073. this.color.copy(source.color);
  16074. this.linewidth = source.linewidth;
  16075. this.linecap = source.linecap;
  16076. this.linejoin = source.linejoin;
  16077. this.morphTargets = source.morphTargets;
  16078. return this;
  16079. };
  16080. var _start = new Vector3();
  16081. var _end = new Vector3();
  16082. var _inverseMatrix$1 = new Matrix4();
  16083. var _ray$1 = new Ray();
  16084. var _sphere$2 = new Sphere();
  16085. function Line(geometry, material, mode) {
  16086. if (mode === 1) {
  16087. console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');
  16088. }
  16089. Object3D.call(this);
  16090. this.type = 'Line';
  16091. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16092. this.material = material !== undefined ? material : new LineBasicMaterial();
  16093. this.updateMorphTargets();
  16094. }
  16095. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16096. constructor: Line,
  16097. isLine: true,
  16098. copy: function copy(source) {
  16099. Object3D.prototype.copy.call(this, source);
  16100. this.material = source.material;
  16101. this.geometry = source.geometry;
  16102. return this;
  16103. },
  16104. computeLineDistances: function computeLineDistances() {
  16105. var geometry = this.geometry;
  16106. if (geometry.isBufferGeometry) {
  16107. // we assume non-indexed geometry
  16108. if (geometry.index === null) {
  16109. var positionAttribute = geometry.attributes.position;
  16110. var lineDistances = [0];
  16111. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16112. _start.fromBufferAttribute(positionAttribute, i - 1);
  16113. _end.fromBufferAttribute(positionAttribute, i);
  16114. lineDistances[i] = lineDistances[i - 1];
  16115. lineDistances[i] += _start.distanceTo(_end);
  16116. }
  16117. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16118. } else {
  16119. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16120. }
  16121. } else if (geometry.isGeometry) {
  16122. var vertices = geometry.vertices;
  16123. var _lineDistances = geometry.lineDistances;
  16124. _lineDistances[0] = 0;
  16125. for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
  16126. _lineDistances[_i] = _lineDistances[_i - 1];
  16127. _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
  16128. }
  16129. }
  16130. return this;
  16131. },
  16132. raycast: function raycast(raycaster, intersects) {
  16133. var geometry = this.geometry;
  16134. var matrixWorld = this.matrixWorld;
  16135. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16136. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16137. _sphere$2.copy(geometry.boundingSphere);
  16138. _sphere$2.applyMatrix4(matrixWorld);
  16139. _sphere$2.radius += threshold;
  16140. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16141. _inverseMatrix$1.copy(matrixWorld).invert();
  16142. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16143. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16144. var localThresholdSq = localThreshold * localThreshold;
  16145. var vStart = new Vector3();
  16146. var vEnd = new Vector3();
  16147. var interSegment = new Vector3();
  16148. var interRay = new Vector3();
  16149. var step = this.isLineSegments ? 2 : 1;
  16150. if (geometry.isBufferGeometry) {
  16151. var index = geometry.index;
  16152. var attributes = geometry.attributes;
  16153. var positionAttribute = attributes.position;
  16154. if (index !== null) {
  16155. var indices = index.array;
  16156. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16157. var a = indices[i];
  16158. var b = indices[i + 1];
  16159. vStart.fromBufferAttribute(positionAttribute, a);
  16160. vEnd.fromBufferAttribute(positionAttribute, b);
  16161. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16162. if (distSq > localThresholdSq) continue;
  16163. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16164. var distance = raycaster.ray.origin.distanceTo(interRay);
  16165. if (distance < raycaster.near || distance > raycaster.far) continue;
  16166. intersects.push({
  16167. distance: distance,
  16168. // What do we want? intersection point on the ray or on the segment??
  16169. // point: raycaster.ray.at( distance ),
  16170. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16171. index: i,
  16172. face: null,
  16173. faceIndex: null,
  16174. object: this
  16175. });
  16176. }
  16177. } else {
  16178. for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
  16179. vStart.fromBufferAttribute(positionAttribute, _i2);
  16180. vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
  16181. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16182. if (_distSq > localThresholdSq) continue;
  16183. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16184. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16185. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16186. intersects.push({
  16187. distance: _distance,
  16188. // What do we want? intersection point on the ray or on the segment??
  16189. // point: raycaster.ray.at( distance ),
  16190. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16191. index: _i2,
  16192. face: null,
  16193. faceIndex: null,
  16194. object: this
  16195. });
  16196. }
  16197. }
  16198. } else if (geometry.isGeometry) {
  16199. var vertices = geometry.vertices;
  16200. var nbVertices = vertices.length;
  16201. for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
  16202. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
  16203. if (_distSq2 > localThresholdSq) continue;
  16204. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16205. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16206. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16207. intersects.push({
  16208. distance: _distance2,
  16209. // What do we want? intersection point on the ray or on the segment??
  16210. // point: raycaster.ray.at( distance ),
  16211. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16212. index: _i3,
  16213. face: null,
  16214. faceIndex: null,
  16215. object: this
  16216. });
  16217. }
  16218. }
  16219. },
  16220. updateMorphTargets: function updateMorphTargets() {
  16221. var geometry = this.geometry;
  16222. if (geometry.isBufferGeometry) {
  16223. var morphAttributes = geometry.morphAttributes;
  16224. var keys = Object.keys(morphAttributes);
  16225. if (keys.length > 0) {
  16226. var morphAttribute = morphAttributes[keys[0]];
  16227. if (morphAttribute !== undefined) {
  16228. this.morphTargetInfluences = [];
  16229. this.morphTargetDictionary = {};
  16230. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16231. var name = morphAttribute[m].name || String(m);
  16232. this.morphTargetInfluences.push(0);
  16233. this.morphTargetDictionary[name] = m;
  16234. }
  16235. }
  16236. }
  16237. } else {
  16238. var morphTargets = geometry.morphTargets;
  16239. if (morphTargets !== undefined && morphTargets.length > 0) {
  16240. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16241. }
  16242. }
  16243. }
  16244. });
  16245. var _start$1 = new Vector3();
  16246. var _end$1 = new Vector3();
  16247. function LineSegments(geometry, material) {
  16248. Line.call(this, geometry, material);
  16249. this.type = 'LineSegments';
  16250. }
  16251. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16252. constructor: LineSegments,
  16253. isLineSegments: true,
  16254. computeLineDistances: function computeLineDistances() {
  16255. var geometry = this.geometry;
  16256. if (geometry.isBufferGeometry) {
  16257. // we assume non-indexed geometry
  16258. if (geometry.index === null) {
  16259. var positionAttribute = geometry.attributes.position;
  16260. var lineDistances = [];
  16261. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16262. _start$1.fromBufferAttribute(positionAttribute, i);
  16263. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16264. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16265. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16266. }
  16267. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16268. } else {
  16269. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16270. }
  16271. } else if (geometry.isGeometry) {
  16272. var vertices = geometry.vertices;
  16273. var _lineDistances = geometry.lineDistances;
  16274. for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
  16275. _start$1.copy(vertices[_i]);
  16276. _end$1.copy(vertices[_i + 1]);
  16277. _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
  16278. _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
  16279. }
  16280. }
  16281. return this;
  16282. }
  16283. });
  16284. function LineLoop(geometry, material) {
  16285. Line.call(this, geometry, material);
  16286. this.type = 'LineLoop';
  16287. }
  16288. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16289. constructor: LineLoop,
  16290. isLineLoop: true
  16291. });
  16292. /**
  16293. * parameters = {
  16294. * color: <hex>,
  16295. * opacity: <float>,
  16296. * map: new THREE.Texture( <Image> ),
  16297. * alphaMap: new THREE.Texture( <Image> ),
  16298. *
  16299. * size: <float>,
  16300. * sizeAttenuation: <bool>
  16301. *
  16302. * morphTargets: <bool>
  16303. * }
  16304. */
  16305. function PointsMaterial(parameters) {
  16306. Material.call(this);
  16307. this.type = 'PointsMaterial';
  16308. this.color = new Color(0xffffff);
  16309. this.map = null;
  16310. this.alphaMap = null;
  16311. this.size = 1;
  16312. this.sizeAttenuation = true;
  16313. this.morphTargets = false;
  16314. this.setValues(parameters);
  16315. }
  16316. PointsMaterial.prototype = Object.create(Material.prototype);
  16317. PointsMaterial.prototype.constructor = PointsMaterial;
  16318. PointsMaterial.prototype.isPointsMaterial = true;
  16319. PointsMaterial.prototype.copy = function (source) {
  16320. Material.prototype.copy.call(this, source);
  16321. this.color.copy(source.color);
  16322. this.map = source.map;
  16323. this.alphaMap = source.alphaMap;
  16324. this.size = source.size;
  16325. this.sizeAttenuation = source.sizeAttenuation;
  16326. this.morphTargets = source.morphTargets;
  16327. return this;
  16328. };
  16329. var _inverseMatrix$2 = new Matrix4();
  16330. var _ray$2 = new Ray();
  16331. var _sphere$3 = new Sphere();
  16332. var _position$1 = new Vector3();
  16333. function Points(geometry, material) {
  16334. Object3D.call(this);
  16335. this.type = 'Points';
  16336. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16337. this.material = material !== undefined ? material : new PointsMaterial();
  16338. this.updateMorphTargets();
  16339. }
  16340. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16341. constructor: Points,
  16342. isPoints: true,
  16343. copy: function copy(source) {
  16344. Object3D.prototype.copy.call(this, source);
  16345. this.material = source.material;
  16346. this.geometry = source.geometry;
  16347. return this;
  16348. },
  16349. raycast: function raycast(raycaster, intersects) {
  16350. var geometry = this.geometry;
  16351. var matrixWorld = this.matrixWorld;
  16352. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16353. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16354. _sphere$3.copy(geometry.boundingSphere);
  16355. _sphere$3.applyMatrix4(matrixWorld);
  16356. _sphere$3.radius += threshold;
  16357. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16358. _inverseMatrix$2.copy(matrixWorld).invert();
  16359. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16360. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16361. var localThresholdSq = localThreshold * localThreshold;
  16362. if (geometry.isBufferGeometry) {
  16363. var index = geometry.index;
  16364. var attributes = geometry.attributes;
  16365. var positionAttribute = attributes.position;
  16366. if (index !== null) {
  16367. var indices = index.array;
  16368. for (var i = 0, il = indices.length; i < il; i++) {
  16369. var a = indices[i];
  16370. _position$1.fromBufferAttribute(positionAttribute, a);
  16371. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16372. }
  16373. } else {
  16374. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16375. _position$1.fromBufferAttribute(positionAttribute, _i);
  16376. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16377. }
  16378. }
  16379. } else {
  16380. var vertices = geometry.vertices;
  16381. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16382. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16383. }
  16384. }
  16385. },
  16386. updateMorphTargets: function updateMorphTargets() {
  16387. var geometry = this.geometry;
  16388. if (geometry.isBufferGeometry) {
  16389. var morphAttributes = geometry.morphAttributes;
  16390. var keys = Object.keys(morphAttributes);
  16391. if (keys.length > 0) {
  16392. var morphAttribute = morphAttributes[keys[0]];
  16393. if (morphAttribute !== undefined) {
  16394. this.morphTargetInfluences = [];
  16395. this.morphTargetDictionary = {};
  16396. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16397. var name = morphAttribute[m].name || String(m);
  16398. this.morphTargetInfluences.push(0);
  16399. this.morphTargetDictionary[name] = m;
  16400. }
  16401. }
  16402. }
  16403. } else {
  16404. var morphTargets = geometry.morphTargets;
  16405. if (morphTargets !== undefined && morphTargets.length > 0) {
  16406. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16407. }
  16408. }
  16409. }
  16410. });
  16411. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16412. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16413. if (rayPointDistanceSq < localThresholdSq) {
  16414. var intersectPoint = new Vector3();
  16415. _ray$2.closestPointToPoint(point, intersectPoint);
  16416. intersectPoint.applyMatrix4(matrixWorld);
  16417. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16418. if (distance < raycaster.near || distance > raycaster.far) return;
  16419. intersects.push({
  16420. distance: distance,
  16421. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16422. point: intersectPoint,
  16423. index: index,
  16424. face: null,
  16425. object: object
  16426. });
  16427. }
  16428. }
  16429. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16430. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16431. this.format = format !== undefined ? format : RGBFormat;
  16432. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16433. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16434. this.generateMipmaps = false;
  16435. var scope = this;
  16436. function updateVideo() {
  16437. scope.needsUpdate = true;
  16438. video.requestVideoFrameCallback(updateVideo);
  16439. }
  16440. if ('requestVideoFrameCallback' in video) {
  16441. video.requestVideoFrameCallback(updateVideo);
  16442. }
  16443. }
  16444. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16445. constructor: VideoTexture,
  16446. clone: function clone() {
  16447. return new this.constructor(this.image).copy(this);
  16448. },
  16449. isVideoTexture: true,
  16450. update: function update() {
  16451. var video = this.image;
  16452. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16453. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16454. this.needsUpdate = true;
  16455. }
  16456. }
  16457. });
  16458. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16459. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16460. this.image = {
  16461. width: width,
  16462. height: height
  16463. };
  16464. this.mipmaps = mipmaps; // no flipping for cube textures
  16465. // (also flipping doesn't work for compressed textures )
  16466. this.flipY = false; // can't generate mipmaps for compressed textures
  16467. // mips must be embedded in DDS files
  16468. this.generateMipmaps = false;
  16469. }
  16470. CompressedTexture.prototype = Object.create(Texture.prototype);
  16471. CompressedTexture.prototype.constructor = CompressedTexture;
  16472. CompressedTexture.prototype.isCompressedTexture = true;
  16473. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16474. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16475. this.needsUpdate = true;
  16476. }
  16477. CanvasTexture.prototype = Object.create(Texture.prototype);
  16478. CanvasTexture.prototype.constructor = CanvasTexture;
  16479. CanvasTexture.prototype.isCanvasTexture = true;
  16480. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16481. format = format !== undefined ? format : DepthFormat;
  16482. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16483. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16484. }
  16485. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16486. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16487. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16488. this.image = {
  16489. width: width,
  16490. height: height
  16491. };
  16492. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16493. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16494. this.flipY = false;
  16495. this.generateMipmaps = false;
  16496. }
  16497. DepthTexture.prototype = Object.create(Texture.prototype);
  16498. DepthTexture.prototype.constructor = DepthTexture;
  16499. DepthTexture.prototype.isDepthTexture = true;
  16500. var _geometryId = 0; // Geometry uses even numbers as Id
  16501. var _m1$3 = new Matrix4();
  16502. var _obj$1 = new Object3D();
  16503. var _offset$1 = new Vector3();
  16504. function Geometry() {
  16505. Object.defineProperty(this, 'id', {
  16506. value: _geometryId += 2
  16507. });
  16508. this.uuid = MathUtils.generateUUID();
  16509. this.name = '';
  16510. this.type = 'Geometry';
  16511. this.vertices = [];
  16512. this.colors = [];
  16513. this.faces = [];
  16514. this.faceVertexUvs = [[]];
  16515. this.morphTargets = [];
  16516. this.morphNormals = [];
  16517. this.skinWeights = [];
  16518. this.skinIndices = [];
  16519. this.lineDistances = [];
  16520. this.boundingBox = null;
  16521. this.boundingSphere = null; // update flags
  16522. this.elementsNeedUpdate = false;
  16523. this.verticesNeedUpdate = false;
  16524. this.uvsNeedUpdate = false;
  16525. this.normalsNeedUpdate = false;
  16526. this.colorsNeedUpdate = false;
  16527. this.lineDistancesNeedUpdate = false;
  16528. this.groupsNeedUpdate = false;
  16529. }
  16530. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16531. constructor: Geometry,
  16532. isGeometry: true,
  16533. applyMatrix4: function applyMatrix4(matrix) {
  16534. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16535. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16536. var vertex = this.vertices[i];
  16537. vertex.applyMatrix4(matrix);
  16538. }
  16539. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16540. var face = this.faces[_i];
  16541. face.normal.applyMatrix3(normalMatrix).normalize();
  16542. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16543. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16544. }
  16545. }
  16546. if (this.boundingBox !== null) {
  16547. this.computeBoundingBox();
  16548. }
  16549. if (this.boundingSphere !== null) {
  16550. this.computeBoundingSphere();
  16551. }
  16552. this.verticesNeedUpdate = true;
  16553. this.normalsNeedUpdate = true;
  16554. return this;
  16555. },
  16556. rotateX: function rotateX(angle) {
  16557. // rotate geometry around world x-axis
  16558. _m1$3.makeRotationX(angle);
  16559. this.applyMatrix4(_m1$3);
  16560. return this;
  16561. },
  16562. rotateY: function rotateY(angle) {
  16563. // rotate geometry around world y-axis
  16564. _m1$3.makeRotationY(angle);
  16565. this.applyMatrix4(_m1$3);
  16566. return this;
  16567. },
  16568. rotateZ: function rotateZ(angle) {
  16569. // rotate geometry around world z-axis
  16570. _m1$3.makeRotationZ(angle);
  16571. this.applyMatrix4(_m1$3);
  16572. return this;
  16573. },
  16574. translate: function translate(x, y, z) {
  16575. // translate geometry
  16576. _m1$3.makeTranslation(x, y, z);
  16577. this.applyMatrix4(_m1$3);
  16578. return this;
  16579. },
  16580. scale: function scale(x, y, z) {
  16581. // scale geometry
  16582. _m1$3.makeScale(x, y, z);
  16583. this.applyMatrix4(_m1$3);
  16584. return this;
  16585. },
  16586. lookAt: function lookAt(vector) {
  16587. _obj$1.lookAt(vector);
  16588. _obj$1.updateMatrix();
  16589. this.applyMatrix4(_obj$1.matrix);
  16590. return this;
  16591. },
  16592. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16593. var scope = this;
  16594. var index = geometry.index !== null ? geometry.index : undefined;
  16595. var attributes = geometry.attributes;
  16596. if (attributes.position === undefined) {
  16597. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16598. return this;
  16599. }
  16600. var position = attributes.position;
  16601. var normal = attributes.normal;
  16602. var color = attributes.color;
  16603. var uv = attributes.uv;
  16604. var uv2 = attributes.uv2;
  16605. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16606. for (var i = 0; i < position.count; i++) {
  16607. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16608. if (color !== undefined) {
  16609. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16610. }
  16611. }
  16612. function addFace(a, b, c, materialIndex) {
  16613. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16614. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16615. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16616. scope.faces.push(face);
  16617. if (uv !== undefined) {
  16618. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16619. }
  16620. if (uv2 !== undefined) {
  16621. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16622. }
  16623. }
  16624. var groups = geometry.groups;
  16625. if (groups.length > 0) {
  16626. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16627. var group = groups[_i2];
  16628. var start = group.start;
  16629. var count = group.count;
  16630. for (var j = start, jl = start + count; j < jl; j += 3) {
  16631. if (index !== undefined) {
  16632. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16633. } else {
  16634. addFace(j, j + 1, j + 2, group.materialIndex);
  16635. }
  16636. }
  16637. }
  16638. } else {
  16639. if (index !== undefined) {
  16640. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16641. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16642. }
  16643. } else {
  16644. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16645. addFace(_i4, _i4 + 1, _i4 + 2);
  16646. }
  16647. }
  16648. }
  16649. this.computeFaceNormals();
  16650. if (geometry.boundingBox !== null) {
  16651. this.boundingBox = geometry.boundingBox.clone();
  16652. }
  16653. if (geometry.boundingSphere !== null) {
  16654. this.boundingSphere = geometry.boundingSphere.clone();
  16655. }
  16656. return this;
  16657. },
  16658. center: function center() {
  16659. this.computeBoundingBox();
  16660. this.boundingBox.getCenter(_offset$1).negate();
  16661. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16662. return this;
  16663. },
  16664. normalize: function normalize() {
  16665. this.computeBoundingSphere();
  16666. var center = this.boundingSphere.center;
  16667. var radius = this.boundingSphere.radius;
  16668. var s = radius === 0 ? 1 : 1.0 / radius;
  16669. var matrix = new Matrix4();
  16670. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16671. this.applyMatrix4(matrix);
  16672. return this;
  16673. },
  16674. computeFaceNormals: function computeFaceNormals() {
  16675. var cb = new Vector3(),
  16676. ab = new Vector3();
  16677. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16678. var face = this.faces[f];
  16679. var vA = this.vertices[face.a];
  16680. var vB = this.vertices[face.b];
  16681. var vC = this.vertices[face.c];
  16682. cb.subVectors(vC, vB);
  16683. ab.subVectors(vA, vB);
  16684. cb.cross(ab);
  16685. cb.normalize();
  16686. face.normal.copy(cb);
  16687. }
  16688. },
  16689. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16690. if (areaWeighted === void 0) {
  16691. areaWeighted = true;
  16692. }
  16693. var vertices = new Array(this.vertices.length);
  16694. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16695. vertices[v] = new Vector3();
  16696. }
  16697. if (areaWeighted) {
  16698. // vertex normals weighted by triangle areas
  16699. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16700. var cb = new Vector3(),
  16701. ab = new Vector3();
  16702. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16703. var face = this.faces[f];
  16704. var vA = this.vertices[face.a];
  16705. var vB = this.vertices[face.b];
  16706. var vC = this.vertices[face.c];
  16707. cb.subVectors(vC, vB);
  16708. ab.subVectors(vA, vB);
  16709. cb.cross(ab);
  16710. vertices[face.a].add(cb);
  16711. vertices[face.b].add(cb);
  16712. vertices[face.c].add(cb);
  16713. }
  16714. } else {
  16715. this.computeFaceNormals();
  16716. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16717. var _face = this.faces[_f];
  16718. vertices[_face.a].add(_face.normal);
  16719. vertices[_face.b].add(_face.normal);
  16720. vertices[_face.c].add(_face.normal);
  16721. }
  16722. }
  16723. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16724. vertices[_v].normalize();
  16725. }
  16726. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16727. var _face2 = this.faces[_f2];
  16728. var vertexNormals = _face2.vertexNormals;
  16729. if (vertexNormals.length === 3) {
  16730. vertexNormals[0].copy(vertices[_face2.a]);
  16731. vertexNormals[1].copy(vertices[_face2.b]);
  16732. vertexNormals[2].copy(vertices[_face2.c]);
  16733. } else {
  16734. vertexNormals[0] = vertices[_face2.a].clone();
  16735. vertexNormals[1] = vertices[_face2.b].clone();
  16736. vertexNormals[2] = vertices[_face2.c].clone();
  16737. }
  16738. }
  16739. if (this.faces.length > 0) {
  16740. this.normalsNeedUpdate = true;
  16741. }
  16742. },
  16743. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16744. this.computeFaceNormals();
  16745. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16746. var face = this.faces[f];
  16747. var vertexNormals = face.vertexNormals;
  16748. if (vertexNormals.length === 3) {
  16749. vertexNormals[0].copy(face.normal);
  16750. vertexNormals[1].copy(face.normal);
  16751. vertexNormals[2].copy(face.normal);
  16752. } else {
  16753. vertexNormals[0] = face.normal.clone();
  16754. vertexNormals[1] = face.normal.clone();
  16755. vertexNormals[2] = face.normal.clone();
  16756. }
  16757. }
  16758. if (this.faces.length > 0) {
  16759. this.normalsNeedUpdate = true;
  16760. }
  16761. },
  16762. computeMorphNormals: function computeMorphNormals() {
  16763. // save original normals
  16764. // - create temp variables on first access
  16765. // otherwise just copy (for faster repeated calls)
  16766. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16767. var face = this.faces[f];
  16768. if (!face.__originalFaceNormal) {
  16769. face.__originalFaceNormal = face.normal.clone();
  16770. } else {
  16771. face.__originalFaceNormal.copy(face.normal);
  16772. }
  16773. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16774. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16775. if (!face.__originalVertexNormals[i]) {
  16776. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16777. } else {
  16778. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16779. }
  16780. }
  16781. } // use temp geometry to compute face and vertex normals for each morph
  16782. var tmpGeo = new Geometry();
  16783. tmpGeo.faces = this.faces;
  16784. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  16785. // create on first access
  16786. if (!this.morphNormals[_i5]) {
  16787. this.morphNormals[_i5] = {};
  16788. this.morphNormals[_i5].faceNormals = [];
  16789. this.morphNormals[_i5].vertexNormals = [];
  16790. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  16791. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  16792. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  16793. var faceNormal = new Vector3();
  16794. var vertexNormals = {
  16795. a: new Vector3(),
  16796. b: new Vector3(),
  16797. c: new Vector3()
  16798. };
  16799. dstNormalsFace.push(faceNormal);
  16800. dstNormalsVertex.push(vertexNormals);
  16801. }
  16802. }
  16803. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  16804. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  16805. tmpGeo.computeFaceNormals();
  16806. tmpGeo.computeVertexNormals(); // store morph normals
  16807. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  16808. var _face3 = this.faces[_f4];
  16809. var _faceNormal = morphNormals.faceNormals[_f4];
  16810. var _vertexNormals = morphNormals.vertexNormals[_f4];
  16811. _faceNormal.copy(_face3.normal);
  16812. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  16813. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  16814. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  16815. }
  16816. } // restore original normals
  16817. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  16818. var _face4 = this.faces[_f5];
  16819. _face4.normal = _face4.__originalFaceNormal;
  16820. _face4.vertexNormals = _face4.__originalVertexNormals;
  16821. }
  16822. },
  16823. computeBoundingBox: function computeBoundingBox() {
  16824. if (this.boundingBox === null) {
  16825. this.boundingBox = new Box3();
  16826. }
  16827. this.boundingBox.setFromPoints(this.vertices);
  16828. },
  16829. computeBoundingSphere: function computeBoundingSphere() {
  16830. if (this.boundingSphere === null) {
  16831. this.boundingSphere = new Sphere();
  16832. }
  16833. this.boundingSphere.setFromPoints(this.vertices);
  16834. },
  16835. merge: function merge(geometry, matrix, materialIndexOffset) {
  16836. if (materialIndexOffset === void 0) {
  16837. materialIndexOffset = 0;
  16838. }
  16839. if (!(geometry && geometry.isGeometry)) {
  16840. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  16841. return;
  16842. }
  16843. var normalMatrix;
  16844. var vertexOffset = this.vertices.length,
  16845. vertices1 = this.vertices,
  16846. vertices2 = geometry.vertices,
  16847. faces1 = this.faces,
  16848. faces2 = geometry.faces,
  16849. colors1 = this.colors,
  16850. colors2 = geometry.colors;
  16851. if (matrix !== undefined) {
  16852. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16853. } // vertices
  16854. for (var i = 0, il = vertices2.length; i < il; i++) {
  16855. var vertex = vertices2[i];
  16856. var vertexCopy = vertex.clone();
  16857. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  16858. vertices1.push(vertexCopy);
  16859. } // colors
  16860. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  16861. colors1.push(colors2[_i6].clone());
  16862. } // faces
  16863. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  16864. var face = faces2[_i7];
  16865. var normal = void 0,
  16866. color = void 0;
  16867. var faceVertexNormals = face.vertexNormals,
  16868. faceVertexColors = face.vertexColors;
  16869. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  16870. faceCopy.normal.copy(face.normal);
  16871. if (normalMatrix !== undefined) {
  16872. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  16873. }
  16874. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  16875. normal = faceVertexNormals[j].clone();
  16876. if (normalMatrix !== undefined) {
  16877. normal.applyMatrix3(normalMatrix).normalize();
  16878. }
  16879. faceCopy.vertexNormals.push(normal);
  16880. }
  16881. faceCopy.color.copy(face.color);
  16882. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  16883. color = faceVertexColors[_j];
  16884. faceCopy.vertexColors.push(color.clone());
  16885. }
  16886. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  16887. faces1.push(faceCopy);
  16888. } // uvs
  16889. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  16890. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  16891. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  16892. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  16893. var uvs2 = faceVertexUvs2[_j2],
  16894. uvsCopy = [];
  16895. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  16896. uvsCopy.push(uvs2[k].clone());
  16897. }
  16898. this.faceVertexUvs[_i8].push(uvsCopy);
  16899. }
  16900. }
  16901. },
  16902. mergeMesh: function mergeMesh(mesh) {
  16903. if (!(mesh && mesh.isMesh)) {
  16904. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  16905. return;
  16906. }
  16907. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  16908. this.merge(mesh.geometry, mesh.matrix);
  16909. },
  16910. /*
  16911. * Checks for duplicate vertices with hashmap.
  16912. * Duplicated vertices are removed
  16913. * and faces' vertices are updated.
  16914. */
  16915. mergeVertices: function mergeVertices(precisionPoints) {
  16916. if (precisionPoints === void 0) {
  16917. precisionPoints = 4;
  16918. }
  16919. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  16920. var unique = [],
  16921. changes = [];
  16922. var precision = Math.pow(10, precisionPoints);
  16923. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16924. var v = this.vertices[i];
  16925. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  16926. if (verticesMap[key] === undefined) {
  16927. verticesMap[key] = i;
  16928. unique.push(this.vertices[i]);
  16929. changes[i] = unique.length - 1;
  16930. } else {
  16931. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  16932. changes[i] = changes[verticesMap[key]];
  16933. }
  16934. } // if faces are completely degenerate after merging vertices, we
  16935. // have to remove them from the geometry.
  16936. var faceIndicesToRemove = [];
  16937. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  16938. var face = this.faces[_i9];
  16939. face.a = changes[face.a];
  16940. face.b = changes[face.b];
  16941. face.c = changes[face.c];
  16942. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  16943. // we have to remove the face as nothing can be saved
  16944. for (var n = 0; n < 3; n++) {
  16945. if (indices[n] === indices[(n + 1) % 3]) {
  16946. faceIndicesToRemove.push(_i9);
  16947. break;
  16948. }
  16949. }
  16950. }
  16951. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  16952. var idx = faceIndicesToRemove[_i10];
  16953. this.faces.splice(idx, 1);
  16954. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  16955. this.faceVertexUvs[j].splice(idx, 1);
  16956. }
  16957. } // Use unique set of vertices
  16958. var diff = this.vertices.length - unique.length;
  16959. this.vertices = unique;
  16960. return diff;
  16961. },
  16962. setFromPoints: function setFromPoints(points) {
  16963. this.vertices = [];
  16964. for (var i = 0, l = points.length; i < l; i++) {
  16965. var point = points[i];
  16966. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  16967. }
  16968. return this;
  16969. },
  16970. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  16971. var faces = this.faces;
  16972. var length = faces.length; // tag faces
  16973. for (var i = 0; i < length; i++) {
  16974. faces[i]._id = i;
  16975. } // sort faces
  16976. function materialIndexSort(a, b) {
  16977. return a.materialIndex - b.materialIndex;
  16978. }
  16979. faces.sort(materialIndexSort); // sort uvs
  16980. var uvs1 = this.faceVertexUvs[0];
  16981. var uvs2 = this.faceVertexUvs[1];
  16982. var newUvs1, newUvs2;
  16983. if (uvs1 && uvs1.length === length) newUvs1 = [];
  16984. if (uvs2 && uvs2.length === length) newUvs2 = [];
  16985. for (var _i11 = 0; _i11 < length; _i11++) {
  16986. var id = faces[_i11]._id;
  16987. if (newUvs1) newUvs1.push(uvs1[id]);
  16988. if (newUvs2) newUvs2.push(uvs2[id]);
  16989. }
  16990. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  16991. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  16992. },
  16993. toJSON: function toJSON() {
  16994. var data = {
  16995. metadata: {
  16996. version: 4.5,
  16997. type: 'Geometry',
  16998. generator: 'Geometry.toJSON'
  16999. }
  17000. }; // standard Geometry serialization
  17001. data.uuid = this.uuid;
  17002. data.type = this.type;
  17003. if (this.name !== '') data.name = this.name;
  17004. if (this.parameters !== undefined) {
  17005. var parameters = this.parameters;
  17006. for (var key in parameters) {
  17007. if (parameters[key] !== undefined) data[key] = parameters[key];
  17008. }
  17009. return data;
  17010. }
  17011. var vertices = [];
  17012. for (var i = 0; i < this.vertices.length; i++) {
  17013. var vertex = this.vertices[i];
  17014. vertices.push(vertex.x, vertex.y, vertex.z);
  17015. }
  17016. var faces = [];
  17017. var normals = [];
  17018. var normalsHash = {};
  17019. var colors = [];
  17020. var colorsHash = {};
  17021. var uvs = [];
  17022. var uvsHash = {};
  17023. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  17024. var face = this.faces[_i12];
  17025. var hasMaterial = true;
  17026. var hasFaceUv = false; // deprecated
  17027. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  17028. var hasFaceNormal = face.normal.length() > 0;
  17029. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  17030. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  17031. var hasFaceVertexColor = face.vertexColors.length > 0;
  17032. var faceType = 0;
  17033. faceType = setBit(faceType, 0, 0); // isQuad
  17034. faceType = setBit(faceType, 1, hasMaterial);
  17035. faceType = setBit(faceType, 2, hasFaceUv);
  17036. faceType = setBit(faceType, 3, hasFaceVertexUv);
  17037. faceType = setBit(faceType, 4, hasFaceNormal);
  17038. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  17039. faceType = setBit(faceType, 6, hasFaceColor);
  17040. faceType = setBit(faceType, 7, hasFaceVertexColor);
  17041. faces.push(faceType);
  17042. faces.push(face.a, face.b, face.c);
  17043. faces.push(face.materialIndex);
  17044. if (hasFaceVertexUv) {
  17045. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  17046. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  17047. }
  17048. if (hasFaceNormal) {
  17049. faces.push(getNormalIndex(face.normal));
  17050. }
  17051. if (hasFaceVertexNormal) {
  17052. var vertexNormals = face.vertexNormals;
  17053. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  17054. }
  17055. if (hasFaceColor) {
  17056. faces.push(getColorIndex(face.color));
  17057. }
  17058. if (hasFaceVertexColor) {
  17059. var vertexColors = face.vertexColors;
  17060. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  17061. }
  17062. }
  17063. function setBit(value, position, enabled) {
  17064. return enabled ? value | 1 << position : value & ~(1 << position);
  17065. }
  17066. function getNormalIndex(normal) {
  17067. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  17068. if (normalsHash[hash] !== undefined) {
  17069. return normalsHash[hash];
  17070. }
  17071. normalsHash[hash] = normals.length / 3;
  17072. normals.push(normal.x, normal.y, normal.z);
  17073. return normalsHash[hash];
  17074. }
  17075. function getColorIndex(color) {
  17076. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  17077. if (colorsHash[hash] !== undefined) {
  17078. return colorsHash[hash];
  17079. }
  17080. colorsHash[hash] = colors.length;
  17081. colors.push(color.getHex());
  17082. return colorsHash[hash];
  17083. }
  17084. function getUvIndex(uv) {
  17085. var hash = uv.x.toString() + uv.y.toString();
  17086. if (uvsHash[hash] !== undefined) {
  17087. return uvsHash[hash];
  17088. }
  17089. uvsHash[hash] = uvs.length / 2;
  17090. uvs.push(uv.x, uv.y);
  17091. return uvsHash[hash];
  17092. }
  17093. data.data = {};
  17094. data.data.vertices = vertices;
  17095. data.data.normals = normals;
  17096. if (colors.length > 0) data.data.colors = colors;
  17097. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  17098. data.data.faces = faces;
  17099. return data;
  17100. },
  17101. clone: function clone() {
  17102. /*
  17103. // Handle primitives
  17104. const parameters = this.parameters;
  17105. if ( parameters !== undefined ) {
  17106. const values = [];
  17107. for ( const key in parameters ) {
  17108. values.push( parameters[ key ] );
  17109. }
  17110. const geometry = Object.create( this.constructor.prototype );
  17111. this.constructor.apply( geometry, values );
  17112. return geometry;
  17113. }
  17114. return new this.constructor().copy( this );
  17115. */
  17116. return new Geometry().copy(this);
  17117. },
  17118. copy: function copy(source) {
  17119. // reset
  17120. this.vertices = [];
  17121. this.colors = [];
  17122. this.faces = [];
  17123. this.faceVertexUvs = [[]];
  17124. this.morphTargets = [];
  17125. this.morphNormals = [];
  17126. this.skinWeights = [];
  17127. this.skinIndices = [];
  17128. this.lineDistances = [];
  17129. this.boundingBox = null;
  17130. this.boundingSphere = null; // name
  17131. this.name = source.name; // vertices
  17132. var vertices = source.vertices;
  17133. for (var i = 0, il = vertices.length; i < il; i++) {
  17134. this.vertices.push(vertices[i].clone());
  17135. } // colors
  17136. var colors = source.colors;
  17137. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  17138. this.colors.push(colors[_i13].clone());
  17139. } // faces
  17140. var faces = source.faces;
  17141. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  17142. this.faces.push(faces[_i14].clone());
  17143. } // face vertex uvs
  17144. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  17145. var faceVertexUvs = source.faceVertexUvs[_i15];
  17146. if (this.faceVertexUvs[_i15] === undefined) {
  17147. this.faceVertexUvs[_i15] = [];
  17148. }
  17149. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  17150. var uvs = faceVertexUvs[j],
  17151. uvsCopy = [];
  17152. for (var k = 0, kl = uvs.length; k < kl; k++) {
  17153. var uv = uvs[k];
  17154. uvsCopy.push(uv.clone());
  17155. }
  17156. this.faceVertexUvs[_i15].push(uvsCopy);
  17157. }
  17158. } // morph targets
  17159. var morphTargets = source.morphTargets;
  17160. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  17161. var morphTarget = {};
  17162. morphTarget.name = morphTargets[_i16].name; // vertices
  17163. if (morphTargets[_i16].vertices !== undefined) {
  17164. morphTarget.vertices = [];
  17165. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  17166. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  17167. }
  17168. } // normals
  17169. if (morphTargets[_i16].normals !== undefined) {
  17170. morphTarget.normals = [];
  17171. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  17172. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  17173. }
  17174. }
  17175. this.morphTargets.push(morphTarget);
  17176. } // morph normals
  17177. var morphNormals = source.morphNormals;
  17178. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  17179. var morphNormal = {}; // vertex normals
  17180. if (morphNormals[_i17].vertexNormals !== undefined) {
  17181. morphNormal.vertexNormals = [];
  17182. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17183. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17184. var destVertexNormal = {};
  17185. destVertexNormal.a = srcVertexNormal.a.clone();
  17186. destVertexNormal.b = srcVertexNormal.b.clone();
  17187. destVertexNormal.c = srcVertexNormal.c.clone();
  17188. morphNormal.vertexNormals.push(destVertexNormal);
  17189. }
  17190. } // face normals
  17191. if (morphNormals[_i17].faceNormals !== undefined) {
  17192. morphNormal.faceNormals = [];
  17193. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17194. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17195. }
  17196. }
  17197. this.morphNormals.push(morphNormal);
  17198. } // skin weights
  17199. var skinWeights = source.skinWeights;
  17200. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17201. this.skinWeights.push(skinWeights[_i18].clone());
  17202. } // skin indices
  17203. var skinIndices = source.skinIndices;
  17204. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17205. this.skinIndices.push(skinIndices[_i19].clone());
  17206. } // line distances
  17207. var lineDistances = source.lineDistances;
  17208. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17209. this.lineDistances.push(lineDistances[_i20]);
  17210. } // bounding box
  17211. var boundingBox = source.boundingBox;
  17212. if (boundingBox !== null) {
  17213. this.boundingBox = boundingBox.clone();
  17214. } // bounding sphere
  17215. var boundingSphere = source.boundingSphere;
  17216. if (boundingSphere !== null) {
  17217. this.boundingSphere = boundingSphere.clone();
  17218. } // update flags
  17219. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17220. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17221. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17222. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17223. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17224. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17225. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17226. return this;
  17227. },
  17228. dispose: function dispose() {
  17229. this.dispatchEvent({
  17230. type: 'dispose'
  17231. });
  17232. }
  17233. });
  17234. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17235. _inheritsLoose(BoxGeometry, _Geometry);
  17236. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17237. var _this;
  17238. _this = _Geometry.call(this) || this;
  17239. _this.type = 'BoxGeometry';
  17240. _this.parameters = {
  17241. width: width,
  17242. height: height,
  17243. depth: depth,
  17244. widthSegments: widthSegments,
  17245. heightSegments: heightSegments,
  17246. depthSegments: depthSegments
  17247. };
  17248. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17249. _this.mergeVertices();
  17250. return _this;
  17251. }
  17252. return BoxGeometry;
  17253. }(Geometry);
  17254. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17255. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17256. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17257. var _this;
  17258. _this = _BufferGeometry.call(this) || this;
  17259. _this.type = 'CircleBufferGeometry';
  17260. _this.parameters = {
  17261. radius: radius,
  17262. segments: segments,
  17263. thetaStart: thetaStart,
  17264. thetaLength: thetaLength
  17265. };
  17266. radius = radius || 1;
  17267. segments = segments !== undefined ? Math.max(3, segments) : 8;
  17268. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17269. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17270. var indices = [];
  17271. var vertices = [];
  17272. var normals = [];
  17273. var uvs = []; // helper variables
  17274. var vertex = new Vector3();
  17275. var uv = new Vector2(); // center point
  17276. vertices.push(0, 0, 0);
  17277. normals.push(0, 0, 1);
  17278. uvs.push(0.5, 0.5);
  17279. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17280. var segment = thetaStart + s / segments * thetaLength; // vertex
  17281. vertex.x = radius * Math.cos(segment);
  17282. vertex.y = radius * Math.sin(segment);
  17283. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17284. normals.push(0, 0, 1); // uvs
  17285. uv.x = (vertices[i] / radius + 1) / 2;
  17286. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17287. uvs.push(uv.x, uv.y);
  17288. } // indices
  17289. for (var _i = 1; _i <= segments; _i++) {
  17290. indices.push(_i, _i + 1, 0);
  17291. } // build geometry
  17292. _this.setIndex(indices);
  17293. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17294. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17295. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17296. return _this;
  17297. }
  17298. return CircleBufferGeometry;
  17299. }(BufferGeometry);
  17300. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17301. _inheritsLoose(CircleGeometry, _Geometry);
  17302. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17303. var _this;
  17304. _this = _Geometry.call(this) || this;
  17305. _this.type = 'CircleGeometry';
  17306. _this.parameters = {
  17307. radius: radius,
  17308. segments: segments,
  17309. thetaStart: thetaStart,
  17310. thetaLength: thetaLength
  17311. };
  17312. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17313. _this.mergeVertices();
  17314. return _this;
  17315. }
  17316. return CircleGeometry;
  17317. }(Geometry);
  17318. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17319. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17320. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17321. var _this;
  17322. _this = _BufferGeometry.call(this) || this;
  17323. _this.type = 'CylinderBufferGeometry';
  17324. _this.parameters = {
  17325. radiusTop: radiusTop,
  17326. radiusBottom: radiusBottom,
  17327. height: height,
  17328. radialSegments: radialSegments,
  17329. heightSegments: heightSegments,
  17330. openEnded: openEnded,
  17331. thetaStart: thetaStart,
  17332. thetaLength: thetaLength
  17333. };
  17334. var scope = _assertThisInitialized(_this);
  17335. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17336. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17337. height = height || 1;
  17338. radialSegments = Math.floor(radialSegments) || 8;
  17339. heightSegments = Math.floor(heightSegments) || 1;
  17340. openEnded = openEnded !== undefined ? openEnded : false;
  17341. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17342. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17343. var indices = [];
  17344. var vertices = [];
  17345. var normals = [];
  17346. var uvs = []; // helper variables
  17347. var index = 0;
  17348. var indexArray = [];
  17349. var halfHeight = height / 2;
  17350. var groupStart = 0; // generate geometry
  17351. generateTorso();
  17352. if (openEnded === false) {
  17353. if (radiusTop > 0) generateCap(true);
  17354. if (radiusBottom > 0) generateCap(false);
  17355. } // build geometry
  17356. _this.setIndex(indices);
  17357. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17358. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17359. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17360. function generateTorso() {
  17361. var normal = new Vector3();
  17362. var vertex = new Vector3();
  17363. var groupCount = 0; // this will be used to calculate the normal
  17364. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17365. for (var y = 0; y <= heightSegments; y++) {
  17366. var indexRow = [];
  17367. var v = y / heightSegments; // calculate the radius of the current row
  17368. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17369. for (var x = 0; x <= radialSegments; x++) {
  17370. var u = x / radialSegments;
  17371. var theta = u * thetaLength + thetaStart;
  17372. var sinTheta = Math.sin(theta);
  17373. var cosTheta = Math.cos(theta); // vertex
  17374. vertex.x = radius * sinTheta;
  17375. vertex.y = -v * height + halfHeight;
  17376. vertex.z = radius * cosTheta;
  17377. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17378. normal.set(sinTheta, slope, cosTheta).normalize();
  17379. normals.push(normal.x, normal.y, normal.z); // uv
  17380. uvs.push(u, 1 - v); // save index of vertex in respective row
  17381. indexRow.push(index++);
  17382. } // now save vertices of the row in our index array
  17383. indexArray.push(indexRow);
  17384. } // generate indices
  17385. for (var _x = 0; _x < radialSegments; _x++) {
  17386. for (var _y = 0; _y < heightSegments; _y++) {
  17387. // we use the index array to access the correct indices
  17388. var a = indexArray[_y][_x];
  17389. var b = indexArray[_y + 1][_x];
  17390. var c = indexArray[_y + 1][_x + 1];
  17391. var d = indexArray[_y][_x + 1]; // faces
  17392. indices.push(a, b, d);
  17393. indices.push(b, c, d); // update group counter
  17394. groupCount += 6;
  17395. }
  17396. } // add a group to the geometry. this will ensure multi material support
  17397. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17398. groupStart += groupCount;
  17399. }
  17400. function generateCap(top) {
  17401. // save the index of the first center vertex
  17402. var centerIndexStart = index;
  17403. var uv = new Vector2();
  17404. var vertex = new Vector3();
  17405. var groupCount = 0;
  17406. var radius = top === true ? radiusTop : radiusBottom;
  17407. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17408. // because the geometry needs one set of uvs per face,
  17409. // we must generate a center vertex per face/segment
  17410. for (var x = 1; x <= radialSegments; x++) {
  17411. // vertex
  17412. vertices.push(0, halfHeight * sign, 0); // normal
  17413. normals.push(0, sign, 0); // uv
  17414. uvs.push(0.5, 0.5); // increase index
  17415. index++;
  17416. } // save the index of the last center vertex
  17417. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17418. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17419. var u = _x2 / radialSegments;
  17420. var theta = u * thetaLength + thetaStart;
  17421. var cosTheta = Math.cos(theta);
  17422. var sinTheta = Math.sin(theta); // vertex
  17423. vertex.x = radius * sinTheta;
  17424. vertex.y = halfHeight * sign;
  17425. vertex.z = radius * cosTheta;
  17426. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17427. normals.push(0, sign, 0); // uv
  17428. uv.x = cosTheta * 0.5 + 0.5;
  17429. uv.y = sinTheta * 0.5 * sign + 0.5;
  17430. uvs.push(uv.x, uv.y); // increase index
  17431. index++;
  17432. } // generate indices
  17433. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17434. var c = centerIndexStart + _x3;
  17435. var i = centerIndexEnd + _x3;
  17436. if (top === true) {
  17437. // face top
  17438. indices.push(i, i + 1, c);
  17439. } else {
  17440. // face bottom
  17441. indices.push(i + 1, i, c);
  17442. }
  17443. groupCount += 3;
  17444. } // add a group to the geometry. this will ensure multi material support
  17445. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17446. groupStart += groupCount;
  17447. }
  17448. return _this;
  17449. }
  17450. return CylinderBufferGeometry;
  17451. }(BufferGeometry);
  17452. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17453. _inheritsLoose(CylinderGeometry, _Geometry);
  17454. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17455. var _this;
  17456. _this = _Geometry.call(this) || this;
  17457. _this.type = 'CylinderGeometry';
  17458. _this.parameters = {
  17459. radiusTop: radiusTop,
  17460. radiusBottom: radiusBottom,
  17461. height: height,
  17462. radialSegments: radialSegments,
  17463. heightSegments: heightSegments,
  17464. openEnded: openEnded,
  17465. thetaStart: thetaStart,
  17466. thetaLength: thetaLength
  17467. };
  17468. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17469. _this.mergeVertices();
  17470. return _this;
  17471. }
  17472. return CylinderGeometry;
  17473. }(Geometry);
  17474. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17475. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17476. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17477. var _this;
  17478. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17479. _this.type = 'ConeGeometry';
  17480. _this.parameters = {
  17481. radius: radius,
  17482. height: height,
  17483. radialSegments: radialSegments,
  17484. heightSegments: heightSegments,
  17485. openEnded: openEnded,
  17486. thetaStart: thetaStart,
  17487. thetaLength: thetaLength
  17488. };
  17489. return _this;
  17490. }
  17491. return ConeGeometry;
  17492. }(CylinderGeometry);
  17493. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17494. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17495. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17496. var _this;
  17497. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17498. _this.type = 'ConeBufferGeometry';
  17499. _this.parameters = {
  17500. radius: radius,
  17501. height: height,
  17502. radialSegments: radialSegments,
  17503. heightSegments: heightSegments,
  17504. openEnded: openEnded,
  17505. thetaStart: thetaStart,
  17506. thetaLength: thetaLength
  17507. };
  17508. return _this;
  17509. }
  17510. return ConeBufferGeometry;
  17511. }(CylinderBufferGeometry);
  17512. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17513. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17514. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17515. var _this;
  17516. _this = _BufferGeometry.call(this) || this;
  17517. _this.type = 'PolyhedronBufferGeometry';
  17518. _this.parameters = {
  17519. vertices: vertices,
  17520. indices: indices,
  17521. radius: radius,
  17522. detail: detail
  17523. };
  17524. radius = radius || 1;
  17525. detail = detail || 0; // default buffer data
  17526. var vertexBuffer = [];
  17527. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17528. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17529. applyRadius(radius); // finally, create the uv data
  17530. generateUVs(); // build non-indexed geometry
  17531. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17532. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17533. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17534. if (detail === 0) {
  17535. _this.computeVertexNormals(); // flat normals
  17536. } else {
  17537. _this.normalizeNormals(); // smooth normals
  17538. } // helper functions
  17539. function subdivide(detail) {
  17540. var a = new Vector3();
  17541. var b = new Vector3();
  17542. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17543. for (var i = 0; i < indices.length; i += 3) {
  17544. // get the vertices of the face
  17545. getVertexByIndex(indices[i + 0], a);
  17546. getVertexByIndex(indices[i + 1], b);
  17547. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17548. subdivideFace(a, b, c, detail);
  17549. }
  17550. }
  17551. function subdivideFace(a, b, c, detail) {
  17552. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17553. var v = []; // construct all of the vertices for this subdivision
  17554. for (var i = 0; i <= cols; i++) {
  17555. v[i] = [];
  17556. var aj = a.clone().lerp(c, i / cols);
  17557. var bj = b.clone().lerp(c, i / cols);
  17558. var rows = cols - i;
  17559. for (var j = 0; j <= rows; j++) {
  17560. if (j === 0 && i === cols) {
  17561. v[i][j] = aj;
  17562. } else {
  17563. v[i][j] = aj.clone().lerp(bj, j / rows);
  17564. }
  17565. }
  17566. } // construct all of the faces
  17567. for (var _i = 0; _i < cols; _i++) {
  17568. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17569. var k = Math.floor(_j / 2);
  17570. if (_j % 2 === 0) {
  17571. pushVertex(v[_i][k + 1]);
  17572. pushVertex(v[_i + 1][k]);
  17573. pushVertex(v[_i][k]);
  17574. } else {
  17575. pushVertex(v[_i][k + 1]);
  17576. pushVertex(v[_i + 1][k + 1]);
  17577. pushVertex(v[_i + 1][k]);
  17578. }
  17579. }
  17580. }
  17581. }
  17582. function applyRadius(radius) {
  17583. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17584. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17585. vertex.x = vertexBuffer[i + 0];
  17586. vertex.y = vertexBuffer[i + 1];
  17587. vertex.z = vertexBuffer[i + 2];
  17588. vertex.normalize().multiplyScalar(radius);
  17589. vertexBuffer[i + 0] = vertex.x;
  17590. vertexBuffer[i + 1] = vertex.y;
  17591. vertexBuffer[i + 2] = vertex.z;
  17592. }
  17593. }
  17594. function generateUVs() {
  17595. var vertex = new Vector3();
  17596. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17597. vertex.x = vertexBuffer[i + 0];
  17598. vertex.y = vertexBuffer[i + 1];
  17599. vertex.z = vertexBuffer[i + 2];
  17600. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17601. var v = inclination(vertex) / Math.PI + 0.5;
  17602. uvBuffer.push(u, 1 - v);
  17603. }
  17604. correctUVs();
  17605. correctSeam();
  17606. }
  17607. function correctSeam() {
  17608. // handle case when face straddles the seam, see #3269
  17609. for (var i = 0; i < uvBuffer.length; i += 6) {
  17610. // uv data of a single face
  17611. var x0 = uvBuffer[i + 0];
  17612. var x1 = uvBuffer[i + 2];
  17613. var x2 = uvBuffer[i + 4];
  17614. var max = Math.max(x0, x1, x2);
  17615. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17616. if (max > 0.9 && min < 0.1) {
  17617. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17618. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17619. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17620. }
  17621. }
  17622. }
  17623. function pushVertex(vertex) {
  17624. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17625. }
  17626. function getVertexByIndex(index, vertex) {
  17627. var stride = index * 3;
  17628. vertex.x = vertices[stride + 0];
  17629. vertex.y = vertices[stride + 1];
  17630. vertex.z = vertices[stride + 2];
  17631. }
  17632. function correctUVs() {
  17633. var a = new Vector3();
  17634. var b = new Vector3();
  17635. var c = new Vector3();
  17636. var centroid = new Vector3();
  17637. var uvA = new Vector2();
  17638. var uvB = new Vector2();
  17639. var uvC = new Vector2();
  17640. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17641. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17642. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17643. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17644. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17645. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17646. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17647. centroid.copy(a).add(b).add(c).divideScalar(3);
  17648. var azi = azimuth(centroid);
  17649. correctUV(uvA, j + 0, a, azi);
  17650. correctUV(uvB, j + 2, b, azi);
  17651. correctUV(uvC, j + 4, c, azi);
  17652. }
  17653. }
  17654. function correctUV(uv, stride, vector, azimuth) {
  17655. if (azimuth < 0 && uv.x === 1) {
  17656. uvBuffer[stride] = uv.x - 1;
  17657. }
  17658. if (vector.x === 0 && vector.z === 0) {
  17659. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17660. }
  17661. } // Angle around the Y axis, counter-clockwise when looking from above.
  17662. function azimuth(vector) {
  17663. return Math.atan2(vector.z, -vector.x);
  17664. } // Angle above the XZ plane.
  17665. function inclination(vector) {
  17666. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17667. }
  17668. return _this;
  17669. }
  17670. return PolyhedronBufferGeometry;
  17671. }(BufferGeometry);
  17672. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17673. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17674. function DodecahedronBufferGeometry(radius, detail) {
  17675. var _this;
  17676. var t = (1 + Math.sqrt(5)) / 2;
  17677. var r = 1 / t;
  17678. var vertices = [// (±1, ±1, ±1)
  17679. -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/φ, ±φ)
  17680. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17681. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17682. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17683. 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];
  17684. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17685. _this.type = 'DodecahedronBufferGeometry';
  17686. _this.parameters = {
  17687. radius: radius,
  17688. detail: detail
  17689. };
  17690. return _this;
  17691. }
  17692. return DodecahedronBufferGeometry;
  17693. }(PolyhedronBufferGeometry);
  17694. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17695. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17696. function DodecahedronGeometry(radius, detail) {
  17697. var _this;
  17698. _this = _Geometry.call(this) || this;
  17699. _this.type = 'DodecahedronGeometry';
  17700. _this.parameters = {
  17701. radius: radius,
  17702. detail: detail
  17703. };
  17704. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17705. _this.mergeVertices();
  17706. return _this;
  17707. }
  17708. return DodecahedronGeometry;
  17709. }(Geometry);
  17710. var _v0$2 = new Vector3();
  17711. var _v1$5 = new Vector3();
  17712. var _normal$1 = new Vector3();
  17713. var _triangle = new Triangle();
  17714. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17715. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17716. function EdgesGeometry(geometry, thresholdAngle) {
  17717. var _this;
  17718. _this = _BufferGeometry.call(this) || this;
  17719. _this.type = 'EdgesGeometry';
  17720. _this.parameters = {
  17721. thresholdAngle: thresholdAngle
  17722. };
  17723. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17724. if (geometry.isGeometry) {
  17725. geometry = new BufferGeometry().fromGeometry(geometry);
  17726. }
  17727. var precisionPoints = 4;
  17728. var precision = Math.pow(10, precisionPoints);
  17729. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17730. var indexAttr = geometry.getIndex();
  17731. var positionAttr = geometry.getAttribute('position');
  17732. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17733. var indexArr = [0, 0, 0];
  17734. var vertKeys = ['a', 'b', 'c'];
  17735. var hashes = new Array(3);
  17736. var edgeData = {};
  17737. var vertices = [];
  17738. for (var i = 0; i < indexCount; i += 3) {
  17739. if (indexAttr) {
  17740. indexArr[0] = indexAttr.getX(i);
  17741. indexArr[1] = indexAttr.getX(i + 1);
  17742. indexArr[2] = indexAttr.getX(i + 2);
  17743. } else {
  17744. indexArr[0] = i;
  17745. indexArr[1] = i + 1;
  17746. indexArr[2] = i + 2;
  17747. }
  17748. var a = _triangle.a,
  17749. b = _triangle.b,
  17750. c = _triangle.c;
  17751. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17752. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17753. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17754. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17755. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17756. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17757. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17758. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17759. continue;
  17760. } // iterate over every edge
  17761. for (var j = 0; j < 3; j++) {
  17762. // get the first and next vertex making up the edge
  17763. var jNext = (j + 1) % 3;
  17764. var vecHash0 = hashes[j];
  17765. var vecHash1 = hashes[jNext];
  17766. var v0 = _triangle[vertKeys[j]];
  17767. var v1 = _triangle[vertKeys[jNext]];
  17768. var hash = vecHash0 + "_" + vecHash1;
  17769. var reverseHash = vecHash1 + "_" + vecHash0;
  17770. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17771. // if we found a sibling edge add it into the vertex array if
  17772. // it meets the angle threshold and delete the edge from the map.
  17773. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17774. vertices.push(v0.x, v0.y, v0.z);
  17775. vertices.push(v1.x, v1.y, v1.z);
  17776. }
  17777. edgeData[reverseHash] = null;
  17778. } else if (!(hash in edgeData)) {
  17779. // if we've already got an edge here then skip adding a new one
  17780. edgeData[hash] = {
  17781. index0: indexArr[j],
  17782. index1: indexArr[jNext],
  17783. normal: _normal$1.clone()
  17784. };
  17785. }
  17786. }
  17787. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17788. for (var key in edgeData) {
  17789. if (edgeData[key]) {
  17790. var _edgeData$key = edgeData[key],
  17791. index0 = _edgeData$key.index0,
  17792. index1 = _edgeData$key.index1;
  17793. _v0$2.fromBufferAttribute(positionAttr, index0);
  17794. _v1$5.fromBufferAttribute(positionAttr, index1);
  17795. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17796. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17797. }
  17798. }
  17799. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17800. return _this;
  17801. }
  17802. return EdgesGeometry;
  17803. }(BufferGeometry);
  17804. /**
  17805. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17806. */
  17807. var Earcut = {
  17808. triangulate: function triangulate(data, holeIndices, dim) {
  17809. dim = dim || 2;
  17810. var hasHoles = holeIndices && holeIndices.length;
  17811. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17812. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17813. var triangles = [];
  17814. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17815. var minX, minY, maxX, maxY, x, y, invSize;
  17816. 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
  17817. if (data.length > 80 * dim) {
  17818. minX = maxX = data[0];
  17819. minY = maxY = data[1];
  17820. for (var i = dim; i < outerLen; i += dim) {
  17821. x = data[i];
  17822. y = data[i + 1];
  17823. if (x < minX) minX = x;
  17824. if (y < minY) minY = y;
  17825. if (x > maxX) maxX = x;
  17826. if (y > maxY) maxY = y;
  17827. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17828. invSize = Math.max(maxX - minX, maxY - minY);
  17829. invSize = invSize !== 0 ? 1 / invSize : 0;
  17830. }
  17831. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17832. return triangles;
  17833. }
  17834. }; // create a circular doubly linked list from polygon points in the specified winding order
  17835. function linkedList(data, start, end, dim, clockwise) {
  17836. var i, last;
  17837. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17838. for (i = start; i < end; i += dim) {
  17839. last = insertNode(i, data[i], data[i + 1], last);
  17840. }
  17841. } else {
  17842. for (i = end - dim; i >= start; i -= dim) {
  17843. last = insertNode(i, data[i], data[i + 1], last);
  17844. }
  17845. }
  17846. if (last && equals(last, last.next)) {
  17847. removeNode(last);
  17848. last = last.next;
  17849. }
  17850. return last;
  17851. } // eliminate colinear or duplicate points
  17852. function filterPoints(start, end) {
  17853. if (!start) return start;
  17854. if (!end) end = start;
  17855. var p = start,
  17856. again;
  17857. do {
  17858. again = false;
  17859. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17860. removeNode(p);
  17861. p = end = p.prev;
  17862. if (p === p.next) break;
  17863. again = true;
  17864. } else {
  17865. p = p.next;
  17866. }
  17867. } while (again || p !== end);
  17868. return end;
  17869. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17870. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17871. if (!ear) return; // interlink polygon nodes in z-order
  17872. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17873. var stop = ear,
  17874. prev,
  17875. next; // iterate through ears, slicing them one by one
  17876. while (ear.prev !== ear.next) {
  17877. prev = ear.prev;
  17878. next = ear.next;
  17879. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17880. // cut off the triangle
  17881. triangles.push(prev.i / dim);
  17882. triangles.push(ear.i / dim);
  17883. triangles.push(next.i / dim);
  17884. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17885. ear = next.next;
  17886. stop = next.next;
  17887. continue;
  17888. }
  17889. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17890. if (ear === stop) {
  17891. // try filtering points and slicing again
  17892. if (!pass) {
  17893. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17894. } else if (pass === 1) {
  17895. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17896. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17897. } else if (pass === 2) {
  17898. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17899. }
  17900. break;
  17901. }
  17902. }
  17903. } // check whether a polygon node forms a valid ear with adjacent nodes
  17904. function isEar(ear) {
  17905. var a = ear.prev,
  17906. b = ear,
  17907. c = ear.next;
  17908. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17909. // now make sure we don't have other points inside the potential ear
  17910. var p = ear.next.next;
  17911. while (p !== ear.prev) {
  17912. 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;
  17913. p = p.next;
  17914. }
  17915. return true;
  17916. }
  17917. function isEarHashed(ear, minX, minY, invSize) {
  17918. var a = ear.prev,
  17919. b = ear,
  17920. c = ear.next;
  17921. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17922. // triangle bbox; min & max are calculated like this for speed
  17923. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17924. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17925. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17926. 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;
  17927. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17928. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17929. var p = ear.prevZ,
  17930. n = ear.nextZ; // look for points inside the triangle in both directions
  17931. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17932. 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;
  17933. p = p.prevZ;
  17934. 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;
  17935. n = n.nextZ;
  17936. } // look for remaining points in decreasing z-order
  17937. while (p && p.z >= minZ) {
  17938. 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;
  17939. p = p.prevZ;
  17940. } // look for remaining points in increasing z-order
  17941. while (n && n.z <= maxZ) {
  17942. 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;
  17943. n = n.nextZ;
  17944. }
  17945. return true;
  17946. } // go through all polygon nodes and cure small local self-intersections
  17947. function cureLocalIntersections(start, triangles, dim) {
  17948. var p = start;
  17949. do {
  17950. var a = p.prev,
  17951. b = p.next.next;
  17952. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17953. triangles.push(a.i / dim);
  17954. triangles.push(p.i / dim);
  17955. triangles.push(b.i / dim); // remove two nodes involved
  17956. removeNode(p);
  17957. removeNode(p.next);
  17958. p = start = b;
  17959. }
  17960. p = p.next;
  17961. } while (p !== start);
  17962. return filterPoints(p);
  17963. } // try splitting polygon into two and triangulate them independently
  17964. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17965. // look for a valid diagonal that divides the polygon into two
  17966. var a = start;
  17967. do {
  17968. var b = a.next.next;
  17969. while (b !== a.prev) {
  17970. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17971. // split the polygon in two by the diagonal
  17972. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17973. a = filterPoints(a, a.next);
  17974. c = filterPoints(c, c.next); // run earcut on each half
  17975. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17976. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17977. return;
  17978. }
  17979. b = b.next;
  17980. }
  17981. a = a.next;
  17982. } while (a !== start);
  17983. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17984. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17985. var queue = [];
  17986. var i, len, start, end, list;
  17987. for (i = 0, len = holeIndices.length; i < len; i++) {
  17988. start = holeIndices[i] * dim;
  17989. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17990. list = linkedList(data, start, end, dim, false);
  17991. if (list === list.next) list.steiner = true;
  17992. queue.push(getLeftmost(list));
  17993. }
  17994. queue.sort(compareX); // process holes from left to right
  17995. for (i = 0; i < queue.length; i++) {
  17996. eliminateHole(queue[i], outerNode);
  17997. outerNode = filterPoints(outerNode, outerNode.next);
  17998. }
  17999. return outerNode;
  18000. }
  18001. function compareX(a, b) {
  18002. return a.x - b.x;
  18003. } // find a bridge between vertices that connects hole with an outer ring and and link it
  18004. function eliminateHole(hole, outerNode) {
  18005. outerNode = findHoleBridge(hole, outerNode);
  18006. if (outerNode) {
  18007. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  18008. filterPoints(outerNode, outerNode.next);
  18009. filterPoints(b, b.next);
  18010. }
  18011. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18012. function findHoleBridge(hole, outerNode) {
  18013. var p = outerNode;
  18014. var hx = hole.x;
  18015. var hy = hole.y;
  18016. var qx = -Infinity,
  18017. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18018. // segment's endpoint with lesser x will be potential connection point
  18019. do {
  18020. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18021. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18022. if (x <= hx && x > qx) {
  18023. qx = x;
  18024. if (x === hx) {
  18025. if (hy === p.y) return p;
  18026. if (hy === p.next.y) return p.next;
  18027. }
  18028. m = p.x < p.next.x ? p : p.next;
  18029. }
  18030. }
  18031. p = p.next;
  18032. } while (p !== outerNode);
  18033. if (!m) return null;
  18034. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18035. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18036. // if there are no points found, we have a valid connection;
  18037. // otherwise choose the point of the minimum angle with the ray as connection point
  18038. var stop = m,
  18039. mx = m.x,
  18040. my = m.y;
  18041. var tanMin = Infinity,
  18042. tan;
  18043. p = m;
  18044. do {
  18045. 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)) {
  18046. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18047. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18048. m = p;
  18049. tanMin = tan;
  18050. }
  18051. }
  18052. p = p.next;
  18053. } while (p !== stop);
  18054. return m;
  18055. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18056. function sectorContainsSector(m, p) {
  18057. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18058. } // interlink polygon nodes in z-order
  18059. function indexCurve(start, minX, minY, invSize) {
  18060. var p = start;
  18061. do {
  18062. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18063. p.prevZ = p.prev;
  18064. p.nextZ = p.next;
  18065. p = p.next;
  18066. } while (p !== start);
  18067. p.prevZ.nextZ = null;
  18068. p.prevZ = null;
  18069. sortLinked(p);
  18070. } // Simon Tatham's linked list merge sort algorithm
  18071. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18072. function sortLinked(list) {
  18073. var i,
  18074. p,
  18075. q,
  18076. e,
  18077. tail,
  18078. numMerges,
  18079. pSize,
  18080. qSize,
  18081. inSize = 1;
  18082. do {
  18083. p = list;
  18084. list = null;
  18085. tail = null;
  18086. numMerges = 0;
  18087. while (p) {
  18088. numMerges++;
  18089. q = p;
  18090. pSize = 0;
  18091. for (i = 0; i < inSize; i++) {
  18092. pSize++;
  18093. q = q.nextZ;
  18094. if (!q) break;
  18095. }
  18096. qSize = inSize;
  18097. while (pSize > 0 || qSize > 0 && q) {
  18098. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18099. e = p;
  18100. p = p.nextZ;
  18101. pSize--;
  18102. } else {
  18103. e = q;
  18104. q = q.nextZ;
  18105. qSize--;
  18106. }
  18107. if (tail) tail.nextZ = e;else list = e;
  18108. e.prevZ = tail;
  18109. tail = e;
  18110. }
  18111. p = q;
  18112. }
  18113. tail.nextZ = null;
  18114. inSize *= 2;
  18115. } while (numMerges > 1);
  18116. return list;
  18117. } // z-order of a point given coords and inverse of the longer side of data bbox
  18118. function zOrder(x, y, minX, minY, invSize) {
  18119. // coords are transformed into non-negative 15-bit integer range
  18120. x = 32767 * (x - minX) * invSize;
  18121. y = 32767 * (y - minY) * invSize;
  18122. x = (x | x << 8) & 0x00FF00FF;
  18123. x = (x | x << 4) & 0x0F0F0F0F;
  18124. x = (x | x << 2) & 0x33333333;
  18125. x = (x | x << 1) & 0x55555555;
  18126. y = (y | y << 8) & 0x00FF00FF;
  18127. y = (y | y << 4) & 0x0F0F0F0F;
  18128. y = (y | y << 2) & 0x33333333;
  18129. y = (y | y << 1) & 0x55555555;
  18130. return x | y << 1;
  18131. } // find the leftmost node of a polygon ring
  18132. function getLeftmost(start) {
  18133. var p = start,
  18134. leftmost = start;
  18135. do {
  18136. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18137. p = p.next;
  18138. } while (p !== start);
  18139. return leftmost;
  18140. } // check if a point lies within a convex triangle
  18141. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18142. 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;
  18143. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18144. function isValidDiagonal(a, b) {
  18145. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18146. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18147. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18148. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18149. } // signed area of a triangle
  18150. function area(p, q, r) {
  18151. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18152. } // check if two points are equal
  18153. function equals(p1, p2) {
  18154. return p1.x === p2.x && p1.y === p2.y;
  18155. } // check if two segments intersect
  18156. function intersects(p1, q1, p2, q2) {
  18157. var o1 = sign(area(p1, q1, p2));
  18158. var o2 = sign(area(p1, q1, q2));
  18159. var o3 = sign(area(p2, q2, p1));
  18160. var o4 = sign(area(p2, q2, q1));
  18161. if (o1 !== o2 && o3 !== o4) return true; // general case
  18162. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18163. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18164. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18165. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18166. return false;
  18167. } // for collinear points p, q, r, check if point q lies on segment pr
  18168. function onSegment(p, q, r) {
  18169. 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);
  18170. }
  18171. function sign(num) {
  18172. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18173. } // check if a polygon diagonal intersects any polygon segments
  18174. function intersectsPolygon(a, b) {
  18175. var p = a;
  18176. do {
  18177. 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;
  18178. p = p.next;
  18179. } while (p !== a);
  18180. return false;
  18181. } // check if a polygon diagonal is locally inside the polygon
  18182. function locallyInside(a, b) {
  18183. 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;
  18184. } // check if the middle point of a polygon diagonal is inside the polygon
  18185. function middleInside(a, b) {
  18186. var p = a,
  18187. inside = false;
  18188. var px = (a.x + b.x) / 2,
  18189. py = (a.y + b.y) / 2;
  18190. do {
  18191. 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;
  18192. p = p.next;
  18193. } while (p !== a);
  18194. return inside;
  18195. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18196. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18197. function splitPolygon(a, b) {
  18198. var a2 = new Node(a.i, a.x, a.y),
  18199. b2 = new Node(b.i, b.x, b.y),
  18200. an = a.next,
  18201. bp = b.prev;
  18202. a.next = b;
  18203. b.prev = a;
  18204. a2.next = an;
  18205. an.prev = a2;
  18206. b2.next = a2;
  18207. a2.prev = b2;
  18208. bp.next = b2;
  18209. b2.prev = bp;
  18210. return b2;
  18211. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18212. function insertNode(i, x, y, last) {
  18213. var p = new Node(i, x, y);
  18214. if (!last) {
  18215. p.prev = p;
  18216. p.next = p;
  18217. } else {
  18218. p.next = last.next;
  18219. p.prev = last;
  18220. last.next.prev = p;
  18221. last.next = p;
  18222. }
  18223. return p;
  18224. }
  18225. function removeNode(p) {
  18226. p.next.prev = p.prev;
  18227. p.prev.next = p.next;
  18228. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18229. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18230. }
  18231. function Node(i, x, y) {
  18232. // vertex index in coordinates array
  18233. this.i = i; // vertex coordinates
  18234. this.x = x;
  18235. this.y = y; // previous and next vertex nodes in a polygon ring
  18236. this.prev = null;
  18237. this.next = null; // z-order curve value
  18238. this.z = null; // previous and next nodes in z-order
  18239. this.prevZ = null;
  18240. this.nextZ = null; // indicates whether this is a steiner point
  18241. this.steiner = false;
  18242. }
  18243. function signedArea(data, start, end, dim) {
  18244. var sum = 0;
  18245. for (var i = start, j = end - dim; i < end; i += dim) {
  18246. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18247. j = i;
  18248. }
  18249. return sum;
  18250. }
  18251. var ShapeUtils = {
  18252. // calculate area of the contour polygon
  18253. area: function area(contour) {
  18254. var n = contour.length;
  18255. var a = 0.0;
  18256. for (var p = n - 1, q = 0; q < n; p = q++) {
  18257. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18258. }
  18259. return a * 0.5;
  18260. },
  18261. isClockWise: function isClockWise(pts) {
  18262. return ShapeUtils.area(pts) < 0;
  18263. },
  18264. triangulateShape: function triangulateShape(contour, holes) {
  18265. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18266. var holeIndices = []; // array of hole indices
  18267. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18268. removeDupEndPts(contour);
  18269. addContour(vertices, contour); //
  18270. var holeIndex = contour.length;
  18271. holes.forEach(removeDupEndPts);
  18272. for (var i = 0; i < holes.length; i++) {
  18273. holeIndices.push(holeIndex);
  18274. holeIndex += holes[i].length;
  18275. addContour(vertices, holes[i]);
  18276. } //
  18277. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18278. for (var _i = 0; _i < triangles.length; _i += 3) {
  18279. faces.push(triangles.slice(_i, _i + 3));
  18280. }
  18281. return faces;
  18282. }
  18283. };
  18284. function removeDupEndPts(points) {
  18285. var l = points.length;
  18286. if (l > 2 && points[l - 1].equals(points[0])) {
  18287. points.pop();
  18288. }
  18289. }
  18290. function addContour(vertices, contour) {
  18291. for (var i = 0; i < contour.length; i++) {
  18292. vertices.push(contour[i].x);
  18293. vertices.push(contour[i].y);
  18294. }
  18295. }
  18296. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18297. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18298. function ExtrudeBufferGeometry(shapes, options) {
  18299. var _this;
  18300. _this = _BufferGeometry.call(this) || this;
  18301. _this.type = 'ExtrudeBufferGeometry';
  18302. _this.parameters = {
  18303. shapes: shapes,
  18304. options: options
  18305. };
  18306. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18307. var scope = _assertThisInitialized(_this);
  18308. var verticesArray = [];
  18309. var uvArray = [];
  18310. for (var i = 0, l = shapes.length; i < l; i++) {
  18311. var shape = shapes[i];
  18312. addShape(shape);
  18313. } // build geometry
  18314. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18315. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18316. _this.computeVertexNormals(); // functions
  18317. function addShape(shape) {
  18318. var placeholder = []; // options
  18319. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18320. var steps = options.steps !== undefined ? options.steps : 1;
  18321. var depth = options.depth !== undefined ? options.depth : 100;
  18322. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18323. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18324. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18325. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18326. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18327. var extrudePath = options.extrudePath;
  18328. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18329. if (options.amount !== undefined) {
  18330. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18331. depth = options.amount;
  18332. } //
  18333. var extrudePts,
  18334. extrudeByPath = false;
  18335. var splineTube, binormal, normal, position2;
  18336. if (extrudePath) {
  18337. extrudePts = extrudePath.getSpacedPoints(steps);
  18338. extrudeByPath = true;
  18339. bevelEnabled = false; // bevels not supported for path extrusion
  18340. // SETUP TNB variables
  18341. // TODO1 - have a .isClosed in spline?
  18342. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18343. binormal = new Vector3();
  18344. normal = new Vector3();
  18345. position2 = new Vector3();
  18346. } // Safeguards if bevels are not enabled
  18347. if (!bevelEnabled) {
  18348. bevelSegments = 0;
  18349. bevelThickness = 0;
  18350. bevelSize = 0;
  18351. bevelOffset = 0;
  18352. } // Variables initialization
  18353. var shapePoints = shape.extractPoints(curveSegments);
  18354. var vertices = shapePoints.shape;
  18355. var holes = shapePoints.holes;
  18356. var reverse = !ShapeUtils.isClockWise(vertices);
  18357. if (reverse) {
  18358. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18359. for (var h = 0, hl = holes.length; h < hl; h++) {
  18360. var ahole = holes[h];
  18361. if (ShapeUtils.isClockWise(ahole)) {
  18362. holes[h] = ahole.reverse();
  18363. }
  18364. }
  18365. }
  18366. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18367. /* Vertices */
  18368. var contour = vertices; // vertices has all points but contour has only points of circumference
  18369. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18370. var _ahole = holes[_h];
  18371. vertices = vertices.concat(_ahole);
  18372. }
  18373. function scalePt2(pt, vec, size) {
  18374. if (!vec) console.error("THREE.ExtrudeGeometry: vec does not exist");
  18375. return vec.clone().multiplyScalar(size).add(pt);
  18376. }
  18377. var vlen = vertices.length,
  18378. flen = faces.length; // Find directions for point movement
  18379. function getBevelVec(inPt, inPrev, inNext) {
  18380. // computes for inPt the corresponding point inPt' on a new contour
  18381. // shifted by 1 unit (length of normalized vector) to the left
  18382. // if we walk along contour clockwise, this new contour is outside the old one
  18383. //
  18384. // inPt' is the intersection of the two lines parallel to the two
  18385. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18386. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18387. // good reading for geometry algorithms (here: line-line intersection)
  18388. // http://geomalgorithms.com/a05-_intersect-1.html
  18389. var v_prev_x = inPt.x - inPrev.x,
  18390. v_prev_y = inPt.y - inPrev.y;
  18391. var v_next_x = inNext.x - inPt.x,
  18392. v_next_y = inNext.y - inPt.y;
  18393. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18394. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18395. if (Math.abs(collinear0) > Number.EPSILON) {
  18396. // not collinear
  18397. // length of vectors for normalizing
  18398. var v_prev_len = Math.sqrt(v_prev_lensq);
  18399. 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
  18400. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18401. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18402. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18403. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18404. 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
  18405. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18406. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18407. // but prevent crazy spikes
  18408. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18409. if (v_trans_lensq <= 2) {
  18410. return new Vector2(v_trans_x, v_trans_y);
  18411. } else {
  18412. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18413. }
  18414. } else {
  18415. // handle special case of collinear edges
  18416. var direction_eq = false; // assumes: opposite
  18417. if (v_prev_x > Number.EPSILON) {
  18418. if (v_next_x > Number.EPSILON) {
  18419. direction_eq = true;
  18420. }
  18421. } else {
  18422. if (v_prev_x < -Number.EPSILON) {
  18423. if (v_next_x < -Number.EPSILON) {
  18424. direction_eq = true;
  18425. }
  18426. } else {
  18427. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18428. direction_eq = true;
  18429. }
  18430. }
  18431. }
  18432. if (direction_eq) {
  18433. // console.log("Warning: lines are a straight sequence");
  18434. v_trans_x = -v_prev_y;
  18435. v_trans_y = v_prev_x;
  18436. shrink_by = Math.sqrt(v_prev_lensq);
  18437. } else {
  18438. // console.log("Warning: lines are a straight spike");
  18439. v_trans_x = v_prev_x;
  18440. v_trans_y = v_prev_y;
  18441. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18442. }
  18443. }
  18444. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18445. }
  18446. var contourMovements = [];
  18447. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18448. if (j === il) j = 0;
  18449. if (k === il) k = 0; // (j)---(i)---(k)
  18450. // console.log('i,j,k', i, j , k)
  18451. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18452. }
  18453. var holesMovements = [];
  18454. var oneHoleMovements,
  18455. verticesMovements = contourMovements.concat();
  18456. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18457. var _ahole2 = holes[_h2];
  18458. oneHoleMovements = [];
  18459. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18460. if (_j === _il) _j = 0;
  18461. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18462. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18463. }
  18464. holesMovements.push(oneHoleMovements);
  18465. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18466. } // Loop bevelSegments, 1 for the front, 1 for the back
  18467. for (var b = 0; b < bevelSegments; b++) {
  18468. //for ( b = bevelSegments; b > 0; b -- ) {
  18469. var t = b / bevelSegments;
  18470. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18471. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18472. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18473. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18474. v(vert.x, vert.y, -z);
  18475. } // expand holes
  18476. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18477. var _ahole3 = holes[_h3];
  18478. oneHoleMovements = holesMovements[_h3];
  18479. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18480. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18481. v(_vert.x, _vert.y, -z);
  18482. }
  18483. }
  18484. }
  18485. var bs = bevelSize + bevelOffset; // Back facing vertices
  18486. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18487. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18488. if (!extrudeByPath) {
  18489. v(_vert2.x, _vert2.y, 0);
  18490. } else {
  18491. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18492. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18493. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18494. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18495. v(position2.x, position2.y, position2.z);
  18496. }
  18497. } // Add stepped vertices...
  18498. // Including front facing vertices
  18499. for (var s = 1; s <= steps; s++) {
  18500. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18501. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18502. if (!extrudeByPath) {
  18503. v(_vert3.x, _vert3.y, depth / steps * s);
  18504. } else {
  18505. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18506. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18507. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18508. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18509. v(position2.x, position2.y, position2.z);
  18510. }
  18511. }
  18512. } // Add bevel segments planes
  18513. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18514. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18515. var _t = _b / bevelSegments;
  18516. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18517. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18518. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18519. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18520. v(_vert4.x, _vert4.y, depth + _z);
  18521. } // expand holes
  18522. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18523. var _ahole4 = holes[_h4];
  18524. oneHoleMovements = holesMovements[_h4];
  18525. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18526. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18527. if (!extrudeByPath) {
  18528. v(_vert5.x, _vert5.y, depth + _z);
  18529. } else {
  18530. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18531. }
  18532. }
  18533. }
  18534. }
  18535. /* Faces */
  18536. // Top and bottom faces
  18537. buildLidFaces(); // Sides faces
  18538. buildSideFaces(); ///// Internal functions
  18539. function buildLidFaces() {
  18540. var start = verticesArray.length / 3;
  18541. if (bevelEnabled) {
  18542. var layer = 0; // steps + 1
  18543. var offset = vlen * layer; // Bottom faces
  18544. for (var _i9 = 0; _i9 < flen; _i9++) {
  18545. var face = faces[_i9];
  18546. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18547. }
  18548. layer = steps + bevelSegments * 2;
  18549. offset = vlen * layer; // Top faces
  18550. for (var _i10 = 0; _i10 < flen; _i10++) {
  18551. var _face = faces[_i10];
  18552. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18553. }
  18554. } else {
  18555. // Bottom faces
  18556. for (var _i11 = 0; _i11 < flen; _i11++) {
  18557. var _face2 = faces[_i11];
  18558. f3(_face2[2], _face2[1], _face2[0]);
  18559. } // Top faces
  18560. for (var _i12 = 0; _i12 < flen; _i12++) {
  18561. var _face3 = faces[_i12];
  18562. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18563. }
  18564. }
  18565. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18566. } // Create faces for the z-sides of the shape
  18567. function buildSideFaces() {
  18568. var start = verticesArray.length / 3;
  18569. var layeroffset = 0;
  18570. sidewalls(contour, layeroffset);
  18571. layeroffset += contour.length;
  18572. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18573. var _ahole5 = holes[_h5];
  18574. sidewalls(_ahole5, layeroffset); //, true
  18575. layeroffset += _ahole5.length;
  18576. }
  18577. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18578. }
  18579. function sidewalls(contour, layeroffset) {
  18580. var i = contour.length;
  18581. while (--i >= 0) {
  18582. var _j2 = i;
  18583. var _k2 = i - 1;
  18584. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18585. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18586. var slen1 = vlen * _s;
  18587. var slen2 = vlen * (_s + 1);
  18588. var a = layeroffset + _j2 + slen1,
  18589. _b2 = layeroffset + _k2 + slen1,
  18590. c = layeroffset + _k2 + slen2,
  18591. d = layeroffset + _j2 + slen2;
  18592. f4(a, _b2, c, d);
  18593. }
  18594. }
  18595. }
  18596. function v(x, y, z) {
  18597. placeholder.push(x);
  18598. placeholder.push(y);
  18599. placeholder.push(z);
  18600. }
  18601. function f3(a, b, c) {
  18602. addVertex(a);
  18603. addVertex(b);
  18604. addVertex(c);
  18605. var nextIndex = verticesArray.length / 3;
  18606. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18607. addUV(uvs[0]);
  18608. addUV(uvs[1]);
  18609. addUV(uvs[2]);
  18610. }
  18611. function f4(a, b, c, d) {
  18612. addVertex(a);
  18613. addVertex(b);
  18614. addVertex(d);
  18615. addVertex(b);
  18616. addVertex(c);
  18617. addVertex(d);
  18618. var nextIndex = verticesArray.length / 3;
  18619. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18620. addUV(uvs[0]);
  18621. addUV(uvs[1]);
  18622. addUV(uvs[3]);
  18623. addUV(uvs[1]);
  18624. addUV(uvs[2]);
  18625. addUV(uvs[3]);
  18626. }
  18627. function addVertex(index) {
  18628. verticesArray.push(placeholder[index * 3 + 0]);
  18629. verticesArray.push(placeholder[index * 3 + 1]);
  18630. verticesArray.push(placeholder[index * 3 + 2]);
  18631. }
  18632. function addUV(vector2) {
  18633. uvArray.push(vector2.x);
  18634. uvArray.push(vector2.y);
  18635. }
  18636. }
  18637. return _this;
  18638. }
  18639. var _proto = ExtrudeBufferGeometry.prototype;
  18640. _proto.toJSON = function toJSON() {
  18641. var data = BufferGeometry.prototype.toJSON.call(this);
  18642. var shapes = this.parameters.shapes;
  18643. var options = this.parameters.options;
  18644. return _toJSON(shapes, options, data);
  18645. };
  18646. return ExtrudeBufferGeometry;
  18647. }(BufferGeometry);
  18648. var WorldUVGenerator = {
  18649. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18650. var a_x = vertices[indexA * 3];
  18651. var a_y = vertices[indexA * 3 + 1];
  18652. var b_x = vertices[indexB * 3];
  18653. var b_y = vertices[indexB * 3 + 1];
  18654. var c_x = vertices[indexC * 3];
  18655. var c_y = vertices[indexC * 3 + 1];
  18656. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18657. },
  18658. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18659. var a_x = vertices[indexA * 3];
  18660. var a_y = vertices[indexA * 3 + 1];
  18661. var a_z = vertices[indexA * 3 + 2];
  18662. var b_x = vertices[indexB * 3];
  18663. var b_y = vertices[indexB * 3 + 1];
  18664. var b_z = vertices[indexB * 3 + 2];
  18665. var c_x = vertices[indexC * 3];
  18666. var c_y = vertices[indexC * 3 + 1];
  18667. var c_z = vertices[indexC * 3 + 2];
  18668. var d_x = vertices[indexD * 3];
  18669. var d_y = vertices[indexD * 3 + 1];
  18670. var d_z = vertices[indexD * 3 + 2];
  18671. if (Math.abs(a_y - b_y) < 0.01) {
  18672. 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)];
  18673. } else {
  18674. 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)];
  18675. }
  18676. }
  18677. };
  18678. function _toJSON(shapes, options, data) {
  18679. data.shapes = [];
  18680. if (Array.isArray(shapes)) {
  18681. for (var i = 0, l = shapes.length; i < l; i++) {
  18682. var shape = shapes[i];
  18683. data.shapes.push(shape.uuid);
  18684. }
  18685. } else {
  18686. data.shapes.push(shapes.uuid);
  18687. }
  18688. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18689. return data;
  18690. }
  18691. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18692. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18693. function ExtrudeGeometry(shapes, options) {
  18694. var _this;
  18695. _this = _Geometry.call(this) || this;
  18696. _this.type = 'ExtrudeGeometry';
  18697. _this.parameters = {
  18698. shapes: shapes,
  18699. options: options
  18700. };
  18701. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18702. _this.mergeVertices();
  18703. return _this;
  18704. }
  18705. var _proto = ExtrudeGeometry.prototype;
  18706. _proto.toJSON = function toJSON() {
  18707. var data = _Geometry.prototype.toJSON.call(this);
  18708. var shapes = this.parameters.shapes;
  18709. var options = this.parameters.options;
  18710. return _toJSON$1(shapes, options, data);
  18711. };
  18712. return ExtrudeGeometry;
  18713. }(Geometry);
  18714. function _toJSON$1(shapes, options, data) {
  18715. data.shapes = [];
  18716. if (Array.isArray(shapes)) {
  18717. for (var i = 0, l = shapes.length; i < l; i++) {
  18718. var shape = shapes[i];
  18719. data.shapes.push(shape.uuid);
  18720. }
  18721. } else {
  18722. data.shapes.push(shapes.uuid);
  18723. }
  18724. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18725. return data;
  18726. }
  18727. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18728. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  18729. function IcosahedronBufferGeometry(radius, detail) {
  18730. var _this;
  18731. var t = (1 + Math.sqrt(5)) / 2;
  18732. 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];
  18733. 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];
  18734. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18735. _this.type = 'IcosahedronBufferGeometry';
  18736. _this.parameters = {
  18737. radius: radius,
  18738. detail: detail
  18739. };
  18740. return _this;
  18741. }
  18742. return IcosahedronBufferGeometry;
  18743. }(PolyhedronBufferGeometry);
  18744. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18745. _inheritsLoose(IcosahedronGeometry, _Geometry);
  18746. function IcosahedronGeometry(radius, detail) {
  18747. var _this;
  18748. _this = _Geometry.call(this) || this;
  18749. _this.type = 'IcosahedronGeometry';
  18750. _this.parameters = {
  18751. radius: radius,
  18752. detail: detail
  18753. };
  18754. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  18755. _this.mergeVertices();
  18756. return _this;
  18757. }
  18758. return IcosahedronGeometry;
  18759. }(Geometry);
  18760. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18761. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  18762. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  18763. var _this;
  18764. _this = _BufferGeometry.call(this) || this;
  18765. _this.type = 'LatheBufferGeometry';
  18766. _this.parameters = {
  18767. points: points,
  18768. segments: segments,
  18769. phiStart: phiStart,
  18770. phiLength: phiLength
  18771. };
  18772. segments = Math.floor(segments) || 12;
  18773. phiStart = phiStart || 0;
  18774. phiLength = phiLength || Math.PI * 2; // clamp phiLength so it's in range of [ 0, 2PI ]
  18775. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18776. var indices = [];
  18777. var vertices = [];
  18778. var uvs = []; // helper variables
  18779. var inverseSegments = 1.0 / segments;
  18780. var vertex = new Vector3();
  18781. var uv = new Vector2(); // generate vertices and uvs
  18782. for (var i = 0; i <= segments; i++) {
  18783. var phi = phiStart + i * inverseSegments * phiLength;
  18784. var sin = Math.sin(phi);
  18785. var cos = Math.cos(phi);
  18786. for (var j = 0; j <= points.length - 1; j++) {
  18787. // vertex
  18788. vertex.x = points[j].x * sin;
  18789. vertex.y = points[j].y;
  18790. vertex.z = points[j].x * cos;
  18791. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18792. uv.x = i / segments;
  18793. uv.y = j / (points.length - 1);
  18794. uvs.push(uv.x, uv.y);
  18795. }
  18796. } // indices
  18797. for (var _i = 0; _i < segments; _i++) {
  18798. for (var _j = 0; _j < points.length - 1; _j++) {
  18799. var base = _j + _i * points.length;
  18800. var a = base;
  18801. var b = base + points.length;
  18802. var c = base + points.length + 1;
  18803. var d = base + 1; // faces
  18804. indices.push(a, b, d);
  18805. indices.push(b, c, d);
  18806. }
  18807. } // build geometry
  18808. _this.setIndex(indices);
  18809. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18810. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18811. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18812. // because the corresponding vertices are identical (but still have different UVs).
  18813. if (phiLength === Math.PI * 2) {
  18814. var normals = _this.attributes.normal.array;
  18815. var n1 = new Vector3();
  18816. var n2 = new Vector3();
  18817. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18818. var _base = segments * points.length * 3;
  18819. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18820. // select the normal of the vertex in the first line
  18821. n1.x = normals[_j2 + 0];
  18822. n1.y = normals[_j2 + 1];
  18823. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18824. n2.x = normals[_base + _j2 + 0];
  18825. n2.y = normals[_base + _j2 + 1];
  18826. n2.z = normals[_base + _j2 + 2]; // average normals
  18827. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18828. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18829. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18830. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18831. }
  18832. }
  18833. return _this;
  18834. }
  18835. return LatheBufferGeometry;
  18836. }(BufferGeometry);
  18837. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  18838. _inheritsLoose(LatheGeometry, _Geometry);
  18839. function LatheGeometry(points, segments, phiStart, phiLength) {
  18840. var _this;
  18841. _this = _Geometry.call(this) || this;
  18842. _this.type = 'LatheGeometry';
  18843. _this.parameters = {
  18844. points: points,
  18845. segments: segments,
  18846. phiStart: phiStart,
  18847. phiLength: phiLength
  18848. };
  18849. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  18850. _this.mergeVertices();
  18851. return _this;
  18852. }
  18853. return LatheGeometry;
  18854. }(Geometry);
  18855. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18856. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  18857. function OctahedronBufferGeometry(radius, detail) {
  18858. var _this;
  18859. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18860. 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];
  18861. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18862. _this.type = 'OctahedronBufferGeometry';
  18863. _this.parameters = {
  18864. radius: radius,
  18865. detail: detail
  18866. };
  18867. return _this;
  18868. }
  18869. return OctahedronBufferGeometry;
  18870. }(PolyhedronBufferGeometry);
  18871. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18872. _inheritsLoose(OctahedronGeometry, _Geometry);
  18873. function OctahedronGeometry(radius, detail) {
  18874. var _this;
  18875. _this = _Geometry.call(this) || this;
  18876. _this.type = 'OctahedronGeometry';
  18877. _this.parameters = {
  18878. radius: radius,
  18879. detail: detail
  18880. };
  18881. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  18882. _this.mergeVertices();
  18883. return _this;
  18884. }
  18885. return OctahedronGeometry;
  18886. }(Geometry);
  18887. /**
  18888. * Parametric Surfaces Geometry
  18889. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18890. */
  18891. function ParametricBufferGeometry(func, slices, stacks) {
  18892. BufferGeometry.call(this);
  18893. this.type = 'ParametricBufferGeometry';
  18894. this.parameters = {
  18895. func: func,
  18896. slices: slices,
  18897. stacks: stacks
  18898. }; // buffers
  18899. var indices = [];
  18900. var vertices = [];
  18901. var normals = [];
  18902. var uvs = [];
  18903. var EPS = 0.00001;
  18904. var normal = new Vector3();
  18905. var p0 = new Vector3(),
  18906. p1 = new Vector3();
  18907. var pu = new Vector3(),
  18908. pv = new Vector3();
  18909. if (func.length < 3) {
  18910. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18911. } // generate vertices, normals and uvs
  18912. var sliceCount = slices + 1;
  18913. for (var i = 0; i <= stacks; i++) {
  18914. var v = i / stacks;
  18915. for (var j = 0; j <= slices; j++) {
  18916. var u = j / slices; // vertex
  18917. func(u, v, p0);
  18918. vertices.push(p0.x, p0.y, p0.z); // normal
  18919. // approximate tangent vectors via finite differences
  18920. if (u - EPS >= 0) {
  18921. func(u - EPS, v, p1);
  18922. pu.subVectors(p0, p1);
  18923. } else {
  18924. func(u + EPS, v, p1);
  18925. pu.subVectors(p1, p0);
  18926. }
  18927. if (v - EPS >= 0) {
  18928. func(u, v - EPS, p1);
  18929. pv.subVectors(p0, p1);
  18930. } else {
  18931. func(u, v + EPS, p1);
  18932. pv.subVectors(p1, p0);
  18933. } // cross product of tangent vectors returns surface normal
  18934. normal.crossVectors(pu, pv).normalize();
  18935. normals.push(normal.x, normal.y, normal.z); // uv
  18936. uvs.push(u, v);
  18937. }
  18938. } // generate indices
  18939. for (var _i = 0; _i < stacks; _i++) {
  18940. for (var _j = 0; _j < slices; _j++) {
  18941. var a = _i * sliceCount + _j;
  18942. var b = _i * sliceCount + _j + 1;
  18943. var c = (_i + 1) * sliceCount + _j + 1;
  18944. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18945. indices.push(a, b, d);
  18946. indices.push(b, c, d);
  18947. }
  18948. } // build geometry
  18949. this.setIndex(indices);
  18950. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18951. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18952. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18953. }
  18954. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  18955. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  18956. /**
  18957. * Parametric Surfaces Geometry
  18958. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18959. */
  18960. function ParametricGeometry(func, slices, stacks) {
  18961. Geometry.call(this);
  18962. this.type = 'ParametricGeometry';
  18963. this.parameters = {
  18964. func: func,
  18965. slices: slices,
  18966. stacks: stacks
  18967. };
  18968. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  18969. this.mergeVertices();
  18970. }
  18971. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  18972. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18973. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  18974. _inheritsLoose(PlaneGeometry, _Geometry);
  18975. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  18976. var _this;
  18977. _this = _Geometry.call(this) || this;
  18978. _this.type = 'PlaneGeometry';
  18979. _this.parameters = {
  18980. width: width,
  18981. height: height,
  18982. widthSegments: widthSegments,
  18983. heightSegments: heightSegments
  18984. };
  18985. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  18986. _this.mergeVertices();
  18987. return _this;
  18988. }
  18989. return PlaneGeometry;
  18990. }(Geometry);
  18991. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  18992. _inheritsLoose(PolyhedronGeometry, _Geometry);
  18993. function PolyhedronGeometry(vertices, indices, radius, detail) {
  18994. var _this;
  18995. _this = _Geometry.call(this) || this;
  18996. _this.type = 'PolyhedronGeometry';
  18997. _this.parameters = {
  18998. vertices: vertices,
  18999. indices: indices,
  19000. radius: radius,
  19001. detail: detail
  19002. };
  19003. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  19004. _this.mergeVertices();
  19005. return _this;
  19006. }
  19007. return PolyhedronGeometry;
  19008. }(Geometry);
  19009. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19010. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  19011. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19012. var _this;
  19013. _this = _BufferGeometry.call(this) || this;
  19014. _this.type = 'RingBufferGeometry';
  19015. _this.parameters = {
  19016. innerRadius: innerRadius,
  19017. outerRadius: outerRadius,
  19018. thetaSegments: thetaSegments,
  19019. phiSegments: phiSegments,
  19020. thetaStart: thetaStart,
  19021. thetaLength: thetaLength
  19022. };
  19023. innerRadius = innerRadius || 0.5;
  19024. outerRadius = outerRadius || 1;
  19025. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19026. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19027. thetaSegments = thetaSegments !== undefined ? Math.max(3, thetaSegments) : 8;
  19028. phiSegments = phiSegments !== undefined ? Math.max(1, phiSegments) : 1; // buffers
  19029. var indices = [];
  19030. var vertices = [];
  19031. var normals = [];
  19032. var uvs = []; // some helper variables
  19033. var radius = innerRadius;
  19034. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  19035. var vertex = new Vector3();
  19036. var uv = new Vector2(); // generate vertices, normals and uvs
  19037. for (var j = 0; j <= phiSegments; j++) {
  19038. for (var i = 0; i <= thetaSegments; i++) {
  19039. // values are generate from the inside of the ring to the outside
  19040. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  19041. vertex.x = radius * Math.cos(segment);
  19042. vertex.y = radius * Math.sin(segment);
  19043. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19044. normals.push(0, 0, 1); // uv
  19045. uv.x = (vertex.x / outerRadius + 1) / 2;
  19046. uv.y = (vertex.y / outerRadius + 1) / 2;
  19047. uvs.push(uv.x, uv.y);
  19048. } // increase the radius for next row of vertices
  19049. radius += radiusStep;
  19050. } // indices
  19051. for (var _j = 0; _j < phiSegments; _j++) {
  19052. var thetaSegmentLevel = _j * (thetaSegments + 1);
  19053. for (var _i = 0; _i < thetaSegments; _i++) {
  19054. var _segment = _i + thetaSegmentLevel;
  19055. var a = _segment;
  19056. var b = _segment + thetaSegments + 1;
  19057. var c = _segment + thetaSegments + 2;
  19058. var d = _segment + 1; // faces
  19059. indices.push(a, b, d);
  19060. indices.push(b, c, d);
  19061. }
  19062. } // build geometry
  19063. _this.setIndex(indices);
  19064. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19065. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19066. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19067. return _this;
  19068. }
  19069. return RingBufferGeometry;
  19070. }(BufferGeometry);
  19071. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  19072. _inheritsLoose(RingGeometry, _Geometry);
  19073. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19074. var _this;
  19075. _this = _Geometry.call(this) || this;
  19076. _this.type = 'RingGeometry';
  19077. _this.parameters = {
  19078. innerRadius: innerRadius,
  19079. outerRadius: outerRadius,
  19080. thetaSegments: thetaSegments,
  19081. phiSegments: phiSegments,
  19082. thetaStart: thetaStart,
  19083. thetaLength: thetaLength
  19084. };
  19085. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  19086. _this.mergeVertices();
  19087. return _this;
  19088. }
  19089. return RingGeometry;
  19090. }(Geometry);
  19091. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19092. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  19093. function ShapeBufferGeometry(shapes, curveSegments) {
  19094. var _this;
  19095. _this = _BufferGeometry.call(this) || this;
  19096. _this.type = 'ShapeBufferGeometry';
  19097. _this.parameters = {
  19098. shapes: shapes,
  19099. curveSegments: curveSegments
  19100. };
  19101. curveSegments = curveSegments || 12; // buffers
  19102. var indices = [];
  19103. var vertices = [];
  19104. var normals = [];
  19105. var uvs = []; // helper variables
  19106. var groupStart = 0;
  19107. var groupCount = 0; // allow single and array values for "shapes" parameter
  19108. if (Array.isArray(shapes) === false) {
  19109. addShape(shapes);
  19110. } else {
  19111. for (var i = 0; i < shapes.length; i++) {
  19112. addShape(shapes[i]);
  19113. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19114. groupStart += groupCount;
  19115. groupCount = 0;
  19116. }
  19117. } // build geometry
  19118. _this.setIndex(indices);
  19119. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19120. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19121. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19122. function addShape(shape) {
  19123. var indexOffset = vertices.length / 3;
  19124. var points = shape.extractPoints(curveSegments);
  19125. var shapeVertices = points.shape;
  19126. var shapeHoles = points.holes; // check direction of vertices
  19127. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19128. shapeVertices = shapeVertices.reverse();
  19129. }
  19130. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19131. var shapeHole = shapeHoles[_i];
  19132. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19133. shapeHoles[_i] = shapeHole.reverse();
  19134. }
  19135. }
  19136. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19137. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19138. var _shapeHole = shapeHoles[_i2];
  19139. shapeVertices = shapeVertices.concat(_shapeHole);
  19140. } // vertices, normals, uvs
  19141. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19142. var vertex = shapeVertices[_i3];
  19143. vertices.push(vertex.x, vertex.y, 0);
  19144. normals.push(0, 0, 1);
  19145. uvs.push(vertex.x, vertex.y); // world uvs
  19146. } // incides
  19147. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19148. var face = faces[_i4];
  19149. var a = face[0] + indexOffset;
  19150. var b = face[1] + indexOffset;
  19151. var c = face[2] + indexOffset;
  19152. indices.push(a, b, c);
  19153. groupCount += 3;
  19154. }
  19155. }
  19156. return _this;
  19157. }
  19158. var _proto = ShapeBufferGeometry.prototype;
  19159. _proto.toJSON = function toJSON() {
  19160. var data = BufferGeometry.prototype.toJSON.call(this);
  19161. var shapes = this.parameters.shapes;
  19162. return _toJSON$2(shapes, data);
  19163. };
  19164. return ShapeBufferGeometry;
  19165. }(BufferGeometry);
  19166. function _toJSON$2(shapes, data) {
  19167. data.shapes = [];
  19168. if (Array.isArray(shapes)) {
  19169. for (var i = 0, l = shapes.length; i < l; i++) {
  19170. var shape = shapes[i];
  19171. data.shapes.push(shape.uuid);
  19172. }
  19173. } else {
  19174. data.shapes.push(shapes.uuid);
  19175. }
  19176. return data;
  19177. }
  19178. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  19179. _inheritsLoose(ShapeGeometry, _Geometry);
  19180. function ShapeGeometry(shapes, curveSegments) {
  19181. var _this;
  19182. _this = _Geometry.call(this) || this;
  19183. _this.type = 'ShapeGeometry';
  19184. if (typeof curveSegments === 'object') {
  19185. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19186. curveSegments = curveSegments.curveSegments;
  19187. }
  19188. _this.parameters = {
  19189. shapes: shapes,
  19190. curveSegments: curveSegments
  19191. };
  19192. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19193. _this.mergeVertices();
  19194. return _this;
  19195. }
  19196. var _proto = ShapeGeometry.prototype;
  19197. _proto.toJSON = function toJSON() {
  19198. var data = Geometry.prototype.toJSON.call(this);
  19199. var shapes = this.parameters.shapes;
  19200. return _toJSON$3(shapes, data);
  19201. };
  19202. return ShapeGeometry;
  19203. }(Geometry);
  19204. function _toJSON$3(shapes, data) {
  19205. data.shapes = [];
  19206. if (Array.isArray(shapes)) {
  19207. for (var i = 0, l = shapes.length; i < l; i++) {
  19208. var shape = shapes[i];
  19209. data.shapes.push(shape.uuid);
  19210. }
  19211. } else {
  19212. data.shapes.push(shapes.uuid);
  19213. }
  19214. return data;
  19215. }
  19216. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19217. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19218. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19219. var _this;
  19220. _this = _BufferGeometry.call(this) || this;
  19221. _this.type = 'SphereBufferGeometry';
  19222. _this.parameters = {
  19223. radius: radius,
  19224. widthSegments: widthSegments,
  19225. heightSegments: heightSegments,
  19226. phiStart: phiStart,
  19227. phiLength: phiLength,
  19228. thetaStart: thetaStart,
  19229. thetaLength: thetaLength
  19230. };
  19231. radius = radius || 1;
  19232. widthSegments = Math.max(3, Math.floor(widthSegments) || 8);
  19233. heightSegments = Math.max(2, Math.floor(heightSegments) || 6);
  19234. phiStart = phiStart !== undefined ? phiStart : 0;
  19235. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19236. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19237. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19238. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19239. var index = 0;
  19240. var grid = [];
  19241. var vertex = new Vector3();
  19242. var normal = new Vector3(); // buffers
  19243. var indices = [];
  19244. var vertices = [];
  19245. var normals = [];
  19246. var uvs = []; // generate vertices, normals and uvs
  19247. for (var iy = 0; iy <= heightSegments; iy++) {
  19248. var verticesRow = [];
  19249. var v = iy / heightSegments; // special case for the poles
  19250. var uOffset = 0;
  19251. if (iy == 0 && thetaStart == 0) {
  19252. uOffset = 0.5 / widthSegments;
  19253. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19254. uOffset = -0.5 / widthSegments;
  19255. }
  19256. for (var ix = 0; ix <= widthSegments; ix++) {
  19257. var u = ix / widthSegments; // vertex
  19258. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19259. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19260. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19261. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19262. normal.copy(vertex).normalize();
  19263. normals.push(normal.x, normal.y, normal.z); // uv
  19264. uvs.push(u + uOffset, 1 - v);
  19265. verticesRow.push(index++);
  19266. }
  19267. grid.push(verticesRow);
  19268. } // indices
  19269. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19270. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19271. var a = grid[_iy][_ix + 1];
  19272. var b = grid[_iy][_ix];
  19273. var c = grid[_iy + 1][_ix];
  19274. var d = grid[_iy + 1][_ix + 1];
  19275. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19276. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19277. }
  19278. } // build geometry
  19279. _this.setIndex(indices);
  19280. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19281. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19282. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19283. return _this;
  19284. }
  19285. return SphereBufferGeometry;
  19286. }(BufferGeometry);
  19287. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19288. _inheritsLoose(SphereGeometry, _Geometry);
  19289. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19290. var _this;
  19291. _this = _Geometry.call(this) || this;
  19292. _this.type = 'SphereGeometry';
  19293. _this.parameters = {
  19294. radius: radius,
  19295. widthSegments: widthSegments,
  19296. heightSegments: heightSegments,
  19297. phiStart: phiStart,
  19298. phiLength: phiLength,
  19299. thetaStart: thetaStart,
  19300. thetaLength: thetaLength
  19301. };
  19302. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19303. _this.mergeVertices();
  19304. return _this;
  19305. }
  19306. return SphereGeometry;
  19307. }(Geometry);
  19308. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19309. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19310. function TetrahedronBufferGeometry(radius, detail) {
  19311. var _this;
  19312. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19313. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19314. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19315. _this.type = 'TetrahedronBufferGeometry';
  19316. _this.parameters = {
  19317. radius: radius,
  19318. detail: detail
  19319. };
  19320. return _this;
  19321. }
  19322. return TetrahedronBufferGeometry;
  19323. }(PolyhedronBufferGeometry);
  19324. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19325. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19326. function TetrahedronGeometry(radius, detail) {
  19327. var _this;
  19328. _this = _Geometry.call(this) || this;
  19329. _this.type = 'TetrahedronGeometry';
  19330. _this.parameters = {
  19331. radius: radius,
  19332. detail: detail
  19333. };
  19334. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19335. _this.mergeVertices();
  19336. return _this;
  19337. }
  19338. return TetrahedronGeometry;
  19339. }(Geometry);
  19340. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19341. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19342. function TextBufferGeometry(text, parameters) {
  19343. var _this;
  19344. parameters = parameters || {};
  19345. var font = parameters.font;
  19346. if (!(font && font.isFont)) {
  19347. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19348. return new BufferGeometry() || _assertThisInitialized(_this);
  19349. }
  19350. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19351. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19352. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19353. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19354. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19355. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19356. _this.type = 'TextBufferGeometry';
  19357. return _this;
  19358. }
  19359. return TextBufferGeometry;
  19360. }(ExtrudeBufferGeometry);
  19361. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19362. _inheritsLoose(TextGeometry, _Geometry);
  19363. function TextGeometry(text, parameters) {
  19364. var _this;
  19365. _this = _Geometry.call(this) || this;
  19366. _this.type = 'TextGeometry';
  19367. _this.parameters = {
  19368. text: text,
  19369. parameters: parameters
  19370. };
  19371. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19372. _this.mergeVertices();
  19373. return _this;
  19374. }
  19375. return TextGeometry;
  19376. }(Geometry);
  19377. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19378. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19379. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19380. var _this;
  19381. _this = _BufferGeometry.call(this) || this;
  19382. _this.type = 'TorusBufferGeometry';
  19383. _this.parameters = {
  19384. radius: radius,
  19385. tube: tube,
  19386. radialSegments: radialSegments,
  19387. tubularSegments: tubularSegments,
  19388. arc: arc
  19389. };
  19390. radius = radius || 1;
  19391. tube = tube || 0.4;
  19392. radialSegments = Math.floor(radialSegments) || 8;
  19393. tubularSegments = Math.floor(tubularSegments) || 6;
  19394. arc = arc || Math.PI * 2; // buffers
  19395. var indices = [];
  19396. var vertices = [];
  19397. var normals = [];
  19398. var uvs = []; // helper variables
  19399. var center = new Vector3();
  19400. var vertex = new Vector3();
  19401. var normal = new Vector3(); // generate vertices, normals and uvs
  19402. for (var j = 0; j <= radialSegments; j++) {
  19403. for (var i = 0; i <= tubularSegments; i++) {
  19404. var u = i / tubularSegments * arc;
  19405. var v = j / radialSegments * Math.PI * 2; // vertex
  19406. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19407. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19408. vertex.z = tube * Math.sin(v);
  19409. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19410. center.x = radius * Math.cos(u);
  19411. center.y = radius * Math.sin(u);
  19412. normal.subVectors(vertex, center).normalize();
  19413. normals.push(normal.x, normal.y, normal.z); // uv
  19414. uvs.push(i / tubularSegments);
  19415. uvs.push(j / radialSegments);
  19416. }
  19417. } // generate indices
  19418. for (var _j = 1; _j <= radialSegments; _j++) {
  19419. for (var _i = 1; _i <= tubularSegments; _i++) {
  19420. // indices
  19421. var a = (tubularSegments + 1) * _j + _i - 1;
  19422. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19423. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19424. var d = (tubularSegments + 1) * _j + _i; // faces
  19425. indices.push(a, b, d);
  19426. indices.push(b, c, d);
  19427. }
  19428. } // build geometry
  19429. _this.setIndex(indices);
  19430. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19431. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19432. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19433. return _this;
  19434. }
  19435. return TorusBufferGeometry;
  19436. }(BufferGeometry);
  19437. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19438. _inheritsLoose(TorusGeometry, _Geometry);
  19439. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19440. var _this;
  19441. _this = _Geometry.call(this) || this;
  19442. _this.type = 'TorusGeometry';
  19443. _this.parameters = {
  19444. radius: radius,
  19445. tube: tube,
  19446. radialSegments: radialSegments,
  19447. tubularSegments: tubularSegments,
  19448. arc: arc
  19449. };
  19450. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19451. _this.mergeVertices();
  19452. return _this;
  19453. }
  19454. return TorusGeometry;
  19455. }(Geometry);
  19456. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19457. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19458. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19459. var _this;
  19460. _this = _BufferGeometry.call(this) || this;
  19461. _this.type = 'TorusKnotBufferGeometry';
  19462. _this.parameters = {
  19463. radius: radius,
  19464. tube: tube,
  19465. tubularSegments: tubularSegments,
  19466. radialSegments: radialSegments,
  19467. p: p,
  19468. q: q
  19469. };
  19470. radius = radius || 1;
  19471. tube = tube || 0.4;
  19472. tubularSegments = Math.floor(tubularSegments) || 64;
  19473. radialSegments = Math.floor(radialSegments) || 8;
  19474. p = p || 2;
  19475. q = q || 3; // buffers
  19476. var indices = [];
  19477. var vertices = [];
  19478. var normals = [];
  19479. var uvs = []; // helper variables
  19480. var vertex = new Vector3();
  19481. var normal = new Vector3();
  19482. var P1 = new Vector3();
  19483. var P2 = new Vector3();
  19484. var B = new Vector3();
  19485. var T = new Vector3();
  19486. var N = new Vector3(); // generate vertices, normals and uvs
  19487. for (var i = 0; i <= tubularSegments; ++i) {
  19488. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19489. 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.
  19490. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19491. calculatePositionOnCurve(u, p, q, radius, P1);
  19492. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19493. T.subVectors(P2, P1);
  19494. N.addVectors(P2, P1);
  19495. B.crossVectors(T, N);
  19496. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19497. B.normalize();
  19498. N.normalize();
  19499. for (var j = 0; j <= radialSegments; ++j) {
  19500. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19501. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19502. var v = j / radialSegments * Math.PI * 2;
  19503. var cx = -tube * Math.cos(v);
  19504. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19505. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19506. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19507. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19508. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19509. 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)
  19510. normal.subVectors(vertex, P1).normalize();
  19511. normals.push(normal.x, normal.y, normal.z); // uv
  19512. uvs.push(i / tubularSegments);
  19513. uvs.push(j / radialSegments);
  19514. }
  19515. } // generate indices
  19516. for (var _j = 1; _j <= tubularSegments; _j++) {
  19517. for (var _i = 1; _i <= radialSegments; _i++) {
  19518. // indices
  19519. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19520. var b = (radialSegments + 1) * _j + (_i - 1);
  19521. var c = (radialSegments + 1) * _j + _i;
  19522. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19523. indices.push(a, b, d);
  19524. indices.push(b, c, d);
  19525. }
  19526. } // build geometry
  19527. _this.setIndex(indices);
  19528. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19529. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19530. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19531. function calculatePositionOnCurve(u, p, q, radius, position) {
  19532. var cu = Math.cos(u);
  19533. var su = Math.sin(u);
  19534. var quOverP = q / p * u;
  19535. var cs = Math.cos(quOverP);
  19536. position.x = radius * (2 + cs) * 0.5 * cu;
  19537. position.y = radius * (2 + cs) * su * 0.5;
  19538. position.z = radius * Math.sin(quOverP) * 0.5;
  19539. }
  19540. return _this;
  19541. }
  19542. return TorusKnotBufferGeometry;
  19543. }(BufferGeometry);
  19544. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19545. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19546. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19547. var _this;
  19548. _this = _Geometry.call(this) || this;
  19549. _this.type = 'TorusKnotGeometry';
  19550. _this.parameters = {
  19551. radius: radius,
  19552. tube: tube,
  19553. tubularSegments: tubularSegments,
  19554. radialSegments: radialSegments,
  19555. p: p,
  19556. q: q
  19557. };
  19558. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19559. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19560. _this.mergeVertices();
  19561. return _this;
  19562. }
  19563. return TorusKnotGeometry;
  19564. }(Geometry);
  19565. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19566. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19567. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19568. var _this;
  19569. _this = _BufferGeometry.call(this) || this;
  19570. _this.type = 'TubeBufferGeometry';
  19571. _this.parameters = {
  19572. path: path,
  19573. tubularSegments: tubularSegments,
  19574. radius: radius,
  19575. radialSegments: radialSegments,
  19576. closed: closed
  19577. };
  19578. tubularSegments = tubularSegments || 64;
  19579. radius = radius || 1;
  19580. radialSegments = radialSegments || 8;
  19581. closed = closed || false;
  19582. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19583. _this.tangents = frames.tangents;
  19584. _this.normals = frames.normals;
  19585. _this.binormals = frames.binormals; // helper variables
  19586. var vertex = new Vector3();
  19587. var normal = new Vector3();
  19588. var uv = new Vector2();
  19589. var P = new Vector3(); // buffer
  19590. var vertices = [];
  19591. var normals = [];
  19592. var uvs = [];
  19593. var indices = []; // create buffer data
  19594. generateBufferData(); // build geometry
  19595. _this.setIndex(indices);
  19596. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19597. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19598. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19599. function generateBufferData() {
  19600. for (var i = 0; i < tubularSegments; i++) {
  19601. generateSegment(i);
  19602. } // if the geometry is not closed, generate the last row of vertices and normals
  19603. // at the regular position on the given path
  19604. //
  19605. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19606. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19607. // this makes it easy compute correct values for closed geometries
  19608. generateUVs(); // finally create faces
  19609. generateIndices();
  19610. }
  19611. function generateSegment(i) {
  19612. // we use getPointAt to sample evenly distributed points from the given path
  19613. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19614. var N = frames.normals[i];
  19615. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19616. for (var j = 0; j <= radialSegments; j++) {
  19617. var v = j / radialSegments * Math.PI * 2;
  19618. var sin = Math.sin(v);
  19619. var cos = -Math.cos(v); // normal
  19620. normal.x = cos * N.x + sin * B.x;
  19621. normal.y = cos * N.y + sin * B.y;
  19622. normal.z = cos * N.z + sin * B.z;
  19623. normal.normalize();
  19624. normals.push(normal.x, normal.y, normal.z); // vertex
  19625. vertex.x = P.x + radius * normal.x;
  19626. vertex.y = P.y + radius * normal.y;
  19627. vertex.z = P.z + radius * normal.z;
  19628. vertices.push(vertex.x, vertex.y, vertex.z);
  19629. }
  19630. }
  19631. function generateIndices() {
  19632. for (var j = 1; j <= tubularSegments; j++) {
  19633. for (var i = 1; i <= radialSegments; i++) {
  19634. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19635. var b = (radialSegments + 1) * j + (i - 1);
  19636. var c = (radialSegments + 1) * j + i;
  19637. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19638. indices.push(a, b, d);
  19639. indices.push(b, c, d);
  19640. }
  19641. }
  19642. }
  19643. function generateUVs() {
  19644. for (var i = 0; i <= tubularSegments; i++) {
  19645. for (var j = 0; j <= radialSegments; j++) {
  19646. uv.x = i / tubularSegments;
  19647. uv.y = j / radialSegments;
  19648. uvs.push(uv.x, uv.y);
  19649. }
  19650. }
  19651. }
  19652. return _this;
  19653. }
  19654. var _proto = TubeBufferGeometry.prototype;
  19655. _proto.toJSON = function toJSON() {
  19656. var data = BufferGeometry.prototype.toJSON.call(this);
  19657. data.path = this.parameters.path.toJSON();
  19658. return data;
  19659. };
  19660. return TubeBufferGeometry;
  19661. }(BufferGeometry);
  19662. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  19663. _inheritsLoose(TubeGeometry, _Geometry);
  19664. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  19665. var _this;
  19666. _this = _Geometry.call(this) || this;
  19667. _this.type = 'TubeGeometry';
  19668. _this.parameters = {
  19669. path: path,
  19670. tubularSegments: tubularSegments,
  19671. radius: radius,
  19672. radialSegments: radialSegments,
  19673. closed: closed
  19674. };
  19675. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  19676. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  19677. _this.tangents = bufferGeometry.tangents;
  19678. _this.normals = bufferGeometry.normals;
  19679. _this.binormals = bufferGeometry.binormals; // create geometry
  19680. _this.fromBufferGeometry(bufferGeometry);
  19681. _this.mergeVertices();
  19682. return _this;
  19683. }
  19684. return TubeGeometry;
  19685. }(Geometry);
  19686. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19687. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19688. function WireframeGeometry(geometry) {
  19689. var _this;
  19690. _this = _BufferGeometry.call(this) || this;
  19691. _this.type = 'WireframeGeometry'; // buffer
  19692. var vertices = []; // helper variables
  19693. var edge = [0, 0],
  19694. edges = {};
  19695. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  19696. if (geometry && geometry.isGeometry) {
  19697. // create a data structure that contains all edges without duplicates
  19698. var faces = geometry.faces;
  19699. for (var i = 0, l = faces.length; i < l; i++) {
  19700. var face = faces[i];
  19701. for (var j = 0; j < 3; j++) {
  19702. var edge1 = face[keys[j]];
  19703. var edge2 = face[keys[(j + 1) % 3]];
  19704. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19705. edge[1] = Math.max(edge1, edge2);
  19706. var key = edge[0] + ',' + edge[1];
  19707. if (edges[key] === undefined) {
  19708. edges[key] = {
  19709. index1: edge[0],
  19710. index2: edge[1]
  19711. };
  19712. }
  19713. }
  19714. } // generate vertices
  19715. for (var _key in edges) {
  19716. var e = edges[_key];
  19717. var vertex = geometry.vertices[e.index1];
  19718. vertices.push(vertex.x, vertex.y, vertex.z);
  19719. vertex = geometry.vertices[e.index2];
  19720. vertices.push(vertex.x, vertex.y, vertex.z);
  19721. }
  19722. } else if (geometry && geometry.isBufferGeometry) {
  19723. var _vertex = new Vector3();
  19724. if (geometry.index !== null) {
  19725. // indexed BufferGeometry
  19726. var position = geometry.attributes.position;
  19727. var indices = geometry.index;
  19728. var groups = geometry.groups;
  19729. if (groups.length === 0) {
  19730. groups = [{
  19731. start: 0,
  19732. count: indices.count,
  19733. materialIndex: 0
  19734. }];
  19735. } // create a data structure that contains all eges without duplicates
  19736. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19737. var group = groups[o];
  19738. var start = group.start;
  19739. var count = group.count;
  19740. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  19741. for (var _j = 0; _j < 3; _j++) {
  19742. var _edge = indices.getX(_i + _j);
  19743. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  19744. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  19745. edge[1] = Math.max(_edge, _edge2);
  19746. var _key2 = edge[0] + ',' + edge[1];
  19747. if (edges[_key2] === undefined) {
  19748. edges[_key2] = {
  19749. index1: edge[0],
  19750. index2: edge[1]
  19751. };
  19752. }
  19753. }
  19754. }
  19755. } // generate vertices
  19756. for (var _key3 in edges) {
  19757. var _e = edges[_key3];
  19758. _vertex.fromBufferAttribute(position, _e.index1);
  19759. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19760. _vertex.fromBufferAttribute(position, _e.index2);
  19761. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19762. }
  19763. } else {
  19764. // non-indexed BufferGeometry
  19765. var _position = geometry.attributes.position;
  19766. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  19767. for (var _j2 = 0; _j2 < 3; _j2++) {
  19768. // three edges per triangle, an edge is represented as (index1, index2)
  19769. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19770. var index1 = 3 * _i2 + _j2;
  19771. _vertex.fromBufferAttribute(_position, index1);
  19772. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19773. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  19774. _vertex.fromBufferAttribute(_position, index2);
  19775. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19776. }
  19777. }
  19778. }
  19779. } // build geometry
  19780. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19781. return _this;
  19782. }
  19783. return WireframeGeometry;
  19784. }(BufferGeometry);
  19785. var Geometries = /*#__PURE__*/Object.freeze({
  19786. __proto__: null,
  19787. BoxGeometry: BoxGeometry,
  19788. BoxBufferGeometry: BoxBufferGeometry,
  19789. CircleGeometry: CircleGeometry,
  19790. CircleBufferGeometry: CircleBufferGeometry,
  19791. ConeGeometry: ConeGeometry,
  19792. ConeBufferGeometry: ConeBufferGeometry,
  19793. CylinderGeometry: CylinderGeometry,
  19794. CylinderBufferGeometry: CylinderBufferGeometry,
  19795. DodecahedronGeometry: DodecahedronGeometry,
  19796. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19797. EdgesGeometry: EdgesGeometry,
  19798. ExtrudeGeometry: ExtrudeGeometry,
  19799. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19800. IcosahedronGeometry: IcosahedronGeometry,
  19801. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19802. LatheGeometry: LatheGeometry,
  19803. LatheBufferGeometry: LatheBufferGeometry,
  19804. OctahedronGeometry: OctahedronGeometry,
  19805. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19806. ParametricGeometry: ParametricGeometry,
  19807. ParametricBufferGeometry: ParametricBufferGeometry,
  19808. PlaneGeometry: PlaneGeometry,
  19809. PlaneBufferGeometry: PlaneBufferGeometry,
  19810. PolyhedronGeometry: PolyhedronGeometry,
  19811. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19812. RingGeometry: RingGeometry,
  19813. RingBufferGeometry: RingBufferGeometry,
  19814. ShapeGeometry: ShapeGeometry,
  19815. ShapeBufferGeometry: ShapeBufferGeometry,
  19816. SphereGeometry: SphereGeometry,
  19817. SphereBufferGeometry: SphereBufferGeometry,
  19818. TetrahedronGeometry: TetrahedronGeometry,
  19819. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19820. TextGeometry: TextGeometry,
  19821. TextBufferGeometry: TextBufferGeometry,
  19822. TorusGeometry: TorusGeometry,
  19823. TorusBufferGeometry: TorusBufferGeometry,
  19824. TorusKnotGeometry: TorusKnotGeometry,
  19825. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19826. TubeGeometry: TubeGeometry,
  19827. TubeBufferGeometry: TubeBufferGeometry,
  19828. WireframeGeometry: WireframeGeometry
  19829. });
  19830. /**
  19831. * parameters = {
  19832. * color: <THREE.Color>
  19833. * }
  19834. */
  19835. function ShadowMaterial(parameters) {
  19836. Material.call(this);
  19837. this.type = 'ShadowMaterial';
  19838. this.color = new Color(0x000000);
  19839. this.transparent = true;
  19840. this.setValues(parameters);
  19841. }
  19842. ShadowMaterial.prototype = Object.create(Material.prototype);
  19843. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19844. ShadowMaterial.prototype.isShadowMaterial = true;
  19845. ShadowMaterial.prototype.copy = function (source) {
  19846. Material.prototype.copy.call(this, source);
  19847. this.color.copy(source.color);
  19848. return this;
  19849. };
  19850. function RawShaderMaterial(parameters) {
  19851. ShaderMaterial.call(this, parameters);
  19852. this.type = 'RawShaderMaterial';
  19853. }
  19854. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19855. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19856. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19857. /**
  19858. * parameters = {
  19859. * color: <hex>,
  19860. * roughness: <float>,
  19861. * metalness: <float>,
  19862. * opacity: <float>,
  19863. *
  19864. * map: new THREE.Texture( <Image> ),
  19865. *
  19866. * lightMap: new THREE.Texture( <Image> ),
  19867. * lightMapIntensity: <float>
  19868. *
  19869. * aoMap: new THREE.Texture( <Image> ),
  19870. * aoMapIntensity: <float>
  19871. *
  19872. * emissive: <hex>,
  19873. * emissiveIntensity: <float>
  19874. * emissiveMap: new THREE.Texture( <Image> ),
  19875. *
  19876. * bumpMap: new THREE.Texture( <Image> ),
  19877. * bumpScale: <float>,
  19878. *
  19879. * normalMap: new THREE.Texture( <Image> ),
  19880. * normalMapType: THREE.TangentSpaceNormalMap,
  19881. * normalScale: <Vector2>,
  19882. *
  19883. * displacementMap: new THREE.Texture( <Image> ),
  19884. * displacementScale: <float>,
  19885. * displacementBias: <float>,
  19886. *
  19887. * roughnessMap: new THREE.Texture( <Image> ),
  19888. *
  19889. * metalnessMap: new THREE.Texture( <Image> ),
  19890. *
  19891. * alphaMap: new THREE.Texture( <Image> ),
  19892. *
  19893. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19894. * envMapIntensity: <float>
  19895. *
  19896. * refractionRatio: <float>,
  19897. *
  19898. * wireframe: <boolean>,
  19899. * wireframeLinewidth: <float>,
  19900. *
  19901. * skinning: <bool>,
  19902. * morphTargets: <bool>,
  19903. * morphNormals: <bool>
  19904. * }
  19905. */
  19906. function MeshStandardMaterial(parameters) {
  19907. Material.call(this);
  19908. this.defines = {
  19909. 'STANDARD': ''
  19910. };
  19911. this.type = 'MeshStandardMaterial';
  19912. this.color = new Color(0xffffff); // diffuse
  19913. this.roughness = 1.0;
  19914. this.metalness = 0.0;
  19915. this.map = null;
  19916. this.lightMap = null;
  19917. this.lightMapIntensity = 1.0;
  19918. this.aoMap = null;
  19919. this.aoMapIntensity = 1.0;
  19920. this.emissive = new Color(0x000000);
  19921. this.emissiveIntensity = 1.0;
  19922. this.emissiveMap = null;
  19923. this.bumpMap = null;
  19924. this.bumpScale = 1;
  19925. this.normalMap = null;
  19926. this.normalMapType = TangentSpaceNormalMap;
  19927. this.normalScale = new Vector2(1, 1);
  19928. this.displacementMap = null;
  19929. this.displacementScale = 1;
  19930. this.displacementBias = 0;
  19931. this.roughnessMap = null;
  19932. this.metalnessMap = null;
  19933. this.alphaMap = null;
  19934. this.envMap = null;
  19935. this.envMapIntensity = 1.0;
  19936. this.refractionRatio = 0.98;
  19937. this.wireframe = false;
  19938. this.wireframeLinewidth = 1;
  19939. this.wireframeLinecap = 'round';
  19940. this.wireframeLinejoin = 'round';
  19941. this.skinning = false;
  19942. this.morphTargets = false;
  19943. this.morphNormals = false;
  19944. this.vertexTangents = false;
  19945. this.setValues(parameters);
  19946. }
  19947. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19948. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19949. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19950. MeshStandardMaterial.prototype.copy = function (source) {
  19951. Material.prototype.copy.call(this, source);
  19952. this.defines = {
  19953. 'STANDARD': ''
  19954. };
  19955. this.color.copy(source.color);
  19956. this.roughness = source.roughness;
  19957. this.metalness = source.metalness;
  19958. this.map = source.map;
  19959. this.lightMap = source.lightMap;
  19960. this.lightMapIntensity = source.lightMapIntensity;
  19961. this.aoMap = source.aoMap;
  19962. this.aoMapIntensity = source.aoMapIntensity;
  19963. this.emissive.copy(source.emissive);
  19964. this.emissiveMap = source.emissiveMap;
  19965. this.emissiveIntensity = source.emissiveIntensity;
  19966. this.bumpMap = source.bumpMap;
  19967. this.bumpScale = source.bumpScale;
  19968. this.normalMap = source.normalMap;
  19969. this.normalMapType = source.normalMapType;
  19970. this.normalScale.copy(source.normalScale);
  19971. this.displacementMap = source.displacementMap;
  19972. this.displacementScale = source.displacementScale;
  19973. this.displacementBias = source.displacementBias;
  19974. this.roughnessMap = source.roughnessMap;
  19975. this.metalnessMap = source.metalnessMap;
  19976. this.alphaMap = source.alphaMap;
  19977. this.envMap = source.envMap;
  19978. this.envMapIntensity = source.envMapIntensity;
  19979. this.refractionRatio = source.refractionRatio;
  19980. this.wireframe = source.wireframe;
  19981. this.wireframeLinewidth = source.wireframeLinewidth;
  19982. this.wireframeLinecap = source.wireframeLinecap;
  19983. this.wireframeLinejoin = source.wireframeLinejoin;
  19984. this.skinning = source.skinning;
  19985. this.morphTargets = source.morphTargets;
  19986. this.morphNormals = source.morphNormals;
  19987. this.vertexTangents = source.vertexTangents;
  19988. return this;
  19989. };
  19990. /**
  19991. * parameters = {
  19992. * clearcoat: <float>,
  19993. * clearcoatMap: new THREE.Texture( <Image> ),
  19994. * clearcoatRoughness: <float>,
  19995. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19996. * clearcoatNormalScale: <Vector2>,
  19997. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19998. *
  19999. * reflectivity: <float>,
  20000. * ior: <float>,
  20001. *
  20002. * sheen: <Color>,
  20003. *
  20004. * transmission: <float>,
  20005. * transmissionMap: new THREE.Texture( <Image> )
  20006. * }
  20007. */
  20008. function MeshPhysicalMaterial(parameters) {
  20009. MeshStandardMaterial.call(this);
  20010. this.defines = {
  20011. 'STANDARD': '',
  20012. 'PHYSICAL': ''
  20013. };
  20014. this.type = 'MeshPhysicalMaterial';
  20015. this.clearcoat = 0.0;
  20016. this.clearcoatMap = null;
  20017. this.clearcoatRoughness = 0.0;
  20018. this.clearcoatRoughnessMap = null;
  20019. this.clearcoatNormalScale = new Vector2(1, 1);
  20020. this.clearcoatNormalMap = null;
  20021. this.reflectivity = 0.5; // maps to F0 = 0.04
  20022. Object.defineProperty(this, 'ior', {
  20023. get: function get() {
  20024. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  20025. },
  20026. set: function set(ior) {
  20027. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  20028. }
  20029. });
  20030. this.sheen = null; // null will disable sheen bsdf
  20031. this.transmission = 0.0;
  20032. this.transmissionMap = null;
  20033. this.setValues(parameters);
  20034. }
  20035. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  20036. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20037. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20038. MeshPhysicalMaterial.prototype.copy = function (source) {
  20039. MeshStandardMaterial.prototype.copy.call(this, source);
  20040. this.defines = {
  20041. 'STANDARD': '',
  20042. 'PHYSICAL': ''
  20043. };
  20044. this.clearcoat = source.clearcoat;
  20045. this.clearcoatMap = source.clearcoatMap;
  20046. this.clearcoatRoughness = source.clearcoatRoughness;
  20047. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  20048. this.clearcoatNormalMap = source.clearcoatNormalMap;
  20049. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  20050. this.reflectivity = source.reflectivity;
  20051. if (source.sheen) {
  20052. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  20053. } else {
  20054. this.sheen = null;
  20055. }
  20056. this.transmission = source.transmission;
  20057. this.transmissionMap = source.transmissionMap;
  20058. return this;
  20059. };
  20060. /**
  20061. * parameters = {
  20062. * color: <hex>,
  20063. * specular: <hex>,
  20064. * shininess: <float>,
  20065. * opacity: <float>,
  20066. *
  20067. * map: new THREE.Texture( <Image> ),
  20068. *
  20069. * lightMap: new THREE.Texture( <Image> ),
  20070. * lightMapIntensity: <float>
  20071. *
  20072. * aoMap: new THREE.Texture( <Image> ),
  20073. * aoMapIntensity: <float>
  20074. *
  20075. * emissive: <hex>,
  20076. * emissiveIntensity: <float>
  20077. * emissiveMap: new THREE.Texture( <Image> ),
  20078. *
  20079. * bumpMap: new THREE.Texture( <Image> ),
  20080. * bumpScale: <float>,
  20081. *
  20082. * normalMap: new THREE.Texture( <Image> ),
  20083. * normalMapType: THREE.TangentSpaceNormalMap,
  20084. * normalScale: <Vector2>,
  20085. *
  20086. * displacementMap: new THREE.Texture( <Image> ),
  20087. * displacementScale: <float>,
  20088. * displacementBias: <float>,
  20089. *
  20090. * specularMap: new THREE.Texture( <Image> ),
  20091. *
  20092. * alphaMap: new THREE.Texture( <Image> ),
  20093. *
  20094. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20095. * combine: THREE.MultiplyOperation,
  20096. * reflectivity: <float>,
  20097. * refractionRatio: <float>,
  20098. *
  20099. * wireframe: <boolean>,
  20100. * wireframeLinewidth: <float>,
  20101. *
  20102. * skinning: <bool>,
  20103. * morphTargets: <bool>,
  20104. * morphNormals: <bool>
  20105. * }
  20106. */
  20107. function MeshPhongMaterial(parameters) {
  20108. Material.call(this);
  20109. this.type = 'MeshPhongMaterial';
  20110. this.color = new Color(0xffffff); // diffuse
  20111. this.specular = new Color(0x111111);
  20112. this.shininess = 30;
  20113. this.map = 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.specularMap = null;
  20130. this.alphaMap = null;
  20131. this.envMap = null;
  20132. this.combine = MultiplyOperation;
  20133. this.reflectivity = 1;
  20134. this.refractionRatio = 0.98;
  20135. this.wireframe = false;
  20136. this.wireframeLinewidth = 1;
  20137. this.wireframeLinecap = 'round';
  20138. this.wireframeLinejoin = 'round';
  20139. this.skinning = false;
  20140. this.morphTargets = false;
  20141. this.morphNormals = false;
  20142. this.setValues(parameters);
  20143. }
  20144. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  20145. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20146. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20147. MeshPhongMaterial.prototype.copy = function (source) {
  20148. Material.prototype.copy.call(this, source);
  20149. this.color.copy(source.color);
  20150. this.specular.copy(source.specular);
  20151. this.shininess = source.shininess;
  20152. this.map = source.map;
  20153. this.lightMap = source.lightMap;
  20154. this.lightMapIntensity = source.lightMapIntensity;
  20155. this.aoMap = source.aoMap;
  20156. this.aoMapIntensity = source.aoMapIntensity;
  20157. this.emissive.copy(source.emissive);
  20158. this.emissiveMap = source.emissiveMap;
  20159. this.emissiveIntensity = source.emissiveIntensity;
  20160. this.bumpMap = source.bumpMap;
  20161. this.bumpScale = source.bumpScale;
  20162. this.normalMap = source.normalMap;
  20163. this.normalMapType = source.normalMapType;
  20164. this.normalScale.copy(source.normalScale);
  20165. this.displacementMap = source.displacementMap;
  20166. this.displacementScale = source.displacementScale;
  20167. this.displacementBias = source.displacementBias;
  20168. this.specularMap = source.specularMap;
  20169. this.alphaMap = source.alphaMap;
  20170. this.envMap = source.envMap;
  20171. this.combine = source.combine;
  20172. this.reflectivity = source.reflectivity;
  20173. this.refractionRatio = source.refractionRatio;
  20174. this.wireframe = source.wireframe;
  20175. this.wireframeLinewidth = source.wireframeLinewidth;
  20176. this.wireframeLinecap = source.wireframeLinecap;
  20177. this.wireframeLinejoin = source.wireframeLinejoin;
  20178. this.skinning = source.skinning;
  20179. this.morphTargets = source.morphTargets;
  20180. this.morphNormals = source.morphNormals;
  20181. return this;
  20182. };
  20183. /**
  20184. * parameters = {
  20185. * color: <hex>,
  20186. *
  20187. * map: new THREE.Texture( <Image> ),
  20188. * gradientMap: new THREE.Texture( <Image> ),
  20189. *
  20190. * lightMap: new THREE.Texture( <Image> ),
  20191. * lightMapIntensity: <float>
  20192. *
  20193. * aoMap: new THREE.Texture( <Image> ),
  20194. * aoMapIntensity: <float>
  20195. *
  20196. * emissive: <hex>,
  20197. * emissiveIntensity: <float>
  20198. * emissiveMap: new THREE.Texture( <Image> ),
  20199. *
  20200. * bumpMap: new THREE.Texture( <Image> ),
  20201. * bumpScale: <float>,
  20202. *
  20203. * normalMap: new THREE.Texture( <Image> ),
  20204. * normalMapType: THREE.TangentSpaceNormalMap,
  20205. * normalScale: <Vector2>,
  20206. *
  20207. * displacementMap: new THREE.Texture( <Image> ),
  20208. * displacementScale: <float>,
  20209. * displacementBias: <float>,
  20210. *
  20211. * alphaMap: new THREE.Texture( <Image> ),
  20212. *
  20213. * wireframe: <boolean>,
  20214. * wireframeLinewidth: <float>,
  20215. *
  20216. * skinning: <bool>,
  20217. * morphTargets: <bool>,
  20218. * morphNormals: <bool>
  20219. * }
  20220. */
  20221. function MeshToonMaterial(parameters) {
  20222. Material.call(this);
  20223. this.defines = {
  20224. 'TOON': ''
  20225. };
  20226. this.type = 'MeshToonMaterial';
  20227. this.color = new Color(0xffffff);
  20228. this.map = null;
  20229. this.gradientMap = null;
  20230. this.lightMap = null;
  20231. this.lightMapIntensity = 1.0;
  20232. this.aoMap = null;
  20233. this.aoMapIntensity = 1.0;
  20234. this.emissive = new Color(0x000000);
  20235. this.emissiveIntensity = 1.0;
  20236. this.emissiveMap = null;
  20237. this.bumpMap = null;
  20238. this.bumpScale = 1;
  20239. this.normalMap = null;
  20240. this.normalMapType = TangentSpaceNormalMap;
  20241. this.normalScale = new Vector2(1, 1);
  20242. this.displacementMap = null;
  20243. this.displacementScale = 1;
  20244. this.displacementBias = 0;
  20245. this.alphaMap = null;
  20246. this.wireframe = false;
  20247. this.wireframeLinewidth = 1;
  20248. this.wireframeLinecap = 'round';
  20249. this.wireframeLinejoin = 'round';
  20250. this.skinning = false;
  20251. this.morphTargets = false;
  20252. this.morphNormals = false;
  20253. this.setValues(parameters);
  20254. }
  20255. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20256. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20257. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20258. MeshToonMaterial.prototype.copy = function (source) {
  20259. Material.prototype.copy.call(this, source);
  20260. this.color.copy(source.color);
  20261. this.map = source.map;
  20262. this.gradientMap = source.gradientMap;
  20263. this.lightMap = source.lightMap;
  20264. this.lightMapIntensity = source.lightMapIntensity;
  20265. this.aoMap = source.aoMap;
  20266. this.aoMapIntensity = source.aoMapIntensity;
  20267. this.emissive.copy(source.emissive);
  20268. this.emissiveMap = source.emissiveMap;
  20269. this.emissiveIntensity = source.emissiveIntensity;
  20270. this.bumpMap = source.bumpMap;
  20271. this.bumpScale = source.bumpScale;
  20272. this.normalMap = source.normalMap;
  20273. this.normalMapType = source.normalMapType;
  20274. this.normalScale.copy(source.normalScale);
  20275. this.displacementMap = source.displacementMap;
  20276. this.displacementScale = source.displacementScale;
  20277. this.displacementBias = source.displacementBias;
  20278. this.alphaMap = source.alphaMap;
  20279. this.wireframe = source.wireframe;
  20280. this.wireframeLinewidth = source.wireframeLinewidth;
  20281. this.wireframeLinecap = source.wireframeLinecap;
  20282. this.wireframeLinejoin = source.wireframeLinejoin;
  20283. this.skinning = source.skinning;
  20284. this.morphTargets = source.morphTargets;
  20285. this.morphNormals = source.morphNormals;
  20286. return this;
  20287. };
  20288. /**
  20289. * parameters = {
  20290. * opacity: <float>,
  20291. *
  20292. * bumpMap: new THREE.Texture( <Image> ),
  20293. * bumpScale: <float>,
  20294. *
  20295. * normalMap: new THREE.Texture( <Image> ),
  20296. * normalMapType: THREE.TangentSpaceNormalMap,
  20297. * normalScale: <Vector2>,
  20298. *
  20299. * displacementMap: new THREE.Texture( <Image> ),
  20300. * displacementScale: <float>,
  20301. * displacementBias: <float>,
  20302. *
  20303. * wireframe: <boolean>,
  20304. * wireframeLinewidth: <float>
  20305. *
  20306. * skinning: <bool>,
  20307. * morphTargets: <bool>,
  20308. * morphNormals: <bool>
  20309. * }
  20310. */
  20311. function MeshNormalMaterial(parameters) {
  20312. Material.call(this);
  20313. this.type = 'MeshNormalMaterial';
  20314. this.bumpMap = null;
  20315. this.bumpScale = 1;
  20316. this.normalMap = null;
  20317. this.normalMapType = TangentSpaceNormalMap;
  20318. this.normalScale = new Vector2(1, 1);
  20319. this.displacementMap = null;
  20320. this.displacementScale = 1;
  20321. this.displacementBias = 0;
  20322. this.wireframe = false;
  20323. this.wireframeLinewidth = 1;
  20324. this.fog = false;
  20325. this.skinning = false;
  20326. this.morphTargets = false;
  20327. this.morphNormals = false;
  20328. this.setValues(parameters);
  20329. }
  20330. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20331. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20332. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20333. MeshNormalMaterial.prototype.copy = function (source) {
  20334. Material.prototype.copy.call(this, source);
  20335. this.bumpMap = source.bumpMap;
  20336. this.bumpScale = source.bumpScale;
  20337. this.normalMap = source.normalMap;
  20338. this.normalMapType = source.normalMapType;
  20339. this.normalScale.copy(source.normalScale);
  20340. this.displacementMap = source.displacementMap;
  20341. this.displacementScale = source.displacementScale;
  20342. this.displacementBias = source.displacementBias;
  20343. this.wireframe = source.wireframe;
  20344. this.wireframeLinewidth = source.wireframeLinewidth;
  20345. this.skinning = source.skinning;
  20346. this.morphTargets = source.morphTargets;
  20347. this.morphNormals = source.morphNormals;
  20348. return this;
  20349. };
  20350. /**
  20351. * parameters = {
  20352. * color: <hex>,
  20353. * opacity: <float>,
  20354. *
  20355. * map: new THREE.Texture( <Image> ),
  20356. *
  20357. * lightMap: new THREE.Texture( <Image> ),
  20358. * lightMapIntensity: <float>
  20359. *
  20360. * aoMap: new THREE.Texture( <Image> ),
  20361. * aoMapIntensity: <float>
  20362. *
  20363. * emissive: <hex>,
  20364. * emissiveIntensity: <float>
  20365. * emissiveMap: new THREE.Texture( <Image> ),
  20366. *
  20367. * specularMap: new THREE.Texture( <Image> ),
  20368. *
  20369. * alphaMap: new THREE.Texture( <Image> ),
  20370. *
  20371. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20372. * combine: THREE.Multiply,
  20373. * reflectivity: <float>,
  20374. * refractionRatio: <float>,
  20375. *
  20376. * wireframe: <boolean>,
  20377. * wireframeLinewidth: <float>,
  20378. *
  20379. * skinning: <bool>,
  20380. * morphTargets: <bool>,
  20381. * morphNormals: <bool>
  20382. * }
  20383. */
  20384. function MeshLambertMaterial(parameters) {
  20385. Material.call(this);
  20386. this.type = 'MeshLambertMaterial';
  20387. this.color = new Color(0xffffff); // diffuse
  20388. this.map = null;
  20389. this.lightMap = null;
  20390. this.lightMapIntensity = 1.0;
  20391. this.aoMap = null;
  20392. this.aoMapIntensity = 1.0;
  20393. this.emissive = new Color(0x000000);
  20394. this.emissiveIntensity = 1.0;
  20395. this.emissiveMap = null;
  20396. this.specularMap = null;
  20397. this.alphaMap = null;
  20398. this.envMap = null;
  20399. this.combine = MultiplyOperation;
  20400. this.reflectivity = 1;
  20401. this.refractionRatio = 0.98;
  20402. this.wireframe = false;
  20403. this.wireframeLinewidth = 1;
  20404. this.wireframeLinecap = 'round';
  20405. this.wireframeLinejoin = 'round';
  20406. this.skinning = false;
  20407. this.morphTargets = false;
  20408. this.morphNormals = false;
  20409. this.setValues(parameters);
  20410. }
  20411. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20412. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20413. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20414. MeshLambertMaterial.prototype.copy = function (source) {
  20415. Material.prototype.copy.call(this, source);
  20416. this.color.copy(source.color);
  20417. this.map = source.map;
  20418. this.lightMap = source.lightMap;
  20419. this.lightMapIntensity = source.lightMapIntensity;
  20420. this.aoMap = source.aoMap;
  20421. this.aoMapIntensity = source.aoMapIntensity;
  20422. this.emissive.copy(source.emissive);
  20423. this.emissiveMap = source.emissiveMap;
  20424. this.emissiveIntensity = source.emissiveIntensity;
  20425. this.specularMap = source.specularMap;
  20426. this.alphaMap = source.alphaMap;
  20427. this.envMap = source.envMap;
  20428. this.combine = source.combine;
  20429. this.reflectivity = source.reflectivity;
  20430. this.refractionRatio = source.refractionRatio;
  20431. this.wireframe = source.wireframe;
  20432. this.wireframeLinewidth = source.wireframeLinewidth;
  20433. this.wireframeLinecap = source.wireframeLinecap;
  20434. this.wireframeLinejoin = source.wireframeLinejoin;
  20435. this.skinning = source.skinning;
  20436. this.morphTargets = source.morphTargets;
  20437. this.morphNormals = source.morphNormals;
  20438. return this;
  20439. };
  20440. /**
  20441. * parameters = {
  20442. * color: <hex>,
  20443. * opacity: <float>,
  20444. *
  20445. * matcap: new THREE.Texture( <Image> ),
  20446. *
  20447. * map: new THREE.Texture( <Image> ),
  20448. *
  20449. * bumpMap: new THREE.Texture( <Image> ),
  20450. * bumpScale: <float>,
  20451. *
  20452. * normalMap: new THREE.Texture( <Image> ),
  20453. * normalMapType: THREE.TangentSpaceNormalMap,
  20454. * normalScale: <Vector2>,
  20455. *
  20456. * displacementMap: new THREE.Texture( <Image> ),
  20457. * displacementScale: <float>,
  20458. * displacementBias: <float>,
  20459. *
  20460. * alphaMap: new THREE.Texture( <Image> ),
  20461. *
  20462. * skinning: <bool>,
  20463. * morphTargets: <bool>,
  20464. * morphNormals: <bool>
  20465. * }
  20466. */
  20467. function MeshMatcapMaterial(parameters) {
  20468. Material.call(this);
  20469. this.defines = {
  20470. 'MATCAP': ''
  20471. };
  20472. this.type = 'MeshMatcapMaterial';
  20473. this.color = new Color(0xffffff); // diffuse
  20474. this.matcap = null;
  20475. this.map = null;
  20476. this.bumpMap = null;
  20477. this.bumpScale = 1;
  20478. this.normalMap = null;
  20479. this.normalMapType = TangentSpaceNormalMap;
  20480. this.normalScale = new Vector2(1, 1);
  20481. this.displacementMap = null;
  20482. this.displacementScale = 1;
  20483. this.displacementBias = 0;
  20484. this.alphaMap = null;
  20485. this.skinning = false;
  20486. this.morphTargets = false;
  20487. this.morphNormals = false;
  20488. this.setValues(parameters);
  20489. }
  20490. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20491. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20492. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20493. MeshMatcapMaterial.prototype.copy = function (source) {
  20494. Material.prototype.copy.call(this, source);
  20495. this.defines = {
  20496. 'MATCAP': ''
  20497. };
  20498. this.color.copy(source.color);
  20499. this.matcap = source.matcap;
  20500. this.map = source.map;
  20501. this.bumpMap = source.bumpMap;
  20502. this.bumpScale = source.bumpScale;
  20503. this.normalMap = source.normalMap;
  20504. this.normalMapType = source.normalMapType;
  20505. this.normalScale.copy(source.normalScale);
  20506. this.displacementMap = source.displacementMap;
  20507. this.displacementScale = source.displacementScale;
  20508. this.displacementBias = source.displacementBias;
  20509. this.alphaMap = source.alphaMap;
  20510. this.skinning = source.skinning;
  20511. this.morphTargets = source.morphTargets;
  20512. this.morphNormals = source.morphNormals;
  20513. return this;
  20514. };
  20515. /**
  20516. * parameters = {
  20517. * color: <hex>,
  20518. * opacity: <float>,
  20519. *
  20520. * linewidth: <float>,
  20521. *
  20522. * scale: <float>,
  20523. * dashSize: <float>,
  20524. * gapSize: <float>
  20525. * }
  20526. */
  20527. function LineDashedMaterial(parameters) {
  20528. LineBasicMaterial.call(this);
  20529. this.type = 'LineDashedMaterial';
  20530. this.scale = 1;
  20531. this.dashSize = 3;
  20532. this.gapSize = 1;
  20533. this.setValues(parameters);
  20534. }
  20535. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20536. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20537. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20538. LineDashedMaterial.prototype.copy = function (source) {
  20539. LineBasicMaterial.prototype.copy.call(this, source);
  20540. this.scale = source.scale;
  20541. this.dashSize = source.dashSize;
  20542. this.gapSize = source.gapSize;
  20543. return this;
  20544. };
  20545. var Materials = /*#__PURE__*/Object.freeze({
  20546. __proto__: null,
  20547. ShadowMaterial: ShadowMaterial,
  20548. SpriteMaterial: SpriteMaterial,
  20549. RawShaderMaterial: RawShaderMaterial,
  20550. ShaderMaterial: ShaderMaterial,
  20551. PointsMaterial: PointsMaterial,
  20552. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20553. MeshStandardMaterial: MeshStandardMaterial,
  20554. MeshPhongMaterial: MeshPhongMaterial,
  20555. MeshToonMaterial: MeshToonMaterial,
  20556. MeshNormalMaterial: MeshNormalMaterial,
  20557. MeshLambertMaterial: MeshLambertMaterial,
  20558. MeshDepthMaterial: MeshDepthMaterial,
  20559. MeshDistanceMaterial: MeshDistanceMaterial,
  20560. MeshBasicMaterial: MeshBasicMaterial,
  20561. MeshMatcapMaterial: MeshMatcapMaterial,
  20562. LineDashedMaterial: LineDashedMaterial,
  20563. LineBasicMaterial: LineBasicMaterial,
  20564. Material: Material
  20565. });
  20566. var AnimationUtils = {
  20567. // same as Array.prototype.slice, but also works on typed arrays
  20568. arraySlice: function arraySlice(array, from, to) {
  20569. if (AnimationUtils.isTypedArray(array)) {
  20570. // in ios9 array.subarray(from, undefined) will return empty array
  20571. // but array.subarray(from) or array.subarray(from, len) is correct
  20572. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20573. }
  20574. return array.slice(from, to);
  20575. },
  20576. // converts an array to a specific type
  20577. convertArray: function convertArray(array, type, forceClone) {
  20578. if (!array || // let 'undefined' and 'null' pass
  20579. !forceClone && array.constructor === type) return array;
  20580. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20581. return new type(array); // create typed array
  20582. }
  20583. return Array.prototype.slice.call(array); // create Array
  20584. },
  20585. isTypedArray: function isTypedArray(object) {
  20586. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20587. },
  20588. // returns an array by which times and values can be sorted
  20589. getKeyframeOrder: function getKeyframeOrder(times) {
  20590. function compareTime(i, j) {
  20591. return times[i] - times[j];
  20592. }
  20593. var n = times.length;
  20594. var result = new Array(n);
  20595. for (var i = 0; i !== n; ++i) {
  20596. result[i] = i;
  20597. }
  20598. result.sort(compareTime);
  20599. return result;
  20600. },
  20601. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20602. sortedArray: function sortedArray(values, stride, order) {
  20603. var nValues = values.length;
  20604. var result = new values.constructor(nValues);
  20605. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20606. var srcOffset = order[i] * stride;
  20607. for (var j = 0; j !== stride; ++j) {
  20608. result[dstOffset++] = values[srcOffset + j];
  20609. }
  20610. }
  20611. return result;
  20612. },
  20613. // function for parsing AOS keyframe formats
  20614. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20615. var i = 1,
  20616. key = jsonKeys[0];
  20617. while (key !== undefined && key[valuePropertyName] === undefined) {
  20618. key = jsonKeys[i++];
  20619. }
  20620. if (key === undefined) return; // no data
  20621. var value = key[valuePropertyName];
  20622. if (value === undefined) return; // no data
  20623. if (Array.isArray(value)) {
  20624. do {
  20625. value = key[valuePropertyName];
  20626. if (value !== undefined) {
  20627. times.push(key.time);
  20628. values.push.apply(values, value); // push all elements
  20629. }
  20630. key = jsonKeys[i++];
  20631. } while (key !== undefined);
  20632. } else if (value.toArray !== undefined) {
  20633. // ...assume THREE.Math-ish
  20634. do {
  20635. value = key[valuePropertyName];
  20636. if (value !== undefined) {
  20637. times.push(key.time);
  20638. value.toArray(values, values.length);
  20639. }
  20640. key = jsonKeys[i++];
  20641. } while (key !== undefined);
  20642. } else {
  20643. // otherwise push as-is
  20644. do {
  20645. value = key[valuePropertyName];
  20646. if (value !== undefined) {
  20647. times.push(key.time);
  20648. values.push(value);
  20649. }
  20650. key = jsonKeys[i++];
  20651. } while (key !== undefined);
  20652. }
  20653. },
  20654. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20655. fps = fps || 30;
  20656. var clip = sourceClip.clone();
  20657. clip.name = name;
  20658. var tracks = [];
  20659. for (var i = 0; i < clip.tracks.length; ++i) {
  20660. var track = clip.tracks[i];
  20661. var valueSize = track.getValueSize();
  20662. var times = [];
  20663. var values = [];
  20664. for (var j = 0; j < track.times.length; ++j) {
  20665. var frame = track.times[j] * fps;
  20666. if (frame < startFrame || frame >= endFrame) continue;
  20667. times.push(track.times[j]);
  20668. for (var k = 0; k < valueSize; ++k) {
  20669. values.push(track.values[j * valueSize + k]);
  20670. }
  20671. }
  20672. if (times.length === 0) continue;
  20673. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20674. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20675. tracks.push(track);
  20676. }
  20677. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20678. var minStartTime = Infinity;
  20679. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20680. if (minStartTime > clip.tracks[_i].times[0]) {
  20681. minStartTime = clip.tracks[_i].times[0];
  20682. }
  20683. } // shift all tracks such that clip begins at t=0
  20684. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20685. clip.tracks[_i2].shift(-1 * minStartTime);
  20686. }
  20687. clip.resetDuration();
  20688. return clip;
  20689. },
  20690. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20691. if (referenceFrame === void 0) {
  20692. referenceFrame = 0;
  20693. }
  20694. if (referenceClip === void 0) {
  20695. referenceClip = targetClip;
  20696. }
  20697. if (fps === void 0) {
  20698. fps = 30;
  20699. }
  20700. if (fps <= 0) fps = 30;
  20701. var numTracks = referenceClip.tracks.length;
  20702. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20703. var _loop = function _loop(i) {
  20704. var referenceTrack = referenceClip.tracks[i];
  20705. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20706. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20707. var targetTrack = targetClip.tracks.find(function (track) {
  20708. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20709. });
  20710. if (targetTrack === undefined) return "continue";
  20711. var referenceOffset = 0;
  20712. var referenceValueSize = referenceTrack.getValueSize();
  20713. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20714. referenceOffset = referenceValueSize / 3;
  20715. }
  20716. var targetOffset = 0;
  20717. var targetValueSize = targetTrack.getValueSize();
  20718. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20719. targetOffset = targetValueSize / 3;
  20720. }
  20721. var lastIndex = referenceTrack.times.length - 1;
  20722. var referenceValue = void 0; // Find the value to subtract out of the track
  20723. if (referenceTime <= referenceTrack.times[0]) {
  20724. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20725. var startIndex = referenceOffset;
  20726. var endIndex = referenceValueSize - referenceOffset;
  20727. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20728. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20729. // Reference frame is after the last keyframe, so just use the last keyframe
  20730. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20731. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20732. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20733. } else {
  20734. // Interpolate to the reference value
  20735. var interpolant = referenceTrack.createInterpolant();
  20736. var _startIndex2 = referenceOffset;
  20737. var _endIndex2 = referenceValueSize - referenceOffset;
  20738. interpolant.evaluate(referenceTime);
  20739. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20740. } // Conjugate the quaternion
  20741. if (referenceTrackType === 'quaternion') {
  20742. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20743. referenceQuat.toArray(referenceValue);
  20744. } // Subtract the reference value from all of the track values
  20745. var numTimes = targetTrack.times.length;
  20746. for (var j = 0; j < numTimes; ++j) {
  20747. var valueStart = j * targetValueSize + targetOffset;
  20748. if (referenceTrackType === 'quaternion') {
  20749. // Multiply the conjugate for quaternion track types
  20750. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20751. } else {
  20752. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20753. for (var k = 0; k < valueEnd; ++k) {
  20754. targetTrack.values[valueStart + k] -= referenceValue[k];
  20755. }
  20756. }
  20757. }
  20758. };
  20759. for (var i = 0; i < numTracks; ++i) {
  20760. var _ret = _loop(i);
  20761. if (_ret === "continue") continue;
  20762. }
  20763. targetClip.blendMode = AdditiveAnimationBlendMode;
  20764. return targetClip;
  20765. }
  20766. };
  20767. /**
  20768. * Abstract base class of interpolants over parametric samples.
  20769. *
  20770. * The parameter domain is one dimensional, typically the time or a path
  20771. * along a curve defined by the data.
  20772. *
  20773. * The sample values can have any dimensionality and derived classes may
  20774. * apply special interpretations to the data.
  20775. *
  20776. * This class provides the interval seek in a Template Method, deferring
  20777. * the actual interpolation to derived classes.
  20778. *
  20779. * Time complexity is O(1) for linear access crossing at most two points
  20780. * and O(log N) for random access, where N is the number of positions.
  20781. *
  20782. * References:
  20783. *
  20784. * http://www.oodesign.com/template-method-pattern.html
  20785. *
  20786. */
  20787. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20788. this.parameterPositions = parameterPositions;
  20789. this._cachedIndex = 0;
  20790. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20791. this.sampleValues = sampleValues;
  20792. this.valueSize = sampleSize;
  20793. }
  20794. Object.assign(Interpolant.prototype, {
  20795. evaluate: function evaluate(t) {
  20796. var pp = this.parameterPositions;
  20797. var i1 = this._cachedIndex,
  20798. t1 = pp[i1],
  20799. t0 = pp[i1 - 1];
  20800. validate_interval: {
  20801. seek: {
  20802. var right;
  20803. linear_scan: {
  20804. //- See http://jsperf.com/comparison-to-undefined/3
  20805. //- slower code:
  20806. //-
  20807. //- if ( t >= t1 || t1 === undefined ) {
  20808. forward_scan: if (!(t < t1)) {
  20809. for (var giveUpAt = i1 + 2;;) {
  20810. if (t1 === undefined) {
  20811. if (t < t0) break forward_scan; // after end
  20812. i1 = pp.length;
  20813. this._cachedIndex = i1;
  20814. return this.afterEnd_(i1 - 1, t, t0);
  20815. }
  20816. if (i1 === giveUpAt) break; // this loop
  20817. t0 = t1;
  20818. t1 = pp[++i1];
  20819. if (t < t1) {
  20820. // we have arrived at the sought interval
  20821. break seek;
  20822. }
  20823. } // prepare binary search on the right side of the index
  20824. right = pp.length;
  20825. break linear_scan;
  20826. } //- slower code:
  20827. //- if ( t < t0 || t0 === undefined ) {
  20828. if (!(t >= t0)) {
  20829. // looping?
  20830. var t1global = pp[1];
  20831. if (t < t1global) {
  20832. i1 = 2; // + 1, using the scan for the details
  20833. t0 = t1global;
  20834. } // linear reverse scan
  20835. for (var _giveUpAt = i1 - 2;;) {
  20836. if (t0 === undefined) {
  20837. // before start
  20838. this._cachedIndex = 0;
  20839. return this.beforeStart_(0, t, t1);
  20840. }
  20841. if (i1 === _giveUpAt) break; // this loop
  20842. t1 = t0;
  20843. t0 = pp[--i1 - 1];
  20844. if (t >= t0) {
  20845. // we have arrived at the sought interval
  20846. break seek;
  20847. }
  20848. } // prepare binary search on the left side of the index
  20849. right = i1;
  20850. i1 = 0;
  20851. break linear_scan;
  20852. } // the interval is valid
  20853. break validate_interval;
  20854. } // linear scan
  20855. // binary search
  20856. while (i1 < right) {
  20857. var mid = i1 + right >>> 1;
  20858. if (t < pp[mid]) {
  20859. right = mid;
  20860. } else {
  20861. i1 = mid + 1;
  20862. }
  20863. }
  20864. t1 = pp[i1];
  20865. t0 = pp[i1 - 1]; // check boundary cases, again
  20866. if (t0 === undefined) {
  20867. this._cachedIndex = 0;
  20868. return this.beforeStart_(0, t, t1);
  20869. }
  20870. if (t1 === undefined) {
  20871. i1 = pp.length;
  20872. this._cachedIndex = i1;
  20873. return this.afterEnd_(i1 - 1, t0, t);
  20874. }
  20875. } // seek
  20876. this._cachedIndex = i1;
  20877. this.intervalChanged_(i1, t0, t1);
  20878. } // validate_interval
  20879. return this.interpolate_(i1, t0, t, t1);
  20880. },
  20881. settings: null,
  20882. // optional, subclass-specific settings structure
  20883. // Note: The indirection allows central control of many interpolants.
  20884. // --- Protected interface
  20885. DefaultSettings_: {},
  20886. getSettings_: function getSettings_() {
  20887. return this.settings || this.DefaultSettings_;
  20888. },
  20889. copySampleValue_: function copySampleValue_(index) {
  20890. // copies a sample value to the result buffer
  20891. var result = this.resultBuffer,
  20892. values = this.sampleValues,
  20893. stride = this.valueSize,
  20894. offset = index * stride;
  20895. for (var i = 0; i !== stride; ++i) {
  20896. result[i] = values[offset + i];
  20897. }
  20898. return result;
  20899. },
  20900. // Template methods for derived classes:
  20901. interpolate_: function interpolate_()
  20902. /* i1, t0, t, t1 */
  20903. {
  20904. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20905. },
  20906. intervalChanged_: function intervalChanged_()
  20907. /* i1, t0, t1 */
  20908. {// empty
  20909. }
  20910. }); // DECLARE ALIAS AFTER assign prototype
  20911. Object.assign(Interpolant.prototype, {
  20912. //( 0, t, t0 ), returns this.resultBuffer
  20913. beforeStart_: Interpolant.prototype.copySampleValue_,
  20914. //( N-1, tN-1, t ), returns this.resultBuffer
  20915. afterEnd_: Interpolant.prototype.copySampleValue_
  20916. });
  20917. /**
  20918. * Fast and simple cubic spline interpolant.
  20919. *
  20920. * It was derived from a Hermitian construction setting the first derivative
  20921. * at each sample position to the linear slope between neighboring positions
  20922. * over their parameter interval.
  20923. */
  20924. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20925. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20926. this._weightPrev = -0;
  20927. this._offsetPrev = -0;
  20928. this._weightNext = -0;
  20929. this._offsetNext = -0;
  20930. }
  20931. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20932. constructor: CubicInterpolant,
  20933. DefaultSettings_: {
  20934. endingStart: ZeroCurvatureEnding,
  20935. endingEnd: ZeroCurvatureEnding
  20936. },
  20937. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20938. var pp = this.parameterPositions;
  20939. var iPrev = i1 - 2,
  20940. iNext = i1 + 1,
  20941. tPrev = pp[iPrev],
  20942. tNext = pp[iNext];
  20943. if (tPrev === undefined) {
  20944. switch (this.getSettings_().endingStart) {
  20945. case ZeroSlopeEnding:
  20946. // f'(t0) = 0
  20947. iPrev = i1;
  20948. tPrev = 2 * t0 - t1;
  20949. break;
  20950. case WrapAroundEnding:
  20951. // use the other end of the curve
  20952. iPrev = pp.length - 2;
  20953. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20954. break;
  20955. default:
  20956. // ZeroCurvatureEnding
  20957. // f''(t0) = 0 a.k.a. Natural Spline
  20958. iPrev = i1;
  20959. tPrev = t1;
  20960. }
  20961. }
  20962. if (tNext === undefined) {
  20963. switch (this.getSettings_().endingEnd) {
  20964. case ZeroSlopeEnding:
  20965. // f'(tN) = 0
  20966. iNext = i1;
  20967. tNext = 2 * t1 - t0;
  20968. break;
  20969. case WrapAroundEnding:
  20970. // use the other end of the curve
  20971. iNext = 1;
  20972. tNext = t1 + pp[1] - pp[0];
  20973. break;
  20974. default:
  20975. // ZeroCurvatureEnding
  20976. // f''(tN) = 0, a.k.a. Natural Spline
  20977. iNext = i1 - 1;
  20978. tNext = t0;
  20979. }
  20980. }
  20981. var halfDt = (t1 - t0) * 0.5,
  20982. stride = this.valueSize;
  20983. this._weightPrev = halfDt / (t0 - tPrev);
  20984. this._weightNext = halfDt / (tNext - t1);
  20985. this._offsetPrev = iPrev * stride;
  20986. this._offsetNext = iNext * stride;
  20987. },
  20988. interpolate_: function interpolate_(i1, t0, t, t1) {
  20989. var result = this.resultBuffer,
  20990. values = this.sampleValues,
  20991. stride = this.valueSize,
  20992. o1 = i1 * stride,
  20993. o0 = o1 - stride,
  20994. oP = this._offsetPrev,
  20995. oN = this._offsetNext,
  20996. wP = this._weightPrev,
  20997. wN = this._weightNext,
  20998. p = (t - t0) / (t1 - t0),
  20999. pp = p * p,
  21000. ppp = pp * p; // evaluate polynomials
  21001. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  21002. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  21003. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  21004. var sN = wN * ppp - wN * pp; // combine data linearly
  21005. for (var i = 0; i !== stride; ++i) {
  21006. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  21007. }
  21008. return result;
  21009. }
  21010. });
  21011. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21012. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21013. }
  21014. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21015. constructor: LinearInterpolant,
  21016. interpolate_: function interpolate_(i1, t0, t, t1) {
  21017. var result = this.resultBuffer,
  21018. values = this.sampleValues,
  21019. stride = this.valueSize,
  21020. offset1 = i1 * stride,
  21021. offset0 = offset1 - stride,
  21022. weight1 = (t - t0) / (t1 - t0),
  21023. weight0 = 1 - weight1;
  21024. for (var i = 0; i !== stride; ++i) {
  21025. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  21026. }
  21027. return result;
  21028. }
  21029. });
  21030. /**
  21031. *
  21032. * Interpolant that evaluates to the sample value at the position preceeding
  21033. * the parameter.
  21034. */
  21035. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21036. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21037. }
  21038. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21039. constructor: DiscreteInterpolant,
  21040. interpolate_: function interpolate_(i1
  21041. /*, t0, t, t1 */
  21042. ) {
  21043. return this.copySampleValue_(i1 - 1);
  21044. }
  21045. });
  21046. function KeyframeTrack(name, times, values, interpolation) {
  21047. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  21048. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  21049. this.name = name;
  21050. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  21051. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  21052. this.setInterpolation(interpolation || this.DefaultInterpolation);
  21053. } // Static methods
  21054. Object.assign(KeyframeTrack, {
  21055. // Serialization (in static context, because of constructor invocation
  21056. // and automatic invocation of .toJSON):
  21057. toJSON: function toJSON(track) {
  21058. var trackType = track.constructor;
  21059. var json; // derived classes can define a static toJSON method
  21060. if (trackType.toJSON !== undefined) {
  21061. json = trackType.toJSON(track);
  21062. } else {
  21063. // by default, we assume the data can be serialized as-is
  21064. json = {
  21065. 'name': track.name,
  21066. 'times': AnimationUtils.convertArray(track.times, Array),
  21067. 'values': AnimationUtils.convertArray(track.values, Array)
  21068. };
  21069. var interpolation = track.getInterpolation();
  21070. if (interpolation !== track.DefaultInterpolation) {
  21071. json.interpolation = interpolation;
  21072. }
  21073. }
  21074. json.type = track.ValueTypeName; // mandatory
  21075. return json;
  21076. }
  21077. });
  21078. Object.assign(KeyframeTrack.prototype, {
  21079. constructor: KeyframeTrack,
  21080. TimeBufferType: Float32Array,
  21081. ValueBufferType: Float32Array,
  21082. DefaultInterpolation: InterpolateLinear,
  21083. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  21084. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  21085. },
  21086. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21087. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21088. },
  21089. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  21090. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  21091. },
  21092. setInterpolation: function setInterpolation(interpolation) {
  21093. var factoryMethod;
  21094. switch (interpolation) {
  21095. case InterpolateDiscrete:
  21096. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21097. break;
  21098. case InterpolateLinear:
  21099. factoryMethod = this.InterpolantFactoryMethodLinear;
  21100. break;
  21101. case InterpolateSmooth:
  21102. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21103. break;
  21104. }
  21105. if (factoryMethod === undefined) {
  21106. var message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
  21107. if (this.createInterpolant === undefined) {
  21108. // fall back to default, unless the default itself is messed up
  21109. if (interpolation !== this.DefaultInterpolation) {
  21110. this.setInterpolation(this.DefaultInterpolation);
  21111. } else {
  21112. throw new Error(message); // fatal, in this case
  21113. }
  21114. }
  21115. console.warn('THREE.KeyframeTrack:', message);
  21116. return this;
  21117. }
  21118. this.createInterpolant = factoryMethod;
  21119. return this;
  21120. },
  21121. getInterpolation: function getInterpolation() {
  21122. switch (this.createInterpolant) {
  21123. case this.InterpolantFactoryMethodDiscrete:
  21124. return InterpolateDiscrete;
  21125. case this.InterpolantFactoryMethodLinear:
  21126. return InterpolateLinear;
  21127. case this.InterpolantFactoryMethodSmooth:
  21128. return InterpolateSmooth;
  21129. }
  21130. },
  21131. getValueSize: function getValueSize() {
  21132. return this.values.length / this.times.length;
  21133. },
  21134. // move all keyframes either forwards or backwards in time
  21135. shift: function shift(timeOffset) {
  21136. if (timeOffset !== 0.0) {
  21137. var times = this.times;
  21138. for (var i = 0, n = times.length; i !== n; ++i) {
  21139. times[i] += timeOffset;
  21140. }
  21141. }
  21142. return this;
  21143. },
  21144. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21145. scale: function scale(timeScale) {
  21146. if (timeScale !== 1.0) {
  21147. var times = this.times;
  21148. for (var i = 0, n = times.length; i !== n; ++i) {
  21149. times[i] *= timeScale;
  21150. }
  21151. }
  21152. return this;
  21153. },
  21154. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21155. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21156. trim: function trim(startTime, endTime) {
  21157. var times = this.times,
  21158. nKeys = times.length;
  21159. var from = 0,
  21160. to = nKeys - 1;
  21161. while (from !== nKeys && times[from] < startTime) {
  21162. ++from;
  21163. }
  21164. while (to !== -1 && times[to] > endTime) {
  21165. --to;
  21166. }
  21167. ++to; // inclusive -> exclusive bound
  21168. if (from !== 0 || to !== nKeys) {
  21169. // empty tracks are forbidden, so keep at least one keyframe
  21170. if (from >= to) {
  21171. to = Math.max(to, 1);
  21172. from = to - 1;
  21173. }
  21174. var stride = this.getValueSize();
  21175. this.times = AnimationUtils.arraySlice(times, from, to);
  21176. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21177. }
  21178. return this;
  21179. },
  21180. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21181. validate: function validate() {
  21182. var valid = true;
  21183. var valueSize = this.getValueSize();
  21184. if (valueSize - Math.floor(valueSize) !== 0) {
  21185. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21186. valid = false;
  21187. }
  21188. var times = this.times,
  21189. values = this.values,
  21190. nKeys = times.length;
  21191. if (nKeys === 0) {
  21192. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21193. valid = false;
  21194. }
  21195. var prevTime = null;
  21196. for (var i = 0; i !== nKeys; i++) {
  21197. var currTime = times[i];
  21198. if (typeof currTime === 'number' && isNaN(currTime)) {
  21199. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21200. valid = false;
  21201. break;
  21202. }
  21203. if (prevTime !== null && prevTime > currTime) {
  21204. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21205. valid = false;
  21206. break;
  21207. }
  21208. prevTime = currTime;
  21209. }
  21210. if (values !== undefined) {
  21211. if (AnimationUtils.isTypedArray(values)) {
  21212. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21213. var value = values[_i];
  21214. if (isNaN(value)) {
  21215. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21216. valid = false;
  21217. break;
  21218. }
  21219. }
  21220. }
  21221. }
  21222. return valid;
  21223. },
  21224. // removes equivalent sequential keys as common in morph target sequences
  21225. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21226. optimize: function optimize() {
  21227. // times or values may be shared with other tracks, so overwriting is unsafe
  21228. var times = AnimationUtils.arraySlice(this.times),
  21229. values = AnimationUtils.arraySlice(this.values),
  21230. stride = this.getValueSize(),
  21231. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21232. lastIndex = times.length - 1;
  21233. var writeIndex = 1;
  21234. for (var i = 1; i < lastIndex; ++i) {
  21235. var keep = false;
  21236. var time = times[i];
  21237. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21238. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21239. if (!smoothInterpolation) {
  21240. // remove unnecessary keyframes same as their neighbors
  21241. var offset = i * stride,
  21242. offsetP = offset - stride,
  21243. offsetN = offset + stride;
  21244. for (var j = 0; j !== stride; ++j) {
  21245. var value = values[offset + j];
  21246. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21247. keep = true;
  21248. break;
  21249. }
  21250. }
  21251. } else {
  21252. keep = true;
  21253. }
  21254. } // in-place compaction
  21255. if (keep) {
  21256. if (i !== writeIndex) {
  21257. times[writeIndex] = times[i];
  21258. var readOffset = i * stride,
  21259. writeOffset = writeIndex * stride;
  21260. for (var _j = 0; _j !== stride; ++_j) {
  21261. values[writeOffset + _j] = values[readOffset + _j];
  21262. }
  21263. }
  21264. ++writeIndex;
  21265. }
  21266. } // flush last keyframe (compaction looks ahead)
  21267. if (lastIndex > 0) {
  21268. times[writeIndex] = times[lastIndex];
  21269. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21270. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21271. }
  21272. ++writeIndex;
  21273. }
  21274. if (writeIndex !== times.length) {
  21275. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21276. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21277. } else {
  21278. this.times = times;
  21279. this.values = values;
  21280. }
  21281. return this;
  21282. },
  21283. clone: function clone() {
  21284. var times = AnimationUtils.arraySlice(this.times, 0);
  21285. var values = AnimationUtils.arraySlice(this.values, 0);
  21286. var TypedKeyframeTrack = this.constructor;
  21287. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21288. track.createInterpolant = this.createInterpolant;
  21289. return track;
  21290. }
  21291. });
  21292. /**
  21293. * A Track of Boolean keyframe values.
  21294. */
  21295. function BooleanKeyframeTrack(name, times, values) {
  21296. KeyframeTrack.call(this, name, times, values);
  21297. }
  21298. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21299. constructor: BooleanKeyframeTrack,
  21300. ValueTypeName: 'bool',
  21301. ValueBufferType: Array,
  21302. DefaultInterpolation: InterpolateDiscrete,
  21303. InterpolantFactoryMethodLinear: undefined,
  21304. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21305. // representation of a single value and a custom interpolant that
  21306. // computes "firstValue ^ isOdd( index )".
  21307. });
  21308. /**
  21309. * A Track of keyframe values that represent color.
  21310. */
  21311. function ColorKeyframeTrack(name, times, values, interpolation) {
  21312. KeyframeTrack.call(this, name, times, values, interpolation);
  21313. }
  21314. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21315. constructor: ColorKeyframeTrack,
  21316. ValueTypeName: 'color' // ValueBufferType is inherited
  21317. // DefaultInterpolation is inherited
  21318. // Note: Very basic implementation and nothing special yet.
  21319. // However, this is the place for color space parameterization.
  21320. });
  21321. /**
  21322. * A Track of numeric keyframe values.
  21323. */
  21324. function NumberKeyframeTrack(name, times, values, interpolation) {
  21325. KeyframeTrack.call(this, name, times, values, interpolation);
  21326. }
  21327. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21328. constructor: NumberKeyframeTrack,
  21329. ValueTypeName: 'number' // ValueBufferType is inherited
  21330. // DefaultInterpolation is inherited
  21331. });
  21332. /**
  21333. * Spherical linear unit quaternion interpolant.
  21334. */
  21335. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21336. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21337. }
  21338. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21339. constructor: QuaternionLinearInterpolant,
  21340. interpolate_: function interpolate_(i1, t0, t, t1) {
  21341. var result = this.resultBuffer,
  21342. values = this.sampleValues,
  21343. stride = this.valueSize,
  21344. alpha = (t - t0) / (t1 - t0);
  21345. var offset = i1 * stride;
  21346. for (var end = offset + stride; offset !== end; offset += 4) {
  21347. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21348. }
  21349. return result;
  21350. }
  21351. });
  21352. /**
  21353. * A Track of quaternion keyframe values.
  21354. */
  21355. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21356. KeyframeTrack.call(this, name, times, values, interpolation);
  21357. }
  21358. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21359. constructor: QuaternionKeyframeTrack,
  21360. ValueTypeName: 'quaternion',
  21361. // ValueBufferType is inherited
  21362. DefaultInterpolation: InterpolateLinear,
  21363. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21364. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21365. },
  21366. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21367. });
  21368. /**
  21369. * A Track that interpolates Strings
  21370. */
  21371. function StringKeyframeTrack(name, times, values, interpolation) {
  21372. KeyframeTrack.call(this, name, times, values, interpolation);
  21373. }
  21374. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21375. constructor: StringKeyframeTrack,
  21376. ValueTypeName: 'string',
  21377. ValueBufferType: Array,
  21378. DefaultInterpolation: InterpolateDiscrete,
  21379. InterpolantFactoryMethodLinear: undefined,
  21380. InterpolantFactoryMethodSmooth: undefined
  21381. });
  21382. /**
  21383. * A Track of vectored keyframe values.
  21384. */
  21385. function VectorKeyframeTrack(name, times, values, interpolation) {
  21386. KeyframeTrack.call(this, name, times, values, interpolation);
  21387. }
  21388. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21389. constructor: VectorKeyframeTrack,
  21390. ValueTypeName: 'vector' // ValueBufferType is inherited
  21391. // DefaultInterpolation is inherited
  21392. });
  21393. function AnimationClip(name, duration, tracks, blendMode) {
  21394. this.name = name;
  21395. this.tracks = tracks;
  21396. this.duration = duration !== undefined ? duration : -1;
  21397. this.blendMode = blendMode !== undefined ? blendMode : NormalAnimationBlendMode;
  21398. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21399. if (this.duration < 0) {
  21400. this.resetDuration();
  21401. }
  21402. }
  21403. function getTrackTypeForValueTypeName(typeName) {
  21404. switch (typeName.toLowerCase()) {
  21405. case 'scalar':
  21406. case 'double':
  21407. case 'float':
  21408. case 'number':
  21409. case 'integer':
  21410. return NumberKeyframeTrack;
  21411. case 'vector':
  21412. case 'vector2':
  21413. case 'vector3':
  21414. case 'vector4':
  21415. return VectorKeyframeTrack;
  21416. case 'color':
  21417. return ColorKeyframeTrack;
  21418. case 'quaternion':
  21419. return QuaternionKeyframeTrack;
  21420. case 'bool':
  21421. case 'boolean':
  21422. return BooleanKeyframeTrack;
  21423. case 'string':
  21424. return StringKeyframeTrack;
  21425. }
  21426. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21427. }
  21428. function parseKeyframeTrack(json) {
  21429. if (json.type === undefined) {
  21430. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21431. }
  21432. var trackType = getTrackTypeForValueTypeName(json.type);
  21433. if (json.times === undefined) {
  21434. var times = [],
  21435. values = [];
  21436. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21437. json.times = times;
  21438. json.values = values;
  21439. } // derived classes can define a static parse method
  21440. if (trackType.parse !== undefined) {
  21441. return trackType.parse(json);
  21442. } else {
  21443. // by default, we assume a constructor compatible with the base
  21444. return new trackType(json.name, json.times, json.values, json.interpolation);
  21445. }
  21446. }
  21447. Object.assign(AnimationClip, {
  21448. parse: function parse(json) {
  21449. var tracks = [],
  21450. jsonTracks = json.tracks,
  21451. frameTime = 1.0 / (json.fps || 1.0);
  21452. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21453. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21454. }
  21455. return new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21456. },
  21457. toJSON: function toJSON(clip) {
  21458. var tracks = [],
  21459. clipTracks = clip.tracks;
  21460. var json = {
  21461. 'name': clip.name,
  21462. 'duration': clip.duration,
  21463. 'tracks': tracks,
  21464. 'uuid': clip.uuid,
  21465. 'blendMode': clip.blendMode
  21466. };
  21467. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21468. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21469. }
  21470. return json;
  21471. },
  21472. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21473. var numMorphTargets = morphTargetSequence.length;
  21474. var tracks = [];
  21475. for (var i = 0; i < numMorphTargets; i++) {
  21476. var times = [];
  21477. var values = [];
  21478. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21479. values.push(0, 1, 0);
  21480. var order = AnimationUtils.getKeyframeOrder(times);
  21481. times = AnimationUtils.sortedArray(times, 1, order);
  21482. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21483. // last frame as well for perfect loop.
  21484. if (!noLoop && times[0] === 0) {
  21485. times.push(numMorphTargets);
  21486. values.push(values[0]);
  21487. }
  21488. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21489. }
  21490. return new AnimationClip(name, -1, tracks);
  21491. },
  21492. findByName: function findByName(objectOrClipArray, name) {
  21493. var clipArray = objectOrClipArray;
  21494. if (!Array.isArray(objectOrClipArray)) {
  21495. var o = objectOrClipArray;
  21496. clipArray = o.geometry && o.geometry.animations || o.animations;
  21497. }
  21498. for (var i = 0; i < clipArray.length; i++) {
  21499. if (clipArray[i].name === name) {
  21500. return clipArray[i];
  21501. }
  21502. }
  21503. return null;
  21504. },
  21505. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21506. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21507. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21508. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21509. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21510. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21511. var morphTarget = morphTargets[i];
  21512. var parts = morphTarget.name.match(pattern);
  21513. if (parts && parts.length > 1) {
  21514. var name = parts[1];
  21515. var animationMorphTargets = animationToMorphTargets[name];
  21516. if (!animationMorphTargets) {
  21517. animationToMorphTargets[name] = animationMorphTargets = [];
  21518. }
  21519. animationMorphTargets.push(morphTarget);
  21520. }
  21521. }
  21522. var clips = [];
  21523. for (var _name in animationToMorphTargets) {
  21524. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21525. }
  21526. return clips;
  21527. },
  21528. // parse the animation.hierarchy format
  21529. parseAnimation: function parseAnimation(animation, bones) {
  21530. if (!animation) {
  21531. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21532. return null;
  21533. }
  21534. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21535. // only return track if there are actually keys.
  21536. if (animationKeys.length !== 0) {
  21537. var times = [];
  21538. var values = [];
  21539. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21540. if (times.length !== 0) {
  21541. destTracks.push(new trackType(trackName, times, values));
  21542. }
  21543. }
  21544. };
  21545. var tracks = [];
  21546. var clipName = animation.name || 'default';
  21547. var fps = animation.fps || 30;
  21548. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21549. var duration = animation.length || -1;
  21550. var hierarchyTracks = animation.hierarchy || [];
  21551. for (var h = 0; h < hierarchyTracks.length; h++) {
  21552. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21553. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21554. if (animationKeys[0].morphTargets) {
  21555. // figure out all morph targets used in this track
  21556. var morphTargetNames = {};
  21557. var k = void 0;
  21558. for (k = 0; k < animationKeys.length; k++) {
  21559. if (animationKeys[k].morphTargets) {
  21560. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21561. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21562. }
  21563. }
  21564. } // create a track for each morph target with all zero
  21565. // morphTargetInfluences except for the keys in which
  21566. // the morphTarget is named.
  21567. for (var morphTargetName in morphTargetNames) {
  21568. var times = [];
  21569. var values = [];
  21570. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21571. var animationKey = animationKeys[k];
  21572. times.push(animationKey.time);
  21573. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21574. }
  21575. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21576. }
  21577. duration = morphTargetNames.length * (fps || 1.0);
  21578. } else {
  21579. // ...assume skeletal animation
  21580. var boneName = '.bones[' + bones[h].name + ']';
  21581. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21582. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21583. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21584. }
  21585. }
  21586. if (tracks.length === 0) {
  21587. return null;
  21588. }
  21589. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21590. return clip;
  21591. }
  21592. });
  21593. Object.assign(AnimationClip.prototype, {
  21594. resetDuration: function resetDuration() {
  21595. var tracks = this.tracks;
  21596. var duration = 0;
  21597. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21598. var track = this.tracks[i];
  21599. duration = Math.max(duration, track.times[track.times.length - 1]);
  21600. }
  21601. this.duration = duration;
  21602. return this;
  21603. },
  21604. trim: function trim() {
  21605. for (var i = 0; i < this.tracks.length; i++) {
  21606. this.tracks[i].trim(0, this.duration);
  21607. }
  21608. return this;
  21609. },
  21610. validate: function validate() {
  21611. var valid = true;
  21612. for (var i = 0; i < this.tracks.length; i++) {
  21613. valid = valid && this.tracks[i].validate();
  21614. }
  21615. return valid;
  21616. },
  21617. optimize: function optimize() {
  21618. for (var i = 0; i < this.tracks.length; i++) {
  21619. this.tracks[i].optimize();
  21620. }
  21621. return this;
  21622. },
  21623. clone: function clone() {
  21624. var tracks = [];
  21625. for (var i = 0; i < this.tracks.length; i++) {
  21626. tracks.push(this.tracks[i].clone());
  21627. }
  21628. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21629. }
  21630. });
  21631. var Cache = {
  21632. enabled: false,
  21633. files: {},
  21634. add: function add(key, file) {
  21635. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21636. this.files[key] = file;
  21637. },
  21638. get: function get(key) {
  21639. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21640. return this.files[key];
  21641. },
  21642. remove: function remove(key) {
  21643. delete this.files[key];
  21644. },
  21645. clear: function clear() {
  21646. this.files = {};
  21647. }
  21648. };
  21649. function LoadingManager(onLoad, onProgress, onError) {
  21650. var scope = this;
  21651. var isLoading = false;
  21652. var itemsLoaded = 0;
  21653. var itemsTotal = 0;
  21654. var urlModifier = undefined;
  21655. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21656. // in the constructor
  21657. this.onStart = undefined;
  21658. this.onLoad = onLoad;
  21659. this.onProgress = onProgress;
  21660. this.onError = onError;
  21661. this.itemStart = function (url) {
  21662. itemsTotal++;
  21663. if (isLoading === false) {
  21664. if (scope.onStart !== undefined) {
  21665. scope.onStart(url, itemsLoaded, itemsTotal);
  21666. }
  21667. }
  21668. isLoading = true;
  21669. };
  21670. this.itemEnd = function (url) {
  21671. itemsLoaded++;
  21672. if (scope.onProgress !== undefined) {
  21673. scope.onProgress(url, itemsLoaded, itemsTotal);
  21674. }
  21675. if (itemsLoaded === itemsTotal) {
  21676. isLoading = false;
  21677. if (scope.onLoad !== undefined) {
  21678. scope.onLoad();
  21679. }
  21680. }
  21681. };
  21682. this.itemError = function (url) {
  21683. if (scope.onError !== undefined) {
  21684. scope.onError(url);
  21685. }
  21686. };
  21687. this.resolveURL = function (url) {
  21688. if (urlModifier) {
  21689. return urlModifier(url);
  21690. }
  21691. return url;
  21692. };
  21693. this.setURLModifier = function (transform) {
  21694. urlModifier = transform;
  21695. return this;
  21696. };
  21697. this.addHandler = function (regex, loader) {
  21698. handlers.push(regex, loader);
  21699. return this;
  21700. };
  21701. this.removeHandler = function (regex) {
  21702. var index = handlers.indexOf(regex);
  21703. if (index !== -1) {
  21704. handlers.splice(index, 2);
  21705. }
  21706. return this;
  21707. };
  21708. this.getHandler = function (file) {
  21709. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21710. var regex = handlers[i];
  21711. var loader = handlers[i + 1];
  21712. if (regex.global) regex.lastIndex = 0; // see #17920
  21713. if (regex.test(file)) {
  21714. return loader;
  21715. }
  21716. }
  21717. return null;
  21718. };
  21719. }
  21720. var DefaultLoadingManager = new LoadingManager();
  21721. function Loader(manager) {
  21722. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21723. this.crossOrigin = 'anonymous';
  21724. this.withCredentials = false;
  21725. this.path = '';
  21726. this.resourcePath = '';
  21727. this.requestHeader = {};
  21728. }
  21729. Object.assign(Loader.prototype, {
  21730. load: function load()
  21731. /* url, onLoad, onProgress, onError */
  21732. {},
  21733. loadAsync: function loadAsync(url, onProgress) {
  21734. var scope = this;
  21735. return new Promise(function (resolve, reject) {
  21736. scope.load(url, resolve, onProgress, reject);
  21737. });
  21738. },
  21739. parse: function parse()
  21740. /* data */
  21741. {},
  21742. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21743. this.crossOrigin = crossOrigin;
  21744. return this;
  21745. },
  21746. setWithCredentials: function setWithCredentials(value) {
  21747. this.withCredentials = value;
  21748. return this;
  21749. },
  21750. setPath: function setPath(path) {
  21751. this.path = path;
  21752. return this;
  21753. },
  21754. setResourcePath: function setResourcePath(resourcePath) {
  21755. this.resourcePath = resourcePath;
  21756. return this;
  21757. },
  21758. setRequestHeader: function setRequestHeader(requestHeader) {
  21759. this.requestHeader = requestHeader;
  21760. return this;
  21761. }
  21762. });
  21763. var loading = {};
  21764. function FileLoader(manager) {
  21765. Loader.call(this, manager);
  21766. }
  21767. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21768. constructor: FileLoader,
  21769. load: function load(url, onLoad, onProgress, onError) {
  21770. if (url === undefined) url = '';
  21771. if (this.path !== undefined) url = this.path + url;
  21772. url = this.manager.resolveURL(url);
  21773. var scope = this;
  21774. var cached = Cache.get(url);
  21775. if (cached !== undefined) {
  21776. scope.manager.itemStart(url);
  21777. setTimeout(function () {
  21778. if (onLoad) onLoad(cached);
  21779. scope.manager.itemEnd(url);
  21780. }, 0);
  21781. return cached;
  21782. } // Check if request is duplicate
  21783. if (loading[url] !== undefined) {
  21784. loading[url].push({
  21785. onLoad: onLoad,
  21786. onProgress: onProgress,
  21787. onError: onError
  21788. });
  21789. return;
  21790. } // Check for data: URI
  21791. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21792. var dataUriRegexResult = url.match(dataUriRegex);
  21793. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21794. if (dataUriRegexResult) {
  21795. var mimeType = dataUriRegexResult[1];
  21796. var isBase64 = !!dataUriRegexResult[2];
  21797. var data = dataUriRegexResult[3];
  21798. data = decodeURIComponent(data);
  21799. if (isBase64) data = atob(data);
  21800. try {
  21801. var response;
  21802. var responseType = (this.responseType || '').toLowerCase();
  21803. switch (responseType) {
  21804. case 'arraybuffer':
  21805. case 'blob':
  21806. var view = new Uint8Array(data.length);
  21807. for (var i = 0; i < data.length; i++) {
  21808. view[i] = data.charCodeAt(i);
  21809. }
  21810. if (responseType === 'blob') {
  21811. response = new Blob([view.buffer], {
  21812. type: mimeType
  21813. });
  21814. } else {
  21815. response = view.buffer;
  21816. }
  21817. break;
  21818. case 'document':
  21819. var parser = new DOMParser();
  21820. response = parser.parseFromString(data, mimeType);
  21821. break;
  21822. case 'json':
  21823. response = JSON.parse(data);
  21824. break;
  21825. default:
  21826. // 'text' or other
  21827. response = data;
  21828. break;
  21829. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21830. setTimeout(function () {
  21831. if (onLoad) onLoad(response);
  21832. scope.manager.itemEnd(url);
  21833. }, 0);
  21834. } catch (error) {
  21835. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21836. setTimeout(function () {
  21837. if (onError) onError(error);
  21838. scope.manager.itemError(url);
  21839. scope.manager.itemEnd(url);
  21840. }, 0);
  21841. }
  21842. } else {
  21843. // Initialise array for duplicate requests
  21844. loading[url] = [];
  21845. loading[url].push({
  21846. onLoad: onLoad,
  21847. onProgress: onProgress,
  21848. onError: onError
  21849. });
  21850. request = new XMLHttpRequest();
  21851. request.open('GET', url, true);
  21852. request.addEventListener('load', function (event) {
  21853. var response = this.response;
  21854. var callbacks = loading[url];
  21855. delete loading[url];
  21856. if (this.status === 200 || this.status === 0) {
  21857. // Some browsers return HTTP Status 0 when using non-http protocol
  21858. // e.g. 'file://' or 'data://'. Handle as success.
  21859. 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
  21860. // error response bodies as proper responses to requests.
  21861. Cache.add(url, response);
  21862. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21863. var callback = callbacks[_i];
  21864. if (callback.onLoad) callback.onLoad(response);
  21865. }
  21866. scope.manager.itemEnd(url);
  21867. } else {
  21868. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21869. var _callback = callbacks[_i2];
  21870. if (_callback.onError) _callback.onError(event);
  21871. }
  21872. scope.manager.itemError(url);
  21873. scope.manager.itemEnd(url);
  21874. }
  21875. }, false);
  21876. request.addEventListener('progress', function (event) {
  21877. var callbacks = loading[url];
  21878. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21879. var callback = callbacks[_i3];
  21880. if (callback.onProgress) callback.onProgress(event);
  21881. }
  21882. }, false);
  21883. request.addEventListener('error', function (event) {
  21884. var callbacks = loading[url];
  21885. delete loading[url];
  21886. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21887. var callback = callbacks[_i4];
  21888. if (callback.onError) callback.onError(event);
  21889. }
  21890. scope.manager.itemError(url);
  21891. scope.manager.itemEnd(url);
  21892. }, false);
  21893. request.addEventListener('abort', function (event) {
  21894. var callbacks = loading[url];
  21895. delete loading[url];
  21896. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21897. var callback = callbacks[_i5];
  21898. if (callback.onError) callback.onError(event);
  21899. }
  21900. scope.manager.itemError(url);
  21901. scope.manager.itemEnd(url);
  21902. }, false);
  21903. if (this.responseType !== undefined) request.responseType = this.responseType;
  21904. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21905. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21906. for (var header in this.requestHeader) {
  21907. request.setRequestHeader(header, this.requestHeader[header]);
  21908. }
  21909. request.send(null);
  21910. }
  21911. scope.manager.itemStart(url);
  21912. return request;
  21913. },
  21914. setResponseType: function setResponseType(value) {
  21915. this.responseType = value;
  21916. return this;
  21917. },
  21918. setMimeType: function setMimeType(value) {
  21919. this.mimeType = value;
  21920. return this;
  21921. }
  21922. });
  21923. function AnimationLoader(manager) {
  21924. Loader.call(this, manager);
  21925. }
  21926. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21927. constructor: AnimationLoader,
  21928. load: function load(url, onLoad, onProgress, onError) {
  21929. var scope = this;
  21930. var loader = new FileLoader(scope.manager);
  21931. loader.setPath(scope.path);
  21932. loader.setRequestHeader(scope.requestHeader);
  21933. loader.setWithCredentials(scope.withCredentials);
  21934. loader.load(url, function (text) {
  21935. try {
  21936. onLoad(scope.parse(JSON.parse(text)));
  21937. } catch (e) {
  21938. if (onError) {
  21939. onError(e);
  21940. } else {
  21941. console.error(e);
  21942. }
  21943. scope.manager.itemError(url);
  21944. }
  21945. }, onProgress, onError);
  21946. },
  21947. parse: function parse(json) {
  21948. var animations = [];
  21949. for (var i = 0; i < json.length; i++) {
  21950. var clip = AnimationClip.parse(json[i]);
  21951. animations.push(clip);
  21952. }
  21953. return animations;
  21954. }
  21955. });
  21956. /**
  21957. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21958. *
  21959. * Sub classes have to implement the parse() method which will be used in load().
  21960. */
  21961. function CompressedTextureLoader(manager) {
  21962. Loader.call(this, manager);
  21963. }
  21964. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21965. constructor: CompressedTextureLoader,
  21966. load: function load(url, onLoad, onProgress, onError) {
  21967. var scope = this;
  21968. var images = [];
  21969. var texture = new CompressedTexture();
  21970. texture.image = images;
  21971. var loader = new FileLoader(this.manager);
  21972. loader.setPath(this.path);
  21973. loader.setResponseType('arraybuffer');
  21974. loader.setRequestHeader(this.requestHeader);
  21975. loader.setWithCredentials(scope.withCredentials);
  21976. var loaded = 0;
  21977. function loadTexture(i) {
  21978. loader.load(url[i], function (buffer) {
  21979. var texDatas = scope.parse(buffer, true);
  21980. images[i] = {
  21981. width: texDatas.width,
  21982. height: texDatas.height,
  21983. format: texDatas.format,
  21984. mipmaps: texDatas.mipmaps
  21985. };
  21986. loaded += 1;
  21987. if (loaded === 6) {
  21988. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21989. texture.format = texDatas.format;
  21990. texture.needsUpdate = true;
  21991. if (onLoad) onLoad(texture);
  21992. }
  21993. }, onProgress, onError);
  21994. }
  21995. if (Array.isArray(url)) {
  21996. for (var i = 0, il = url.length; i < il; ++i) {
  21997. loadTexture(i);
  21998. }
  21999. } else {
  22000. // compressed cubemap texture stored in a single DDS file
  22001. loader.load(url, function (buffer) {
  22002. var texDatas = scope.parse(buffer, true);
  22003. if (texDatas.isCubemap) {
  22004. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22005. for (var f = 0; f < faces; f++) {
  22006. images[f] = {
  22007. mipmaps: []
  22008. };
  22009. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  22010. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  22011. images[f].format = texDatas.format;
  22012. images[f].width = texDatas.width;
  22013. images[f].height = texDatas.height;
  22014. }
  22015. }
  22016. } else {
  22017. texture.image.width = texDatas.width;
  22018. texture.image.height = texDatas.height;
  22019. texture.mipmaps = texDatas.mipmaps;
  22020. }
  22021. if (texDatas.mipmapCount === 1) {
  22022. texture.minFilter = LinearFilter;
  22023. }
  22024. texture.format = texDatas.format;
  22025. texture.needsUpdate = true;
  22026. if (onLoad) onLoad(texture);
  22027. }, onProgress, onError);
  22028. }
  22029. return texture;
  22030. }
  22031. });
  22032. function ImageLoader(manager) {
  22033. Loader.call(this, manager);
  22034. }
  22035. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22036. constructor: ImageLoader,
  22037. load: function load(url, onLoad, onProgress, onError) {
  22038. if (this.path !== undefined) url = this.path + url;
  22039. url = this.manager.resolveURL(url);
  22040. var scope = this;
  22041. var cached = Cache.get(url);
  22042. if (cached !== undefined) {
  22043. scope.manager.itemStart(url);
  22044. setTimeout(function () {
  22045. if (onLoad) onLoad(cached);
  22046. scope.manager.itemEnd(url);
  22047. }, 0);
  22048. return cached;
  22049. }
  22050. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  22051. function onImageLoad() {
  22052. image.removeEventListener('load', onImageLoad, false);
  22053. image.removeEventListener('error', onImageError, false);
  22054. Cache.add(url, this);
  22055. if (onLoad) onLoad(this);
  22056. scope.manager.itemEnd(url);
  22057. }
  22058. function onImageError(event) {
  22059. image.removeEventListener('load', onImageLoad, false);
  22060. image.removeEventListener('error', onImageError, false);
  22061. if (onError) onError(event);
  22062. scope.manager.itemError(url);
  22063. scope.manager.itemEnd(url);
  22064. }
  22065. image.addEventListener('load', onImageLoad, false);
  22066. image.addEventListener('error', onImageError, false);
  22067. if (url.substr(0, 5) !== 'data:') {
  22068. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  22069. }
  22070. scope.manager.itemStart(url);
  22071. image.src = url;
  22072. return image;
  22073. }
  22074. });
  22075. function CubeTextureLoader(manager) {
  22076. Loader.call(this, manager);
  22077. }
  22078. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22079. constructor: CubeTextureLoader,
  22080. load: function load(urls, onLoad, onProgress, onError) {
  22081. var texture = new CubeTexture();
  22082. var loader = new ImageLoader(this.manager);
  22083. loader.setCrossOrigin(this.crossOrigin);
  22084. loader.setPath(this.path);
  22085. var loaded = 0;
  22086. function loadTexture(i) {
  22087. loader.load(urls[i], function (image) {
  22088. texture.images[i] = image;
  22089. loaded++;
  22090. if (loaded === 6) {
  22091. texture.needsUpdate = true;
  22092. if (onLoad) onLoad(texture);
  22093. }
  22094. }, undefined, onError);
  22095. }
  22096. for (var i = 0; i < urls.length; ++i) {
  22097. loadTexture(i);
  22098. }
  22099. return texture;
  22100. }
  22101. });
  22102. /**
  22103. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22104. *
  22105. * Sub classes have to implement the parse() method which will be used in load().
  22106. */
  22107. function DataTextureLoader(manager) {
  22108. Loader.call(this, manager);
  22109. }
  22110. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22111. constructor: DataTextureLoader,
  22112. load: function load(url, onLoad, onProgress, onError) {
  22113. var scope = this;
  22114. var texture = new DataTexture();
  22115. var loader = new FileLoader(this.manager);
  22116. loader.setResponseType('arraybuffer');
  22117. loader.setRequestHeader(this.requestHeader);
  22118. loader.setPath(this.path);
  22119. loader.setWithCredentials(scope.withCredentials);
  22120. loader.load(url, function (buffer) {
  22121. var texData = scope.parse(buffer);
  22122. if (!texData) return;
  22123. if (texData.image !== undefined) {
  22124. texture.image = texData.image;
  22125. } else if (texData.data !== undefined) {
  22126. texture.image.width = texData.width;
  22127. texture.image.height = texData.height;
  22128. texture.image.data = texData.data;
  22129. }
  22130. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22131. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22132. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22133. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22134. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22135. if (texData.format !== undefined) {
  22136. texture.format = texData.format;
  22137. }
  22138. if (texData.type !== undefined) {
  22139. texture.type = texData.type;
  22140. }
  22141. if (texData.mipmaps !== undefined) {
  22142. texture.mipmaps = texData.mipmaps;
  22143. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22144. }
  22145. if (texData.mipmapCount === 1) {
  22146. texture.minFilter = LinearFilter;
  22147. }
  22148. texture.needsUpdate = true;
  22149. if (onLoad) onLoad(texture, texData);
  22150. }, onProgress, onError);
  22151. return texture;
  22152. }
  22153. });
  22154. function TextureLoader(manager) {
  22155. Loader.call(this, manager);
  22156. }
  22157. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22158. constructor: TextureLoader,
  22159. load: function load(url, onLoad, onProgress, onError) {
  22160. var texture = new Texture();
  22161. var loader = new ImageLoader(this.manager);
  22162. loader.setCrossOrigin(this.crossOrigin);
  22163. loader.setPath(this.path);
  22164. loader.load(url, function (image) {
  22165. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22166. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22167. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22168. texture.needsUpdate = true;
  22169. if (onLoad !== undefined) {
  22170. onLoad(texture);
  22171. }
  22172. }, onProgress, onError);
  22173. return texture;
  22174. }
  22175. });
  22176. /**
  22177. * Extensible curve object.
  22178. *
  22179. * Some common of curve methods:
  22180. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22181. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22182. * .getPoints(), .getSpacedPoints()
  22183. * .getLength()
  22184. * .updateArcLengths()
  22185. *
  22186. * This following curves inherit from THREE.Curve:
  22187. *
  22188. * -- 2D curves --
  22189. * THREE.ArcCurve
  22190. * THREE.CubicBezierCurve
  22191. * THREE.EllipseCurve
  22192. * THREE.LineCurve
  22193. * THREE.QuadraticBezierCurve
  22194. * THREE.SplineCurve
  22195. *
  22196. * -- 3D curves --
  22197. * THREE.CatmullRomCurve3
  22198. * THREE.CubicBezierCurve3
  22199. * THREE.LineCurve3
  22200. * THREE.QuadraticBezierCurve3
  22201. *
  22202. * A series of curves can be represented as a THREE.CurvePath.
  22203. *
  22204. **/
  22205. function Curve() {
  22206. this.type = 'Curve';
  22207. this.arcLengthDivisions = 200;
  22208. }
  22209. Object.assign(Curve.prototype, {
  22210. // Virtual base class method to overwrite and implement in subclasses
  22211. // - t [0 .. 1]
  22212. getPoint: function getPoint()
  22213. /* t, optionalTarget */
  22214. {
  22215. console.warn('THREE.Curve: .getPoint() not implemented.');
  22216. return null;
  22217. },
  22218. // Get point at relative position in curve according to arc length
  22219. // - u [0 .. 1]
  22220. getPointAt: function getPointAt(u, optionalTarget) {
  22221. var t = this.getUtoTmapping(u);
  22222. return this.getPoint(t, optionalTarget);
  22223. },
  22224. // Get sequence of points using getPoint( t )
  22225. getPoints: function getPoints(divisions) {
  22226. if (divisions === void 0) {
  22227. divisions = 5;
  22228. }
  22229. var points = [];
  22230. for (var d = 0; d <= divisions; d++) {
  22231. points.push(this.getPoint(d / divisions));
  22232. }
  22233. return points;
  22234. },
  22235. // Get sequence of points using getPointAt( u )
  22236. getSpacedPoints: function getSpacedPoints(divisions) {
  22237. if (divisions === void 0) {
  22238. divisions = 5;
  22239. }
  22240. var points = [];
  22241. for (var d = 0; d <= divisions; d++) {
  22242. points.push(this.getPointAt(d / divisions));
  22243. }
  22244. return points;
  22245. },
  22246. // Get total curve arc length
  22247. getLength: function getLength() {
  22248. var lengths = this.getLengths();
  22249. return lengths[lengths.length - 1];
  22250. },
  22251. // Get list of cumulative segment lengths
  22252. getLengths: function getLengths(divisions) {
  22253. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22254. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22255. return this.cacheArcLengths;
  22256. }
  22257. this.needsUpdate = false;
  22258. var cache = [];
  22259. var current,
  22260. last = this.getPoint(0);
  22261. var sum = 0;
  22262. cache.push(0);
  22263. for (var p = 1; p <= divisions; p++) {
  22264. current = this.getPoint(p / divisions);
  22265. sum += current.distanceTo(last);
  22266. cache.push(sum);
  22267. last = current;
  22268. }
  22269. this.cacheArcLengths = cache;
  22270. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22271. },
  22272. updateArcLengths: function updateArcLengths() {
  22273. this.needsUpdate = true;
  22274. this.getLengths();
  22275. },
  22276. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22277. getUtoTmapping: function getUtoTmapping(u, distance) {
  22278. var arcLengths = this.getLengths();
  22279. var i = 0;
  22280. var il = arcLengths.length;
  22281. var targetArcLength; // The targeted u distance value to get
  22282. if (distance) {
  22283. targetArcLength = distance;
  22284. } else {
  22285. targetArcLength = u * arcLengths[il - 1];
  22286. } // binary search for the index with largest value smaller than target u distance
  22287. var low = 0,
  22288. high = il - 1,
  22289. comparison;
  22290. while (low <= high) {
  22291. 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
  22292. comparison = arcLengths[i] - targetArcLength;
  22293. if (comparison < 0) {
  22294. low = i + 1;
  22295. } else if (comparison > 0) {
  22296. high = i - 1;
  22297. } else {
  22298. high = i;
  22299. break; // DONE
  22300. }
  22301. }
  22302. i = high;
  22303. if (arcLengths[i] === targetArcLength) {
  22304. return i / (il - 1);
  22305. } // we could get finer grain at lengths, or use simple interpolation between two points
  22306. var lengthBefore = arcLengths[i];
  22307. var lengthAfter = arcLengths[i + 1];
  22308. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22309. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22310. var t = (i + segmentFraction) / (il - 1);
  22311. return t;
  22312. },
  22313. // Returns a unit vector tangent at t
  22314. // In case any sub curve does not implement its tangent derivation,
  22315. // 2 points a small delta apart will be used to find its gradient
  22316. // which seems to give a reasonable approximation
  22317. getTangent: function getTangent(t, optionalTarget) {
  22318. var delta = 0.0001;
  22319. var t1 = t - delta;
  22320. var t2 = t + delta; // Capping in case of danger
  22321. if (t1 < 0) t1 = 0;
  22322. if (t2 > 1) t2 = 1;
  22323. var pt1 = this.getPoint(t1);
  22324. var pt2 = this.getPoint(t2);
  22325. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22326. tangent.copy(pt2).sub(pt1).normalize();
  22327. return tangent;
  22328. },
  22329. getTangentAt: function getTangentAt(u, optionalTarget) {
  22330. var t = this.getUtoTmapping(u);
  22331. return this.getTangent(t, optionalTarget);
  22332. },
  22333. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22334. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22335. var normal = new Vector3();
  22336. var tangents = [];
  22337. var normals = [];
  22338. var binormals = [];
  22339. var vec = new Vector3();
  22340. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22341. for (var i = 0; i <= segments; i++) {
  22342. var u = i / segments;
  22343. tangents[i] = this.getTangentAt(u, new Vector3());
  22344. tangents[i].normalize();
  22345. } // select an initial normal vector perpendicular to the first tangent vector,
  22346. // and in the direction of the minimum tangent xyz component
  22347. normals[0] = new Vector3();
  22348. binormals[0] = new Vector3();
  22349. var min = Number.MAX_VALUE;
  22350. var tx = Math.abs(tangents[0].x);
  22351. var ty = Math.abs(tangents[0].y);
  22352. var tz = Math.abs(tangents[0].z);
  22353. if (tx <= min) {
  22354. min = tx;
  22355. normal.set(1, 0, 0);
  22356. }
  22357. if (ty <= min) {
  22358. min = ty;
  22359. normal.set(0, 1, 0);
  22360. }
  22361. if (tz <= min) {
  22362. normal.set(0, 0, 1);
  22363. }
  22364. vec.crossVectors(tangents[0], normal).normalize();
  22365. normals[0].crossVectors(tangents[0], vec);
  22366. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22367. for (var _i = 1; _i <= segments; _i++) {
  22368. normals[_i] = normals[_i - 1].clone();
  22369. binormals[_i] = binormals[_i - 1].clone();
  22370. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22371. if (vec.length() > Number.EPSILON) {
  22372. vec.normalize();
  22373. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22374. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22375. }
  22376. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22377. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22378. if (closed === true) {
  22379. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22380. _theta /= segments;
  22381. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22382. _theta = -_theta;
  22383. }
  22384. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22385. // twist a little...
  22386. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22387. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22388. }
  22389. }
  22390. return {
  22391. tangents: tangents,
  22392. normals: normals,
  22393. binormals: binormals
  22394. };
  22395. },
  22396. clone: function clone() {
  22397. return new this.constructor().copy(this);
  22398. },
  22399. copy: function copy(source) {
  22400. this.arcLengthDivisions = source.arcLengthDivisions;
  22401. return this;
  22402. },
  22403. toJSON: function toJSON() {
  22404. var data = {
  22405. metadata: {
  22406. version: 4.5,
  22407. type: 'Curve',
  22408. generator: 'Curve.toJSON'
  22409. }
  22410. };
  22411. data.arcLengthDivisions = this.arcLengthDivisions;
  22412. data.type = this.type;
  22413. return data;
  22414. },
  22415. fromJSON: function fromJSON(json) {
  22416. this.arcLengthDivisions = json.arcLengthDivisions;
  22417. return this;
  22418. }
  22419. });
  22420. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22421. Curve.call(this);
  22422. this.type = 'EllipseCurve';
  22423. this.aX = aX || 0;
  22424. this.aY = aY || 0;
  22425. this.xRadius = xRadius || 1;
  22426. this.yRadius = yRadius || 1;
  22427. this.aStartAngle = aStartAngle || 0;
  22428. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22429. this.aClockwise = aClockwise || false;
  22430. this.aRotation = aRotation || 0;
  22431. }
  22432. EllipseCurve.prototype = Object.create(Curve.prototype);
  22433. EllipseCurve.prototype.constructor = EllipseCurve;
  22434. EllipseCurve.prototype.isEllipseCurve = true;
  22435. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22436. var point = optionalTarget || new Vector2();
  22437. var twoPi = Math.PI * 2;
  22438. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22439. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22440. while (deltaAngle < 0) {
  22441. deltaAngle += twoPi;
  22442. }
  22443. while (deltaAngle > twoPi) {
  22444. deltaAngle -= twoPi;
  22445. }
  22446. if (deltaAngle < Number.EPSILON) {
  22447. if (samePoints) {
  22448. deltaAngle = 0;
  22449. } else {
  22450. deltaAngle = twoPi;
  22451. }
  22452. }
  22453. if (this.aClockwise === true && !samePoints) {
  22454. if (deltaAngle === twoPi) {
  22455. deltaAngle = -twoPi;
  22456. } else {
  22457. deltaAngle = deltaAngle - twoPi;
  22458. }
  22459. }
  22460. var angle = this.aStartAngle + t * deltaAngle;
  22461. var x = this.aX + this.xRadius * Math.cos(angle);
  22462. var y = this.aY + this.yRadius * Math.sin(angle);
  22463. if (this.aRotation !== 0) {
  22464. var cos = Math.cos(this.aRotation);
  22465. var sin = Math.sin(this.aRotation);
  22466. var tx = x - this.aX;
  22467. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22468. x = tx * cos - ty * sin + this.aX;
  22469. y = tx * sin + ty * cos + this.aY;
  22470. }
  22471. return point.set(x, y);
  22472. };
  22473. EllipseCurve.prototype.copy = function (source) {
  22474. Curve.prototype.copy.call(this, source);
  22475. this.aX = source.aX;
  22476. this.aY = source.aY;
  22477. this.xRadius = source.xRadius;
  22478. this.yRadius = source.yRadius;
  22479. this.aStartAngle = source.aStartAngle;
  22480. this.aEndAngle = source.aEndAngle;
  22481. this.aClockwise = source.aClockwise;
  22482. this.aRotation = source.aRotation;
  22483. return this;
  22484. };
  22485. EllipseCurve.prototype.toJSON = function () {
  22486. var data = Curve.prototype.toJSON.call(this);
  22487. data.aX = this.aX;
  22488. data.aY = this.aY;
  22489. data.xRadius = this.xRadius;
  22490. data.yRadius = this.yRadius;
  22491. data.aStartAngle = this.aStartAngle;
  22492. data.aEndAngle = this.aEndAngle;
  22493. data.aClockwise = this.aClockwise;
  22494. data.aRotation = this.aRotation;
  22495. return data;
  22496. };
  22497. EllipseCurve.prototype.fromJSON = function (json) {
  22498. Curve.prototype.fromJSON.call(this, json);
  22499. this.aX = json.aX;
  22500. this.aY = json.aY;
  22501. this.xRadius = json.xRadius;
  22502. this.yRadius = json.yRadius;
  22503. this.aStartAngle = json.aStartAngle;
  22504. this.aEndAngle = json.aEndAngle;
  22505. this.aClockwise = json.aClockwise;
  22506. this.aRotation = json.aRotation;
  22507. return this;
  22508. };
  22509. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22510. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22511. this.type = 'ArcCurve';
  22512. }
  22513. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22514. ArcCurve.prototype.constructor = ArcCurve;
  22515. ArcCurve.prototype.isArcCurve = true;
  22516. /**
  22517. * Centripetal CatmullRom Curve - which is useful for avoiding
  22518. * cusps and self-intersections in non-uniform catmull rom curves.
  22519. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22520. *
  22521. * curve.type accepts centripetal(default), chordal and catmullrom
  22522. * curve.tension is used for catmullrom which defaults to 0.5
  22523. */
  22524. /*
  22525. Based on an optimized c++ solution in
  22526. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22527. - http://ideone.com/NoEbVM
  22528. This CubicPoly class could be used for reusing some variables and calculations,
  22529. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22530. which can be placed in CurveUtils.
  22531. */
  22532. function CubicPoly() {
  22533. var c0 = 0,
  22534. c1 = 0,
  22535. c2 = 0,
  22536. c3 = 0;
  22537. /*
  22538. * Compute coefficients for a cubic polynomial
  22539. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22540. * such that
  22541. * p(0) = x0, p(1) = x1
  22542. * and
  22543. * p'(0) = t0, p'(1) = t1.
  22544. */
  22545. function init(x0, x1, t0, t1) {
  22546. c0 = x0;
  22547. c1 = t0;
  22548. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22549. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22550. }
  22551. return {
  22552. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22553. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22554. },
  22555. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22556. // compute tangents when parameterized in [t1,t2]
  22557. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22558. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22559. t1 *= dt1;
  22560. t2 *= dt1;
  22561. init(x1, x2, t1, t2);
  22562. },
  22563. calc: function calc(t) {
  22564. var t2 = t * t;
  22565. var t3 = t2 * t;
  22566. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22567. }
  22568. };
  22569. } //
  22570. var tmp = new Vector3();
  22571. var px = new CubicPoly(),
  22572. py = new CubicPoly(),
  22573. pz = new CubicPoly();
  22574. function CatmullRomCurve3(points, closed, curveType, tension) {
  22575. Curve.call(this);
  22576. this.type = 'CatmullRomCurve3';
  22577. this.points = points || [];
  22578. this.closed = closed || false;
  22579. this.curveType = curveType || 'centripetal';
  22580. this.tension = tension !== undefined ? tension : 0.5;
  22581. }
  22582. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22583. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22584. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22585. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22586. var point = optionalTarget || new Vector3();
  22587. var points = this.points;
  22588. var l = points.length;
  22589. var p = (l - (this.closed ? 0 : 1)) * t;
  22590. var intPoint = Math.floor(p);
  22591. var weight = p - intPoint;
  22592. if (this.closed) {
  22593. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22594. } else if (weight === 0 && intPoint === l - 1) {
  22595. intPoint = l - 2;
  22596. weight = 1;
  22597. }
  22598. var p0, p3; // 4 points (p1 & p2 defined below)
  22599. if (this.closed || intPoint > 0) {
  22600. p0 = points[(intPoint - 1) % l];
  22601. } else {
  22602. // extrapolate first point
  22603. tmp.subVectors(points[0], points[1]).add(points[0]);
  22604. p0 = tmp;
  22605. }
  22606. var p1 = points[intPoint % l];
  22607. var p2 = points[(intPoint + 1) % l];
  22608. if (this.closed || intPoint + 2 < l) {
  22609. p3 = points[(intPoint + 2) % l];
  22610. } else {
  22611. // extrapolate last point
  22612. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22613. p3 = tmp;
  22614. }
  22615. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22616. // init Centripetal / Chordal Catmull-Rom
  22617. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22618. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22619. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22620. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22621. if (dt1 < 1e-4) dt1 = 1.0;
  22622. if (dt0 < 1e-4) dt0 = dt1;
  22623. if (dt2 < 1e-4) dt2 = dt1;
  22624. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22625. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22626. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22627. } else if (this.curveType === 'catmullrom') {
  22628. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22629. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22630. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22631. }
  22632. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22633. return point;
  22634. };
  22635. CatmullRomCurve3.prototype.copy = function (source) {
  22636. Curve.prototype.copy.call(this, source);
  22637. this.points = [];
  22638. for (var i = 0, l = source.points.length; i < l; i++) {
  22639. var point = source.points[i];
  22640. this.points.push(point.clone());
  22641. }
  22642. this.closed = source.closed;
  22643. this.curveType = source.curveType;
  22644. this.tension = source.tension;
  22645. return this;
  22646. };
  22647. CatmullRomCurve3.prototype.toJSON = function () {
  22648. var data = Curve.prototype.toJSON.call(this);
  22649. data.points = [];
  22650. for (var i = 0, l = this.points.length; i < l; i++) {
  22651. var point = this.points[i];
  22652. data.points.push(point.toArray());
  22653. }
  22654. data.closed = this.closed;
  22655. data.curveType = this.curveType;
  22656. data.tension = this.tension;
  22657. return data;
  22658. };
  22659. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22660. Curve.prototype.fromJSON.call(this, json);
  22661. this.points = [];
  22662. for (var i = 0, l = json.points.length; i < l; i++) {
  22663. var point = json.points[i];
  22664. this.points.push(new Vector3().fromArray(point));
  22665. }
  22666. this.closed = json.closed;
  22667. this.curveType = json.curveType;
  22668. this.tension = json.tension;
  22669. return this;
  22670. };
  22671. /**
  22672. * Bezier Curves formulas obtained from
  22673. * http://en.wikipedia.org/wiki/Bézier_curve
  22674. */
  22675. function CatmullRom(t, p0, p1, p2, p3) {
  22676. var v0 = (p2 - p0) * 0.5;
  22677. var v1 = (p3 - p1) * 0.5;
  22678. var t2 = t * t;
  22679. var t3 = t * t2;
  22680. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22681. } //
  22682. function QuadraticBezierP0(t, p) {
  22683. var k = 1 - t;
  22684. return k * k * p;
  22685. }
  22686. function QuadraticBezierP1(t, p) {
  22687. return 2 * (1 - t) * t * p;
  22688. }
  22689. function QuadraticBezierP2(t, p) {
  22690. return t * t * p;
  22691. }
  22692. function QuadraticBezier(t, p0, p1, p2) {
  22693. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22694. } //
  22695. function CubicBezierP0(t, p) {
  22696. var k = 1 - t;
  22697. return k * k * k * p;
  22698. }
  22699. function CubicBezierP1(t, p) {
  22700. var k = 1 - t;
  22701. return 3 * k * k * t * p;
  22702. }
  22703. function CubicBezierP2(t, p) {
  22704. return 3 * (1 - t) * t * t * p;
  22705. }
  22706. function CubicBezierP3(t, p) {
  22707. return t * t * t * p;
  22708. }
  22709. function CubicBezier(t, p0, p1, p2, p3) {
  22710. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22711. }
  22712. function CubicBezierCurve(v0, v1, v2, v3) {
  22713. Curve.call(this);
  22714. this.type = 'CubicBezierCurve';
  22715. this.v0 = v0 || new Vector2();
  22716. this.v1 = v1 || new Vector2();
  22717. this.v2 = v2 || new Vector2();
  22718. this.v3 = v3 || new Vector2();
  22719. }
  22720. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  22721. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22722. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22723. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22724. var point = optionalTarget || new Vector2();
  22725. var v0 = this.v0,
  22726. v1 = this.v1,
  22727. v2 = this.v2,
  22728. v3 = this.v3;
  22729. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22730. return point;
  22731. };
  22732. CubicBezierCurve.prototype.copy = function (source) {
  22733. Curve.prototype.copy.call(this, source);
  22734. this.v0.copy(source.v0);
  22735. this.v1.copy(source.v1);
  22736. this.v2.copy(source.v2);
  22737. this.v3.copy(source.v3);
  22738. return this;
  22739. };
  22740. CubicBezierCurve.prototype.toJSON = function () {
  22741. var data = Curve.prototype.toJSON.call(this);
  22742. data.v0 = this.v0.toArray();
  22743. data.v1 = this.v1.toArray();
  22744. data.v2 = this.v2.toArray();
  22745. data.v3 = this.v3.toArray();
  22746. return data;
  22747. };
  22748. CubicBezierCurve.prototype.fromJSON = function (json) {
  22749. Curve.prototype.fromJSON.call(this, json);
  22750. this.v0.fromArray(json.v0);
  22751. this.v1.fromArray(json.v1);
  22752. this.v2.fromArray(json.v2);
  22753. this.v3.fromArray(json.v3);
  22754. return this;
  22755. };
  22756. function CubicBezierCurve3(v0, v1, v2, v3) {
  22757. Curve.call(this);
  22758. this.type = 'CubicBezierCurve3';
  22759. this.v0 = v0 || new Vector3();
  22760. this.v1 = v1 || new Vector3();
  22761. this.v2 = v2 || new Vector3();
  22762. this.v3 = v3 || new Vector3();
  22763. }
  22764. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  22765. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22766. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22767. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22768. var point = optionalTarget || new Vector3();
  22769. var v0 = this.v0,
  22770. v1 = this.v1,
  22771. v2 = this.v2,
  22772. v3 = this.v3;
  22773. 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));
  22774. return point;
  22775. };
  22776. CubicBezierCurve3.prototype.copy = function (source) {
  22777. Curve.prototype.copy.call(this, source);
  22778. this.v0.copy(source.v0);
  22779. this.v1.copy(source.v1);
  22780. this.v2.copy(source.v2);
  22781. this.v3.copy(source.v3);
  22782. return this;
  22783. };
  22784. CubicBezierCurve3.prototype.toJSON = function () {
  22785. var data = Curve.prototype.toJSON.call(this);
  22786. data.v0 = this.v0.toArray();
  22787. data.v1 = this.v1.toArray();
  22788. data.v2 = this.v2.toArray();
  22789. data.v3 = this.v3.toArray();
  22790. return data;
  22791. };
  22792. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22793. Curve.prototype.fromJSON.call(this, json);
  22794. this.v0.fromArray(json.v0);
  22795. this.v1.fromArray(json.v1);
  22796. this.v2.fromArray(json.v2);
  22797. this.v3.fromArray(json.v3);
  22798. return this;
  22799. };
  22800. function LineCurve(v1, v2) {
  22801. Curve.call(this);
  22802. this.type = 'LineCurve';
  22803. this.v1 = v1 || new Vector2();
  22804. this.v2 = v2 || new Vector2();
  22805. }
  22806. LineCurve.prototype = Object.create(Curve.prototype);
  22807. LineCurve.prototype.constructor = LineCurve;
  22808. LineCurve.prototype.isLineCurve = true;
  22809. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22810. var point = optionalTarget || new Vector2();
  22811. if (t === 1) {
  22812. point.copy(this.v2);
  22813. } else {
  22814. point.copy(this.v2).sub(this.v1);
  22815. point.multiplyScalar(t).add(this.v1);
  22816. }
  22817. return point;
  22818. }; // Line curve is linear, so we can overwrite default getPointAt
  22819. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22820. return this.getPoint(u, optionalTarget);
  22821. };
  22822. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22823. var tangent = optionalTarget || new Vector2();
  22824. tangent.copy(this.v2).sub(this.v1).normalize();
  22825. return tangent;
  22826. };
  22827. LineCurve.prototype.copy = function (source) {
  22828. Curve.prototype.copy.call(this, source);
  22829. this.v1.copy(source.v1);
  22830. this.v2.copy(source.v2);
  22831. return this;
  22832. };
  22833. LineCurve.prototype.toJSON = function () {
  22834. var data = Curve.prototype.toJSON.call(this);
  22835. data.v1 = this.v1.toArray();
  22836. data.v2 = this.v2.toArray();
  22837. return data;
  22838. };
  22839. LineCurve.prototype.fromJSON = function (json) {
  22840. Curve.prototype.fromJSON.call(this, json);
  22841. this.v1.fromArray(json.v1);
  22842. this.v2.fromArray(json.v2);
  22843. return this;
  22844. };
  22845. function LineCurve3(v1, v2) {
  22846. Curve.call(this);
  22847. this.type = 'LineCurve3';
  22848. this.v1 = v1 || new Vector3();
  22849. this.v2 = v2 || new Vector3();
  22850. }
  22851. LineCurve3.prototype = Object.create(Curve.prototype);
  22852. LineCurve3.prototype.constructor = LineCurve3;
  22853. LineCurve3.prototype.isLineCurve3 = true;
  22854. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22855. var point = optionalTarget || new Vector3();
  22856. if (t === 1) {
  22857. point.copy(this.v2);
  22858. } else {
  22859. point.copy(this.v2).sub(this.v1);
  22860. point.multiplyScalar(t).add(this.v1);
  22861. }
  22862. return point;
  22863. }; // Line curve is linear, so we can overwrite default getPointAt
  22864. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22865. return this.getPoint(u, optionalTarget);
  22866. };
  22867. LineCurve3.prototype.copy = function (source) {
  22868. Curve.prototype.copy.call(this, source);
  22869. this.v1.copy(source.v1);
  22870. this.v2.copy(source.v2);
  22871. return this;
  22872. };
  22873. LineCurve3.prototype.toJSON = function () {
  22874. var data = Curve.prototype.toJSON.call(this);
  22875. data.v1 = this.v1.toArray();
  22876. data.v2 = this.v2.toArray();
  22877. return data;
  22878. };
  22879. LineCurve3.prototype.fromJSON = function (json) {
  22880. Curve.prototype.fromJSON.call(this, json);
  22881. this.v1.fromArray(json.v1);
  22882. this.v2.fromArray(json.v2);
  22883. return this;
  22884. };
  22885. function QuadraticBezierCurve(v0, v1, v2) {
  22886. Curve.call(this);
  22887. this.type = 'QuadraticBezierCurve';
  22888. this.v0 = v0 || new Vector2();
  22889. this.v1 = v1 || new Vector2();
  22890. this.v2 = v2 || new Vector2();
  22891. }
  22892. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22893. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22894. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22895. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22896. var point = optionalTarget || new Vector2();
  22897. var v0 = this.v0,
  22898. v1 = this.v1,
  22899. v2 = this.v2;
  22900. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22901. return point;
  22902. };
  22903. QuadraticBezierCurve.prototype.copy = function (source) {
  22904. Curve.prototype.copy.call(this, source);
  22905. this.v0.copy(source.v0);
  22906. this.v1.copy(source.v1);
  22907. this.v2.copy(source.v2);
  22908. return this;
  22909. };
  22910. QuadraticBezierCurve.prototype.toJSON = function () {
  22911. var data = Curve.prototype.toJSON.call(this);
  22912. data.v0 = this.v0.toArray();
  22913. data.v1 = this.v1.toArray();
  22914. data.v2 = this.v2.toArray();
  22915. return data;
  22916. };
  22917. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22918. Curve.prototype.fromJSON.call(this, json);
  22919. this.v0.fromArray(json.v0);
  22920. this.v1.fromArray(json.v1);
  22921. this.v2.fromArray(json.v2);
  22922. return this;
  22923. };
  22924. function QuadraticBezierCurve3(v0, v1, v2) {
  22925. Curve.call(this);
  22926. this.type = 'QuadraticBezierCurve3';
  22927. this.v0 = v0 || new Vector3();
  22928. this.v1 = v1 || new Vector3();
  22929. this.v2 = v2 || new Vector3();
  22930. }
  22931. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22932. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22933. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22934. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22935. var point = optionalTarget || new Vector3();
  22936. var v0 = this.v0,
  22937. v1 = this.v1,
  22938. v2 = this.v2;
  22939. 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));
  22940. return point;
  22941. };
  22942. QuadraticBezierCurve3.prototype.copy = function (source) {
  22943. Curve.prototype.copy.call(this, source);
  22944. this.v0.copy(source.v0);
  22945. this.v1.copy(source.v1);
  22946. this.v2.copy(source.v2);
  22947. return this;
  22948. };
  22949. QuadraticBezierCurve3.prototype.toJSON = function () {
  22950. var data = Curve.prototype.toJSON.call(this);
  22951. data.v0 = this.v0.toArray();
  22952. data.v1 = this.v1.toArray();
  22953. data.v2 = this.v2.toArray();
  22954. return data;
  22955. };
  22956. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  22957. Curve.prototype.fromJSON.call(this, json);
  22958. this.v0.fromArray(json.v0);
  22959. this.v1.fromArray(json.v1);
  22960. this.v2.fromArray(json.v2);
  22961. return this;
  22962. };
  22963. function SplineCurve(points) {
  22964. Curve.call(this);
  22965. this.type = 'SplineCurve';
  22966. this.points = points || [];
  22967. }
  22968. SplineCurve.prototype = Object.create(Curve.prototype);
  22969. SplineCurve.prototype.constructor = SplineCurve;
  22970. SplineCurve.prototype.isSplineCurve = true;
  22971. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  22972. var point = optionalTarget || new Vector2();
  22973. var points = this.points;
  22974. var p = (points.length - 1) * t;
  22975. var intPoint = Math.floor(p);
  22976. var weight = p - intPoint;
  22977. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22978. var p1 = points[intPoint];
  22979. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22980. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22981. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22982. return point;
  22983. };
  22984. SplineCurve.prototype.copy = function (source) {
  22985. Curve.prototype.copy.call(this, source);
  22986. this.points = [];
  22987. for (var i = 0, l = source.points.length; i < l; i++) {
  22988. var point = source.points[i];
  22989. this.points.push(point.clone());
  22990. }
  22991. return this;
  22992. };
  22993. SplineCurve.prototype.toJSON = function () {
  22994. var data = Curve.prototype.toJSON.call(this);
  22995. data.points = [];
  22996. for (var i = 0, l = this.points.length; i < l; i++) {
  22997. var point = this.points[i];
  22998. data.points.push(point.toArray());
  22999. }
  23000. return data;
  23001. };
  23002. SplineCurve.prototype.fromJSON = function (json) {
  23003. Curve.prototype.fromJSON.call(this, json);
  23004. this.points = [];
  23005. for (var i = 0, l = json.points.length; i < l; i++) {
  23006. var point = json.points[i];
  23007. this.points.push(new Vector2().fromArray(point));
  23008. }
  23009. return this;
  23010. };
  23011. var Curves = /*#__PURE__*/Object.freeze({
  23012. __proto__: null,
  23013. ArcCurve: ArcCurve,
  23014. CatmullRomCurve3: CatmullRomCurve3,
  23015. CubicBezierCurve: CubicBezierCurve,
  23016. CubicBezierCurve3: CubicBezierCurve3,
  23017. EllipseCurve: EllipseCurve,
  23018. LineCurve: LineCurve,
  23019. LineCurve3: LineCurve3,
  23020. QuadraticBezierCurve: QuadraticBezierCurve,
  23021. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23022. SplineCurve: SplineCurve
  23023. });
  23024. /**************************************************************
  23025. * Curved Path - a curve path is simply a array of connected
  23026. * curves, but retains the api of a curve
  23027. **************************************************************/
  23028. function CurvePath() {
  23029. Curve.call(this);
  23030. this.type = 'CurvePath';
  23031. this.curves = [];
  23032. this.autoClose = false; // Automatically closes the path
  23033. }
  23034. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  23035. constructor: CurvePath,
  23036. add: function add(curve) {
  23037. this.curves.push(curve);
  23038. },
  23039. closePath: function closePath() {
  23040. // Add a line curve if start and end of lines are not connected
  23041. var startPoint = this.curves[0].getPoint(0);
  23042. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  23043. if (!startPoint.equals(endPoint)) {
  23044. this.curves.push(new LineCurve(endPoint, startPoint));
  23045. }
  23046. },
  23047. // To get accurate point with reference to
  23048. // entire path distance at time t,
  23049. // following has to be done:
  23050. // 1. Length of each sub path have to be known
  23051. // 2. Locate and identify type of curve
  23052. // 3. Get t for the curve
  23053. // 4. Return curve.getPointAt(t')
  23054. getPoint: function getPoint(t) {
  23055. var d = t * this.getLength();
  23056. var curveLengths = this.getCurveLengths();
  23057. var i = 0; // To think about boundaries points.
  23058. while (i < curveLengths.length) {
  23059. if (curveLengths[i] >= d) {
  23060. var diff = curveLengths[i] - d;
  23061. var curve = this.curves[i];
  23062. var segmentLength = curve.getLength();
  23063. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23064. return curve.getPointAt(u);
  23065. }
  23066. i++;
  23067. }
  23068. return null; // loop where sum != 0, sum > d , sum+1 <d
  23069. },
  23070. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23071. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23072. // getPoint() depends on getLength
  23073. getLength: function getLength() {
  23074. var lens = this.getCurveLengths();
  23075. return lens[lens.length - 1];
  23076. },
  23077. // cacheLengths must be recalculated.
  23078. updateArcLengths: function updateArcLengths() {
  23079. this.needsUpdate = true;
  23080. this.cacheLengths = null;
  23081. this.getCurveLengths();
  23082. },
  23083. // Compute lengths and cache them
  23084. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23085. getCurveLengths: function getCurveLengths() {
  23086. // We use cache values if curves and cache array are same length
  23087. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23088. return this.cacheLengths;
  23089. } // Get length of sub-curve
  23090. // Push sums into cached array
  23091. var lengths = [];
  23092. var sums = 0;
  23093. for (var i = 0, l = this.curves.length; i < l; i++) {
  23094. sums += this.curves[i].getLength();
  23095. lengths.push(sums);
  23096. }
  23097. this.cacheLengths = lengths;
  23098. return lengths;
  23099. },
  23100. getSpacedPoints: function getSpacedPoints(divisions) {
  23101. if (divisions === void 0) {
  23102. divisions = 40;
  23103. }
  23104. var points = [];
  23105. for (var i = 0; i <= divisions; i++) {
  23106. points.push(this.getPoint(i / divisions));
  23107. }
  23108. if (this.autoClose) {
  23109. points.push(points[0]);
  23110. }
  23111. return points;
  23112. },
  23113. getPoints: function getPoints(divisions) {
  23114. divisions = divisions || 12;
  23115. var points = [];
  23116. var last;
  23117. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23118. var curve = curves[i];
  23119. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23120. var pts = curve.getPoints(resolution);
  23121. for (var j = 0; j < pts.length; j++) {
  23122. var point = pts[j];
  23123. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23124. points.push(point);
  23125. last = point;
  23126. }
  23127. }
  23128. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23129. points.push(points[0]);
  23130. }
  23131. return points;
  23132. },
  23133. copy: function copy(source) {
  23134. Curve.prototype.copy.call(this, source);
  23135. this.curves = [];
  23136. for (var i = 0, l = source.curves.length; i < l; i++) {
  23137. var curve = source.curves[i];
  23138. this.curves.push(curve.clone());
  23139. }
  23140. this.autoClose = source.autoClose;
  23141. return this;
  23142. },
  23143. toJSON: function toJSON() {
  23144. var data = Curve.prototype.toJSON.call(this);
  23145. data.autoClose = this.autoClose;
  23146. data.curves = [];
  23147. for (var i = 0, l = this.curves.length; i < l; i++) {
  23148. var curve = this.curves[i];
  23149. data.curves.push(curve.toJSON());
  23150. }
  23151. return data;
  23152. },
  23153. fromJSON: function fromJSON(json) {
  23154. Curve.prototype.fromJSON.call(this, json);
  23155. this.autoClose = json.autoClose;
  23156. this.curves = [];
  23157. for (var i = 0, l = json.curves.length; i < l; i++) {
  23158. var curve = json.curves[i];
  23159. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23160. }
  23161. return this;
  23162. }
  23163. });
  23164. function Path(points) {
  23165. CurvePath.call(this);
  23166. this.type = 'Path';
  23167. this.currentPoint = new Vector2();
  23168. if (points) {
  23169. this.setFromPoints(points);
  23170. }
  23171. }
  23172. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  23173. constructor: Path,
  23174. setFromPoints: function setFromPoints(points) {
  23175. this.moveTo(points[0].x, points[0].y);
  23176. for (var i = 1, l = points.length; i < l; i++) {
  23177. this.lineTo(points[i].x, points[i].y);
  23178. }
  23179. return this;
  23180. },
  23181. moveTo: function moveTo(x, y) {
  23182. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23183. return this;
  23184. },
  23185. lineTo: function lineTo(x, y) {
  23186. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23187. this.curves.push(curve);
  23188. this.currentPoint.set(x, y);
  23189. return this;
  23190. },
  23191. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23192. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23193. this.curves.push(curve);
  23194. this.currentPoint.set(aX, aY);
  23195. return this;
  23196. },
  23197. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23198. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23199. this.curves.push(curve);
  23200. this.currentPoint.set(aX, aY);
  23201. return this;
  23202. },
  23203. splineThru: function splineThru(pts
  23204. /*Array of Vector*/
  23205. ) {
  23206. var npts = [this.currentPoint.clone()].concat(pts);
  23207. var curve = new SplineCurve(npts);
  23208. this.curves.push(curve);
  23209. this.currentPoint.copy(pts[pts.length - 1]);
  23210. return this;
  23211. },
  23212. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23213. var x0 = this.currentPoint.x;
  23214. var y0 = this.currentPoint.y;
  23215. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23216. return this;
  23217. },
  23218. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23219. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23220. return this;
  23221. },
  23222. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23223. var x0 = this.currentPoint.x;
  23224. var y0 = this.currentPoint.y;
  23225. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23226. return this;
  23227. },
  23228. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23229. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23230. if (this.curves.length > 0) {
  23231. // if a previous curve is present, attempt to join
  23232. var firstPoint = curve.getPoint(0);
  23233. if (!firstPoint.equals(this.currentPoint)) {
  23234. this.lineTo(firstPoint.x, firstPoint.y);
  23235. }
  23236. }
  23237. this.curves.push(curve);
  23238. var lastPoint = curve.getPoint(1);
  23239. this.currentPoint.copy(lastPoint);
  23240. return this;
  23241. },
  23242. copy: function copy(source) {
  23243. CurvePath.prototype.copy.call(this, source);
  23244. this.currentPoint.copy(source.currentPoint);
  23245. return this;
  23246. },
  23247. toJSON: function toJSON() {
  23248. var data = CurvePath.prototype.toJSON.call(this);
  23249. data.currentPoint = this.currentPoint.toArray();
  23250. return data;
  23251. },
  23252. fromJSON: function fromJSON(json) {
  23253. CurvePath.prototype.fromJSON.call(this, json);
  23254. this.currentPoint.fromArray(json.currentPoint);
  23255. return this;
  23256. }
  23257. });
  23258. function Shape(points) {
  23259. Path.call(this, points);
  23260. this.uuid = MathUtils.generateUUID();
  23261. this.type = 'Shape';
  23262. this.holes = [];
  23263. }
  23264. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23265. constructor: Shape,
  23266. getPointsHoles: function getPointsHoles(divisions) {
  23267. var holesPts = [];
  23268. for (var i = 0, l = this.holes.length; i < l; i++) {
  23269. holesPts[i] = this.holes[i].getPoints(divisions);
  23270. }
  23271. return holesPts;
  23272. },
  23273. // get points of shape and holes (keypoints based on segments parameter)
  23274. extractPoints: function extractPoints(divisions) {
  23275. return {
  23276. shape: this.getPoints(divisions),
  23277. holes: this.getPointsHoles(divisions)
  23278. };
  23279. },
  23280. copy: function copy(source) {
  23281. Path.prototype.copy.call(this, source);
  23282. this.holes = [];
  23283. for (var i = 0, l = source.holes.length; i < l; i++) {
  23284. var hole = source.holes[i];
  23285. this.holes.push(hole.clone());
  23286. }
  23287. return this;
  23288. },
  23289. toJSON: function toJSON() {
  23290. var data = Path.prototype.toJSON.call(this);
  23291. data.uuid = this.uuid;
  23292. data.holes = [];
  23293. for (var i = 0, l = this.holes.length; i < l; i++) {
  23294. var hole = this.holes[i];
  23295. data.holes.push(hole.toJSON());
  23296. }
  23297. return data;
  23298. },
  23299. fromJSON: function fromJSON(json) {
  23300. Path.prototype.fromJSON.call(this, json);
  23301. this.uuid = json.uuid;
  23302. this.holes = [];
  23303. for (var i = 0, l = json.holes.length; i < l; i++) {
  23304. var hole = json.holes[i];
  23305. this.holes.push(new Path().fromJSON(hole));
  23306. }
  23307. return this;
  23308. }
  23309. });
  23310. function Light(color, intensity) {
  23311. Object3D.call(this);
  23312. this.type = 'Light';
  23313. this.color = new Color(color);
  23314. this.intensity = intensity !== undefined ? intensity : 1;
  23315. }
  23316. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23317. constructor: Light,
  23318. isLight: true,
  23319. copy: function copy(source) {
  23320. Object3D.prototype.copy.call(this, source);
  23321. this.color.copy(source.color);
  23322. this.intensity = source.intensity;
  23323. return this;
  23324. },
  23325. toJSON: function toJSON(meta) {
  23326. var data = Object3D.prototype.toJSON.call(this, meta);
  23327. data.object.color = this.color.getHex();
  23328. data.object.intensity = this.intensity;
  23329. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23330. if (this.distance !== undefined) data.object.distance = this.distance;
  23331. if (this.angle !== undefined) data.object.angle = this.angle;
  23332. if (this.decay !== undefined) data.object.decay = this.decay;
  23333. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23334. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23335. return data;
  23336. }
  23337. });
  23338. function HemisphereLight(skyColor, groundColor, intensity) {
  23339. Light.call(this, skyColor, intensity);
  23340. this.type = 'HemisphereLight';
  23341. this.position.copy(Object3D.DefaultUp);
  23342. this.updateMatrix();
  23343. this.groundColor = new Color(groundColor);
  23344. }
  23345. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23346. constructor: HemisphereLight,
  23347. isHemisphereLight: true,
  23348. copy: function copy(source) {
  23349. Light.prototype.copy.call(this, source);
  23350. this.groundColor.copy(source.groundColor);
  23351. return this;
  23352. }
  23353. });
  23354. function LightShadow(camera) {
  23355. this.camera = camera;
  23356. this.bias = 0;
  23357. this.normalBias = 0;
  23358. this.radius = 1;
  23359. this.mapSize = new Vector2(512, 512);
  23360. this.map = null;
  23361. this.mapPass = null;
  23362. this.matrix = new Matrix4();
  23363. this.autoUpdate = true;
  23364. this.needsUpdate = false;
  23365. this._frustum = new Frustum();
  23366. this._frameExtents = new Vector2(1, 1);
  23367. this._viewportCount = 1;
  23368. this._viewports = [new Vector4(0, 0, 1, 1)];
  23369. }
  23370. Object.assign(LightShadow.prototype, {
  23371. _projScreenMatrix: new Matrix4(),
  23372. _lightPositionWorld: new Vector3(),
  23373. _lookTarget: new Vector3(),
  23374. getViewportCount: function getViewportCount() {
  23375. return this._viewportCount;
  23376. },
  23377. getFrustum: function getFrustum() {
  23378. return this._frustum;
  23379. },
  23380. updateMatrices: function updateMatrices(light) {
  23381. var shadowCamera = this.camera,
  23382. shadowMatrix = this.matrix,
  23383. projScreenMatrix = this._projScreenMatrix,
  23384. lookTarget = this._lookTarget,
  23385. lightPositionWorld = this._lightPositionWorld;
  23386. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23387. shadowCamera.position.copy(lightPositionWorld);
  23388. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23389. shadowCamera.lookAt(lookTarget);
  23390. shadowCamera.updateMatrixWorld();
  23391. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23392. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23393. 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);
  23394. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23395. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23396. },
  23397. getViewport: function getViewport(viewportIndex) {
  23398. return this._viewports[viewportIndex];
  23399. },
  23400. getFrameExtents: function getFrameExtents() {
  23401. return this._frameExtents;
  23402. },
  23403. copy: function copy(source) {
  23404. this.camera = source.camera.clone();
  23405. this.bias = source.bias;
  23406. this.radius = source.radius;
  23407. this.mapSize.copy(source.mapSize);
  23408. return this;
  23409. },
  23410. clone: function clone() {
  23411. return new this.constructor().copy(this);
  23412. },
  23413. toJSON: function toJSON() {
  23414. var object = {};
  23415. if (this.bias !== 0) object.bias = this.bias;
  23416. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23417. if (this.radius !== 1) object.radius = this.radius;
  23418. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23419. object.camera = this.camera.toJSON(false).object;
  23420. delete object.camera.matrix;
  23421. return object;
  23422. }
  23423. });
  23424. function SpotLightShadow() {
  23425. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23426. this.focus = 1;
  23427. }
  23428. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23429. constructor: SpotLightShadow,
  23430. isSpotLightShadow: true,
  23431. updateMatrices: function updateMatrices(light) {
  23432. var camera = this.camera;
  23433. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23434. var aspect = this.mapSize.width / this.mapSize.height;
  23435. var far = light.distance || camera.far;
  23436. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23437. camera.fov = fov;
  23438. camera.aspect = aspect;
  23439. camera.far = far;
  23440. camera.updateProjectionMatrix();
  23441. }
  23442. LightShadow.prototype.updateMatrices.call(this, light);
  23443. }
  23444. });
  23445. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23446. Light.call(this, color, intensity);
  23447. this.type = 'SpotLight';
  23448. this.position.copy(Object3D.DefaultUp);
  23449. this.updateMatrix();
  23450. this.target = new Object3D();
  23451. Object.defineProperty(this, 'power', {
  23452. get: function get() {
  23453. // intensity = power per solid angle.
  23454. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23455. return this.intensity * Math.PI;
  23456. },
  23457. set: function set(power) {
  23458. // intensity = power per solid angle.
  23459. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23460. this.intensity = power / Math.PI;
  23461. }
  23462. });
  23463. this.distance = distance !== undefined ? distance : 0;
  23464. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23465. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23466. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23467. this.shadow = new SpotLightShadow();
  23468. }
  23469. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23470. constructor: SpotLight,
  23471. isSpotLight: true,
  23472. copy: function copy(source) {
  23473. Light.prototype.copy.call(this, source);
  23474. this.distance = source.distance;
  23475. this.angle = source.angle;
  23476. this.penumbra = source.penumbra;
  23477. this.decay = source.decay;
  23478. this.target = source.target.clone();
  23479. this.shadow = source.shadow.clone();
  23480. return this;
  23481. }
  23482. });
  23483. function PointLightShadow() {
  23484. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23485. this._frameExtents = new Vector2(4, 2);
  23486. this._viewportCount = 6;
  23487. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23488. // following orientation:
  23489. //
  23490. // xzXZ
  23491. // y Y
  23492. //
  23493. // X - Positive x direction
  23494. // x - Negative x direction
  23495. // Y - Positive y direction
  23496. // y - Negative y direction
  23497. // Z - Positive z direction
  23498. // z - Negative z direction
  23499. // positive X
  23500. new Vector4(2, 1, 1, 1), // negative X
  23501. new Vector4(0, 1, 1, 1), // positive Z
  23502. new Vector4(3, 1, 1, 1), // negative Z
  23503. new Vector4(1, 1, 1, 1), // positive Y
  23504. new Vector4(3, 0, 1, 1), // negative Y
  23505. new Vector4(1, 0, 1, 1)];
  23506. 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)];
  23507. 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)];
  23508. }
  23509. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23510. constructor: PointLightShadow,
  23511. isPointLightShadow: true,
  23512. updateMatrices: function updateMatrices(light, viewportIndex) {
  23513. if (viewportIndex === void 0) {
  23514. viewportIndex = 0;
  23515. }
  23516. var camera = this.camera,
  23517. shadowMatrix = this.matrix,
  23518. lightPositionWorld = this._lightPositionWorld,
  23519. lookTarget = this._lookTarget,
  23520. projScreenMatrix = this._projScreenMatrix;
  23521. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23522. camera.position.copy(lightPositionWorld);
  23523. lookTarget.copy(camera.position);
  23524. lookTarget.add(this._cubeDirections[viewportIndex]);
  23525. camera.up.copy(this._cubeUps[viewportIndex]);
  23526. camera.lookAt(lookTarget);
  23527. camera.updateMatrixWorld();
  23528. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23529. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23530. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23531. }
  23532. });
  23533. function PointLight(color, intensity, distance, decay) {
  23534. Light.call(this, color, intensity);
  23535. this.type = 'PointLight';
  23536. Object.defineProperty(this, 'power', {
  23537. get: function get() {
  23538. // intensity = power per solid angle.
  23539. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23540. return this.intensity * 4 * Math.PI;
  23541. },
  23542. set: function set(power) {
  23543. // intensity = power per solid angle.
  23544. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23545. this.intensity = power / (4 * Math.PI);
  23546. }
  23547. });
  23548. this.distance = distance !== undefined ? distance : 0;
  23549. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23550. this.shadow = new PointLightShadow();
  23551. }
  23552. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23553. constructor: PointLight,
  23554. isPointLight: true,
  23555. copy: function copy(source) {
  23556. Light.prototype.copy.call(this, source);
  23557. this.distance = source.distance;
  23558. this.decay = source.decay;
  23559. this.shadow = source.shadow.clone();
  23560. return this;
  23561. }
  23562. });
  23563. function OrthographicCamera(left, right, top, bottom, near, far) {
  23564. Camera.call(this);
  23565. this.type = 'OrthographicCamera';
  23566. this.zoom = 1;
  23567. this.view = null;
  23568. this.left = left !== undefined ? left : -1;
  23569. this.right = right !== undefined ? right : 1;
  23570. this.top = top !== undefined ? top : 1;
  23571. this.bottom = bottom !== undefined ? bottom : -1;
  23572. this.near = near !== undefined ? near : 0.1;
  23573. this.far = far !== undefined ? far : 2000;
  23574. this.updateProjectionMatrix();
  23575. }
  23576. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23577. constructor: OrthographicCamera,
  23578. isOrthographicCamera: true,
  23579. copy: function copy(source, recursive) {
  23580. Camera.prototype.copy.call(this, source, recursive);
  23581. this.left = source.left;
  23582. this.right = source.right;
  23583. this.top = source.top;
  23584. this.bottom = source.bottom;
  23585. this.near = source.near;
  23586. this.far = source.far;
  23587. this.zoom = source.zoom;
  23588. this.view = source.view === null ? null : Object.assign({}, source.view);
  23589. return this;
  23590. },
  23591. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23592. if (this.view === null) {
  23593. this.view = {
  23594. enabled: true,
  23595. fullWidth: 1,
  23596. fullHeight: 1,
  23597. offsetX: 0,
  23598. offsetY: 0,
  23599. width: 1,
  23600. height: 1
  23601. };
  23602. }
  23603. this.view.enabled = true;
  23604. this.view.fullWidth = fullWidth;
  23605. this.view.fullHeight = fullHeight;
  23606. this.view.offsetX = x;
  23607. this.view.offsetY = y;
  23608. this.view.width = width;
  23609. this.view.height = height;
  23610. this.updateProjectionMatrix();
  23611. },
  23612. clearViewOffset: function clearViewOffset() {
  23613. if (this.view !== null) {
  23614. this.view.enabled = false;
  23615. }
  23616. this.updateProjectionMatrix();
  23617. },
  23618. updateProjectionMatrix: function updateProjectionMatrix() {
  23619. var dx = (this.right - this.left) / (2 * this.zoom);
  23620. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23621. var cx = (this.right + this.left) / 2;
  23622. var cy = (this.top + this.bottom) / 2;
  23623. var left = cx - dx;
  23624. var right = cx + dx;
  23625. var top = cy + dy;
  23626. var bottom = cy - dy;
  23627. if (this.view !== null && this.view.enabled) {
  23628. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23629. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23630. left += scaleW * this.view.offsetX;
  23631. right = left + scaleW * this.view.width;
  23632. top -= scaleH * this.view.offsetY;
  23633. bottom = top - scaleH * this.view.height;
  23634. }
  23635. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23636. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23637. },
  23638. toJSON: function toJSON(meta) {
  23639. var data = Object3D.prototype.toJSON.call(this, meta);
  23640. data.object.zoom = this.zoom;
  23641. data.object.left = this.left;
  23642. data.object.right = this.right;
  23643. data.object.top = this.top;
  23644. data.object.bottom = this.bottom;
  23645. data.object.near = this.near;
  23646. data.object.far = this.far;
  23647. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23648. return data;
  23649. }
  23650. });
  23651. function DirectionalLightShadow() {
  23652. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23653. }
  23654. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23655. constructor: DirectionalLightShadow,
  23656. isDirectionalLightShadow: true,
  23657. updateMatrices: function updateMatrices(light) {
  23658. LightShadow.prototype.updateMatrices.call(this, light);
  23659. }
  23660. });
  23661. function DirectionalLight(color, intensity) {
  23662. Light.call(this, color, intensity);
  23663. this.type = 'DirectionalLight';
  23664. this.position.copy(Object3D.DefaultUp);
  23665. this.updateMatrix();
  23666. this.target = new Object3D();
  23667. this.shadow = new DirectionalLightShadow();
  23668. }
  23669. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23670. constructor: DirectionalLight,
  23671. isDirectionalLight: true,
  23672. copy: function copy(source) {
  23673. Light.prototype.copy.call(this, source);
  23674. this.target = source.target.clone();
  23675. this.shadow = source.shadow.clone();
  23676. return this;
  23677. }
  23678. });
  23679. function AmbientLight(color, intensity) {
  23680. Light.call(this, color, intensity);
  23681. this.type = 'AmbientLight';
  23682. }
  23683. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23684. constructor: AmbientLight,
  23685. isAmbientLight: true
  23686. });
  23687. function RectAreaLight(color, intensity, width, height) {
  23688. Light.call(this, color, intensity);
  23689. this.type = 'RectAreaLight';
  23690. this.width = width !== undefined ? width : 10;
  23691. this.height = height !== undefined ? height : 10;
  23692. }
  23693. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23694. constructor: RectAreaLight,
  23695. isRectAreaLight: true,
  23696. copy: function copy(source) {
  23697. Light.prototype.copy.call(this, source);
  23698. this.width = source.width;
  23699. this.height = source.height;
  23700. return this;
  23701. },
  23702. toJSON: function toJSON(meta) {
  23703. var data = Light.prototype.toJSON.call(this, meta);
  23704. data.object.width = this.width;
  23705. data.object.height = this.height;
  23706. return data;
  23707. }
  23708. });
  23709. /**
  23710. * Primary reference:
  23711. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23712. *
  23713. * Secondary reference:
  23714. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23715. */
  23716. // 3-band SH defined by 9 coefficients
  23717. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23718. function SphericalHarmonics3() {
  23719. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23720. value: true
  23721. });
  23722. this.coefficients = [];
  23723. for (var i = 0; i < 9; i++) {
  23724. this.coefficients.push(new Vector3());
  23725. }
  23726. }
  23727. var _proto = SphericalHarmonics3.prototype;
  23728. _proto.set = function set(coefficients) {
  23729. for (var i = 0; i < 9; i++) {
  23730. this.coefficients[i].copy(coefficients[i]);
  23731. }
  23732. return this;
  23733. };
  23734. _proto.zero = function zero() {
  23735. for (var i = 0; i < 9; i++) {
  23736. this.coefficients[i].set(0, 0, 0);
  23737. }
  23738. return this;
  23739. } // get the radiance in the direction of the normal
  23740. // target is a Vector3
  23741. ;
  23742. _proto.getAt = function getAt(normal, target) {
  23743. // normal is assumed to be unit length
  23744. var x = normal.x,
  23745. y = normal.y,
  23746. z = normal.z;
  23747. var coeff = this.coefficients; // band 0
  23748. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23749. target.addScaledVector(coeff[1], 0.488603 * y);
  23750. target.addScaledVector(coeff[2], 0.488603 * z);
  23751. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23752. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23753. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23754. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23755. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23756. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23757. return target;
  23758. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23759. // target is a Vector3
  23760. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23761. ;
  23762. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23763. // normal is assumed to be unit length
  23764. var x = normal.x,
  23765. y = normal.y,
  23766. z = normal.z;
  23767. var coeff = this.coefficients; // band 0
  23768. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23769. // band 1
  23770. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23771. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23772. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23773. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23774. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23775. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23776. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23777. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23778. return target;
  23779. };
  23780. _proto.add = function add(sh) {
  23781. for (var i = 0; i < 9; i++) {
  23782. this.coefficients[i].add(sh.coefficients[i]);
  23783. }
  23784. return this;
  23785. };
  23786. _proto.addScaledSH = function addScaledSH(sh, s) {
  23787. for (var i = 0; i < 9; i++) {
  23788. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23789. }
  23790. return this;
  23791. };
  23792. _proto.scale = function scale(s) {
  23793. for (var i = 0; i < 9; i++) {
  23794. this.coefficients[i].multiplyScalar(s);
  23795. }
  23796. return this;
  23797. };
  23798. _proto.lerp = function lerp(sh, alpha) {
  23799. for (var i = 0; i < 9; i++) {
  23800. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23801. }
  23802. return this;
  23803. };
  23804. _proto.equals = function equals(sh) {
  23805. for (var i = 0; i < 9; i++) {
  23806. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23807. return false;
  23808. }
  23809. }
  23810. return true;
  23811. };
  23812. _proto.copy = function copy(sh) {
  23813. return this.set(sh.coefficients);
  23814. };
  23815. _proto.clone = function clone() {
  23816. return new this.constructor().copy(this);
  23817. };
  23818. _proto.fromArray = function fromArray(array, offset) {
  23819. if (offset === void 0) {
  23820. offset = 0;
  23821. }
  23822. var coefficients = this.coefficients;
  23823. for (var i = 0; i < 9; i++) {
  23824. coefficients[i].fromArray(array, offset + i * 3);
  23825. }
  23826. return this;
  23827. };
  23828. _proto.toArray = function toArray(array, offset) {
  23829. if (array === void 0) {
  23830. array = [];
  23831. }
  23832. if (offset === void 0) {
  23833. offset = 0;
  23834. }
  23835. var coefficients = this.coefficients;
  23836. for (var i = 0; i < 9; i++) {
  23837. coefficients[i].toArray(array, offset + i * 3);
  23838. }
  23839. return array;
  23840. } // evaluate the basis functions
  23841. // shBasis is an Array[ 9 ]
  23842. ;
  23843. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23844. // normal is assumed to be unit length
  23845. var x = normal.x,
  23846. y = normal.y,
  23847. z = normal.z; // band 0
  23848. shBasis[0] = 0.282095; // band 1
  23849. shBasis[1] = 0.488603 * y;
  23850. shBasis[2] = 0.488603 * z;
  23851. shBasis[3] = 0.488603 * x; // band 2
  23852. shBasis[4] = 1.092548 * x * y;
  23853. shBasis[5] = 1.092548 * y * z;
  23854. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23855. shBasis[7] = 1.092548 * x * z;
  23856. shBasis[8] = 0.546274 * (x * x - y * y);
  23857. };
  23858. return SphericalHarmonics3;
  23859. }();
  23860. function LightProbe(sh, intensity) {
  23861. Light.call(this, undefined, intensity);
  23862. this.type = 'LightProbe';
  23863. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23864. }
  23865. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23866. constructor: LightProbe,
  23867. isLightProbe: true,
  23868. copy: function copy(source) {
  23869. Light.prototype.copy.call(this, source);
  23870. this.sh.copy(source.sh);
  23871. return this;
  23872. },
  23873. fromJSON: function fromJSON(json) {
  23874. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23875. this.sh.fromArray(json.sh);
  23876. return this;
  23877. },
  23878. toJSON: function toJSON(meta) {
  23879. var data = Light.prototype.toJSON.call(this, meta);
  23880. data.object.sh = this.sh.toArray();
  23881. return data;
  23882. }
  23883. });
  23884. function MaterialLoader(manager) {
  23885. Loader.call(this, manager);
  23886. this.textures = {};
  23887. }
  23888. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23889. constructor: MaterialLoader,
  23890. load: function load(url, onLoad, onProgress, onError) {
  23891. var scope = this;
  23892. var loader = new FileLoader(scope.manager);
  23893. loader.setPath(scope.path);
  23894. loader.setRequestHeader(scope.requestHeader);
  23895. loader.setWithCredentials(scope.withCredentials);
  23896. loader.load(url, function (text) {
  23897. try {
  23898. onLoad(scope.parse(JSON.parse(text)));
  23899. } catch (e) {
  23900. if (onError) {
  23901. onError(e);
  23902. } else {
  23903. console.error(e);
  23904. }
  23905. scope.manager.itemError(url);
  23906. }
  23907. }, onProgress, onError);
  23908. },
  23909. parse: function parse(json) {
  23910. var textures = this.textures;
  23911. function getTexture(name) {
  23912. if (textures[name] === undefined) {
  23913. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23914. }
  23915. return textures[name];
  23916. }
  23917. var material = new Materials[json.type]();
  23918. if (json.uuid !== undefined) material.uuid = json.uuid;
  23919. if (json.name !== undefined) material.name = json.name;
  23920. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  23921. if (json.roughness !== undefined) material.roughness = json.roughness;
  23922. if (json.metalness !== undefined) material.metalness = json.metalness;
  23923. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23924. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  23925. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  23926. if (json.shininess !== undefined) material.shininess = json.shininess;
  23927. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23928. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23929. if (json.fog !== undefined) material.fog = json.fog;
  23930. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23931. if (json.blending !== undefined) material.blending = json.blending;
  23932. if (json.combine !== undefined) material.combine = json.combine;
  23933. if (json.side !== undefined) material.side = json.side;
  23934. if (json.opacity !== undefined) material.opacity = json.opacity;
  23935. if (json.transparent !== undefined) material.transparent = json.transparent;
  23936. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23937. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23938. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23939. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23940. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23941. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23942. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23943. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23944. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23945. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23946. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23947. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23948. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23949. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23950. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23951. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23952. if (json.rotation !== undefined) material.rotation = json.rotation;
  23953. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23954. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23955. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23956. if (json.scale !== undefined) material.scale = json.scale;
  23957. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23958. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23959. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23960. if (json.skinning !== undefined) material.skinning = json.skinning;
  23961. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23962. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23963. if (json.dithering !== undefined) material.dithering = json.dithering;
  23964. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23965. if (json.visible !== undefined) material.visible = json.visible;
  23966. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23967. if (json.userData !== undefined) material.userData = json.userData;
  23968. if (json.vertexColors !== undefined) {
  23969. if (typeof json.vertexColors === 'number') {
  23970. material.vertexColors = json.vertexColors > 0 ? true : false;
  23971. } else {
  23972. material.vertexColors = json.vertexColors;
  23973. }
  23974. } // Shader Material
  23975. if (json.uniforms !== undefined) {
  23976. for (var name in json.uniforms) {
  23977. var uniform = json.uniforms[name];
  23978. material.uniforms[name] = {};
  23979. switch (uniform.type) {
  23980. case 't':
  23981. material.uniforms[name].value = getTexture(uniform.value);
  23982. break;
  23983. case 'c':
  23984. material.uniforms[name].value = new Color().setHex(uniform.value);
  23985. break;
  23986. case 'v2':
  23987. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23988. break;
  23989. case 'v3':
  23990. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23991. break;
  23992. case 'v4':
  23993. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23994. break;
  23995. case 'm3':
  23996. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23997. break;
  23998. case 'm4':
  23999. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24000. break;
  24001. default:
  24002. material.uniforms[name].value = uniform.value;
  24003. }
  24004. }
  24005. }
  24006. if (json.defines !== undefined) material.defines = json.defines;
  24007. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24008. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24009. if (json.extensions !== undefined) {
  24010. for (var key in json.extensions) {
  24011. material.extensions[key] = json.extensions[key];
  24012. }
  24013. } // Deprecated
  24014. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24015. // for PointsMaterial
  24016. if (json.size !== undefined) material.size = json.size;
  24017. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24018. if (json.map !== undefined) material.map = getTexture(json.map);
  24019. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24020. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24021. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24022. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24023. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24024. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24025. if (json.normalScale !== undefined) {
  24026. var normalScale = json.normalScale;
  24027. if (Array.isArray(normalScale) === false) {
  24028. // Blender exporter used to export a scalar. See #7459
  24029. normalScale = [normalScale, normalScale];
  24030. }
  24031. material.normalScale = new Vector2().fromArray(normalScale);
  24032. }
  24033. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24034. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24035. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24036. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24037. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24038. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24039. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24040. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24041. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24042. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24043. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24044. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24045. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24046. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24047. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24048. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24049. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24050. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24051. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24052. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24053. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24054. if (json.transmission !== undefined) material.transmission = json.transmission;
  24055. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24056. return material;
  24057. },
  24058. setTextures: function setTextures(value) {
  24059. this.textures = value;
  24060. return this;
  24061. }
  24062. });
  24063. var LoaderUtils = {
  24064. decodeText: function decodeText(array) {
  24065. if (typeof TextDecoder !== 'undefined') {
  24066. return new TextDecoder().decode(array);
  24067. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24068. // throws a "maximum call stack size exceeded" error for large arrays.
  24069. var s = '';
  24070. for (var i = 0, il = array.length; i < il; i++) {
  24071. // Implicitly assumes little-endian.
  24072. s += String.fromCharCode(array[i]);
  24073. }
  24074. try {
  24075. // merges multi-byte utf-8 characters.
  24076. return decodeURIComponent(escape(s));
  24077. } catch (e) {
  24078. // see #16358
  24079. return s;
  24080. }
  24081. },
  24082. extractUrlBase: function extractUrlBase(url) {
  24083. var index = url.lastIndexOf('/');
  24084. if (index === -1) return './';
  24085. return url.substr(0, index + 1);
  24086. }
  24087. };
  24088. function InstancedBufferGeometry() {
  24089. BufferGeometry.call(this);
  24090. this.type = 'InstancedBufferGeometry';
  24091. this.instanceCount = Infinity;
  24092. }
  24093. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24094. constructor: InstancedBufferGeometry,
  24095. isInstancedBufferGeometry: true,
  24096. copy: function copy(source) {
  24097. BufferGeometry.prototype.copy.call(this, source);
  24098. this.instanceCount = source.instanceCount;
  24099. return this;
  24100. },
  24101. clone: function clone() {
  24102. return new this.constructor().copy(this);
  24103. },
  24104. toJSON: function toJSON() {
  24105. var data = BufferGeometry.prototype.toJSON.call(this);
  24106. data.instanceCount = this.instanceCount;
  24107. data.isInstancedBufferGeometry = true;
  24108. return data;
  24109. }
  24110. });
  24111. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24112. if (typeof normalized === 'number') {
  24113. meshPerAttribute = normalized;
  24114. normalized = false;
  24115. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24116. }
  24117. BufferAttribute.call(this, array, itemSize, normalized);
  24118. this.meshPerAttribute = meshPerAttribute || 1;
  24119. }
  24120. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24121. constructor: InstancedBufferAttribute,
  24122. isInstancedBufferAttribute: true,
  24123. copy: function copy(source) {
  24124. BufferAttribute.prototype.copy.call(this, source);
  24125. this.meshPerAttribute = source.meshPerAttribute;
  24126. return this;
  24127. },
  24128. toJSON: function toJSON() {
  24129. var data = BufferAttribute.prototype.toJSON.call(this);
  24130. data.meshPerAttribute = this.meshPerAttribute;
  24131. data.isInstancedBufferAttribute = true;
  24132. return data;
  24133. }
  24134. });
  24135. function BufferGeometryLoader(manager) {
  24136. Loader.call(this, manager);
  24137. }
  24138. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24139. constructor: BufferGeometryLoader,
  24140. load: function load(url, onLoad, onProgress, onError) {
  24141. var scope = this;
  24142. var loader = new FileLoader(scope.manager);
  24143. loader.setPath(scope.path);
  24144. loader.setRequestHeader(scope.requestHeader);
  24145. loader.setWithCredentials(scope.withCredentials);
  24146. loader.load(url, function (text) {
  24147. try {
  24148. onLoad(scope.parse(JSON.parse(text)));
  24149. } catch (e) {
  24150. if (onError) {
  24151. onError(e);
  24152. } else {
  24153. console.error(e);
  24154. }
  24155. scope.manager.itemError(url);
  24156. }
  24157. }, onProgress, onError);
  24158. },
  24159. parse: function parse(json) {
  24160. var interleavedBufferMap = {};
  24161. var arrayBufferMap = {};
  24162. function getInterleavedBuffer(json, uuid) {
  24163. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24164. var interleavedBuffers = json.interleavedBuffers;
  24165. var interleavedBuffer = interleavedBuffers[uuid];
  24166. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24167. var array = new TYPED_ARRAYS[interleavedBuffer.type](buffer);
  24168. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24169. ib.uuid = interleavedBuffer.uuid;
  24170. interleavedBufferMap[uuid] = ib;
  24171. return ib;
  24172. }
  24173. function getArrayBuffer(json, uuid) {
  24174. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24175. var arrayBuffers = json.arrayBuffers;
  24176. var arrayBuffer = arrayBuffers[uuid];
  24177. var ab = new Uint32Array(arrayBuffer).buffer;
  24178. arrayBufferMap[uuid] = ab;
  24179. return ab;
  24180. }
  24181. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24182. var index = json.data.index;
  24183. if (index !== undefined) {
  24184. var typedArray = new TYPED_ARRAYS[index.type](index.array);
  24185. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24186. }
  24187. var attributes = json.data.attributes;
  24188. for (var key in attributes) {
  24189. var attribute = attributes[key];
  24190. var bufferAttribute = void 0;
  24191. if (attribute.isInterleavedBufferAttribute) {
  24192. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24193. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24194. } else {
  24195. var _typedArray = new TYPED_ARRAYS[attribute.type](attribute.array);
  24196. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24197. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24198. }
  24199. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24200. geometry.setAttribute(key, bufferAttribute);
  24201. }
  24202. var morphAttributes = json.data.morphAttributes;
  24203. if (morphAttributes) {
  24204. for (var _key in morphAttributes) {
  24205. var attributeArray = morphAttributes[_key];
  24206. var array = [];
  24207. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24208. var _attribute = attributeArray[i];
  24209. var _bufferAttribute = void 0;
  24210. if (_attribute.isInterleavedBufferAttribute) {
  24211. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24212. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24213. } else {
  24214. var _typedArray2 = new TYPED_ARRAYS[_attribute.type](_attribute.array);
  24215. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24216. }
  24217. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24218. array.push(_bufferAttribute);
  24219. }
  24220. geometry.morphAttributes[_key] = array;
  24221. }
  24222. }
  24223. var morphTargetsRelative = json.data.morphTargetsRelative;
  24224. if (morphTargetsRelative) {
  24225. geometry.morphTargetsRelative = true;
  24226. }
  24227. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24228. if (groups !== undefined) {
  24229. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24230. var group = groups[_i];
  24231. geometry.addGroup(group.start, group.count, group.materialIndex);
  24232. }
  24233. }
  24234. var boundingSphere = json.data.boundingSphere;
  24235. if (boundingSphere !== undefined) {
  24236. var center = new Vector3();
  24237. if (boundingSphere.center !== undefined) {
  24238. center.fromArray(boundingSphere.center);
  24239. }
  24240. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24241. }
  24242. if (json.name) geometry.name = json.name;
  24243. if (json.userData) geometry.userData = json.userData;
  24244. return geometry;
  24245. }
  24246. });
  24247. var TYPED_ARRAYS = {
  24248. Int8Array: Int8Array,
  24249. Uint8Array: Uint8Array,
  24250. // Workaround for IE11 pre KB2929437. See #11440
  24251. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  24252. Int16Array: Int16Array,
  24253. Uint16Array: Uint16Array,
  24254. Int32Array: Int32Array,
  24255. Uint32Array: Uint32Array,
  24256. Float32Array: Float32Array,
  24257. Float64Array: Float64Array
  24258. };
  24259. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24260. _inheritsLoose(ObjectLoader, _Loader);
  24261. function ObjectLoader(manager) {
  24262. return _Loader.call(this, manager) || this;
  24263. }
  24264. var _proto = ObjectLoader.prototype;
  24265. _proto.load = function load(url, onLoad, onProgress, onError) {
  24266. var scope = this;
  24267. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24268. this.resourcePath = this.resourcePath || path;
  24269. var loader = new FileLoader(this.manager);
  24270. loader.setPath(this.path);
  24271. loader.setRequestHeader(this.requestHeader);
  24272. loader.setWithCredentials(this.withCredentials);
  24273. loader.load(url, function (text) {
  24274. var json = null;
  24275. try {
  24276. json = JSON.parse(text);
  24277. } catch (error) {
  24278. if (onError !== undefined) onError(error);
  24279. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24280. return;
  24281. }
  24282. var metadata = json.metadata;
  24283. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24284. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24285. return;
  24286. }
  24287. scope.parse(json, onLoad);
  24288. }, onProgress, onError);
  24289. };
  24290. _proto.parse = function parse(json, onLoad) {
  24291. var shapes = this.parseShapes(json.shapes);
  24292. var geometries = this.parseGeometries(json.geometries, shapes);
  24293. var images = this.parseImages(json.images, function () {
  24294. if (onLoad !== undefined) onLoad(object);
  24295. });
  24296. var textures = this.parseTextures(json.textures, images);
  24297. var materials = this.parseMaterials(json.materials, textures);
  24298. var object = this.parseObject(json.object, geometries, materials);
  24299. var skeletons = this.parseSkeletons(json.skeletons, object);
  24300. this.bindSkeletons(object, skeletons);
  24301. if (json.animations) {
  24302. object.animations = this.parseAnimations(json.animations);
  24303. }
  24304. if (json.images === undefined || json.images.length === 0) {
  24305. if (onLoad !== undefined) onLoad(object);
  24306. }
  24307. return object;
  24308. };
  24309. _proto.parseShapes = function parseShapes(json) {
  24310. var shapes = {};
  24311. if (json !== undefined) {
  24312. for (var i = 0, l = json.length; i < l; i++) {
  24313. var shape = new Shape().fromJSON(json[i]);
  24314. shapes[shape.uuid] = shape;
  24315. }
  24316. }
  24317. return shapes;
  24318. };
  24319. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24320. var skeletons = {};
  24321. var bones = {}; // generate bone lookup table
  24322. object.traverse(function (child) {
  24323. if (child.isBone) bones[child.uuid] = child;
  24324. }); // create skeletons
  24325. if (json !== undefined) {
  24326. for (var i = 0, l = json.length; i < l; i++) {
  24327. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24328. skeletons[skeleton.uuid] = skeleton;
  24329. }
  24330. }
  24331. return skeletons;
  24332. };
  24333. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24334. var geometries = {};
  24335. var geometryShapes;
  24336. if (json !== undefined) {
  24337. var bufferGeometryLoader = new BufferGeometryLoader();
  24338. for (var i = 0, l = json.length; i < l; i++) {
  24339. var geometry = void 0;
  24340. var data = json[i];
  24341. switch (data.type) {
  24342. case 'PlaneGeometry':
  24343. case 'PlaneBufferGeometry':
  24344. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24345. break;
  24346. case 'BoxGeometry':
  24347. case 'BoxBufferGeometry':
  24348. case 'CubeGeometry':
  24349. // backwards compatible
  24350. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24351. break;
  24352. case 'CircleGeometry':
  24353. case 'CircleBufferGeometry':
  24354. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24355. break;
  24356. case 'CylinderGeometry':
  24357. case 'CylinderBufferGeometry':
  24358. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24359. break;
  24360. case 'ConeGeometry':
  24361. case 'ConeBufferGeometry':
  24362. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24363. break;
  24364. case 'SphereGeometry':
  24365. case 'SphereBufferGeometry':
  24366. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24367. break;
  24368. case 'DodecahedronGeometry':
  24369. case 'DodecahedronBufferGeometry':
  24370. case 'IcosahedronGeometry':
  24371. case 'IcosahedronBufferGeometry':
  24372. case 'OctahedronGeometry':
  24373. case 'OctahedronBufferGeometry':
  24374. case 'TetrahedronGeometry':
  24375. case 'TetrahedronBufferGeometry':
  24376. geometry = new Geometries[data.type](data.radius, data.detail);
  24377. break;
  24378. case 'RingGeometry':
  24379. case 'RingBufferGeometry':
  24380. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24381. break;
  24382. case 'TorusGeometry':
  24383. case 'TorusBufferGeometry':
  24384. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24385. break;
  24386. case 'TorusKnotGeometry':
  24387. case 'TorusKnotBufferGeometry':
  24388. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24389. break;
  24390. case 'TubeGeometry':
  24391. case 'TubeBufferGeometry':
  24392. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24393. // User defined curves or instances of CurvePath will not be deserialized.
  24394. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24395. break;
  24396. case 'LatheGeometry':
  24397. case 'LatheBufferGeometry':
  24398. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24399. break;
  24400. case 'PolyhedronGeometry':
  24401. case 'PolyhedronBufferGeometry':
  24402. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24403. break;
  24404. case 'ShapeGeometry':
  24405. case 'ShapeBufferGeometry':
  24406. geometryShapes = [];
  24407. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24408. var shape = shapes[data.shapes[j]];
  24409. geometryShapes.push(shape);
  24410. }
  24411. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24412. break;
  24413. case 'ExtrudeGeometry':
  24414. case 'ExtrudeBufferGeometry':
  24415. geometryShapes = [];
  24416. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24417. var _shape = shapes[data.shapes[_j]];
  24418. geometryShapes.push(_shape);
  24419. }
  24420. var extrudePath = data.options.extrudePath;
  24421. if (extrudePath !== undefined) {
  24422. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24423. }
  24424. geometry = new Geometries[data.type](geometryShapes, data.options);
  24425. break;
  24426. case 'BufferGeometry':
  24427. case 'InstancedBufferGeometry':
  24428. geometry = bufferGeometryLoader.parse(data);
  24429. break;
  24430. case 'Geometry':
  24431. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24432. break;
  24433. default:
  24434. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24435. continue;
  24436. }
  24437. geometry.uuid = data.uuid;
  24438. if (data.name !== undefined) geometry.name = data.name;
  24439. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24440. geometries[data.uuid] = geometry;
  24441. }
  24442. }
  24443. return geometries;
  24444. };
  24445. _proto.parseMaterials = function parseMaterials(json, textures) {
  24446. var cache = {}; // MultiMaterial
  24447. var materials = {};
  24448. if (json !== undefined) {
  24449. var loader = new MaterialLoader();
  24450. loader.setTextures(textures);
  24451. for (var i = 0, l = json.length; i < l; i++) {
  24452. var data = json[i];
  24453. if (data.type === 'MultiMaterial') {
  24454. // Deprecated
  24455. var array = [];
  24456. for (var j = 0; j < data.materials.length; j++) {
  24457. var material = data.materials[j];
  24458. if (cache[material.uuid] === undefined) {
  24459. cache[material.uuid] = loader.parse(material);
  24460. }
  24461. array.push(cache[material.uuid]);
  24462. }
  24463. materials[data.uuid] = array;
  24464. } else {
  24465. if (cache[data.uuid] === undefined) {
  24466. cache[data.uuid] = loader.parse(data);
  24467. }
  24468. materials[data.uuid] = cache[data.uuid];
  24469. }
  24470. }
  24471. }
  24472. return materials;
  24473. };
  24474. _proto.parseAnimations = function parseAnimations(json) {
  24475. var animations = [];
  24476. for (var i = 0; i < json.length; i++) {
  24477. var data = json[i];
  24478. var clip = AnimationClip.parse(data);
  24479. if (data.uuid !== undefined) clip.uuid = data.uuid;
  24480. animations.push(clip);
  24481. }
  24482. return animations;
  24483. };
  24484. _proto.parseImages = function parseImages(json, onLoad) {
  24485. var scope = this;
  24486. var images = {};
  24487. var loader;
  24488. function loadImage(url) {
  24489. scope.manager.itemStart(url);
  24490. return loader.load(url, function () {
  24491. scope.manager.itemEnd(url);
  24492. }, undefined, function () {
  24493. scope.manager.itemError(url);
  24494. scope.manager.itemEnd(url);
  24495. });
  24496. }
  24497. if (json !== undefined && json.length > 0) {
  24498. var manager = new LoadingManager(onLoad);
  24499. loader = new ImageLoader(manager);
  24500. loader.setCrossOrigin(this.crossOrigin);
  24501. for (var i = 0, il = json.length; i < il; i++) {
  24502. var image = json[i];
  24503. var url = image.url;
  24504. if (Array.isArray(url)) {
  24505. // load array of images e.g CubeTexture
  24506. images[image.uuid] = [];
  24507. for (var j = 0, jl = url.length; j < jl; j++) {
  24508. var currentUrl = url[j];
  24509. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(currentUrl) ? currentUrl : scope.resourcePath + currentUrl;
  24510. images[image.uuid].push(loadImage(path));
  24511. }
  24512. } else {
  24513. // load single image
  24514. var _path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(image.url) ? image.url : scope.resourcePath + image.url;
  24515. images[image.uuid] = loadImage(_path);
  24516. }
  24517. }
  24518. }
  24519. return images;
  24520. };
  24521. _proto.parseTextures = function parseTextures(json, images) {
  24522. function parseConstant(value, type) {
  24523. if (typeof value === 'number') return value;
  24524. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24525. return type[value];
  24526. }
  24527. var textures = {};
  24528. if (json !== undefined) {
  24529. for (var i = 0, l = json.length; i < l; i++) {
  24530. var data = json[i];
  24531. if (data.image === undefined) {
  24532. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24533. }
  24534. if (images[data.image] === undefined) {
  24535. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24536. }
  24537. var texture = void 0;
  24538. if (Array.isArray(images[data.image])) {
  24539. texture = new CubeTexture(images[data.image]);
  24540. } else {
  24541. texture = new Texture(images[data.image]);
  24542. }
  24543. texture.needsUpdate = true;
  24544. texture.uuid = data.uuid;
  24545. if (data.name !== undefined) texture.name = data.name;
  24546. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24547. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24548. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24549. if (data.center !== undefined) texture.center.fromArray(data.center);
  24550. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24551. if (data.wrap !== undefined) {
  24552. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24553. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24554. }
  24555. if (data.format !== undefined) texture.format = data.format;
  24556. if (data.type !== undefined) texture.type = data.type;
  24557. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24558. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24559. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24560. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24561. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24562. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24563. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24564. textures[data.uuid] = texture;
  24565. }
  24566. }
  24567. return textures;
  24568. };
  24569. _proto.parseObject = function parseObject(data, geometries, materials) {
  24570. var object;
  24571. function getGeometry(name) {
  24572. if (geometries[name] === undefined) {
  24573. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24574. }
  24575. return geometries[name];
  24576. }
  24577. function getMaterial(name) {
  24578. if (name === undefined) return undefined;
  24579. if (Array.isArray(name)) {
  24580. var array = [];
  24581. for (var i = 0, l = name.length; i < l; i++) {
  24582. var uuid = name[i];
  24583. if (materials[uuid] === undefined) {
  24584. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24585. }
  24586. array.push(materials[uuid]);
  24587. }
  24588. return array;
  24589. }
  24590. if (materials[name] === undefined) {
  24591. console.warn('THREE.ObjectLoader: Undefined material', name);
  24592. }
  24593. return materials[name];
  24594. }
  24595. var geometry, material;
  24596. switch (data.type) {
  24597. case 'Scene':
  24598. object = new Scene();
  24599. if (data.background !== undefined) {
  24600. if (Number.isInteger(data.background)) {
  24601. object.background = new Color(data.background);
  24602. }
  24603. }
  24604. if (data.fog !== undefined) {
  24605. if (data.fog.type === 'Fog') {
  24606. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24607. } else if (data.fog.type === 'FogExp2') {
  24608. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24609. }
  24610. }
  24611. break;
  24612. case 'PerspectiveCamera':
  24613. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24614. if (data.focus !== undefined) object.focus = data.focus;
  24615. if (data.zoom !== undefined) object.zoom = data.zoom;
  24616. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24617. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24618. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24619. break;
  24620. case 'OrthographicCamera':
  24621. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24622. if (data.zoom !== undefined) object.zoom = data.zoom;
  24623. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24624. break;
  24625. case 'AmbientLight':
  24626. object = new AmbientLight(data.color, data.intensity);
  24627. break;
  24628. case 'DirectionalLight':
  24629. object = new DirectionalLight(data.color, data.intensity);
  24630. break;
  24631. case 'PointLight':
  24632. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24633. break;
  24634. case 'RectAreaLight':
  24635. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24636. break;
  24637. case 'SpotLight':
  24638. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24639. break;
  24640. case 'HemisphereLight':
  24641. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24642. break;
  24643. case 'LightProbe':
  24644. object = new LightProbe().fromJSON(data);
  24645. break;
  24646. case 'SkinnedMesh':
  24647. geometry = getGeometry(data.geometry);
  24648. material = getMaterial(data.material);
  24649. object = new SkinnedMesh(geometry, material);
  24650. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24651. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24652. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24653. break;
  24654. case 'Mesh':
  24655. geometry = getGeometry(data.geometry);
  24656. material = getMaterial(data.material);
  24657. object = new Mesh(geometry, material);
  24658. break;
  24659. case 'InstancedMesh':
  24660. geometry = getGeometry(data.geometry);
  24661. material = getMaterial(data.material);
  24662. var count = data.count;
  24663. var instanceMatrix = data.instanceMatrix;
  24664. object = new InstancedMesh(geometry, material, count);
  24665. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24666. break;
  24667. case 'LOD':
  24668. object = new LOD();
  24669. break;
  24670. case 'Line':
  24671. object = new Line(getGeometry(data.geometry), getMaterial(data.material), data.mode);
  24672. break;
  24673. case 'LineLoop':
  24674. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24675. break;
  24676. case 'LineSegments':
  24677. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24678. break;
  24679. case 'PointCloud':
  24680. case 'Points':
  24681. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24682. break;
  24683. case 'Sprite':
  24684. object = new Sprite(getMaterial(data.material));
  24685. break;
  24686. case 'Group':
  24687. object = new Group();
  24688. break;
  24689. case 'Bone':
  24690. object = new Bone();
  24691. break;
  24692. default:
  24693. object = new Object3D();
  24694. }
  24695. object.uuid = data.uuid;
  24696. if (data.name !== undefined) object.name = data.name;
  24697. if (data.matrix !== undefined) {
  24698. object.matrix.fromArray(data.matrix);
  24699. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24700. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24701. } else {
  24702. if (data.position !== undefined) object.position.fromArray(data.position);
  24703. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24704. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24705. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24706. }
  24707. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24708. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24709. if (data.shadow) {
  24710. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24711. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24712. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24713. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24714. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24715. }
  24716. if (data.visible !== undefined) object.visible = data.visible;
  24717. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24718. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24719. if (data.userData !== undefined) object.userData = data.userData;
  24720. if (data.layers !== undefined) object.layers.mask = data.layers;
  24721. if (data.children !== undefined) {
  24722. var children = data.children;
  24723. for (var i = 0; i < children.length; i++) {
  24724. object.add(this.parseObject(children[i], geometries, materials));
  24725. }
  24726. }
  24727. if (data.type === 'LOD') {
  24728. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24729. var levels = data.levels;
  24730. for (var l = 0; l < levels.length; l++) {
  24731. var level = levels[l];
  24732. var child = object.getObjectByProperty('uuid', level.object);
  24733. if (child !== undefined) {
  24734. object.addLevel(child, level.distance);
  24735. }
  24736. }
  24737. }
  24738. return object;
  24739. };
  24740. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24741. if (Object.keys(skeletons).length === 0) return;
  24742. object.traverse(function (child) {
  24743. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24744. var skeleton = skeletons[child.skeleton];
  24745. if (skeleton === undefined) {
  24746. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24747. } else {
  24748. child.bind(skeleton, child.bindMatrix);
  24749. }
  24750. }
  24751. });
  24752. }
  24753. /* DEPRECATED */
  24754. ;
  24755. _proto.setTexturePath = function setTexturePath(value) {
  24756. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24757. return this.setResourcePath(value);
  24758. };
  24759. return ObjectLoader;
  24760. }(Loader);
  24761. var TEXTURE_MAPPING = {
  24762. UVMapping: UVMapping,
  24763. CubeReflectionMapping: CubeReflectionMapping,
  24764. CubeRefractionMapping: CubeRefractionMapping,
  24765. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24766. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24767. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24768. CubeUVRefractionMapping: CubeUVRefractionMapping
  24769. };
  24770. var TEXTURE_WRAPPING = {
  24771. RepeatWrapping: RepeatWrapping,
  24772. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24773. MirroredRepeatWrapping: MirroredRepeatWrapping
  24774. };
  24775. var TEXTURE_FILTER = {
  24776. NearestFilter: NearestFilter,
  24777. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24778. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24779. LinearFilter: LinearFilter,
  24780. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24781. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24782. };
  24783. function ImageBitmapLoader(manager) {
  24784. if (typeof createImageBitmap === 'undefined') {
  24785. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24786. }
  24787. if (typeof fetch === 'undefined') {
  24788. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24789. }
  24790. Loader.call(this, manager);
  24791. this.options = {
  24792. premultiplyAlpha: 'none'
  24793. };
  24794. }
  24795. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24796. constructor: ImageBitmapLoader,
  24797. isImageBitmapLoader: true,
  24798. setOptions: function setOptions(options) {
  24799. this.options = options;
  24800. return this;
  24801. },
  24802. load: function load(url, onLoad, onProgress, onError) {
  24803. if (url === undefined) url = '';
  24804. if (this.path !== undefined) url = this.path + url;
  24805. url = this.manager.resolveURL(url);
  24806. var scope = this;
  24807. var cached = Cache.get(url);
  24808. if (cached !== undefined) {
  24809. scope.manager.itemStart(url);
  24810. setTimeout(function () {
  24811. if (onLoad) onLoad(cached);
  24812. scope.manager.itemEnd(url);
  24813. }, 0);
  24814. return cached;
  24815. }
  24816. var fetchOptions = {};
  24817. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24818. fetch(url, fetchOptions).then(function (res) {
  24819. return res.blob();
  24820. }).then(function (blob) {
  24821. return createImageBitmap(blob, scope.options);
  24822. }).then(function (imageBitmap) {
  24823. Cache.add(url, imageBitmap);
  24824. if (onLoad) onLoad(imageBitmap);
  24825. scope.manager.itemEnd(url);
  24826. }).catch(function (e) {
  24827. if (onError) onError(e);
  24828. scope.manager.itemError(url);
  24829. scope.manager.itemEnd(url);
  24830. });
  24831. scope.manager.itemStart(url);
  24832. }
  24833. });
  24834. function ShapePath() {
  24835. this.type = 'ShapePath';
  24836. this.color = new Color();
  24837. this.subPaths = [];
  24838. this.currentPath = null;
  24839. }
  24840. Object.assign(ShapePath.prototype, {
  24841. moveTo: function moveTo(x, y) {
  24842. this.currentPath = new Path();
  24843. this.subPaths.push(this.currentPath);
  24844. this.currentPath.moveTo(x, y);
  24845. return this;
  24846. },
  24847. lineTo: function lineTo(x, y) {
  24848. this.currentPath.lineTo(x, y);
  24849. return this;
  24850. },
  24851. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24852. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24853. return this;
  24854. },
  24855. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24856. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24857. return this;
  24858. },
  24859. splineThru: function splineThru(pts) {
  24860. this.currentPath.splineThru(pts);
  24861. return this;
  24862. },
  24863. toShapes: function toShapes(isCCW, noHoles) {
  24864. function toShapesNoHoles(inSubpaths) {
  24865. var shapes = [];
  24866. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24867. var _tmpPath = inSubpaths[i];
  24868. var _tmpShape = new Shape();
  24869. _tmpShape.curves = _tmpPath.curves;
  24870. shapes.push(_tmpShape);
  24871. }
  24872. return shapes;
  24873. }
  24874. function isPointInsidePolygon(inPt, inPolygon) {
  24875. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24876. // toggling of inside/outside at every single! intersection point of an edge
  24877. // with the horizontal line through inPt, left of inPt
  24878. // not counting lowerY endpoints of edges and whole edges on that line
  24879. var inside = false;
  24880. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24881. var edgeLowPt = inPolygon[p];
  24882. var edgeHighPt = inPolygon[q];
  24883. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24884. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24885. if (Math.abs(edgeDy) > Number.EPSILON) {
  24886. // not parallel
  24887. if (edgeDy < 0) {
  24888. edgeLowPt = inPolygon[q];
  24889. edgeDx = -edgeDx;
  24890. edgeHighPt = inPolygon[p];
  24891. edgeDy = -edgeDy;
  24892. }
  24893. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24894. if (inPt.y === edgeLowPt.y) {
  24895. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24896. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24897. } else {
  24898. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24899. if (perpEdge === 0) return true; // inPt is on contour ?
  24900. if (perpEdge < 0) continue;
  24901. inside = !inside; // true intersection left of inPt
  24902. }
  24903. } else {
  24904. // parallel or collinear
  24905. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24906. // edge lies on the same horizontal line as inPt
  24907. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24908. // continue;
  24909. }
  24910. }
  24911. return inside;
  24912. }
  24913. var isClockWise = ShapeUtils.isClockWise;
  24914. var subPaths = this.subPaths;
  24915. if (subPaths.length === 0) return [];
  24916. if (noHoles === true) return toShapesNoHoles(subPaths);
  24917. var solid, tmpPath, tmpShape;
  24918. var shapes = [];
  24919. if (subPaths.length === 1) {
  24920. tmpPath = subPaths[0];
  24921. tmpShape = new Shape();
  24922. tmpShape.curves = tmpPath.curves;
  24923. shapes.push(tmpShape);
  24924. return shapes;
  24925. }
  24926. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24927. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24928. var betterShapeHoles = [];
  24929. var newShapes = [];
  24930. var newShapeHoles = [];
  24931. var mainIdx = 0;
  24932. var tmpPoints;
  24933. newShapes[mainIdx] = undefined;
  24934. newShapeHoles[mainIdx] = [];
  24935. for (var i = 0, l = subPaths.length; i < l; i++) {
  24936. tmpPath = subPaths[i];
  24937. tmpPoints = tmpPath.getPoints();
  24938. solid = isClockWise(tmpPoints);
  24939. solid = isCCW ? !solid : solid;
  24940. if (solid) {
  24941. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24942. newShapes[mainIdx] = {
  24943. s: new Shape(),
  24944. p: tmpPoints
  24945. };
  24946. newShapes[mainIdx].s.curves = tmpPath.curves;
  24947. if (holesFirst) mainIdx++;
  24948. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24949. } else {
  24950. newShapeHoles[mainIdx].push({
  24951. h: tmpPath,
  24952. p: tmpPoints[0]
  24953. }); //console.log('ccw', i);
  24954. }
  24955. } // only Holes? -> probably all Shapes with wrong orientation
  24956. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24957. if (newShapes.length > 1) {
  24958. var ambiguous = false;
  24959. var toChange = [];
  24960. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24961. betterShapeHoles[sIdx] = [];
  24962. }
  24963. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24964. var sho = newShapeHoles[_sIdx];
  24965. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24966. var ho = sho[hIdx];
  24967. var hole_unassigned = true;
  24968. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24969. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24970. if (_sIdx !== s2Idx) toChange.push({
  24971. froms: _sIdx,
  24972. tos: s2Idx,
  24973. hole: hIdx
  24974. });
  24975. if (hole_unassigned) {
  24976. hole_unassigned = false;
  24977. betterShapeHoles[s2Idx].push(ho);
  24978. } else {
  24979. ambiguous = true;
  24980. }
  24981. }
  24982. }
  24983. if (hole_unassigned) {
  24984. betterShapeHoles[_sIdx].push(ho);
  24985. }
  24986. }
  24987. } // console.log("ambiguous: ", ambiguous);
  24988. if (toChange.length > 0) {
  24989. // console.log("to change: ", toChange);
  24990. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24991. }
  24992. }
  24993. var tmpHoles;
  24994. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24995. tmpShape = newShapes[_i].s;
  24996. shapes.push(tmpShape);
  24997. tmpHoles = newShapeHoles[_i];
  24998. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24999. tmpShape.holes.push(tmpHoles[j].h);
  25000. }
  25001. } //console.log("shape", shapes);
  25002. return shapes;
  25003. }
  25004. });
  25005. function Font(data) {
  25006. this.type = 'Font';
  25007. this.data = data;
  25008. }
  25009. Object.assign(Font.prototype, {
  25010. isFont: true,
  25011. generateShapes: function generateShapes(text, size) {
  25012. if (size === void 0) {
  25013. size = 100;
  25014. }
  25015. var shapes = [];
  25016. var paths = createPaths(text, size, this.data);
  25017. for (var p = 0, pl = paths.length; p < pl; p++) {
  25018. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25019. }
  25020. return shapes;
  25021. }
  25022. });
  25023. function createPaths(text, size, data) {
  25024. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25025. var scale = size / data.resolution;
  25026. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25027. var paths = [];
  25028. var offsetX = 0,
  25029. offsetY = 0;
  25030. for (var i = 0; i < chars.length; i++) {
  25031. var char = chars[i];
  25032. if (char === '\n') {
  25033. offsetX = 0;
  25034. offsetY -= line_height;
  25035. } else {
  25036. var ret = createPath(char, scale, offsetX, offsetY, data);
  25037. offsetX += ret.offsetX;
  25038. paths.push(ret.path);
  25039. }
  25040. }
  25041. return paths;
  25042. }
  25043. function createPath(char, scale, offsetX, offsetY, data) {
  25044. var glyph = data.glyphs[char] || data.glyphs['?'];
  25045. if (!glyph) {
  25046. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25047. return;
  25048. }
  25049. var path = new ShapePath();
  25050. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25051. if (glyph.o) {
  25052. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25053. for (var i = 0, l = outline.length; i < l;) {
  25054. var action = outline[i++];
  25055. switch (action) {
  25056. case 'm':
  25057. // moveTo
  25058. x = outline[i++] * scale + offsetX;
  25059. y = outline[i++] * scale + offsetY;
  25060. path.moveTo(x, y);
  25061. break;
  25062. case 'l':
  25063. // lineTo
  25064. x = outline[i++] * scale + offsetX;
  25065. y = outline[i++] * scale + offsetY;
  25066. path.lineTo(x, y);
  25067. break;
  25068. case 'q':
  25069. // quadraticCurveTo
  25070. cpx = outline[i++] * scale + offsetX;
  25071. cpy = outline[i++] * scale + offsetY;
  25072. cpx1 = outline[i++] * scale + offsetX;
  25073. cpy1 = outline[i++] * scale + offsetY;
  25074. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25075. break;
  25076. case 'b':
  25077. // bezierCurveTo
  25078. cpx = outline[i++] * scale + offsetX;
  25079. cpy = outline[i++] * scale + offsetY;
  25080. cpx1 = outline[i++] * scale + offsetX;
  25081. cpy1 = outline[i++] * scale + offsetY;
  25082. cpx2 = outline[i++] * scale + offsetX;
  25083. cpy2 = outline[i++] * scale + offsetY;
  25084. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25085. break;
  25086. }
  25087. }
  25088. }
  25089. return {
  25090. offsetX: glyph.ha * scale,
  25091. path: path
  25092. };
  25093. }
  25094. function FontLoader(manager) {
  25095. Loader.call(this, manager);
  25096. }
  25097. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25098. constructor: FontLoader,
  25099. load: function load(url, onLoad, onProgress, onError) {
  25100. var scope = this;
  25101. var loader = new FileLoader(this.manager);
  25102. loader.setPath(this.path);
  25103. loader.setRequestHeader(this.requestHeader);
  25104. loader.setWithCredentials(scope.withCredentials);
  25105. loader.load(url, function (text) {
  25106. var json;
  25107. try {
  25108. json = JSON.parse(text);
  25109. } catch (e) {
  25110. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25111. json = JSON.parse(text.substring(65, text.length - 2));
  25112. }
  25113. var font = scope.parse(json);
  25114. if (onLoad) onLoad(font);
  25115. }, onProgress, onError);
  25116. },
  25117. parse: function parse(json) {
  25118. return new Font(json);
  25119. }
  25120. });
  25121. var _context;
  25122. var AudioContext = {
  25123. getContext: function getContext() {
  25124. if (_context === undefined) {
  25125. _context = new (window.AudioContext || window.webkitAudioContext)();
  25126. }
  25127. return _context;
  25128. },
  25129. setContext: function setContext(value) {
  25130. _context = value;
  25131. }
  25132. };
  25133. function AudioLoader(manager) {
  25134. Loader.call(this, manager);
  25135. }
  25136. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25137. constructor: AudioLoader,
  25138. load: function load(url, onLoad, onProgress, onError) {
  25139. var scope = this;
  25140. var loader = new FileLoader(scope.manager);
  25141. loader.setResponseType('arraybuffer');
  25142. loader.setPath(scope.path);
  25143. loader.setRequestHeader(scope.requestHeader);
  25144. loader.setWithCredentials(scope.withCredentials);
  25145. loader.load(url, function (buffer) {
  25146. try {
  25147. // Create a copy of the buffer. The `decodeAudioData` method
  25148. // detaches the buffer when complete, preventing reuse.
  25149. var bufferCopy = buffer.slice(0);
  25150. var context = AudioContext.getContext();
  25151. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25152. onLoad(audioBuffer);
  25153. });
  25154. } catch (e) {
  25155. if (onError) {
  25156. onError(e);
  25157. } else {
  25158. console.error(e);
  25159. }
  25160. scope.manager.itemError(url);
  25161. }
  25162. }, onProgress, onError);
  25163. }
  25164. });
  25165. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25166. LightProbe.call(this, undefined, intensity);
  25167. var color1 = new Color().set(skyColor);
  25168. var color2 = new Color().set(groundColor);
  25169. var sky = new Vector3(color1.r, color1.g, color1.b);
  25170. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25171. var c0 = Math.sqrt(Math.PI);
  25172. var c1 = c0 * Math.sqrt(0.75);
  25173. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25174. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25175. }
  25176. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25177. constructor: HemisphereLightProbe,
  25178. isHemisphereLightProbe: true,
  25179. copy: function copy(source) {
  25180. // modifying colors not currently supported
  25181. LightProbe.prototype.copy.call(this, source);
  25182. return this;
  25183. },
  25184. toJSON: function toJSON(meta) {
  25185. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25186. return data;
  25187. }
  25188. });
  25189. function AmbientLightProbe(color, intensity) {
  25190. LightProbe.call(this, undefined, intensity);
  25191. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25192. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25193. }
  25194. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25195. constructor: AmbientLightProbe,
  25196. isAmbientLightProbe: true,
  25197. copy: function copy(source) {
  25198. // modifying color not currently supported
  25199. LightProbe.prototype.copy.call(this, source);
  25200. return this;
  25201. },
  25202. toJSON: function toJSON(meta) {
  25203. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25204. return data;
  25205. }
  25206. });
  25207. var _eyeRight = new Matrix4();
  25208. var _eyeLeft = new Matrix4();
  25209. function StereoCamera() {
  25210. this.type = 'StereoCamera';
  25211. this.aspect = 1;
  25212. this.eyeSep = 0.064;
  25213. this.cameraL = new PerspectiveCamera();
  25214. this.cameraL.layers.enable(1);
  25215. this.cameraL.matrixAutoUpdate = false;
  25216. this.cameraR = new PerspectiveCamera();
  25217. this.cameraR.layers.enable(2);
  25218. this.cameraR.matrixAutoUpdate = false;
  25219. this._cache = {
  25220. focus: null,
  25221. fov: null,
  25222. aspect: null,
  25223. near: null,
  25224. far: null,
  25225. zoom: null,
  25226. eyeSep: null
  25227. };
  25228. }
  25229. Object.assign(StereoCamera.prototype, {
  25230. update: function update(camera) {
  25231. var cache = this._cache;
  25232. 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;
  25233. if (needsUpdate) {
  25234. cache.focus = camera.focus;
  25235. cache.fov = camera.fov;
  25236. cache.aspect = camera.aspect * this.aspect;
  25237. cache.near = camera.near;
  25238. cache.far = camera.far;
  25239. cache.zoom = camera.zoom;
  25240. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25241. // http://paulbourke.net/stereographics/stereorender/
  25242. var projectionMatrix = camera.projectionMatrix.clone();
  25243. var eyeSepHalf = cache.eyeSep / 2;
  25244. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25245. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25246. var xmin, xmax; // translate xOffset
  25247. _eyeLeft.elements[12] = -eyeSepHalf;
  25248. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25249. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25250. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25251. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25252. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25253. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25254. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25255. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25256. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25257. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25258. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25259. }
  25260. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25261. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25262. }
  25263. });
  25264. var Clock = /*#__PURE__*/function () {
  25265. function Clock(autoStart) {
  25266. this.autoStart = autoStart !== undefined ? autoStart : true;
  25267. this.startTime = 0;
  25268. this.oldTime = 0;
  25269. this.elapsedTime = 0;
  25270. this.running = false;
  25271. }
  25272. var _proto = Clock.prototype;
  25273. _proto.start = function start() {
  25274. this.startTime = (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25275. this.oldTime = this.startTime;
  25276. this.elapsedTime = 0;
  25277. this.running = true;
  25278. };
  25279. _proto.stop = function stop() {
  25280. this.getElapsedTime();
  25281. this.running = false;
  25282. this.autoStart = false;
  25283. };
  25284. _proto.getElapsedTime = function getElapsedTime() {
  25285. this.getDelta();
  25286. return this.elapsedTime;
  25287. };
  25288. _proto.getDelta = function getDelta() {
  25289. var diff = 0;
  25290. if (this.autoStart && !this.running) {
  25291. this.start();
  25292. return 0;
  25293. }
  25294. if (this.running) {
  25295. var newTime = (typeof performance === 'undefined' ? Date : performance).now();
  25296. diff = (newTime - this.oldTime) / 1000;
  25297. this.oldTime = newTime;
  25298. this.elapsedTime += diff;
  25299. }
  25300. return diff;
  25301. };
  25302. return Clock;
  25303. }();
  25304. var _position$2 = /*@__PURE__*/new Vector3();
  25305. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25306. var _scale$1 = /*@__PURE__*/new Vector3();
  25307. var _orientation = /*@__PURE__*/new Vector3();
  25308. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25309. _inheritsLoose(AudioListener, _Object3D);
  25310. function AudioListener() {
  25311. var _this;
  25312. _this = _Object3D.call(this) || this;
  25313. _this.type = 'AudioListener';
  25314. _this.context = AudioContext.getContext();
  25315. _this.gain = _this.context.createGain();
  25316. _this.gain.connect(_this.context.destination);
  25317. _this.filter = null;
  25318. _this.timeDelta = 0; // private
  25319. _this._clock = new Clock();
  25320. return _this;
  25321. }
  25322. var _proto = AudioListener.prototype;
  25323. _proto.getInput = function getInput() {
  25324. return this.gain;
  25325. };
  25326. _proto.removeFilter = function removeFilter() {
  25327. if (this.filter !== null) {
  25328. this.gain.disconnect(this.filter);
  25329. this.filter.disconnect(this.context.destination);
  25330. this.gain.connect(this.context.destination);
  25331. this.filter = null;
  25332. }
  25333. return this;
  25334. };
  25335. _proto.getFilter = function getFilter() {
  25336. return this.filter;
  25337. };
  25338. _proto.setFilter = function setFilter(value) {
  25339. if (this.filter !== null) {
  25340. this.gain.disconnect(this.filter);
  25341. this.filter.disconnect(this.context.destination);
  25342. } else {
  25343. this.gain.disconnect(this.context.destination);
  25344. }
  25345. this.filter = value;
  25346. this.gain.connect(this.filter);
  25347. this.filter.connect(this.context.destination);
  25348. return this;
  25349. };
  25350. _proto.getMasterVolume = function getMasterVolume() {
  25351. return this.gain.gain.value;
  25352. };
  25353. _proto.setMasterVolume = function setMasterVolume(value) {
  25354. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25355. return this;
  25356. };
  25357. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25358. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25359. var listener = this.context.listener;
  25360. var up = this.up;
  25361. this.timeDelta = this._clock.getDelta();
  25362. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25363. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25364. if (listener.positionX) {
  25365. // code path for Chrome (see #14393)
  25366. var endTime = this.context.currentTime + this.timeDelta;
  25367. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25368. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25369. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25370. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25371. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25372. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25373. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25374. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25375. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25376. } else {
  25377. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25378. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25379. }
  25380. };
  25381. return AudioListener;
  25382. }(Object3D);
  25383. var Audio = /*#__PURE__*/function (_Object3D) {
  25384. _inheritsLoose(Audio, _Object3D);
  25385. function Audio(listener) {
  25386. var _this;
  25387. _this = _Object3D.call(this) || this;
  25388. _this.type = 'Audio';
  25389. _this.listener = listener;
  25390. _this.context = listener.context;
  25391. _this.gain = _this.context.createGain();
  25392. _this.gain.connect(listener.getInput());
  25393. _this.autoplay = false;
  25394. _this.buffer = null;
  25395. _this.detune = 0;
  25396. _this.loop = false;
  25397. _this.loopStart = 0;
  25398. _this.loopEnd = 0;
  25399. _this.offset = 0;
  25400. _this.duration = undefined;
  25401. _this.playbackRate = 1;
  25402. _this.isPlaying = false;
  25403. _this.hasPlaybackControl = true;
  25404. _this.source = null;
  25405. _this.sourceType = 'empty';
  25406. _this._startedAt = 0;
  25407. _this._progress = 0;
  25408. _this._connected = false;
  25409. _this.filters = [];
  25410. return _this;
  25411. }
  25412. var _proto = Audio.prototype;
  25413. _proto.getOutput = function getOutput() {
  25414. return this.gain;
  25415. };
  25416. _proto.setNodeSource = function setNodeSource(audioNode) {
  25417. this.hasPlaybackControl = false;
  25418. this.sourceType = 'audioNode';
  25419. this.source = audioNode;
  25420. this.connect();
  25421. return this;
  25422. };
  25423. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25424. this.hasPlaybackControl = false;
  25425. this.sourceType = 'mediaNode';
  25426. this.source = this.context.createMediaElementSource(mediaElement);
  25427. this.connect();
  25428. return this;
  25429. };
  25430. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25431. this.hasPlaybackControl = false;
  25432. this.sourceType = 'mediaStreamNode';
  25433. this.source = this.context.createMediaStreamSource(mediaStream);
  25434. this.connect();
  25435. return this;
  25436. };
  25437. _proto.setBuffer = function setBuffer(audioBuffer) {
  25438. this.buffer = audioBuffer;
  25439. this.sourceType = 'buffer';
  25440. if (this.autoplay) this.play();
  25441. return this;
  25442. };
  25443. _proto.play = function play(delay) {
  25444. if (delay === void 0) {
  25445. delay = 0;
  25446. }
  25447. if (this.isPlaying === true) {
  25448. console.warn('THREE.Audio: Audio is already playing.');
  25449. return;
  25450. }
  25451. if (this.hasPlaybackControl === false) {
  25452. console.warn('THREE.Audio: this Audio has no playback control.');
  25453. return;
  25454. }
  25455. this._startedAt = this.context.currentTime + delay;
  25456. var source = this.context.createBufferSource();
  25457. source.buffer = this.buffer;
  25458. source.loop = this.loop;
  25459. source.loopStart = this.loopStart;
  25460. source.loopEnd = this.loopEnd;
  25461. source.onended = this.onEnded.bind(this);
  25462. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25463. this.isPlaying = true;
  25464. this.source = source;
  25465. this.setDetune(this.detune);
  25466. this.setPlaybackRate(this.playbackRate);
  25467. return this.connect();
  25468. };
  25469. _proto.pause = function pause() {
  25470. if (this.hasPlaybackControl === false) {
  25471. console.warn('THREE.Audio: this Audio has no playback control.');
  25472. return;
  25473. }
  25474. if (this.isPlaying === true) {
  25475. // update current progress
  25476. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25477. if (this.loop === true) {
  25478. // ensure _progress does not exceed duration with looped audios
  25479. this._progress = this._progress % (this.duration || this.buffer.duration);
  25480. }
  25481. this.source.stop();
  25482. this.source.onended = null;
  25483. this.isPlaying = false;
  25484. }
  25485. return this;
  25486. };
  25487. _proto.stop = function stop() {
  25488. if (this.hasPlaybackControl === false) {
  25489. console.warn('THREE.Audio: this Audio has no playback control.');
  25490. return;
  25491. }
  25492. this._progress = 0;
  25493. this.source.stop();
  25494. this.source.onended = null;
  25495. this.isPlaying = false;
  25496. return this;
  25497. };
  25498. _proto.connect = function connect() {
  25499. if (this.filters.length > 0) {
  25500. this.source.connect(this.filters[0]);
  25501. for (var i = 1, l = this.filters.length; i < l; i++) {
  25502. this.filters[i - 1].connect(this.filters[i]);
  25503. }
  25504. this.filters[this.filters.length - 1].connect(this.getOutput());
  25505. } else {
  25506. this.source.connect(this.getOutput());
  25507. }
  25508. this._connected = true;
  25509. return this;
  25510. };
  25511. _proto.disconnect = function disconnect() {
  25512. if (this.filters.length > 0) {
  25513. this.source.disconnect(this.filters[0]);
  25514. for (var i = 1, l = this.filters.length; i < l; i++) {
  25515. this.filters[i - 1].disconnect(this.filters[i]);
  25516. }
  25517. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25518. } else {
  25519. this.source.disconnect(this.getOutput());
  25520. }
  25521. this._connected = false;
  25522. return this;
  25523. };
  25524. _proto.getFilters = function getFilters() {
  25525. return this.filters;
  25526. };
  25527. _proto.setFilters = function setFilters(value) {
  25528. if (!value) value = [];
  25529. if (this._connected === true) {
  25530. this.disconnect();
  25531. this.filters = value.slice();
  25532. this.connect();
  25533. } else {
  25534. this.filters = value.slice();
  25535. }
  25536. return this;
  25537. };
  25538. _proto.setDetune = function setDetune(value) {
  25539. this.detune = value;
  25540. if (this.source.detune === undefined) return; // only set detune when available
  25541. if (this.isPlaying === true) {
  25542. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25543. }
  25544. return this;
  25545. };
  25546. _proto.getDetune = function getDetune() {
  25547. return this.detune;
  25548. };
  25549. _proto.getFilter = function getFilter() {
  25550. return this.getFilters()[0];
  25551. };
  25552. _proto.setFilter = function setFilter(filter) {
  25553. return this.setFilters(filter ? [filter] : []);
  25554. };
  25555. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25556. if (this.hasPlaybackControl === false) {
  25557. console.warn('THREE.Audio: this Audio has no playback control.');
  25558. return;
  25559. }
  25560. this.playbackRate = value;
  25561. if (this.isPlaying === true) {
  25562. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25563. }
  25564. return this;
  25565. };
  25566. _proto.getPlaybackRate = function getPlaybackRate() {
  25567. return this.playbackRate;
  25568. };
  25569. _proto.onEnded = function onEnded() {
  25570. this.isPlaying = false;
  25571. };
  25572. _proto.getLoop = function getLoop() {
  25573. if (this.hasPlaybackControl === false) {
  25574. console.warn('THREE.Audio: this Audio has no playback control.');
  25575. return false;
  25576. }
  25577. return this.loop;
  25578. };
  25579. _proto.setLoop = function setLoop(value) {
  25580. if (this.hasPlaybackControl === false) {
  25581. console.warn('THREE.Audio: this Audio has no playback control.');
  25582. return;
  25583. }
  25584. this.loop = value;
  25585. if (this.isPlaying === true) {
  25586. this.source.loop = this.loop;
  25587. }
  25588. return this;
  25589. };
  25590. _proto.setLoopStart = function setLoopStart(value) {
  25591. this.loopStart = value;
  25592. return this;
  25593. };
  25594. _proto.setLoopEnd = function setLoopEnd(value) {
  25595. this.loopEnd = value;
  25596. return this;
  25597. };
  25598. _proto.getVolume = function getVolume() {
  25599. return this.gain.gain.value;
  25600. };
  25601. _proto.setVolume = function setVolume(value) {
  25602. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25603. return this;
  25604. };
  25605. return Audio;
  25606. }(Object3D);
  25607. var _position$3 = /*@__PURE__*/new Vector3();
  25608. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25609. var _scale$2 = /*@__PURE__*/new Vector3();
  25610. var _orientation$1 = /*@__PURE__*/new Vector3();
  25611. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25612. _inheritsLoose(PositionalAudio, _Audio);
  25613. function PositionalAudio(listener) {
  25614. var _this;
  25615. _this = _Audio.call(this, listener) || this;
  25616. _this.panner = _this.context.createPanner();
  25617. _this.panner.panningModel = 'HRTF';
  25618. _this.panner.connect(_this.gain);
  25619. return _this;
  25620. }
  25621. var _proto = PositionalAudio.prototype;
  25622. _proto.getOutput = function getOutput() {
  25623. return this.panner;
  25624. };
  25625. _proto.getRefDistance = function getRefDistance() {
  25626. return this.panner.refDistance;
  25627. };
  25628. _proto.setRefDistance = function setRefDistance(value) {
  25629. this.panner.refDistance = value;
  25630. return this;
  25631. };
  25632. _proto.getRolloffFactor = function getRolloffFactor() {
  25633. return this.panner.rolloffFactor;
  25634. };
  25635. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25636. this.panner.rolloffFactor = value;
  25637. return this;
  25638. };
  25639. _proto.getDistanceModel = function getDistanceModel() {
  25640. return this.panner.distanceModel;
  25641. };
  25642. _proto.setDistanceModel = function setDistanceModel(value) {
  25643. this.panner.distanceModel = value;
  25644. return this;
  25645. };
  25646. _proto.getMaxDistance = function getMaxDistance() {
  25647. return this.panner.maxDistance;
  25648. };
  25649. _proto.setMaxDistance = function setMaxDistance(value) {
  25650. this.panner.maxDistance = value;
  25651. return this;
  25652. };
  25653. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25654. this.panner.coneInnerAngle = coneInnerAngle;
  25655. this.panner.coneOuterAngle = coneOuterAngle;
  25656. this.panner.coneOuterGain = coneOuterGain;
  25657. return this;
  25658. };
  25659. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25660. _Audio.prototype.updateMatrixWorld.call(this, force);
  25661. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25662. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25663. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25664. var panner = this.panner;
  25665. if (panner.positionX) {
  25666. // code path for Chrome and Firefox (see #14393)
  25667. var endTime = this.context.currentTime + this.listener.timeDelta;
  25668. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25669. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25670. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25671. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25672. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25673. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25674. } else {
  25675. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25676. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25677. }
  25678. };
  25679. return PositionalAudio;
  25680. }(Audio);
  25681. var AudioAnalyser = /*#__PURE__*/function () {
  25682. function AudioAnalyser(audio, fftSize) {
  25683. this.analyser = audio.context.createAnalyser();
  25684. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25685. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25686. audio.getOutput().connect(this.analyser);
  25687. }
  25688. var _proto = AudioAnalyser.prototype;
  25689. _proto.getFrequencyData = function getFrequencyData() {
  25690. this.analyser.getByteFrequencyData(this.data);
  25691. return this.data;
  25692. };
  25693. _proto.getAverageFrequency = function getAverageFrequency() {
  25694. var value = 0;
  25695. var data = this.getFrequencyData();
  25696. for (var i = 0; i < data.length; i++) {
  25697. value += data[i];
  25698. }
  25699. return value / data.length;
  25700. };
  25701. return AudioAnalyser;
  25702. }();
  25703. function PropertyMixer(binding, typeName, valueSize) {
  25704. this.binding = binding;
  25705. this.valueSize = valueSize;
  25706. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25707. //
  25708. // interpolators can use .buffer as their .result
  25709. // the data then goes to 'incoming'
  25710. //
  25711. // 'accu0' and 'accu1' are used frame-interleaved for
  25712. // the cumulative result and are compared to detect
  25713. // changes
  25714. //
  25715. // 'orig' stores the original state of the property
  25716. //
  25717. // 'add' is used for additive cumulative results
  25718. //
  25719. // 'work' is optional and is only present for quaternion types. It is used
  25720. // to store intermediate quaternion multiplication results
  25721. switch (typeName) {
  25722. case 'quaternion':
  25723. mixFunction = this._slerp;
  25724. mixFunctionAdditive = this._slerpAdditive;
  25725. setIdentity = this._setAdditiveIdentityQuaternion;
  25726. this.buffer = new Float64Array(valueSize * 6);
  25727. this._workIndex = 5;
  25728. break;
  25729. case 'string':
  25730. case 'bool':
  25731. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25732. // additive is not relevant for non-numeric types
  25733. mixFunctionAdditive = this._select;
  25734. setIdentity = this._setAdditiveIdentityOther;
  25735. this.buffer = new Array(valueSize * 5);
  25736. break;
  25737. default:
  25738. mixFunction = this._lerp;
  25739. mixFunctionAdditive = this._lerpAdditive;
  25740. setIdentity = this._setAdditiveIdentityNumeric;
  25741. this.buffer = new Float64Array(valueSize * 5);
  25742. }
  25743. this._mixBufferRegion = mixFunction;
  25744. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25745. this._setIdentity = setIdentity;
  25746. this._origIndex = 3;
  25747. this._addIndex = 4;
  25748. this.cumulativeWeight = 0;
  25749. this.cumulativeWeightAdditive = 0;
  25750. this.useCount = 0;
  25751. this.referenceCount = 0;
  25752. }
  25753. Object.assign(PropertyMixer.prototype, {
  25754. // accumulate data in the 'incoming' region into 'accu<i>'
  25755. accumulate: function accumulate(accuIndex, weight) {
  25756. // note: happily accumulating nothing when weight = 0, the caller knows
  25757. // the weight and shouldn't have made the call in the first place
  25758. var buffer = this.buffer,
  25759. stride = this.valueSize,
  25760. offset = accuIndex * stride + stride;
  25761. var currentWeight = this.cumulativeWeight;
  25762. if (currentWeight === 0) {
  25763. // accuN := incoming * weight
  25764. for (var i = 0; i !== stride; ++i) {
  25765. buffer[offset + i] = buffer[i];
  25766. }
  25767. currentWeight = weight;
  25768. } else {
  25769. // accuN := accuN + incoming * weight
  25770. currentWeight += weight;
  25771. var mix = weight / currentWeight;
  25772. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25773. }
  25774. this.cumulativeWeight = currentWeight;
  25775. },
  25776. // accumulate data in the 'incoming' region into 'add'
  25777. accumulateAdditive: function accumulateAdditive(weight) {
  25778. var buffer = this.buffer,
  25779. stride = this.valueSize,
  25780. offset = stride * this._addIndex;
  25781. if (this.cumulativeWeightAdditive === 0) {
  25782. // add = identity
  25783. this._setIdentity();
  25784. } // add := add + incoming * weight
  25785. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25786. this.cumulativeWeightAdditive += weight;
  25787. },
  25788. // apply the state of 'accu<i>' to the binding when accus differ
  25789. apply: function apply(accuIndex) {
  25790. var stride = this.valueSize,
  25791. buffer = this.buffer,
  25792. offset = accuIndex * stride + stride,
  25793. weight = this.cumulativeWeight,
  25794. weightAdditive = this.cumulativeWeightAdditive,
  25795. binding = this.binding;
  25796. this.cumulativeWeight = 0;
  25797. this.cumulativeWeightAdditive = 0;
  25798. if (weight < 1) {
  25799. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25800. var originalValueOffset = stride * this._origIndex;
  25801. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25802. }
  25803. if (weightAdditive > 0) {
  25804. // accuN := accuN + additive accuN
  25805. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25806. }
  25807. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25808. if (buffer[i] !== buffer[i + stride]) {
  25809. // value has changed -> update scene graph
  25810. binding.setValue(buffer, offset);
  25811. break;
  25812. }
  25813. }
  25814. },
  25815. // remember the state of the bound property and copy it to both accus
  25816. saveOriginalState: function saveOriginalState() {
  25817. var binding = this.binding;
  25818. var buffer = this.buffer,
  25819. stride = this.valueSize,
  25820. originalValueOffset = stride * this._origIndex;
  25821. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25822. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25823. buffer[i] = buffer[originalValueOffset + i % stride];
  25824. } // Add to identity for additive
  25825. this._setIdentity();
  25826. this.cumulativeWeight = 0;
  25827. this.cumulativeWeightAdditive = 0;
  25828. },
  25829. // apply the state previously taken via 'saveOriginalState' to the binding
  25830. restoreOriginalState: function restoreOriginalState() {
  25831. var originalValueOffset = this.valueSize * 3;
  25832. this.binding.setValue(this.buffer, originalValueOffset);
  25833. },
  25834. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25835. var startIndex = this._addIndex * this.valueSize;
  25836. var endIndex = startIndex + this.valueSize;
  25837. for (var i = startIndex; i < endIndex; i++) {
  25838. this.buffer[i] = 0;
  25839. }
  25840. },
  25841. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25842. this._setAdditiveIdentityNumeric();
  25843. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25844. },
  25845. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25846. var startIndex = this._origIndex * this.valueSize;
  25847. var targetIndex = this._addIndex * this.valueSize;
  25848. for (var i = 0; i < this.valueSize; i++) {
  25849. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25850. }
  25851. },
  25852. // mix functions
  25853. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25854. if (t >= 0.5) {
  25855. for (var i = 0; i !== stride; ++i) {
  25856. buffer[dstOffset + i] = buffer[srcOffset + i];
  25857. }
  25858. }
  25859. },
  25860. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25861. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25862. },
  25863. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25864. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25865. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25866. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25867. },
  25868. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25869. var s = 1 - t;
  25870. for (var i = 0; i !== stride; ++i) {
  25871. var j = dstOffset + i;
  25872. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25873. }
  25874. },
  25875. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25876. for (var i = 0; i !== stride; ++i) {
  25877. var j = dstOffset + i;
  25878. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25879. }
  25880. }
  25881. });
  25882. // Characters [].:/ are reserved for track binding syntax.
  25883. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25884. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25885. // only latin characters, and the unicode \p{L} is not yet supported. So
  25886. // instead, we exclude reserved characters and match everything else.
  25887. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25888. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25889. // be matched to parse the rest of the track name.
  25890. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25891. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25892. // characters. Accessor may contain any character except closing bracket.
  25893. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25894. // contain any non-bracket characters.
  25895. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25896. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25897. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25898. function Composite(targetGroup, path, optionalParsedPath) {
  25899. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25900. this._targetGroup = targetGroup;
  25901. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25902. }
  25903. Object.assign(Composite.prototype, {
  25904. getValue: function getValue(array, offset) {
  25905. this.bind(); // bind all binding
  25906. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25907. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25908. if (binding !== undefined) binding.getValue(array, offset);
  25909. },
  25910. setValue: function setValue(array, offset) {
  25911. var bindings = this._bindings;
  25912. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25913. bindings[i].setValue(array, offset);
  25914. }
  25915. },
  25916. bind: function bind() {
  25917. var bindings = this._bindings;
  25918. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25919. bindings[i].bind();
  25920. }
  25921. },
  25922. unbind: function unbind() {
  25923. var bindings = this._bindings;
  25924. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25925. bindings[i].unbind();
  25926. }
  25927. }
  25928. });
  25929. function PropertyBinding(rootNode, path, parsedPath) {
  25930. this.path = path;
  25931. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25932. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25933. this.rootNode = rootNode;
  25934. }
  25935. Object.assign(PropertyBinding, {
  25936. Composite: Composite,
  25937. create: function create(root, path, parsedPath) {
  25938. if (!(root && root.isAnimationObjectGroup)) {
  25939. return new PropertyBinding(root, path, parsedPath);
  25940. } else {
  25941. return new PropertyBinding.Composite(root, path, parsedPath);
  25942. }
  25943. },
  25944. /**
  25945. * Replaces spaces with underscores and removes unsupported characters from
  25946. * node names, to ensure compatibility with parseTrackName().
  25947. *
  25948. * @param {string} name Node name to be sanitized.
  25949. * @return {string}
  25950. */
  25951. sanitizeNodeName: function sanitizeNodeName(name) {
  25952. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25953. },
  25954. parseTrackName: function parseTrackName(trackName) {
  25955. var matches = _trackRe.exec(trackName);
  25956. if (!matches) {
  25957. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25958. }
  25959. var results = {
  25960. // directoryName: matches[ 1 ], // (tschw) currently unused
  25961. nodeName: matches[2],
  25962. objectName: matches[3],
  25963. objectIndex: matches[4],
  25964. propertyName: matches[5],
  25965. // required
  25966. propertyIndex: matches[6]
  25967. };
  25968. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25969. if (lastDot !== undefined && lastDot !== -1) {
  25970. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25971. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25972. // 'bar' could be the objectName, or part of a nodeName (which can
  25973. // include '.' characters).
  25974. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25975. results.nodeName = results.nodeName.substring(0, lastDot);
  25976. results.objectName = objectName;
  25977. }
  25978. }
  25979. if (results.propertyName === null || results.propertyName.length === 0) {
  25980. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25981. }
  25982. return results;
  25983. },
  25984. findNode: function findNode(root, nodeName) {
  25985. if (!nodeName || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25986. return root;
  25987. } // search into skeleton bones.
  25988. if (root.skeleton) {
  25989. var bone = root.skeleton.getBoneByName(nodeName);
  25990. if (bone !== undefined) {
  25991. return bone;
  25992. }
  25993. } // search into node subtree.
  25994. if (root.children) {
  25995. var searchNodeSubtree = function searchNodeSubtree(children) {
  25996. for (var i = 0; i < children.length; i++) {
  25997. var childNode = children[i];
  25998. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25999. return childNode;
  26000. }
  26001. var result = searchNodeSubtree(childNode.children);
  26002. if (result) return result;
  26003. }
  26004. return null;
  26005. };
  26006. var subTreeNode = searchNodeSubtree(root.children);
  26007. if (subTreeNode) {
  26008. return subTreeNode;
  26009. }
  26010. }
  26011. return null;
  26012. }
  26013. });
  26014. Object.assign(PropertyBinding.prototype, {
  26015. // prototype, continued
  26016. // these are used to "bind" a nonexistent property
  26017. _getValue_unavailable: function _getValue_unavailable() {},
  26018. _setValue_unavailable: function _setValue_unavailable() {},
  26019. BindingType: {
  26020. Direct: 0,
  26021. EntireArray: 1,
  26022. ArrayElement: 2,
  26023. HasFromToArray: 3
  26024. },
  26025. Versioning: {
  26026. None: 0,
  26027. NeedsUpdate: 1,
  26028. MatrixWorldNeedsUpdate: 2
  26029. },
  26030. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26031. buffer[offset] = this.node[this.propertyName];
  26032. }, function getValue_array(buffer, offset) {
  26033. var source = this.resolvedProperty;
  26034. for (var i = 0, n = source.length; i !== n; ++i) {
  26035. buffer[offset++] = source[i];
  26036. }
  26037. }, function getValue_arrayElement(buffer, offset) {
  26038. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26039. }, function getValue_toArray(buffer, offset) {
  26040. this.resolvedProperty.toArray(buffer, offset);
  26041. }],
  26042. SetterByBindingTypeAndVersioning: [[// Direct
  26043. function setValue_direct(buffer, offset) {
  26044. this.targetObject[this.propertyName] = buffer[offset];
  26045. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26046. this.targetObject[this.propertyName] = buffer[offset];
  26047. this.targetObject.needsUpdate = true;
  26048. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26049. this.targetObject[this.propertyName] = buffer[offset];
  26050. this.targetObject.matrixWorldNeedsUpdate = true;
  26051. }], [// EntireArray
  26052. function setValue_array(buffer, offset) {
  26053. var dest = this.resolvedProperty;
  26054. for (var i = 0, n = dest.length; i !== n; ++i) {
  26055. dest[i] = buffer[offset++];
  26056. }
  26057. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26058. var dest = this.resolvedProperty;
  26059. for (var i = 0, n = dest.length; i !== n; ++i) {
  26060. dest[i] = buffer[offset++];
  26061. }
  26062. this.targetObject.needsUpdate = true;
  26063. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26064. var dest = this.resolvedProperty;
  26065. for (var i = 0, n = dest.length; i !== n; ++i) {
  26066. dest[i] = buffer[offset++];
  26067. }
  26068. this.targetObject.matrixWorldNeedsUpdate = true;
  26069. }], [// ArrayElement
  26070. function setValue_arrayElement(buffer, offset) {
  26071. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26072. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26073. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26074. this.targetObject.needsUpdate = true;
  26075. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26076. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26077. this.targetObject.matrixWorldNeedsUpdate = true;
  26078. }], [// HasToFromArray
  26079. function setValue_fromArray(buffer, offset) {
  26080. this.resolvedProperty.fromArray(buffer, offset);
  26081. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26082. this.resolvedProperty.fromArray(buffer, offset);
  26083. this.targetObject.needsUpdate = true;
  26084. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26085. this.resolvedProperty.fromArray(buffer, offset);
  26086. this.targetObject.matrixWorldNeedsUpdate = true;
  26087. }]],
  26088. getValue: function getValue_unbound(targetArray, offset) {
  26089. this.bind();
  26090. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26091. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26092. // prototype version of these methods with one that represents
  26093. // the bound state. When the property is not found, the methods
  26094. // become no-ops.
  26095. },
  26096. setValue: function getValue_unbound(sourceArray, offset) {
  26097. this.bind();
  26098. this.setValue(sourceArray, offset);
  26099. },
  26100. // create getter / setter pair for a property in the scene graph
  26101. bind: function bind() {
  26102. var targetObject = this.node;
  26103. var parsedPath = this.parsedPath;
  26104. var objectName = parsedPath.objectName;
  26105. var propertyName = parsedPath.propertyName;
  26106. var propertyIndex = parsedPath.propertyIndex;
  26107. if (!targetObject) {
  26108. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26109. this.node = targetObject;
  26110. } // set fail state so we can just 'return' on error
  26111. this.getValue = this._getValue_unavailable;
  26112. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26113. if (!targetObject) {
  26114. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26115. return;
  26116. }
  26117. if (objectName) {
  26118. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26119. switch (objectName) {
  26120. case 'materials':
  26121. if (!targetObject.material) {
  26122. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26123. return;
  26124. }
  26125. if (!targetObject.material.materials) {
  26126. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26127. return;
  26128. }
  26129. targetObject = targetObject.material.materials;
  26130. break;
  26131. case 'bones':
  26132. if (!targetObject.skeleton) {
  26133. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26134. return;
  26135. } // potential future optimization: skip this if propertyIndex is already an integer
  26136. // and convert the integer string to a true integer.
  26137. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26138. for (var i = 0; i < targetObject.length; i++) {
  26139. if (targetObject[i].name === objectIndex) {
  26140. objectIndex = i;
  26141. break;
  26142. }
  26143. }
  26144. break;
  26145. default:
  26146. if (targetObject[objectName] === undefined) {
  26147. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26148. return;
  26149. }
  26150. targetObject = targetObject[objectName];
  26151. }
  26152. if (objectIndex !== undefined) {
  26153. if (targetObject[objectIndex] === undefined) {
  26154. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26155. return;
  26156. }
  26157. targetObject = targetObject[objectIndex];
  26158. }
  26159. } // resolve property
  26160. var nodeProperty = targetObject[propertyName];
  26161. if (nodeProperty === undefined) {
  26162. var nodeName = parsedPath.nodeName;
  26163. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26164. return;
  26165. } // determine versioning scheme
  26166. var versioning = this.Versioning.None;
  26167. this.targetObject = targetObject;
  26168. if (targetObject.needsUpdate !== undefined) {
  26169. // material
  26170. versioning = this.Versioning.NeedsUpdate;
  26171. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26172. // node transform
  26173. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26174. } // determine how the property gets bound
  26175. var bindingType = this.BindingType.Direct;
  26176. if (propertyIndex !== undefined) {
  26177. // access a sub element of the property array (only primitives are supported right now)
  26178. if (propertyName === "morphTargetInfluences") {
  26179. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26180. // support resolving morphTarget names into indices.
  26181. if (!targetObject.geometry) {
  26182. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26183. return;
  26184. }
  26185. if (targetObject.geometry.isBufferGeometry) {
  26186. if (!targetObject.geometry.morphAttributes) {
  26187. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26188. return;
  26189. }
  26190. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26191. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26192. }
  26193. } else {
  26194. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26195. return;
  26196. }
  26197. }
  26198. bindingType = this.BindingType.ArrayElement;
  26199. this.resolvedProperty = nodeProperty;
  26200. this.propertyIndex = propertyIndex;
  26201. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26202. // must use copy for Object3D.Euler/Quaternion
  26203. bindingType = this.BindingType.HasFromToArray;
  26204. this.resolvedProperty = nodeProperty;
  26205. } else if (Array.isArray(nodeProperty)) {
  26206. bindingType = this.BindingType.EntireArray;
  26207. this.resolvedProperty = nodeProperty;
  26208. } else {
  26209. this.propertyName = propertyName;
  26210. } // select getter / setter
  26211. this.getValue = this.GetterByBindingType[bindingType];
  26212. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26213. },
  26214. unbind: function unbind() {
  26215. this.node = null; // back to the prototype version of getValue / setValue
  26216. // note: avoiding to mutate the shape of 'this' via 'delete'
  26217. this.getValue = this._getValue_unbound;
  26218. this.setValue = this._setValue_unbound;
  26219. }
  26220. }); // DECLARE ALIAS AFTER assign prototype
  26221. Object.assign(PropertyBinding.prototype, {
  26222. // initial state of these methods that calls 'bind'
  26223. _getValue_unbound: PropertyBinding.prototype.getValue,
  26224. _setValue_unbound: PropertyBinding.prototype.setValue
  26225. });
  26226. /**
  26227. *
  26228. * A group of objects that receives a shared animation state.
  26229. *
  26230. * Usage:
  26231. *
  26232. * - Add objects you would otherwise pass as 'root' to the
  26233. * constructor or the .clipAction method of AnimationMixer.
  26234. *
  26235. * - Instead pass this object as 'root'.
  26236. *
  26237. * - You can also add and remove objects later when the mixer
  26238. * is running.
  26239. *
  26240. * Note:
  26241. *
  26242. * Objects of this class appear as one object to the mixer,
  26243. * so cache control of the individual objects must be done
  26244. * on the group.
  26245. *
  26246. * Limitation:
  26247. *
  26248. * - The animated properties must be compatible among the
  26249. * all objects in the group.
  26250. *
  26251. * - A single property can either be controlled through a
  26252. * target group or directly, but not both.
  26253. */
  26254. function AnimationObjectGroup() {
  26255. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26256. this._objects = Array.prototype.slice.call(arguments);
  26257. this.nCachedObjects_ = 0; // threshold
  26258. // note: read by PropertyBinding.Composite
  26259. var indices = {};
  26260. this._indicesByUUID = indices; // for bookkeeping
  26261. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26262. indices[arguments[i].uuid] = i;
  26263. }
  26264. this._paths = []; // inside: string
  26265. this._parsedPaths = []; // inside: { we don't care, here }
  26266. this._bindings = []; // inside: Array< PropertyBinding >
  26267. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26268. var scope = this;
  26269. this.stats = {
  26270. objects: {
  26271. get total() {
  26272. return scope._objects.length;
  26273. },
  26274. get inUse() {
  26275. return this.total - scope.nCachedObjects_;
  26276. }
  26277. },
  26278. get bindingsPerObject() {
  26279. return scope._bindings.length;
  26280. }
  26281. };
  26282. }
  26283. Object.assign(AnimationObjectGroup.prototype, {
  26284. isAnimationObjectGroup: true,
  26285. add: function add() {
  26286. var objects = this._objects,
  26287. indicesByUUID = this._indicesByUUID,
  26288. paths = this._paths,
  26289. parsedPaths = this._parsedPaths,
  26290. bindings = this._bindings,
  26291. nBindings = bindings.length;
  26292. var knownObject = undefined,
  26293. nObjects = objects.length,
  26294. nCachedObjects = this.nCachedObjects_;
  26295. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26296. var object = arguments[i],
  26297. uuid = object.uuid;
  26298. var index = indicesByUUID[uuid];
  26299. if (index === undefined) {
  26300. // unknown object -> add it to the ACTIVE region
  26301. index = nObjects++;
  26302. indicesByUUID[uuid] = index;
  26303. objects.push(object); // accounting is done, now do the same for all bindings
  26304. for (var j = 0, m = nBindings; j !== m; ++j) {
  26305. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26306. }
  26307. } else if (index < nCachedObjects) {
  26308. knownObject = objects[index]; // move existing object to the ACTIVE region
  26309. var firstActiveIndex = --nCachedObjects,
  26310. lastCachedObject = objects[firstActiveIndex];
  26311. indicesByUUID[lastCachedObject.uuid] = index;
  26312. objects[index] = lastCachedObject;
  26313. indicesByUUID[uuid] = firstActiveIndex;
  26314. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26315. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26316. var bindingsForPath = bindings[_j],
  26317. lastCached = bindingsForPath[firstActiveIndex];
  26318. var binding = bindingsForPath[index];
  26319. bindingsForPath[index] = lastCached;
  26320. if (binding === undefined) {
  26321. // since we do not bother to create new bindings
  26322. // for objects that are cached, the binding may
  26323. // or may not exist
  26324. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26325. }
  26326. bindingsForPath[firstActiveIndex] = binding;
  26327. }
  26328. } else if (objects[index] !== knownObject) {
  26329. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26330. } // else the object is already where we want it to be
  26331. } // for arguments
  26332. this.nCachedObjects_ = nCachedObjects;
  26333. },
  26334. remove: function remove() {
  26335. var objects = this._objects,
  26336. indicesByUUID = this._indicesByUUID,
  26337. bindings = this._bindings,
  26338. nBindings = bindings.length;
  26339. var nCachedObjects = this.nCachedObjects_;
  26340. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26341. var object = arguments[i],
  26342. uuid = object.uuid,
  26343. index = indicesByUUID[uuid];
  26344. if (index !== undefined && index >= nCachedObjects) {
  26345. // move existing object into the CACHED region
  26346. var lastCachedIndex = nCachedObjects++,
  26347. firstActiveObject = objects[lastCachedIndex];
  26348. indicesByUUID[firstActiveObject.uuid] = index;
  26349. objects[index] = firstActiveObject;
  26350. indicesByUUID[uuid] = lastCachedIndex;
  26351. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26352. for (var j = 0, m = nBindings; j !== m; ++j) {
  26353. var bindingsForPath = bindings[j],
  26354. firstActive = bindingsForPath[lastCachedIndex],
  26355. binding = bindingsForPath[index];
  26356. bindingsForPath[index] = firstActive;
  26357. bindingsForPath[lastCachedIndex] = binding;
  26358. }
  26359. }
  26360. } // for arguments
  26361. this.nCachedObjects_ = nCachedObjects;
  26362. },
  26363. // remove & forget
  26364. uncache: function uncache() {
  26365. var objects = this._objects,
  26366. indicesByUUID = this._indicesByUUID,
  26367. bindings = this._bindings,
  26368. nBindings = bindings.length;
  26369. var nCachedObjects = this.nCachedObjects_,
  26370. nObjects = objects.length;
  26371. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26372. var object = arguments[i],
  26373. uuid = object.uuid,
  26374. index = indicesByUUID[uuid];
  26375. if (index !== undefined) {
  26376. delete indicesByUUID[uuid];
  26377. if (index < nCachedObjects) {
  26378. // object is cached, shrink the CACHED region
  26379. var firstActiveIndex = --nCachedObjects,
  26380. lastCachedObject = objects[firstActiveIndex],
  26381. lastIndex = --nObjects,
  26382. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26383. indicesByUUID[lastCachedObject.uuid] = index;
  26384. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26385. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26386. objects[firstActiveIndex] = lastObject;
  26387. objects.pop(); // accounting is done, now do the same for all bindings
  26388. for (var j = 0, m = nBindings; j !== m; ++j) {
  26389. var bindingsForPath = bindings[j],
  26390. lastCached = bindingsForPath[firstActiveIndex],
  26391. last = bindingsForPath[lastIndex];
  26392. bindingsForPath[index] = lastCached;
  26393. bindingsForPath[firstActiveIndex] = last;
  26394. bindingsForPath.pop();
  26395. }
  26396. } else {
  26397. // object is active, just swap with the last and pop
  26398. var _lastIndex = --nObjects,
  26399. _lastObject = objects[_lastIndex];
  26400. if (_lastIndex > 0) {
  26401. indicesByUUID[_lastObject.uuid] = index;
  26402. }
  26403. objects[index] = _lastObject;
  26404. objects.pop(); // accounting is done, now do the same for all bindings
  26405. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26406. var _bindingsForPath = bindings[_j2];
  26407. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26408. _bindingsForPath.pop();
  26409. }
  26410. } // cached or active
  26411. } // if object is known
  26412. } // for arguments
  26413. this.nCachedObjects_ = nCachedObjects;
  26414. },
  26415. // Internal interface used by befriended PropertyBinding.Composite:
  26416. subscribe_: function subscribe_(path, parsedPath) {
  26417. // returns an array of bindings for the given path that is changed
  26418. // according to the contained objects in the group
  26419. var indicesByPath = this._bindingsIndicesByPath;
  26420. var index = indicesByPath[path];
  26421. var bindings = this._bindings;
  26422. if (index !== undefined) return bindings[index];
  26423. var paths = this._paths,
  26424. parsedPaths = this._parsedPaths,
  26425. objects = this._objects,
  26426. nObjects = objects.length,
  26427. nCachedObjects = this.nCachedObjects_,
  26428. bindingsForPath = new Array(nObjects);
  26429. index = bindings.length;
  26430. indicesByPath[path] = index;
  26431. paths.push(path);
  26432. parsedPaths.push(parsedPath);
  26433. bindings.push(bindingsForPath);
  26434. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26435. var object = objects[i];
  26436. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26437. }
  26438. return bindingsForPath;
  26439. },
  26440. unsubscribe_: function unsubscribe_(path) {
  26441. // tells the group to forget about a property path and no longer
  26442. // update the array previously obtained with 'subscribe_'
  26443. var indicesByPath = this._bindingsIndicesByPath,
  26444. index = indicesByPath[path];
  26445. if (index !== undefined) {
  26446. var paths = this._paths,
  26447. parsedPaths = this._parsedPaths,
  26448. bindings = this._bindings,
  26449. lastBindingsIndex = bindings.length - 1,
  26450. lastBindings = bindings[lastBindingsIndex],
  26451. lastBindingsPath = path[lastBindingsIndex];
  26452. indicesByPath[lastBindingsPath] = index;
  26453. bindings[index] = lastBindings;
  26454. bindings.pop();
  26455. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26456. parsedPaths.pop();
  26457. paths[index] = paths[lastBindingsIndex];
  26458. paths.pop();
  26459. }
  26460. }
  26461. });
  26462. var AnimationAction = /*#__PURE__*/function () {
  26463. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26464. this._mixer = mixer;
  26465. this._clip = clip;
  26466. this._localRoot = localRoot || null;
  26467. this.blendMode = blendMode || clip.blendMode;
  26468. var tracks = clip.tracks,
  26469. nTracks = tracks.length,
  26470. interpolants = new Array(nTracks);
  26471. var interpolantSettings = {
  26472. endingStart: ZeroCurvatureEnding,
  26473. endingEnd: ZeroCurvatureEnding
  26474. };
  26475. for (var i = 0; i !== nTracks; ++i) {
  26476. var interpolant = tracks[i].createInterpolant(null);
  26477. interpolants[i] = interpolant;
  26478. interpolant.settings = interpolantSettings;
  26479. }
  26480. this._interpolantSettings = interpolantSettings;
  26481. this._interpolants = interpolants; // bound by the mixer
  26482. // inside: PropertyMixer (managed by the mixer)
  26483. this._propertyBindings = new Array(nTracks);
  26484. this._cacheIndex = null; // for the memory manager
  26485. this._byClipCacheIndex = null; // for the memory manager
  26486. this._timeScaleInterpolant = null;
  26487. this._weightInterpolant = null;
  26488. this.loop = LoopRepeat;
  26489. this._loopCount = -1; // global mixer time when the action is to be started
  26490. // it's set back to 'null' upon start of the action
  26491. this._startTime = null; // scaled local time of the action
  26492. // gets clamped or wrapped to 0..clip.duration according to loop
  26493. this.time = 0;
  26494. this.timeScale = 1;
  26495. this._effectiveTimeScale = 1;
  26496. this.weight = 1;
  26497. this._effectiveWeight = 1;
  26498. this.repetitions = Infinity; // no. of repetitions when looping
  26499. this.paused = false; // true -> zero effective time scale
  26500. this.enabled = true; // false -> zero effective weight
  26501. this.clampWhenFinished = false; // keep feeding the last frame?
  26502. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26503. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26504. } // State & Scheduling
  26505. var _proto = AnimationAction.prototype;
  26506. _proto.play = function play() {
  26507. this._mixer._activateAction(this);
  26508. return this;
  26509. };
  26510. _proto.stop = function stop() {
  26511. this._mixer._deactivateAction(this);
  26512. return this.reset();
  26513. };
  26514. _proto.reset = function reset() {
  26515. this.paused = false;
  26516. this.enabled = true;
  26517. this.time = 0; // restart clip
  26518. this._loopCount = -1; // forget previous loops
  26519. this._startTime = null; // forget scheduling
  26520. return this.stopFading().stopWarping();
  26521. };
  26522. _proto.isRunning = function isRunning() {
  26523. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26524. } // return true when play has been called
  26525. ;
  26526. _proto.isScheduled = function isScheduled() {
  26527. return this._mixer._isActiveAction(this);
  26528. };
  26529. _proto.startAt = function startAt(time) {
  26530. this._startTime = time;
  26531. return this;
  26532. };
  26533. _proto.setLoop = function setLoop(mode, repetitions) {
  26534. this.loop = mode;
  26535. this.repetitions = repetitions;
  26536. return this;
  26537. } // Weight
  26538. // set the weight stopping any scheduled fading
  26539. // although .enabled = false yields an effective weight of zero, this
  26540. // method does *not* change .enabled, because it would be confusing
  26541. ;
  26542. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26543. this.weight = weight; // note: same logic as when updated at runtime
  26544. this._effectiveWeight = this.enabled ? weight : 0;
  26545. return this.stopFading();
  26546. } // return the weight considering fading and .enabled
  26547. ;
  26548. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26549. return this._effectiveWeight;
  26550. };
  26551. _proto.fadeIn = function fadeIn(duration) {
  26552. return this._scheduleFading(duration, 0, 1);
  26553. };
  26554. _proto.fadeOut = function fadeOut(duration) {
  26555. return this._scheduleFading(duration, 1, 0);
  26556. };
  26557. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26558. fadeOutAction.fadeOut(duration);
  26559. this.fadeIn(duration);
  26560. if (warp) {
  26561. var fadeInDuration = this._clip.duration,
  26562. fadeOutDuration = fadeOutAction._clip.duration,
  26563. startEndRatio = fadeOutDuration / fadeInDuration,
  26564. endStartRatio = fadeInDuration / fadeOutDuration;
  26565. fadeOutAction.warp(1.0, startEndRatio, duration);
  26566. this.warp(endStartRatio, 1.0, duration);
  26567. }
  26568. return this;
  26569. };
  26570. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26571. return fadeInAction.crossFadeFrom(this, duration, warp);
  26572. };
  26573. _proto.stopFading = function stopFading() {
  26574. var weightInterpolant = this._weightInterpolant;
  26575. if (weightInterpolant !== null) {
  26576. this._weightInterpolant = null;
  26577. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26578. }
  26579. return this;
  26580. } // Time Scale Control
  26581. // set the time scale stopping any scheduled warping
  26582. // although .paused = true yields an effective time scale of zero, this
  26583. // method does *not* change .paused, because it would be confusing
  26584. ;
  26585. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26586. this.timeScale = timeScale;
  26587. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26588. return this.stopWarping();
  26589. } // return the time scale considering warping and .paused
  26590. ;
  26591. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26592. return this._effectiveTimeScale;
  26593. };
  26594. _proto.setDuration = function setDuration(duration) {
  26595. this.timeScale = this._clip.duration / duration;
  26596. return this.stopWarping();
  26597. };
  26598. _proto.syncWith = function syncWith(action) {
  26599. this.time = action.time;
  26600. this.timeScale = action.timeScale;
  26601. return this.stopWarping();
  26602. };
  26603. _proto.halt = function halt(duration) {
  26604. return this.warp(this._effectiveTimeScale, 0, duration);
  26605. };
  26606. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26607. var mixer = this._mixer,
  26608. now = mixer.time,
  26609. timeScale = this.timeScale;
  26610. var interpolant = this._timeScaleInterpolant;
  26611. if (interpolant === null) {
  26612. interpolant = mixer._lendControlInterpolant();
  26613. this._timeScaleInterpolant = interpolant;
  26614. }
  26615. var times = interpolant.parameterPositions,
  26616. values = interpolant.sampleValues;
  26617. times[0] = now;
  26618. times[1] = now + duration;
  26619. values[0] = startTimeScale / timeScale;
  26620. values[1] = endTimeScale / timeScale;
  26621. return this;
  26622. };
  26623. _proto.stopWarping = function stopWarping() {
  26624. var timeScaleInterpolant = this._timeScaleInterpolant;
  26625. if (timeScaleInterpolant !== null) {
  26626. this._timeScaleInterpolant = null;
  26627. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26628. }
  26629. return this;
  26630. } // Object Accessors
  26631. ;
  26632. _proto.getMixer = function getMixer() {
  26633. return this._mixer;
  26634. };
  26635. _proto.getClip = function getClip() {
  26636. return this._clip;
  26637. };
  26638. _proto.getRoot = function getRoot() {
  26639. return this._localRoot || this._mixer._root;
  26640. } // Interna
  26641. ;
  26642. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26643. // called by the mixer
  26644. if (!this.enabled) {
  26645. // call ._updateWeight() to update ._effectiveWeight
  26646. this._updateWeight(time);
  26647. return;
  26648. }
  26649. var startTime = this._startTime;
  26650. if (startTime !== null) {
  26651. // check for scheduled start of action
  26652. var timeRunning = (time - startTime) * timeDirection;
  26653. if (timeRunning < 0 || timeDirection === 0) {
  26654. return; // yet to come / don't decide when delta = 0
  26655. } // start
  26656. this._startTime = null; // unschedule
  26657. deltaTime = timeDirection * timeRunning;
  26658. } // apply time scale and advance time
  26659. deltaTime *= this._updateTimeScale(time);
  26660. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26661. // an effective weight of 0
  26662. var weight = this._updateWeight(time);
  26663. if (weight > 0) {
  26664. var _interpolants = this._interpolants;
  26665. var propertyMixers = this._propertyBindings;
  26666. switch (this.blendMode) {
  26667. case AdditiveAnimationBlendMode:
  26668. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26669. _interpolants[j].evaluate(clipTime);
  26670. propertyMixers[j].accumulateAdditive(weight);
  26671. }
  26672. break;
  26673. case NormalAnimationBlendMode:
  26674. default:
  26675. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26676. _interpolants[_j].evaluate(clipTime);
  26677. propertyMixers[_j].accumulate(accuIndex, weight);
  26678. }
  26679. }
  26680. }
  26681. };
  26682. _proto._updateWeight = function _updateWeight(time) {
  26683. var weight = 0;
  26684. if (this.enabled) {
  26685. weight = this.weight;
  26686. var interpolant = this._weightInterpolant;
  26687. if (interpolant !== null) {
  26688. var interpolantValue = interpolant.evaluate(time)[0];
  26689. weight *= interpolantValue;
  26690. if (time > interpolant.parameterPositions[1]) {
  26691. this.stopFading();
  26692. if (interpolantValue === 0) {
  26693. // faded out, disable
  26694. this.enabled = false;
  26695. }
  26696. }
  26697. }
  26698. }
  26699. this._effectiveWeight = weight;
  26700. return weight;
  26701. };
  26702. _proto._updateTimeScale = function _updateTimeScale(time) {
  26703. var timeScale = 0;
  26704. if (!this.paused) {
  26705. timeScale = this.timeScale;
  26706. var interpolant = this._timeScaleInterpolant;
  26707. if (interpolant !== null) {
  26708. var interpolantValue = interpolant.evaluate(time)[0];
  26709. timeScale *= interpolantValue;
  26710. if (time > interpolant.parameterPositions[1]) {
  26711. this.stopWarping();
  26712. if (timeScale === 0) {
  26713. // motion has halted, pause
  26714. this.paused = true;
  26715. } else {
  26716. // warp done - apply final time scale
  26717. this.timeScale = timeScale;
  26718. }
  26719. }
  26720. }
  26721. }
  26722. this._effectiveTimeScale = timeScale;
  26723. return timeScale;
  26724. };
  26725. _proto._updateTime = function _updateTime(deltaTime) {
  26726. var duration = this._clip.duration;
  26727. var loop = this.loop;
  26728. var time = this.time + deltaTime;
  26729. var loopCount = this._loopCount;
  26730. var pingPong = loop === LoopPingPong;
  26731. if (deltaTime === 0) {
  26732. if (loopCount === -1) return time;
  26733. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26734. }
  26735. if (loop === LoopOnce) {
  26736. if (loopCount === -1) {
  26737. // just started
  26738. this._loopCount = 0;
  26739. this._setEndings(true, true, false);
  26740. }
  26741. handle_stop: {
  26742. if (time >= duration) {
  26743. time = duration;
  26744. } else if (time < 0) {
  26745. time = 0;
  26746. } else {
  26747. this.time = time;
  26748. break handle_stop;
  26749. }
  26750. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26751. this.time = time;
  26752. this._mixer.dispatchEvent({
  26753. type: 'finished',
  26754. action: this,
  26755. direction: deltaTime < 0 ? -1 : 1
  26756. });
  26757. }
  26758. } else {
  26759. // repetitive Repeat or PingPong
  26760. if (loopCount === -1) {
  26761. // just started
  26762. if (deltaTime >= 0) {
  26763. loopCount = 0;
  26764. this._setEndings(true, this.repetitions === 0, pingPong);
  26765. } else {
  26766. // when looping in reverse direction, the initial
  26767. // transition through zero counts as a repetition,
  26768. // so leave loopCount at -1
  26769. this._setEndings(this.repetitions === 0, true, pingPong);
  26770. }
  26771. }
  26772. if (time >= duration || time < 0) {
  26773. // wrap around
  26774. var loopDelta = Math.floor(time / duration); // signed
  26775. time -= duration * loopDelta;
  26776. loopCount += Math.abs(loopDelta);
  26777. var pending = this.repetitions - loopCount;
  26778. if (pending <= 0) {
  26779. // have to stop (switch state, clamp time, fire event)
  26780. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26781. time = deltaTime > 0 ? duration : 0;
  26782. this.time = time;
  26783. this._mixer.dispatchEvent({
  26784. type: 'finished',
  26785. action: this,
  26786. direction: deltaTime > 0 ? 1 : -1
  26787. });
  26788. } else {
  26789. // keep running
  26790. if (pending === 1) {
  26791. // entering the last round
  26792. var atStart = deltaTime < 0;
  26793. this._setEndings(atStart, !atStart, pingPong);
  26794. } else {
  26795. this._setEndings(false, false, pingPong);
  26796. }
  26797. this._loopCount = loopCount;
  26798. this.time = time;
  26799. this._mixer.dispatchEvent({
  26800. type: 'loop',
  26801. action: this,
  26802. loopDelta: loopDelta
  26803. });
  26804. }
  26805. } else {
  26806. this.time = time;
  26807. }
  26808. if (pingPong && (loopCount & 1) === 1) {
  26809. // invert time for the "pong round"
  26810. return duration - time;
  26811. }
  26812. }
  26813. return time;
  26814. };
  26815. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26816. var settings = this._interpolantSettings;
  26817. if (pingPong) {
  26818. settings.endingStart = ZeroSlopeEnding;
  26819. settings.endingEnd = ZeroSlopeEnding;
  26820. } else {
  26821. // assuming for LoopOnce atStart == atEnd == true
  26822. if (atStart) {
  26823. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26824. } else {
  26825. settings.endingStart = WrapAroundEnding;
  26826. }
  26827. if (atEnd) {
  26828. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26829. } else {
  26830. settings.endingEnd = WrapAroundEnding;
  26831. }
  26832. }
  26833. };
  26834. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26835. var mixer = this._mixer,
  26836. now = mixer.time;
  26837. var interpolant = this._weightInterpolant;
  26838. if (interpolant === null) {
  26839. interpolant = mixer._lendControlInterpolant();
  26840. this._weightInterpolant = interpolant;
  26841. }
  26842. var times = interpolant.parameterPositions,
  26843. values = interpolant.sampleValues;
  26844. times[0] = now;
  26845. values[0] = weightNow;
  26846. times[1] = now + duration;
  26847. values[1] = weightThen;
  26848. return this;
  26849. };
  26850. return AnimationAction;
  26851. }();
  26852. function AnimationMixer(root) {
  26853. this._root = root;
  26854. this._initMemoryManager();
  26855. this._accuIndex = 0;
  26856. this.time = 0;
  26857. this.timeScale = 1.0;
  26858. }
  26859. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26860. constructor: AnimationMixer,
  26861. _bindAction: function _bindAction(action, prototypeAction) {
  26862. var root = action._localRoot || this._root,
  26863. tracks = action._clip.tracks,
  26864. nTracks = tracks.length,
  26865. bindings = action._propertyBindings,
  26866. interpolants = action._interpolants,
  26867. rootUuid = root.uuid,
  26868. bindingsByRoot = this._bindingsByRootAndName;
  26869. var bindingsByName = bindingsByRoot[rootUuid];
  26870. if (bindingsByName === undefined) {
  26871. bindingsByName = {};
  26872. bindingsByRoot[rootUuid] = bindingsByName;
  26873. }
  26874. for (var i = 0; i !== nTracks; ++i) {
  26875. var track = tracks[i],
  26876. trackName = track.name;
  26877. var binding = bindingsByName[trackName];
  26878. if (binding !== undefined) {
  26879. bindings[i] = binding;
  26880. } else {
  26881. binding = bindings[i];
  26882. if (binding !== undefined) {
  26883. // existing binding, make sure the cache knows
  26884. if (binding._cacheIndex === null) {
  26885. ++binding.referenceCount;
  26886. this._addInactiveBinding(binding, rootUuid, trackName);
  26887. }
  26888. continue;
  26889. }
  26890. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26891. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26892. ++binding.referenceCount;
  26893. this._addInactiveBinding(binding, rootUuid, trackName);
  26894. bindings[i] = binding;
  26895. }
  26896. interpolants[i].resultBuffer = binding.buffer;
  26897. }
  26898. },
  26899. _activateAction: function _activateAction(action) {
  26900. if (!this._isActiveAction(action)) {
  26901. if (action._cacheIndex === null) {
  26902. // this action has been forgotten by the cache, but the user
  26903. // appears to be still using it -> rebind
  26904. var rootUuid = (action._localRoot || this._root).uuid,
  26905. clipUuid = action._clip.uuid,
  26906. actionsForClip = this._actionsByClip[clipUuid];
  26907. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26908. this._addInactiveAction(action, clipUuid, rootUuid);
  26909. }
  26910. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26911. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26912. var binding = bindings[i];
  26913. if (binding.useCount++ === 0) {
  26914. this._lendBinding(binding);
  26915. binding.saveOriginalState();
  26916. }
  26917. }
  26918. this._lendAction(action);
  26919. }
  26920. },
  26921. _deactivateAction: function _deactivateAction(action) {
  26922. if (this._isActiveAction(action)) {
  26923. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26924. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26925. var binding = bindings[i];
  26926. if (--binding.useCount === 0) {
  26927. binding.restoreOriginalState();
  26928. this._takeBackBinding(binding);
  26929. }
  26930. }
  26931. this._takeBackAction(action);
  26932. }
  26933. },
  26934. // Memory manager
  26935. _initMemoryManager: function _initMemoryManager() {
  26936. this._actions = []; // 'nActiveActions' followed by inactive ones
  26937. this._nActiveActions = 0;
  26938. this._actionsByClip = {}; // inside:
  26939. // {
  26940. // knownActions: Array< AnimationAction > - used as prototypes
  26941. // actionByRoot: AnimationAction - lookup
  26942. // }
  26943. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26944. this._nActiveBindings = 0;
  26945. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26946. this._controlInterpolants = []; // same game as above
  26947. this._nActiveControlInterpolants = 0;
  26948. var scope = this;
  26949. this.stats = {
  26950. actions: {
  26951. get total() {
  26952. return scope._actions.length;
  26953. },
  26954. get inUse() {
  26955. return scope._nActiveActions;
  26956. }
  26957. },
  26958. bindings: {
  26959. get total() {
  26960. return scope._bindings.length;
  26961. },
  26962. get inUse() {
  26963. return scope._nActiveBindings;
  26964. }
  26965. },
  26966. controlInterpolants: {
  26967. get total() {
  26968. return scope._controlInterpolants.length;
  26969. },
  26970. get inUse() {
  26971. return scope._nActiveControlInterpolants;
  26972. }
  26973. }
  26974. };
  26975. },
  26976. // Memory management for AnimationAction objects
  26977. _isActiveAction: function _isActiveAction(action) {
  26978. var index = action._cacheIndex;
  26979. return index !== null && index < this._nActiveActions;
  26980. },
  26981. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26982. var actions = this._actions,
  26983. actionsByClip = this._actionsByClip;
  26984. var actionsForClip = actionsByClip[clipUuid];
  26985. if (actionsForClip === undefined) {
  26986. actionsForClip = {
  26987. knownActions: [action],
  26988. actionByRoot: {}
  26989. };
  26990. action._byClipCacheIndex = 0;
  26991. actionsByClip[clipUuid] = actionsForClip;
  26992. } else {
  26993. var knownActions = actionsForClip.knownActions;
  26994. action._byClipCacheIndex = knownActions.length;
  26995. knownActions.push(action);
  26996. }
  26997. action._cacheIndex = actions.length;
  26998. actions.push(action);
  26999. actionsForClip.actionByRoot[rootUuid] = action;
  27000. },
  27001. _removeInactiveAction: function _removeInactiveAction(action) {
  27002. var actions = this._actions,
  27003. lastInactiveAction = actions[actions.length - 1],
  27004. cacheIndex = action._cacheIndex;
  27005. lastInactiveAction._cacheIndex = cacheIndex;
  27006. actions[cacheIndex] = lastInactiveAction;
  27007. actions.pop();
  27008. action._cacheIndex = null;
  27009. var clipUuid = action._clip.uuid,
  27010. actionsByClip = this._actionsByClip,
  27011. actionsForClip = actionsByClip[clipUuid],
  27012. knownActionsForClip = actionsForClip.knownActions,
  27013. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27014. byClipCacheIndex = action._byClipCacheIndex;
  27015. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27016. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27017. knownActionsForClip.pop();
  27018. action._byClipCacheIndex = null;
  27019. var actionByRoot = actionsForClip.actionByRoot,
  27020. rootUuid = (action._localRoot || this._root).uuid;
  27021. delete actionByRoot[rootUuid];
  27022. if (knownActionsForClip.length === 0) {
  27023. delete actionsByClip[clipUuid];
  27024. }
  27025. this._removeInactiveBindingsForAction(action);
  27026. },
  27027. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27028. var bindings = action._propertyBindings;
  27029. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27030. var binding = bindings[i];
  27031. if (--binding.referenceCount === 0) {
  27032. this._removeInactiveBinding(binding);
  27033. }
  27034. }
  27035. },
  27036. _lendAction: function _lendAction(action) {
  27037. // [ active actions | inactive actions ]
  27038. // [ active actions >| inactive actions ]
  27039. // s a
  27040. // <-swap->
  27041. // a s
  27042. var actions = this._actions,
  27043. prevIndex = action._cacheIndex,
  27044. lastActiveIndex = this._nActiveActions++,
  27045. firstInactiveAction = actions[lastActiveIndex];
  27046. action._cacheIndex = lastActiveIndex;
  27047. actions[lastActiveIndex] = action;
  27048. firstInactiveAction._cacheIndex = prevIndex;
  27049. actions[prevIndex] = firstInactiveAction;
  27050. },
  27051. _takeBackAction: function _takeBackAction(action) {
  27052. // [ active actions | inactive actions ]
  27053. // [ active actions |< inactive actions ]
  27054. // a s
  27055. // <-swap->
  27056. // s a
  27057. var actions = this._actions,
  27058. prevIndex = action._cacheIndex,
  27059. firstInactiveIndex = --this._nActiveActions,
  27060. lastActiveAction = actions[firstInactiveIndex];
  27061. action._cacheIndex = firstInactiveIndex;
  27062. actions[firstInactiveIndex] = action;
  27063. lastActiveAction._cacheIndex = prevIndex;
  27064. actions[prevIndex] = lastActiveAction;
  27065. },
  27066. // Memory management for PropertyMixer objects
  27067. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27068. var bindingsByRoot = this._bindingsByRootAndName,
  27069. bindings = this._bindings;
  27070. var bindingByName = bindingsByRoot[rootUuid];
  27071. if (bindingByName === undefined) {
  27072. bindingByName = {};
  27073. bindingsByRoot[rootUuid] = bindingByName;
  27074. }
  27075. bindingByName[trackName] = binding;
  27076. binding._cacheIndex = bindings.length;
  27077. bindings.push(binding);
  27078. },
  27079. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27080. var bindings = this._bindings,
  27081. propBinding = binding.binding,
  27082. rootUuid = propBinding.rootNode.uuid,
  27083. trackName = propBinding.path,
  27084. bindingsByRoot = this._bindingsByRootAndName,
  27085. bindingByName = bindingsByRoot[rootUuid],
  27086. lastInactiveBinding = bindings[bindings.length - 1],
  27087. cacheIndex = binding._cacheIndex;
  27088. lastInactiveBinding._cacheIndex = cacheIndex;
  27089. bindings[cacheIndex] = lastInactiveBinding;
  27090. bindings.pop();
  27091. delete bindingByName[trackName];
  27092. if (Object.keys(bindingByName).length === 0) {
  27093. delete bindingsByRoot[rootUuid];
  27094. }
  27095. },
  27096. _lendBinding: function _lendBinding(binding) {
  27097. var bindings = this._bindings,
  27098. prevIndex = binding._cacheIndex,
  27099. lastActiveIndex = this._nActiveBindings++,
  27100. firstInactiveBinding = bindings[lastActiveIndex];
  27101. binding._cacheIndex = lastActiveIndex;
  27102. bindings[lastActiveIndex] = binding;
  27103. firstInactiveBinding._cacheIndex = prevIndex;
  27104. bindings[prevIndex] = firstInactiveBinding;
  27105. },
  27106. _takeBackBinding: function _takeBackBinding(binding) {
  27107. var bindings = this._bindings,
  27108. prevIndex = binding._cacheIndex,
  27109. firstInactiveIndex = --this._nActiveBindings,
  27110. lastActiveBinding = bindings[firstInactiveIndex];
  27111. binding._cacheIndex = firstInactiveIndex;
  27112. bindings[firstInactiveIndex] = binding;
  27113. lastActiveBinding._cacheIndex = prevIndex;
  27114. bindings[prevIndex] = lastActiveBinding;
  27115. },
  27116. // Memory management of Interpolants for weight and time scale
  27117. _lendControlInterpolant: function _lendControlInterpolant() {
  27118. var interpolants = this._controlInterpolants,
  27119. lastActiveIndex = this._nActiveControlInterpolants++;
  27120. var interpolant = interpolants[lastActiveIndex];
  27121. if (interpolant === undefined) {
  27122. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27123. interpolant.__cacheIndex = lastActiveIndex;
  27124. interpolants[lastActiveIndex] = interpolant;
  27125. }
  27126. return interpolant;
  27127. },
  27128. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27129. var interpolants = this._controlInterpolants,
  27130. prevIndex = interpolant.__cacheIndex,
  27131. firstInactiveIndex = --this._nActiveControlInterpolants,
  27132. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27133. interpolant.__cacheIndex = firstInactiveIndex;
  27134. interpolants[firstInactiveIndex] = interpolant;
  27135. lastActiveInterpolant.__cacheIndex = prevIndex;
  27136. interpolants[prevIndex] = lastActiveInterpolant;
  27137. },
  27138. _controlInterpolantsResultBuffer: new Float32Array(1),
  27139. // return an action for a clip optionally using a custom root target
  27140. // object (this method allocates a lot of dynamic memory in case a
  27141. // previously unknown clip/root combination is specified)
  27142. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27143. var root = optionalRoot || this._root,
  27144. rootUuid = root.uuid;
  27145. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27146. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27147. var actionsForClip = this._actionsByClip[clipUuid];
  27148. var prototypeAction = null;
  27149. if (blendMode === undefined) {
  27150. if (clipObject !== null) {
  27151. blendMode = clipObject.blendMode;
  27152. } else {
  27153. blendMode = NormalAnimationBlendMode;
  27154. }
  27155. }
  27156. if (actionsForClip !== undefined) {
  27157. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27158. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27159. return existingAction;
  27160. } // we know the clip, so we don't have to parse all
  27161. // the bindings again but can just copy
  27162. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27163. if (clipObject === null) clipObject = prototypeAction._clip;
  27164. } // clip must be known when specified via string
  27165. if (clipObject === null) return null; // allocate all resources required to run it
  27166. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27167. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27168. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27169. return newAction;
  27170. },
  27171. // get an existing action
  27172. existingAction: function existingAction(clip, optionalRoot) {
  27173. var root = optionalRoot || this._root,
  27174. rootUuid = root.uuid,
  27175. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27176. clipUuid = clipObject ? clipObject.uuid : clip,
  27177. actionsForClip = this._actionsByClip[clipUuid];
  27178. if (actionsForClip !== undefined) {
  27179. return actionsForClip.actionByRoot[rootUuid] || null;
  27180. }
  27181. return null;
  27182. },
  27183. // deactivates all previously scheduled actions
  27184. stopAllAction: function stopAllAction() {
  27185. var actions = this._actions,
  27186. nActions = this._nActiveActions;
  27187. for (var i = nActions - 1; i >= 0; --i) {
  27188. actions[i].stop();
  27189. }
  27190. return this;
  27191. },
  27192. // advance the time and update apply the animation
  27193. update: function update(deltaTime) {
  27194. deltaTime *= this.timeScale;
  27195. var actions = this._actions,
  27196. nActions = this._nActiveActions,
  27197. time = this.time += deltaTime,
  27198. timeDirection = Math.sign(deltaTime),
  27199. accuIndex = this._accuIndex ^= 1; // run active actions
  27200. for (var i = 0; i !== nActions; ++i) {
  27201. var action = actions[i];
  27202. action._update(time, deltaTime, timeDirection, accuIndex);
  27203. } // update scene graph
  27204. var bindings = this._bindings,
  27205. nBindings = this._nActiveBindings;
  27206. for (var _i = 0; _i !== nBindings; ++_i) {
  27207. bindings[_i].apply(accuIndex);
  27208. }
  27209. return this;
  27210. },
  27211. // Allows you to seek to a specific time in an animation.
  27212. setTime: function setTime(timeInSeconds) {
  27213. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27214. for (var i = 0; i < this._actions.length; i++) {
  27215. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27216. }
  27217. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27218. },
  27219. // return this mixer's root target object
  27220. getRoot: function getRoot() {
  27221. return this._root;
  27222. },
  27223. // free all resources specific to a particular clip
  27224. uncacheClip: function uncacheClip(clip) {
  27225. var actions = this._actions,
  27226. clipUuid = clip.uuid,
  27227. actionsByClip = this._actionsByClip,
  27228. actionsForClip = actionsByClip[clipUuid];
  27229. if (actionsForClip !== undefined) {
  27230. // note: just calling _removeInactiveAction would mess up the
  27231. // iteration state and also require updating the state we can
  27232. // just throw away
  27233. var actionsToRemove = actionsForClip.knownActions;
  27234. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27235. var action = actionsToRemove[i];
  27236. this._deactivateAction(action);
  27237. var cacheIndex = action._cacheIndex,
  27238. lastInactiveAction = actions[actions.length - 1];
  27239. action._cacheIndex = null;
  27240. action._byClipCacheIndex = null;
  27241. lastInactiveAction._cacheIndex = cacheIndex;
  27242. actions[cacheIndex] = lastInactiveAction;
  27243. actions.pop();
  27244. this._removeInactiveBindingsForAction(action);
  27245. }
  27246. delete actionsByClip[clipUuid];
  27247. }
  27248. },
  27249. // free all resources specific to a particular root target object
  27250. uncacheRoot: function uncacheRoot(root) {
  27251. var rootUuid = root.uuid,
  27252. actionsByClip = this._actionsByClip;
  27253. for (var clipUuid in actionsByClip) {
  27254. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27255. action = actionByRoot[rootUuid];
  27256. if (action !== undefined) {
  27257. this._deactivateAction(action);
  27258. this._removeInactiveAction(action);
  27259. }
  27260. }
  27261. var bindingsByRoot = this._bindingsByRootAndName,
  27262. bindingByName = bindingsByRoot[rootUuid];
  27263. if (bindingByName !== undefined) {
  27264. for (var trackName in bindingByName) {
  27265. var binding = bindingByName[trackName];
  27266. binding.restoreOriginalState();
  27267. this._removeInactiveBinding(binding);
  27268. }
  27269. }
  27270. },
  27271. // remove a targeted clip from the cache
  27272. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27273. var action = this.existingAction(clip, optionalRoot);
  27274. if (action !== null) {
  27275. this._deactivateAction(action);
  27276. this._removeInactiveAction(action);
  27277. }
  27278. }
  27279. });
  27280. var Uniform = /*#__PURE__*/function () {
  27281. function Uniform(value) {
  27282. if (typeof value === 'string') {
  27283. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27284. value = arguments[1];
  27285. }
  27286. this.value = value;
  27287. }
  27288. var _proto = Uniform.prototype;
  27289. _proto.clone = function clone() {
  27290. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27291. };
  27292. return Uniform;
  27293. }();
  27294. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27295. InterleavedBuffer.call(this, array, stride);
  27296. this.meshPerAttribute = meshPerAttribute || 1;
  27297. }
  27298. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27299. constructor: InstancedInterleavedBuffer,
  27300. isInstancedInterleavedBuffer: true,
  27301. copy: function copy(source) {
  27302. InterleavedBuffer.prototype.copy.call(this, source);
  27303. this.meshPerAttribute = source.meshPerAttribute;
  27304. return this;
  27305. },
  27306. clone: function clone(data) {
  27307. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27308. ib.meshPerAttribute = this.meshPerAttribute;
  27309. return ib;
  27310. },
  27311. toJSON: function toJSON(data) {
  27312. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27313. json.isInstancedInterleavedBuffer = true;
  27314. json.meshPerAttribute = this.meshPerAttribute;
  27315. return json;
  27316. }
  27317. });
  27318. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27319. this.buffer = buffer;
  27320. this.type = type;
  27321. this.itemSize = itemSize;
  27322. this.elementSize = elementSize;
  27323. this.count = count;
  27324. this.version = 0;
  27325. }
  27326. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27327. set: function set(value) {
  27328. if (value === true) this.version++;
  27329. }
  27330. });
  27331. Object.assign(GLBufferAttribute.prototype, {
  27332. isGLBufferAttribute: true,
  27333. setBuffer: function setBuffer(buffer) {
  27334. this.buffer = buffer;
  27335. return this;
  27336. },
  27337. setType: function setType(type, elementSize) {
  27338. this.type = type;
  27339. this.elementSize = elementSize;
  27340. return this;
  27341. },
  27342. setItemSize: function setItemSize(itemSize) {
  27343. this.itemSize = itemSize;
  27344. return this;
  27345. },
  27346. setCount: function setCount(count) {
  27347. this.count = count;
  27348. return this;
  27349. }
  27350. });
  27351. function Raycaster(origin, direction, near, far) {
  27352. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27353. this.near = near || 0;
  27354. this.far = far || Infinity;
  27355. this.camera = null;
  27356. this.layers = new Layers();
  27357. this.params = {
  27358. Mesh: {},
  27359. Line: {
  27360. threshold: 1
  27361. },
  27362. LOD: {},
  27363. Points: {
  27364. threshold: 1
  27365. },
  27366. Sprite: {}
  27367. };
  27368. Object.defineProperties(this.params, {
  27369. PointCloud: {
  27370. get: function get() {
  27371. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27372. return this.Points;
  27373. }
  27374. }
  27375. });
  27376. }
  27377. function ascSort(a, b) {
  27378. return a.distance - b.distance;
  27379. }
  27380. function _intersectObject(object, raycaster, intersects, recursive) {
  27381. if (object.layers.test(raycaster.layers)) {
  27382. object.raycast(raycaster, intersects);
  27383. }
  27384. if (recursive === true) {
  27385. var children = object.children;
  27386. for (var i = 0, l = children.length; i < l; i++) {
  27387. _intersectObject(children[i], raycaster, intersects, true);
  27388. }
  27389. }
  27390. }
  27391. Object.assign(Raycaster.prototype, {
  27392. set: function set(origin, direction) {
  27393. // direction is assumed to be normalized (for accurate distance calculations)
  27394. this.ray.set(origin, direction);
  27395. },
  27396. setFromCamera: function setFromCamera(coords, camera) {
  27397. if (camera && camera.isPerspectiveCamera) {
  27398. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27399. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27400. this.camera = camera;
  27401. } else if (camera && camera.isOrthographicCamera) {
  27402. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27403. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27404. this.camera = camera;
  27405. } else {
  27406. console.error('THREE.Raycaster: Unsupported camera type.');
  27407. }
  27408. },
  27409. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27410. var intersects = optionalTarget || [];
  27411. _intersectObject(object, this, intersects, recursive);
  27412. intersects.sort(ascSort);
  27413. return intersects;
  27414. },
  27415. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27416. var intersects = optionalTarget || [];
  27417. if (Array.isArray(objects) === false) {
  27418. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27419. return intersects;
  27420. }
  27421. for (var i = 0, l = objects.length; i < l; i++) {
  27422. _intersectObject(objects[i], this, intersects, recursive);
  27423. }
  27424. intersects.sort(ascSort);
  27425. return intersects;
  27426. }
  27427. });
  27428. /**
  27429. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27430. *
  27431. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27432. * The azimuthal angle (theta) is measured from the positive z-axis.
  27433. */
  27434. var Spherical = /*#__PURE__*/function () {
  27435. function Spherical(radius, phi, theta) {
  27436. if (radius === void 0) {
  27437. radius = 1;
  27438. }
  27439. if (phi === void 0) {
  27440. phi = 0;
  27441. }
  27442. if (theta === void 0) {
  27443. theta = 0;
  27444. }
  27445. this.radius = radius;
  27446. this.phi = phi; // polar angle
  27447. this.theta = theta; // azimuthal angle
  27448. return this;
  27449. }
  27450. var _proto = Spherical.prototype;
  27451. _proto.set = function set(radius, phi, theta) {
  27452. this.radius = radius;
  27453. this.phi = phi;
  27454. this.theta = theta;
  27455. return this;
  27456. };
  27457. _proto.clone = function clone() {
  27458. return new this.constructor().copy(this);
  27459. };
  27460. _proto.copy = function copy(other) {
  27461. this.radius = other.radius;
  27462. this.phi = other.phi;
  27463. this.theta = other.theta;
  27464. return this;
  27465. } // restrict phi to be betwee EPS and PI-EPS
  27466. ;
  27467. _proto.makeSafe = function makeSafe() {
  27468. var EPS = 0.000001;
  27469. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27470. return this;
  27471. };
  27472. _proto.setFromVector3 = function setFromVector3(v) {
  27473. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27474. };
  27475. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27476. this.radius = Math.sqrt(x * x + y * y + z * z);
  27477. if (this.radius === 0) {
  27478. this.theta = 0;
  27479. this.phi = 0;
  27480. } else {
  27481. this.theta = Math.atan2(x, z);
  27482. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27483. }
  27484. return this;
  27485. };
  27486. return Spherical;
  27487. }();
  27488. /**
  27489. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27490. */
  27491. var Cylindrical = /*#__PURE__*/function () {
  27492. function Cylindrical(radius, theta, y) {
  27493. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27494. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27495. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27496. return this;
  27497. }
  27498. var _proto = Cylindrical.prototype;
  27499. _proto.set = function set(radius, theta, y) {
  27500. this.radius = radius;
  27501. this.theta = theta;
  27502. this.y = y;
  27503. return this;
  27504. };
  27505. _proto.clone = function clone() {
  27506. return new this.constructor().copy(this);
  27507. };
  27508. _proto.copy = function copy(other) {
  27509. this.radius = other.radius;
  27510. this.theta = other.theta;
  27511. this.y = other.y;
  27512. return this;
  27513. };
  27514. _proto.setFromVector3 = function setFromVector3(v) {
  27515. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27516. };
  27517. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27518. this.radius = Math.sqrt(x * x + z * z);
  27519. this.theta = Math.atan2(x, z);
  27520. this.y = y;
  27521. return this;
  27522. };
  27523. return Cylindrical;
  27524. }();
  27525. var _vector$7 = /*@__PURE__*/new Vector2();
  27526. var Box2 = /*#__PURE__*/function () {
  27527. function Box2(min, max) {
  27528. Object.defineProperty(this, 'isBox2', {
  27529. value: true
  27530. });
  27531. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27532. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27533. }
  27534. var _proto = Box2.prototype;
  27535. _proto.set = function set(min, max) {
  27536. this.min.copy(min);
  27537. this.max.copy(max);
  27538. return this;
  27539. };
  27540. _proto.setFromPoints = function setFromPoints(points) {
  27541. this.makeEmpty();
  27542. for (var i = 0, il = points.length; i < il; i++) {
  27543. this.expandByPoint(points[i]);
  27544. }
  27545. return this;
  27546. };
  27547. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27548. var halfSize = _vector$7.copy(size).multiplyScalar(0.5);
  27549. this.min.copy(center).sub(halfSize);
  27550. this.max.copy(center).add(halfSize);
  27551. return this;
  27552. };
  27553. _proto.clone = function clone() {
  27554. return new this.constructor().copy(this);
  27555. };
  27556. _proto.copy = function copy(box) {
  27557. this.min.copy(box.min);
  27558. this.max.copy(box.max);
  27559. return this;
  27560. };
  27561. _proto.makeEmpty = function makeEmpty() {
  27562. this.min.x = this.min.y = +Infinity;
  27563. this.max.x = this.max.y = -Infinity;
  27564. return this;
  27565. };
  27566. _proto.isEmpty = function isEmpty() {
  27567. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27568. return this.max.x < this.min.x || this.max.y < this.min.y;
  27569. };
  27570. _proto.getCenter = function getCenter(target) {
  27571. if (target === undefined) {
  27572. console.warn('THREE.Box2: .getCenter() target is now required');
  27573. target = new Vector2();
  27574. }
  27575. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27576. };
  27577. _proto.getSize = function getSize(target) {
  27578. if (target === undefined) {
  27579. console.warn('THREE.Box2: .getSize() target is now required');
  27580. target = new Vector2();
  27581. }
  27582. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27583. };
  27584. _proto.expandByPoint = function expandByPoint(point) {
  27585. this.min.min(point);
  27586. this.max.max(point);
  27587. return this;
  27588. };
  27589. _proto.expandByVector = function expandByVector(vector) {
  27590. this.min.sub(vector);
  27591. this.max.add(vector);
  27592. return this;
  27593. };
  27594. _proto.expandByScalar = function expandByScalar(scalar) {
  27595. this.min.addScalar(-scalar);
  27596. this.max.addScalar(scalar);
  27597. return this;
  27598. };
  27599. _proto.containsPoint = function containsPoint(point) {
  27600. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27601. };
  27602. _proto.containsBox = function containsBox(box) {
  27603. 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;
  27604. };
  27605. _proto.getParameter = function getParameter(point, target) {
  27606. // This can potentially have a divide by zero if the box
  27607. // has a size dimension of 0.
  27608. if (target === undefined) {
  27609. console.warn('THREE.Box2: .getParameter() target is now required');
  27610. target = new Vector2();
  27611. }
  27612. 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));
  27613. };
  27614. _proto.intersectsBox = function intersectsBox(box) {
  27615. // using 4 splitting planes to rule out intersections
  27616. 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;
  27617. };
  27618. _proto.clampPoint = function clampPoint(point, target) {
  27619. if (target === undefined) {
  27620. console.warn('THREE.Box2: .clampPoint() target is now required');
  27621. target = new Vector2();
  27622. }
  27623. return target.copy(point).clamp(this.min, this.max);
  27624. };
  27625. _proto.distanceToPoint = function distanceToPoint(point) {
  27626. var clampedPoint = _vector$7.copy(point).clamp(this.min, this.max);
  27627. return clampedPoint.sub(point).length();
  27628. };
  27629. _proto.intersect = function intersect(box) {
  27630. this.min.max(box.min);
  27631. this.max.min(box.max);
  27632. return this;
  27633. };
  27634. _proto.union = function union(box) {
  27635. this.min.min(box.min);
  27636. this.max.max(box.max);
  27637. return this;
  27638. };
  27639. _proto.translate = function translate(offset) {
  27640. this.min.add(offset);
  27641. this.max.add(offset);
  27642. return this;
  27643. };
  27644. _proto.equals = function equals(box) {
  27645. return box.min.equals(this.min) && box.max.equals(this.max);
  27646. };
  27647. return Box2;
  27648. }();
  27649. var _startP = /*@__PURE__*/new Vector3();
  27650. var _startEnd = /*@__PURE__*/new Vector3();
  27651. var Line3 = /*#__PURE__*/function () {
  27652. function Line3(start, end) {
  27653. this.start = start !== undefined ? start : new Vector3();
  27654. this.end = end !== undefined ? end : new Vector3();
  27655. }
  27656. var _proto = Line3.prototype;
  27657. _proto.set = function set(start, end) {
  27658. this.start.copy(start);
  27659. this.end.copy(end);
  27660. return this;
  27661. };
  27662. _proto.clone = function clone() {
  27663. return new this.constructor().copy(this);
  27664. };
  27665. _proto.copy = function copy(line) {
  27666. this.start.copy(line.start);
  27667. this.end.copy(line.end);
  27668. return this;
  27669. };
  27670. _proto.getCenter = function getCenter(target) {
  27671. if (target === undefined) {
  27672. console.warn('THREE.Line3: .getCenter() target is now required');
  27673. target = new Vector3();
  27674. }
  27675. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27676. };
  27677. _proto.delta = function delta(target) {
  27678. if (target === undefined) {
  27679. console.warn('THREE.Line3: .delta() target is now required');
  27680. target = new Vector3();
  27681. }
  27682. return target.subVectors(this.end, this.start);
  27683. };
  27684. _proto.distanceSq = function distanceSq() {
  27685. return this.start.distanceToSquared(this.end);
  27686. };
  27687. _proto.distance = function distance() {
  27688. return this.start.distanceTo(this.end);
  27689. };
  27690. _proto.at = function at(t, target) {
  27691. if (target === undefined) {
  27692. console.warn('THREE.Line3: .at() target is now required');
  27693. target = new Vector3();
  27694. }
  27695. return this.delta(target).multiplyScalar(t).add(this.start);
  27696. };
  27697. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27698. _startP.subVectors(point, this.start);
  27699. _startEnd.subVectors(this.end, this.start);
  27700. var startEnd2 = _startEnd.dot(_startEnd);
  27701. var startEnd_startP = _startEnd.dot(_startP);
  27702. var t = startEnd_startP / startEnd2;
  27703. if (clampToLine) {
  27704. t = MathUtils.clamp(t, 0, 1);
  27705. }
  27706. return t;
  27707. };
  27708. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27709. var t = this.closestPointToPointParameter(point, clampToLine);
  27710. if (target === undefined) {
  27711. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27712. target = new Vector3();
  27713. }
  27714. return this.delta(target).multiplyScalar(t).add(this.start);
  27715. };
  27716. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27717. this.start.applyMatrix4(matrix);
  27718. this.end.applyMatrix4(matrix);
  27719. return this;
  27720. };
  27721. _proto.equals = function equals(line) {
  27722. return line.start.equals(this.start) && line.end.equals(this.end);
  27723. };
  27724. return Line3;
  27725. }();
  27726. function ImmediateRenderObject(material) {
  27727. Object3D.call(this);
  27728. this.material = material;
  27729. this.render = function ()
  27730. /* renderCallback */
  27731. {};
  27732. this.hasPositions = false;
  27733. this.hasNormals = false;
  27734. this.hasColors = false;
  27735. this.hasUvs = false;
  27736. this.positionArray = null;
  27737. this.normalArray = null;
  27738. this.colorArray = null;
  27739. this.uvArray = null;
  27740. this.count = 0;
  27741. }
  27742. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27743. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27744. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27745. var _vector$8 = /*@__PURE__*/new Vector3();
  27746. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27747. _inheritsLoose(SpotLightHelper, _Object3D);
  27748. function SpotLightHelper(light, color) {
  27749. var _this;
  27750. _this = _Object3D.call(this) || this;
  27751. _this.light = light;
  27752. _this.light.updateMatrixWorld();
  27753. _this.matrix = light.matrixWorld;
  27754. _this.matrixAutoUpdate = false;
  27755. _this.color = color;
  27756. var geometry = new BufferGeometry();
  27757. 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];
  27758. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27759. var p1 = i / l * Math.PI * 2;
  27760. var p2 = j / l * Math.PI * 2;
  27761. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27762. }
  27763. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27764. var material = new LineBasicMaterial({
  27765. fog: false,
  27766. toneMapped: false
  27767. });
  27768. _this.cone = new LineSegments(geometry, material);
  27769. _this.add(_this.cone);
  27770. _this.update();
  27771. return _this;
  27772. }
  27773. var _proto = SpotLightHelper.prototype;
  27774. _proto.dispose = function dispose() {
  27775. this.cone.geometry.dispose();
  27776. this.cone.material.dispose();
  27777. };
  27778. _proto.update = function update() {
  27779. this.light.updateMatrixWorld();
  27780. var coneLength = this.light.distance ? this.light.distance : 1000;
  27781. var coneWidth = coneLength * Math.tan(this.light.angle);
  27782. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27783. _vector$8.setFromMatrixPosition(this.light.target.matrixWorld);
  27784. this.cone.lookAt(_vector$8);
  27785. if (this.color !== undefined) {
  27786. this.cone.material.color.set(this.color);
  27787. } else {
  27788. this.cone.material.color.copy(this.light.color);
  27789. }
  27790. };
  27791. return SpotLightHelper;
  27792. }(Object3D);
  27793. var _vector$9 = /*@__PURE__*/new Vector3();
  27794. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27795. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27796. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27797. _inheritsLoose(SkeletonHelper, _LineSegments);
  27798. function SkeletonHelper(object) {
  27799. var _this;
  27800. var bones = getBoneList(object);
  27801. var geometry = new BufferGeometry();
  27802. var vertices = [];
  27803. var colors = [];
  27804. var color1 = new Color(0, 0, 1);
  27805. var color2 = new Color(0, 1, 0);
  27806. for (var i = 0; i < bones.length; i++) {
  27807. var bone = bones[i];
  27808. if (bone.parent && bone.parent.isBone) {
  27809. vertices.push(0, 0, 0);
  27810. vertices.push(0, 0, 0);
  27811. colors.push(color1.r, color1.g, color1.b);
  27812. colors.push(color2.r, color2.g, color2.b);
  27813. }
  27814. }
  27815. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27816. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27817. var material = new LineBasicMaterial({
  27818. vertexColors: true,
  27819. depthTest: false,
  27820. depthWrite: false,
  27821. toneMapped: false,
  27822. transparent: true
  27823. });
  27824. _this = _LineSegments.call(this, geometry, material) || this;
  27825. _this.type = 'SkeletonHelper';
  27826. _this.isSkeletonHelper = true;
  27827. _this.root = object;
  27828. _this.bones = bones;
  27829. _this.matrix = object.matrixWorld;
  27830. _this.matrixAutoUpdate = false;
  27831. return _this;
  27832. }
  27833. var _proto = SkeletonHelper.prototype;
  27834. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27835. var bones = this.bones;
  27836. var geometry = this.geometry;
  27837. var position = geometry.getAttribute('position');
  27838. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  27839. for (var i = 0, j = 0; i < bones.length; i++) {
  27840. var bone = bones[i];
  27841. if (bone.parent && bone.parent.isBone) {
  27842. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27843. _vector$9.setFromMatrixPosition(_boneMatrix);
  27844. position.setXYZ(j, _vector$9.x, _vector$9.y, _vector$9.z);
  27845. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27846. _vector$9.setFromMatrixPosition(_boneMatrix);
  27847. position.setXYZ(j + 1, _vector$9.x, _vector$9.y, _vector$9.z);
  27848. j += 2;
  27849. }
  27850. }
  27851. geometry.getAttribute('position').needsUpdate = true;
  27852. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27853. };
  27854. return SkeletonHelper;
  27855. }(LineSegments);
  27856. function getBoneList(object) {
  27857. var boneList = [];
  27858. if (object && object.isBone) {
  27859. boneList.push(object);
  27860. }
  27861. for (var i = 0; i < object.children.length; i++) {
  27862. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27863. }
  27864. return boneList;
  27865. }
  27866. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27867. _inheritsLoose(PointLightHelper, _Mesh);
  27868. function PointLightHelper(light, sphereSize, color) {
  27869. var _this;
  27870. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  27871. var material = new MeshBasicMaterial({
  27872. wireframe: true,
  27873. fog: false,
  27874. toneMapped: false
  27875. });
  27876. _this = _Mesh.call(this, geometry, material) || this;
  27877. _this.light = light;
  27878. _this.light.updateMatrixWorld();
  27879. _this.color = color;
  27880. _this.type = 'PointLightHelper';
  27881. _this.matrix = _this.light.matrixWorld;
  27882. _this.matrixAutoUpdate = false;
  27883. _this.update();
  27884. /*
  27885. // TODO: delete this comment?
  27886. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27887. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27888. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27889. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27890. const d = light.distance;
  27891. if ( d === 0.0 ) {
  27892. this.lightDistance.visible = false;
  27893. } else {
  27894. this.lightDistance.scale.set( d, d, d );
  27895. }
  27896. this.add( this.lightDistance );
  27897. */
  27898. return _this;
  27899. }
  27900. var _proto = PointLightHelper.prototype;
  27901. _proto.dispose = function dispose() {
  27902. this.geometry.dispose();
  27903. this.material.dispose();
  27904. };
  27905. _proto.update = function update() {
  27906. if (this.color !== undefined) {
  27907. this.material.color.set(this.color);
  27908. } else {
  27909. this.material.color.copy(this.light.color);
  27910. }
  27911. /*
  27912. const d = this.light.distance;
  27913. if ( d === 0.0 ) {
  27914. this.lightDistance.visible = false;
  27915. } else {
  27916. this.lightDistance.visible = true;
  27917. this.lightDistance.scale.set( d, d, d );
  27918. }
  27919. */
  27920. };
  27921. return PointLightHelper;
  27922. }(Mesh);
  27923. var _vector$a = /*@__PURE__*/new Vector3();
  27924. var _color1 = /*@__PURE__*/new Color();
  27925. var _color2 = /*@__PURE__*/new Color();
  27926. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27927. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27928. function HemisphereLightHelper(light, size, color) {
  27929. var _this;
  27930. _this = _Object3D.call(this) || this;
  27931. _this.light = light;
  27932. _this.light.updateMatrixWorld();
  27933. _this.matrix = light.matrixWorld;
  27934. _this.matrixAutoUpdate = false;
  27935. _this.color = color;
  27936. var geometry = new OctahedronBufferGeometry(size);
  27937. geometry.rotateY(Math.PI * 0.5);
  27938. _this.material = new MeshBasicMaterial({
  27939. wireframe: true,
  27940. fog: false,
  27941. toneMapped: false
  27942. });
  27943. if (_this.color === undefined) _this.material.vertexColors = true;
  27944. var position = geometry.getAttribute('position');
  27945. var colors = new Float32Array(position.count * 3);
  27946. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27947. _this.add(new Mesh(geometry, _this.material));
  27948. _this.update();
  27949. return _this;
  27950. }
  27951. var _proto = HemisphereLightHelper.prototype;
  27952. _proto.dispose = function dispose() {
  27953. this.children[0].geometry.dispose();
  27954. this.children[0].material.dispose();
  27955. };
  27956. _proto.update = function update() {
  27957. var mesh = this.children[0];
  27958. if (this.color !== undefined) {
  27959. this.material.color.set(this.color);
  27960. } else {
  27961. var colors = mesh.geometry.getAttribute('color');
  27962. _color1.copy(this.light.color);
  27963. _color2.copy(this.light.groundColor);
  27964. for (var i = 0, l = colors.count; i < l; i++) {
  27965. var color = i < l / 2 ? _color1 : _color2;
  27966. colors.setXYZ(i, color.r, color.g, color.b);
  27967. }
  27968. colors.needsUpdate = true;
  27969. }
  27970. mesh.lookAt(_vector$a.setFromMatrixPosition(this.light.matrixWorld).negate());
  27971. };
  27972. return HemisphereLightHelper;
  27973. }(Object3D);
  27974. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27975. _inheritsLoose(GridHelper, _LineSegments);
  27976. function GridHelper(size, divisions, color1, color2) {
  27977. var _this;
  27978. size = size || 10;
  27979. divisions = divisions || 10;
  27980. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  27981. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  27982. var center = divisions / 2;
  27983. var step = size / divisions;
  27984. var halfSize = size / 2;
  27985. var vertices = [],
  27986. colors = [];
  27987. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  27988. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  27989. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  27990. var color = i === center ? color1 : color2;
  27991. color.toArray(colors, j);
  27992. j += 3;
  27993. color.toArray(colors, j);
  27994. j += 3;
  27995. color.toArray(colors, j);
  27996. j += 3;
  27997. color.toArray(colors, j);
  27998. j += 3;
  27999. }
  28000. var geometry = new BufferGeometry();
  28001. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28002. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28003. var material = new LineBasicMaterial({
  28004. vertexColors: true,
  28005. toneMapped: false
  28006. });
  28007. _this = _LineSegments.call(this, geometry, material) || this;
  28008. _this.type = 'GridHelper';
  28009. return _this;
  28010. }
  28011. return GridHelper;
  28012. }(LineSegments);
  28013. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28014. _inheritsLoose(PolarGridHelper, _LineSegments);
  28015. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28016. var _this;
  28017. radius = radius || 10;
  28018. radials = radials || 16;
  28019. circles = circles || 8;
  28020. divisions = divisions || 64;
  28021. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  28022. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  28023. var vertices = [];
  28024. var colors = []; // create the radials
  28025. for (var i = 0; i <= radials; i++) {
  28026. var v = i / radials * (Math.PI * 2);
  28027. var x = Math.sin(v) * radius;
  28028. var z = Math.cos(v) * radius;
  28029. vertices.push(0, 0, 0);
  28030. vertices.push(x, 0, z);
  28031. var color = i & 1 ? color1 : color2;
  28032. colors.push(color.r, color.g, color.b);
  28033. colors.push(color.r, color.g, color.b);
  28034. } // create the circles
  28035. for (var _i = 0; _i <= circles; _i++) {
  28036. var _color = _i & 1 ? color1 : color2;
  28037. var r = radius - radius / circles * _i;
  28038. for (var j = 0; j < divisions; j++) {
  28039. // first vertex
  28040. var _v = j / divisions * (Math.PI * 2);
  28041. var _x = Math.sin(_v) * r;
  28042. var _z = Math.cos(_v) * r;
  28043. vertices.push(_x, 0, _z);
  28044. colors.push(_color.r, _color.g, _color.b); // second vertex
  28045. _v = (j + 1) / divisions * (Math.PI * 2);
  28046. _x = Math.sin(_v) * r;
  28047. _z = Math.cos(_v) * r;
  28048. vertices.push(_x, 0, _z);
  28049. colors.push(_color.r, _color.g, _color.b);
  28050. }
  28051. }
  28052. var geometry = new BufferGeometry();
  28053. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28054. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28055. var material = new LineBasicMaterial({
  28056. vertexColors: true,
  28057. toneMapped: false
  28058. });
  28059. _this = _LineSegments.call(this, geometry, material) || this;
  28060. _this.type = 'PolarGridHelper';
  28061. return _this;
  28062. }
  28063. return PolarGridHelper;
  28064. }(LineSegments);
  28065. var _v1$6 = /*@__PURE__*/new Vector3();
  28066. var _v2$3 = /*@__PURE__*/new Vector3();
  28067. var _v3$1 = /*@__PURE__*/new Vector3();
  28068. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28069. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28070. function DirectionalLightHelper(light, size, color) {
  28071. var _this;
  28072. _this = _Object3D.call(this) || this;
  28073. _this.light = light;
  28074. _this.light.updateMatrixWorld();
  28075. _this.matrix = light.matrixWorld;
  28076. _this.matrixAutoUpdate = false;
  28077. _this.color = color;
  28078. if (size === undefined) size = 1;
  28079. var geometry = new BufferGeometry();
  28080. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28081. var material = new LineBasicMaterial({
  28082. fog: false,
  28083. toneMapped: false
  28084. });
  28085. _this.lightPlane = new Line(geometry, material);
  28086. _this.add(_this.lightPlane);
  28087. geometry = new BufferGeometry();
  28088. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28089. _this.targetLine = new Line(geometry, material);
  28090. _this.add(_this.targetLine);
  28091. _this.update();
  28092. return _this;
  28093. }
  28094. var _proto = DirectionalLightHelper.prototype;
  28095. _proto.dispose = function dispose() {
  28096. this.lightPlane.geometry.dispose();
  28097. this.lightPlane.material.dispose();
  28098. this.targetLine.geometry.dispose();
  28099. this.targetLine.material.dispose();
  28100. };
  28101. _proto.update = function update() {
  28102. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28103. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28104. _v3$1.subVectors(_v2$3, _v1$6);
  28105. this.lightPlane.lookAt(_v2$3);
  28106. if (this.color !== undefined) {
  28107. this.lightPlane.material.color.set(this.color);
  28108. this.targetLine.material.color.set(this.color);
  28109. } else {
  28110. this.lightPlane.material.color.copy(this.light.color);
  28111. this.targetLine.material.color.copy(this.light.color);
  28112. }
  28113. this.targetLine.lookAt(_v2$3);
  28114. this.targetLine.scale.z = _v3$1.length();
  28115. };
  28116. return DirectionalLightHelper;
  28117. }(Object3D);
  28118. var _vector$b = /*@__PURE__*/new Vector3();
  28119. var _camera = /*@__PURE__*/new Camera();
  28120. /**
  28121. * - shows frustum, line of sight and up of the camera
  28122. * - suitable for fast updates
  28123. * - based on frustum visualization in lightgl.js shadowmap example
  28124. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28125. */
  28126. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28127. _inheritsLoose(CameraHelper, _LineSegments);
  28128. function CameraHelper(camera) {
  28129. var _this;
  28130. var geometry = new BufferGeometry();
  28131. var material = new LineBasicMaterial({
  28132. color: 0xffffff,
  28133. vertexColors: true,
  28134. toneMapped: false
  28135. });
  28136. var vertices = [];
  28137. var colors = [];
  28138. var pointMap = {}; // colors
  28139. var colorFrustum = new Color(0xffaa00);
  28140. var colorCone = new Color(0xff0000);
  28141. var colorUp = new Color(0x00aaff);
  28142. var colorTarget = new Color(0xffffff);
  28143. var colorCross = new Color(0x333333); // near
  28144. addLine('n1', 'n2', colorFrustum);
  28145. addLine('n2', 'n4', colorFrustum);
  28146. addLine('n4', 'n3', colorFrustum);
  28147. addLine('n3', 'n1', colorFrustum); // far
  28148. addLine('f1', 'f2', colorFrustum);
  28149. addLine('f2', 'f4', colorFrustum);
  28150. addLine('f4', 'f3', colorFrustum);
  28151. addLine('f3', 'f1', colorFrustum); // sides
  28152. addLine('n1', 'f1', colorFrustum);
  28153. addLine('n2', 'f2', colorFrustum);
  28154. addLine('n3', 'f3', colorFrustum);
  28155. addLine('n4', 'f4', colorFrustum); // cone
  28156. addLine('p', 'n1', colorCone);
  28157. addLine('p', 'n2', colorCone);
  28158. addLine('p', 'n3', colorCone);
  28159. addLine('p', 'n4', colorCone); // up
  28160. addLine('u1', 'u2', colorUp);
  28161. addLine('u2', 'u3', colorUp);
  28162. addLine('u3', 'u1', colorUp); // target
  28163. addLine('c', 't', colorTarget);
  28164. addLine('p', 'c', colorCross); // cross
  28165. addLine('cn1', 'cn2', colorCross);
  28166. addLine('cn3', 'cn4', colorCross);
  28167. addLine('cf1', 'cf2', colorCross);
  28168. addLine('cf3', 'cf4', colorCross);
  28169. function addLine(a, b, color) {
  28170. addPoint(a, color);
  28171. addPoint(b, color);
  28172. }
  28173. function addPoint(id, color) {
  28174. vertices.push(0, 0, 0);
  28175. colors.push(color.r, color.g, color.b);
  28176. if (pointMap[id] === undefined) {
  28177. pointMap[id] = [];
  28178. }
  28179. pointMap[id].push(vertices.length / 3 - 1);
  28180. }
  28181. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28182. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28183. _this = _LineSegments.call(this, geometry, material) || this;
  28184. _this.type = 'CameraHelper';
  28185. _this.camera = camera;
  28186. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28187. _this.matrix = camera.matrixWorld;
  28188. _this.matrixAutoUpdate = false;
  28189. _this.pointMap = pointMap;
  28190. _this.update();
  28191. return _this;
  28192. }
  28193. var _proto = CameraHelper.prototype;
  28194. _proto.update = function update() {
  28195. var geometry = this.geometry;
  28196. var pointMap = this.pointMap;
  28197. var w = 1,
  28198. h = 1; // we need just camera projection matrix inverse
  28199. // world matrix must be identity
  28200. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28201. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28202. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28203. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28204. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28205. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28206. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28207. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28208. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28209. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28210. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28211. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28212. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28213. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28214. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28215. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28216. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28217. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28218. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28219. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28220. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28221. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28222. geometry.getAttribute('position').needsUpdate = true;
  28223. };
  28224. return CameraHelper;
  28225. }(LineSegments);
  28226. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28227. _vector$b.set(x, y, z).unproject(camera);
  28228. var points = pointMap[point];
  28229. if (points !== undefined) {
  28230. var position = geometry.getAttribute('position');
  28231. for (var i = 0, l = points.length; i < l; i++) {
  28232. position.setXYZ(points[i], _vector$b.x, _vector$b.y, _vector$b.z);
  28233. }
  28234. }
  28235. }
  28236. var _box$3 = /*@__PURE__*/new Box3();
  28237. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28238. _inheritsLoose(BoxHelper, _LineSegments);
  28239. function BoxHelper(object, color) {
  28240. var _this;
  28241. if (color === void 0) {
  28242. color = 0xffff00;
  28243. }
  28244. 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]);
  28245. var positions = new Float32Array(8 * 3);
  28246. var geometry = new BufferGeometry();
  28247. geometry.setIndex(new BufferAttribute(indices, 1));
  28248. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28249. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28250. color: color,
  28251. toneMapped: false
  28252. })) || this;
  28253. _this.object = object;
  28254. _this.type = 'BoxHelper';
  28255. _this.matrixAutoUpdate = false;
  28256. _this.update();
  28257. return _this;
  28258. }
  28259. var _proto = BoxHelper.prototype;
  28260. _proto.update = function update(object) {
  28261. if (object !== undefined) {
  28262. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28263. }
  28264. if (this.object !== undefined) {
  28265. _box$3.setFromObject(this.object);
  28266. }
  28267. if (_box$3.isEmpty()) return;
  28268. var min = _box$3.min;
  28269. var max = _box$3.max;
  28270. /*
  28271. 5____4
  28272. 1/___0/|
  28273. | 6__|_7
  28274. 2/___3/
  28275. 0: max.x, max.y, max.z
  28276. 1: min.x, max.y, max.z
  28277. 2: min.x, min.y, max.z
  28278. 3: max.x, min.y, max.z
  28279. 4: max.x, max.y, min.z
  28280. 5: min.x, max.y, min.z
  28281. 6: min.x, min.y, min.z
  28282. 7: max.x, min.y, min.z
  28283. */
  28284. var position = this.geometry.attributes.position;
  28285. var array = position.array;
  28286. array[0] = max.x;
  28287. array[1] = max.y;
  28288. array[2] = max.z;
  28289. array[3] = min.x;
  28290. array[4] = max.y;
  28291. array[5] = max.z;
  28292. array[6] = min.x;
  28293. array[7] = min.y;
  28294. array[8] = max.z;
  28295. array[9] = max.x;
  28296. array[10] = min.y;
  28297. array[11] = max.z;
  28298. array[12] = max.x;
  28299. array[13] = max.y;
  28300. array[14] = min.z;
  28301. array[15] = min.x;
  28302. array[16] = max.y;
  28303. array[17] = min.z;
  28304. array[18] = min.x;
  28305. array[19] = min.y;
  28306. array[20] = min.z;
  28307. array[21] = max.x;
  28308. array[22] = min.y;
  28309. array[23] = min.z;
  28310. position.needsUpdate = true;
  28311. this.geometry.computeBoundingSphere();
  28312. };
  28313. _proto.setFromObject = function setFromObject(object) {
  28314. this.object = object;
  28315. this.update();
  28316. return this;
  28317. };
  28318. _proto.copy = function copy(source) {
  28319. LineSegments.prototype.copy.call(this, source);
  28320. this.object = source.object;
  28321. return this;
  28322. };
  28323. return BoxHelper;
  28324. }(LineSegments);
  28325. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28326. _inheritsLoose(Box3Helper, _LineSegments);
  28327. function Box3Helper(box, color) {
  28328. var _this;
  28329. if (color === void 0) {
  28330. color = 0xffff00;
  28331. }
  28332. 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]);
  28333. 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];
  28334. var geometry = new BufferGeometry();
  28335. geometry.setIndex(new BufferAttribute(indices, 1));
  28336. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28337. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28338. color: color,
  28339. toneMapped: false
  28340. })) || this;
  28341. _this.box = box;
  28342. _this.type = 'Box3Helper';
  28343. _this.geometry.computeBoundingSphere();
  28344. return _this;
  28345. }
  28346. var _proto = Box3Helper.prototype;
  28347. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28348. var box = this.box;
  28349. if (box.isEmpty()) return;
  28350. box.getCenter(this.position);
  28351. box.getSize(this.scale);
  28352. this.scale.multiplyScalar(0.5);
  28353. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28354. };
  28355. return Box3Helper;
  28356. }(LineSegments);
  28357. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28358. _inheritsLoose(PlaneHelper, _Line);
  28359. function PlaneHelper(plane, size, hex) {
  28360. var _this;
  28361. if (size === void 0) {
  28362. size = 1;
  28363. }
  28364. if (hex === void 0) {
  28365. hex = 0xffff00;
  28366. }
  28367. var color = hex;
  28368. 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];
  28369. var geometry = new BufferGeometry();
  28370. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28371. geometry.computeBoundingSphere();
  28372. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28373. color: color,
  28374. toneMapped: false
  28375. })) || this;
  28376. _this.type = 'PlaneHelper';
  28377. _this.plane = plane;
  28378. _this.size = size;
  28379. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28380. var geometry2 = new BufferGeometry();
  28381. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28382. geometry2.computeBoundingSphere();
  28383. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28384. color: color,
  28385. opacity: 0.2,
  28386. transparent: true,
  28387. depthWrite: false,
  28388. toneMapped: false
  28389. })));
  28390. return _this;
  28391. }
  28392. var _proto = PlaneHelper.prototype;
  28393. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28394. var scale = -this.plane.constant;
  28395. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28396. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28397. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28398. this.lookAt(this.plane.normal);
  28399. _Line.prototype.updateMatrixWorld.call(this, force);
  28400. };
  28401. return PlaneHelper;
  28402. }(Line);
  28403. var _axis = /*@__PURE__*/new Vector3();
  28404. var _lineGeometry, _coneGeometry;
  28405. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28406. _inheritsLoose(ArrowHelper, _Object3D);
  28407. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28408. var _this;
  28409. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28410. _this.type = 'ArrowHelper';
  28411. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28412. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28413. if (length === undefined) length = 1;
  28414. if (color === undefined) color = 0xffff00;
  28415. if (headLength === undefined) headLength = 0.2 * length;
  28416. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28417. if (_lineGeometry === undefined) {
  28418. _lineGeometry = new BufferGeometry();
  28419. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28420. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28421. _coneGeometry.translate(0, -0.5, 0);
  28422. }
  28423. _this.position.copy(origin);
  28424. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28425. color: color,
  28426. toneMapped: false
  28427. }));
  28428. _this.line.matrixAutoUpdate = false;
  28429. _this.add(_this.line);
  28430. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28431. color: color,
  28432. toneMapped: false
  28433. }));
  28434. _this.cone.matrixAutoUpdate = false;
  28435. _this.add(_this.cone);
  28436. _this.setDirection(dir);
  28437. _this.setLength(length, headLength, headWidth);
  28438. return _this;
  28439. }
  28440. var _proto = ArrowHelper.prototype;
  28441. _proto.setDirection = function setDirection(dir) {
  28442. // dir is assumed to be normalized
  28443. if (dir.y > 0.99999) {
  28444. this.quaternion.set(0, 0, 0, 1);
  28445. } else if (dir.y < -0.99999) {
  28446. this.quaternion.set(1, 0, 0, 0);
  28447. } else {
  28448. _axis.set(dir.z, 0, -dir.x).normalize();
  28449. var radians = Math.acos(dir.y);
  28450. this.quaternion.setFromAxisAngle(_axis, radians);
  28451. }
  28452. };
  28453. _proto.setLength = function setLength(length, headLength, headWidth) {
  28454. if (headLength === undefined) headLength = 0.2 * length;
  28455. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28456. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28457. this.line.updateMatrix();
  28458. this.cone.scale.set(headWidth, headLength, headWidth);
  28459. this.cone.position.y = length;
  28460. this.cone.updateMatrix();
  28461. };
  28462. _proto.setColor = function setColor(color) {
  28463. this.line.material.color.set(color);
  28464. this.cone.material.color.set(color);
  28465. };
  28466. _proto.copy = function copy(source) {
  28467. _Object3D.prototype.copy.call(this, source, false);
  28468. this.line.copy(source.line);
  28469. this.cone.copy(source.cone);
  28470. return this;
  28471. };
  28472. return ArrowHelper;
  28473. }(Object3D);
  28474. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28475. _inheritsLoose(AxesHelper, _LineSegments);
  28476. function AxesHelper(size) {
  28477. var _this;
  28478. if (size === void 0) {
  28479. size = 1;
  28480. }
  28481. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28482. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28483. var geometry = new BufferGeometry();
  28484. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28485. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28486. var material = new LineBasicMaterial({
  28487. vertexColors: true,
  28488. toneMapped: false
  28489. });
  28490. _this = _LineSegments.call(this, geometry, material) || this;
  28491. _this.type = 'AxesHelper';
  28492. return _this;
  28493. }
  28494. return AxesHelper;
  28495. }(LineSegments);
  28496. var _floatView = new Float32Array(1);
  28497. var _int32View = new Int32Array(_floatView.buffer);
  28498. var DataUtils = {
  28499. // Converts float32 to float16 (stored as uint16 value).
  28500. toHalfFloat: function toHalfFloat(val) {
  28501. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28502. /* This method is faster than the OpenEXR implementation (very often
  28503. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28504. * by James Tursa?s half-precision code. */
  28505. _floatView[0] = val;
  28506. var x = _int32View[0];
  28507. var bits = x >> 16 & 0x8000;
  28508. /* Get the sign */
  28509. var m = x >> 12 & 0x07ff;
  28510. /* Keep one extra bit for rounding */
  28511. var e = x >> 23 & 0xff;
  28512. /* Using int is faster here */
  28513. /* If zero, or denormal, or exponent underflows too much for a denormal
  28514. * half, return signed zero. */
  28515. if (e < 103) return bits;
  28516. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28517. if (e > 142) {
  28518. bits |= 0x7c00;
  28519. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28520. * not Inf, so make sure we set one mantissa bit too. */
  28521. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28522. return bits;
  28523. }
  28524. /* If exponent underflows but not too much, return a denormal */
  28525. if (e < 113) {
  28526. m |= 0x0800;
  28527. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28528. * to 1, which is OK. */
  28529. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28530. return bits;
  28531. }
  28532. bits |= e - 112 << 10 | m >> 1;
  28533. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28534. * the exponent, which is OK. */
  28535. bits += m & 1;
  28536. return bits;
  28537. }
  28538. };
  28539. var _ENCODINGS;
  28540. var LOD_MIN = 4;
  28541. var LOD_MAX = 8;
  28542. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28543. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28544. // geometric shadowing function. These sigma values squared must match the
  28545. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28546. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28547. 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
  28548. // samples and exit early, but not recompile the shader.
  28549. var MAX_SAMPLES = 20;
  28550. 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);
  28551. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28552. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28553. _lodPlanes = _createPlanes2._lodPlanes,
  28554. _sizeLods = _createPlanes2._sizeLods,
  28555. _sigmas = _createPlanes2._sigmas;
  28556. var _oldTarget = null; // Golden Ratio
  28557. var PHI = (1 + Math.sqrt(5)) / 2;
  28558. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28559. // same axis), used as axis directions evenly spread on a sphere.
  28560. 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)];
  28561. /**
  28562. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28563. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28564. * blur to be quickly accessed based on material roughness. It is packed into a
  28565. * special CubeUV format that allows us to perform custom interpolation so that
  28566. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28567. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28568. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28569. * higher roughness levels. In this way we maintain resolution to smoothly
  28570. * interpolate diffuse lighting while limiting sampling computation.
  28571. */
  28572. var PMREMGenerator = /*#__PURE__*/function () {
  28573. function PMREMGenerator(renderer) {
  28574. this._renderer = renderer;
  28575. this._pingPongRenderTarget = null;
  28576. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28577. this._equirectShader = null;
  28578. this._cubemapShader = null;
  28579. this._compileMaterial(this._blurMaterial);
  28580. }
  28581. /**
  28582. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28583. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28584. * in radians to be applied to the scene before PMREM generation. Optional near
  28585. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28586. * is placed at the origin).
  28587. */
  28588. var _proto = PMREMGenerator.prototype;
  28589. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28590. if (sigma === void 0) {
  28591. sigma = 0;
  28592. }
  28593. if (near === void 0) {
  28594. near = 0.1;
  28595. }
  28596. if (far === void 0) {
  28597. far = 100;
  28598. }
  28599. _oldTarget = this._renderer.getRenderTarget();
  28600. var cubeUVRenderTarget = this._allocateTargets();
  28601. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28602. if (sigma > 0) {
  28603. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28604. }
  28605. this._applyPMREM(cubeUVRenderTarget);
  28606. this._cleanup(cubeUVRenderTarget);
  28607. return cubeUVRenderTarget;
  28608. }
  28609. /**
  28610. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28611. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28612. * as this matches best with the 256 x 256 cubemap output.
  28613. */
  28614. ;
  28615. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28616. return this._fromTexture(equirectangular);
  28617. }
  28618. /**
  28619. * Generates a PMREM from an cubemap texture, which can be either LDR
  28620. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28621. * as this matches best with the 256 x 256 cubemap output.
  28622. */
  28623. ;
  28624. _proto.fromCubemap = function fromCubemap(cubemap) {
  28625. return this._fromTexture(cubemap);
  28626. }
  28627. /**
  28628. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28629. * your texture's network fetch for increased concurrency.
  28630. */
  28631. ;
  28632. _proto.compileCubemapShader = function compileCubemapShader() {
  28633. if (this._cubemapShader === null) {
  28634. this._cubemapShader = _getCubemapShader();
  28635. this._compileMaterial(this._cubemapShader);
  28636. }
  28637. }
  28638. /**
  28639. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28640. * your texture's network fetch for increased concurrency.
  28641. */
  28642. ;
  28643. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28644. if (this._equirectShader === null) {
  28645. this._equirectShader = _getEquirectShader();
  28646. this._compileMaterial(this._equirectShader);
  28647. }
  28648. }
  28649. /**
  28650. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28651. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28652. * one of them will cause any others to also become unusable.
  28653. */
  28654. ;
  28655. _proto.dispose = function dispose() {
  28656. this._blurMaterial.dispose();
  28657. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28658. if (this._equirectShader !== null) this._equirectShader.dispose();
  28659. for (var i = 0; i < _lodPlanes.length; i++) {
  28660. _lodPlanes[i].dispose();
  28661. }
  28662. } // private interface
  28663. ;
  28664. _proto._cleanup = function _cleanup(outputTarget) {
  28665. this._pingPongRenderTarget.dispose();
  28666. this._renderer.setRenderTarget(_oldTarget);
  28667. outputTarget.scissorTest = false;
  28668. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28669. };
  28670. _proto._fromTexture = function _fromTexture(texture) {
  28671. _oldTarget = this._renderer.getRenderTarget();
  28672. var cubeUVRenderTarget = this._allocateTargets(texture);
  28673. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28674. this._applyPMREM(cubeUVRenderTarget);
  28675. this._cleanup(cubeUVRenderTarget);
  28676. return cubeUVRenderTarget;
  28677. };
  28678. _proto._allocateTargets = function _allocateTargets(texture) {
  28679. // warning: null texture is valid
  28680. var params = {
  28681. magFilter: NearestFilter,
  28682. minFilter: NearestFilter,
  28683. generateMipmaps: false,
  28684. type: UnsignedByteType,
  28685. format: RGBEFormat,
  28686. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28687. depthBuffer: false
  28688. };
  28689. var cubeUVRenderTarget = _createRenderTarget(params);
  28690. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28691. this._pingPongRenderTarget = _createRenderTarget(params);
  28692. return cubeUVRenderTarget;
  28693. };
  28694. _proto._compileMaterial = function _compileMaterial(material) {
  28695. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28696. this._renderer.compile(tmpMesh, _flatCamera);
  28697. };
  28698. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28699. var fov = 90;
  28700. var aspect = 1;
  28701. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28702. var upSign = [1, -1, 1, 1, 1, 1];
  28703. var forwardSign = [1, 1, 1, -1, -1, -1];
  28704. var renderer = this._renderer;
  28705. var outputEncoding = renderer.outputEncoding;
  28706. var toneMapping = renderer.toneMapping;
  28707. var clearColor = renderer.getClearColor();
  28708. var clearAlpha = renderer.getClearAlpha();
  28709. renderer.toneMapping = NoToneMapping;
  28710. renderer.outputEncoding = LinearEncoding;
  28711. var background = scene.background;
  28712. if (background && background.isColor) {
  28713. background.convertSRGBToLinear(); // Convert linear to RGBE
  28714. var maxComponent = Math.max(background.r, background.g, background.b);
  28715. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28716. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  28717. var alpha = (fExp + 128.0) / 255.0;
  28718. renderer.setClearColor(background, alpha);
  28719. scene.background = null;
  28720. }
  28721. for (var i = 0; i < 6; i++) {
  28722. var col = i % 3;
  28723. if (col == 0) {
  28724. cubeCamera.up.set(0, upSign[i], 0);
  28725. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28726. } else if (col == 1) {
  28727. cubeCamera.up.set(0, 0, upSign[i]);
  28728. cubeCamera.lookAt(0, forwardSign[i], 0);
  28729. } else {
  28730. cubeCamera.up.set(0, upSign[i], 0);
  28731. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28732. }
  28733. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28734. renderer.setRenderTarget(cubeUVRenderTarget);
  28735. renderer.render(scene, cubeCamera);
  28736. }
  28737. renderer.toneMapping = toneMapping;
  28738. renderer.outputEncoding = outputEncoding;
  28739. renderer.setClearColor(clearColor, clearAlpha);
  28740. };
  28741. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28742. var renderer = this._renderer;
  28743. if (texture.isCubeTexture) {
  28744. if (this._cubemapShader == null) {
  28745. this._cubemapShader = _getCubemapShader();
  28746. }
  28747. } else {
  28748. if (this._equirectShader == null) {
  28749. this._equirectShader = _getEquirectShader();
  28750. }
  28751. }
  28752. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28753. var mesh = new Mesh(_lodPlanes[0], material);
  28754. var uniforms = material.uniforms;
  28755. uniforms['envMap'].value = texture;
  28756. if (!texture.isCubeTexture) {
  28757. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28758. }
  28759. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28760. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28761. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28762. renderer.setRenderTarget(cubeUVRenderTarget);
  28763. renderer.render(mesh, _flatCamera);
  28764. };
  28765. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28766. var renderer = this._renderer;
  28767. var autoClear = renderer.autoClear;
  28768. renderer.autoClear = false;
  28769. for (var i = 1; i < TOTAL_LODS; i++) {
  28770. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28771. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28772. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28773. }
  28774. renderer.autoClear = autoClear;
  28775. }
  28776. /**
  28777. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28778. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28779. * the blur latitudinally (around the poles), and then longitudinally (towards
  28780. * the poles) to approximate the orthogonally-separable blur. It is least
  28781. * accurate at the poles, but still does a decent job.
  28782. */
  28783. ;
  28784. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28785. var pingPongRenderTarget = this._pingPongRenderTarget;
  28786. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28787. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28788. };
  28789. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28790. var renderer = this._renderer;
  28791. var blurMaterial = this._blurMaterial;
  28792. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28793. console.error('blur direction must be either latitudinal or longitudinal!');
  28794. } // Number of standard deviations at which to cut off the discrete approximation.
  28795. var STANDARD_DEVIATIONS = 3;
  28796. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28797. var blurUniforms = blurMaterial.uniforms;
  28798. var pixels = _sizeLods[lodIn] - 1;
  28799. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28800. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28801. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28802. if (samples > MAX_SAMPLES) {
  28803. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28804. }
  28805. var weights = [];
  28806. var sum = 0;
  28807. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28808. var _x = i / sigmaPixels;
  28809. var weight = Math.exp(-_x * _x / 2);
  28810. weights.push(weight);
  28811. if (i == 0) {
  28812. sum += weight;
  28813. } else if (i < samples) {
  28814. sum += 2 * weight;
  28815. }
  28816. }
  28817. for (var _i = 0; _i < weights.length; _i++) {
  28818. weights[_i] = weights[_i] / sum;
  28819. }
  28820. blurUniforms['envMap'].value = targetIn.texture;
  28821. blurUniforms['samples'].value = samples;
  28822. blurUniforms['weights'].value = weights;
  28823. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28824. if (poleAxis) {
  28825. blurUniforms['poleAxis'].value = poleAxis;
  28826. }
  28827. blurUniforms['dTheta'].value = radiansPerPixel;
  28828. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28829. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28830. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28831. var outputSize = _sizeLods[lodOut];
  28832. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28833. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28834. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28835. renderer.setRenderTarget(targetOut);
  28836. renderer.render(blurMesh, _flatCamera);
  28837. };
  28838. return PMREMGenerator;
  28839. }();
  28840. function _isLDR(texture) {
  28841. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28842. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28843. }
  28844. function _createPlanes() {
  28845. var _lodPlanes = [];
  28846. var _sizeLods = [];
  28847. var _sigmas = [];
  28848. var lod = LOD_MAX;
  28849. for (var i = 0; i < TOTAL_LODS; i++) {
  28850. var sizeLod = Math.pow(2, lod);
  28851. _sizeLods.push(sizeLod);
  28852. var sigma = 1.0 / sizeLod;
  28853. if (i > LOD_MAX - LOD_MIN) {
  28854. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28855. } else if (i == 0) {
  28856. sigma = 0;
  28857. }
  28858. _sigmas.push(sigma);
  28859. var texelSize = 1.0 / (sizeLod - 1);
  28860. var min = -texelSize / 2;
  28861. var max = 1 + texelSize / 2;
  28862. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28863. var cubeFaces = 6;
  28864. var vertices = 6;
  28865. var positionSize = 3;
  28866. var uvSize = 2;
  28867. var faceIndexSize = 1;
  28868. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28869. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28870. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28871. for (var face = 0; face < cubeFaces; face++) {
  28872. var x = face % 3 * 2 / 3 - 1;
  28873. var y = face > 2 ? 0 : -1;
  28874. 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];
  28875. position.set(coordinates, positionSize * vertices * face);
  28876. uv.set(uv1, uvSize * vertices * face);
  28877. var fill = [face, face, face, face, face, face];
  28878. faceIndex.set(fill, faceIndexSize * vertices * face);
  28879. }
  28880. var planes = new BufferGeometry();
  28881. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28882. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28883. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28884. _lodPlanes.push(planes);
  28885. if (lod > LOD_MIN) {
  28886. lod--;
  28887. }
  28888. }
  28889. return {
  28890. _lodPlanes: _lodPlanes,
  28891. _sizeLods: _sizeLods,
  28892. _sigmas: _sigmas
  28893. };
  28894. }
  28895. function _createRenderTarget(params) {
  28896. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28897. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28898. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28899. cubeUVRenderTarget.scissorTest = true;
  28900. return cubeUVRenderTarget;
  28901. }
  28902. function _setViewport(target, x, y, width, height) {
  28903. target.viewport.set(x, y, width, height);
  28904. target.scissor.set(x, y, width, height);
  28905. }
  28906. function _getBlurShader(maxSamples) {
  28907. var weights = new Float32Array(maxSamples);
  28908. var poleAxis = new Vector3(0, 1, 0);
  28909. var shaderMaterial = new RawShaderMaterial({
  28910. name: 'SphericalGaussianBlur',
  28911. defines: {
  28912. 'n': maxSamples
  28913. },
  28914. uniforms: {
  28915. 'envMap': {
  28916. value: null
  28917. },
  28918. 'samples': {
  28919. value: 1
  28920. },
  28921. 'weights': {
  28922. value: weights
  28923. },
  28924. 'latitudinal': {
  28925. value: false
  28926. },
  28927. 'dTheta': {
  28928. value: 0
  28929. },
  28930. 'mipInt': {
  28931. value: 0
  28932. },
  28933. 'poleAxis': {
  28934. value: poleAxis
  28935. },
  28936. 'inputEncoding': {
  28937. value: ENCODINGS[LinearEncoding]
  28938. },
  28939. 'outputEncoding': {
  28940. value: ENCODINGS[LinearEncoding]
  28941. }
  28942. },
  28943. vertexShader: _getCommonVertexShader(),
  28944. fragmentShader:
  28945. /* glsl */
  28946. "\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",
  28947. blending: NoBlending,
  28948. depthTest: false,
  28949. depthWrite: false
  28950. });
  28951. return shaderMaterial;
  28952. }
  28953. function _getEquirectShader() {
  28954. var texelSize = new Vector2(1, 1);
  28955. var shaderMaterial = new RawShaderMaterial({
  28956. name: 'EquirectangularToCubeUV',
  28957. uniforms: {
  28958. 'envMap': {
  28959. value: null
  28960. },
  28961. 'texelSize': {
  28962. value: texelSize
  28963. },
  28964. 'inputEncoding': {
  28965. value: ENCODINGS[LinearEncoding]
  28966. },
  28967. 'outputEncoding': {
  28968. value: ENCODINGS[LinearEncoding]
  28969. }
  28970. },
  28971. vertexShader: _getCommonVertexShader(),
  28972. fragmentShader:
  28973. /* glsl */
  28974. "\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",
  28975. blending: NoBlending,
  28976. depthTest: false,
  28977. depthWrite: false
  28978. });
  28979. return shaderMaterial;
  28980. }
  28981. function _getCubemapShader() {
  28982. var shaderMaterial = new RawShaderMaterial({
  28983. name: 'CubemapToCubeUV',
  28984. uniforms: {
  28985. 'envMap': {
  28986. value: null
  28987. },
  28988. 'inputEncoding': {
  28989. value: ENCODINGS[LinearEncoding]
  28990. },
  28991. 'outputEncoding': {
  28992. value: ENCODINGS[LinearEncoding]
  28993. }
  28994. },
  28995. vertexShader: _getCommonVertexShader(),
  28996. fragmentShader:
  28997. /* glsl */
  28998. "\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",
  28999. blending: NoBlending,
  29000. depthTest: false,
  29001. depthWrite: false
  29002. });
  29003. return shaderMaterial;
  29004. }
  29005. function _getCommonVertexShader() {
  29006. return (
  29007. /* glsl */
  29008. "\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"
  29009. );
  29010. }
  29011. function _getEncodings() {
  29012. return (
  29013. /* glsl */
  29014. "\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"
  29015. );
  29016. }
  29017. function Face4(a, b, c, d, normal, color, materialIndex) {
  29018. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  29019. return new Face3(a, b, c, normal, color, materialIndex);
  29020. }
  29021. var LineStrip = 0;
  29022. var LinePieces = 1;
  29023. var NoColors = 0;
  29024. var FaceColors = 1;
  29025. var VertexColors = 2;
  29026. function MeshFaceMaterial(materials) {
  29027. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29028. return materials;
  29029. }
  29030. function MultiMaterial(materials) {
  29031. if (materials === void 0) {
  29032. materials = [];
  29033. }
  29034. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29035. materials.isMultiMaterial = true;
  29036. materials.materials = materials;
  29037. materials.clone = function () {
  29038. return materials.slice();
  29039. };
  29040. return materials;
  29041. }
  29042. function PointCloud(geometry, material) {
  29043. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29044. return new Points(geometry, material);
  29045. }
  29046. function Particle(material) {
  29047. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29048. return new Sprite(material);
  29049. }
  29050. function ParticleSystem(geometry, material) {
  29051. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29052. return new Points(geometry, material);
  29053. }
  29054. function PointCloudMaterial(parameters) {
  29055. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29056. return new PointsMaterial(parameters);
  29057. }
  29058. function ParticleBasicMaterial(parameters) {
  29059. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29060. return new PointsMaterial(parameters);
  29061. }
  29062. function ParticleSystemMaterial(parameters) {
  29063. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29064. return new PointsMaterial(parameters);
  29065. }
  29066. function Vertex(x, y, z) {
  29067. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29068. return new Vector3(x, y, z);
  29069. } //
  29070. function DynamicBufferAttribute(array, itemSize) {
  29071. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29072. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29073. }
  29074. function Int8Attribute(array, itemSize) {
  29075. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29076. return new Int8BufferAttribute(array, itemSize);
  29077. }
  29078. function Uint8Attribute(array, itemSize) {
  29079. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29080. return new Uint8BufferAttribute(array, itemSize);
  29081. }
  29082. function Uint8ClampedAttribute(array, itemSize) {
  29083. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29084. return new Uint8ClampedBufferAttribute(array, itemSize);
  29085. }
  29086. function Int16Attribute(array, itemSize) {
  29087. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29088. return new Int16BufferAttribute(array, itemSize);
  29089. }
  29090. function Uint16Attribute(array, itemSize) {
  29091. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29092. return new Uint16BufferAttribute(array, itemSize);
  29093. }
  29094. function Int32Attribute(array, itemSize) {
  29095. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29096. return new Int32BufferAttribute(array, itemSize);
  29097. }
  29098. function Uint32Attribute(array, itemSize) {
  29099. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29100. return new Uint32BufferAttribute(array, itemSize);
  29101. }
  29102. function Float32Attribute(array, itemSize) {
  29103. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29104. return new Float32BufferAttribute(array, itemSize);
  29105. }
  29106. function Float64Attribute(array, itemSize) {
  29107. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29108. return new Float64BufferAttribute(array, itemSize);
  29109. } //
  29110. Curve.create = function (construct, getPoint) {
  29111. console.log('THREE.Curve.create() has been deprecated');
  29112. construct.prototype = Object.create(Curve.prototype);
  29113. construct.prototype.constructor = construct;
  29114. construct.prototype.getPoint = getPoint;
  29115. return construct;
  29116. }; //
  29117. Object.assign(CurvePath.prototype, {
  29118. createPointsGeometry: function createPointsGeometry(divisions) {
  29119. console.warn('THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from path points (for Line or Points objects)
  29120. var pts = this.getPoints(divisions);
  29121. return this.createGeometry(pts);
  29122. },
  29123. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  29124. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  29125. var pts = this.getSpacedPoints(divisions);
  29126. return this.createGeometry(pts);
  29127. },
  29128. createGeometry: function createGeometry(points) {
  29129. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  29130. var geometry = new Geometry();
  29131. for (var i = 0, l = points.length; i < l; i++) {
  29132. var point = points[i];
  29133. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  29134. }
  29135. return geometry;
  29136. }
  29137. }); //
  29138. Object.assign(Path.prototype, {
  29139. fromPoints: function fromPoints(points) {
  29140. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29141. return this.setFromPoints(points);
  29142. }
  29143. }); //
  29144. function ClosedSplineCurve3(points) {
  29145. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29146. CatmullRomCurve3.call(this, points);
  29147. this.type = 'catmullrom';
  29148. this.closed = true;
  29149. }
  29150. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29151. function SplineCurve3(points) {
  29152. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29153. CatmullRomCurve3.call(this, points);
  29154. this.type = 'catmullrom';
  29155. }
  29156. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29157. function Spline(points) {
  29158. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29159. CatmullRomCurve3.call(this, points);
  29160. this.type = 'catmullrom';
  29161. }
  29162. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29163. Object.assign(Spline.prototype, {
  29164. initFromArray: function initFromArray()
  29165. /* a */
  29166. {
  29167. console.error('THREE.Spline: .initFromArray() has been removed.');
  29168. },
  29169. getControlPointsArray: function getControlPointsArray()
  29170. /* optionalTarget */
  29171. {
  29172. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29173. },
  29174. reparametrizeByArcLength: function reparametrizeByArcLength()
  29175. /* samplingCoef */
  29176. {
  29177. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29178. }
  29179. }); //
  29180. function AxisHelper(size) {
  29181. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29182. return new AxesHelper(size);
  29183. }
  29184. function BoundingBoxHelper(object, color) {
  29185. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29186. return new BoxHelper(object, color);
  29187. }
  29188. function EdgesHelper(object, hex) {
  29189. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29190. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29191. color: hex !== undefined ? hex : 0xffffff
  29192. }));
  29193. }
  29194. GridHelper.prototype.setColors = function () {
  29195. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29196. };
  29197. SkeletonHelper.prototype.update = function () {
  29198. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29199. };
  29200. function WireframeHelper(object, hex) {
  29201. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29202. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29203. color: hex !== undefined ? hex : 0xffffff
  29204. }));
  29205. } //
  29206. Object.assign(Loader.prototype, {
  29207. extractUrlBase: function extractUrlBase(url) {
  29208. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29209. return LoaderUtils.extractUrlBase(url);
  29210. }
  29211. });
  29212. Loader.Handlers = {
  29213. add: function add()
  29214. /* regex, loader */
  29215. {
  29216. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29217. },
  29218. get: function get()
  29219. /* file */
  29220. {
  29221. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29222. }
  29223. };
  29224. function XHRLoader(manager) {
  29225. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29226. return new FileLoader(manager);
  29227. }
  29228. function BinaryTextureLoader(manager) {
  29229. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29230. return new DataTextureLoader(manager);
  29231. } //
  29232. Object.assign(Box2.prototype, {
  29233. center: function center(optionalTarget) {
  29234. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29235. return this.getCenter(optionalTarget);
  29236. },
  29237. empty: function empty() {
  29238. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29239. return this.isEmpty();
  29240. },
  29241. isIntersectionBox: function isIntersectionBox(box) {
  29242. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29243. return this.intersectsBox(box);
  29244. },
  29245. size: function size(optionalTarget) {
  29246. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29247. return this.getSize(optionalTarget);
  29248. }
  29249. });
  29250. Object.assign(Box3.prototype, {
  29251. center: function center(optionalTarget) {
  29252. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29253. return this.getCenter(optionalTarget);
  29254. },
  29255. empty: function empty() {
  29256. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29257. return this.isEmpty();
  29258. },
  29259. isIntersectionBox: function isIntersectionBox(box) {
  29260. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29261. return this.intersectsBox(box);
  29262. },
  29263. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29264. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29265. return this.intersectsSphere(sphere);
  29266. },
  29267. size: function size(optionalTarget) {
  29268. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29269. return this.getSize(optionalTarget);
  29270. }
  29271. });
  29272. Object.assign(Sphere.prototype, {
  29273. empty: function empty() {
  29274. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29275. return this.isEmpty();
  29276. }
  29277. });
  29278. Frustum.prototype.setFromMatrix = function (m) {
  29279. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29280. return this.setFromProjectionMatrix(m);
  29281. };
  29282. Line3.prototype.center = function (optionalTarget) {
  29283. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29284. return this.getCenter(optionalTarget);
  29285. };
  29286. Object.assign(MathUtils, {
  29287. random16: function random16() {
  29288. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29289. return Math.random();
  29290. },
  29291. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29292. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29293. return MathUtils.floorPowerOfTwo(value);
  29294. },
  29295. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29296. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29297. return MathUtils.ceilPowerOfTwo(value);
  29298. }
  29299. });
  29300. Object.assign(Matrix3.prototype, {
  29301. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29302. console.warn("THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29303. return this.toArray(array, offset);
  29304. },
  29305. multiplyVector3: function multiplyVector3(vector) {
  29306. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29307. return vector.applyMatrix3(this);
  29308. },
  29309. multiplyVector3Array: function multiplyVector3Array()
  29310. /* a */
  29311. {
  29312. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29313. },
  29314. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29315. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29316. return attribute.applyMatrix3(this);
  29317. },
  29318. applyToVector3Array: function applyToVector3Array()
  29319. /* array, offset, length */
  29320. {
  29321. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29322. },
  29323. getInverse: function getInverse(matrix) {
  29324. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29325. return this.copy(matrix).invert();
  29326. }
  29327. });
  29328. Object.assign(Matrix4.prototype, {
  29329. extractPosition: function extractPosition(m) {
  29330. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29331. return this.copyPosition(m);
  29332. },
  29333. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29334. console.warn("THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29335. return this.toArray(array, offset);
  29336. },
  29337. getPosition: function getPosition() {
  29338. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29339. return new Vector3().setFromMatrixColumn(this, 3);
  29340. },
  29341. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29342. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29343. return this.makeRotationFromQuaternion(q);
  29344. },
  29345. multiplyToArray: function multiplyToArray() {
  29346. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29347. },
  29348. multiplyVector3: function multiplyVector3(vector) {
  29349. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29350. return vector.applyMatrix4(this);
  29351. },
  29352. multiplyVector4: function multiplyVector4(vector) {
  29353. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29354. return vector.applyMatrix4(this);
  29355. },
  29356. multiplyVector3Array: function multiplyVector3Array()
  29357. /* a */
  29358. {
  29359. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29360. },
  29361. rotateAxis: function rotateAxis(v) {
  29362. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29363. v.transformDirection(this);
  29364. },
  29365. crossVector: function crossVector(vector) {
  29366. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29367. return vector.applyMatrix4(this);
  29368. },
  29369. translate: function translate() {
  29370. console.error('THREE.Matrix4: .translate() has been removed.');
  29371. },
  29372. rotateX: function rotateX() {
  29373. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29374. },
  29375. rotateY: function rotateY() {
  29376. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29377. },
  29378. rotateZ: function rotateZ() {
  29379. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29380. },
  29381. rotateByAxis: function rotateByAxis() {
  29382. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29383. },
  29384. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29385. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29386. return attribute.applyMatrix4(this);
  29387. },
  29388. applyToVector3Array: function applyToVector3Array()
  29389. /* array, offset, length */
  29390. {
  29391. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29392. },
  29393. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29394. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29395. return this.makePerspective(left, right, top, bottom, near, far);
  29396. },
  29397. getInverse: function getInverse(matrix) {
  29398. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29399. return this.copy(matrix).invert();
  29400. }
  29401. });
  29402. Plane.prototype.isIntersectionLine = function (line) {
  29403. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29404. return this.intersectsLine(line);
  29405. };
  29406. Object.assign(Quaternion.prototype, {
  29407. multiplyVector3: function multiplyVector3(vector) {
  29408. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29409. return vector.applyQuaternion(this);
  29410. },
  29411. inverse: function inverse() {
  29412. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29413. return this.invert();
  29414. }
  29415. });
  29416. Object.assign(Ray.prototype, {
  29417. isIntersectionBox: function isIntersectionBox(box) {
  29418. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29419. return this.intersectsBox(box);
  29420. },
  29421. isIntersectionPlane: function isIntersectionPlane(plane) {
  29422. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29423. return this.intersectsPlane(plane);
  29424. },
  29425. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29426. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29427. return this.intersectsSphere(sphere);
  29428. }
  29429. });
  29430. Object.assign(Triangle.prototype, {
  29431. area: function area() {
  29432. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29433. return this.getArea();
  29434. },
  29435. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29436. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29437. return this.getBarycoord(point, target);
  29438. },
  29439. midpoint: function midpoint(target) {
  29440. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29441. return this.getMidpoint(target);
  29442. },
  29443. normal: function normal(target) {
  29444. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29445. return this.getNormal(target);
  29446. },
  29447. plane: function plane(target) {
  29448. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29449. return this.getPlane(target);
  29450. }
  29451. });
  29452. Object.assign(Triangle, {
  29453. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29454. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29455. return Triangle.getBarycoord(point, a, b, c, target);
  29456. },
  29457. normal: function normal(a, b, c, target) {
  29458. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29459. return Triangle.getNormal(a, b, c, target);
  29460. }
  29461. });
  29462. Object.assign(Shape.prototype, {
  29463. extractAllPoints: function extractAllPoints(divisions) {
  29464. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29465. return this.extractPoints(divisions);
  29466. },
  29467. extrude: function extrude(options) {
  29468. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29469. return new ExtrudeGeometry(this, options);
  29470. },
  29471. makeGeometry: function makeGeometry(options) {
  29472. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29473. return new ShapeGeometry(this, options);
  29474. }
  29475. });
  29476. Object.assign(Vector2.prototype, {
  29477. fromAttribute: function fromAttribute(attribute, index, offset) {
  29478. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29479. return this.fromBufferAttribute(attribute, index, offset);
  29480. },
  29481. distanceToManhattan: function distanceToManhattan(v) {
  29482. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29483. return this.manhattanDistanceTo(v);
  29484. },
  29485. lengthManhattan: function lengthManhattan() {
  29486. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29487. return this.manhattanLength();
  29488. }
  29489. });
  29490. Object.assign(Vector3.prototype, {
  29491. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29492. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29493. },
  29494. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29495. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29496. },
  29497. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29498. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29499. return this.setFromMatrixPosition(m);
  29500. },
  29501. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29502. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29503. return this.setFromMatrixScale(m);
  29504. },
  29505. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29506. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29507. return this.setFromMatrixColumn(matrix, index);
  29508. },
  29509. applyProjection: function applyProjection(m) {
  29510. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29511. return this.applyMatrix4(m);
  29512. },
  29513. fromAttribute: function fromAttribute(attribute, index, offset) {
  29514. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29515. return this.fromBufferAttribute(attribute, index, offset);
  29516. },
  29517. distanceToManhattan: function distanceToManhattan(v) {
  29518. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29519. return this.manhattanDistanceTo(v);
  29520. },
  29521. lengthManhattan: function lengthManhattan() {
  29522. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29523. return this.manhattanLength();
  29524. }
  29525. });
  29526. Object.assign(Vector4.prototype, {
  29527. fromAttribute: function fromAttribute(attribute, index, offset) {
  29528. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29529. return this.fromBufferAttribute(attribute, index, offset);
  29530. },
  29531. lengthManhattan: function lengthManhattan() {
  29532. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29533. return this.manhattanLength();
  29534. }
  29535. }); //
  29536. Object.assign(Geometry.prototype, {
  29537. computeTangents: function computeTangents() {
  29538. console.error('THREE.Geometry: .computeTangents() has been removed.');
  29539. },
  29540. computeLineDistances: function computeLineDistances() {
  29541. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  29542. },
  29543. applyMatrix: function applyMatrix(matrix) {
  29544. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29545. return this.applyMatrix4(matrix);
  29546. }
  29547. });
  29548. Object.assign(Object3D.prototype, {
  29549. getChildByName: function getChildByName(name) {
  29550. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29551. return this.getObjectByName(name);
  29552. },
  29553. renderDepth: function renderDepth() {
  29554. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29555. },
  29556. translate: function translate(distance, axis) {
  29557. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29558. return this.translateOnAxis(axis, distance);
  29559. },
  29560. getWorldRotation: function getWorldRotation() {
  29561. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29562. },
  29563. applyMatrix: function applyMatrix(matrix) {
  29564. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29565. return this.applyMatrix4(matrix);
  29566. }
  29567. });
  29568. Object.defineProperties(Object3D.prototype, {
  29569. eulerOrder: {
  29570. get: function get() {
  29571. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29572. return this.rotation.order;
  29573. },
  29574. set: function set(value) {
  29575. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29576. this.rotation.order = value;
  29577. }
  29578. },
  29579. useQuaternion: {
  29580. get: function get() {
  29581. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29582. },
  29583. set: function set() {
  29584. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29585. }
  29586. }
  29587. });
  29588. Object.assign(Mesh.prototype, {
  29589. setDrawMode: function setDrawMode() {
  29590. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29591. }
  29592. });
  29593. Object.defineProperties(Mesh.prototype, {
  29594. drawMode: {
  29595. get: function get() {
  29596. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29597. return TrianglesDrawMode;
  29598. },
  29599. set: function set() {
  29600. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29601. }
  29602. }
  29603. });
  29604. Object.defineProperties(LOD.prototype, {
  29605. objects: {
  29606. get: function get() {
  29607. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29608. return this.levels;
  29609. }
  29610. }
  29611. });
  29612. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29613. get: function get() {
  29614. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29615. },
  29616. set: function set() {
  29617. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29618. }
  29619. });
  29620. SkinnedMesh.prototype.initBones = function () {
  29621. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29622. };
  29623. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29624. get: function get() {
  29625. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29626. return this.arcLengthDivisions;
  29627. },
  29628. set: function set(value) {
  29629. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29630. this.arcLengthDivisions = value;
  29631. }
  29632. }); //
  29633. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29634. console.warn("THREE.PerspectiveCamera.setLens is deprecated. " + "Use .setFocalLength and .filmGauge for a photographic setup.");
  29635. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29636. this.setFocalLength(focalLength);
  29637. }; //
  29638. Object.defineProperties(Light.prototype, {
  29639. onlyShadow: {
  29640. set: function set() {
  29641. console.warn('THREE.Light: .onlyShadow has been removed.');
  29642. }
  29643. },
  29644. shadowCameraFov: {
  29645. set: function set(value) {
  29646. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29647. this.shadow.camera.fov = value;
  29648. }
  29649. },
  29650. shadowCameraLeft: {
  29651. set: function set(value) {
  29652. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29653. this.shadow.camera.left = value;
  29654. }
  29655. },
  29656. shadowCameraRight: {
  29657. set: function set(value) {
  29658. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29659. this.shadow.camera.right = value;
  29660. }
  29661. },
  29662. shadowCameraTop: {
  29663. set: function set(value) {
  29664. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29665. this.shadow.camera.top = value;
  29666. }
  29667. },
  29668. shadowCameraBottom: {
  29669. set: function set(value) {
  29670. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29671. this.shadow.camera.bottom = value;
  29672. }
  29673. },
  29674. shadowCameraNear: {
  29675. set: function set(value) {
  29676. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29677. this.shadow.camera.near = value;
  29678. }
  29679. },
  29680. shadowCameraFar: {
  29681. set: function set(value) {
  29682. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29683. this.shadow.camera.far = value;
  29684. }
  29685. },
  29686. shadowCameraVisible: {
  29687. set: function set() {
  29688. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29689. }
  29690. },
  29691. shadowBias: {
  29692. set: function set(value) {
  29693. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29694. this.shadow.bias = value;
  29695. }
  29696. },
  29697. shadowDarkness: {
  29698. set: function set() {
  29699. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29700. }
  29701. },
  29702. shadowMapWidth: {
  29703. set: function set(value) {
  29704. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29705. this.shadow.mapSize.width = value;
  29706. }
  29707. },
  29708. shadowMapHeight: {
  29709. set: function set(value) {
  29710. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29711. this.shadow.mapSize.height = value;
  29712. }
  29713. }
  29714. }); //
  29715. Object.defineProperties(BufferAttribute.prototype, {
  29716. length: {
  29717. get: function get() {
  29718. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29719. return this.array.length;
  29720. }
  29721. },
  29722. dynamic: {
  29723. get: function get() {
  29724. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29725. return this.usage === DynamicDrawUsage;
  29726. },
  29727. set: function set()
  29728. /* value */
  29729. {
  29730. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29731. this.setUsage(DynamicDrawUsage);
  29732. }
  29733. }
  29734. });
  29735. Object.assign(BufferAttribute.prototype, {
  29736. setDynamic: function setDynamic(value) {
  29737. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29738. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29739. return this;
  29740. },
  29741. copyIndicesArray: function copyIndicesArray()
  29742. /* indices */
  29743. {
  29744. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29745. },
  29746. setArray: function setArray()
  29747. /* array */
  29748. {
  29749. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29750. }
  29751. });
  29752. Object.assign(BufferGeometry.prototype, {
  29753. addIndex: function addIndex(index) {
  29754. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29755. this.setIndex(index);
  29756. },
  29757. addAttribute: function addAttribute(name, attribute) {
  29758. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29759. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29760. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29761. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29762. }
  29763. if (name === 'index') {
  29764. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29765. this.setIndex(attribute);
  29766. return this;
  29767. }
  29768. return this.setAttribute(name, attribute);
  29769. },
  29770. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29771. if (indexOffset !== undefined) {
  29772. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29773. }
  29774. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29775. this.addGroup(start, count);
  29776. },
  29777. clearDrawCalls: function clearDrawCalls() {
  29778. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29779. this.clearGroups();
  29780. },
  29781. computeTangents: function computeTangents() {
  29782. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  29783. },
  29784. computeOffsets: function computeOffsets() {
  29785. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29786. },
  29787. removeAttribute: function removeAttribute(name) {
  29788. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29789. return this.deleteAttribute(name);
  29790. },
  29791. applyMatrix: function applyMatrix(matrix) {
  29792. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29793. return this.applyMatrix4(matrix);
  29794. }
  29795. });
  29796. Object.defineProperties(BufferGeometry.prototype, {
  29797. drawcalls: {
  29798. get: function get() {
  29799. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29800. return this.groups;
  29801. }
  29802. },
  29803. offsets: {
  29804. get: function get() {
  29805. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29806. return this.groups;
  29807. }
  29808. }
  29809. });
  29810. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29811. maxInstancedCount: {
  29812. get: function get() {
  29813. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29814. return this.instanceCount;
  29815. },
  29816. set: function set(value) {
  29817. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29818. this.instanceCount = value;
  29819. }
  29820. }
  29821. });
  29822. Object.defineProperties(Raycaster.prototype, {
  29823. linePrecision: {
  29824. get: function get() {
  29825. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29826. return this.params.Line.threshold;
  29827. },
  29828. set: function set(value) {
  29829. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29830. this.params.Line.threshold = value;
  29831. }
  29832. }
  29833. });
  29834. Object.defineProperties(InterleavedBuffer.prototype, {
  29835. dynamic: {
  29836. get: function get() {
  29837. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29838. return this.usage === DynamicDrawUsage;
  29839. },
  29840. set: function set(value) {
  29841. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29842. this.setUsage(value);
  29843. }
  29844. }
  29845. });
  29846. Object.assign(InterleavedBuffer.prototype, {
  29847. setDynamic: function setDynamic(value) {
  29848. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29849. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29850. return this;
  29851. },
  29852. setArray: function setArray()
  29853. /* array */
  29854. {
  29855. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29856. }
  29857. }); //
  29858. Object.assign(ExtrudeBufferGeometry.prototype, {
  29859. getArrays: function getArrays() {
  29860. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  29861. },
  29862. addShapeList: function addShapeList() {
  29863. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  29864. },
  29865. addShape: function addShape() {
  29866. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  29867. }
  29868. }); //
  29869. Object.assign(Scene.prototype, {
  29870. dispose: function dispose() {
  29871. console.error('THREE.Scene: .dispose() has been removed.');
  29872. }
  29873. }); //
  29874. Object.defineProperties(Uniform.prototype, {
  29875. dynamic: {
  29876. set: function set() {
  29877. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29878. }
  29879. },
  29880. onUpdate: {
  29881. value: function value() {
  29882. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29883. return this;
  29884. }
  29885. }
  29886. }); //
  29887. Object.defineProperties(Material.prototype, {
  29888. wrapAround: {
  29889. get: function get() {
  29890. console.warn('THREE.Material: .wrapAround has been removed.');
  29891. },
  29892. set: function set() {
  29893. console.warn('THREE.Material: .wrapAround has been removed.');
  29894. }
  29895. },
  29896. overdraw: {
  29897. get: function get() {
  29898. console.warn('THREE.Material: .overdraw has been removed.');
  29899. },
  29900. set: function set() {
  29901. console.warn('THREE.Material: .overdraw has been removed.');
  29902. }
  29903. },
  29904. wrapRGB: {
  29905. get: function get() {
  29906. console.warn('THREE.Material: .wrapRGB has been removed.');
  29907. return new Color();
  29908. }
  29909. },
  29910. shading: {
  29911. get: function get() {
  29912. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29913. },
  29914. set: function set(value) {
  29915. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29916. this.flatShading = value === FlatShading;
  29917. }
  29918. },
  29919. stencilMask: {
  29920. get: function get() {
  29921. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29922. return this.stencilFuncMask;
  29923. },
  29924. set: function set(value) {
  29925. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29926. this.stencilFuncMask = value;
  29927. }
  29928. }
  29929. });
  29930. Object.defineProperties(MeshPhongMaterial.prototype, {
  29931. metal: {
  29932. get: function get() {
  29933. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29934. return false;
  29935. },
  29936. set: function set() {
  29937. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29938. }
  29939. }
  29940. });
  29941. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29942. transparency: {
  29943. get: function get() {
  29944. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29945. return this.transmission;
  29946. },
  29947. set: function set(value) {
  29948. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29949. this.transmission = value;
  29950. }
  29951. }
  29952. });
  29953. Object.defineProperties(ShaderMaterial.prototype, {
  29954. derivatives: {
  29955. get: function get() {
  29956. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29957. return this.extensions.derivatives;
  29958. },
  29959. set: function set(value) {
  29960. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29961. this.extensions.derivatives = value;
  29962. }
  29963. }
  29964. }); //
  29965. Object.assign(WebGLRenderer.prototype, {
  29966. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29967. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29968. this.setRenderTarget(renderTarget);
  29969. this.clear(color, depth, stencil);
  29970. },
  29971. animate: function animate(callback) {
  29972. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29973. this.setAnimationLoop(callback);
  29974. },
  29975. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29976. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29977. return this.getRenderTarget();
  29978. },
  29979. getMaxAnisotropy: function getMaxAnisotropy() {
  29980. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29981. return this.capabilities.getMaxAnisotropy();
  29982. },
  29983. getPrecision: function getPrecision() {
  29984. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29985. return this.capabilities.precision;
  29986. },
  29987. resetGLState: function resetGLState() {
  29988. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29989. return this.state.reset();
  29990. },
  29991. supportsFloatTextures: function supportsFloatTextures() {
  29992. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  29993. return this.extensions.get('OES_texture_float');
  29994. },
  29995. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  29996. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  29997. return this.extensions.get('OES_texture_half_float');
  29998. },
  29999. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30000. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30001. return this.extensions.get('OES_standard_derivatives');
  30002. },
  30003. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30004. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30005. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30006. },
  30007. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30008. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30009. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30010. },
  30011. supportsBlendMinMax: function supportsBlendMinMax() {
  30012. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30013. return this.extensions.get('EXT_blend_minmax');
  30014. },
  30015. supportsVertexTextures: function supportsVertexTextures() {
  30016. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30017. return this.capabilities.vertexTextures;
  30018. },
  30019. supportsInstancedArrays: function supportsInstancedArrays() {
  30020. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30021. return this.extensions.get('ANGLE_instanced_arrays');
  30022. },
  30023. enableScissorTest: function enableScissorTest(boolean) {
  30024. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30025. this.setScissorTest(boolean);
  30026. },
  30027. initMaterial: function initMaterial() {
  30028. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30029. },
  30030. addPrePlugin: function addPrePlugin() {
  30031. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30032. },
  30033. addPostPlugin: function addPostPlugin() {
  30034. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30035. },
  30036. updateShadowMap: function updateShadowMap() {
  30037. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30038. },
  30039. setFaceCulling: function setFaceCulling() {
  30040. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30041. },
  30042. allocTextureUnit: function allocTextureUnit() {
  30043. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30044. },
  30045. setTexture: function setTexture() {
  30046. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30047. },
  30048. setTexture2D: function setTexture2D() {
  30049. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30050. },
  30051. setTextureCube: function setTextureCube() {
  30052. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30053. },
  30054. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30055. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30056. return this.getActiveMipmapLevel();
  30057. }
  30058. });
  30059. Object.defineProperties(WebGLRenderer.prototype, {
  30060. shadowMapEnabled: {
  30061. get: function get() {
  30062. return this.shadowMap.enabled;
  30063. },
  30064. set: function set(value) {
  30065. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30066. this.shadowMap.enabled = value;
  30067. }
  30068. },
  30069. shadowMapType: {
  30070. get: function get() {
  30071. return this.shadowMap.type;
  30072. },
  30073. set: function set(value) {
  30074. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30075. this.shadowMap.type = value;
  30076. }
  30077. },
  30078. shadowMapCullFace: {
  30079. get: function get() {
  30080. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30081. return undefined;
  30082. },
  30083. set: function set()
  30084. /* value */
  30085. {
  30086. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30087. }
  30088. },
  30089. context: {
  30090. get: function get() {
  30091. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30092. return this.getContext();
  30093. }
  30094. },
  30095. vr: {
  30096. get: function get() {
  30097. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30098. return this.xr;
  30099. }
  30100. },
  30101. gammaInput: {
  30102. get: function get() {
  30103. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30104. return false;
  30105. },
  30106. set: function set() {
  30107. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30108. }
  30109. },
  30110. gammaOutput: {
  30111. get: function get() {
  30112. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30113. return false;
  30114. },
  30115. set: function set(value) {
  30116. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30117. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30118. }
  30119. },
  30120. toneMappingWhitePoint: {
  30121. get: function get() {
  30122. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30123. return 1.0;
  30124. },
  30125. set: function set() {
  30126. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30127. }
  30128. }
  30129. });
  30130. Object.defineProperties(WebGLShadowMap.prototype, {
  30131. cullFace: {
  30132. get: function get() {
  30133. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30134. return undefined;
  30135. },
  30136. set: function set()
  30137. /* cullFace */
  30138. {
  30139. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30140. }
  30141. },
  30142. renderReverseSided: {
  30143. get: function get() {
  30144. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30145. return undefined;
  30146. },
  30147. set: function set() {
  30148. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30149. }
  30150. },
  30151. renderSingleSided: {
  30152. get: function get() {
  30153. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30154. return undefined;
  30155. },
  30156. set: function set() {
  30157. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30158. }
  30159. }
  30160. });
  30161. function WebGLRenderTargetCube(width, height, options) {
  30162. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30163. return new WebGLCubeRenderTarget(width, options);
  30164. } //
  30165. Object.defineProperties(WebGLRenderTarget.prototype, {
  30166. wrapS: {
  30167. get: function get() {
  30168. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30169. return this.texture.wrapS;
  30170. },
  30171. set: function set(value) {
  30172. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30173. this.texture.wrapS = value;
  30174. }
  30175. },
  30176. wrapT: {
  30177. get: function get() {
  30178. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30179. return this.texture.wrapT;
  30180. },
  30181. set: function set(value) {
  30182. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30183. this.texture.wrapT = value;
  30184. }
  30185. },
  30186. magFilter: {
  30187. get: function get() {
  30188. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30189. return this.texture.magFilter;
  30190. },
  30191. set: function set(value) {
  30192. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30193. this.texture.magFilter = value;
  30194. }
  30195. },
  30196. minFilter: {
  30197. get: function get() {
  30198. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30199. return this.texture.minFilter;
  30200. },
  30201. set: function set(value) {
  30202. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30203. this.texture.minFilter = value;
  30204. }
  30205. },
  30206. anisotropy: {
  30207. get: function get() {
  30208. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30209. return this.texture.anisotropy;
  30210. },
  30211. set: function set(value) {
  30212. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30213. this.texture.anisotropy = value;
  30214. }
  30215. },
  30216. offset: {
  30217. get: function get() {
  30218. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30219. return this.texture.offset;
  30220. },
  30221. set: function set(value) {
  30222. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30223. this.texture.offset = value;
  30224. }
  30225. },
  30226. repeat: {
  30227. get: function get() {
  30228. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30229. return this.texture.repeat;
  30230. },
  30231. set: function set(value) {
  30232. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30233. this.texture.repeat = value;
  30234. }
  30235. },
  30236. format: {
  30237. get: function get() {
  30238. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30239. return this.texture.format;
  30240. },
  30241. set: function set(value) {
  30242. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30243. this.texture.format = value;
  30244. }
  30245. },
  30246. type: {
  30247. get: function get() {
  30248. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30249. return this.texture.type;
  30250. },
  30251. set: function set(value) {
  30252. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30253. this.texture.type = value;
  30254. }
  30255. },
  30256. generateMipmaps: {
  30257. get: function get() {
  30258. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30259. return this.texture.generateMipmaps;
  30260. },
  30261. set: function set(value) {
  30262. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30263. this.texture.generateMipmaps = value;
  30264. }
  30265. }
  30266. }); //
  30267. Object.defineProperties(Audio.prototype, {
  30268. load: {
  30269. value: function value(file) {
  30270. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30271. var scope = this;
  30272. var audioLoader = new AudioLoader();
  30273. audioLoader.load(file, function (buffer) {
  30274. scope.setBuffer(buffer);
  30275. });
  30276. return this;
  30277. }
  30278. },
  30279. startTime: {
  30280. set: function set() {
  30281. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30282. }
  30283. }
  30284. });
  30285. AudioAnalyser.prototype.getData = function () {
  30286. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30287. return this.getFrequencyData();
  30288. }; //
  30289. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30290. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30291. return this.update(renderer, scene);
  30292. };
  30293. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30294. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30295. return this.renderTarget.clear(renderer, color, depth, stencil);
  30296. }; //
  30297. var GeometryUtils = {
  30298. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30299. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30300. var matrix;
  30301. if (geometry2.isMesh) {
  30302. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30303. matrix = geometry2.matrix;
  30304. geometry2 = geometry2.geometry;
  30305. }
  30306. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30307. },
  30308. center: function center(geometry) {
  30309. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30310. return geometry.center();
  30311. }
  30312. };
  30313. ImageUtils.crossOrigin = undefined;
  30314. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30315. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30316. var loader = new TextureLoader();
  30317. loader.setCrossOrigin(this.crossOrigin);
  30318. var texture = loader.load(url, onLoad, undefined, onError);
  30319. if (mapping) texture.mapping = mapping;
  30320. return texture;
  30321. };
  30322. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30323. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30324. var loader = new CubeTextureLoader();
  30325. loader.setCrossOrigin(this.crossOrigin);
  30326. var texture = loader.load(urls, onLoad, undefined, onError);
  30327. if (mapping) texture.mapping = mapping;
  30328. return texture;
  30329. };
  30330. ImageUtils.loadCompressedTexture = function () {
  30331. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30332. };
  30333. ImageUtils.loadCompressedTextureCube = function () {
  30334. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30335. }; //
  30336. function CanvasRenderer() {
  30337. console.error('THREE.CanvasRenderer has been removed');
  30338. } //
  30339. function JSONLoader() {
  30340. console.error('THREE.JSONLoader has been removed.');
  30341. } //
  30342. var SceneUtils = {
  30343. createMultiMaterialObject: function createMultiMaterialObject()
  30344. /* geometry, materials */
  30345. {
  30346. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30347. },
  30348. detach: function detach()
  30349. /* child, parent, scene */
  30350. {
  30351. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30352. },
  30353. attach: function attach()
  30354. /* child, scene, parent */
  30355. {
  30356. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30357. }
  30358. }; //
  30359. function LensFlare() {
  30360. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30361. }
  30362. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30363. /* eslint-disable no-undef */
  30364. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30365. detail: {
  30366. revision: REVISION
  30367. }
  30368. }));
  30369. /* eslint-enable no-undef */
  30370. }
  30371. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30372. exports.AddEquation = AddEquation;
  30373. exports.AddOperation = AddOperation;
  30374. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30375. exports.AdditiveBlending = AdditiveBlending;
  30376. exports.AlphaFormat = AlphaFormat;
  30377. exports.AlwaysDepth = AlwaysDepth;
  30378. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30379. exports.AmbientLight = AmbientLight;
  30380. exports.AmbientLightProbe = AmbientLightProbe;
  30381. exports.AnimationClip = AnimationClip;
  30382. exports.AnimationLoader = AnimationLoader;
  30383. exports.AnimationMixer = AnimationMixer;
  30384. exports.AnimationObjectGroup = AnimationObjectGroup;
  30385. exports.AnimationUtils = AnimationUtils;
  30386. exports.ArcCurve = ArcCurve;
  30387. exports.ArrayCamera = ArrayCamera;
  30388. exports.ArrowHelper = ArrowHelper;
  30389. exports.Audio = Audio;
  30390. exports.AudioAnalyser = AudioAnalyser;
  30391. exports.AudioContext = AudioContext;
  30392. exports.AudioListener = AudioListener;
  30393. exports.AudioLoader = AudioLoader;
  30394. exports.AxesHelper = AxesHelper;
  30395. exports.AxisHelper = AxisHelper;
  30396. exports.BackSide = BackSide;
  30397. exports.BasicDepthPacking = BasicDepthPacking;
  30398. exports.BasicShadowMap = BasicShadowMap;
  30399. exports.BinaryTextureLoader = BinaryTextureLoader;
  30400. exports.Bone = Bone;
  30401. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30402. exports.BoundingBoxHelper = BoundingBoxHelper;
  30403. exports.Box2 = Box2;
  30404. exports.Box3 = Box3;
  30405. exports.Box3Helper = Box3Helper;
  30406. exports.BoxBufferGeometry = BoxBufferGeometry;
  30407. exports.BoxGeometry = BoxGeometry;
  30408. exports.BoxHelper = BoxHelper;
  30409. exports.BufferAttribute = BufferAttribute;
  30410. exports.BufferGeometry = BufferGeometry;
  30411. exports.BufferGeometryLoader = BufferGeometryLoader;
  30412. exports.ByteType = ByteType;
  30413. exports.Cache = Cache;
  30414. exports.Camera = Camera;
  30415. exports.CameraHelper = CameraHelper;
  30416. exports.CanvasRenderer = CanvasRenderer;
  30417. exports.CanvasTexture = CanvasTexture;
  30418. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30419. exports.CineonToneMapping = CineonToneMapping;
  30420. exports.CircleBufferGeometry = CircleBufferGeometry;
  30421. exports.CircleGeometry = CircleGeometry;
  30422. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30423. exports.Clock = Clock;
  30424. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30425. exports.Color = Color;
  30426. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30427. exports.CompressedTexture = CompressedTexture;
  30428. exports.CompressedTextureLoader = CompressedTextureLoader;
  30429. exports.ConeBufferGeometry = ConeBufferGeometry;
  30430. exports.ConeGeometry = ConeGeometry;
  30431. exports.CubeCamera = CubeCamera;
  30432. exports.CubeGeometry = BoxGeometry;
  30433. exports.CubeReflectionMapping = CubeReflectionMapping;
  30434. exports.CubeRefractionMapping = CubeRefractionMapping;
  30435. exports.CubeTexture = CubeTexture;
  30436. exports.CubeTextureLoader = CubeTextureLoader;
  30437. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30438. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30439. exports.CubicBezierCurve = CubicBezierCurve;
  30440. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30441. exports.CubicInterpolant = CubicInterpolant;
  30442. exports.CullFaceBack = CullFaceBack;
  30443. exports.CullFaceFront = CullFaceFront;
  30444. exports.CullFaceFrontBack = CullFaceFrontBack;
  30445. exports.CullFaceNone = CullFaceNone;
  30446. exports.Curve = Curve;
  30447. exports.CurvePath = CurvePath;
  30448. exports.CustomBlending = CustomBlending;
  30449. exports.CustomToneMapping = CustomToneMapping;
  30450. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  30451. exports.CylinderGeometry = CylinderGeometry;
  30452. exports.Cylindrical = Cylindrical;
  30453. exports.DataTexture = DataTexture;
  30454. exports.DataTexture2DArray = DataTexture2DArray;
  30455. exports.DataTexture3D = DataTexture3D;
  30456. exports.DataTextureLoader = DataTextureLoader;
  30457. exports.DataUtils = DataUtils;
  30458. exports.DecrementStencilOp = DecrementStencilOp;
  30459. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30460. exports.DefaultLoadingManager = DefaultLoadingManager;
  30461. exports.DepthFormat = DepthFormat;
  30462. exports.DepthStencilFormat = DepthStencilFormat;
  30463. exports.DepthTexture = DepthTexture;
  30464. exports.DirectionalLight = DirectionalLight;
  30465. exports.DirectionalLightHelper = DirectionalLightHelper;
  30466. exports.DiscreteInterpolant = DiscreteInterpolant;
  30467. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  30468. exports.DodecahedronGeometry = DodecahedronGeometry;
  30469. exports.DoubleSide = DoubleSide;
  30470. exports.DstAlphaFactor = DstAlphaFactor;
  30471. exports.DstColorFactor = DstColorFactor;
  30472. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30473. exports.DynamicCopyUsage = DynamicCopyUsage;
  30474. exports.DynamicDrawUsage = DynamicDrawUsage;
  30475. exports.DynamicReadUsage = DynamicReadUsage;
  30476. exports.EdgesGeometry = EdgesGeometry;
  30477. exports.EdgesHelper = EdgesHelper;
  30478. exports.EllipseCurve = EllipseCurve;
  30479. exports.EqualDepth = EqualDepth;
  30480. exports.EqualStencilFunc = EqualStencilFunc;
  30481. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30482. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30483. exports.Euler = Euler;
  30484. exports.EventDispatcher = EventDispatcher;
  30485. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  30486. exports.ExtrudeGeometry = ExtrudeGeometry;
  30487. exports.Face3 = Face3;
  30488. exports.Face4 = Face4;
  30489. exports.FaceColors = FaceColors;
  30490. exports.FileLoader = FileLoader;
  30491. exports.FlatShading = FlatShading;
  30492. exports.Float16BufferAttribute = Float16BufferAttribute;
  30493. exports.Float32Attribute = Float32Attribute;
  30494. exports.Float32BufferAttribute = Float32BufferAttribute;
  30495. exports.Float64Attribute = Float64Attribute;
  30496. exports.Float64BufferAttribute = Float64BufferAttribute;
  30497. exports.FloatType = FloatType;
  30498. exports.Fog = Fog;
  30499. exports.FogExp2 = FogExp2;
  30500. exports.Font = Font;
  30501. exports.FontLoader = FontLoader;
  30502. exports.FrontSide = FrontSide;
  30503. exports.Frustum = Frustum;
  30504. exports.GLBufferAttribute = GLBufferAttribute;
  30505. exports.GLSL1 = GLSL1;
  30506. exports.GLSL3 = GLSL3;
  30507. exports.GammaEncoding = GammaEncoding;
  30508. exports.Geometry = Geometry;
  30509. exports.GeometryUtils = GeometryUtils;
  30510. exports.GreaterDepth = GreaterDepth;
  30511. exports.GreaterEqualDepth = GreaterEqualDepth;
  30512. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30513. exports.GreaterStencilFunc = GreaterStencilFunc;
  30514. exports.GridHelper = GridHelper;
  30515. exports.Group = Group;
  30516. exports.HalfFloatType = HalfFloatType;
  30517. exports.HemisphereLight = HemisphereLight;
  30518. exports.HemisphereLightHelper = HemisphereLightHelper;
  30519. exports.HemisphereLightProbe = HemisphereLightProbe;
  30520. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  30521. exports.IcosahedronGeometry = IcosahedronGeometry;
  30522. exports.ImageBitmapLoader = ImageBitmapLoader;
  30523. exports.ImageLoader = ImageLoader;
  30524. exports.ImageUtils = ImageUtils;
  30525. exports.ImmediateRenderObject = ImmediateRenderObject;
  30526. exports.IncrementStencilOp = IncrementStencilOp;
  30527. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30528. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30529. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30530. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30531. exports.InstancedMesh = InstancedMesh;
  30532. exports.Int16Attribute = Int16Attribute;
  30533. exports.Int16BufferAttribute = Int16BufferAttribute;
  30534. exports.Int32Attribute = Int32Attribute;
  30535. exports.Int32BufferAttribute = Int32BufferAttribute;
  30536. exports.Int8Attribute = Int8Attribute;
  30537. exports.Int8BufferAttribute = Int8BufferAttribute;
  30538. exports.IntType = IntType;
  30539. exports.InterleavedBuffer = InterleavedBuffer;
  30540. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30541. exports.Interpolant = Interpolant;
  30542. exports.InterpolateDiscrete = InterpolateDiscrete;
  30543. exports.InterpolateLinear = InterpolateLinear;
  30544. exports.InterpolateSmooth = InterpolateSmooth;
  30545. exports.InvertStencilOp = InvertStencilOp;
  30546. exports.JSONLoader = JSONLoader;
  30547. exports.KeepStencilOp = KeepStencilOp;
  30548. exports.KeyframeTrack = KeyframeTrack;
  30549. exports.LOD = LOD;
  30550. exports.LatheBufferGeometry = LatheBufferGeometry;
  30551. exports.LatheGeometry = LatheGeometry;
  30552. exports.Layers = Layers;
  30553. exports.LensFlare = LensFlare;
  30554. exports.LessDepth = LessDepth;
  30555. exports.LessEqualDepth = LessEqualDepth;
  30556. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30557. exports.LessStencilFunc = LessStencilFunc;
  30558. exports.Light = Light;
  30559. exports.LightProbe = LightProbe;
  30560. exports.Line = Line;
  30561. exports.Line3 = Line3;
  30562. exports.LineBasicMaterial = LineBasicMaterial;
  30563. exports.LineCurve = LineCurve;
  30564. exports.LineCurve3 = LineCurve3;
  30565. exports.LineDashedMaterial = LineDashedMaterial;
  30566. exports.LineLoop = LineLoop;
  30567. exports.LinePieces = LinePieces;
  30568. exports.LineSegments = LineSegments;
  30569. exports.LineStrip = LineStrip;
  30570. exports.LinearEncoding = LinearEncoding;
  30571. exports.LinearFilter = LinearFilter;
  30572. exports.LinearInterpolant = LinearInterpolant;
  30573. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30574. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30575. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30576. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30577. exports.LinearToneMapping = LinearToneMapping;
  30578. exports.Loader = Loader;
  30579. exports.LoaderUtils = LoaderUtils;
  30580. exports.LoadingManager = LoadingManager;
  30581. exports.LogLuvEncoding = LogLuvEncoding;
  30582. exports.LoopOnce = LoopOnce;
  30583. exports.LoopPingPong = LoopPingPong;
  30584. exports.LoopRepeat = LoopRepeat;
  30585. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30586. exports.LuminanceFormat = LuminanceFormat;
  30587. exports.MOUSE = MOUSE;
  30588. exports.Material = Material;
  30589. exports.MaterialLoader = MaterialLoader;
  30590. exports.Math = MathUtils;
  30591. exports.MathUtils = MathUtils;
  30592. exports.Matrix3 = Matrix3;
  30593. exports.Matrix4 = Matrix4;
  30594. exports.MaxEquation = MaxEquation;
  30595. exports.Mesh = Mesh;
  30596. exports.MeshBasicMaterial = MeshBasicMaterial;
  30597. exports.MeshDepthMaterial = MeshDepthMaterial;
  30598. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30599. exports.MeshFaceMaterial = MeshFaceMaterial;
  30600. exports.MeshLambertMaterial = MeshLambertMaterial;
  30601. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30602. exports.MeshNormalMaterial = MeshNormalMaterial;
  30603. exports.MeshPhongMaterial = MeshPhongMaterial;
  30604. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30605. exports.MeshStandardMaterial = MeshStandardMaterial;
  30606. exports.MeshToonMaterial = MeshToonMaterial;
  30607. exports.MinEquation = MinEquation;
  30608. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30609. exports.MixOperation = MixOperation;
  30610. exports.MultiMaterial = MultiMaterial;
  30611. exports.MultiplyBlending = MultiplyBlending;
  30612. exports.MultiplyOperation = MultiplyOperation;
  30613. exports.NearestFilter = NearestFilter;
  30614. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30615. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30616. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30617. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30618. exports.NeverDepth = NeverDepth;
  30619. exports.NeverStencilFunc = NeverStencilFunc;
  30620. exports.NoBlending = NoBlending;
  30621. exports.NoColors = NoColors;
  30622. exports.NoToneMapping = NoToneMapping;
  30623. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30624. exports.NormalBlending = NormalBlending;
  30625. exports.NotEqualDepth = NotEqualDepth;
  30626. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30627. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30628. exports.Object3D = Object3D;
  30629. exports.ObjectLoader = ObjectLoader;
  30630. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30631. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  30632. exports.OctahedronGeometry = OctahedronGeometry;
  30633. exports.OneFactor = OneFactor;
  30634. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30635. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30636. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30637. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30638. exports.OrthographicCamera = OrthographicCamera;
  30639. exports.PCFShadowMap = PCFShadowMap;
  30640. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30641. exports.PMREMGenerator = PMREMGenerator;
  30642. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  30643. exports.ParametricGeometry = ParametricGeometry;
  30644. exports.Particle = Particle;
  30645. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30646. exports.ParticleSystem = ParticleSystem;
  30647. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30648. exports.Path = Path;
  30649. exports.PerspectiveCamera = PerspectiveCamera;
  30650. exports.Plane = Plane;
  30651. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  30652. exports.PlaneGeometry = PlaneGeometry;
  30653. exports.PlaneHelper = PlaneHelper;
  30654. exports.PointCloud = PointCloud;
  30655. exports.PointCloudMaterial = PointCloudMaterial;
  30656. exports.PointLight = PointLight;
  30657. exports.PointLightHelper = PointLightHelper;
  30658. exports.Points = Points;
  30659. exports.PointsMaterial = PointsMaterial;
  30660. exports.PolarGridHelper = PolarGridHelper;
  30661. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  30662. exports.PolyhedronGeometry = PolyhedronGeometry;
  30663. exports.PositionalAudio = PositionalAudio;
  30664. exports.PropertyBinding = PropertyBinding;
  30665. exports.PropertyMixer = PropertyMixer;
  30666. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30667. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30668. exports.Quaternion = Quaternion;
  30669. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30670. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30671. exports.REVISION = REVISION;
  30672. exports.RGBADepthPacking = RGBADepthPacking;
  30673. exports.RGBAFormat = RGBAFormat;
  30674. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30675. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30676. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30677. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30678. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30679. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30680. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30681. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30682. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30683. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30684. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30685. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30686. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30687. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30688. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30689. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30690. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30691. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30692. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30693. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30694. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30695. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30696. exports.RGBDEncoding = RGBDEncoding;
  30697. exports.RGBEEncoding = RGBEEncoding;
  30698. exports.RGBEFormat = RGBEFormat;
  30699. exports.RGBFormat = RGBFormat;
  30700. exports.RGBIntegerFormat = RGBIntegerFormat;
  30701. exports.RGBM16Encoding = RGBM16Encoding;
  30702. exports.RGBM7Encoding = RGBM7Encoding;
  30703. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30704. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30705. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30706. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30707. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30708. exports.RGFormat = RGFormat;
  30709. exports.RGIntegerFormat = RGIntegerFormat;
  30710. exports.RawShaderMaterial = RawShaderMaterial;
  30711. exports.Ray = Ray;
  30712. exports.Raycaster = Raycaster;
  30713. exports.RectAreaLight = RectAreaLight;
  30714. exports.RedFormat = RedFormat;
  30715. exports.RedIntegerFormat = RedIntegerFormat;
  30716. exports.ReinhardToneMapping = ReinhardToneMapping;
  30717. exports.RepeatWrapping = RepeatWrapping;
  30718. exports.ReplaceStencilOp = ReplaceStencilOp;
  30719. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30720. exports.RingBufferGeometry = RingBufferGeometry;
  30721. exports.RingGeometry = RingGeometry;
  30722. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30723. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30724. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30725. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30726. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30727. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30728. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30729. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30730. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30731. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30732. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30733. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30734. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30735. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30736. exports.Scene = Scene;
  30737. exports.SceneUtils = SceneUtils;
  30738. exports.ShaderChunk = ShaderChunk;
  30739. exports.ShaderLib = ShaderLib;
  30740. exports.ShaderMaterial = ShaderMaterial;
  30741. exports.ShadowMaterial = ShadowMaterial;
  30742. exports.Shape = Shape;
  30743. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  30744. exports.ShapeGeometry = ShapeGeometry;
  30745. exports.ShapePath = ShapePath;
  30746. exports.ShapeUtils = ShapeUtils;
  30747. exports.ShortType = ShortType;
  30748. exports.Skeleton = Skeleton;
  30749. exports.SkeletonHelper = SkeletonHelper;
  30750. exports.SkinnedMesh = SkinnedMesh;
  30751. exports.SmoothShading = SmoothShading;
  30752. exports.Sphere = Sphere;
  30753. exports.SphereBufferGeometry = SphereBufferGeometry;
  30754. exports.SphereGeometry = SphereGeometry;
  30755. exports.Spherical = Spherical;
  30756. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30757. exports.Spline = Spline;
  30758. exports.SplineCurve = SplineCurve;
  30759. exports.SplineCurve3 = SplineCurve3;
  30760. exports.SpotLight = SpotLight;
  30761. exports.SpotLightHelper = SpotLightHelper;
  30762. exports.Sprite = Sprite;
  30763. exports.SpriteMaterial = SpriteMaterial;
  30764. exports.SrcAlphaFactor = SrcAlphaFactor;
  30765. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30766. exports.SrcColorFactor = SrcColorFactor;
  30767. exports.StaticCopyUsage = StaticCopyUsage;
  30768. exports.StaticDrawUsage = StaticDrawUsage;
  30769. exports.StaticReadUsage = StaticReadUsage;
  30770. exports.StereoCamera = StereoCamera;
  30771. exports.StreamCopyUsage = StreamCopyUsage;
  30772. exports.StreamDrawUsage = StreamDrawUsage;
  30773. exports.StreamReadUsage = StreamReadUsage;
  30774. exports.StringKeyframeTrack = StringKeyframeTrack;
  30775. exports.SubtractEquation = SubtractEquation;
  30776. exports.SubtractiveBlending = SubtractiveBlending;
  30777. exports.TOUCH = TOUCH;
  30778. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30779. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  30780. exports.TetrahedronGeometry = TetrahedronGeometry;
  30781. exports.TextBufferGeometry = TextBufferGeometry;
  30782. exports.TextGeometry = TextGeometry;
  30783. exports.Texture = Texture;
  30784. exports.TextureLoader = TextureLoader;
  30785. exports.TorusBufferGeometry = TorusBufferGeometry;
  30786. exports.TorusGeometry = TorusGeometry;
  30787. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  30788. exports.TorusKnotGeometry = TorusKnotGeometry;
  30789. exports.Triangle = Triangle;
  30790. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30791. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30792. exports.TrianglesDrawMode = TrianglesDrawMode;
  30793. exports.TubeBufferGeometry = TubeBufferGeometry;
  30794. exports.TubeGeometry = TubeGeometry;
  30795. exports.UVMapping = UVMapping;
  30796. exports.Uint16Attribute = Uint16Attribute;
  30797. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30798. exports.Uint32Attribute = Uint32Attribute;
  30799. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30800. exports.Uint8Attribute = Uint8Attribute;
  30801. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30802. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30803. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30804. exports.Uniform = Uniform;
  30805. exports.UniformsLib = UniformsLib;
  30806. exports.UniformsUtils = UniformsUtils;
  30807. exports.UnsignedByteType = UnsignedByteType;
  30808. exports.UnsignedInt248Type = UnsignedInt248Type;
  30809. exports.UnsignedIntType = UnsignedIntType;
  30810. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30811. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30812. exports.UnsignedShort565Type = UnsignedShort565Type;
  30813. exports.UnsignedShortType = UnsignedShortType;
  30814. exports.VSMShadowMap = VSMShadowMap;
  30815. exports.Vector2 = Vector2;
  30816. exports.Vector3 = Vector3;
  30817. exports.Vector4 = Vector4;
  30818. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30819. exports.Vertex = Vertex;
  30820. exports.VertexColors = VertexColors;
  30821. exports.VideoTexture = VideoTexture;
  30822. exports.WebGL1Renderer = WebGL1Renderer;
  30823. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30824. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30825. exports.WebGLRenderTarget = WebGLRenderTarget;
  30826. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30827. exports.WebGLRenderer = WebGLRenderer;
  30828. exports.WebGLUtils = WebGLUtils;
  30829. exports.WireframeGeometry = WireframeGeometry;
  30830. exports.WireframeHelper = WireframeHelper;
  30831. exports.WrapAroundEnding = WrapAroundEnding;
  30832. exports.XHRLoader = XHRLoader;
  30833. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30834. exports.ZeroFactor = ZeroFactor;
  30835. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30836. exports.ZeroStencilOp = ZeroStencilOp;
  30837. exports.sRGBEncoding = sRGBEncoding;
  30838. Object.defineProperty(exports, '__esModule', { value: true });
  30839. })));