three.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262
  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 = '122dev';
  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.getInverse = function getInverse(matrix, throwOnDegenerate) {
  862. if (throwOnDegenerate !== undefined) {
  863. console.warn("THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate.");
  864. }
  865. var me = matrix.elements,
  866. te = this.elements,
  867. n11 = me[0],
  868. n21 = me[1],
  869. n31 = me[2],
  870. n12 = me[3],
  871. n22 = me[4],
  872. n32 = me[5],
  873. n13 = me[6],
  874. n23 = me[7],
  875. n33 = me[8],
  876. t11 = n33 * n22 - n32 * n23,
  877. t12 = n32 * n13 - n33 * n12,
  878. t13 = n23 * n12 - n22 * n13,
  879. det = n11 * t11 + n21 * t12 + n31 * t13;
  880. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  881. var detInv = 1 / det;
  882. te[0] = t11 * detInv;
  883. te[1] = (n31 * n23 - n33 * n21) * detInv;
  884. te[2] = (n32 * n21 - n31 * n22) * detInv;
  885. te[3] = t12 * detInv;
  886. te[4] = (n33 * n11 - n31 * n13) * detInv;
  887. te[5] = (n31 * n12 - n32 * n11) * detInv;
  888. te[6] = t13 * detInv;
  889. te[7] = (n21 * n13 - n23 * n11) * detInv;
  890. te[8] = (n22 * n11 - n21 * n12) * detInv;
  891. return this;
  892. };
  893. _proto.transpose = function transpose() {
  894. var tmp;
  895. var m = this.elements;
  896. tmp = m[1];
  897. m[1] = m[3];
  898. m[3] = tmp;
  899. tmp = m[2];
  900. m[2] = m[6];
  901. m[6] = tmp;
  902. tmp = m[5];
  903. m[5] = m[7];
  904. m[7] = tmp;
  905. return this;
  906. };
  907. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  908. return this.setFromMatrix4(matrix4).getInverse(this).transpose();
  909. };
  910. _proto.transposeIntoArray = function transposeIntoArray(r) {
  911. var m = this.elements;
  912. r[0] = m[0];
  913. r[1] = m[3];
  914. r[2] = m[6];
  915. r[3] = m[1];
  916. r[4] = m[4];
  917. r[5] = m[7];
  918. r[6] = m[2];
  919. r[7] = m[5];
  920. r[8] = m[8];
  921. return this;
  922. };
  923. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  924. var c = Math.cos(rotation);
  925. var s = Math.sin(rotation);
  926. 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);
  927. };
  928. _proto.scale = function scale(sx, sy) {
  929. var te = this.elements;
  930. te[0] *= sx;
  931. te[3] *= sx;
  932. te[6] *= sx;
  933. te[1] *= sy;
  934. te[4] *= sy;
  935. te[7] *= sy;
  936. return this;
  937. };
  938. _proto.rotate = function rotate(theta) {
  939. var c = Math.cos(theta);
  940. var s = Math.sin(theta);
  941. var te = this.elements;
  942. var a11 = te[0],
  943. a12 = te[3],
  944. a13 = te[6];
  945. var a21 = te[1],
  946. a22 = te[4],
  947. a23 = te[7];
  948. te[0] = c * a11 + s * a21;
  949. te[3] = c * a12 + s * a22;
  950. te[6] = c * a13 + s * a23;
  951. te[1] = -s * a11 + c * a21;
  952. te[4] = -s * a12 + c * a22;
  953. te[7] = -s * a13 + c * a23;
  954. return this;
  955. };
  956. _proto.translate = function translate(tx, ty) {
  957. var te = this.elements;
  958. te[0] += tx * te[2];
  959. te[3] += tx * te[5];
  960. te[6] += tx * te[8];
  961. te[1] += ty * te[2];
  962. te[4] += ty * te[5];
  963. te[7] += ty * te[8];
  964. return this;
  965. };
  966. _proto.equals = function equals(matrix) {
  967. var te = this.elements;
  968. var me = matrix.elements;
  969. for (var i = 0; i < 9; i++) {
  970. if (te[i] !== me[i]) return false;
  971. }
  972. return true;
  973. };
  974. _proto.fromArray = function fromArray(array, offset) {
  975. if (offset === void 0) {
  976. offset = 0;
  977. }
  978. for (var i = 0; i < 9; i++) {
  979. this.elements[i] = array[i + offset];
  980. }
  981. return this;
  982. };
  983. _proto.toArray = function toArray(array, offset) {
  984. if (array === void 0) {
  985. array = [];
  986. }
  987. if (offset === void 0) {
  988. offset = 0;
  989. }
  990. var te = this.elements;
  991. array[offset] = te[0];
  992. array[offset + 1] = te[1];
  993. array[offset + 2] = te[2];
  994. array[offset + 3] = te[3];
  995. array[offset + 4] = te[4];
  996. array[offset + 5] = te[5];
  997. array[offset + 6] = te[6];
  998. array[offset + 7] = te[7];
  999. array[offset + 8] = te[8];
  1000. return array;
  1001. };
  1002. return Matrix3;
  1003. }();
  1004. var _canvas;
  1005. var ImageUtils = {
  1006. getDataURL: function getDataURL(image) {
  1007. if (/^data:/i.test(image.src)) {
  1008. return image.src;
  1009. }
  1010. if (typeof HTMLCanvasElement == 'undefined') {
  1011. return image.src;
  1012. }
  1013. var canvas;
  1014. if (image instanceof HTMLCanvasElement) {
  1015. canvas = image;
  1016. } else {
  1017. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1018. _canvas.width = image.width;
  1019. _canvas.height = image.height;
  1020. var context = _canvas.getContext('2d');
  1021. if (image instanceof ImageData) {
  1022. context.putImageData(image, 0, 0);
  1023. } else {
  1024. context.drawImage(image, 0, 0, image.width, image.height);
  1025. }
  1026. canvas = _canvas;
  1027. }
  1028. if (canvas.width > 2048 || canvas.height > 2048) {
  1029. return canvas.toDataURL('image/jpeg', 0.6);
  1030. } else {
  1031. return canvas.toDataURL('image/png');
  1032. }
  1033. }
  1034. };
  1035. var textureId = 0;
  1036. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1037. Object.defineProperty(this, 'id', {
  1038. value: textureId++
  1039. });
  1040. this.uuid = MathUtils.generateUUID();
  1041. this.name = '';
  1042. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1043. this.mipmaps = [];
  1044. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1045. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1046. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1047. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1048. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1049. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1050. this.format = format !== undefined ? format : RGBAFormat;
  1051. this.internalFormat = null;
  1052. this.type = type !== undefined ? type : UnsignedByteType;
  1053. this.offset = new Vector2(0, 0);
  1054. this.repeat = new Vector2(1, 1);
  1055. this.center = new Vector2(0, 0);
  1056. this.rotation = 0;
  1057. this.matrixAutoUpdate = true;
  1058. this.matrix = new Matrix3();
  1059. this.generateMipmaps = true;
  1060. this.premultiplyAlpha = false;
  1061. this.flipY = true;
  1062. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1063. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1064. //
  1065. // Also changing the encoding after already used by a Material will not automatically make the Material
  1066. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1067. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1068. this.version = 0;
  1069. this.onUpdate = null;
  1070. }
  1071. Texture.DEFAULT_IMAGE = undefined;
  1072. Texture.DEFAULT_MAPPING = UVMapping;
  1073. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1074. constructor: Texture,
  1075. isTexture: true,
  1076. updateMatrix: function updateMatrix() {
  1077. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1078. },
  1079. clone: function clone() {
  1080. return new this.constructor().copy(this);
  1081. },
  1082. copy: function copy(source) {
  1083. this.name = source.name;
  1084. this.image = source.image;
  1085. this.mipmaps = source.mipmaps.slice(0);
  1086. this.mapping = source.mapping;
  1087. this.wrapS = source.wrapS;
  1088. this.wrapT = source.wrapT;
  1089. this.magFilter = source.magFilter;
  1090. this.minFilter = source.minFilter;
  1091. this.anisotropy = source.anisotropy;
  1092. this.format = source.format;
  1093. this.internalFormat = source.internalFormat;
  1094. this.type = source.type;
  1095. this.offset.copy(source.offset);
  1096. this.repeat.copy(source.repeat);
  1097. this.center.copy(source.center);
  1098. this.rotation = source.rotation;
  1099. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1100. this.matrix.copy(source.matrix);
  1101. this.generateMipmaps = source.generateMipmaps;
  1102. this.premultiplyAlpha = source.premultiplyAlpha;
  1103. this.flipY = source.flipY;
  1104. this.unpackAlignment = source.unpackAlignment;
  1105. this.encoding = source.encoding;
  1106. return this;
  1107. },
  1108. toJSON: function toJSON(meta) {
  1109. var isRootObject = meta === undefined || typeof meta === 'string';
  1110. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1111. return meta.textures[this.uuid];
  1112. }
  1113. var output = {
  1114. metadata: {
  1115. version: 4.5,
  1116. type: 'Texture',
  1117. generator: 'Texture.toJSON'
  1118. },
  1119. uuid: this.uuid,
  1120. name: this.name,
  1121. mapping: this.mapping,
  1122. repeat: [this.repeat.x, this.repeat.y],
  1123. offset: [this.offset.x, this.offset.y],
  1124. center: [this.center.x, this.center.y],
  1125. rotation: this.rotation,
  1126. wrap: [this.wrapS, this.wrapT],
  1127. format: this.format,
  1128. type: this.type,
  1129. encoding: this.encoding,
  1130. minFilter: this.minFilter,
  1131. magFilter: this.magFilter,
  1132. anisotropy: this.anisotropy,
  1133. flipY: this.flipY,
  1134. premultiplyAlpha: this.premultiplyAlpha,
  1135. unpackAlignment: this.unpackAlignment
  1136. };
  1137. if (this.image !== undefined) {
  1138. // TODO: Move to THREE.Image
  1139. var image = this.image;
  1140. if (image.uuid === undefined) {
  1141. image.uuid = MathUtils.generateUUID(); // UGH
  1142. }
  1143. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1144. var url;
  1145. if (Array.isArray(image)) {
  1146. // process array of images e.g. CubeTexture
  1147. url = [];
  1148. for (var i = 0, l = image.length; i < l; i++) {
  1149. url.push(ImageUtils.getDataURL(image[i]));
  1150. }
  1151. } else {
  1152. // process single image
  1153. url = ImageUtils.getDataURL(image);
  1154. }
  1155. meta.images[image.uuid] = {
  1156. uuid: image.uuid,
  1157. url: url
  1158. };
  1159. }
  1160. output.image = image.uuid;
  1161. }
  1162. if (!isRootObject) {
  1163. meta.textures[this.uuid] = output;
  1164. }
  1165. return output;
  1166. },
  1167. dispose: function dispose() {
  1168. this.dispatchEvent({
  1169. type: 'dispose'
  1170. });
  1171. },
  1172. transformUv: function transformUv(uv) {
  1173. if (this.mapping !== UVMapping) return uv;
  1174. uv.applyMatrix3(this.matrix);
  1175. if (uv.x < 0 || uv.x > 1) {
  1176. switch (this.wrapS) {
  1177. case RepeatWrapping:
  1178. uv.x = uv.x - Math.floor(uv.x);
  1179. break;
  1180. case ClampToEdgeWrapping:
  1181. uv.x = uv.x < 0 ? 0 : 1;
  1182. break;
  1183. case MirroredRepeatWrapping:
  1184. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1185. uv.x = Math.ceil(uv.x) - uv.x;
  1186. } else {
  1187. uv.x = uv.x - Math.floor(uv.x);
  1188. }
  1189. break;
  1190. }
  1191. }
  1192. if (uv.y < 0 || uv.y > 1) {
  1193. switch (this.wrapT) {
  1194. case RepeatWrapping:
  1195. uv.y = uv.y - Math.floor(uv.y);
  1196. break;
  1197. case ClampToEdgeWrapping:
  1198. uv.y = uv.y < 0 ? 0 : 1;
  1199. break;
  1200. case MirroredRepeatWrapping:
  1201. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1202. uv.y = Math.ceil(uv.y) - uv.y;
  1203. } else {
  1204. uv.y = uv.y - Math.floor(uv.y);
  1205. }
  1206. break;
  1207. }
  1208. }
  1209. if (this.flipY) {
  1210. uv.y = 1 - uv.y;
  1211. }
  1212. return uv;
  1213. }
  1214. });
  1215. Object.defineProperty(Texture.prototype, "needsUpdate", {
  1216. set: function set(value) {
  1217. if (value === true) this.version++;
  1218. }
  1219. });
  1220. var Vector4 = /*#__PURE__*/function () {
  1221. function Vector4(x, y, z, w) {
  1222. if (x === void 0) {
  1223. x = 0;
  1224. }
  1225. if (y === void 0) {
  1226. y = 0;
  1227. }
  1228. if (z === void 0) {
  1229. z = 0;
  1230. }
  1231. if (w === void 0) {
  1232. w = 1;
  1233. }
  1234. Object.defineProperty(this, 'isVector4', {
  1235. value: true
  1236. });
  1237. this.x = x;
  1238. this.y = y;
  1239. this.z = z;
  1240. this.w = w;
  1241. }
  1242. var _proto = Vector4.prototype;
  1243. _proto.set = function set(x, y, z, w) {
  1244. this.x = x;
  1245. this.y = y;
  1246. this.z = z;
  1247. this.w = w;
  1248. return this;
  1249. };
  1250. _proto.setScalar = function setScalar(scalar) {
  1251. this.x = scalar;
  1252. this.y = scalar;
  1253. this.z = scalar;
  1254. this.w = scalar;
  1255. return this;
  1256. };
  1257. _proto.setX = function setX(x) {
  1258. this.x = x;
  1259. return this;
  1260. };
  1261. _proto.setY = function setY(y) {
  1262. this.y = y;
  1263. return this;
  1264. };
  1265. _proto.setZ = function setZ(z) {
  1266. this.z = z;
  1267. return this;
  1268. };
  1269. _proto.setW = function setW(w) {
  1270. this.w = w;
  1271. return this;
  1272. };
  1273. _proto.setComponent = function setComponent(index, value) {
  1274. switch (index) {
  1275. case 0:
  1276. this.x = value;
  1277. break;
  1278. case 1:
  1279. this.y = value;
  1280. break;
  1281. case 2:
  1282. this.z = value;
  1283. break;
  1284. case 3:
  1285. this.w = value;
  1286. break;
  1287. default:
  1288. throw new Error('index is out of range: ' + index);
  1289. }
  1290. return this;
  1291. };
  1292. _proto.getComponent = function getComponent(index) {
  1293. switch (index) {
  1294. case 0:
  1295. return this.x;
  1296. case 1:
  1297. return this.y;
  1298. case 2:
  1299. return this.z;
  1300. case 3:
  1301. return this.w;
  1302. default:
  1303. throw new Error('index is out of range: ' + index);
  1304. }
  1305. };
  1306. _proto.clone = function clone() {
  1307. return new this.constructor(this.x, this.y, this.z, this.w);
  1308. };
  1309. _proto.copy = function copy(v) {
  1310. this.x = v.x;
  1311. this.y = v.y;
  1312. this.z = v.z;
  1313. this.w = v.w !== undefined ? v.w : 1;
  1314. return this;
  1315. };
  1316. _proto.add = function add(v, w) {
  1317. if (w !== undefined) {
  1318. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1319. return this.addVectors(v, w);
  1320. }
  1321. this.x += v.x;
  1322. this.y += v.y;
  1323. this.z += v.z;
  1324. this.w += v.w;
  1325. return this;
  1326. };
  1327. _proto.addScalar = function addScalar(s) {
  1328. this.x += s;
  1329. this.y += s;
  1330. this.z += s;
  1331. this.w += s;
  1332. return this;
  1333. };
  1334. _proto.addVectors = function addVectors(a, b) {
  1335. this.x = a.x + b.x;
  1336. this.y = a.y + b.y;
  1337. this.z = a.z + b.z;
  1338. this.w = a.w + b.w;
  1339. return this;
  1340. };
  1341. _proto.addScaledVector = function addScaledVector(v, s) {
  1342. this.x += v.x * s;
  1343. this.y += v.y * s;
  1344. this.z += v.z * s;
  1345. this.w += v.w * s;
  1346. return this;
  1347. };
  1348. _proto.sub = function sub(v, w) {
  1349. if (w !== undefined) {
  1350. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1351. return this.subVectors(v, w);
  1352. }
  1353. this.x -= v.x;
  1354. this.y -= v.y;
  1355. this.z -= v.z;
  1356. this.w -= v.w;
  1357. return this;
  1358. };
  1359. _proto.subScalar = function subScalar(s) {
  1360. this.x -= s;
  1361. this.y -= s;
  1362. this.z -= s;
  1363. this.w -= s;
  1364. return this;
  1365. };
  1366. _proto.subVectors = function subVectors(a, b) {
  1367. this.x = a.x - b.x;
  1368. this.y = a.y - b.y;
  1369. this.z = a.z - b.z;
  1370. this.w = a.w - b.w;
  1371. return this;
  1372. };
  1373. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1374. this.x *= scalar;
  1375. this.y *= scalar;
  1376. this.z *= scalar;
  1377. this.w *= scalar;
  1378. return this;
  1379. };
  1380. _proto.applyMatrix4 = function applyMatrix4(m) {
  1381. var x = this.x,
  1382. y = this.y,
  1383. z = this.z,
  1384. w = this.w;
  1385. var e = m.elements;
  1386. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1387. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1388. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1389. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1390. return this;
  1391. };
  1392. _proto.divideScalar = function divideScalar(scalar) {
  1393. return this.multiplyScalar(1 / scalar);
  1394. };
  1395. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1396. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1397. // q is assumed to be normalized
  1398. this.w = 2 * Math.acos(q.w);
  1399. var s = Math.sqrt(1 - q.w * q.w);
  1400. if (s < 0.0001) {
  1401. this.x = 1;
  1402. this.y = 0;
  1403. this.z = 0;
  1404. } else {
  1405. this.x = q.x / s;
  1406. this.y = q.y / s;
  1407. this.z = q.z / s;
  1408. }
  1409. return this;
  1410. };
  1411. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1412. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1413. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1414. var angle, x, y, z; // variables for result
  1415. var epsilon = 0.01,
  1416. // margin to allow for rounding errors
  1417. epsilon2 = 0.1,
  1418. // margin to distinguish between 0 and 180 degrees
  1419. te = m.elements,
  1420. m11 = te[0],
  1421. m12 = te[4],
  1422. m13 = te[8],
  1423. m21 = te[1],
  1424. m22 = te[5],
  1425. m23 = te[9],
  1426. m31 = te[2],
  1427. m32 = te[6],
  1428. m33 = te[10];
  1429. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1430. // singularity found
  1431. // first check for identity matrix which must have +1 for all terms
  1432. // in leading diagonal and zero in other terms
  1433. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1434. // this singularity is identity matrix so angle = 0
  1435. this.set(1, 0, 0, 0);
  1436. return this; // zero angle, arbitrary axis
  1437. } // otherwise this singularity is angle = 180
  1438. angle = Math.PI;
  1439. var xx = (m11 + 1) / 2;
  1440. var yy = (m22 + 1) / 2;
  1441. var zz = (m33 + 1) / 2;
  1442. var xy = (m12 + m21) / 4;
  1443. var xz = (m13 + m31) / 4;
  1444. var yz = (m23 + m32) / 4;
  1445. if (xx > yy && xx > zz) {
  1446. // m11 is the largest diagonal term
  1447. if (xx < epsilon) {
  1448. x = 0;
  1449. y = 0.707106781;
  1450. z = 0.707106781;
  1451. } else {
  1452. x = Math.sqrt(xx);
  1453. y = xy / x;
  1454. z = xz / x;
  1455. }
  1456. } else if (yy > zz) {
  1457. // m22 is the largest diagonal term
  1458. if (yy < epsilon) {
  1459. x = 0.707106781;
  1460. y = 0;
  1461. z = 0.707106781;
  1462. } else {
  1463. y = Math.sqrt(yy);
  1464. x = xy / y;
  1465. z = yz / y;
  1466. }
  1467. } else {
  1468. // m33 is the largest diagonal term so base result on this
  1469. if (zz < epsilon) {
  1470. x = 0.707106781;
  1471. y = 0.707106781;
  1472. z = 0;
  1473. } else {
  1474. z = Math.sqrt(zz);
  1475. x = xz / z;
  1476. y = yz / z;
  1477. }
  1478. }
  1479. this.set(x, y, z, angle);
  1480. return this; // return 180 deg rotation
  1481. } // as we have reached here there are no singularities so we can handle normally
  1482. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1483. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1484. // caught by singularity test above, but I've left it in just in case
  1485. this.x = (m32 - m23) / s;
  1486. this.y = (m13 - m31) / s;
  1487. this.z = (m21 - m12) / s;
  1488. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1489. return this;
  1490. };
  1491. _proto.min = function min(v) {
  1492. this.x = Math.min(this.x, v.x);
  1493. this.y = Math.min(this.y, v.y);
  1494. this.z = Math.min(this.z, v.z);
  1495. this.w = Math.min(this.w, v.w);
  1496. return this;
  1497. };
  1498. _proto.max = function max(v) {
  1499. this.x = Math.max(this.x, v.x);
  1500. this.y = Math.max(this.y, v.y);
  1501. this.z = Math.max(this.z, v.z);
  1502. this.w = Math.max(this.w, v.w);
  1503. return this;
  1504. };
  1505. _proto.clamp = function clamp(min, max) {
  1506. // assumes min < max, componentwise
  1507. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1508. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1509. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1510. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1511. return this;
  1512. };
  1513. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1514. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1515. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1516. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1517. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1518. return this;
  1519. };
  1520. _proto.clampLength = function clampLength(min, max) {
  1521. var length = this.length();
  1522. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1523. };
  1524. _proto.floor = function floor() {
  1525. this.x = Math.floor(this.x);
  1526. this.y = Math.floor(this.y);
  1527. this.z = Math.floor(this.z);
  1528. this.w = Math.floor(this.w);
  1529. return this;
  1530. };
  1531. _proto.ceil = function ceil() {
  1532. this.x = Math.ceil(this.x);
  1533. this.y = Math.ceil(this.y);
  1534. this.z = Math.ceil(this.z);
  1535. this.w = Math.ceil(this.w);
  1536. return this;
  1537. };
  1538. _proto.round = function round() {
  1539. this.x = Math.round(this.x);
  1540. this.y = Math.round(this.y);
  1541. this.z = Math.round(this.z);
  1542. this.w = Math.round(this.w);
  1543. return this;
  1544. };
  1545. _proto.roundToZero = function roundToZero() {
  1546. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1547. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1548. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1549. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1550. return this;
  1551. };
  1552. _proto.negate = function negate() {
  1553. this.x = -this.x;
  1554. this.y = -this.y;
  1555. this.z = -this.z;
  1556. this.w = -this.w;
  1557. return this;
  1558. };
  1559. _proto.dot = function dot(v) {
  1560. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1561. };
  1562. _proto.lengthSq = function lengthSq() {
  1563. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1564. };
  1565. _proto.length = function length() {
  1566. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1567. };
  1568. _proto.manhattanLength = function manhattanLength() {
  1569. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1570. };
  1571. _proto.normalize = function normalize() {
  1572. return this.divideScalar(this.length() || 1);
  1573. };
  1574. _proto.setLength = function setLength(length) {
  1575. return this.normalize().multiplyScalar(length);
  1576. };
  1577. _proto.lerp = function lerp(v, alpha) {
  1578. this.x += (v.x - this.x) * alpha;
  1579. this.y += (v.y - this.y) * alpha;
  1580. this.z += (v.z - this.z) * alpha;
  1581. this.w += (v.w - this.w) * alpha;
  1582. return this;
  1583. };
  1584. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1585. this.x = v1.x + (v2.x - v1.x) * alpha;
  1586. this.y = v1.y + (v2.y - v1.y) * alpha;
  1587. this.z = v1.z + (v2.z - v1.z) * alpha;
  1588. this.w = v1.w + (v2.w - v1.w) * alpha;
  1589. return this;
  1590. };
  1591. _proto.equals = function equals(v) {
  1592. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1593. };
  1594. _proto.fromArray = function fromArray(array, offset) {
  1595. if (offset === void 0) {
  1596. offset = 0;
  1597. }
  1598. this.x = array[offset];
  1599. this.y = array[offset + 1];
  1600. this.z = array[offset + 2];
  1601. this.w = array[offset + 3];
  1602. return this;
  1603. };
  1604. _proto.toArray = function toArray(array, offset) {
  1605. if (array === void 0) {
  1606. array = [];
  1607. }
  1608. if (offset === void 0) {
  1609. offset = 0;
  1610. }
  1611. array[offset] = this.x;
  1612. array[offset + 1] = this.y;
  1613. array[offset + 2] = this.z;
  1614. array[offset + 3] = this.w;
  1615. return array;
  1616. };
  1617. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1618. if (offset !== undefined) {
  1619. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1620. }
  1621. this.x = attribute.getX(index);
  1622. this.y = attribute.getY(index);
  1623. this.z = attribute.getZ(index);
  1624. this.w = attribute.getW(index);
  1625. return this;
  1626. };
  1627. _proto.random = function random() {
  1628. this.x = Math.random();
  1629. this.y = Math.random();
  1630. this.z = Math.random();
  1631. this.w = Math.random();
  1632. return this;
  1633. };
  1634. _createClass(Vector4, [{
  1635. key: "width",
  1636. get: function get() {
  1637. return this.z;
  1638. },
  1639. set: function set(value) {
  1640. this.z = value;
  1641. }
  1642. }, {
  1643. key: "height",
  1644. get: function get() {
  1645. return this.w;
  1646. },
  1647. set: function set(value) {
  1648. this.w = value;
  1649. }
  1650. }]);
  1651. return Vector4;
  1652. }();
  1653. /*
  1654. In options, we can specify:
  1655. * Texture parameters for an auto-generated target texture
  1656. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1657. */
  1658. function WebGLRenderTarget(width, height, options) {
  1659. this.width = width;
  1660. this.height = height;
  1661. this.scissor = new Vector4(0, 0, width, height);
  1662. this.scissorTest = false;
  1663. this.viewport = new Vector4(0, 0, width, height);
  1664. options = options || {};
  1665. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1666. this.texture.image = {};
  1667. this.texture.image.width = width;
  1668. this.texture.image.height = height;
  1669. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1670. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1671. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1672. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1673. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1674. }
  1675. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1676. constructor: WebGLRenderTarget,
  1677. isWebGLRenderTarget: true,
  1678. setSize: function setSize(width, height) {
  1679. if (this.width !== width || this.height !== height) {
  1680. this.width = width;
  1681. this.height = height;
  1682. this.texture.image.width = width;
  1683. this.texture.image.height = height;
  1684. this.dispose();
  1685. }
  1686. this.viewport.set(0, 0, width, height);
  1687. this.scissor.set(0, 0, width, height);
  1688. },
  1689. clone: function clone() {
  1690. return new this.constructor().copy(this);
  1691. },
  1692. copy: function copy(source) {
  1693. this.width = source.width;
  1694. this.height = source.height;
  1695. this.viewport.copy(source.viewport);
  1696. this.texture = source.texture.clone();
  1697. this.depthBuffer = source.depthBuffer;
  1698. this.stencilBuffer = source.stencilBuffer;
  1699. this.depthTexture = source.depthTexture;
  1700. return this;
  1701. },
  1702. dispose: function dispose() {
  1703. this.dispatchEvent({
  1704. type: 'dispose'
  1705. });
  1706. }
  1707. });
  1708. function WebGLMultisampleRenderTarget(width, height, options) {
  1709. WebGLRenderTarget.call(this, width, height, options);
  1710. this.samples = 4;
  1711. }
  1712. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1713. constructor: WebGLMultisampleRenderTarget,
  1714. isWebGLMultisampleRenderTarget: true,
  1715. copy: function copy(source) {
  1716. WebGLRenderTarget.prototype.copy.call(this, source);
  1717. this.samples = source.samples;
  1718. return this;
  1719. }
  1720. });
  1721. var Quaternion = /*#__PURE__*/function () {
  1722. function Quaternion(x, y, z, w) {
  1723. if (x === void 0) {
  1724. x = 0;
  1725. }
  1726. if (y === void 0) {
  1727. y = 0;
  1728. }
  1729. if (z === void 0) {
  1730. z = 0;
  1731. }
  1732. if (w === void 0) {
  1733. w = 1;
  1734. }
  1735. Object.defineProperty(this, 'isQuaternion', {
  1736. value: true
  1737. });
  1738. this._x = x;
  1739. this._y = y;
  1740. this._z = z;
  1741. this._w = w;
  1742. }
  1743. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1744. return qm.copy(qa).slerp(qb, t);
  1745. };
  1746. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1747. // fuzz-free, array-based Quaternion SLERP operation
  1748. var x0 = src0[srcOffset0 + 0],
  1749. y0 = src0[srcOffset0 + 1],
  1750. z0 = src0[srcOffset0 + 2],
  1751. w0 = src0[srcOffset0 + 3];
  1752. var x1 = src1[srcOffset1 + 0],
  1753. y1 = src1[srcOffset1 + 1],
  1754. z1 = src1[srcOffset1 + 2],
  1755. w1 = src1[srcOffset1 + 3];
  1756. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1757. var s = 1 - t;
  1758. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1759. dir = cos >= 0 ? 1 : -1,
  1760. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1761. if (sqrSin > Number.EPSILON) {
  1762. var sin = Math.sqrt(sqrSin),
  1763. len = Math.atan2(sin, cos * dir);
  1764. s = Math.sin(s * len) / sin;
  1765. t = Math.sin(t * len) / sin;
  1766. }
  1767. var tDir = t * dir;
  1768. x0 = x0 * s + x1 * tDir;
  1769. y0 = y0 * s + y1 * tDir;
  1770. z0 = z0 * s + z1 * tDir;
  1771. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1772. if (s === 1 - t) {
  1773. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1774. x0 *= f;
  1775. y0 *= f;
  1776. z0 *= f;
  1777. w0 *= f;
  1778. }
  1779. }
  1780. dst[dstOffset] = x0;
  1781. dst[dstOffset + 1] = y0;
  1782. dst[dstOffset + 2] = z0;
  1783. dst[dstOffset + 3] = w0;
  1784. };
  1785. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1786. var x0 = src0[srcOffset0];
  1787. var y0 = src0[srcOffset0 + 1];
  1788. var z0 = src0[srcOffset0 + 2];
  1789. var w0 = src0[srcOffset0 + 3];
  1790. var x1 = src1[srcOffset1];
  1791. var y1 = src1[srcOffset1 + 1];
  1792. var z1 = src1[srcOffset1 + 2];
  1793. var w1 = src1[srcOffset1 + 3];
  1794. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1795. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1796. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1797. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1798. return dst;
  1799. };
  1800. var _proto = Quaternion.prototype;
  1801. _proto.set = function set(x, y, z, w) {
  1802. this._x = x;
  1803. this._y = y;
  1804. this._z = z;
  1805. this._w = w;
  1806. this._onChangeCallback();
  1807. return this;
  1808. };
  1809. _proto.clone = function clone() {
  1810. return new this.constructor(this._x, this._y, this._z, this._w);
  1811. };
  1812. _proto.copy = function copy(quaternion) {
  1813. this._x = quaternion.x;
  1814. this._y = quaternion.y;
  1815. this._z = quaternion.z;
  1816. this._w = quaternion.w;
  1817. this._onChangeCallback();
  1818. return this;
  1819. };
  1820. _proto.setFromEuler = function setFromEuler(euler, update) {
  1821. if (!(euler && euler.isEuler)) {
  1822. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1823. }
  1824. var x = euler._x,
  1825. y = euler._y,
  1826. z = euler._z,
  1827. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1828. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1829. // content/SpinCalc.m
  1830. var cos = Math.cos;
  1831. var sin = Math.sin;
  1832. var c1 = cos(x / 2);
  1833. var c2 = cos(y / 2);
  1834. var c3 = cos(z / 2);
  1835. var s1 = sin(x / 2);
  1836. var s2 = sin(y / 2);
  1837. var s3 = sin(z / 2);
  1838. switch (order) {
  1839. case 'XYZ':
  1840. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1841. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1842. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1843. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1844. break;
  1845. case 'YXZ':
  1846. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1847. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1848. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1849. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1850. break;
  1851. case 'ZXY':
  1852. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1853. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1854. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1855. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1856. break;
  1857. case 'ZYX':
  1858. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1859. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1860. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1861. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1862. break;
  1863. case 'YZX':
  1864. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1865. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1866. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1867. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1868. break;
  1869. case 'XZY':
  1870. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1871. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1872. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1873. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1874. break;
  1875. default:
  1876. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1877. }
  1878. if (update !== false) this._onChangeCallback();
  1879. return this;
  1880. };
  1881. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1882. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1883. // assumes axis is normalized
  1884. var halfAngle = angle / 2,
  1885. s = Math.sin(halfAngle);
  1886. this._x = axis.x * s;
  1887. this._y = axis.y * s;
  1888. this._z = axis.z * s;
  1889. this._w = Math.cos(halfAngle);
  1890. this._onChangeCallback();
  1891. return this;
  1892. };
  1893. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1894. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1895. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1896. var te = m.elements,
  1897. m11 = te[0],
  1898. m12 = te[4],
  1899. m13 = te[8],
  1900. m21 = te[1],
  1901. m22 = te[5],
  1902. m23 = te[9],
  1903. m31 = te[2],
  1904. m32 = te[6],
  1905. m33 = te[10],
  1906. trace = m11 + m22 + m33;
  1907. if (trace > 0) {
  1908. var s = 0.5 / Math.sqrt(trace + 1.0);
  1909. this._w = 0.25 / s;
  1910. this._x = (m32 - m23) * s;
  1911. this._y = (m13 - m31) * s;
  1912. this._z = (m21 - m12) * s;
  1913. } else if (m11 > m22 && m11 > m33) {
  1914. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1915. this._w = (m32 - m23) / _s;
  1916. this._x = 0.25 * _s;
  1917. this._y = (m12 + m21) / _s;
  1918. this._z = (m13 + m31) / _s;
  1919. } else if (m22 > m33) {
  1920. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1921. this._w = (m13 - m31) / _s2;
  1922. this._x = (m12 + m21) / _s2;
  1923. this._y = 0.25 * _s2;
  1924. this._z = (m23 + m32) / _s2;
  1925. } else {
  1926. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1927. this._w = (m21 - m12) / _s3;
  1928. this._x = (m13 + m31) / _s3;
  1929. this._y = (m23 + m32) / _s3;
  1930. this._z = 0.25 * _s3;
  1931. }
  1932. this._onChangeCallback();
  1933. return this;
  1934. };
  1935. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1936. // assumes direction vectors vFrom and vTo are normalized
  1937. var EPS = 0.000001;
  1938. var r = vFrom.dot(vTo) + 1;
  1939. if (r < EPS) {
  1940. r = 0;
  1941. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1942. this._x = -vFrom.y;
  1943. this._y = vFrom.x;
  1944. this._z = 0;
  1945. this._w = r;
  1946. } else {
  1947. this._x = 0;
  1948. this._y = -vFrom.z;
  1949. this._z = vFrom.y;
  1950. this._w = r;
  1951. }
  1952. } else {
  1953. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1954. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1955. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1956. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1957. this._w = r;
  1958. }
  1959. return this.normalize();
  1960. };
  1961. _proto.angleTo = function angleTo(q) {
  1962. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  1963. };
  1964. _proto.rotateTowards = function rotateTowards(q, step) {
  1965. var angle = this.angleTo(q);
  1966. if (angle === 0) return this;
  1967. var t = Math.min(1, step / angle);
  1968. this.slerp(q, t);
  1969. return this;
  1970. };
  1971. _proto.identity = function identity() {
  1972. return this.set(0, 0, 0, 1);
  1973. };
  1974. _proto.inverse = function inverse() {
  1975. // quaternion is assumed to have unit length
  1976. return this.conjugate();
  1977. };
  1978. _proto.conjugate = function conjugate() {
  1979. this._x *= -1;
  1980. this._y *= -1;
  1981. this._z *= -1;
  1982. this._onChangeCallback();
  1983. return this;
  1984. };
  1985. _proto.dot = function dot(v) {
  1986. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1987. };
  1988. _proto.lengthSq = function lengthSq() {
  1989. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1990. };
  1991. _proto.length = function length() {
  1992. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  1993. };
  1994. _proto.normalize = function normalize() {
  1995. var l = this.length();
  1996. if (l === 0) {
  1997. this._x = 0;
  1998. this._y = 0;
  1999. this._z = 0;
  2000. this._w = 1;
  2001. } else {
  2002. l = 1 / l;
  2003. this._x = this._x * l;
  2004. this._y = this._y * l;
  2005. this._z = this._z * l;
  2006. this._w = this._w * l;
  2007. }
  2008. this._onChangeCallback();
  2009. return this;
  2010. };
  2011. _proto.multiply = function multiply(q, p) {
  2012. if (p !== undefined) {
  2013. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2014. return this.multiplyQuaternions(q, p);
  2015. }
  2016. return this.multiplyQuaternions(this, q);
  2017. };
  2018. _proto.premultiply = function premultiply(q) {
  2019. return this.multiplyQuaternions(q, this);
  2020. };
  2021. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2022. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2023. var qax = a._x,
  2024. qay = a._y,
  2025. qaz = a._z,
  2026. qaw = a._w;
  2027. var qbx = b._x,
  2028. qby = b._y,
  2029. qbz = b._z,
  2030. qbw = b._w;
  2031. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2032. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2033. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2034. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2035. this._onChangeCallback();
  2036. return this;
  2037. };
  2038. _proto.slerp = function slerp(qb, t) {
  2039. if (t === 0) return this;
  2040. if (t === 1) return this.copy(qb);
  2041. var x = this._x,
  2042. y = this._y,
  2043. z = this._z,
  2044. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2045. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2046. if (cosHalfTheta < 0) {
  2047. this._w = -qb._w;
  2048. this._x = -qb._x;
  2049. this._y = -qb._y;
  2050. this._z = -qb._z;
  2051. cosHalfTheta = -cosHalfTheta;
  2052. } else {
  2053. this.copy(qb);
  2054. }
  2055. if (cosHalfTheta >= 1.0) {
  2056. this._w = w;
  2057. this._x = x;
  2058. this._y = y;
  2059. this._z = z;
  2060. return this;
  2061. }
  2062. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2063. if (sqrSinHalfTheta <= Number.EPSILON) {
  2064. var s = 1 - t;
  2065. this._w = s * w + t * this._w;
  2066. this._x = s * x + t * this._x;
  2067. this._y = s * y + t * this._y;
  2068. this._z = s * z + t * this._z;
  2069. this.normalize();
  2070. this._onChangeCallback();
  2071. return this;
  2072. }
  2073. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2074. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2075. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2076. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2077. this._w = w * ratioA + this._w * ratioB;
  2078. this._x = x * ratioA + this._x * ratioB;
  2079. this._y = y * ratioA + this._y * ratioB;
  2080. this._z = z * ratioA + this._z * ratioB;
  2081. this._onChangeCallback();
  2082. return this;
  2083. };
  2084. _proto.equals = function equals(quaternion) {
  2085. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2086. };
  2087. _proto.fromArray = function fromArray(array, offset) {
  2088. if (offset === void 0) {
  2089. offset = 0;
  2090. }
  2091. this._x = array[offset];
  2092. this._y = array[offset + 1];
  2093. this._z = array[offset + 2];
  2094. this._w = array[offset + 3];
  2095. this._onChangeCallback();
  2096. return this;
  2097. };
  2098. _proto.toArray = function toArray(array, offset) {
  2099. if (array === void 0) {
  2100. array = [];
  2101. }
  2102. if (offset === void 0) {
  2103. offset = 0;
  2104. }
  2105. array[offset] = this._x;
  2106. array[offset + 1] = this._y;
  2107. array[offset + 2] = this._z;
  2108. array[offset + 3] = this._w;
  2109. return array;
  2110. };
  2111. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2112. this._x = attribute.getX(index);
  2113. this._y = attribute.getY(index);
  2114. this._z = attribute.getZ(index);
  2115. this._w = attribute.getW(index);
  2116. return this;
  2117. };
  2118. _proto._onChange = function _onChange(callback) {
  2119. this._onChangeCallback = callback;
  2120. return this;
  2121. };
  2122. _proto._onChangeCallback = function _onChangeCallback() {};
  2123. _createClass(Quaternion, [{
  2124. key: "x",
  2125. get: function get() {
  2126. return this._x;
  2127. },
  2128. set: function set(value) {
  2129. this._x = value;
  2130. this._onChangeCallback();
  2131. }
  2132. }, {
  2133. key: "y",
  2134. get: function get() {
  2135. return this._y;
  2136. },
  2137. set: function set(value) {
  2138. this._y = value;
  2139. this._onChangeCallback();
  2140. }
  2141. }, {
  2142. key: "z",
  2143. get: function get() {
  2144. return this._z;
  2145. },
  2146. set: function set(value) {
  2147. this._z = value;
  2148. this._onChangeCallback();
  2149. }
  2150. }, {
  2151. key: "w",
  2152. get: function get() {
  2153. return this._w;
  2154. },
  2155. set: function set(value) {
  2156. this._w = value;
  2157. this._onChangeCallback();
  2158. }
  2159. }]);
  2160. return Quaternion;
  2161. }();
  2162. var Vector3 = /*#__PURE__*/function () {
  2163. function Vector3(x, y, z) {
  2164. if (x === void 0) {
  2165. x = 0;
  2166. }
  2167. if (y === void 0) {
  2168. y = 0;
  2169. }
  2170. if (z === void 0) {
  2171. z = 0;
  2172. }
  2173. Object.defineProperty(this, 'isVector3', {
  2174. value: true
  2175. });
  2176. this.x = x;
  2177. this.y = y;
  2178. this.z = z;
  2179. }
  2180. var _proto = Vector3.prototype;
  2181. _proto.set = function set(x, y, z) {
  2182. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2183. this.x = x;
  2184. this.y = y;
  2185. this.z = z;
  2186. return this;
  2187. };
  2188. _proto.setScalar = function setScalar(scalar) {
  2189. this.x = scalar;
  2190. this.y = scalar;
  2191. this.z = scalar;
  2192. return this;
  2193. };
  2194. _proto.setX = function setX(x) {
  2195. this.x = x;
  2196. return this;
  2197. };
  2198. _proto.setY = function setY(y) {
  2199. this.y = y;
  2200. return this;
  2201. };
  2202. _proto.setZ = function setZ(z) {
  2203. this.z = z;
  2204. return this;
  2205. };
  2206. _proto.setComponent = function setComponent(index, value) {
  2207. switch (index) {
  2208. case 0:
  2209. this.x = value;
  2210. break;
  2211. case 1:
  2212. this.y = value;
  2213. break;
  2214. case 2:
  2215. this.z = value;
  2216. break;
  2217. default:
  2218. throw new Error('index is out of range: ' + index);
  2219. }
  2220. return this;
  2221. };
  2222. _proto.getComponent = function getComponent(index) {
  2223. switch (index) {
  2224. case 0:
  2225. return this.x;
  2226. case 1:
  2227. return this.y;
  2228. case 2:
  2229. return this.z;
  2230. default:
  2231. throw new Error('index is out of range: ' + index);
  2232. }
  2233. };
  2234. _proto.clone = function clone() {
  2235. return new this.constructor(this.x, this.y, this.z);
  2236. };
  2237. _proto.copy = function copy(v) {
  2238. this.x = v.x;
  2239. this.y = v.y;
  2240. this.z = v.z;
  2241. return this;
  2242. };
  2243. _proto.add = function add(v, w) {
  2244. if (w !== undefined) {
  2245. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2246. return this.addVectors(v, w);
  2247. }
  2248. this.x += v.x;
  2249. this.y += v.y;
  2250. this.z += v.z;
  2251. return this;
  2252. };
  2253. _proto.addScalar = function addScalar(s) {
  2254. this.x += s;
  2255. this.y += s;
  2256. this.z += s;
  2257. return this;
  2258. };
  2259. _proto.addVectors = function addVectors(a, b) {
  2260. this.x = a.x + b.x;
  2261. this.y = a.y + b.y;
  2262. this.z = a.z + b.z;
  2263. return this;
  2264. };
  2265. _proto.addScaledVector = function addScaledVector(v, s) {
  2266. this.x += v.x * s;
  2267. this.y += v.y * s;
  2268. this.z += v.z * s;
  2269. return this;
  2270. };
  2271. _proto.sub = function sub(v, w) {
  2272. if (w !== undefined) {
  2273. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2274. return this.subVectors(v, w);
  2275. }
  2276. this.x -= v.x;
  2277. this.y -= v.y;
  2278. this.z -= v.z;
  2279. return this;
  2280. };
  2281. _proto.subScalar = function subScalar(s) {
  2282. this.x -= s;
  2283. this.y -= s;
  2284. this.z -= s;
  2285. return this;
  2286. };
  2287. _proto.subVectors = function subVectors(a, b) {
  2288. this.x = a.x - b.x;
  2289. this.y = a.y - b.y;
  2290. this.z = a.z - b.z;
  2291. return this;
  2292. };
  2293. _proto.multiply = function multiply(v, w) {
  2294. if (w !== undefined) {
  2295. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2296. return this.multiplyVectors(v, w);
  2297. }
  2298. this.x *= v.x;
  2299. this.y *= v.y;
  2300. this.z *= v.z;
  2301. return this;
  2302. };
  2303. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2304. this.x *= scalar;
  2305. this.y *= scalar;
  2306. this.z *= scalar;
  2307. return this;
  2308. };
  2309. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2310. this.x = a.x * b.x;
  2311. this.y = a.y * b.y;
  2312. this.z = a.z * b.z;
  2313. return this;
  2314. };
  2315. _proto.applyEuler = function applyEuler(euler) {
  2316. if (!(euler && euler.isEuler)) {
  2317. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2318. }
  2319. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2320. };
  2321. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2322. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2323. };
  2324. _proto.applyMatrix3 = function applyMatrix3(m) {
  2325. var x = this.x,
  2326. y = this.y,
  2327. z = this.z;
  2328. var e = m.elements;
  2329. this.x = e[0] * x + e[3] * y + e[6] * z;
  2330. this.y = e[1] * x + e[4] * y + e[7] * z;
  2331. this.z = e[2] * x + e[5] * y + e[8] * z;
  2332. return this;
  2333. };
  2334. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2335. return this.applyMatrix3(m).normalize();
  2336. };
  2337. _proto.applyMatrix4 = function applyMatrix4(m) {
  2338. var x = this.x,
  2339. y = this.y,
  2340. z = this.z;
  2341. var e = m.elements;
  2342. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2343. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2344. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2345. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2346. return this;
  2347. };
  2348. _proto.applyQuaternion = function applyQuaternion(q) {
  2349. var x = this.x,
  2350. y = this.y,
  2351. z = this.z;
  2352. var qx = q.x,
  2353. qy = q.y,
  2354. qz = q.z,
  2355. qw = q.w; // calculate quat * vector
  2356. var ix = qw * x + qy * z - qz * y;
  2357. var iy = qw * y + qz * x - qx * z;
  2358. var iz = qw * z + qx * y - qy * x;
  2359. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2360. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2361. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2362. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2363. return this;
  2364. };
  2365. _proto.project = function project(camera) {
  2366. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2367. };
  2368. _proto.unproject = function unproject(camera) {
  2369. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2370. };
  2371. _proto.transformDirection = function transformDirection(m) {
  2372. // input: THREE.Matrix4 affine matrix
  2373. // vector interpreted as a direction
  2374. var x = this.x,
  2375. y = this.y,
  2376. z = this.z;
  2377. var e = m.elements;
  2378. this.x = e[0] * x + e[4] * y + e[8] * z;
  2379. this.y = e[1] * x + e[5] * y + e[9] * z;
  2380. this.z = e[2] * x + e[6] * y + e[10] * z;
  2381. return this.normalize();
  2382. };
  2383. _proto.divide = function divide(v) {
  2384. this.x /= v.x;
  2385. this.y /= v.y;
  2386. this.z /= v.z;
  2387. return this;
  2388. };
  2389. _proto.divideScalar = function divideScalar(scalar) {
  2390. return this.multiplyScalar(1 / scalar);
  2391. };
  2392. _proto.min = function min(v) {
  2393. this.x = Math.min(this.x, v.x);
  2394. this.y = Math.min(this.y, v.y);
  2395. this.z = Math.min(this.z, v.z);
  2396. return this;
  2397. };
  2398. _proto.max = function max(v) {
  2399. this.x = Math.max(this.x, v.x);
  2400. this.y = Math.max(this.y, v.y);
  2401. this.z = Math.max(this.z, v.z);
  2402. return this;
  2403. };
  2404. _proto.clamp = function clamp(min, max) {
  2405. // assumes min < max, componentwise
  2406. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2407. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2408. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2409. return this;
  2410. };
  2411. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2412. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2413. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2414. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2415. return this;
  2416. };
  2417. _proto.clampLength = function clampLength(min, max) {
  2418. var length = this.length();
  2419. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2420. };
  2421. _proto.floor = function floor() {
  2422. this.x = Math.floor(this.x);
  2423. this.y = Math.floor(this.y);
  2424. this.z = Math.floor(this.z);
  2425. return this;
  2426. };
  2427. _proto.ceil = function ceil() {
  2428. this.x = Math.ceil(this.x);
  2429. this.y = Math.ceil(this.y);
  2430. this.z = Math.ceil(this.z);
  2431. return this;
  2432. };
  2433. _proto.round = function round() {
  2434. this.x = Math.round(this.x);
  2435. this.y = Math.round(this.y);
  2436. this.z = Math.round(this.z);
  2437. return this;
  2438. };
  2439. _proto.roundToZero = function roundToZero() {
  2440. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2441. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2442. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2443. return this;
  2444. };
  2445. _proto.negate = function negate() {
  2446. this.x = -this.x;
  2447. this.y = -this.y;
  2448. this.z = -this.z;
  2449. return this;
  2450. };
  2451. _proto.dot = function dot(v) {
  2452. return this.x * v.x + this.y * v.y + this.z * v.z;
  2453. } // TODO lengthSquared?
  2454. ;
  2455. _proto.lengthSq = function lengthSq() {
  2456. return this.x * this.x + this.y * this.y + this.z * this.z;
  2457. };
  2458. _proto.length = function length() {
  2459. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2460. };
  2461. _proto.manhattanLength = function manhattanLength() {
  2462. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2463. };
  2464. _proto.normalize = function normalize() {
  2465. return this.divideScalar(this.length() || 1);
  2466. };
  2467. _proto.setLength = function setLength(length) {
  2468. return this.normalize().multiplyScalar(length);
  2469. };
  2470. _proto.lerp = function lerp(v, alpha) {
  2471. this.x += (v.x - this.x) * alpha;
  2472. this.y += (v.y - this.y) * alpha;
  2473. this.z += (v.z - this.z) * alpha;
  2474. return this;
  2475. };
  2476. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2477. this.x = v1.x + (v2.x - v1.x) * alpha;
  2478. this.y = v1.y + (v2.y - v1.y) * alpha;
  2479. this.z = v1.z + (v2.z - v1.z) * alpha;
  2480. return this;
  2481. };
  2482. _proto.cross = function cross(v, w) {
  2483. if (w !== undefined) {
  2484. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2485. return this.crossVectors(v, w);
  2486. }
  2487. return this.crossVectors(this, v);
  2488. };
  2489. _proto.crossVectors = function crossVectors(a, b) {
  2490. var ax = a.x,
  2491. ay = a.y,
  2492. az = a.z;
  2493. var bx = b.x,
  2494. by = b.y,
  2495. bz = b.z;
  2496. this.x = ay * bz - az * by;
  2497. this.y = az * bx - ax * bz;
  2498. this.z = ax * by - ay * bx;
  2499. return this;
  2500. };
  2501. _proto.projectOnVector = function projectOnVector(v) {
  2502. var denominator = v.lengthSq();
  2503. if (denominator === 0) return this.set(0, 0, 0);
  2504. var scalar = v.dot(this) / denominator;
  2505. return this.copy(v).multiplyScalar(scalar);
  2506. };
  2507. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2508. _vector.copy(this).projectOnVector(planeNormal);
  2509. return this.sub(_vector);
  2510. };
  2511. _proto.reflect = function reflect(normal) {
  2512. // reflect incident vector off plane orthogonal to normal
  2513. // normal is assumed to have unit length
  2514. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2515. };
  2516. _proto.angleTo = function angleTo(v) {
  2517. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2518. if (denominator === 0) return Math.PI / 2;
  2519. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2520. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2521. };
  2522. _proto.distanceTo = function distanceTo(v) {
  2523. return Math.sqrt(this.distanceToSquared(v));
  2524. };
  2525. _proto.distanceToSquared = function distanceToSquared(v) {
  2526. var dx = this.x - v.x,
  2527. dy = this.y - v.y,
  2528. dz = this.z - v.z;
  2529. return dx * dx + dy * dy + dz * dz;
  2530. };
  2531. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2532. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2533. };
  2534. _proto.setFromSpherical = function setFromSpherical(s) {
  2535. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2536. };
  2537. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2538. var sinPhiRadius = Math.sin(phi) * radius;
  2539. this.x = sinPhiRadius * Math.sin(theta);
  2540. this.y = Math.cos(phi) * radius;
  2541. this.z = sinPhiRadius * Math.cos(theta);
  2542. return this;
  2543. };
  2544. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2545. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2546. };
  2547. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2548. this.x = radius * Math.sin(theta);
  2549. this.y = y;
  2550. this.z = radius * Math.cos(theta);
  2551. return this;
  2552. };
  2553. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2554. var e = m.elements;
  2555. this.x = e[12];
  2556. this.y = e[13];
  2557. this.z = e[14];
  2558. return this;
  2559. };
  2560. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2561. var sx = this.setFromMatrixColumn(m, 0).length();
  2562. var sy = this.setFromMatrixColumn(m, 1).length();
  2563. var sz = this.setFromMatrixColumn(m, 2).length();
  2564. this.x = sx;
  2565. this.y = sy;
  2566. this.z = sz;
  2567. return this;
  2568. };
  2569. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2570. return this.fromArray(m.elements, index * 4);
  2571. };
  2572. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2573. return this.fromArray(m.elements, index * 3);
  2574. };
  2575. _proto.equals = function equals(v) {
  2576. return v.x === this.x && v.y === this.y && v.z === this.z;
  2577. };
  2578. _proto.fromArray = function fromArray(array, offset) {
  2579. if (offset === void 0) {
  2580. offset = 0;
  2581. }
  2582. this.x = array[offset];
  2583. this.y = array[offset + 1];
  2584. this.z = array[offset + 2];
  2585. return this;
  2586. };
  2587. _proto.toArray = function toArray(array, offset) {
  2588. if (array === void 0) {
  2589. array = [];
  2590. }
  2591. if (offset === void 0) {
  2592. offset = 0;
  2593. }
  2594. array[offset] = this.x;
  2595. array[offset + 1] = this.y;
  2596. array[offset + 2] = this.z;
  2597. return array;
  2598. };
  2599. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2600. if (offset !== undefined) {
  2601. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2602. }
  2603. this.x = attribute.getX(index);
  2604. this.y = attribute.getY(index);
  2605. this.z = attribute.getZ(index);
  2606. return this;
  2607. };
  2608. _proto.random = function random() {
  2609. this.x = Math.random();
  2610. this.y = Math.random();
  2611. this.z = Math.random();
  2612. return this;
  2613. };
  2614. return Vector3;
  2615. }();
  2616. var _vector = /*@__PURE__*/new Vector3();
  2617. var _quaternion = /*@__PURE__*/new Quaternion();
  2618. var Box3 = /*#__PURE__*/function () {
  2619. function Box3(min, max) {
  2620. Object.defineProperty(this, 'isBox3', {
  2621. value: true
  2622. });
  2623. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2624. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2625. }
  2626. var _proto = Box3.prototype;
  2627. _proto.set = function set(min, max) {
  2628. this.min.copy(min);
  2629. this.max.copy(max);
  2630. return this;
  2631. };
  2632. _proto.setFromArray = function setFromArray(array) {
  2633. var minX = +Infinity;
  2634. var minY = +Infinity;
  2635. var minZ = +Infinity;
  2636. var maxX = -Infinity;
  2637. var maxY = -Infinity;
  2638. var maxZ = -Infinity;
  2639. for (var i = 0, l = array.length; i < l; i += 3) {
  2640. var x = array[i];
  2641. var y = array[i + 1];
  2642. var z = array[i + 2];
  2643. if (x < minX) minX = x;
  2644. if (y < minY) minY = y;
  2645. if (z < minZ) minZ = z;
  2646. if (x > maxX) maxX = x;
  2647. if (y > maxY) maxY = y;
  2648. if (z > maxZ) maxZ = z;
  2649. }
  2650. this.min.set(minX, minY, minZ);
  2651. this.max.set(maxX, maxY, maxZ);
  2652. return this;
  2653. };
  2654. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2655. var minX = +Infinity;
  2656. var minY = +Infinity;
  2657. var minZ = +Infinity;
  2658. var maxX = -Infinity;
  2659. var maxY = -Infinity;
  2660. var maxZ = -Infinity;
  2661. for (var i = 0, l = attribute.count; i < l; i++) {
  2662. var x = attribute.getX(i);
  2663. var y = attribute.getY(i);
  2664. var z = attribute.getZ(i);
  2665. if (x < minX) minX = x;
  2666. if (y < minY) minY = y;
  2667. if (z < minZ) minZ = z;
  2668. if (x > maxX) maxX = x;
  2669. if (y > maxY) maxY = y;
  2670. if (z > maxZ) maxZ = z;
  2671. }
  2672. this.min.set(minX, minY, minZ);
  2673. this.max.set(maxX, maxY, maxZ);
  2674. return this;
  2675. };
  2676. _proto.setFromPoints = function setFromPoints(points) {
  2677. this.makeEmpty();
  2678. for (var i = 0, il = points.length; i < il; i++) {
  2679. this.expandByPoint(points[i]);
  2680. }
  2681. return this;
  2682. };
  2683. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2684. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2685. this.min.copy(center).sub(halfSize);
  2686. this.max.copy(center).add(halfSize);
  2687. return this;
  2688. };
  2689. _proto.setFromObject = function setFromObject(object) {
  2690. this.makeEmpty();
  2691. return this.expandByObject(object);
  2692. };
  2693. _proto.clone = function clone() {
  2694. return new this.constructor().copy(this);
  2695. };
  2696. _proto.copy = function copy(box) {
  2697. this.min.copy(box.min);
  2698. this.max.copy(box.max);
  2699. return this;
  2700. };
  2701. _proto.makeEmpty = function makeEmpty() {
  2702. this.min.x = this.min.y = this.min.z = +Infinity;
  2703. this.max.x = this.max.y = this.max.z = -Infinity;
  2704. return this;
  2705. };
  2706. _proto.isEmpty = function isEmpty() {
  2707. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2708. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2709. };
  2710. _proto.getCenter = function getCenter(target) {
  2711. if (target === undefined) {
  2712. console.warn('THREE.Box3: .getCenter() target is now required');
  2713. target = new Vector3();
  2714. }
  2715. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2716. };
  2717. _proto.getSize = function getSize(target) {
  2718. if (target === undefined) {
  2719. console.warn('THREE.Box3: .getSize() target is now required');
  2720. target = new Vector3();
  2721. }
  2722. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2723. };
  2724. _proto.expandByPoint = function expandByPoint(point) {
  2725. this.min.min(point);
  2726. this.max.max(point);
  2727. return this;
  2728. };
  2729. _proto.expandByVector = function expandByVector(vector) {
  2730. this.min.sub(vector);
  2731. this.max.add(vector);
  2732. return this;
  2733. };
  2734. _proto.expandByScalar = function expandByScalar(scalar) {
  2735. this.min.addScalar(-scalar);
  2736. this.max.addScalar(scalar);
  2737. return this;
  2738. };
  2739. _proto.expandByObject = function expandByObject(object) {
  2740. // Computes the world-axis-aligned bounding box of an object (including its children),
  2741. // accounting for both the object's, and children's, world transforms
  2742. object.updateWorldMatrix(false, false);
  2743. var geometry = object.geometry;
  2744. if (geometry !== undefined) {
  2745. if (geometry.boundingBox === null) {
  2746. geometry.computeBoundingBox();
  2747. }
  2748. _box.copy(geometry.boundingBox);
  2749. _box.applyMatrix4(object.matrixWorld);
  2750. this.union(_box);
  2751. }
  2752. var children = object.children;
  2753. for (var i = 0, l = children.length; i < l; i++) {
  2754. this.expandByObject(children[i]);
  2755. }
  2756. return this;
  2757. };
  2758. _proto.containsPoint = function containsPoint(point) {
  2759. 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;
  2760. };
  2761. _proto.containsBox = function containsBox(box) {
  2762. 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;
  2763. };
  2764. _proto.getParameter = function getParameter(point, target) {
  2765. // This can potentially have a divide by zero if the box
  2766. // has a size dimension of 0.
  2767. if (target === undefined) {
  2768. console.warn('THREE.Box3: .getParameter() target is now required');
  2769. target = new Vector3();
  2770. }
  2771. 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));
  2772. };
  2773. _proto.intersectsBox = function intersectsBox(box) {
  2774. // using 6 splitting planes to rule out intersections.
  2775. 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;
  2776. };
  2777. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2778. // Find the point on the AABB closest to the sphere center.
  2779. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2780. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2781. };
  2782. _proto.intersectsPlane = function intersectsPlane(plane) {
  2783. // We compute the minimum and maximum dot product values. If those values
  2784. // are on the same side (back or front) of the plane, then there is no intersection.
  2785. var min, max;
  2786. if (plane.normal.x > 0) {
  2787. min = plane.normal.x * this.min.x;
  2788. max = plane.normal.x * this.max.x;
  2789. } else {
  2790. min = plane.normal.x * this.max.x;
  2791. max = plane.normal.x * this.min.x;
  2792. }
  2793. if (plane.normal.y > 0) {
  2794. min += plane.normal.y * this.min.y;
  2795. max += plane.normal.y * this.max.y;
  2796. } else {
  2797. min += plane.normal.y * this.max.y;
  2798. max += plane.normal.y * this.min.y;
  2799. }
  2800. if (plane.normal.z > 0) {
  2801. min += plane.normal.z * this.min.z;
  2802. max += plane.normal.z * this.max.z;
  2803. } else {
  2804. min += plane.normal.z * this.max.z;
  2805. max += plane.normal.z * this.min.z;
  2806. }
  2807. return min <= -plane.constant && max >= -plane.constant;
  2808. };
  2809. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2810. if (this.isEmpty()) {
  2811. return false;
  2812. } // compute box center and extents
  2813. this.getCenter(_center);
  2814. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2815. _v0.subVectors(triangle.a, _center);
  2816. _v1.subVectors(triangle.b, _center);
  2817. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2818. _f0.subVectors(_v1, _v0);
  2819. _f1.subVectors(_v2, _v1);
  2820. _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
  2821. // 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
  2822. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2823. 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];
  2824. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2825. return false;
  2826. } // test 3 face normals from the aabb
  2827. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2828. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2829. return false;
  2830. } // finally testing the face normal of the triangle
  2831. // use already existing triangle edge vectors here
  2832. _triangleNormal.crossVectors(_f0, _f1);
  2833. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2834. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2835. };
  2836. _proto.clampPoint = function clampPoint(point, target) {
  2837. if (target === undefined) {
  2838. console.warn('THREE.Box3: .clampPoint() target is now required');
  2839. target = new Vector3();
  2840. }
  2841. return target.copy(point).clamp(this.min, this.max);
  2842. };
  2843. _proto.distanceToPoint = function distanceToPoint(point) {
  2844. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2845. return clampedPoint.sub(point).length();
  2846. };
  2847. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2848. if (target === undefined) {
  2849. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2850. }
  2851. this.getCenter(target.center);
  2852. target.radius = this.getSize(_vector$1).length() * 0.5;
  2853. return target;
  2854. };
  2855. _proto.intersect = function intersect(box) {
  2856. this.min.max(box.min);
  2857. 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.
  2858. if (this.isEmpty()) this.makeEmpty();
  2859. return this;
  2860. };
  2861. _proto.union = function union(box) {
  2862. this.min.min(box.min);
  2863. this.max.max(box.max);
  2864. return this;
  2865. };
  2866. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2867. // transform of empty box is an empty box.
  2868. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2869. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2870. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2871. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2872. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2873. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2874. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2875. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2876. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2877. this.setFromPoints(_points);
  2878. return this;
  2879. };
  2880. _proto.translate = function translate(offset) {
  2881. this.min.add(offset);
  2882. this.max.add(offset);
  2883. return this;
  2884. };
  2885. _proto.equals = function equals(box) {
  2886. return box.min.equals(this.min) && box.max.equals(this.max);
  2887. };
  2888. return Box3;
  2889. }();
  2890. function satForAxes(axes, v0, v1, v2, extents) {
  2891. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2892. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2893. 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
  2894. var p0 = v0.dot(_testAxis);
  2895. var p1 = v1.dot(_testAxis);
  2896. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2897. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2898. // points of the projected triangle are outside the projected half-length of the aabb
  2899. // the axis is seperating and we can exit
  2900. return false;
  2901. }
  2902. }
  2903. return true;
  2904. }
  2905. 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()];
  2906. var _vector$1 = /*@__PURE__*/new Vector3();
  2907. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2908. var _v0 = /*@__PURE__*/new Vector3();
  2909. var _v1 = /*@__PURE__*/new Vector3();
  2910. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2911. var _f0 = /*@__PURE__*/new Vector3();
  2912. var _f1 = /*@__PURE__*/new Vector3();
  2913. var _f2 = /*@__PURE__*/new Vector3();
  2914. var _center = /*@__PURE__*/new Vector3();
  2915. var _extents = /*@__PURE__*/new Vector3();
  2916. var _triangleNormal = /*@__PURE__*/new Vector3();
  2917. var _testAxis = /*@__PURE__*/new Vector3();
  2918. var _box$1 = /*@__PURE__*/new Box3();
  2919. var Sphere = /*#__PURE__*/function () {
  2920. function Sphere(center, radius) {
  2921. this.center = center !== undefined ? center : new Vector3();
  2922. this.radius = radius !== undefined ? radius : -1;
  2923. }
  2924. var _proto = Sphere.prototype;
  2925. _proto.set = function set(center, radius) {
  2926. this.center.copy(center);
  2927. this.radius = radius;
  2928. return this;
  2929. };
  2930. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2931. var center = this.center;
  2932. if (optionalCenter !== undefined) {
  2933. center.copy(optionalCenter);
  2934. } else {
  2935. _box$1.setFromPoints(points).getCenter(center);
  2936. }
  2937. var maxRadiusSq = 0;
  2938. for (var i = 0, il = points.length; i < il; i++) {
  2939. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2940. }
  2941. this.radius = Math.sqrt(maxRadiusSq);
  2942. return this;
  2943. };
  2944. _proto.clone = function clone() {
  2945. return new this.constructor().copy(this);
  2946. };
  2947. _proto.copy = function copy(sphere) {
  2948. this.center.copy(sphere.center);
  2949. this.radius = sphere.radius;
  2950. return this;
  2951. };
  2952. _proto.isEmpty = function isEmpty() {
  2953. return this.radius < 0;
  2954. };
  2955. _proto.makeEmpty = function makeEmpty() {
  2956. this.center.set(0, 0, 0);
  2957. this.radius = -1;
  2958. return this;
  2959. };
  2960. _proto.containsPoint = function containsPoint(point) {
  2961. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  2962. };
  2963. _proto.distanceToPoint = function distanceToPoint(point) {
  2964. return point.distanceTo(this.center) - this.radius;
  2965. };
  2966. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2967. var radiusSum = this.radius + sphere.radius;
  2968. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  2969. };
  2970. _proto.intersectsBox = function intersectsBox(box) {
  2971. return box.intersectsSphere(this);
  2972. };
  2973. _proto.intersectsPlane = function intersectsPlane(plane) {
  2974. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  2975. };
  2976. _proto.clampPoint = function clampPoint(point, target) {
  2977. var deltaLengthSq = this.center.distanceToSquared(point);
  2978. if (target === undefined) {
  2979. console.warn('THREE.Sphere: .clampPoint() target is now required');
  2980. target = new Vector3();
  2981. }
  2982. target.copy(point);
  2983. if (deltaLengthSq > this.radius * this.radius) {
  2984. target.sub(this.center).normalize();
  2985. target.multiplyScalar(this.radius).add(this.center);
  2986. }
  2987. return target;
  2988. };
  2989. _proto.getBoundingBox = function getBoundingBox(target) {
  2990. if (target === undefined) {
  2991. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  2992. target = new Box3();
  2993. }
  2994. if (this.isEmpty()) {
  2995. // Empty sphere produces empty bounding box
  2996. target.makeEmpty();
  2997. return target;
  2998. }
  2999. target.set(this.center, this.center);
  3000. target.expandByScalar(this.radius);
  3001. return target;
  3002. };
  3003. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3004. this.center.applyMatrix4(matrix);
  3005. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3006. return this;
  3007. };
  3008. _proto.translate = function translate(offset) {
  3009. this.center.add(offset);
  3010. return this;
  3011. };
  3012. _proto.equals = function equals(sphere) {
  3013. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3014. };
  3015. return Sphere;
  3016. }();
  3017. var _vector$2 = /*@__PURE__*/new Vector3();
  3018. var _segCenter = /*@__PURE__*/new Vector3();
  3019. var _segDir = /*@__PURE__*/new Vector3();
  3020. var _diff = /*@__PURE__*/new Vector3();
  3021. var _edge1 = /*@__PURE__*/new Vector3();
  3022. var _edge2 = /*@__PURE__*/new Vector3();
  3023. var _normal = /*@__PURE__*/new Vector3();
  3024. var Ray = /*#__PURE__*/function () {
  3025. function Ray(origin, direction) {
  3026. this.origin = origin !== undefined ? origin : new Vector3();
  3027. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3028. }
  3029. var _proto = Ray.prototype;
  3030. _proto.set = function set(origin, direction) {
  3031. this.origin.copy(origin);
  3032. this.direction.copy(direction);
  3033. return this;
  3034. };
  3035. _proto.clone = function clone() {
  3036. return new this.constructor().copy(this);
  3037. };
  3038. _proto.copy = function copy(ray) {
  3039. this.origin.copy(ray.origin);
  3040. this.direction.copy(ray.direction);
  3041. return this;
  3042. };
  3043. _proto.at = function at(t, target) {
  3044. if (target === undefined) {
  3045. console.warn('THREE.Ray: .at() target is now required');
  3046. target = new Vector3();
  3047. }
  3048. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3049. };
  3050. _proto.lookAt = function lookAt(v) {
  3051. this.direction.copy(v).sub(this.origin).normalize();
  3052. return this;
  3053. };
  3054. _proto.recast = function recast(t) {
  3055. this.origin.copy(this.at(t, _vector$2));
  3056. return this;
  3057. };
  3058. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3059. if (target === undefined) {
  3060. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3061. target = new Vector3();
  3062. }
  3063. target.subVectors(point, this.origin);
  3064. var directionDistance = target.dot(this.direction);
  3065. if (directionDistance < 0) {
  3066. return target.copy(this.origin);
  3067. }
  3068. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3069. };
  3070. _proto.distanceToPoint = function distanceToPoint(point) {
  3071. return Math.sqrt(this.distanceSqToPoint(point));
  3072. };
  3073. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3074. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3075. if (directionDistance < 0) {
  3076. return this.origin.distanceToSquared(point);
  3077. }
  3078. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3079. return _vector$2.distanceToSquared(point);
  3080. };
  3081. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3082. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3083. // It returns the min distance between the ray and the segment
  3084. // defined by v0 and v1
  3085. // It can also set two optional targets :
  3086. // - The closest point on the ray
  3087. // - The closest point on the segment
  3088. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3089. _segDir.copy(v1).sub(v0).normalize();
  3090. _diff.copy(this.origin).sub(_segCenter);
  3091. var segExtent = v0.distanceTo(v1) * 0.5;
  3092. var a01 = -this.direction.dot(_segDir);
  3093. var b0 = _diff.dot(this.direction);
  3094. var b1 = -_diff.dot(_segDir);
  3095. var c = _diff.lengthSq();
  3096. var det = Math.abs(1 - a01 * a01);
  3097. var s0, s1, sqrDist, extDet;
  3098. if (det > 0) {
  3099. // The ray and segment are not parallel.
  3100. s0 = a01 * b1 - b0;
  3101. s1 = a01 * b0 - b1;
  3102. extDet = segExtent * det;
  3103. if (s0 >= 0) {
  3104. if (s1 >= -extDet) {
  3105. if (s1 <= extDet) {
  3106. // region 0
  3107. // Minimum at interior points of ray and segment.
  3108. var invDet = 1 / det;
  3109. s0 *= invDet;
  3110. s1 *= invDet;
  3111. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3112. } else {
  3113. // region 1
  3114. s1 = segExtent;
  3115. s0 = Math.max(0, -(a01 * s1 + b0));
  3116. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3117. }
  3118. } else {
  3119. // region 5
  3120. s1 = -segExtent;
  3121. s0 = Math.max(0, -(a01 * s1 + b0));
  3122. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3123. }
  3124. } else {
  3125. if (s1 <= -extDet) {
  3126. // region 4
  3127. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3128. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3129. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3130. } else if (s1 <= extDet) {
  3131. // region 3
  3132. s0 = 0;
  3133. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3134. sqrDist = s1 * (s1 + 2 * b1) + c;
  3135. } else {
  3136. // region 2
  3137. s0 = Math.max(0, -(a01 * segExtent + b0));
  3138. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3139. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3140. }
  3141. }
  3142. } else {
  3143. // Ray and segment are parallel.
  3144. s1 = a01 > 0 ? -segExtent : segExtent;
  3145. s0 = Math.max(0, -(a01 * s1 + b0));
  3146. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3147. }
  3148. if (optionalPointOnRay) {
  3149. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3150. }
  3151. if (optionalPointOnSegment) {
  3152. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3153. }
  3154. return sqrDist;
  3155. };
  3156. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3157. _vector$2.subVectors(sphere.center, this.origin);
  3158. var tca = _vector$2.dot(this.direction);
  3159. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3160. var radius2 = sphere.radius * sphere.radius;
  3161. if (d2 > radius2) return null;
  3162. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3163. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3164. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3165. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3166. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3167. // in order to always return an intersect point that is in front of the ray.
  3168. 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
  3169. return this.at(t0, target);
  3170. };
  3171. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3172. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3173. };
  3174. _proto.distanceToPlane = function distanceToPlane(plane) {
  3175. var denominator = plane.normal.dot(this.direction);
  3176. if (denominator === 0) {
  3177. // line is coplanar, return origin
  3178. if (plane.distanceToPoint(this.origin) === 0) {
  3179. return 0;
  3180. } // Null is preferable to undefined since undefined means.... it is undefined
  3181. return null;
  3182. }
  3183. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3184. return t >= 0 ? t : null;
  3185. };
  3186. _proto.intersectPlane = function intersectPlane(plane, target) {
  3187. var t = this.distanceToPlane(plane);
  3188. if (t === null) {
  3189. return null;
  3190. }
  3191. return this.at(t, target);
  3192. };
  3193. _proto.intersectsPlane = function intersectsPlane(plane) {
  3194. // check if the ray lies on the plane first
  3195. var distToPoint = plane.distanceToPoint(this.origin);
  3196. if (distToPoint === 0) {
  3197. return true;
  3198. }
  3199. var denominator = plane.normal.dot(this.direction);
  3200. if (denominator * distToPoint < 0) {
  3201. return true;
  3202. } // ray origin is behind the plane (and is pointing behind it)
  3203. return false;
  3204. };
  3205. _proto.intersectBox = function intersectBox(box, target) {
  3206. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3207. var invdirx = 1 / this.direction.x,
  3208. invdiry = 1 / this.direction.y,
  3209. invdirz = 1 / this.direction.z;
  3210. var origin = this.origin;
  3211. if (invdirx >= 0) {
  3212. tmin = (box.min.x - origin.x) * invdirx;
  3213. tmax = (box.max.x - origin.x) * invdirx;
  3214. } else {
  3215. tmin = (box.max.x - origin.x) * invdirx;
  3216. tmax = (box.min.x - origin.x) * invdirx;
  3217. }
  3218. if (invdiry >= 0) {
  3219. tymin = (box.min.y - origin.y) * invdiry;
  3220. tymax = (box.max.y - origin.y) * invdiry;
  3221. } else {
  3222. tymin = (box.max.y - origin.y) * invdiry;
  3223. tymax = (box.min.y - origin.y) * invdiry;
  3224. }
  3225. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3226. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3227. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3228. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3229. if (invdirz >= 0) {
  3230. tzmin = (box.min.z - origin.z) * invdirz;
  3231. tzmax = (box.max.z - origin.z) * invdirz;
  3232. } else {
  3233. tzmin = (box.max.z - origin.z) * invdirz;
  3234. tzmax = (box.min.z - origin.z) * invdirz;
  3235. }
  3236. if (tmin > tzmax || tzmin > tmax) return null;
  3237. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3238. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3239. if (tmax < 0) return null;
  3240. return this.at(tmin >= 0 ? tmin : tmax, target);
  3241. };
  3242. _proto.intersectsBox = function intersectsBox(box) {
  3243. return this.intersectBox(box, _vector$2) !== null;
  3244. };
  3245. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3246. // Compute the offset origin, edges, and normal.
  3247. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3248. _edge1.subVectors(b, a);
  3249. _edge2.subVectors(c, a);
  3250. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3251. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3252. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3253. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3254. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3255. var DdN = this.direction.dot(_normal);
  3256. var sign;
  3257. if (DdN > 0) {
  3258. if (backfaceCulling) return null;
  3259. sign = 1;
  3260. } else if (DdN < 0) {
  3261. sign = -1;
  3262. DdN = -DdN;
  3263. } else {
  3264. return null;
  3265. }
  3266. _diff.subVectors(this.origin, a);
  3267. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3268. if (DdQxE2 < 0) {
  3269. return null;
  3270. }
  3271. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3272. if (DdE1xQ < 0) {
  3273. return null;
  3274. } // b1+b2 > 1, no intersection
  3275. if (DdQxE2 + DdE1xQ > DdN) {
  3276. return null;
  3277. } // Line intersects triangle, check if ray does.
  3278. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3279. if (QdN < 0) {
  3280. return null;
  3281. } // Ray intersects triangle.
  3282. return this.at(QdN / DdN, target);
  3283. };
  3284. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3285. this.origin.applyMatrix4(matrix4);
  3286. this.direction.transformDirection(matrix4);
  3287. return this;
  3288. };
  3289. _proto.equals = function equals(ray) {
  3290. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3291. };
  3292. return Ray;
  3293. }();
  3294. var Matrix4 = /*#__PURE__*/function () {
  3295. function Matrix4() {
  3296. Object.defineProperty(this, 'isMatrix4', {
  3297. value: true
  3298. });
  3299. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3300. if (arguments.length > 0) {
  3301. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3302. }
  3303. }
  3304. var _proto = Matrix4.prototype;
  3305. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3306. var te = this.elements;
  3307. te[0] = n11;
  3308. te[4] = n12;
  3309. te[8] = n13;
  3310. te[12] = n14;
  3311. te[1] = n21;
  3312. te[5] = n22;
  3313. te[9] = n23;
  3314. te[13] = n24;
  3315. te[2] = n31;
  3316. te[6] = n32;
  3317. te[10] = n33;
  3318. te[14] = n34;
  3319. te[3] = n41;
  3320. te[7] = n42;
  3321. te[11] = n43;
  3322. te[15] = n44;
  3323. return this;
  3324. };
  3325. _proto.identity = function identity() {
  3326. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3327. return this;
  3328. };
  3329. _proto.clone = function clone() {
  3330. return new Matrix4().fromArray(this.elements);
  3331. };
  3332. _proto.copy = function copy(m) {
  3333. var te = this.elements;
  3334. var me = m.elements;
  3335. te[0] = me[0];
  3336. te[1] = me[1];
  3337. te[2] = me[2];
  3338. te[3] = me[3];
  3339. te[4] = me[4];
  3340. te[5] = me[5];
  3341. te[6] = me[6];
  3342. te[7] = me[7];
  3343. te[8] = me[8];
  3344. te[9] = me[9];
  3345. te[10] = me[10];
  3346. te[11] = me[11];
  3347. te[12] = me[12];
  3348. te[13] = me[13];
  3349. te[14] = me[14];
  3350. te[15] = me[15];
  3351. return this;
  3352. };
  3353. _proto.copyPosition = function copyPosition(m) {
  3354. var te = this.elements,
  3355. me = m.elements;
  3356. te[12] = me[12];
  3357. te[13] = me[13];
  3358. te[14] = me[14];
  3359. return this;
  3360. };
  3361. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3362. xAxis.setFromMatrixColumn(this, 0);
  3363. yAxis.setFromMatrixColumn(this, 1);
  3364. zAxis.setFromMatrixColumn(this, 2);
  3365. return this;
  3366. };
  3367. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3368. 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);
  3369. return this;
  3370. };
  3371. _proto.extractRotation = function extractRotation(m) {
  3372. // this method does not support reflection matrices
  3373. var te = this.elements;
  3374. var me = m.elements;
  3375. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3376. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3377. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3378. te[0] = me[0] * scaleX;
  3379. te[1] = me[1] * scaleX;
  3380. te[2] = me[2] * scaleX;
  3381. te[3] = 0;
  3382. te[4] = me[4] * scaleY;
  3383. te[5] = me[5] * scaleY;
  3384. te[6] = me[6] * scaleY;
  3385. te[7] = 0;
  3386. te[8] = me[8] * scaleZ;
  3387. te[9] = me[9] * scaleZ;
  3388. te[10] = me[10] * scaleZ;
  3389. te[11] = 0;
  3390. te[12] = 0;
  3391. te[13] = 0;
  3392. te[14] = 0;
  3393. te[15] = 1;
  3394. return this;
  3395. };
  3396. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3397. if (!(euler && euler.isEuler)) {
  3398. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3399. }
  3400. var te = this.elements;
  3401. var x = euler.x,
  3402. y = euler.y,
  3403. z = euler.z;
  3404. var a = Math.cos(x),
  3405. b = Math.sin(x);
  3406. var c = Math.cos(y),
  3407. d = Math.sin(y);
  3408. var e = Math.cos(z),
  3409. f = Math.sin(z);
  3410. if (euler.order === 'XYZ') {
  3411. var ae = a * e,
  3412. af = a * f,
  3413. be = b * e,
  3414. bf = b * f;
  3415. te[0] = c * e;
  3416. te[4] = -c * f;
  3417. te[8] = d;
  3418. te[1] = af + be * d;
  3419. te[5] = ae - bf * d;
  3420. te[9] = -b * c;
  3421. te[2] = bf - ae * d;
  3422. te[6] = be + af * d;
  3423. te[10] = a * c;
  3424. } else if (euler.order === 'YXZ') {
  3425. var ce = c * e,
  3426. cf = c * f,
  3427. de = d * e,
  3428. df = d * f;
  3429. te[0] = ce + df * b;
  3430. te[4] = de * b - cf;
  3431. te[8] = a * d;
  3432. te[1] = a * f;
  3433. te[5] = a * e;
  3434. te[9] = -b;
  3435. te[2] = cf * b - de;
  3436. te[6] = df + ce * b;
  3437. te[10] = a * c;
  3438. } else if (euler.order === 'ZXY') {
  3439. var _ce = c * e,
  3440. _cf = c * f,
  3441. _de = d * e,
  3442. _df = d * f;
  3443. te[0] = _ce - _df * b;
  3444. te[4] = -a * f;
  3445. te[8] = _de + _cf * b;
  3446. te[1] = _cf + _de * b;
  3447. te[5] = a * e;
  3448. te[9] = _df - _ce * b;
  3449. te[2] = -a * d;
  3450. te[6] = b;
  3451. te[10] = a * c;
  3452. } else if (euler.order === 'ZYX') {
  3453. var _ae = a * e,
  3454. _af = a * f,
  3455. _be = b * e,
  3456. _bf = b * f;
  3457. te[0] = c * e;
  3458. te[4] = _be * d - _af;
  3459. te[8] = _ae * d + _bf;
  3460. te[1] = c * f;
  3461. te[5] = _bf * d + _ae;
  3462. te[9] = _af * d - _be;
  3463. te[2] = -d;
  3464. te[6] = b * c;
  3465. te[10] = a * c;
  3466. } else if (euler.order === 'YZX') {
  3467. var ac = a * c,
  3468. ad = a * d,
  3469. bc = b * c,
  3470. bd = b * d;
  3471. te[0] = c * e;
  3472. te[4] = bd - ac * f;
  3473. te[8] = bc * f + ad;
  3474. te[1] = f;
  3475. te[5] = a * e;
  3476. te[9] = -b * e;
  3477. te[2] = -d * e;
  3478. te[6] = ad * f + bc;
  3479. te[10] = ac - bd * f;
  3480. } else if (euler.order === 'XZY') {
  3481. var _ac = a * c,
  3482. _ad = a * d,
  3483. _bc = b * c,
  3484. _bd = b * d;
  3485. te[0] = c * e;
  3486. te[4] = -f;
  3487. te[8] = d * e;
  3488. te[1] = _ac * f + _bd;
  3489. te[5] = a * e;
  3490. te[9] = _ad * f - _bc;
  3491. te[2] = _bc * f - _ad;
  3492. te[6] = b * e;
  3493. te[10] = _bd * f + _ac;
  3494. } // bottom row
  3495. te[3] = 0;
  3496. te[7] = 0;
  3497. te[11] = 0; // last column
  3498. te[12] = 0;
  3499. te[13] = 0;
  3500. te[14] = 0;
  3501. te[15] = 1;
  3502. return this;
  3503. };
  3504. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3505. return this.compose(_zero, q, _one);
  3506. };
  3507. _proto.lookAt = function lookAt(eye, target, up) {
  3508. var te = this.elements;
  3509. _z.subVectors(eye, target);
  3510. if (_z.lengthSq() === 0) {
  3511. // eye and target are in the same position
  3512. _z.z = 1;
  3513. }
  3514. _z.normalize();
  3515. _x.crossVectors(up, _z);
  3516. if (_x.lengthSq() === 0) {
  3517. // up and z are parallel
  3518. if (Math.abs(up.z) === 1) {
  3519. _z.x += 0.0001;
  3520. } else {
  3521. _z.z += 0.0001;
  3522. }
  3523. _z.normalize();
  3524. _x.crossVectors(up, _z);
  3525. }
  3526. _x.normalize();
  3527. _y.crossVectors(_z, _x);
  3528. te[0] = _x.x;
  3529. te[4] = _y.x;
  3530. te[8] = _z.x;
  3531. te[1] = _x.y;
  3532. te[5] = _y.y;
  3533. te[9] = _z.y;
  3534. te[2] = _x.z;
  3535. te[6] = _y.z;
  3536. te[10] = _z.z;
  3537. return this;
  3538. };
  3539. _proto.multiply = function multiply(m, n) {
  3540. if (n !== undefined) {
  3541. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3542. return this.multiplyMatrices(m, n);
  3543. }
  3544. return this.multiplyMatrices(this, m);
  3545. };
  3546. _proto.premultiply = function premultiply(m) {
  3547. return this.multiplyMatrices(m, this);
  3548. };
  3549. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3550. var ae = a.elements;
  3551. var be = b.elements;
  3552. var te = this.elements;
  3553. var a11 = ae[0],
  3554. a12 = ae[4],
  3555. a13 = ae[8],
  3556. a14 = ae[12];
  3557. var a21 = ae[1],
  3558. a22 = ae[5],
  3559. a23 = ae[9],
  3560. a24 = ae[13];
  3561. var a31 = ae[2],
  3562. a32 = ae[6],
  3563. a33 = ae[10],
  3564. a34 = ae[14];
  3565. var a41 = ae[3],
  3566. a42 = ae[7],
  3567. a43 = ae[11],
  3568. a44 = ae[15];
  3569. var b11 = be[0],
  3570. b12 = be[4],
  3571. b13 = be[8],
  3572. b14 = be[12];
  3573. var b21 = be[1],
  3574. b22 = be[5],
  3575. b23 = be[9],
  3576. b24 = be[13];
  3577. var b31 = be[2],
  3578. b32 = be[6],
  3579. b33 = be[10],
  3580. b34 = be[14];
  3581. var b41 = be[3],
  3582. b42 = be[7],
  3583. b43 = be[11],
  3584. b44 = be[15];
  3585. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3586. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3587. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3588. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3589. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3590. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3591. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3592. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3593. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3594. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3595. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3596. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3597. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3598. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3599. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3600. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3601. return this;
  3602. };
  3603. _proto.multiplyScalar = function multiplyScalar(s) {
  3604. var te = this.elements;
  3605. te[0] *= s;
  3606. te[4] *= s;
  3607. te[8] *= s;
  3608. te[12] *= s;
  3609. te[1] *= s;
  3610. te[5] *= s;
  3611. te[9] *= s;
  3612. te[13] *= s;
  3613. te[2] *= s;
  3614. te[6] *= s;
  3615. te[10] *= s;
  3616. te[14] *= s;
  3617. te[3] *= s;
  3618. te[7] *= s;
  3619. te[11] *= s;
  3620. te[15] *= s;
  3621. return this;
  3622. };
  3623. _proto.determinant = function determinant() {
  3624. var te = this.elements;
  3625. var n11 = te[0],
  3626. n12 = te[4],
  3627. n13 = te[8],
  3628. n14 = te[12];
  3629. var n21 = te[1],
  3630. n22 = te[5],
  3631. n23 = te[9],
  3632. n24 = te[13];
  3633. var n31 = te[2],
  3634. n32 = te[6],
  3635. n33 = te[10],
  3636. n34 = te[14];
  3637. var n41 = te[3],
  3638. n42 = te[7],
  3639. n43 = te[11],
  3640. n44 = te[15]; //TODO: make this more efficient
  3641. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3642. 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);
  3643. };
  3644. _proto.transpose = function transpose() {
  3645. var te = this.elements;
  3646. var tmp;
  3647. tmp = te[1];
  3648. te[1] = te[4];
  3649. te[4] = tmp;
  3650. tmp = te[2];
  3651. te[2] = te[8];
  3652. te[8] = tmp;
  3653. tmp = te[6];
  3654. te[6] = te[9];
  3655. te[9] = tmp;
  3656. tmp = te[3];
  3657. te[3] = te[12];
  3658. te[12] = tmp;
  3659. tmp = te[7];
  3660. te[7] = te[13];
  3661. te[13] = tmp;
  3662. tmp = te[11];
  3663. te[11] = te[14];
  3664. te[14] = tmp;
  3665. return this;
  3666. };
  3667. _proto.setPosition = function setPosition(x, y, z) {
  3668. var te = this.elements;
  3669. if (x.isVector3) {
  3670. te[12] = x.x;
  3671. te[13] = x.y;
  3672. te[14] = x.z;
  3673. } else {
  3674. te[12] = x;
  3675. te[13] = y;
  3676. te[14] = z;
  3677. }
  3678. return this;
  3679. };
  3680. _proto.getInverse = function getInverse(m, throwOnDegenerate) {
  3681. if (throwOnDegenerate !== undefined) {
  3682. console.warn("THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate.");
  3683. } // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3684. var te = this.elements,
  3685. me = m.elements,
  3686. n11 = me[0],
  3687. n21 = me[1],
  3688. n31 = me[2],
  3689. n41 = me[3],
  3690. n12 = me[4],
  3691. n22 = me[5],
  3692. n32 = me[6],
  3693. n42 = me[7],
  3694. n13 = me[8],
  3695. n23 = me[9],
  3696. n33 = me[10],
  3697. n43 = me[11],
  3698. n14 = me[12],
  3699. n24 = me[13],
  3700. n34 = me[14],
  3701. n44 = me[15],
  3702. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3703. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3704. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3705. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3706. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3707. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3708. var detInv = 1 / det;
  3709. te[0] = t11 * detInv;
  3710. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3711. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3712. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3713. te[4] = t12 * detInv;
  3714. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3715. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3716. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3717. te[8] = t13 * detInv;
  3718. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3719. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3720. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3721. te[12] = t14 * detInv;
  3722. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3723. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3724. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3725. return this;
  3726. };
  3727. _proto.scale = function scale(v) {
  3728. var te = this.elements;
  3729. var x = v.x,
  3730. y = v.y,
  3731. z = v.z;
  3732. te[0] *= x;
  3733. te[4] *= y;
  3734. te[8] *= z;
  3735. te[1] *= x;
  3736. te[5] *= y;
  3737. te[9] *= z;
  3738. te[2] *= x;
  3739. te[6] *= y;
  3740. te[10] *= z;
  3741. te[3] *= x;
  3742. te[7] *= y;
  3743. te[11] *= z;
  3744. return this;
  3745. };
  3746. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3747. var te = this.elements;
  3748. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3749. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3750. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3751. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3752. };
  3753. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3754. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3755. return this;
  3756. };
  3757. _proto.makeRotationX = function makeRotationX(theta) {
  3758. var c = Math.cos(theta),
  3759. s = Math.sin(theta);
  3760. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3761. return this;
  3762. };
  3763. _proto.makeRotationY = function makeRotationY(theta) {
  3764. var c = Math.cos(theta),
  3765. s = Math.sin(theta);
  3766. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3767. return this;
  3768. };
  3769. _proto.makeRotationZ = function makeRotationZ(theta) {
  3770. var c = Math.cos(theta),
  3771. s = Math.sin(theta);
  3772. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3773. return this;
  3774. };
  3775. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3776. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3777. var c = Math.cos(angle);
  3778. var s = Math.sin(angle);
  3779. var t = 1 - c;
  3780. var x = axis.x,
  3781. y = axis.y,
  3782. z = axis.z;
  3783. var tx = t * x,
  3784. ty = t * y;
  3785. 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);
  3786. return this;
  3787. };
  3788. _proto.makeScale = function makeScale(x, y, z) {
  3789. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3790. return this;
  3791. };
  3792. _proto.makeShear = function makeShear(x, y, z) {
  3793. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3794. return this;
  3795. };
  3796. _proto.compose = function compose(position, quaternion, scale) {
  3797. var te = this.elements;
  3798. var x = quaternion._x,
  3799. y = quaternion._y,
  3800. z = quaternion._z,
  3801. w = quaternion._w;
  3802. var x2 = x + x,
  3803. y2 = y + y,
  3804. z2 = z + z;
  3805. var xx = x * x2,
  3806. xy = x * y2,
  3807. xz = x * z2;
  3808. var yy = y * y2,
  3809. yz = y * z2,
  3810. zz = z * z2;
  3811. var wx = w * x2,
  3812. wy = w * y2,
  3813. wz = w * z2;
  3814. var sx = scale.x,
  3815. sy = scale.y,
  3816. sz = scale.z;
  3817. te[0] = (1 - (yy + zz)) * sx;
  3818. te[1] = (xy + wz) * sx;
  3819. te[2] = (xz - wy) * sx;
  3820. te[3] = 0;
  3821. te[4] = (xy - wz) * sy;
  3822. te[5] = (1 - (xx + zz)) * sy;
  3823. te[6] = (yz + wx) * sy;
  3824. te[7] = 0;
  3825. te[8] = (xz + wy) * sz;
  3826. te[9] = (yz - wx) * sz;
  3827. te[10] = (1 - (xx + yy)) * sz;
  3828. te[11] = 0;
  3829. te[12] = position.x;
  3830. te[13] = position.y;
  3831. te[14] = position.z;
  3832. te[15] = 1;
  3833. return this;
  3834. };
  3835. _proto.decompose = function decompose(position, quaternion, scale) {
  3836. var te = this.elements;
  3837. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3838. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3839. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3840. var det = this.determinant();
  3841. if (det < 0) sx = -sx;
  3842. position.x = te[12];
  3843. position.y = te[13];
  3844. position.z = te[14]; // scale the rotation part
  3845. _m1.copy(this);
  3846. var invSX = 1 / sx;
  3847. var invSY = 1 / sy;
  3848. var invSZ = 1 / sz;
  3849. _m1.elements[0] *= invSX;
  3850. _m1.elements[1] *= invSX;
  3851. _m1.elements[2] *= invSX;
  3852. _m1.elements[4] *= invSY;
  3853. _m1.elements[5] *= invSY;
  3854. _m1.elements[6] *= invSY;
  3855. _m1.elements[8] *= invSZ;
  3856. _m1.elements[9] *= invSZ;
  3857. _m1.elements[10] *= invSZ;
  3858. quaternion.setFromRotationMatrix(_m1);
  3859. scale.x = sx;
  3860. scale.y = sy;
  3861. scale.z = sz;
  3862. return this;
  3863. };
  3864. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3865. if (far === undefined) {
  3866. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3867. }
  3868. var te = this.elements;
  3869. var x = 2 * near / (right - left);
  3870. var y = 2 * near / (top - bottom);
  3871. var a = (right + left) / (right - left);
  3872. var b = (top + bottom) / (top - bottom);
  3873. var c = -(far + near) / (far - near);
  3874. var d = -2 * far * near / (far - near);
  3875. te[0] = x;
  3876. te[4] = 0;
  3877. te[8] = a;
  3878. te[12] = 0;
  3879. te[1] = 0;
  3880. te[5] = y;
  3881. te[9] = b;
  3882. te[13] = 0;
  3883. te[2] = 0;
  3884. te[6] = 0;
  3885. te[10] = c;
  3886. te[14] = d;
  3887. te[3] = 0;
  3888. te[7] = 0;
  3889. te[11] = -1;
  3890. te[15] = 0;
  3891. return this;
  3892. };
  3893. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3894. var te = this.elements;
  3895. var w = 1.0 / (right - left);
  3896. var h = 1.0 / (top - bottom);
  3897. var p = 1.0 / (far - near);
  3898. var x = (right + left) * w;
  3899. var y = (top + bottom) * h;
  3900. var z = (far + near) * p;
  3901. te[0] = 2 * w;
  3902. te[4] = 0;
  3903. te[8] = 0;
  3904. te[12] = -x;
  3905. te[1] = 0;
  3906. te[5] = 2 * h;
  3907. te[9] = 0;
  3908. te[13] = -y;
  3909. te[2] = 0;
  3910. te[6] = 0;
  3911. te[10] = -2 * p;
  3912. te[14] = -z;
  3913. te[3] = 0;
  3914. te[7] = 0;
  3915. te[11] = 0;
  3916. te[15] = 1;
  3917. return this;
  3918. };
  3919. _proto.equals = function equals(matrix) {
  3920. var te = this.elements;
  3921. var me = matrix.elements;
  3922. for (var i = 0; i < 16; i++) {
  3923. if (te[i] !== me[i]) return false;
  3924. }
  3925. return true;
  3926. };
  3927. _proto.fromArray = function fromArray(array, offset) {
  3928. if (offset === void 0) {
  3929. offset = 0;
  3930. }
  3931. for (var i = 0; i < 16; i++) {
  3932. this.elements[i] = array[i + offset];
  3933. }
  3934. return this;
  3935. };
  3936. _proto.toArray = function toArray(array, offset) {
  3937. if (array === void 0) {
  3938. array = [];
  3939. }
  3940. if (offset === void 0) {
  3941. offset = 0;
  3942. }
  3943. var te = this.elements;
  3944. array[offset] = te[0];
  3945. array[offset + 1] = te[1];
  3946. array[offset + 2] = te[2];
  3947. array[offset + 3] = te[3];
  3948. array[offset + 4] = te[4];
  3949. array[offset + 5] = te[5];
  3950. array[offset + 6] = te[6];
  3951. array[offset + 7] = te[7];
  3952. array[offset + 8] = te[8];
  3953. array[offset + 9] = te[9];
  3954. array[offset + 10] = te[10];
  3955. array[offset + 11] = te[11];
  3956. array[offset + 12] = te[12];
  3957. array[offset + 13] = te[13];
  3958. array[offset + 14] = te[14];
  3959. array[offset + 15] = te[15];
  3960. return array;
  3961. };
  3962. return Matrix4;
  3963. }();
  3964. var _v1$1 = /*@__PURE__*/new Vector3();
  3965. var _m1 = /*@__PURE__*/new Matrix4();
  3966. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  3967. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  3968. var _x = /*@__PURE__*/new Vector3();
  3969. var _y = /*@__PURE__*/new Vector3();
  3970. var _z = /*@__PURE__*/new Vector3();
  3971. var Euler = /*#__PURE__*/function () {
  3972. function Euler(x, y, z, order) {
  3973. if (x === void 0) {
  3974. x = 0;
  3975. }
  3976. if (y === void 0) {
  3977. y = 0;
  3978. }
  3979. if (z === void 0) {
  3980. z = 0;
  3981. }
  3982. if (order === void 0) {
  3983. order = Euler.DefaultOrder;
  3984. }
  3985. Object.defineProperty(this, 'isEuler', {
  3986. value: true
  3987. });
  3988. this._x = x;
  3989. this._y = y;
  3990. this._z = z;
  3991. this._order = order;
  3992. }
  3993. var _proto = Euler.prototype;
  3994. _proto.set = function set(x, y, z, order) {
  3995. this._x = x;
  3996. this._y = y;
  3997. this._z = z;
  3998. this._order = order || this._order;
  3999. this._onChangeCallback();
  4000. return this;
  4001. };
  4002. _proto.clone = function clone() {
  4003. return new this.constructor(this._x, this._y, this._z, this._order);
  4004. };
  4005. _proto.copy = function copy(euler) {
  4006. this._x = euler._x;
  4007. this._y = euler._y;
  4008. this._z = euler._z;
  4009. this._order = euler._order;
  4010. this._onChangeCallback();
  4011. return this;
  4012. };
  4013. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4014. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4015. var te = m.elements;
  4016. var m11 = te[0],
  4017. m12 = te[4],
  4018. m13 = te[8];
  4019. var m21 = te[1],
  4020. m22 = te[5],
  4021. m23 = te[9];
  4022. var m31 = te[2],
  4023. m32 = te[6],
  4024. m33 = te[10];
  4025. order = order || this._order;
  4026. switch (order) {
  4027. case 'XYZ':
  4028. this._y = Math.asin(clamp(m13, -1, 1));
  4029. if (Math.abs(m13) < 0.9999999) {
  4030. this._x = Math.atan2(-m23, m33);
  4031. this._z = Math.atan2(-m12, m11);
  4032. } else {
  4033. this._x = Math.atan2(m32, m22);
  4034. this._z = 0;
  4035. }
  4036. break;
  4037. case 'YXZ':
  4038. this._x = Math.asin(-clamp(m23, -1, 1));
  4039. if (Math.abs(m23) < 0.9999999) {
  4040. this._y = Math.atan2(m13, m33);
  4041. this._z = Math.atan2(m21, m22);
  4042. } else {
  4043. this._y = Math.atan2(-m31, m11);
  4044. this._z = 0;
  4045. }
  4046. break;
  4047. case 'ZXY':
  4048. this._x = Math.asin(clamp(m32, -1, 1));
  4049. if (Math.abs(m32) < 0.9999999) {
  4050. this._y = Math.atan2(-m31, m33);
  4051. this._z = Math.atan2(-m12, m22);
  4052. } else {
  4053. this._y = 0;
  4054. this._z = Math.atan2(m21, m11);
  4055. }
  4056. break;
  4057. case 'ZYX':
  4058. this._y = Math.asin(-clamp(m31, -1, 1));
  4059. if (Math.abs(m31) < 0.9999999) {
  4060. this._x = Math.atan2(m32, m33);
  4061. this._z = Math.atan2(m21, m11);
  4062. } else {
  4063. this._x = 0;
  4064. this._z = Math.atan2(-m12, m22);
  4065. }
  4066. break;
  4067. case 'YZX':
  4068. this._z = Math.asin(clamp(m21, -1, 1));
  4069. if (Math.abs(m21) < 0.9999999) {
  4070. this._x = Math.atan2(-m23, m22);
  4071. this._y = Math.atan2(-m31, m11);
  4072. } else {
  4073. this._x = 0;
  4074. this._y = Math.atan2(m13, m33);
  4075. }
  4076. break;
  4077. case 'XZY':
  4078. this._z = Math.asin(-clamp(m12, -1, 1));
  4079. if (Math.abs(m12) < 0.9999999) {
  4080. this._x = Math.atan2(m32, m22);
  4081. this._y = Math.atan2(m13, m11);
  4082. } else {
  4083. this._x = Math.atan2(-m23, m33);
  4084. this._y = 0;
  4085. }
  4086. break;
  4087. default:
  4088. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4089. }
  4090. this._order = order;
  4091. if (update !== false) this._onChangeCallback();
  4092. return this;
  4093. };
  4094. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4095. _matrix.makeRotationFromQuaternion(q);
  4096. return this.setFromRotationMatrix(_matrix, order, update);
  4097. };
  4098. _proto.setFromVector3 = function setFromVector3(v, order) {
  4099. return this.set(v.x, v.y, v.z, order || this._order);
  4100. };
  4101. _proto.reorder = function reorder(newOrder) {
  4102. // WARNING: this discards revolution information -bhouston
  4103. _quaternion$1.setFromEuler(this);
  4104. return this.setFromQuaternion(_quaternion$1, newOrder);
  4105. };
  4106. _proto.equals = function equals(euler) {
  4107. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4108. };
  4109. _proto.fromArray = function fromArray(array) {
  4110. this._x = array[0];
  4111. this._y = array[1];
  4112. this._z = array[2];
  4113. if (array[3] !== undefined) this._order = array[3];
  4114. this._onChangeCallback();
  4115. return this;
  4116. };
  4117. _proto.toArray = function toArray(array, offset) {
  4118. if (array === void 0) {
  4119. array = [];
  4120. }
  4121. if (offset === void 0) {
  4122. offset = 0;
  4123. }
  4124. array[offset] = this._x;
  4125. array[offset + 1] = this._y;
  4126. array[offset + 2] = this._z;
  4127. array[offset + 3] = this._order;
  4128. return array;
  4129. };
  4130. _proto.toVector3 = function toVector3(optionalResult) {
  4131. if (optionalResult) {
  4132. return optionalResult.set(this._x, this._y, this._z);
  4133. } else {
  4134. return new Vector3(this._x, this._y, this._z);
  4135. }
  4136. };
  4137. _proto._onChange = function _onChange(callback) {
  4138. this._onChangeCallback = callback;
  4139. return this;
  4140. };
  4141. _proto._onChangeCallback = function _onChangeCallback() {};
  4142. _createClass(Euler, [{
  4143. key: "x",
  4144. get: function get() {
  4145. return this._x;
  4146. },
  4147. set: function set(value) {
  4148. this._x = value;
  4149. this._onChangeCallback();
  4150. }
  4151. }, {
  4152. key: "y",
  4153. get: function get() {
  4154. return this._y;
  4155. },
  4156. set: function set(value) {
  4157. this._y = value;
  4158. this._onChangeCallback();
  4159. }
  4160. }, {
  4161. key: "z",
  4162. get: function get() {
  4163. return this._z;
  4164. },
  4165. set: function set(value) {
  4166. this._z = value;
  4167. this._onChangeCallback();
  4168. }
  4169. }, {
  4170. key: "order",
  4171. get: function get() {
  4172. return this._order;
  4173. },
  4174. set: function set(value) {
  4175. this._order = value;
  4176. this._onChangeCallback();
  4177. }
  4178. }]);
  4179. return Euler;
  4180. }();
  4181. Euler.DefaultOrder = 'XYZ';
  4182. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4183. var _matrix = /*@__PURE__*/new Matrix4();
  4184. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4185. var Layers = /*#__PURE__*/function () {
  4186. function Layers() {
  4187. this.mask = 1 | 0;
  4188. }
  4189. var _proto = Layers.prototype;
  4190. _proto.set = function set(channel) {
  4191. this.mask = 1 << channel | 0;
  4192. };
  4193. _proto.enable = function enable(channel) {
  4194. this.mask |= 1 << channel | 0;
  4195. };
  4196. _proto.enableAll = function enableAll() {
  4197. this.mask = 0xffffffff | 0;
  4198. };
  4199. _proto.toggle = function toggle(channel) {
  4200. this.mask ^= 1 << channel | 0;
  4201. };
  4202. _proto.disable = function disable(channel) {
  4203. this.mask &= ~(1 << channel | 0);
  4204. };
  4205. _proto.disableAll = function disableAll() {
  4206. this.mask = 0;
  4207. };
  4208. _proto.test = function test(layers) {
  4209. return (this.mask & layers.mask) !== 0;
  4210. };
  4211. return Layers;
  4212. }();
  4213. var _object3DId = 0;
  4214. var _v1$2 = new Vector3();
  4215. var _q1 = new Quaternion();
  4216. var _m1$1 = new Matrix4();
  4217. var _target = new Vector3();
  4218. var _position = new Vector3();
  4219. var _scale = new Vector3();
  4220. var _quaternion$2 = new Quaternion();
  4221. var _xAxis = new Vector3(1, 0, 0);
  4222. var _yAxis = new Vector3(0, 1, 0);
  4223. var _zAxis = new Vector3(0, 0, 1);
  4224. var _addedEvent = {
  4225. type: 'added'
  4226. };
  4227. var _removedEvent = {
  4228. type: 'removed'
  4229. };
  4230. function Object3D() {
  4231. Object.defineProperty(this, 'id', {
  4232. value: _object3DId++
  4233. });
  4234. this.uuid = MathUtils.generateUUID();
  4235. this.name = '';
  4236. this.type = 'Object3D';
  4237. this.parent = null;
  4238. this.children = [];
  4239. this.up = Object3D.DefaultUp.clone();
  4240. var position = new Vector3();
  4241. var rotation = new Euler();
  4242. var quaternion = new Quaternion();
  4243. var scale = new Vector3(1, 1, 1);
  4244. function onRotationChange() {
  4245. quaternion.setFromEuler(rotation, false);
  4246. }
  4247. function onQuaternionChange() {
  4248. rotation.setFromQuaternion(quaternion, undefined, false);
  4249. }
  4250. rotation._onChange(onRotationChange);
  4251. quaternion._onChange(onQuaternionChange);
  4252. Object.defineProperties(this, {
  4253. position: {
  4254. configurable: true,
  4255. enumerable: true,
  4256. value: position
  4257. },
  4258. rotation: {
  4259. configurable: true,
  4260. enumerable: true,
  4261. value: rotation
  4262. },
  4263. quaternion: {
  4264. configurable: true,
  4265. enumerable: true,
  4266. value: quaternion
  4267. },
  4268. scale: {
  4269. configurable: true,
  4270. enumerable: true,
  4271. value: scale
  4272. },
  4273. modelViewMatrix: {
  4274. value: new Matrix4()
  4275. },
  4276. normalMatrix: {
  4277. value: new Matrix3()
  4278. }
  4279. });
  4280. this.matrix = new Matrix4();
  4281. this.matrixWorld = new Matrix4();
  4282. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4283. this.matrixWorldNeedsUpdate = false;
  4284. this.layers = new Layers();
  4285. this.visible = true;
  4286. this.castShadow = false;
  4287. this.receiveShadow = false;
  4288. this.frustumCulled = true;
  4289. this.renderOrder = 0;
  4290. this.userData = {};
  4291. }
  4292. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4293. Object3D.DefaultMatrixAutoUpdate = true;
  4294. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4295. constructor: Object3D,
  4296. isObject3D: true,
  4297. onBeforeRender: function onBeforeRender() {},
  4298. onAfterRender: function onAfterRender() {},
  4299. applyMatrix4: function applyMatrix4(matrix) {
  4300. if (this.matrixAutoUpdate) this.updateMatrix();
  4301. this.matrix.premultiply(matrix);
  4302. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4303. },
  4304. applyQuaternion: function applyQuaternion(q) {
  4305. this.quaternion.premultiply(q);
  4306. return this;
  4307. },
  4308. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4309. // assumes axis is normalized
  4310. this.quaternion.setFromAxisAngle(axis, angle);
  4311. },
  4312. setRotationFromEuler: function setRotationFromEuler(euler) {
  4313. this.quaternion.setFromEuler(euler, true);
  4314. },
  4315. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4316. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4317. this.quaternion.setFromRotationMatrix(m);
  4318. },
  4319. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4320. // assumes q is normalized
  4321. this.quaternion.copy(q);
  4322. },
  4323. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4324. // rotate object on axis in object space
  4325. // axis is assumed to be normalized
  4326. _q1.setFromAxisAngle(axis, angle);
  4327. this.quaternion.multiply(_q1);
  4328. return this;
  4329. },
  4330. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4331. // rotate object on axis in world space
  4332. // axis is assumed to be normalized
  4333. // method assumes no rotated parent
  4334. _q1.setFromAxisAngle(axis, angle);
  4335. this.quaternion.premultiply(_q1);
  4336. return this;
  4337. },
  4338. rotateX: function rotateX(angle) {
  4339. return this.rotateOnAxis(_xAxis, angle);
  4340. },
  4341. rotateY: function rotateY(angle) {
  4342. return this.rotateOnAxis(_yAxis, angle);
  4343. },
  4344. rotateZ: function rotateZ(angle) {
  4345. return this.rotateOnAxis(_zAxis, angle);
  4346. },
  4347. translateOnAxis: function translateOnAxis(axis, distance) {
  4348. // translate object by distance along axis in object space
  4349. // axis is assumed to be normalized
  4350. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4351. this.position.add(_v1$2.multiplyScalar(distance));
  4352. return this;
  4353. },
  4354. translateX: function translateX(distance) {
  4355. return this.translateOnAxis(_xAxis, distance);
  4356. },
  4357. translateY: function translateY(distance) {
  4358. return this.translateOnAxis(_yAxis, distance);
  4359. },
  4360. translateZ: function translateZ(distance) {
  4361. return this.translateOnAxis(_zAxis, distance);
  4362. },
  4363. localToWorld: function localToWorld(vector) {
  4364. return vector.applyMatrix4(this.matrixWorld);
  4365. },
  4366. worldToLocal: function worldToLocal(vector) {
  4367. return vector.applyMatrix4(_m1$1.getInverse(this.matrixWorld));
  4368. },
  4369. lookAt: function lookAt(x, y, z) {
  4370. // This method does not support objects having non-uniformly-scaled parent(s)
  4371. if (x.isVector3) {
  4372. _target.copy(x);
  4373. } else {
  4374. _target.set(x, y, z);
  4375. }
  4376. var parent = this.parent;
  4377. this.updateWorldMatrix(true, false);
  4378. _position.setFromMatrixPosition(this.matrixWorld);
  4379. if (this.isCamera || this.isLight) {
  4380. _m1$1.lookAt(_position, _target, this.up);
  4381. } else {
  4382. _m1$1.lookAt(_target, _position, this.up);
  4383. }
  4384. this.quaternion.setFromRotationMatrix(_m1$1);
  4385. if (parent) {
  4386. _m1$1.extractRotation(parent.matrixWorld);
  4387. _q1.setFromRotationMatrix(_m1$1);
  4388. this.quaternion.premultiply(_q1.inverse());
  4389. }
  4390. },
  4391. add: function add(object) {
  4392. if (arguments.length > 1) {
  4393. for (var i = 0; i < arguments.length; i++) {
  4394. this.add(arguments[i]);
  4395. }
  4396. return this;
  4397. }
  4398. if (object === this) {
  4399. console.error("THREE.Object3D.add: object can't be added as a child of itself.", object);
  4400. return this;
  4401. }
  4402. if (object && object.isObject3D) {
  4403. if (object.parent !== null) {
  4404. object.parent.remove(object);
  4405. }
  4406. object.parent = this;
  4407. this.children.push(object);
  4408. object.dispatchEvent(_addedEvent);
  4409. } else {
  4410. console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object);
  4411. }
  4412. return this;
  4413. },
  4414. remove: function remove(object) {
  4415. if (arguments.length > 1) {
  4416. for (var i = 0; i < arguments.length; i++) {
  4417. this.remove(arguments[i]);
  4418. }
  4419. return this;
  4420. }
  4421. var index = this.children.indexOf(object);
  4422. if (index !== -1) {
  4423. object.parent = null;
  4424. this.children.splice(index, 1);
  4425. object.dispatchEvent(_removedEvent);
  4426. }
  4427. return this;
  4428. },
  4429. clear: function clear() {
  4430. for (var i = 0; i < this.children.length; i++) {
  4431. var object = this.children[i];
  4432. object.parent = null;
  4433. object.dispatchEvent(_removedEvent);
  4434. }
  4435. this.children.length = 0;
  4436. return this;
  4437. },
  4438. attach: function attach(object) {
  4439. // adds object as a child of this, while maintaining the object's world transform
  4440. this.updateWorldMatrix(true, false);
  4441. _m1$1.getInverse(this.matrixWorld);
  4442. if (object.parent !== null) {
  4443. object.parent.updateWorldMatrix(true, false);
  4444. _m1$1.multiply(object.parent.matrixWorld);
  4445. }
  4446. object.applyMatrix4(_m1$1);
  4447. object.updateWorldMatrix(false, false);
  4448. this.add(object);
  4449. return this;
  4450. },
  4451. getObjectById: function getObjectById(id) {
  4452. return this.getObjectByProperty('id', id);
  4453. },
  4454. getObjectByName: function getObjectByName(name) {
  4455. return this.getObjectByProperty('name', name);
  4456. },
  4457. getObjectByProperty: function getObjectByProperty(name, value) {
  4458. if (this[name] === value) return this;
  4459. for (var i = 0, l = this.children.length; i < l; i++) {
  4460. var child = this.children[i];
  4461. var object = child.getObjectByProperty(name, value);
  4462. if (object !== undefined) {
  4463. return object;
  4464. }
  4465. }
  4466. return undefined;
  4467. },
  4468. getWorldPosition: function getWorldPosition(target) {
  4469. if (target === undefined) {
  4470. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4471. target = new Vector3();
  4472. }
  4473. this.updateWorldMatrix(true, false);
  4474. return target.setFromMatrixPosition(this.matrixWorld);
  4475. },
  4476. getWorldQuaternion: function getWorldQuaternion(target) {
  4477. if (target === undefined) {
  4478. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4479. target = new Quaternion();
  4480. }
  4481. this.updateWorldMatrix(true, false);
  4482. this.matrixWorld.decompose(_position, target, _scale);
  4483. return target;
  4484. },
  4485. getWorldScale: function getWorldScale(target) {
  4486. if (target === undefined) {
  4487. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4488. target = new Vector3();
  4489. }
  4490. this.updateWorldMatrix(true, false);
  4491. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4492. return target;
  4493. },
  4494. getWorldDirection: function getWorldDirection(target) {
  4495. if (target === undefined) {
  4496. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4497. target = new Vector3();
  4498. }
  4499. this.updateWorldMatrix(true, false);
  4500. var e = this.matrixWorld.elements;
  4501. return target.set(e[8], e[9], e[10]).normalize();
  4502. },
  4503. raycast: function raycast() {},
  4504. traverse: function traverse(callback) {
  4505. callback(this);
  4506. var children = this.children;
  4507. for (var i = 0, l = children.length; i < l; i++) {
  4508. children[i].traverse(callback);
  4509. }
  4510. },
  4511. traverseVisible: function traverseVisible(callback) {
  4512. if (this.visible === false) return;
  4513. callback(this);
  4514. var children = this.children;
  4515. for (var i = 0, l = children.length; i < l; i++) {
  4516. children[i].traverseVisible(callback);
  4517. }
  4518. },
  4519. traverseAncestors: function traverseAncestors(callback) {
  4520. var parent = this.parent;
  4521. if (parent !== null) {
  4522. callback(parent);
  4523. parent.traverseAncestors(callback);
  4524. }
  4525. },
  4526. updateMatrix: function updateMatrix() {
  4527. this.matrix.compose(this.position, this.quaternion, this.scale);
  4528. this.matrixWorldNeedsUpdate = true;
  4529. },
  4530. updateMatrixWorld: function updateMatrixWorld(force) {
  4531. if (this.matrixAutoUpdate) this.updateMatrix();
  4532. if (this.matrixWorldNeedsUpdate || force) {
  4533. if (this.parent === null) {
  4534. this.matrixWorld.copy(this.matrix);
  4535. } else {
  4536. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4537. }
  4538. this.matrixWorldNeedsUpdate = false;
  4539. force = true;
  4540. } // update children
  4541. var children = this.children;
  4542. for (var i = 0, l = children.length; i < l; i++) {
  4543. children[i].updateMatrixWorld(force);
  4544. }
  4545. },
  4546. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4547. var parent = this.parent;
  4548. if (updateParents === true && parent !== null) {
  4549. parent.updateWorldMatrix(true, false);
  4550. }
  4551. if (this.matrixAutoUpdate) this.updateMatrix();
  4552. if (this.parent === null) {
  4553. this.matrixWorld.copy(this.matrix);
  4554. } else {
  4555. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4556. } // update children
  4557. if (updateChildren === true) {
  4558. var children = this.children;
  4559. for (var i = 0, l = children.length; i < l; i++) {
  4560. children[i].updateWorldMatrix(false, true);
  4561. }
  4562. }
  4563. },
  4564. toJSON: function toJSON(meta) {
  4565. // meta is a string when called from JSON.stringify
  4566. var isRootObject = meta === undefined || typeof meta === 'string';
  4567. var output = {}; // meta is a hash used to collect geometries, materials.
  4568. // not providing it implies that this is the root object
  4569. // being serialized.
  4570. if (isRootObject) {
  4571. // initialize meta obj
  4572. meta = {
  4573. geometries: {},
  4574. materials: {},
  4575. textures: {},
  4576. images: {},
  4577. shapes: {}
  4578. };
  4579. output.metadata = {
  4580. version: 4.5,
  4581. type: 'Object',
  4582. generator: 'Object3D.toJSON'
  4583. };
  4584. } // standard Object3D serialization
  4585. var object = {};
  4586. object.uuid = this.uuid;
  4587. object.type = this.type;
  4588. if (this.name !== '') object.name = this.name;
  4589. if (this.castShadow === true) object.castShadow = true;
  4590. if (this.receiveShadow === true) object.receiveShadow = true;
  4591. if (this.visible === false) object.visible = false;
  4592. if (this.frustumCulled === false) object.frustumCulled = false;
  4593. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4594. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4595. object.layers = this.layers.mask;
  4596. object.matrix = this.matrix.toArray();
  4597. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4598. if (this.isInstancedMesh) {
  4599. object.type = 'InstancedMesh';
  4600. object.count = this.count;
  4601. object.instanceMatrix = this.instanceMatrix.toJSON();
  4602. } //
  4603. function serialize(library, element) {
  4604. if (library[element.uuid] === undefined) {
  4605. library[element.uuid] = element.toJSON(meta);
  4606. }
  4607. return element.uuid;
  4608. }
  4609. if (this.isMesh || this.isLine || this.isPoints) {
  4610. object.geometry = serialize(meta.geometries, this.geometry);
  4611. var parameters = this.geometry.parameters;
  4612. if (parameters !== undefined && parameters.shapes !== undefined) {
  4613. var shapes = parameters.shapes;
  4614. if (Array.isArray(shapes)) {
  4615. for (var i = 0, l = shapes.length; i < l; i++) {
  4616. var shape = shapes[i];
  4617. serialize(meta.shapes, shape);
  4618. }
  4619. } else {
  4620. serialize(meta.shapes, shapes);
  4621. }
  4622. }
  4623. }
  4624. if (this.material !== undefined) {
  4625. if (Array.isArray(this.material)) {
  4626. var uuids = [];
  4627. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4628. uuids.push(serialize(meta.materials, this.material[_i]));
  4629. }
  4630. object.material = uuids;
  4631. } else {
  4632. object.material = serialize(meta.materials, this.material);
  4633. }
  4634. } //
  4635. if (this.children.length > 0) {
  4636. object.children = [];
  4637. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4638. object.children.push(this.children[_i2].toJSON(meta).object);
  4639. }
  4640. }
  4641. if (isRootObject) {
  4642. var geometries = extractFromCache(meta.geometries);
  4643. var materials = extractFromCache(meta.materials);
  4644. var textures = extractFromCache(meta.textures);
  4645. var images = extractFromCache(meta.images);
  4646. var _shapes = extractFromCache(meta.shapes);
  4647. if (geometries.length > 0) output.geometries = geometries;
  4648. if (materials.length > 0) output.materials = materials;
  4649. if (textures.length > 0) output.textures = textures;
  4650. if (images.length > 0) output.images = images;
  4651. if (_shapes.length > 0) output.shapes = _shapes;
  4652. }
  4653. output.object = object;
  4654. return output; // extract data from the cache hash
  4655. // remove metadata on each item
  4656. // and return as array
  4657. function extractFromCache(cache) {
  4658. var values = [];
  4659. for (var key in cache) {
  4660. var data = cache[key];
  4661. delete data.metadata;
  4662. values.push(data);
  4663. }
  4664. return values;
  4665. }
  4666. },
  4667. clone: function clone(recursive) {
  4668. return new this.constructor().copy(this, recursive);
  4669. },
  4670. copy: function copy(source, recursive) {
  4671. if (recursive === undefined) recursive = true;
  4672. this.name = source.name;
  4673. this.up.copy(source.up);
  4674. this.position.copy(source.position);
  4675. this.rotation.order = source.rotation.order;
  4676. this.quaternion.copy(source.quaternion);
  4677. this.scale.copy(source.scale);
  4678. this.matrix.copy(source.matrix);
  4679. this.matrixWorld.copy(source.matrixWorld);
  4680. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4681. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4682. this.layers.mask = source.layers.mask;
  4683. this.visible = source.visible;
  4684. this.castShadow = source.castShadow;
  4685. this.receiveShadow = source.receiveShadow;
  4686. this.frustumCulled = source.frustumCulled;
  4687. this.renderOrder = source.renderOrder;
  4688. this.userData = JSON.parse(JSON.stringify(source.userData));
  4689. if (recursive === true) {
  4690. for (var i = 0; i < source.children.length; i++) {
  4691. var child = source.children[i];
  4692. this.add(child.clone());
  4693. }
  4694. }
  4695. return this;
  4696. }
  4697. });
  4698. var _vector1 = /*@__PURE__*/new Vector3();
  4699. var _vector2 = /*@__PURE__*/new Vector3();
  4700. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4701. var Plane = /*#__PURE__*/function () {
  4702. function Plane(normal, constant) {
  4703. Object.defineProperty(this, 'isPlane', {
  4704. value: true
  4705. }); // normal is assumed to be normalized
  4706. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4707. this.constant = constant !== undefined ? constant : 0;
  4708. }
  4709. var _proto = Plane.prototype;
  4710. _proto.set = function set(normal, constant) {
  4711. this.normal.copy(normal);
  4712. this.constant = constant;
  4713. return this;
  4714. };
  4715. _proto.setComponents = function setComponents(x, y, z, w) {
  4716. this.normal.set(x, y, z);
  4717. this.constant = w;
  4718. return this;
  4719. };
  4720. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4721. this.normal.copy(normal);
  4722. this.constant = -point.dot(this.normal);
  4723. return this;
  4724. };
  4725. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4726. 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)?
  4727. this.setFromNormalAndCoplanarPoint(normal, a);
  4728. return this;
  4729. };
  4730. _proto.clone = function clone() {
  4731. return new this.constructor().copy(this);
  4732. };
  4733. _proto.copy = function copy(plane) {
  4734. this.normal.copy(plane.normal);
  4735. this.constant = plane.constant;
  4736. return this;
  4737. };
  4738. _proto.normalize = function normalize() {
  4739. // Note: will lead to a divide by zero if the plane is invalid.
  4740. var inverseNormalLength = 1.0 / this.normal.length();
  4741. this.normal.multiplyScalar(inverseNormalLength);
  4742. this.constant *= inverseNormalLength;
  4743. return this;
  4744. };
  4745. _proto.negate = function negate() {
  4746. this.constant *= -1;
  4747. this.normal.negate();
  4748. return this;
  4749. };
  4750. _proto.distanceToPoint = function distanceToPoint(point) {
  4751. return this.normal.dot(point) + this.constant;
  4752. };
  4753. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4754. return this.distanceToPoint(sphere.center) - sphere.radius;
  4755. };
  4756. _proto.projectPoint = function projectPoint(point, target) {
  4757. if (target === undefined) {
  4758. console.warn('THREE.Plane: .projectPoint() target is now required');
  4759. target = new Vector3();
  4760. }
  4761. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4762. };
  4763. _proto.intersectLine = function intersectLine(line, target) {
  4764. if (target === undefined) {
  4765. console.warn('THREE.Plane: .intersectLine() target is now required');
  4766. target = new Vector3();
  4767. }
  4768. var direction = line.delta(_vector1);
  4769. var denominator = this.normal.dot(direction);
  4770. if (denominator === 0) {
  4771. // line is coplanar, return origin
  4772. if (this.distanceToPoint(line.start) === 0) {
  4773. return target.copy(line.start);
  4774. } // Unsure if this is the correct method to handle this case.
  4775. return undefined;
  4776. }
  4777. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4778. if (t < 0 || t > 1) {
  4779. return undefined;
  4780. }
  4781. return target.copy(direction).multiplyScalar(t).add(line.start);
  4782. };
  4783. _proto.intersectsLine = function intersectsLine(line) {
  4784. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4785. var startSign = this.distanceToPoint(line.start);
  4786. var endSign = this.distanceToPoint(line.end);
  4787. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4788. };
  4789. _proto.intersectsBox = function intersectsBox(box) {
  4790. return box.intersectsPlane(this);
  4791. };
  4792. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4793. return sphere.intersectsPlane(this);
  4794. };
  4795. _proto.coplanarPoint = function coplanarPoint(target) {
  4796. if (target === undefined) {
  4797. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4798. target = new Vector3();
  4799. }
  4800. return target.copy(this.normal).multiplyScalar(-this.constant);
  4801. };
  4802. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4803. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4804. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4805. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4806. this.constant = -referencePoint.dot(normal);
  4807. return this;
  4808. };
  4809. _proto.translate = function translate(offset) {
  4810. this.constant -= offset.dot(this.normal);
  4811. return this;
  4812. };
  4813. _proto.equals = function equals(plane) {
  4814. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4815. };
  4816. return Plane;
  4817. }();
  4818. var _v0$1 = /*@__PURE__*/new Vector3();
  4819. var _v1$3 = /*@__PURE__*/new Vector3();
  4820. var _v2$1 = /*@__PURE__*/new Vector3();
  4821. var _v3 = /*@__PURE__*/new Vector3();
  4822. var _vab = /*@__PURE__*/new Vector3();
  4823. var _vac = /*@__PURE__*/new Vector3();
  4824. var _vbc = /*@__PURE__*/new Vector3();
  4825. var _vap = /*@__PURE__*/new Vector3();
  4826. var _vbp = /*@__PURE__*/new Vector3();
  4827. var _vcp = /*@__PURE__*/new Vector3();
  4828. var Triangle = /*#__PURE__*/function () {
  4829. function Triangle(a, b, c) {
  4830. this.a = a !== undefined ? a : new Vector3();
  4831. this.b = b !== undefined ? b : new Vector3();
  4832. this.c = c !== undefined ? c : new Vector3();
  4833. }
  4834. Triangle.getNormal = function getNormal(a, b, c, target) {
  4835. if (target === undefined) {
  4836. console.warn('THREE.Triangle: .getNormal() target is now required');
  4837. target = new Vector3();
  4838. }
  4839. target.subVectors(c, b);
  4840. _v0$1.subVectors(a, b);
  4841. target.cross(_v0$1);
  4842. var targetLengthSq = target.lengthSq();
  4843. if (targetLengthSq > 0) {
  4844. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4845. }
  4846. return target.set(0, 0, 0);
  4847. } // static/instance method to calculate barycentric coordinates
  4848. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4849. ;
  4850. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4851. _v0$1.subVectors(c, a);
  4852. _v1$3.subVectors(b, a);
  4853. _v2$1.subVectors(point, a);
  4854. var dot00 = _v0$1.dot(_v0$1);
  4855. var dot01 = _v0$1.dot(_v1$3);
  4856. var dot02 = _v0$1.dot(_v2$1);
  4857. var dot11 = _v1$3.dot(_v1$3);
  4858. var dot12 = _v1$3.dot(_v2$1);
  4859. var denom = dot00 * dot11 - dot01 * dot01;
  4860. if (target === undefined) {
  4861. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4862. target = new Vector3();
  4863. } // collinear or singular triangle
  4864. if (denom === 0) {
  4865. // arbitrary location outside of triangle?
  4866. // not sure if this is the best idea, maybe should be returning undefined
  4867. return target.set(-2, -1, -1);
  4868. }
  4869. var invDenom = 1 / denom;
  4870. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4871. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4872. return target.set(1 - u - v, v, u);
  4873. };
  4874. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4875. this.getBarycoord(point, a, b, c, _v3);
  4876. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4877. };
  4878. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4879. this.getBarycoord(point, p1, p2, p3, _v3);
  4880. target.set(0, 0);
  4881. target.addScaledVector(uv1, _v3.x);
  4882. target.addScaledVector(uv2, _v3.y);
  4883. target.addScaledVector(uv3, _v3.z);
  4884. return target;
  4885. };
  4886. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4887. _v0$1.subVectors(c, b);
  4888. _v1$3.subVectors(a, b); // strictly front facing
  4889. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4890. };
  4891. var _proto = Triangle.prototype;
  4892. _proto.set = function set(a, b, c) {
  4893. this.a.copy(a);
  4894. this.b.copy(b);
  4895. this.c.copy(c);
  4896. return this;
  4897. };
  4898. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4899. this.a.copy(points[i0]);
  4900. this.b.copy(points[i1]);
  4901. this.c.copy(points[i2]);
  4902. return this;
  4903. };
  4904. _proto.clone = function clone() {
  4905. return new this.constructor().copy(this);
  4906. };
  4907. _proto.copy = function copy(triangle) {
  4908. this.a.copy(triangle.a);
  4909. this.b.copy(triangle.b);
  4910. this.c.copy(triangle.c);
  4911. return this;
  4912. };
  4913. _proto.getArea = function getArea() {
  4914. _v0$1.subVectors(this.c, this.b);
  4915. _v1$3.subVectors(this.a, this.b);
  4916. return _v0$1.cross(_v1$3).length() * 0.5;
  4917. };
  4918. _proto.getMidpoint = function getMidpoint(target) {
  4919. if (target === undefined) {
  4920. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4921. target = new Vector3();
  4922. }
  4923. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  4924. };
  4925. _proto.getNormal = function getNormal(target) {
  4926. return Triangle.getNormal(this.a, this.b, this.c, target);
  4927. };
  4928. _proto.getPlane = function getPlane(target) {
  4929. if (target === undefined) {
  4930. console.warn('THREE.Triangle: .getPlane() target is now required');
  4931. target = new Plane();
  4932. }
  4933. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  4934. };
  4935. _proto.getBarycoord = function getBarycoord(point, target) {
  4936. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  4937. };
  4938. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  4939. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  4940. };
  4941. _proto.containsPoint = function containsPoint(point) {
  4942. return Triangle.containsPoint(point, this.a, this.b, this.c);
  4943. };
  4944. _proto.isFrontFacing = function isFrontFacing(direction) {
  4945. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  4946. };
  4947. _proto.intersectsBox = function intersectsBox(box) {
  4948. return box.intersectsTriangle(this);
  4949. };
  4950. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  4951. if (target === undefined) {
  4952. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  4953. target = new Vector3();
  4954. }
  4955. var a = this.a,
  4956. b = this.b,
  4957. c = this.c;
  4958. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4959. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4960. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4961. // basically, we're distinguishing which of the voronoi regions of the triangle
  4962. // the point lies in with the minimum amount of redundant computation.
  4963. _vab.subVectors(b, a);
  4964. _vac.subVectors(c, a);
  4965. _vap.subVectors(p, a);
  4966. var d1 = _vab.dot(_vap);
  4967. var d2 = _vac.dot(_vap);
  4968. if (d1 <= 0 && d2 <= 0) {
  4969. // vertex region of A; barycentric coords (1, 0, 0)
  4970. return target.copy(a);
  4971. }
  4972. _vbp.subVectors(p, b);
  4973. var d3 = _vab.dot(_vbp);
  4974. var d4 = _vac.dot(_vbp);
  4975. if (d3 >= 0 && d4 <= d3) {
  4976. // vertex region of B; barycentric coords (0, 1, 0)
  4977. return target.copy(b);
  4978. }
  4979. var vc = d1 * d4 - d3 * d2;
  4980. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  4981. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  4982. return target.copy(a).addScaledVector(_vab, v);
  4983. }
  4984. _vcp.subVectors(p, c);
  4985. var d5 = _vab.dot(_vcp);
  4986. var d6 = _vac.dot(_vcp);
  4987. if (d6 >= 0 && d5 <= d6) {
  4988. // vertex region of C; barycentric coords (0, 0, 1)
  4989. return target.copy(c);
  4990. }
  4991. var vb = d5 * d2 - d1 * d6;
  4992. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  4993. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  4994. return target.copy(a).addScaledVector(_vac, w);
  4995. }
  4996. var va = d3 * d6 - d5 * d4;
  4997. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  4998. _vbc.subVectors(c, b);
  4999. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5000. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5001. } // face region
  5002. var denom = 1 / (va + vb + vc); // u = va * denom
  5003. v = vb * denom;
  5004. w = vc * denom;
  5005. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5006. };
  5007. _proto.equals = function equals(triangle) {
  5008. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5009. };
  5010. return Triangle;
  5011. }();
  5012. var _colorKeywords = {
  5013. 'aliceblue': 0xF0F8FF,
  5014. 'antiquewhite': 0xFAEBD7,
  5015. 'aqua': 0x00FFFF,
  5016. 'aquamarine': 0x7FFFD4,
  5017. 'azure': 0xF0FFFF,
  5018. 'beige': 0xF5F5DC,
  5019. 'bisque': 0xFFE4C4,
  5020. 'black': 0x000000,
  5021. 'blanchedalmond': 0xFFEBCD,
  5022. 'blue': 0x0000FF,
  5023. 'blueviolet': 0x8A2BE2,
  5024. 'brown': 0xA52A2A,
  5025. 'burlywood': 0xDEB887,
  5026. 'cadetblue': 0x5F9EA0,
  5027. 'chartreuse': 0x7FFF00,
  5028. 'chocolate': 0xD2691E,
  5029. 'coral': 0xFF7F50,
  5030. 'cornflowerblue': 0x6495ED,
  5031. 'cornsilk': 0xFFF8DC,
  5032. 'crimson': 0xDC143C,
  5033. 'cyan': 0x00FFFF,
  5034. 'darkblue': 0x00008B,
  5035. 'darkcyan': 0x008B8B,
  5036. 'darkgoldenrod': 0xB8860B,
  5037. 'darkgray': 0xA9A9A9,
  5038. 'darkgreen': 0x006400,
  5039. 'darkgrey': 0xA9A9A9,
  5040. 'darkkhaki': 0xBDB76B,
  5041. 'darkmagenta': 0x8B008B,
  5042. 'darkolivegreen': 0x556B2F,
  5043. 'darkorange': 0xFF8C00,
  5044. 'darkorchid': 0x9932CC,
  5045. 'darkred': 0x8B0000,
  5046. 'darksalmon': 0xE9967A,
  5047. 'darkseagreen': 0x8FBC8F,
  5048. 'darkslateblue': 0x483D8B,
  5049. 'darkslategray': 0x2F4F4F,
  5050. 'darkslategrey': 0x2F4F4F,
  5051. 'darkturquoise': 0x00CED1,
  5052. 'darkviolet': 0x9400D3,
  5053. 'deeppink': 0xFF1493,
  5054. 'deepskyblue': 0x00BFFF,
  5055. 'dimgray': 0x696969,
  5056. 'dimgrey': 0x696969,
  5057. 'dodgerblue': 0x1E90FF,
  5058. 'firebrick': 0xB22222,
  5059. 'floralwhite': 0xFFFAF0,
  5060. 'forestgreen': 0x228B22,
  5061. 'fuchsia': 0xFF00FF,
  5062. 'gainsboro': 0xDCDCDC,
  5063. 'ghostwhite': 0xF8F8FF,
  5064. 'gold': 0xFFD700,
  5065. 'goldenrod': 0xDAA520,
  5066. 'gray': 0x808080,
  5067. 'green': 0x008000,
  5068. 'greenyellow': 0xADFF2F,
  5069. 'grey': 0x808080,
  5070. 'honeydew': 0xF0FFF0,
  5071. 'hotpink': 0xFF69B4,
  5072. 'indianred': 0xCD5C5C,
  5073. 'indigo': 0x4B0082,
  5074. 'ivory': 0xFFFFF0,
  5075. 'khaki': 0xF0E68C,
  5076. 'lavender': 0xE6E6FA,
  5077. 'lavenderblush': 0xFFF0F5,
  5078. 'lawngreen': 0x7CFC00,
  5079. 'lemonchiffon': 0xFFFACD,
  5080. 'lightblue': 0xADD8E6,
  5081. 'lightcoral': 0xF08080,
  5082. 'lightcyan': 0xE0FFFF,
  5083. 'lightgoldenrodyellow': 0xFAFAD2,
  5084. 'lightgray': 0xD3D3D3,
  5085. 'lightgreen': 0x90EE90,
  5086. 'lightgrey': 0xD3D3D3,
  5087. 'lightpink': 0xFFB6C1,
  5088. 'lightsalmon': 0xFFA07A,
  5089. 'lightseagreen': 0x20B2AA,
  5090. 'lightskyblue': 0x87CEFA,
  5091. 'lightslategray': 0x778899,
  5092. 'lightslategrey': 0x778899,
  5093. 'lightsteelblue': 0xB0C4DE,
  5094. 'lightyellow': 0xFFFFE0,
  5095. 'lime': 0x00FF00,
  5096. 'limegreen': 0x32CD32,
  5097. 'linen': 0xFAF0E6,
  5098. 'magenta': 0xFF00FF,
  5099. 'maroon': 0x800000,
  5100. 'mediumaquamarine': 0x66CDAA,
  5101. 'mediumblue': 0x0000CD,
  5102. 'mediumorchid': 0xBA55D3,
  5103. 'mediumpurple': 0x9370DB,
  5104. 'mediumseagreen': 0x3CB371,
  5105. 'mediumslateblue': 0x7B68EE,
  5106. 'mediumspringgreen': 0x00FA9A,
  5107. 'mediumturquoise': 0x48D1CC,
  5108. 'mediumvioletred': 0xC71585,
  5109. 'midnightblue': 0x191970,
  5110. 'mintcream': 0xF5FFFA,
  5111. 'mistyrose': 0xFFE4E1,
  5112. 'moccasin': 0xFFE4B5,
  5113. 'navajowhite': 0xFFDEAD,
  5114. 'navy': 0x000080,
  5115. 'oldlace': 0xFDF5E6,
  5116. 'olive': 0x808000,
  5117. 'olivedrab': 0x6B8E23,
  5118. 'orange': 0xFFA500,
  5119. 'orangered': 0xFF4500,
  5120. 'orchid': 0xDA70D6,
  5121. 'palegoldenrod': 0xEEE8AA,
  5122. 'palegreen': 0x98FB98,
  5123. 'paleturquoise': 0xAFEEEE,
  5124. 'palevioletred': 0xDB7093,
  5125. 'papayawhip': 0xFFEFD5,
  5126. 'peachpuff': 0xFFDAB9,
  5127. 'peru': 0xCD853F,
  5128. 'pink': 0xFFC0CB,
  5129. 'plum': 0xDDA0DD,
  5130. 'powderblue': 0xB0E0E6,
  5131. 'purple': 0x800080,
  5132. 'rebeccapurple': 0x663399,
  5133. 'red': 0xFF0000,
  5134. 'rosybrown': 0xBC8F8F,
  5135. 'royalblue': 0x4169E1,
  5136. 'saddlebrown': 0x8B4513,
  5137. 'salmon': 0xFA8072,
  5138. 'sandybrown': 0xF4A460,
  5139. 'seagreen': 0x2E8B57,
  5140. 'seashell': 0xFFF5EE,
  5141. 'sienna': 0xA0522D,
  5142. 'silver': 0xC0C0C0,
  5143. 'skyblue': 0x87CEEB,
  5144. 'slateblue': 0x6A5ACD,
  5145. 'slategray': 0x708090,
  5146. 'slategrey': 0x708090,
  5147. 'snow': 0xFFFAFA,
  5148. 'springgreen': 0x00FF7F,
  5149. 'steelblue': 0x4682B4,
  5150. 'tan': 0xD2B48C,
  5151. 'teal': 0x008080,
  5152. 'thistle': 0xD8BFD8,
  5153. 'tomato': 0xFF6347,
  5154. 'turquoise': 0x40E0D0,
  5155. 'violet': 0xEE82EE,
  5156. 'wheat': 0xF5DEB3,
  5157. 'white': 0xFFFFFF,
  5158. 'whitesmoke': 0xF5F5F5,
  5159. 'yellow': 0xFFFF00,
  5160. 'yellowgreen': 0x9ACD32
  5161. };
  5162. var _hslA = {
  5163. h: 0,
  5164. s: 0,
  5165. l: 0
  5166. };
  5167. var _hslB = {
  5168. h: 0,
  5169. s: 0,
  5170. l: 0
  5171. };
  5172. function hue2rgb(p, q, t) {
  5173. if (t < 0) t += 1;
  5174. if (t > 1) t -= 1;
  5175. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5176. if (t < 1 / 2) return q;
  5177. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5178. return p;
  5179. }
  5180. function SRGBToLinear(c) {
  5181. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5182. }
  5183. function LinearToSRGB(c) {
  5184. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5185. }
  5186. var Color = /*#__PURE__*/function () {
  5187. function Color(r, g, b) {
  5188. Object.defineProperty(this, 'isColor', {
  5189. value: true
  5190. });
  5191. if (g === undefined && b === undefined) {
  5192. // r is THREE.Color, hex or string
  5193. return this.set(r);
  5194. }
  5195. return this.setRGB(r, g, b);
  5196. }
  5197. var _proto = Color.prototype;
  5198. _proto.set = function set(value) {
  5199. if (value && value.isColor) {
  5200. this.copy(value);
  5201. } else if (typeof value === 'number') {
  5202. this.setHex(value);
  5203. } else if (typeof value === 'string') {
  5204. this.setStyle(value);
  5205. }
  5206. return this;
  5207. };
  5208. _proto.setScalar = function setScalar(scalar) {
  5209. this.r = scalar;
  5210. this.g = scalar;
  5211. this.b = scalar;
  5212. return this;
  5213. };
  5214. _proto.setHex = function setHex(hex) {
  5215. hex = Math.floor(hex);
  5216. this.r = (hex >> 16 & 255) / 255;
  5217. this.g = (hex >> 8 & 255) / 255;
  5218. this.b = (hex & 255) / 255;
  5219. return this;
  5220. };
  5221. _proto.setRGB = function setRGB(r, g, b) {
  5222. this.r = r;
  5223. this.g = g;
  5224. this.b = b;
  5225. return this;
  5226. };
  5227. _proto.setHSL = function setHSL(h, s, l) {
  5228. // h,s,l ranges are in 0.0 - 1.0
  5229. h = MathUtils.euclideanModulo(h, 1);
  5230. s = MathUtils.clamp(s, 0, 1);
  5231. l = MathUtils.clamp(l, 0, 1);
  5232. if (s === 0) {
  5233. this.r = this.g = this.b = l;
  5234. } else {
  5235. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5236. var q = 2 * l - p;
  5237. this.r = hue2rgb(q, p, h + 1 / 3);
  5238. this.g = hue2rgb(q, p, h);
  5239. this.b = hue2rgb(q, p, h - 1 / 3);
  5240. }
  5241. return this;
  5242. };
  5243. _proto.setStyle = function setStyle(style) {
  5244. function handleAlpha(string) {
  5245. if (string === undefined) return;
  5246. if (parseFloat(string) < 1) {
  5247. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5248. }
  5249. }
  5250. var m;
  5251. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5252. // rgb / hsl
  5253. var color;
  5254. var name = m[1];
  5255. var components = m[2];
  5256. switch (name) {
  5257. case 'rgb':
  5258. case 'rgba':
  5259. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5260. // rgb(255,0,0) rgba(255,0,0,0.5)
  5261. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5262. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5263. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5264. handleAlpha(color[5]);
  5265. return this;
  5266. }
  5267. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5268. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5269. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5270. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5271. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5272. handleAlpha(color[5]);
  5273. return this;
  5274. }
  5275. break;
  5276. case 'hsl':
  5277. case 'hsla':
  5278. if (color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5279. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5280. var h = parseFloat(color[1]) / 360;
  5281. var s = parseInt(color[2], 10) / 100;
  5282. var l = parseInt(color[3], 10) / 100;
  5283. handleAlpha(color[5]);
  5284. return this.setHSL(h, s, l);
  5285. }
  5286. break;
  5287. }
  5288. } else if (m = /^\#([A-Fa-f0-9]+)$/.exec(style)) {
  5289. // hex color
  5290. var hex = m[1];
  5291. var size = hex.length;
  5292. if (size === 3) {
  5293. // #ff0
  5294. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5295. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5296. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5297. return this;
  5298. } else if (size === 6) {
  5299. // #ff0000
  5300. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5301. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5302. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5303. return this;
  5304. }
  5305. }
  5306. if (style && style.length > 0) {
  5307. return this.setColorName(style);
  5308. }
  5309. return this;
  5310. };
  5311. _proto.setColorName = function setColorName(style) {
  5312. // color keywords
  5313. var hex = _colorKeywords[style];
  5314. if (hex !== undefined) {
  5315. // red
  5316. this.setHex(hex);
  5317. } else {
  5318. // unknown color
  5319. console.warn('THREE.Color: Unknown color ' + style);
  5320. }
  5321. return this;
  5322. };
  5323. _proto.clone = function clone() {
  5324. return new this.constructor(this.r, this.g, this.b);
  5325. };
  5326. _proto.copy = function copy(color) {
  5327. this.r = color.r;
  5328. this.g = color.g;
  5329. this.b = color.b;
  5330. return this;
  5331. };
  5332. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5333. if (gammaFactor === undefined) gammaFactor = 2.0;
  5334. this.r = Math.pow(color.r, gammaFactor);
  5335. this.g = Math.pow(color.g, gammaFactor);
  5336. this.b = Math.pow(color.b, gammaFactor);
  5337. return this;
  5338. };
  5339. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5340. if (gammaFactor === undefined) gammaFactor = 2.0;
  5341. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5342. this.r = Math.pow(color.r, safeInverse);
  5343. this.g = Math.pow(color.g, safeInverse);
  5344. this.b = Math.pow(color.b, safeInverse);
  5345. return this;
  5346. };
  5347. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5348. this.copyGammaToLinear(this, gammaFactor);
  5349. return this;
  5350. };
  5351. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5352. this.copyLinearToGamma(this, gammaFactor);
  5353. return this;
  5354. };
  5355. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5356. this.r = SRGBToLinear(color.r);
  5357. this.g = SRGBToLinear(color.g);
  5358. this.b = SRGBToLinear(color.b);
  5359. return this;
  5360. };
  5361. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5362. this.r = LinearToSRGB(color.r);
  5363. this.g = LinearToSRGB(color.g);
  5364. this.b = LinearToSRGB(color.b);
  5365. return this;
  5366. };
  5367. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5368. this.copySRGBToLinear(this);
  5369. return this;
  5370. };
  5371. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5372. this.copyLinearToSRGB(this);
  5373. return this;
  5374. };
  5375. _proto.getHex = function getHex() {
  5376. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5377. };
  5378. _proto.getHexString = function getHexString() {
  5379. return ('000000' + this.getHex().toString(16)).slice(-6);
  5380. };
  5381. _proto.getHSL = function getHSL(target) {
  5382. // h,s,l ranges are in 0.0 - 1.0
  5383. if (target === undefined) {
  5384. console.warn('THREE.Color: .getHSL() target is now required');
  5385. target = {
  5386. h: 0,
  5387. s: 0,
  5388. l: 0
  5389. };
  5390. }
  5391. var r = this.r,
  5392. g = this.g,
  5393. b = this.b;
  5394. var max = Math.max(r, g, b);
  5395. var min = Math.min(r, g, b);
  5396. var hue, saturation;
  5397. var lightness = (min + max) / 2.0;
  5398. if (min === max) {
  5399. hue = 0;
  5400. saturation = 0;
  5401. } else {
  5402. var delta = max - min;
  5403. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5404. switch (max) {
  5405. case r:
  5406. hue = (g - b) / delta + (g < b ? 6 : 0);
  5407. break;
  5408. case g:
  5409. hue = (b - r) / delta + 2;
  5410. break;
  5411. case b:
  5412. hue = (r - g) / delta + 4;
  5413. break;
  5414. }
  5415. hue /= 6;
  5416. }
  5417. target.h = hue;
  5418. target.s = saturation;
  5419. target.l = lightness;
  5420. return target;
  5421. };
  5422. _proto.getStyle = function getStyle() {
  5423. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5424. };
  5425. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5426. this.getHSL(_hslA);
  5427. _hslA.h += h;
  5428. _hslA.s += s;
  5429. _hslA.l += l;
  5430. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5431. return this;
  5432. };
  5433. _proto.add = function add(color) {
  5434. this.r += color.r;
  5435. this.g += color.g;
  5436. this.b += color.b;
  5437. return this;
  5438. };
  5439. _proto.addColors = function addColors(color1, color2) {
  5440. this.r = color1.r + color2.r;
  5441. this.g = color1.g + color2.g;
  5442. this.b = color1.b + color2.b;
  5443. return this;
  5444. };
  5445. _proto.addScalar = function addScalar(s) {
  5446. this.r += s;
  5447. this.g += s;
  5448. this.b += s;
  5449. return this;
  5450. };
  5451. _proto.sub = function sub(color) {
  5452. this.r = Math.max(0, this.r - color.r);
  5453. this.g = Math.max(0, this.g - color.g);
  5454. this.b = Math.max(0, this.b - color.b);
  5455. return this;
  5456. };
  5457. _proto.multiply = function multiply(color) {
  5458. this.r *= color.r;
  5459. this.g *= color.g;
  5460. this.b *= color.b;
  5461. return this;
  5462. };
  5463. _proto.multiplyScalar = function multiplyScalar(s) {
  5464. this.r *= s;
  5465. this.g *= s;
  5466. this.b *= s;
  5467. return this;
  5468. };
  5469. _proto.lerp = function lerp(color, alpha) {
  5470. this.r += (color.r - this.r) * alpha;
  5471. this.g += (color.g - this.g) * alpha;
  5472. this.b += (color.b - this.b) * alpha;
  5473. return this;
  5474. };
  5475. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5476. this.getHSL(_hslA);
  5477. color.getHSL(_hslB);
  5478. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5479. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5480. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5481. this.setHSL(h, s, l);
  5482. return this;
  5483. };
  5484. _proto.equals = function equals(c) {
  5485. return c.r === this.r && c.g === this.g && c.b === this.b;
  5486. };
  5487. _proto.fromArray = function fromArray(array, offset) {
  5488. if (offset === void 0) {
  5489. offset = 0;
  5490. }
  5491. this.r = array[offset];
  5492. this.g = array[offset + 1];
  5493. this.b = array[offset + 2];
  5494. return this;
  5495. };
  5496. _proto.toArray = function toArray(array, offset) {
  5497. if (array === void 0) {
  5498. array = [];
  5499. }
  5500. if (offset === void 0) {
  5501. offset = 0;
  5502. }
  5503. array[offset] = this.r;
  5504. array[offset + 1] = this.g;
  5505. array[offset + 2] = this.b;
  5506. return array;
  5507. };
  5508. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5509. this.r = attribute.getX(index);
  5510. this.g = attribute.getY(index);
  5511. this.b = attribute.getZ(index);
  5512. if (attribute.normalized === true) {
  5513. // assuming Uint8Array
  5514. this.r /= 255;
  5515. this.g /= 255;
  5516. this.b /= 255;
  5517. }
  5518. return this;
  5519. };
  5520. _proto.toJSON = function toJSON() {
  5521. return this.getHex();
  5522. };
  5523. return Color;
  5524. }();
  5525. Color.NAMES = _colorKeywords;
  5526. Color.prototype.r = 1;
  5527. Color.prototype.g = 1;
  5528. Color.prototype.b = 1;
  5529. var Face3 = /*#__PURE__*/function () {
  5530. function Face3(a, b, c, normal, color, materialIndex) {
  5531. this.a = a;
  5532. this.b = b;
  5533. this.c = c;
  5534. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5535. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5536. this.color = color && color.isColor ? color : new Color();
  5537. this.vertexColors = Array.isArray(color) ? color : [];
  5538. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5539. }
  5540. var _proto = Face3.prototype;
  5541. _proto.clone = function clone() {
  5542. return new this.constructor().copy(this);
  5543. };
  5544. _proto.copy = function copy(source) {
  5545. this.a = source.a;
  5546. this.b = source.b;
  5547. this.c = source.c;
  5548. this.normal.copy(source.normal);
  5549. this.color.copy(source.color);
  5550. this.materialIndex = source.materialIndex;
  5551. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5552. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5553. }
  5554. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5555. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5556. }
  5557. return this;
  5558. };
  5559. return Face3;
  5560. }();
  5561. var materialId = 0;
  5562. function Material() {
  5563. Object.defineProperty(this, 'id', {
  5564. value: materialId++
  5565. });
  5566. this.uuid = MathUtils.generateUUID();
  5567. this.name = '';
  5568. this.type = 'Material';
  5569. this.fog = true;
  5570. this.blending = NormalBlending;
  5571. this.side = FrontSide;
  5572. this.flatShading = false;
  5573. this.vertexColors = false;
  5574. this.opacity = 1;
  5575. this.transparent = false;
  5576. this.blendSrc = SrcAlphaFactor;
  5577. this.blendDst = OneMinusSrcAlphaFactor;
  5578. this.blendEquation = AddEquation;
  5579. this.blendSrcAlpha = null;
  5580. this.blendDstAlpha = null;
  5581. this.blendEquationAlpha = null;
  5582. this.depthFunc = LessEqualDepth;
  5583. this.depthTest = true;
  5584. this.depthWrite = true;
  5585. this.stencilWriteMask = 0xff;
  5586. this.stencilFunc = AlwaysStencilFunc;
  5587. this.stencilRef = 0;
  5588. this.stencilFuncMask = 0xff;
  5589. this.stencilFail = KeepStencilOp;
  5590. this.stencilZFail = KeepStencilOp;
  5591. this.stencilZPass = KeepStencilOp;
  5592. this.stencilWrite = false;
  5593. this.clippingPlanes = null;
  5594. this.clipIntersection = false;
  5595. this.clipShadows = false;
  5596. this.shadowSide = null;
  5597. this.colorWrite = true;
  5598. this.precision = null; // override the renderer's default precision for this material
  5599. this.polygonOffset = false;
  5600. this.polygonOffsetFactor = 0;
  5601. this.polygonOffsetUnits = 0;
  5602. this.dithering = false;
  5603. this.alphaTest = 0;
  5604. this.premultipliedAlpha = false;
  5605. this.visible = true;
  5606. this.toneMapped = true;
  5607. this.userData = {};
  5608. this.version = 0;
  5609. }
  5610. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5611. constructor: Material,
  5612. isMaterial: true,
  5613. onBeforeCompile: function onBeforeCompile()
  5614. /* shaderobject, renderer */
  5615. {},
  5616. customProgramCacheKey: function customProgramCacheKey() {
  5617. return this.onBeforeCompile.toString();
  5618. },
  5619. setValues: function setValues(values) {
  5620. if (values === undefined) return;
  5621. for (var key in values) {
  5622. var newValue = values[key];
  5623. if (newValue === undefined) {
  5624. console.warn("THREE.Material: '" + key + "' parameter is undefined.");
  5625. continue;
  5626. } // for backward compatability if shading is set in the constructor
  5627. if (key === 'shading') {
  5628. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5629. this.flatShading = newValue === FlatShading ? true : false;
  5630. continue;
  5631. }
  5632. var currentValue = this[key];
  5633. if (currentValue === undefined) {
  5634. console.warn("THREE." + this.type + ": '" + key + "' is not a property of this material.");
  5635. continue;
  5636. }
  5637. if (currentValue && currentValue.isColor) {
  5638. currentValue.set(newValue);
  5639. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5640. currentValue.copy(newValue);
  5641. } else {
  5642. this[key] = newValue;
  5643. }
  5644. }
  5645. },
  5646. toJSON: function toJSON(meta) {
  5647. var isRoot = meta === undefined || typeof meta === 'string';
  5648. if (isRoot) {
  5649. meta = {
  5650. textures: {},
  5651. images: {}
  5652. };
  5653. }
  5654. var data = {
  5655. metadata: {
  5656. version: 4.5,
  5657. type: 'Material',
  5658. generator: 'Material.toJSON'
  5659. }
  5660. }; // standard Material serialization
  5661. data.uuid = this.uuid;
  5662. data.type = this.type;
  5663. if (this.name !== '') data.name = this.name;
  5664. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5665. if (this.roughness !== undefined) data.roughness = this.roughness;
  5666. if (this.metalness !== undefined) data.metalness = this.metalness;
  5667. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5668. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5669. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5670. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5671. if (this.shininess !== undefined) data.shininess = this.shininess;
  5672. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5673. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5674. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5675. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5676. }
  5677. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5678. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5679. }
  5680. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5681. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5682. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5683. }
  5684. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5685. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5686. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5687. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5688. if (this.aoMap && this.aoMap.isTexture) {
  5689. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5690. data.aoMapIntensity = this.aoMapIntensity;
  5691. }
  5692. if (this.bumpMap && this.bumpMap.isTexture) {
  5693. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5694. data.bumpScale = this.bumpScale;
  5695. }
  5696. if (this.normalMap && this.normalMap.isTexture) {
  5697. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5698. data.normalMapType = this.normalMapType;
  5699. data.normalScale = this.normalScale.toArray();
  5700. }
  5701. if (this.displacementMap && this.displacementMap.isTexture) {
  5702. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5703. data.displacementScale = this.displacementScale;
  5704. data.displacementBias = this.displacementBias;
  5705. }
  5706. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5707. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5708. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5709. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5710. if (this.envMap && this.envMap.isTexture) {
  5711. data.envMap = this.envMap.toJSON(meta).uuid;
  5712. data.reflectivity = this.reflectivity; // Scale behind envMap
  5713. data.refractionRatio = this.refractionRatio;
  5714. if (this.combine !== undefined) data.combine = this.combine;
  5715. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5716. }
  5717. if (this.gradientMap && this.gradientMap.isTexture) {
  5718. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5719. }
  5720. if (this.size !== undefined) data.size = this.size;
  5721. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5722. if (this.blending !== NormalBlending) data.blending = this.blending;
  5723. if (this.flatShading === true) data.flatShading = this.flatShading;
  5724. if (this.side !== FrontSide) data.side = this.side;
  5725. if (this.vertexColors) data.vertexColors = true;
  5726. if (this.opacity < 1) data.opacity = this.opacity;
  5727. if (this.transparent === true) data.transparent = this.transparent;
  5728. data.depthFunc = this.depthFunc;
  5729. data.depthTest = this.depthTest;
  5730. data.depthWrite = this.depthWrite;
  5731. data.stencilWrite = this.stencilWrite;
  5732. data.stencilWriteMask = this.stencilWriteMask;
  5733. data.stencilFunc = this.stencilFunc;
  5734. data.stencilRef = this.stencilRef;
  5735. data.stencilFuncMask = this.stencilFuncMask;
  5736. data.stencilFail = this.stencilFail;
  5737. data.stencilZFail = this.stencilZFail;
  5738. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5739. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5740. if (this.polygonOffset === true) data.polygonOffset = true;
  5741. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5742. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5743. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5744. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5745. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5746. if (this.scale !== undefined) data.scale = this.scale;
  5747. if (this.dithering === true) data.dithering = true;
  5748. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5749. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5750. if (this.wireframe === true) data.wireframe = this.wireframe;
  5751. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5752. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5753. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5754. if (this.morphTargets === true) data.morphTargets = true;
  5755. if (this.morphNormals === true) data.morphNormals = true;
  5756. if (this.skinning === true) data.skinning = true;
  5757. if (this.visible === false) data.visible = false;
  5758. if (this.toneMapped === false) data.toneMapped = false;
  5759. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5760. function extractFromCache(cache) {
  5761. var values = [];
  5762. for (var key in cache) {
  5763. var _data = cache[key];
  5764. delete _data.metadata;
  5765. values.push(_data);
  5766. }
  5767. return values;
  5768. }
  5769. if (isRoot) {
  5770. var textures = extractFromCache(meta.textures);
  5771. var images = extractFromCache(meta.images);
  5772. if (textures.length > 0) data.textures = textures;
  5773. if (images.length > 0) data.images = images;
  5774. }
  5775. return data;
  5776. },
  5777. clone: function clone() {
  5778. return new this.constructor().copy(this);
  5779. },
  5780. copy: function copy(source) {
  5781. this.name = source.name;
  5782. this.fog = source.fog;
  5783. this.blending = source.blending;
  5784. this.side = source.side;
  5785. this.flatShading = source.flatShading;
  5786. this.vertexColors = source.vertexColors;
  5787. this.opacity = source.opacity;
  5788. this.transparent = source.transparent;
  5789. this.blendSrc = source.blendSrc;
  5790. this.blendDst = source.blendDst;
  5791. this.blendEquation = source.blendEquation;
  5792. this.blendSrcAlpha = source.blendSrcAlpha;
  5793. this.blendDstAlpha = source.blendDstAlpha;
  5794. this.blendEquationAlpha = source.blendEquationAlpha;
  5795. this.depthFunc = source.depthFunc;
  5796. this.depthTest = source.depthTest;
  5797. this.depthWrite = source.depthWrite;
  5798. this.stencilWriteMask = source.stencilWriteMask;
  5799. this.stencilFunc = source.stencilFunc;
  5800. this.stencilRef = source.stencilRef;
  5801. this.stencilFuncMask = source.stencilFuncMask;
  5802. this.stencilFail = source.stencilFail;
  5803. this.stencilZFail = source.stencilZFail;
  5804. this.stencilZPass = source.stencilZPass;
  5805. this.stencilWrite = source.stencilWrite;
  5806. var srcPlanes = source.clippingPlanes;
  5807. var dstPlanes = null;
  5808. if (srcPlanes !== null) {
  5809. var n = srcPlanes.length;
  5810. dstPlanes = new Array(n);
  5811. for (var i = 0; i !== n; ++i) {
  5812. dstPlanes[i] = srcPlanes[i].clone();
  5813. }
  5814. }
  5815. this.clippingPlanes = dstPlanes;
  5816. this.clipIntersection = source.clipIntersection;
  5817. this.clipShadows = source.clipShadows;
  5818. this.shadowSide = source.shadowSide;
  5819. this.colorWrite = source.colorWrite;
  5820. this.precision = source.precision;
  5821. this.polygonOffset = source.polygonOffset;
  5822. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5823. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5824. this.dithering = source.dithering;
  5825. this.alphaTest = source.alphaTest;
  5826. this.premultipliedAlpha = source.premultipliedAlpha;
  5827. this.visible = source.visible;
  5828. this.toneMapped = source.toneMapped;
  5829. this.userData = JSON.parse(JSON.stringify(source.userData));
  5830. return this;
  5831. },
  5832. dispose: function dispose() {
  5833. this.dispatchEvent({
  5834. type: 'dispose'
  5835. });
  5836. }
  5837. });
  5838. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5839. set: function set(value) {
  5840. if (value === true) this.version++;
  5841. }
  5842. });
  5843. /**
  5844. * parameters = {
  5845. * color: <hex>,
  5846. * opacity: <float>,
  5847. * map: new THREE.Texture( <Image> ),
  5848. *
  5849. * lightMap: new THREE.Texture( <Image> ),
  5850. * lightMapIntensity: <float>
  5851. *
  5852. * aoMap: new THREE.Texture( <Image> ),
  5853. * aoMapIntensity: <float>
  5854. *
  5855. * specularMap: new THREE.Texture( <Image> ),
  5856. *
  5857. * alphaMap: new THREE.Texture( <Image> ),
  5858. *
  5859. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5860. * combine: THREE.Multiply,
  5861. * reflectivity: <float>,
  5862. * refractionRatio: <float>,
  5863. *
  5864. * depthTest: <bool>,
  5865. * depthWrite: <bool>,
  5866. *
  5867. * wireframe: <boolean>,
  5868. * wireframeLinewidth: <float>,
  5869. *
  5870. * skinning: <bool>,
  5871. * morphTargets: <bool>
  5872. * }
  5873. */
  5874. function MeshBasicMaterial(parameters) {
  5875. Material.call(this);
  5876. this.type = 'MeshBasicMaterial';
  5877. this.color = new Color(0xffffff); // emissive
  5878. this.map = null;
  5879. this.lightMap = null;
  5880. this.lightMapIntensity = 1.0;
  5881. this.aoMap = null;
  5882. this.aoMapIntensity = 1.0;
  5883. this.specularMap = null;
  5884. this.alphaMap = null;
  5885. this.envMap = null;
  5886. this.combine = MultiplyOperation;
  5887. this.reflectivity = 1;
  5888. this.refractionRatio = 0.98;
  5889. this.wireframe = false;
  5890. this.wireframeLinewidth = 1;
  5891. this.wireframeLinecap = 'round';
  5892. this.wireframeLinejoin = 'round';
  5893. this.skinning = false;
  5894. this.morphTargets = false;
  5895. this.setValues(parameters);
  5896. }
  5897. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5898. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5899. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5900. MeshBasicMaterial.prototype.copy = function (source) {
  5901. Material.prototype.copy.call(this, source);
  5902. this.color.copy(source.color);
  5903. this.map = source.map;
  5904. this.lightMap = source.lightMap;
  5905. this.lightMapIntensity = source.lightMapIntensity;
  5906. this.aoMap = source.aoMap;
  5907. this.aoMapIntensity = source.aoMapIntensity;
  5908. this.specularMap = source.specularMap;
  5909. this.alphaMap = source.alphaMap;
  5910. this.envMap = source.envMap;
  5911. this.combine = source.combine;
  5912. this.reflectivity = source.reflectivity;
  5913. this.refractionRatio = source.refractionRatio;
  5914. this.wireframe = source.wireframe;
  5915. this.wireframeLinewidth = source.wireframeLinewidth;
  5916. this.wireframeLinecap = source.wireframeLinecap;
  5917. this.wireframeLinejoin = source.wireframeLinejoin;
  5918. this.skinning = source.skinning;
  5919. this.morphTargets = source.morphTargets;
  5920. return this;
  5921. };
  5922. var _vector$3 = new Vector3();
  5923. var _vector2$1 = new Vector2();
  5924. function BufferAttribute(array, itemSize, normalized) {
  5925. if (Array.isArray(array)) {
  5926. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  5927. }
  5928. this.name = '';
  5929. this.array = array;
  5930. this.itemSize = itemSize;
  5931. this.count = array !== undefined ? array.length / itemSize : 0;
  5932. this.normalized = normalized === true;
  5933. this.usage = StaticDrawUsage;
  5934. this.updateRange = {
  5935. offset: 0,
  5936. count: -1
  5937. };
  5938. this.version = 0;
  5939. }
  5940. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  5941. set: function set(value) {
  5942. if (value === true) this.version++;
  5943. }
  5944. });
  5945. Object.assign(BufferAttribute.prototype, {
  5946. isBufferAttribute: true,
  5947. onUploadCallback: function onUploadCallback() {},
  5948. setUsage: function setUsage(value) {
  5949. this.usage = value;
  5950. return this;
  5951. },
  5952. copy: function copy(source) {
  5953. this.name = source.name;
  5954. this.array = new source.array.constructor(source.array);
  5955. this.itemSize = source.itemSize;
  5956. this.count = source.count;
  5957. this.normalized = source.normalized;
  5958. this.usage = source.usage;
  5959. return this;
  5960. },
  5961. copyAt: function copyAt(index1, attribute, index2) {
  5962. index1 *= this.itemSize;
  5963. index2 *= attribute.itemSize;
  5964. for (var i = 0, l = this.itemSize; i < l; i++) {
  5965. this.array[index1 + i] = attribute.array[index2 + i];
  5966. }
  5967. return this;
  5968. },
  5969. copyArray: function copyArray(array) {
  5970. this.array.set(array);
  5971. return this;
  5972. },
  5973. copyColorsArray: function copyColorsArray(colors) {
  5974. var array = this.array;
  5975. var offset = 0;
  5976. for (var i = 0, l = colors.length; i < l; i++) {
  5977. var color = colors[i];
  5978. if (color === undefined) {
  5979. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  5980. color = new Color();
  5981. }
  5982. array[offset++] = color.r;
  5983. array[offset++] = color.g;
  5984. array[offset++] = color.b;
  5985. }
  5986. return this;
  5987. },
  5988. copyVector2sArray: function copyVector2sArray(vectors) {
  5989. var array = this.array;
  5990. var offset = 0;
  5991. for (var i = 0, l = vectors.length; i < l; i++) {
  5992. var vector = vectors[i];
  5993. if (vector === undefined) {
  5994. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  5995. vector = new Vector2();
  5996. }
  5997. array[offset++] = vector.x;
  5998. array[offset++] = vector.y;
  5999. }
  6000. return this;
  6001. },
  6002. copyVector3sArray: function copyVector3sArray(vectors) {
  6003. var array = this.array;
  6004. var offset = 0;
  6005. for (var i = 0, l = vectors.length; i < l; i++) {
  6006. var vector = vectors[i];
  6007. if (vector === undefined) {
  6008. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6009. vector = new Vector3();
  6010. }
  6011. array[offset++] = vector.x;
  6012. array[offset++] = vector.y;
  6013. array[offset++] = vector.z;
  6014. }
  6015. return this;
  6016. },
  6017. copyVector4sArray: function copyVector4sArray(vectors) {
  6018. var array = this.array;
  6019. var offset = 0;
  6020. for (var i = 0, l = vectors.length; i < l; i++) {
  6021. var vector = vectors[i];
  6022. if (vector === undefined) {
  6023. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6024. vector = new Vector4();
  6025. }
  6026. array[offset++] = vector.x;
  6027. array[offset++] = vector.y;
  6028. array[offset++] = vector.z;
  6029. array[offset++] = vector.w;
  6030. }
  6031. return this;
  6032. },
  6033. applyMatrix3: function applyMatrix3(m) {
  6034. if (this.itemSize === 2) {
  6035. for (var i = 0, l = this.count; i < l; i++) {
  6036. _vector2$1.fromBufferAttribute(this, i);
  6037. _vector2$1.applyMatrix3(m);
  6038. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6039. }
  6040. } else if (this.itemSize === 3) {
  6041. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6042. _vector$3.fromBufferAttribute(this, _i);
  6043. _vector$3.applyMatrix3(m);
  6044. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6045. }
  6046. }
  6047. return this;
  6048. },
  6049. applyMatrix4: function applyMatrix4(m) {
  6050. for (var i = 0, l = this.count; i < l; i++) {
  6051. _vector$3.x = this.getX(i);
  6052. _vector$3.y = this.getY(i);
  6053. _vector$3.z = this.getZ(i);
  6054. _vector$3.applyMatrix4(m);
  6055. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6056. }
  6057. return this;
  6058. },
  6059. applyNormalMatrix: function applyNormalMatrix(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.applyNormalMatrix(m);
  6065. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6066. }
  6067. return this;
  6068. },
  6069. transformDirection: function transformDirection(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.transformDirection(m);
  6075. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6076. }
  6077. return this;
  6078. },
  6079. set: function set(value, offset) {
  6080. if (offset === undefined) offset = 0;
  6081. this.array.set(value, offset);
  6082. return this;
  6083. },
  6084. getX: function getX(index) {
  6085. return this.array[index * this.itemSize];
  6086. },
  6087. setX: function setX(index, x) {
  6088. this.array[index * this.itemSize] = x;
  6089. return this;
  6090. },
  6091. getY: function getY(index) {
  6092. return this.array[index * this.itemSize + 1];
  6093. },
  6094. setY: function setY(index, y) {
  6095. this.array[index * this.itemSize + 1] = y;
  6096. return this;
  6097. },
  6098. getZ: function getZ(index) {
  6099. return this.array[index * this.itemSize + 2];
  6100. },
  6101. setZ: function setZ(index, z) {
  6102. this.array[index * this.itemSize + 2] = z;
  6103. return this;
  6104. },
  6105. getW: function getW(index) {
  6106. return this.array[index * this.itemSize + 3];
  6107. },
  6108. setW: function setW(index, w) {
  6109. this.array[index * this.itemSize + 3] = w;
  6110. return this;
  6111. },
  6112. setXY: function setXY(index, x, y) {
  6113. index *= this.itemSize;
  6114. this.array[index + 0] = x;
  6115. this.array[index + 1] = y;
  6116. return this;
  6117. },
  6118. setXYZ: function setXYZ(index, x, y, z) {
  6119. index *= this.itemSize;
  6120. this.array[index + 0] = x;
  6121. this.array[index + 1] = y;
  6122. this.array[index + 2] = z;
  6123. return this;
  6124. },
  6125. setXYZW: function setXYZW(index, x, y, z, w) {
  6126. index *= this.itemSize;
  6127. this.array[index + 0] = x;
  6128. this.array[index + 1] = y;
  6129. this.array[index + 2] = z;
  6130. this.array[index + 3] = w;
  6131. return this;
  6132. },
  6133. onUpload: function onUpload(callback) {
  6134. this.onUploadCallback = callback;
  6135. return this;
  6136. },
  6137. clone: function clone() {
  6138. return new this.constructor(this.array, this.itemSize).copy(this);
  6139. },
  6140. toJSON: function toJSON() {
  6141. return {
  6142. itemSize: this.itemSize,
  6143. type: this.array.constructor.name,
  6144. array: Array.prototype.slice.call(this.array),
  6145. normalized: this.normalized
  6146. };
  6147. }
  6148. }); //
  6149. function Int8BufferAttribute(array, itemSize, normalized) {
  6150. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6151. }
  6152. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6153. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6154. function Uint8BufferAttribute(array, itemSize, normalized) {
  6155. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6156. }
  6157. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6158. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6159. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6160. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6161. }
  6162. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6163. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6164. function Int16BufferAttribute(array, itemSize, normalized) {
  6165. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6166. }
  6167. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6168. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6169. function Uint16BufferAttribute(array, itemSize, normalized) {
  6170. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6171. }
  6172. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6173. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6174. function Int32BufferAttribute(array, itemSize, normalized) {
  6175. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6176. }
  6177. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6178. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6179. function Uint32BufferAttribute(array, itemSize, normalized) {
  6180. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6181. }
  6182. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6183. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6184. function Float32BufferAttribute(array, itemSize, normalized) {
  6185. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6186. }
  6187. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6188. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6189. function Float64BufferAttribute(array, itemSize, normalized) {
  6190. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6191. }
  6192. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6193. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6194. var DirectGeometry = /*#__PURE__*/function () {
  6195. function DirectGeometry() {
  6196. this.vertices = [];
  6197. this.normals = [];
  6198. this.colors = [];
  6199. this.uvs = [];
  6200. this.uvs2 = [];
  6201. this.groups = [];
  6202. this.morphTargets = {};
  6203. this.skinWeights = [];
  6204. this.skinIndices = []; // this.lineDistances = [];
  6205. this.boundingBox = null;
  6206. this.boundingSphere = null; // update flags
  6207. this.verticesNeedUpdate = false;
  6208. this.normalsNeedUpdate = false;
  6209. this.colorsNeedUpdate = false;
  6210. this.uvsNeedUpdate = false;
  6211. this.groupsNeedUpdate = false;
  6212. }
  6213. var _proto = DirectGeometry.prototype;
  6214. _proto.computeGroups = function computeGroups(geometry) {
  6215. var groups = [];
  6216. var group, i;
  6217. var materialIndex = undefined;
  6218. var faces = geometry.faces;
  6219. for (i = 0; i < faces.length; i++) {
  6220. var face = faces[i]; // materials
  6221. if (face.materialIndex !== materialIndex) {
  6222. materialIndex = face.materialIndex;
  6223. if (group !== undefined) {
  6224. group.count = i * 3 - group.start;
  6225. groups.push(group);
  6226. }
  6227. group = {
  6228. start: i * 3,
  6229. materialIndex: materialIndex
  6230. };
  6231. }
  6232. }
  6233. if (group !== undefined) {
  6234. group.count = i * 3 - group.start;
  6235. groups.push(group);
  6236. }
  6237. this.groups = groups;
  6238. };
  6239. _proto.fromGeometry = function fromGeometry(geometry) {
  6240. var faces = geometry.faces;
  6241. var vertices = geometry.vertices;
  6242. var faceVertexUvs = geometry.faceVertexUvs;
  6243. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6244. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6245. var morphTargets = geometry.morphTargets;
  6246. var morphTargetsLength = morphTargets.length;
  6247. var morphTargetsPosition;
  6248. if (morphTargetsLength > 0) {
  6249. morphTargetsPosition = [];
  6250. for (var i = 0; i < morphTargetsLength; i++) {
  6251. morphTargetsPosition[i] = {
  6252. name: morphTargets[i].name,
  6253. data: []
  6254. };
  6255. }
  6256. this.morphTargets.position = morphTargetsPosition;
  6257. }
  6258. var morphNormals = geometry.morphNormals;
  6259. var morphNormalsLength = morphNormals.length;
  6260. var morphTargetsNormal;
  6261. if (morphNormalsLength > 0) {
  6262. morphTargetsNormal = [];
  6263. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6264. morphTargetsNormal[_i] = {
  6265. name: morphNormals[_i].name,
  6266. data: []
  6267. };
  6268. }
  6269. this.morphTargets.normal = morphTargetsNormal;
  6270. } // skins
  6271. var skinIndices = geometry.skinIndices;
  6272. var skinWeights = geometry.skinWeights;
  6273. var hasSkinIndices = skinIndices.length === vertices.length;
  6274. var hasSkinWeights = skinWeights.length === vertices.length; //
  6275. if (vertices.length > 0 && faces.length === 0) {
  6276. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6277. }
  6278. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6279. var face = faces[_i2];
  6280. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6281. var vertexNormals = face.vertexNormals;
  6282. if (vertexNormals.length === 3) {
  6283. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6284. } else {
  6285. var normal = face.normal;
  6286. this.normals.push(normal, normal, normal);
  6287. }
  6288. var vertexColors = face.vertexColors;
  6289. if (vertexColors.length === 3) {
  6290. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6291. } else {
  6292. var color = face.color;
  6293. this.colors.push(color, color, color);
  6294. }
  6295. if (hasFaceVertexUv === true) {
  6296. var vertexUvs = faceVertexUvs[0][_i2];
  6297. if (vertexUvs !== undefined) {
  6298. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6299. } else {
  6300. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6301. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6302. }
  6303. }
  6304. if (hasFaceVertexUv2 === true) {
  6305. var _vertexUvs = faceVertexUvs[1][_i2];
  6306. if (_vertexUvs !== undefined) {
  6307. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6308. } else {
  6309. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6310. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6311. }
  6312. } // morphs
  6313. for (var j = 0; j < morphTargetsLength; j++) {
  6314. var morphTarget = morphTargets[j].vertices;
  6315. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6316. }
  6317. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6318. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6319. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6320. } // skins
  6321. if (hasSkinIndices) {
  6322. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6323. }
  6324. if (hasSkinWeights) {
  6325. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6326. }
  6327. }
  6328. this.computeGroups(geometry);
  6329. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6330. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6331. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6332. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6333. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6334. if (geometry.boundingSphere !== null) {
  6335. this.boundingSphere = geometry.boundingSphere.clone();
  6336. }
  6337. if (geometry.boundingBox !== null) {
  6338. this.boundingBox = geometry.boundingBox.clone();
  6339. }
  6340. return this;
  6341. };
  6342. return DirectGeometry;
  6343. }();
  6344. function arrayMax(array) {
  6345. if (array.length === 0) return -Infinity;
  6346. var max = array[0];
  6347. for (var i = 1, l = array.length; i < l; ++i) {
  6348. if (array[i] > max) max = array[i];
  6349. }
  6350. return max;
  6351. }
  6352. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6353. var _m1$2 = new Matrix4();
  6354. var _obj = new Object3D();
  6355. var _offset = new Vector3();
  6356. var _box$2 = new Box3();
  6357. var _boxMorphTargets = new Box3();
  6358. var _vector$4 = new Vector3();
  6359. function BufferGeometry() {
  6360. Object.defineProperty(this, 'id', {
  6361. value: _bufferGeometryId += 2
  6362. });
  6363. this.uuid = MathUtils.generateUUID();
  6364. this.name = '';
  6365. this.type = 'BufferGeometry';
  6366. this.index = null;
  6367. this.attributes = {};
  6368. this.morphAttributes = {};
  6369. this.morphTargetsRelative = false;
  6370. this.groups = [];
  6371. this.boundingBox = null;
  6372. this.boundingSphere = null;
  6373. this.drawRange = {
  6374. start: 0,
  6375. count: Infinity
  6376. };
  6377. this.userData = {};
  6378. }
  6379. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6380. constructor: BufferGeometry,
  6381. isBufferGeometry: true,
  6382. getIndex: function getIndex() {
  6383. return this.index;
  6384. },
  6385. setIndex: function setIndex(index) {
  6386. if (Array.isArray(index)) {
  6387. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6388. } else {
  6389. this.index = index;
  6390. }
  6391. return this;
  6392. },
  6393. getAttribute: function getAttribute(name) {
  6394. return this.attributes[name];
  6395. },
  6396. setAttribute: function setAttribute(name, attribute) {
  6397. this.attributes[name] = attribute;
  6398. return this;
  6399. },
  6400. deleteAttribute: function deleteAttribute(name) {
  6401. delete this.attributes[name];
  6402. return this;
  6403. },
  6404. addGroup: function addGroup(start, count, materialIndex) {
  6405. this.groups.push({
  6406. start: start,
  6407. count: count,
  6408. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6409. });
  6410. },
  6411. clearGroups: function clearGroups() {
  6412. this.groups = [];
  6413. },
  6414. setDrawRange: function setDrawRange(start, count) {
  6415. this.drawRange.start = start;
  6416. this.drawRange.count = count;
  6417. },
  6418. applyMatrix4: function applyMatrix4(matrix) {
  6419. var position = this.attributes.position;
  6420. if (position !== undefined) {
  6421. position.applyMatrix4(matrix);
  6422. position.needsUpdate = true;
  6423. }
  6424. var normal = this.attributes.normal;
  6425. if (normal !== undefined) {
  6426. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6427. normal.applyNormalMatrix(normalMatrix);
  6428. normal.needsUpdate = true;
  6429. }
  6430. var tangent = this.attributes.tangent;
  6431. if (tangent !== undefined) {
  6432. tangent.transformDirection(matrix);
  6433. tangent.needsUpdate = true;
  6434. }
  6435. if (this.boundingBox !== null) {
  6436. this.computeBoundingBox();
  6437. }
  6438. if (this.boundingSphere !== null) {
  6439. this.computeBoundingSphere();
  6440. }
  6441. return this;
  6442. },
  6443. rotateX: function rotateX(angle) {
  6444. // rotate geometry around world x-axis
  6445. _m1$2.makeRotationX(angle);
  6446. this.applyMatrix4(_m1$2);
  6447. return this;
  6448. },
  6449. rotateY: function rotateY(angle) {
  6450. // rotate geometry around world y-axis
  6451. _m1$2.makeRotationY(angle);
  6452. this.applyMatrix4(_m1$2);
  6453. return this;
  6454. },
  6455. rotateZ: function rotateZ(angle) {
  6456. // rotate geometry around world z-axis
  6457. _m1$2.makeRotationZ(angle);
  6458. this.applyMatrix4(_m1$2);
  6459. return this;
  6460. },
  6461. translate: function translate(x, y, z) {
  6462. // translate geometry
  6463. _m1$2.makeTranslation(x, y, z);
  6464. this.applyMatrix4(_m1$2);
  6465. return this;
  6466. },
  6467. scale: function scale(x, y, z) {
  6468. // scale geometry
  6469. _m1$2.makeScale(x, y, z);
  6470. this.applyMatrix4(_m1$2);
  6471. return this;
  6472. },
  6473. lookAt: function lookAt(vector) {
  6474. _obj.lookAt(vector);
  6475. _obj.updateMatrix();
  6476. this.applyMatrix4(_obj.matrix);
  6477. return this;
  6478. },
  6479. center: function center() {
  6480. this.computeBoundingBox();
  6481. this.boundingBox.getCenter(_offset).negate();
  6482. this.translate(_offset.x, _offset.y, _offset.z);
  6483. return this;
  6484. },
  6485. setFromObject: function setFromObject(object) {
  6486. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6487. var geometry = object.geometry;
  6488. if (object.isPoints || object.isLine) {
  6489. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6490. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6491. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6492. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6493. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6494. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6495. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6496. }
  6497. if (geometry.boundingSphere !== null) {
  6498. this.boundingSphere = geometry.boundingSphere.clone();
  6499. }
  6500. if (geometry.boundingBox !== null) {
  6501. this.boundingBox = geometry.boundingBox.clone();
  6502. }
  6503. } else if (object.isMesh) {
  6504. if (geometry && geometry.isGeometry) {
  6505. this.fromGeometry(geometry);
  6506. }
  6507. }
  6508. return this;
  6509. },
  6510. setFromPoints: function setFromPoints(points) {
  6511. var position = [];
  6512. for (var i = 0, l = points.length; i < l; i++) {
  6513. var point = points[i];
  6514. position.push(point.x, point.y, point.z || 0);
  6515. }
  6516. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6517. return this;
  6518. },
  6519. updateFromObject: function updateFromObject(object) {
  6520. var geometry = object.geometry;
  6521. if (object.isMesh) {
  6522. var direct = geometry.__directGeometry;
  6523. if (geometry.elementsNeedUpdate === true) {
  6524. direct = undefined;
  6525. geometry.elementsNeedUpdate = false;
  6526. }
  6527. if (direct === undefined) {
  6528. return this.fromGeometry(geometry);
  6529. }
  6530. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6531. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6532. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6533. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6534. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6535. geometry.verticesNeedUpdate = false;
  6536. geometry.normalsNeedUpdate = false;
  6537. geometry.colorsNeedUpdate = false;
  6538. geometry.uvsNeedUpdate = false;
  6539. geometry.groupsNeedUpdate = false;
  6540. geometry = direct;
  6541. }
  6542. if (geometry.verticesNeedUpdate === true) {
  6543. var attribute = this.attributes.position;
  6544. if (attribute !== undefined) {
  6545. attribute.copyVector3sArray(geometry.vertices);
  6546. attribute.needsUpdate = true;
  6547. }
  6548. geometry.verticesNeedUpdate = false;
  6549. }
  6550. if (geometry.normalsNeedUpdate === true) {
  6551. var _attribute = this.attributes.normal;
  6552. if (_attribute !== undefined) {
  6553. _attribute.copyVector3sArray(geometry.normals);
  6554. _attribute.needsUpdate = true;
  6555. }
  6556. geometry.normalsNeedUpdate = false;
  6557. }
  6558. if (geometry.colorsNeedUpdate === true) {
  6559. var _attribute2 = this.attributes.color;
  6560. if (_attribute2 !== undefined) {
  6561. _attribute2.copyColorsArray(geometry.colors);
  6562. _attribute2.needsUpdate = true;
  6563. }
  6564. geometry.colorsNeedUpdate = false;
  6565. }
  6566. if (geometry.uvsNeedUpdate) {
  6567. var _attribute3 = this.attributes.uv;
  6568. if (_attribute3 !== undefined) {
  6569. _attribute3.copyVector2sArray(geometry.uvs);
  6570. _attribute3.needsUpdate = true;
  6571. }
  6572. geometry.uvsNeedUpdate = false;
  6573. }
  6574. if (geometry.lineDistancesNeedUpdate) {
  6575. var _attribute4 = this.attributes.lineDistance;
  6576. if (_attribute4 !== undefined) {
  6577. _attribute4.copyArray(geometry.lineDistances);
  6578. _attribute4.needsUpdate = true;
  6579. }
  6580. geometry.lineDistancesNeedUpdate = false;
  6581. }
  6582. if (geometry.groupsNeedUpdate) {
  6583. geometry.computeGroups(object.geometry);
  6584. this.groups = geometry.groups;
  6585. geometry.groupsNeedUpdate = false;
  6586. }
  6587. return this;
  6588. },
  6589. fromGeometry: function fromGeometry(geometry) {
  6590. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6591. return this.fromDirectGeometry(geometry.__directGeometry);
  6592. },
  6593. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6594. var positions = new Float32Array(geometry.vertices.length * 3);
  6595. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6596. if (geometry.normals.length > 0) {
  6597. var normals = new Float32Array(geometry.normals.length * 3);
  6598. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6599. }
  6600. if (geometry.colors.length > 0) {
  6601. var colors = new Float32Array(geometry.colors.length * 3);
  6602. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6603. }
  6604. if (geometry.uvs.length > 0) {
  6605. var uvs = new Float32Array(geometry.uvs.length * 2);
  6606. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6607. }
  6608. if (geometry.uvs2.length > 0) {
  6609. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6610. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6611. } // groups
  6612. this.groups = geometry.groups; // morphs
  6613. for (var name in geometry.morphTargets) {
  6614. var array = [];
  6615. var morphTargets = geometry.morphTargets[name];
  6616. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6617. var morphTarget = morphTargets[i];
  6618. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6619. attribute.name = morphTarget.name;
  6620. array.push(attribute.copyVector3sArray(morphTarget.data));
  6621. }
  6622. this.morphAttributes[name] = array;
  6623. } // skinning
  6624. if (geometry.skinIndices.length > 0) {
  6625. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6626. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6627. }
  6628. if (geometry.skinWeights.length > 0) {
  6629. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6630. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6631. } //
  6632. if (geometry.boundingSphere !== null) {
  6633. this.boundingSphere = geometry.boundingSphere.clone();
  6634. }
  6635. if (geometry.boundingBox !== null) {
  6636. this.boundingBox = geometry.boundingBox.clone();
  6637. }
  6638. return this;
  6639. },
  6640. computeBoundingBox: function computeBoundingBox() {
  6641. if (this.boundingBox === null) {
  6642. this.boundingBox = new Box3();
  6643. }
  6644. var position = this.attributes.position;
  6645. var morphAttributesPosition = this.morphAttributes.position;
  6646. if (position && position.isGLBufferAttribute) {
  6647. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6648. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6649. return;
  6650. }
  6651. if (position !== undefined) {
  6652. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6653. if (morphAttributesPosition) {
  6654. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6655. var morphAttribute = morphAttributesPosition[i];
  6656. _box$2.setFromBufferAttribute(morphAttribute);
  6657. if (this.morphTargetsRelative) {
  6658. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6659. this.boundingBox.expandByPoint(_vector$4);
  6660. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6661. this.boundingBox.expandByPoint(_vector$4);
  6662. } else {
  6663. this.boundingBox.expandByPoint(_box$2.min);
  6664. this.boundingBox.expandByPoint(_box$2.max);
  6665. }
  6666. }
  6667. }
  6668. } else {
  6669. this.boundingBox.makeEmpty();
  6670. }
  6671. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6672. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6673. }
  6674. },
  6675. computeBoundingSphere: function computeBoundingSphere() {
  6676. if (this.boundingSphere === null) {
  6677. this.boundingSphere = new Sphere();
  6678. }
  6679. var position = this.attributes.position;
  6680. var morphAttributesPosition = this.morphAttributes.position;
  6681. if (position && position.isGLBufferAttribute) {
  6682. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6683. this.boundingSphere.set(new Vector3(), Infinity);
  6684. return;
  6685. }
  6686. if (position) {
  6687. // first, find the center of the bounding sphere
  6688. var center = this.boundingSphere.center;
  6689. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6690. if (morphAttributesPosition) {
  6691. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6692. var morphAttribute = morphAttributesPosition[i];
  6693. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6694. if (this.morphTargetsRelative) {
  6695. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6696. _box$2.expandByPoint(_vector$4);
  6697. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6698. _box$2.expandByPoint(_vector$4);
  6699. } else {
  6700. _box$2.expandByPoint(_boxMorphTargets.min);
  6701. _box$2.expandByPoint(_boxMorphTargets.max);
  6702. }
  6703. }
  6704. }
  6705. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6706. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6707. var maxRadiusSq = 0;
  6708. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6709. _vector$4.fromBufferAttribute(position, _i);
  6710. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6711. } // process morph attributes if present
  6712. if (morphAttributesPosition) {
  6713. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6714. var _morphAttribute = morphAttributesPosition[_i2];
  6715. var morphTargetsRelative = this.morphTargetsRelative;
  6716. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6717. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6718. if (morphTargetsRelative) {
  6719. _offset.fromBufferAttribute(position, j);
  6720. _vector$4.add(_offset);
  6721. }
  6722. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6723. }
  6724. }
  6725. }
  6726. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6727. if (isNaN(this.boundingSphere.radius)) {
  6728. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6729. }
  6730. }
  6731. },
  6732. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6733. },
  6734. computeVertexNormals: function computeVertexNormals() {
  6735. var index = this.index;
  6736. var positionAttribute = this.getAttribute('position');
  6737. if (positionAttribute !== undefined) {
  6738. var normalAttribute = this.getAttribute('normal');
  6739. if (normalAttribute === undefined) {
  6740. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6741. this.setAttribute('normal', normalAttribute);
  6742. } else {
  6743. // reset existing normals to zero
  6744. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6745. normalAttribute.setXYZ(i, 0, 0, 0);
  6746. }
  6747. }
  6748. var pA = new Vector3(),
  6749. pB = new Vector3(),
  6750. pC = new Vector3();
  6751. var nA = new Vector3(),
  6752. nB = new Vector3(),
  6753. nC = new Vector3();
  6754. var cb = new Vector3(),
  6755. ab = new Vector3(); // indexed elements
  6756. if (index) {
  6757. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6758. var vA = index.getX(_i3 + 0);
  6759. var vB = index.getX(_i3 + 1);
  6760. var vC = index.getX(_i3 + 2);
  6761. pA.fromBufferAttribute(positionAttribute, vA);
  6762. pB.fromBufferAttribute(positionAttribute, vB);
  6763. pC.fromBufferAttribute(positionAttribute, vC);
  6764. cb.subVectors(pC, pB);
  6765. ab.subVectors(pA, pB);
  6766. cb.cross(ab);
  6767. nA.fromBufferAttribute(normalAttribute, vA);
  6768. nB.fromBufferAttribute(normalAttribute, vB);
  6769. nC.fromBufferAttribute(normalAttribute, vC);
  6770. nA.add(cb);
  6771. nB.add(cb);
  6772. nC.add(cb);
  6773. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6774. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6775. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6776. }
  6777. } else {
  6778. // non-indexed elements (unconnected triangle soup)
  6779. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6780. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6781. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6782. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6783. cb.subVectors(pC, pB);
  6784. ab.subVectors(pA, pB);
  6785. cb.cross(ab);
  6786. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6787. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6788. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6789. }
  6790. }
  6791. this.normalizeNormals();
  6792. normalAttribute.needsUpdate = true;
  6793. }
  6794. },
  6795. merge: function merge(geometry, offset) {
  6796. if (!(geometry && geometry.isBufferGeometry)) {
  6797. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6798. return;
  6799. }
  6800. if (offset === undefined) {
  6801. offset = 0;
  6802. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6803. }
  6804. var attributes = this.attributes;
  6805. for (var key in attributes) {
  6806. if (geometry.attributes[key] === undefined) continue;
  6807. var attribute1 = attributes[key];
  6808. var attributeArray1 = attribute1.array;
  6809. var attribute2 = geometry.attributes[key];
  6810. var attributeArray2 = attribute2.array;
  6811. var attributeOffset = attribute2.itemSize * offset;
  6812. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6813. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6814. attributeArray1[j] = attributeArray2[i];
  6815. }
  6816. }
  6817. return this;
  6818. },
  6819. normalizeNormals: function normalizeNormals() {
  6820. var normals = this.attributes.normal;
  6821. for (var i = 0, il = normals.count; i < il; i++) {
  6822. _vector$4.fromBufferAttribute(normals, i);
  6823. _vector$4.normalize();
  6824. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6825. }
  6826. },
  6827. toNonIndexed: function toNonIndexed() {
  6828. function convertBufferAttribute(attribute, indices) {
  6829. var array = attribute.array;
  6830. var itemSize = attribute.itemSize;
  6831. var normalized = attribute.normalized;
  6832. var array2 = new array.constructor(indices.length * itemSize);
  6833. var index = 0,
  6834. index2 = 0;
  6835. for (var i = 0, l = indices.length; i < l; i++) {
  6836. index = indices[i] * itemSize;
  6837. for (var j = 0; j < itemSize; j++) {
  6838. array2[index2++] = array[index++];
  6839. }
  6840. }
  6841. return new BufferAttribute(array2, itemSize, normalized);
  6842. } //
  6843. if (this.index === null) {
  6844. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6845. return this;
  6846. }
  6847. var geometry2 = new BufferGeometry();
  6848. var indices = this.index.array;
  6849. var attributes = this.attributes; // attributes
  6850. for (var name in attributes) {
  6851. var attribute = attributes[name];
  6852. var newAttribute = convertBufferAttribute(attribute, indices);
  6853. geometry2.setAttribute(name, newAttribute);
  6854. } // morph attributes
  6855. var morphAttributes = this.morphAttributes;
  6856. for (var _name in morphAttributes) {
  6857. var morphArray = [];
  6858. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6859. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6860. var _attribute5 = morphAttribute[i];
  6861. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6862. morphArray.push(_newAttribute);
  6863. }
  6864. geometry2.morphAttributes[_name] = morphArray;
  6865. }
  6866. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6867. var groups = this.groups;
  6868. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6869. var group = groups[_i5];
  6870. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6871. }
  6872. return geometry2;
  6873. },
  6874. toJSON: function toJSON() {
  6875. var data = {
  6876. metadata: {
  6877. version: 4.5,
  6878. type: 'BufferGeometry',
  6879. generator: 'BufferGeometry.toJSON'
  6880. }
  6881. }; // standard BufferGeometry serialization
  6882. data.uuid = this.uuid;
  6883. data.type = this.type;
  6884. if (this.name !== '') data.name = this.name;
  6885. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6886. if (this.parameters !== undefined) {
  6887. var parameters = this.parameters;
  6888. for (var key in parameters) {
  6889. if (parameters[key] !== undefined) data[key] = parameters[key];
  6890. }
  6891. return data;
  6892. }
  6893. data.data = {
  6894. attributes: {}
  6895. };
  6896. var index = this.index;
  6897. if (index !== null) {
  6898. data.data.index = {
  6899. type: index.array.constructor.name,
  6900. array: Array.prototype.slice.call(index.array)
  6901. };
  6902. }
  6903. var attributes = this.attributes;
  6904. for (var _key in attributes) {
  6905. var attribute = attributes[_key];
  6906. var attributeData = attribute.toJSON(data.data);
  6907. if (attribute.name !== '') attributeData.name = attribute.name;
  6908. data.data.attributes[_key] = attributeData;
  6909. }
  6910. var morphAttributes = {};
  6911. var hasMorphAttributes = false;
  6912. for (var _key2 in this.morphAttributes) {
  6913. var attributeArray = this.morphAttributes[_key2];
  6914. var array = [];
  6915. for (var i = 0, il = attributeArray.length; i < il; i++) {
  6916. var _attribute6 = attributeArray[i];
  6917. var _attributeData = _attribute6.toJSON(data.data);
  6918. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  6919. array.push(_attributeData);
  6920. }
  6921. if (array.length > 0) {
  6922. morphAttributes[_key2] = array;
  6923. hasMorphAttributes = true;
  6924. }
  6925. }
  6926. if (hasMorphAttributes) {
  6927. data.data.morphAttributes = morphAttributes;
  6928. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6929. }
  6930. var groups = this.groups;
  6931. if (groups.length > 0) {
  6932. data.data.groups = JSON.parse(JSON.stringify(groups));
  6933. }
  6934. var boundingSphere = this.boundingSphere;
  6935. if (boundingSphere !== null) {
  6936. data.data.boundingSphere = {
  6937. center: boundingSphere.center.toArray(),
  6938. radius: boundingSphere.radius
  6939. };
  6940. }
  6941. return data;
  6942. },
  6943. clone: function clone() {
  6944. /*
  6945. // Handle primitives
  6946. const parameters = this.parameters;
  6947. if ( parameters !== undefined ) {
  6948. const values = [];
  6949. for ( const key in parameters ) {
  6950. values.push( parameters[ key ] );
  6951. }
  6952. const geometry = Object.create( this.constructor.prototype );
  6953. this.constructor.apply( geometry, values );
  6954. return geometry;
  6955. }
  6956. return new this.constructor().copy( this );
  6957. */
  6958. return new BufferGeometry().copy(this);
  6959. },
  6960. copy: function copy(source) {
  6961. // reset
  6962. this.index = null;
  6963. this.attributes = {};
  6964. this.morphAttributes = {};
  6965. this.groups = [];
  6966. this.boundingBox = null;
  6967. this.boundingSphere = null; // used for storing cloned, shared data
  6968. var data = {}; // name
  6969. this.name = source.name; // index
  6970. var index = source.index;
  6971. if (index !== null) {
  6972. this.setIndex(index.clone(data));
  6973. } // attributes
  6974. var attributes = source.attributes;
  6975. for (var name in attributes) {
  6976. var attribute = attributes[name];
  6977. this.setAttribute(name, attribute.clone(data));
  6978. } // morph attributes
  6979. var morphAttributes = source.morphAttributes;
  6980. for (var _name2 in morphAttributes) {
  6981. var array = [];
  6982. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  6983. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  6984. array.push(morphAttribute[i].clone(data));
  6985. }
  6986. this.morphAttributes[_name2] = array;
  6987. }
  6988. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  6989. var groups = source.groups;
  6990. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  6991. var group = groups[_i6];
  6992. this.addGroup(group.start, group.count, group.materialIndex);
  6993. } // bounding box
  6994. var boundingBox = source.boundingBox;
  6995. if (boundingBox !== null) {
  6996. this.boundingBox = boundingBox.clone();
  6997. } // bounding sphere
  6998. var boundingSphere = source.boundingSphere;
  6999. if (boundingSphere !== null) {
  7000. this.boundingSphere = boundingSphere.clone();
  7001. } // draw range
  7002. this.drawRange.start = source.drawRange.start;
  7003. this.drawRange.count = source.drawRange.count; // user data
  7004. this.userData = source.userData;
  7005. return this;
  7006. },
  7007. dispose: function dispose() {
  7008. this.dispatchEvent({
  7009. type: 'dispose'
  7010. });
  7011. }
  7012. });
  7013. var _inverseMatrix = new Matrix4();
  7014. var _ray = new Ray();
  7015. var _sphere = new Sphere();
  7016. var _vA = new Vector3();
  7017. var _vB = new Vector3();
  7018. var _vC = new Vector3();
  7019. var _tempA = new Vector3();
  7020. var _tempB = new Vector3();
  7021. var _tempC = new Vector3();
  7022. var _morphA = new Vector3();
  7023. var _morphB = new Vector3();
  7024. var _morphC = new Vector3();
  7025. var _uvA = new Vector2();
  7026. var _uvB = new Vector2();
  7027. var _uvC = new Vector2();
  7028. var _intersectionPoint = new Vector3();
  7029. var _intersectionPointWorld = new Vector3();
  7030. function Mesh(geometry, material) {
  7031. Object3D.call(this);
  7032. this.type = 'Mesh';
  7033. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  7034. this.material = material !== undefined ? material : new MeshBasicMaterial();
  7035. this.updateMorphTargets();
  7036. }
  7037. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7038. constructor: Mesh,
  7039. isMesh: true,
  7040. copy: function copy(source) {
  7041. Object3D.prototype.copy.call(this, source);
  7042. if (source.morphTargetInfluences !== undefined) {
  7043. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7044. }
  7045. if (source.morphTargetDictionary !== undefined) {
  7046. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7047. }
  7048. this.material = source.material;
  7049. this.geometry = source.geometry;
  7050. return this;
  7051. },
  7052. updateMorphTargets: function updateMorphTargets() {
  7053. var geometry = this.geometry;
  7054. if (geometry.isBufferGeometry) {
  7055. var morphAttributes = geometry.morphAttributes;
  7056. var keys = Object.keys(morphAttributes);
  7057. if (keys.length > 0) {
  7058. var morphAttribute = morphAttributes[keys[0]];
  7059. if (morphAttribute !== undefined) {
  7060. this.morphTargetInfluences = [];
  7061. this.morphTargetDictionary = {};
  7062. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7063. var name = morphAttribute[m].name || String(m);
  7064. this.morphTargetInfluences.push(0);
  7065. this.morphTargetDictionary[name] = m;
  7066. }
  7067. }
  7068. }
  7069. } else {
  7070. var morphTargets = geometry.morphTargets;
  7071. if (morphTargets !== undefined && morphTargets.length > 0) {
  7072. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7073. }
  7074. }
  7075. },
  7076. raycast: function raycast(raycaster, intersects) {
  7077. var geometry = this.geometry;
  7078. var material = this.material;
  7079. var matrixWorld = this.matrixWorld;
  7080. if (material === undefined) return; // Checking boundingSphere distance to ray
  7081. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7082. _sphere.copy(geometry.boundingSphere);
  7083. _sphere.applyMatrix4(matrixWorld);
  7084. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7085. _inverseMatrix.getInverse(matrixWorld);
  7086. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7087. if (geometry.boundingBox !== null) {
  7088. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7089. }
  7090. var intersection;
  7091. if (geometry.isBufferGeometry) {
  7092. var index = geometry.index;
  7093. var position = geometry.attributes.position;
  7094. var morphPosition = geometry.morphAttributes.position;
  7095. var morphTargetsRelative = geometry.morphTargetsRelative;
  7096. var uv = geometry.attributes.uv;
  7097. var uv2 = geometry.attributes.uv2;
  7098. var groups = geometry.groups;
  7099. var drawRange = geometry.drawRange;
  7100. if (index !== null) {
  7101. // indexed buffer geometry
  7102. if (Array.isArray(material)) {
  7103. for (var i = 0, il = groups.length; i < il; i++) {
  7104. var group = groups[i];
  7105. var groupMaterial = material[group.materialIndex];
  7106. var start = Math.max(group.start, drawRange.start);
  7107. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7108. for (var j = start, jl = end; j < jl; j += 3) {
  7109. var a = index.getX(j);
  7110. var b = index.getX(j + 1);
  7111. var c = index.getX(j + 2);
  7112. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7113. if (intersection) {
  7114. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7115. intersection.face.materialIndex = group.materialIndex;
  7116. intersects.push(intersection);
  7117. }
  7118. }
  7119. }
  7120. } else {
  7121. var _start = Math.max(0, drawRange.start);
  7122. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7123. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7124. var _a = index.getX(_i);
  7125. var _b = index.getX(_i + 1);
  7126. var _c = index.getX(_i + 2);
  7127. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7128. if (intersection) {
  7129. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7130. intersects.push(intersection);
  7131. }
  7132. }
  7133. }
  7134. } else if (position !== undefined) {
  7135. // non-indexed buffer geometry
  7136. if (Array.isArray(material)) {
  7137. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7138. var _group = groups[_i2];
  7139. var _groupMaterial = material[_group.materialIndex];
  7140. var _start2 = Math.max(_group.start, drawRange.start);
  7141. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7142. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7143. var _a2 = _j;
  7144. var _b2 = _j + 1;
  7145. var _c2 = _j + 2;
  7146. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7147. if (intersection) {
  7148. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7149. intersection.face.materialIndex = _group.materialIndex;
  7150. intersects.push(intersection);
  7151. }
  7152. }
  7153. }
  7154. } else {
  7155. var _start3 = Math.max(0, drawRange.start);
  7156. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7157. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7158. var _a3 = _i3;
  7159. var _b3 = _i3 + 1;
  7160. var _c3 = _i3 + 2;
  7161. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7162. if (intersection) {
  7163. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7164. intersects.push(intersection);
  7165. }
  7166. }
  7167. }
  7168. }
  7169. } else if (geometry.isGeometry) {
  7170. var isMultiMaterial = Array.isArray(material);
  7171. var vertices = geometry.vertices;
  7172. var faces = geometry.faces;
  7173. var uvs;
  7174. var faceVertexUvs = geometry.faceVertexUvs[0];
  7175. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7176. for (var f = 0, fl = faces.length; f < fl; f++) {
  7177. var face = faces[f];
  7178. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7179. if (faceMaterial === undefined) continue;
  7180. var fvA = vertices[face.a];
  7181. var fvB = vertices[face.b];
  7182. var fvC = vertices[face.c];
  7183. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7184. if (intersection) {
  7185. if (uvs && uvs[f]) {
  7186. var uvs_f = uvs[f];
  7187. _uvA.copy(uvs_f[0]);
  7188. _uvB.copy(uvs_f[1]);
  7189. _uvC.copy(uvs_f[2]);
  7190. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7191. }
  7192. intersection.face = face;
  7193. intersection.faceIndex = f;
  7194. intersects.push(intersection);
  7195. }
  7196. }
  7197. }
  7198. }
  7199. });
  7200. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7201. var intersect;
  7202. if (material.side === BackSide) {
  7203. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7204. } else {
  7205. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7206. }
  7207. if (intersect === null) return null;
  7208. _intersectionPointWorld.copy(point);
  7209. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7210. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7211. if (distance < raycaster.near || distance > raycaster.far) return null;
  7212. return {
  7213. distance: distance,
  7214. point: _intersectionPointWorld.clone(),
  7215. object: object
  7216. };
  7217. }
  7218. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7219. _vA.fromBufferAttribute(position, a);
  7220. _vB.fromBufferAttribute(position, b);
  7221. _vC.fromBufferAttribute(position, c);
  7222. var morphInfluences = object.morphTargetInfluences;
  7223. if (material.morphTargets && morphPosition && morphInfluences) {
  7224. _morphA.set(0, 0, 0);
  7225. _morphB.set(0, 0, 0);
  7226. _morphC.set(0, 0, 0);
  7227. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7228. var influence = morphInfluences[i];
  7229. var morphAttribute = morphPosition[i];
  7230. if (influence === 0) continue;
  7231. _tempA.fromBufferAttribute(morphAttribute, a);
  7232. _tempB.fromBufferAttribute(morphAttribute, b);
  7233. _tempC.fromBufferAttribute(morphAttribute, c);
  7234. if (morphTargetsRelative) {
  7235. _morphA.addScaledVector(_tempA, influence);
  7236. _morphB.addScaledVector(_tempB, influence);
  7237. _morphC.addScaledVector(_tempC, influence);
  7238. } else {
  7239. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7240. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7241. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7242. }
  7243. }
  7244. _vA.add(_morphA);
  7245. _vB.add(_morphB);
  7246. _vC.add(_morphC);
  7247. }
  7248. if (object.isSkinnedMesh) {
  7249. object.boneTransform(a, _vA);
  7250. object.boneTransform(b, _vB);
  7251. object.boneTransform(c, _vC);
  7252. }
  7253. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7254. if (intersection) {
  7255. if (uv) {
  7256. _uvA.fromBufferAttribute(uv, a);
  7257. _uvB.fromBufferAttribute(uv, b);
  7258. _uvC.fromBufferAttribute(uv, c);
  7259. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7260. }
  7261. if (uv2) {
  7262. _uvA.fromBufferAttribute(uv2, a);
  7263. _uvB.fromBufferAttribute(uv2, b);
  7264. _uvC.fromBufferAttribute(uv2, c);
  7265. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7266. }
  7267. var face = new Face3(a, b, c);
  7268. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7269. intersection.face = face;
  7270. }
  7271. return intersection;
  7272. }
  7273. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7274. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7275. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7276. var _this;
  7277. if (width === void 0) {
  7278. width = 1;
  7279. }
  7280. if (height === void 0) {
  7281. height = 1;
  7282. }
  7283. if (depth === void 0) {
  7284. depth = 1;
  7285. }
  7286. if (widthSegments === void 0) {
  7287. widthSegments = 1;
  7288. }
  7289. if (heightSegments === void 0) {
  7290. heightSegments = 1;
  7291. }
  7292. if (depthSegments === void 0) {
  7293. depthSegments = 1;
  7294. }
  7295. _this = _BufferGeometry.call(this) || this;
  7296. _this.type = 'BoxBufferGeometry';
  7297. _this.parameters = {
  7298. width: width,
  7299. height: height,
  7300. depth: depth,
  7301. widthSegments: widthSegments,
  7302. heightSegments: heightSegments,
  7303. depthSegments: depthSegments
  7304. };
  7305. var scope = _assertThisInitialized(_this); // segments
  7306. widthSegments = Math.floor(widthSegments);
  7307. heightSegments = Math.floor(heightSegments);
  7308. depthSegments = Math.floor(depthSegments); // buffers
  7309. var indices = [];
  7310. var vertices = [];
  7311. var normals = [];
  7312. var uvs = []; // helper variables
  7313. var numberOfVertices = 0;
  7314. var groupStart = 0; // build each side of the box geometry
  7315. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7316. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7317. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7318. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7319. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7320. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7321. // build geometry
  7322. _this.setIndex(indices);
  7323. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7324. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7325. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7326. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7327. var segmentWidth = width / gridX;
  7328. var segmentHeight = height / gridY;
  7329. var widthHalf = width / 2;
  7330. var heightHalf = height / 2;
  7331. var depthHalf = depth / 2;
  7332. var gridX1 = gridX + 1;
  7333. var gridY1 = gridY + 1;
  7334. var vertexCounter = 0;
  7335. var groupCount = 0;
  7336. var vector = new Vector3(); // generate vertices, normals and uvs
  7337. for (var iy = 0; iy < gridY1; iy++) {
  7338. var y = iy * segmentHeight - heightHalf;
  7339. for (var ix = 0; ix < gridX1; ix++) {
  7340. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7341. vector[u] = x * udir;
  7342. vector[v] = y * vdir;
  7343. vector[w] = depthHalf; // now apply vector to vertex buffer
  7344. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7345. vector[u] = 0;
  7346. vector[v] = 0;
  7347. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7348. normals.push(vector.x, vector.y, vector.z); // uvs
  7349. uvs.push(ix / gridX);
  7350. uvs.push(1 - iy / gridY); // counters
  7351. vertexCounter += 1;
  7352. }
  7353. } // indices
  7354. // 1. you need three indices to draw a single face
  7355. // 2. a single segment consists of two faces
  7356. // 3. so we need to generate six (2*3) indices per segment
  7357. for (var _iy = 0; _iy < gridY; _iy++) {
  7358. for (var _ix = 0; _ix < gridX; _ix++) {
  7359. var a = numberOfVertices + _ix + gridX1 * _iy;
  7360. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7361. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7362. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7363. indices.push(a, b, d);
  7364. indices.push(b, c, d); // increase counter
  7365. groupCount += 6;
  7366. }
  7367. } // add a group to the geometry. this will ensure multi material support
  7368. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7369. groupStart += groupCount; // update total number of vertices
  7370. numberOfVertices += vertexCounter;
  7371. }
  7372. return _this;
  7373. }
  7374. return BoxBufferGeometry;
  7375. }(BufferGeometry);
  7376. /**
  7377. * Uniform Utilities
  7378. */
  7379. function cloneUniforms(src) {
  7380. var dst = {};
  7381. for (var u in src) {
  7382. dst[u] = {};
  7383. for (var p in src[u]) {
  7384. var property = src[u][p];
  7385. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7386. dst[u][p] = property.clone();
  7387. } else if (Array.isArray(property)) {
  7388. dst[u][p] = property.slice();
  7389. } else {
  7390. dst[u][p] = property;
  7391. }
  7392. }
  7393. }
  7394. return dst;
  7395. }
  7396. function mergeUniforms(uniforms) {
  7397. var merged = {};
  7398. for (var u = 0; u < uniforms.length; u++) {
  7399. var tmp = cloneUniforms(uniforms[u]);
  7400. for (var p in tmp) {
  7401. merged[p] = tmp[p];
  7402. }
  7403. }
  7404. return merged;
  7405. } // Legacy
  7406. var UniformsUtils = {
  7407. clone: cloneUniforms,
  7408. merge: mergeUniforms
  7409. };
  7410. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7411. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7412. /**
  7413. * parameters = {
  7414. * defines: { "label" : "value" },
  7415. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7416. *
  7417. * fragmentShader: <string>,
  7418. * vertexShader: <string>,
  7419. *
  7420. * wireframe: <boolean>,
  7421. * wireframeLinewidth: <float>,
  7422. *
  7423. * lights: <bool>,
  7424. *
  7425. * skinning: <bool>,
  7426. * morphTargets: <bool>,
  7427. * morphNormals: <bool>
  7428. * }
  7429. */
  7430. function ShaderMaterial(parameters) {
  7431. Material.call(this);
  7432. this.type = 'ShaderMaterial';
  7433. this.defines = {};
  7434. this.uniforms = {};
  7435. this.vertexShader = default_vertex;
  7436. this.fragmentShader = default_fragment;
  7437. this.linewidth = 1;
  7438. this.wireframe = false;
  7439. this.wireframeLinewidth = 1;
  7440. this.fog = false; // set to use scene fog
  7441. this.lights = false; // set to use scene lights
  7442. this.clipping = false; // set to use user-defined clipping planes
  7443. this.skinning = false; // set to use skinning attribute streams
  7444. this.morphTargets = false; // set to use morph targets
  7445. this.morphNormals = false; // set to use morph normals
  7446. this.extensions = {
  7447. derivatives: false,
  7448. // set to use derivatives
  7449. fragDepth: false,
  7450. // set to use fragment depth values
  7451. drawBuffers: false,
  7452. // set to use draw buffers
  7453. shaderTextureLOD: false // set to use shader texture LOD
  7454. }; // When rendered geometry doesn't include these attributes but the material does,
  7455. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7456. this.defaultAttributeValues = {
  7457. 'color': [1, 1, 1],
  7458. 'uv': [0, 0],
  7459. 'uv2': [0, 0]
  7460. };
  7461. this.index0AttributeName = undefined;
  7462. this.uniformsNeedUpdate = false;
  7463. this.glslVersion = null;
  7464. if (parameters !== undefined) {
  7465. if (parameters.attributes !== undefined) {
  7466. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7467. }
  7468. this.setValues(parameters);
  7469. }
  7470. }
  7471. ShaderMaterial.prototype = Object.create(Material.prototype);
  7472. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7473. ShaderMaterial.prototype.isShaderMaterial = true;
  7474. ShaderMaterial.prototype.copy = function (source) {
  7475. Material.prototype.copy.call(this, source);
  7476. this.fragmentShader = source.fragmentShader;
  7477. this.vertexShader = source.vertexShader;
  7478. this.uniforms = cloneUniforms(source.uniforms);
  7479. this.defines = Object.assign({}, source.defines);
  7480. this.wireframe = source.wireframe;
  7481. this.wireframeLinewidth = source.wireframeLinewidth;
  7482. this.lights = source.lights;
  7483. this.clipping = source.clipping;
  7484. this.skinning = source.skinning;
  7485. this.morphTargets = source.morphTargets;
  7486. this.morphNormals = source.morphNormals;
  7487. this.extensions = Object.assign({}, source.extensions);
  7488. this.glslVersion = source.glslVersion;
  7489. return this;
  7490. };
  7491. ShaderMaterial.prototype.toJSON = function (meta) {
  7492. var data = Material.prototype.toJSON.call(this, meta);
  7493. data.glslVersion = this.glslVersion;
  7494. data.uniforms = {};
  7495. for (var name in this.uniforms) {
  7496. var uniform = this.uniforms[name];
  7497. var value = uniform.value;
  7498. if (value && value.isTexture) {
  7499. data.uniforms[name] = {
  7500. type: 't',
  7501. value: value.toJSON(meta).uuid
  7502. };
  7503. } else if (value && value.isColor) {
  7504. data.uniforms[name] = {
  7505. type: 'c',
  7506. value: value.getHex()
  7507. };
  7508. } else if (value && value.isVector2) {
  7509. data.uniforms[name] = {
  7510. type: 'v2',
  7511. value: value.toArray()
  7512. };
  7513. } else if (value && value.isVector3) {
  7514. data.uniforms[name] = {
  7515. type: 'v3',
  7516. value: value.toArray()
  7517. };
  7518. } else if (value && value.isVector4) {
  7519. data.uniforms[name] = {
  7520. type: 'v4',
  7521. value: value.toArray()
  7522. };
  7523. } else if (value && value.isMatrix3) {
  7524. data.uniforms[name] = {
  7525. type: 'm3',
  7526. value: value.toArray()
  7527. };
  7528. } else if (value && value.isMatrix4) {
  7529. data.uniforms[name] = {
  7530. type: 'm4',
  7531. value: value.toArray()
  7532. };
  7533. } else {
  7534. data.uniforms[name] = {
  7535. value: value
  7536. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7537. }
  7538. }
  7539. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7540. data.vertexShader = this.vertexShader;
  7541. data.fragmentShader = this.fragmentShader;
  7542. var extensions = {};
  7543. for (var key in this.extensions) {
  7544. if (this.extensions[key] === true) extensions[key] = true;
  7545. }
  7546. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7547. return data;
  7548. };
  7549. function Camera() {
  7550. Object3D.call(this);
  7551. this.type = 'Camera';
  7552. this.matrixWorldInverse = new Matrix4();
  7553. this.projectionMatrix = new Matrix4();
  7554. this.projectionMatrixInverse = new Matrix4();
  7555. }
  7556. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7557. constructor: Camera,
  7558. isCamera: true,
  7559. copy: function copy(source, recursive) {
  7560. Object3D.prototype.copy.call(this, source, recursive);
  7561. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7562. this.projectionMatrix.copy(source.projectionMatrix);
  7563. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7564. return this;
  7565. },
  7566. getWorldDirection: function getWorldDirection(target) {
  7567. if (target === undefined) {
  7568. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7569. target = new Vector3();
  7570. }
  7571. this.updateMatrixWorld(true);
  7572. var e = this.matrixWorld.elements;
  7573. return target.set(-e[8], -e[9], -e[10]).normalize();
  7574. },
  7575. updateMatrixWorld: function updateMatrixWorld(force) {
  7576. Object3D.prototype.updateMatrixWorld.call(this, force);
  7577. this.matrixWorldInverse.getInverse(this.matrixWorld);
  7578. },
  7579. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7580. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7581. this.matrixWorldInverse.getInverse(this.matrixWorld);
  7582. },
  7583. clone: function clone() {
  7584. return new this.constructor().copy(this);
  7585. }
  7586. });
  7587. function PerspectiveCamera(fov, aspect, near, far) {
  7588. Camera.call(this);
  7589. this.type = 'PerspectiveCamera';
  7590. this.fov = fov !== undefined ? fov : 50;
  7591. this.zoom = 1;
  7592. this.near = near !== undefined ? near : 0.1;
  7593. this.far = far !== undefined ? far : 2000;
  7594. this.focus = 10;
  7595. this.aspect = aspect !== undefined ? aspect : 1;
  7596. this.view = null;
  7597. this.filmGauge = 35; // width of the film (default in millimeters)
  7598. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7599. this.updateProjectionMatrix();
  7600. }
  7601. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7602. constructor: PerspectiveCamera,
  7603. isPerspectiveCamera: true,
  7604. copy: function copy(source, recursive) {
  7605. Camera.prototype.copy.call(this, source, recursive);
  7606. this.fov = source.fov;
  7607. this.zoom = source.zoom;
  7608. this.near = source.near;
  7609. this.far = source.far;
  7610. this.focus = source.focus;
  7611. this.aspect = source.aspect;
  7612. this.view = source.view === null ? null : Object.assign({}, source.view);
  7613. this.filmGauge = source.filmGauge;
  7614. this.filmOffset = source.filmOffset;
  7615. return this;
  7616. },
  7617. /**
  7618. * Sets the FOV by focal length in respect to the current .filmGauge.
  7619. *
  7620. * The default film gauge is 35, so that the focal length can be specified for
  7621. * a 35mm (full frame) camera.
  7622. *
  7623. * Values for focal length and film gauge must have the same unit.
  7624. */
  7625. setFocalLength: function setFocalLength(focalLength) {
  7626. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7627. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7628. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7629. this.updateProjectionMatrix();
  7630. },
  7631. /**
  7632. * Calculates the focal length from the current .fov and .filmGauge.
  7633. */
  7634. getFocalLength: function getFocalLength() {
  7635. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7636. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7637. },
  7638. getEffectiveFOV: function getEffectiveFOV() {
  7639. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7640. },
  7641. getFilmWidth: function getFilmWidth() {
  7642. // film not completely covered in portrait format (aspect < 1)
  7643. return this.filmGauge * Math.min(this.aspect, 1);
  7644. },
  7645. getFilmHeight: function getFilmHeight() {
  7646. // film not completely covered in landscape format (aspect > 1)
  7647. return this.filmGauge / Math.max(this.aspect, 1);
  7648. },
  7649. /**
  7650. * Sets an offset in a larger frustum. This is useful for multi-window or
  7651. * multi-monitor/multi-machine setups.
  7652. *
  7653. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7654. * the monitors are in grid like this
  7655. *
  7656. * +---+---+---+
  7657. * | A | B | C |
  7658. * +---+---+---+
  7659. * | D | E | F |
  7660. * +---+---+---+
  7661. *
  7662. * then for each monitor you would call it like this
  7663. *
  7664. * const w = 1920;
  7665. * const h = 1080;
  7666. * const fullWidth = w * 3;
  7667. * const fullHeight = h * 2;
  7668. *
  7669. * --A--
  7670. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7671. * --B--
  7672. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7673. * --C--
  7674. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7675. * --D--
  7676. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7677. * --E--
  7678. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7679. * --F--
  7680. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7681. *
  7682. * Note there is no reason monitors have to be the same size or in a grid.
  7683. */
  7684. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7685. this.aspect = fullWidth / fullHeight;
  7686. if (this.view === null) {
  7687. this.view = {
  7688. enabled: true,
  7689. fullWidth: 1,
  7690. fullHeight: 1,
  7691. offsetX: 0,
  7692. offsetY: 0,
  7693. width: 1,
  7694. height: 1
  7695. };
  7696. }
  7697. this.view.enabled = true;
  7698. this.view.fullWidth = fullWidth;
  7699. this.view.fullHeight = fullHeight;
  7700. this.view.offsetX = x;
  7701. this.view.offsetY = y;
  7702. this.view.width = width;
  7703. this.view.height = height;
  7704. this.updateProjectionMatrix();
  7705. },
  7706. clearViewOffset: function clearViewOffset() {
  7707. if (this.view !== null) {
  7708. this.view.enabled = false;
  7709. }
  7710. this.updateProjectionMatrix();
  7711. },
  7712. updateProjectionMatrix: function updateProjectionMatrix() {
  7713. var near = this.near;
  7714. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7715. var height = 2 * top;
  7716. var width = this.aspect * height;
  7717. var left = -0.5 * width;
  7718. var view = this.view;
  7719. if (this.view !== null && this.view.enabled) {
  7720. var fullWidth = view.fullWidth,
  7721. fullHeight = view.fullHeight;
  7722. left += view.offsetX * width / fullWidth;
  7723. top -= view.offsetY * height / fullHeight;
  7724. width *= view.width / fullWidth;
  7725. height *= view.height / fullHeight;
  7726. }
  7727. var skew = this.filmOffset;
  7728. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7729. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7730. this.projectionMatrixInverse.getInverse(this.projectionMatrix);
  7731. },
  7732. toJSON: function toJSON(meta) {
  7733. var data = Object3D.prototype.toJSON.call(this, meta);
  7734. data.object.fov = this.fov;
  7735. data.object.zoom = this.zoom;
  7736. data.object.near = this.near;
  7737. data.object.far = this.far;
  7738. data.object.focus = this.focus;
  7739. data.object.aspect = this.aspect;
  7740. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7741. data.object.filmGauge = this.filmGauge;
  7742. data.object.filmOffset = this.filmOffset;
  7743. return data;
  7744. }
  7745. });
  7746. var fov = 90,
  7747. aspect = 1;
  7748. function CubeCamera(near, far, renderTarget) {
  7749. Object3D.call(this);
  7750. this.type = 'CubeCamera';
  7751. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7752. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7753. return;
  7754. }
  7755. this.renderTarget = renderTarget;
  7756. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7757. cameraPX.layers = this.layers;
  7758. cameraPX.up.set(0, -1, 0);
  7759. cameraPX.lookAt(new Vector3(1, 0, 0));
  7760. this.add(cameraPX);
  7761. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7762. cameraNX.layers = this.layers;
  7763. cameraNX.up.set(0, -1, 0);
  7764. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7765. this.add(cameraNX);
  7766. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7767. cameraPY.layers = this.layers;
  7768. cameraPY.up.set(0, 0, 1);
  7769. cameraPY.lookAt(new Vector3(0, 1, 0));
  7770. this.add(cameraPY);
  7771. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7772. cameraNY.layers = this.layers;
  7773. cameraNY.up.set(0, 0, -1);
  7774. cameraNY.lookAt(new Vector3(0, -1, 0));
  7775. this.add(cameraNY);
  7776. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7777. cameraPZ.layers = this.layers;
  7778. cameraPZ.up.set(0, -1, 0);
  7779. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7780. this.add(cameraPZ);
  7781. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7782. cameraNZ.layers = this.layers;
  7783. cameraNZ.up.set(0, -1, 0);
  7784. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7785. this.add(cameraNZ);
  7786. this.update = function (renderer, scene) {
  7787. if (this.parent === null) this.updateMatrixWorld();
  7788. var currentXrEnabled = renderer.xr.enabled;
  7789. var currentRenderTarget = renderer.getRenderTarget();
  7790. renderer.xr.enabled = false;
  7791. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7792. renderTarget.texture.generateMipmaps = false;
  7793. renderer.setRenderTarget(renderTarget, 0);
  7794. renderer.render(scene, cameraPX);
  7795. renderer.setRenderTarget(renderTarget, 1);
  7796. renderer.render(scene, cameraNX);
  7797. renderer.setRenderTarget(renderTarget, 2);
  7798. renderer.render(scene, cameraPY);
  7799. renderer.setRenderTarget(renderTarget, 3);
  7800. renderer.render(scene, cameraNY);
  7801. renderer.setRenderTarget(renderTarget, 4);
  7802. renderer.render(scene, cameraPZ);
  7803. renderTarget.texture.generateMipmaps = generateMipmaps;
  7804. renderer.setRenderTarget(renderTarget, 5);
  7805. renderer.render(scene, cameraNZ);
  7806. renderer.setRenderTarget(currentRenderTarget);
  7807. renderer.xr.enabled = currentXrEnabled;
  7808. };
  7809. this.clear = function (renderer, color, depth, stencil) {
  7810. var currentRenderTarget = renderer.getRenderTarget();
  7811. for (var i = 0; i < 6; i++) {
  7812. renderer.setRenderTarget(renderTarget, i);
  7813. renderer.clear(color, depth, stencil);
  7814. }
  7815. renderer.setRenderTarget(currentRenderTarget);
  7816. };
  7817. }
  7818. CubeCamera.prototype = Object.create(Object3D.prototype);
  7819. CubeCamera.prototype.constructor = CubeCamera;
  7820. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7821. images = images !== undefined ? images : [];
  7822. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7823. format = format !== undefined ? format : RGBFormat;
  7824. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7825. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  7826. //
  7827. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7828. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7829. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7830. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7831. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7832. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7833. this._needsFlipEnvMap = true;
  7834. }
  7835. CubeTexture.prototype = Object.create(Texture.prototype);
  7836. CubeTexture.prototype.constructor = CubeTexture;
  7837. CubeTexture.prototype.isCubeTexture = true;
  7838. Object.defineProperty(CubeTexture.prototype, 'images', {
  7839. get: function get() {
  7840. return this.image;
  7841. },
  7842. set: function set(value) {
  7843. this.image = value;
  7844. }
  7845. });
  7846. function WebGLCubeRenderTarget(size, options, dummy) {
  7847. if (Number.isInteger(options)) {
  7848. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7849. options = dummy;
  7850. }
  7851. WebGLRenderTarget.call(this, size, size, options);
  7852. options = options || {};
  7853. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7854. this.texture._needsFlipEnvMap = false;
  7855. }
  7856. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7857. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7858. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7859. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7860. this.texture.type = texture.type;
  7861. this.texture.format = RGBAFormat; // see #18859
  7862. this.texture.encoding = texture.encoding;
  7863. this.texture.generateMipmaps = texture.generateMipmaps;
  7864. this.texture.minFilter = texture.minFilter;
  7865. this.texture.magFilter = texture.magFilter;
  7866. var shader = {
  7867. uniforms: {
  7868. tEquirect: {
  7869. value: null
  7870. }
  7871. },
  7872. vertexShader:
  7873. /* glsl */
  7874. "\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",
  7875. fragmentShader:
  7876. /* glsl */
  7877. "\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"
  7878. };
  7879. var geometry = new BoxBufferGeometry(5, 5, 5);
  7880. var material = new ShaderMaterial({
  7881. name: 'CubemapFromEquirect',
  7882. uniforms: cloneUniforms(shader.uniforms),
  7883. vertexShader: shader.vertexShader,
  7884. fragmentShader: shader.fragmentShader,
  7885. side: BackSide,
  7886. blending: NoBlending
  7887. });
  7888. material.uniforms.tEquirect.value = texture;
  7889. var mesh = new Mesh(geometry, material);
  7890. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  7891. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  7892. var camera = new CubeCamera(1, 10, this);
  7893. camera.update(renderer, mesh);
  7894. texture.minFilter = currentMinFilter;
  7895. mesh.geometry.dispose();
  7896. mesh.material.dispose();
  7897. return this;
  7898. };
  7899. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  7900. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7901. this.image = {
  7902. data: data || null,
  7903. width: width || 1,
  7904. height: height || 1
  7905. };
  7906. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  7907. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  7908. this.generateMipmaps = false;
  7909. this.flipY = false;
  7910. this.unpackAlignment = 1;
  7911. this.needsUpdate = true;
  7912. }
  7913. DataTexture.prototype = Object.create(Texture.prototype);
  7914. DataTexture.prototype.constructor = DataTexture;
  7915. DataTexture.prototype.isDataTexture = true;
  7916. var _sphere$1 = /*@__PURE__*/new Sphere();
  7917. var _vector$5 = /*@__PURE__*/new Vector3();
  7918. var Frustum = /*#__PURE__*/function () {
  7919. function Frustum(p0, p1, p2, p3, p4, p5) {
  7920. 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()];
  7921. }
  7922. var _proto = Frustum.prototype;
  7923. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  7924. var planes = this.planes;
  7925. planes[0].copy(p0);
  7926. planes[1].copy(p1);
  7927. planes[2].copy(p2);
  7928. planes[3].copy(p3);
  7929. planes[4].copy(p4);
  7930. planes[5].copy(p5);
  7931. return this;
  7932. };
  7933. _proto.clone = function clone() {
  7934. return new this.constructor().copy(this);
  7935. };
  7936. _proto.copy = function copy(frustum) {
  7937. var planes = this.planes;
  7938. for (var i = 0; i < 6; i++) {
  7939. planes[i].copy(frustum.planes[i]);
  7940. }
  7941. return this;
  7942. };
  7943. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  7944. var planes = this.planes;
  7945. var me = m.elements;
  7946. var me0 = me[0],
  7947. me1 = me[1],
  7948. me2 = me[2],
  7949. me3 = me[3];
  7950. var me4 = me[4],
  7951. me5 = me[5],
  7952. me6 = me[6],
  7953. me7 = me[7];
  7954. var me8 = me[8],
  7955. me9 = me[9],
  7956. me10 = me[10],
  7957. me11 = me[11];
  7958. var me12 = me[12],
  7959. me13 = me[13],
  7960. me14 = me[14],
  7961. me15 = me[15];
  7962. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  7963. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  7964. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  7965. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  7966. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  7967. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  7968. return this;
  7969. };
  7970. _proto.intersectsObject = function intersectsObject(object) {
  7971. var geometry = object.geometry;
  7972. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7973. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  7974. return this.intersectsSphere(_sphere$1);
  7975. };
  7976. _proto.intersectsSprite = function intersectsSprite(sprite) {
  7977. _sphere$1.center.set(0, 0, 0);
  7978. _sphere$1.radius = 0.7071067811865476;
  7979. _sphere$1.applyMatrix4(sprite.matrixWorld);
  7980. return this.intersectsSphere(_sphere$1);
  7981. };
  7982. _proto.intersectsSphere = function intersectsSphere(sphere) {
  7983. var planes = this.planes;
  7984. var center = sphere.center;
  7985. var negRadius = -sphere.radius;
  7986. for (var i = 0; i < 6; i++) {
  7987. var distance = planes[i].distanceToPoint(center);
  7988. if (distance < negRadius) {
  7989. return false;
  7990. }
  7991. }
  7992. return true;
  7993. };
  7994. _proto.intersectsBox = function intersectsBox(box) {
  7995. var planes = this.planes;
  7996. for (var i = 0; i < 6; i++) {
  7997. var plane = planes[i]; // corner at max distance
  7998. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  7999. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8000. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8001. if (plane.distanceToPoint(_vector$5) < 0) {
  8002. return false;
  8003. }
  8004. }
  8005. return true;
  8006. };
  8007. _proto.containsPoint = function containsPoint(point) {
  8008. var planes = this.planes;
  8009. for (var i = 0; i < 6; i++) {
  8010. if (planes[i].distanceToPoint(point) < 0) {
  8011. return false;
  8012. }
  8013. }
  8014. return true;
  8015. };
  8016. return Frustum;
  8017. }();
  8018. function WebGLAnimation() {
  8019. var context = null;
  8020. var isAnimating = false;
  8021. var animationLoop = null;
  8022. var requestId = null;
  8023. function onAnimationFrame(time, frame) {
  8024. animationLoop(time, frame);
  8025. requestId = context.requestAnimationFrame(onAnimationFrame);
  8026. }
  8027. return {
  8028. start: function start() {
  8029. if (isAnimating === true) return;
  8030. if (animationLoop === null) return;
  8031. requestId = context.requestAnimationFrame(onAnimationFrame);
  8032. isAnimating = true;
  8033. },
  8034. stop: function stop() {
  8035. context.cancelAnimationFrame(requestId);
  8036. isAnimating = false;
  8037. },
  8038. setAnimationLoop: function setAnimationLoop(callback) {
  8039. animationLoop = callback;
  8040. },
  8041. setContext: function setContext(value) {
  8042. context = value;
  8043. }
  8044. };
  8045. }
  8046. function WebGLAttributes(gl, capabilities) {
  8047. var isWebGL2 = capabilities.isWebGL2;
  8048. var buffers = new WeakMap();
  8049. function createBuffer(attribute, bufferType) {
  8050. var array = attribute.array;
  8051. var usage = attribute.usage;
  8052. var buffer = gl.createBuffer();
  8053. gl.bindBuffer(bufferType, buffer);
  8054. gl.bufferData(bufferType, array, usage);
  8055. attribute.onUploadCallback();
  8056. var type = 5126;
  8057. if (array instanceof Float32Array) {
  8058. type = 5126;
  8059. } else if (array instanceof Float64Array) {
  8060. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8061. } else if (array instanceof Uint16Array) {
  8062. type = 5123;
  8063. } else if (array instanceof Int16Array) {
  8064. type = 5122;
  8065. } else if (array instanceof Uint32Array) {
  8066. type = 5125;
  8067. } else if (array instanceof Int32Array) {
  8068. type = 5124;
  8069. } else if (array instanceof Int8Array) {
  8070. type = 5120;
  8071. } else if (array instanceof Uint8Array) {
  8072. type = 5121;
  8073. }
  8074. return {
  8075. buffer: buffer,
  8076. type: type,
  8077. bytesPerElement: array.BYTES_PER_ELEMENT,
  8078. version: attribute.version
  8079. };
  8080. }
  8081. function updateBuffer(buffer, attribute, bufferType) {
  8082. var array = attribute.array;
  8083. var updateRange = attribute.updateRange;
  8084. gl.bindBuffer(bufferType, buffer);
  8085. if (updateRange.count === -1) {
  8086. // Not using update ranges
  8087. gl.bufferSubData(bufferType, 0, array);
  8088. } else {
  8089. if (isWebGL2) {
  8090. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8091. } else {
  8092. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8093. }
  8094. updateRange.count = -1; // reset range
  8095. }
  8096. } //
  8097. function get(attribute) {
  8098. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8099. return buffers.get(attribute);
  8100. }
  8101. function remove(attribute) {
  8102. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8103. var data = buffers.get(attribute);
  8104. if (data) {
  8105. gl.deleteBuffer(data.buffer);
  8106. buffers.delete(attribute);
  8107. }
  8108. }
  8109. function update(attribute, bufferType) {
  8110. if (attribute.isGLBufferAttribute) {
  8111. var cached = buffers.get(attribute);
  8112. if (!cached || cached.version < attribute.version) {
  8113. buffers.set(attribute, {
  8114. buffer: attribute.buffer,
  8115. type: attribute.type,
  8116. bytesPerElement: attribute.elementSize,
  8117. version: attribute.version
  8118. });
  8119. }
  8120. return;
  8121. }
  8122. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8123. var data = buffers.get(attribute);
  8124. if (data === undefined) {
  8125. buffers.set(attribute, createBuffer(attribute, bufferType));
  8126. } else if (data.version < attribute.version) {
  8127. updateBuffer(data.buffer, attribute, bufferType);
  8128. data.version = attribute.version;
  8129. }
  8130. }
  8131. return {
  8132. get: get,
  8133. remove: remove,
  8134. update: update
  8135. };
  8136. }
  8137. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8138. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8139. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8140. var _this;
  8141. _this = _BufferGeometry.call(this) || this;
  8142. _this.type = 'PlaneBufferGeometry';
  8143. _this.parameters = {
  8144. width: width,
  8145. height: height,
  8146. widthSegments: widthSegments,
  8147. heightSegments: heightSegments
  8148. };
  8149. width = width || 1;
  8150. height = height || 1;
  8151. var width_half = width / 2;
  8152. var height_half = height / 2;
  8153. var gridX = Math.floor(widthSegments) || 1;
  8154. var gridY = Math.floor(heightSegments) || 1;
  8155. var gridX1 = gridX + 1;
  8156. var gridY1 = gridY + 1;
  8157. var segment_width = width / gridX;
  8158. var segment_height = height / gridY; // buffers
  8159. var indices = [];
  8160. var vertices = [];
  8161. var normals = [];
  8162. var uvs = []; // generate vertices, normals and uvs
  8163. for (var iy = 0; iy < gridY1; iy++) {
  8164. var y = iy * segment_height - height_half;
  8165. for (var ix = 0; ix < gridX1; ix++) {
  8166. var x = ix * segment_width - width_half;
  8167. vertices.push(x, -y, 0);
  8168. normals.push(0, 0, 1);
  8169. uvs.push(ix / gridX);
  8170. uvs.push(1 - iy / gridY);
  8171. }
  8172. } // indices
  8173. for (var _iy = 0; _iy < gridY; _iy++) {
  8174. for (var _ix = 0; _ix < gridX; _ix++) {
  8175. var a = _ix + gridX1 * _iy;
  8176. var b = _ix + gridX1 * (_iy + 1);
  8177. var c = _ix + 1 + gridX1 * (_iy + 1);
  8178. var d = _ix + 1 + gridX1 * _iy; // faces
  8179. indices.push(a, b, d);
  8180. indices.push(b, c, d);
  8181. }
  8182. } // build geometry
  8183. _this.setIndex(indices);
  8184. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8185. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8186. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8187. return _this;
  8188. }
  8189. return PlaneBufferGeometry;
  8190. }(BufferGeometry);
  8191. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8192. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8193. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8194. 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";
  8195. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8196. var begin_vertex = "vec3 transformed = vec3( position );";
  8197. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8198. 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";
  8199. 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";
  8200. 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";
  8201. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8202. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8203. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8204. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8205. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8206. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8207. 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";
  8208. 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}";
  8209. 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";
  8210. 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";
  8211. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8212. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8213. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8214. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8215. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8216. 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}";
  8217. 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";
  8218. 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";
  8219. 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";
  8220. 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";
  8221. 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";
  8222. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8223. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8224. 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";
  8225. 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";
  8226. 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}";
  8227. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8228. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8229. 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";
  8230. 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";
  8231. 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";
  8232. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8233. 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)";
  8234. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8235. 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)";
  8236. 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";
  8237. 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}";
  8238. 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";
  8239. 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";
  8240. 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";
  8241. 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";
  8242. 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";
  8243. 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";
  8244. 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";
  8245. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8246. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8247. 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";
  8248. 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";
  8249. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8250. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8251. 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";
  8252. 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";
  8253. 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";
  8254. 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;";
  8255. 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";
  8256. 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";
  8257. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8258. 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";
  8259. 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";
  8260. 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}";
  8261. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8262. 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;";
  8263. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8264. 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";
  8265. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8266. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8267. 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";
  8268. 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";
  8269. 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";
  8270. 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}";
  8271. 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";
  8272. 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";
  8273. 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";
  8274. 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";
  8275. 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";
  8276. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8277. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8278. 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; }";
  8279. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8280. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8281. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8282. 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";
  8283. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8284. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8285. 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";
  8286. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8287. 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";
  8288. 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}";
  8289. 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}";
  8290. 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}";
  8291. 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}";
  8292. 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}";
  8293. 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}";
  8294. 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}";
  8295. 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}";
  8296. 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}";
  8297. 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}";
  8298. 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}";
  8299. 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}";
  8300. 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}";
  8301. 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}";
  8302. 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}";
  8303. 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}";
  8304. 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}";
  8305. 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}";
  8306. 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}";
  8307. 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}";
  8308. 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}";
  8309. 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}";
  8310. 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}";
  8311. 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}";
  8312. 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}";
  8313. 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}";
  8314. 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}";
  8315. 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}";
  8316. 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}";
  8317. 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}";
  8318. 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}";
  8319. 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}";
  8320. var ShaderChunk = {
  8321. alphamap_fragment: alphamap_fragment,
  8322. alphamap_pars_fragment: alphamap_pars_fragment,
  8323. alphatest_fragment: alphatest_fragment,
  8324. aomap_fragment: aomap_fragment,
  8325. aomap_pars_fragment: aomap_pars_fragment,
  8326. begin_vertex: begin_vertex,
  8327. beginnormal_vertex: beginnormal_vertex,
  8328. bsdfs: bsdfs,
  8329. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8330. clipping_planes_fragment: clipping_planes_fragment,
  8331. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8332. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8333. clipping_planes_vertex: clipping_planes_vertex,
  8334. color_fragment: color_fragment,
  8335. color_pars_fragment: color_pars_fragment,
  8336. color_pars_vertex: color_pars_vertex,
  8337. color_vertex: color_vertex,
  8338. common: common,
  8339. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8340. defaultnormal_vertex: defaultnormal_vertex,
  8341. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8342. displacementmap_vertex: displacementmap_vertex,
  8343. emissivemap_fragment: emissivemap_fragment,
  8344. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8345. encodings_fragment: encodings_fragment,
  8346. encodings_pars_fragment: encodings_pars_fragment,
  8347. envmap_fragment: envmap_fragment,
  8348. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8349. envmap_pars_fragment: envmap_pars_fragment,
  8350. envmap_pars_vertex: envmap_pars_vertex,
  8351. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8352. envmap_vertex: envmap_vertex,
  8353. fog_vertex: fog_vertex,
  8354. fog_pars_vertex: fog_pars_vertex,
  8355. fog_fragment: fog_fragment,
  8356. fog_pars_fragment: fog_pars_fragment,
  8357. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8358. lightmap_fragment: lightmap_fragment,
  8359. lightmap_pars_fragment: lightmap_pars_fragment,
  8360. lights_lambert_vertex: lights_lambert_vertex,
  8361. lights_pars_begin: lights_pars_begin,
  8362. lights_toon_fragment: lights_toon_fragment,
  8363. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8364. lights_phong_fragment: lights_phong_fragment,
  8365. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8366. lights_physical_fragment: lights_physical_fragment,
  8367. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8368. lights_fragment_begin: lights_fragment_begin,
  8369. lights_fragment_maps: lights_fragment_maps,
  8370. lights_fragment_end: lights_fragment_end,
  8371. logdepthbuf_fragment: logdepthbuf_fragment,
  8372. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8373. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8374. logdepthbuf_vertex: logdepthbuf_vertex,
  8375. map_fragment: map_fragment,
  8376. map_pars_fragment: map_pars_fragment,
  8377. map_particle_fragment: map_particle_fragment,
  8378. map_particle_pars_fragment: map_particle_pars_fragment,
  8379. metalnessmap_fragment: metalnessmap_fragment,
  8380. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8381. morphnormal_vertex: morphnormal_vertex,
  8382. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8383. morphtarget_vertex: morphtarget_vertex,
  8384. normal_fragment_begin: normal_fragment_begin,
  8385. normal_fragment_maps: normal_fragment_maps,
  8386. normalmap_pars_fragment: normalmap_pars_fragment,
  8387. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8388. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8389. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8390. packing: packing,
  8391. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8392. project_vertex: project_vertex,
  8393. dithering_fragment: dithering_fragment,
  8394. dithering_pars_fragment: dithering_pars_fragment,
  8395. roughnessmap_fragment: roughnessmap_fragment,
  8396. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8397. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8398. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8399. shadowmap_vertex: shadowmap_vertex,
  8400. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8401. skinbase_vertex: skinbase_vertex,
  8402. skinning_pars_vertex: skinning_pars_vertex,
  8403. skinning_vertex: skinning_vertex,
  8404. skinnormal_vertex: skinnormal_vertex,
  8405. specularmap_fragment: specularmap_fragment,
  8406. specularmap_pars_fragment: specularmap_pars_fragment,
  8407. tonemapping_fragment: tonemapping_fragment,
  8408. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8409. transmissionmap_fragment: transmissionmap_fragment,
  8410. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8411. uv_pars_fragment: uv_pars_fragment,
  8412. uv_pars_vertex: uv_pars_vertex,
  8413. uv_vertex: uv_vertex,
  8414. uv2_pars_fragment: uv2_pars_fragment,
  8415. uv2_pars_vertex: uv2_pars_vertex,
  8416. uv2_vertex: uv2_vertex,
  8417. worldpos_vertex: worldpos_vertex,
  8418. background_frag: background_frag,
  8419. background_vert: background_vert,
  8420. cube_frag: cube_frag,
  8421. cube_vert: cube_vert,
  8422. depth_frag: depth_frag,
  8423. depth_vert: depth_vert,
  8424. distanceRGBA_frag: distanceRGBA_frag,
  8425. distanceRGBA_vert: distanceRGBA_vert,
  8426. equirect_frag: equirect_frag,
  8427. equirect_vert: equirect_vert,
  8428. linedashed_frag: linedashed_frag,
  8429. linedashed_vert: linedashed_vert,
  8430. meshbasic_frag: meshbasic_frag,
  8431. meshbasic_vert: meshbasic_vert,
  8432. meshlambert_frag: meshlambert_frag,
  8433. meshlambert_vert: meshlambert_vert,
  8434. meshmatcap_frag: meshmatcap_frag,
  8435. meshmatcap_vert: meshmatcap_vert,
  8436. meshtoon_frag: meshtoon_frag,
  8437. meshtoon_vert: meshtoon_vert,
  8438. meshphong_frag: meshphong_frag,
  8439. meshphong_vert: meshphong_vert,
  8440. meshphysical_frag: meshphysical_frag,
  8441. meshphysical_vert: meshphysical_vert,
  8442. normal_frag: normal_frag,
  8443. normal_vert: normal_vert,
  8444. points_frag: points_frag,
  8445. points_vert: points_vert,
  8446. shadow_frag: shadow_frag,
  8447. shadow_vert: shadow_vert,
  8448. sprite_frag: sprite_frag,
  8449. sprite_vert: sprite_vert
  8450. };
  8451. /**
  8452. * Uniforms library for shared webgl shaders
  8453. */
  8454. var UniformsLib = {
  8455. common: {
  8456. diffuse: {
  8457. value: new Color(0xeeeeee)
  8458. },
  8459. opacity: {
  8460. value: 1.0
  8461. },
  8462. map: {
  8463. value: null
  8464. },
  8465. uvTransform: {
  8466. value: new Matrix3()
  8467. },
  8468. uv2Transform: {
  8469. value: new Matrix3()
  8470. },
  8471. alphaMap: {
  8472. value: null
  8473. }
  8474. },
  8475. specularmap: {
  8476. specularMap: {
  8477. value: null
  8478. }
  8479. },
  8480. envmap: {
  8481. envMap: {
  8482. value: null
  8483. },
  8484. flipEnvMap: {
  8485. value: -1
  8486. },
  8487. reflectivity: {
  8488. value: 1.0
  8489. },
  8490. refractionRatio: {
  8491. value: 0.98
  8492. },
  8493. maxMipLevel: {
  8494. value: 0
  8495. }
  8496. },
  8497. aomap: {
  8498. aoMap: {
  8499. value: null
  8500. },
  8501. aoMapIntensity: {
  8502. value: 1
  8503. }
  8504. },
  8505. lightmap: {
  8506. lightMap: {
  8507. value: null
  8508. },
  8509. lightMapIntensity: {
  8510. value: 1
  8511. }
  8512. },
  8513. emissivemap: {
  8514. emissiveMap: {
  8515. value: null
  8516. }
  8517. },
  8518. bumpmap: {
  8519. bumpMap: {
  8520. value: null
  8521. },
  8522. bumpScale: {
  8523. value: 1
  8524. }
  8525. },
  8526. normalmap: {
  8527. normalMap: {
  8528. value: null
  8529. },
  8530. normalScale: {
  8531. value: new Vector2(1, 1)
  8532. }
  8533. },
  8534. displacementmap: {
  8535. displacementMap: {
  8536. value: null
  8537. },
  8538. displacementScale: {
  8539. value: 1
  8540. },
  8541. displacementBias: {
  8542. value: 0
  8543. }
  8544. },
  8545. roughnessmap: {
  8546. roughnessMap: {
  8547. value: null
  8548. }
  8549. },
  8550. metalnessmap: {
  8551. metalnessMap: {
  8552. value: null
  8553. }
  8554. },
  8555. gradientmap: {
  8556. gradientMap: {
  8557. value: null
  8558. }
  8559. },
  8560. fog: {
  8561. fogDensity: {
  8562. value: 0.00025
  8563. },
  8564. fogNear: {
  8565. value: 1
  8566. },
  8567. fogFar: {
  8568. value: 2000
  8569. },
  8570. fogColor: {
  8571. value: new Color(0xffffff)
  8572. }
  8573. },
  8574. lights: {
  8575. ambientLightColor: {
  8576. value: []
  8577. },
  8578. lightProbe: {
  8579. value: []
  8580. },
  8581. directionalLights: {
  8582. value: [],
  8583. properties: {
  8584. direction: {},
  8585. color: {}
  8586. }
  8587. },
  8588. directionalLightShadows: {
  8589. value: [],
  8590. properties: {
  8591. shadowBias: {},
  8592. shadowNormalBias: {},
  8593. shadowRadius: {},
  8594. shadowMapSize: {}
  8595. }
  8596. },
  8597. directionalShadowMap: {
  8598. value: []
  8599. },
  8600. directionalShadowMatrix: {
  8601. value: []
  8602. },
  8603. spotLights: {
  8604. value: [],
  8605. properties: {
  8606. color: {},
  8607. position: {},
  8608. direction: {},
  8609. distance: {},
  8610. coneCos: {},
  8611. penumbraCos: {},
  8612. decay: {}
  8613. }
  8614. },
  8615. spotLightShadows: {
  8616. value: [],
  8617. properties: {
  8618. shadowBias: {},
  8619. shadowNormalBias: {},
  8620. shadowRadius: {},
  8621. shadowMapSize: {}
  8622. }
  8623. },
  8624. spotShadowMap: {
  8625. value: []
  8626. },
  8627. spotShadowMatrix: {
  8628. value: []
  8629. },
  8630. pointLights: {
  8631. value: [],
  8632. properties: {
  8633. color: {},
  8634. position: {},
  8635. decay: {},
  8636. distance: {}
  8637. }
  8638. },
  8639. pointLightShadows: {
  8640. value: [],
  8641. properties: {
  8642. shadowBias: {},
  8643. shadowNormalBias: {},
  8644. shadowRadius: {},
  8645. shadowMapSize: {},
  8646. shadowCameraNear: {},
  8647. shadowCameraFar: {}
  8648. }
  8649. },
  8650. pointShadowMap: {
  8651. value: []
  8652. },
  8653. pointShadowMatrix: {
  8654. value: []
  8655. },
  8656. hemisphereLights: {
  8657. value: [],
  8658. properties: {
  8659. direction: {},
  8660. skyColor: {},
  8661. groundColor: {}
  8662. }
  8663. },
  8664. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8665. rectAreaLights: {
  8666. value: [],
  8667. properties: {
  8668. color: {},
  8669. position: {},
  8670. width: {},
  8671. height: {}
  8672. }
  8673. },
  8674. ltc_1: {
  8675. value: null
  8676. },
  8677. ltc_2: {
  8678. value: null
  8679. }
  8680. },
  8681. points: {
  8682. diffuse: {
  8683. value: new Color(0xeeeeee)
  8684. },
  8685. opacity: {
  8686. value: 1.0
  8687. },
  8688. size: {
  8689. value: 1.0
  8690. },
  8691. scale: {
  8692. value: 1.0
  8693. },
  8694. map: {
  8695. value: null
  8696. },
  8697. alphaMap: {
  8698. value: null
  8699. },
  8700. uvTransform: {
  8701. value: new Matrix3()
  8702. }
  8703. },
  8704. sprite: {
  8705. diffuse: {
  8706. value: new Color(0xeeeeee)
  8707. },
  8708. opacity: {
  8709. value: 1.0
  8710. },
  8711. center: {
  8712. value: new Vector2(0.5, 0.5)
  8713. },
  8714. rotation: {
  8715. value: 0.0
  8716. },
  8717. map: {
  8718. value: null
  8719. },
  8720. alphaMap: {
  8721. value: null
  8722. },
  8723. uvTransform: {
  8724. value: new Matrix3()
  8725. }
  8726. }
  8727. };
  8728. var ShaderLib = {
  8729. basic: {
  8730. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8731. vertexShader: ShaderChunk.meshbasic_vert,
  8732. fragmentShader: ShaderChunk.meshbasic_frag
  8733. },
  8734. lambert: {
  8735. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8736. emissive: {
  8737. value: new Color(0x000000)
  8738. }
  8739. }]),
  8740. vertexShader: ShaderChunk.meshlambert_vert,
  8741. fragmentShader: ShaderChunk.meshlambert_frag
  8742. },
  8743. phong: {
  8744. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8745. emissive: {
  8746. value: new Color(0x000000)
  8747. },
  8748. specular: {
  8749. value: new Color(0x111111)
  8750. },
  8751. shininess: {
  8752. value: 30
  8753. }
  8754. }]),
  8755. vertexShader: ShaderChunk.meshphong_vert,
  8756. fragmentShader: ShaderChunk.meshphong_frag
  8757. },
  8758. standard: {
  8759. 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, {
  8760. emissive: {
  8761. value: new Color(0x000000)
  8762. },
  8763. roughness: {
  8764. value: 1.0
  8765. },
  8766. metalness: {
  8767. value: 0.0
  8768. },
  8769. envMapIntensity: {
  8770. value: 1
  8771. } // temporary
  8772. }]),
  8773. vertexShader: ShaderChunk.meshphysical_vert,
  8774. fragmentShader: ShaderChunk.meshphysical_frag
  8775. },
  8776. toon: {
  8777. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8778. emissive: {
  8779. value: new Color(0x000000)
  8780. }
  8781. }]),
  8782. vertexShader: ShaderChunk.meshtoon_vert,
  8783. fragmentShader: ShaderChunk.meshtoon_frag
  8784. },
  8785. matcap: {
  8786. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8787. matcap: {
  8788. value: null
  8789. }
  8790. }]),
  8791. vertexShader: ShaderChunk.meshmatcap_vert,
  8792. fragmentShader: ShaderChunk.meshmatcap_frag
  8793. },
  8794. points: {
  8795. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8796. vertexShader: ShaderChunk.points_vert,
  8797. fragmentShader: ShaderChunk.points_frag
  8798. },
  8799. dashed: {
  8800. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8801. scale: {
  8802. value: 1
  8803. },
  8804. dashSize: {
  8805. value: 1
  8806. },
  8807. totalSize: {
  8808. value: 2
  8809. }
  8810. }]),
  8811. vertexShader: ShaderChunk.linedashed_vert,
  8812. fragmentShader: ShaderChunk.linedashed_frag
  8813. },
  8814. depth: {
  8815. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8816. vertexShader: ShaderChunk.depth_vert,
  8817. fragmentShader: ShaderChunk.depth_frag
  8818. },
  8819. normal: {
  8820. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8821. opacity: {
  8822. value: 1.0
  8823. }
  8824. }]),
  8825. vertexShader: ShaderChunk.normal_vert,
  8826. fragmentShader: ShaderChunk.normal_frag
  8827. },
  8828. sprite: {
  8829. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8830. vertexShader: ShaderChunk.sprite_vert,
  8831. fragmentShader: ShaderChunk.sprite_frag
  8832. },
  8833. background: {
  8834. uniforms: {
  8835. uvTransform: {
  8836. value: new Matrix3()
  8837. },
  8838. t2D: {
  8839. value: null
  8840. }
  8841. },
  8842. vertexShader: ShaderChunk.background_vert,
  8843. fragmentShader: ShaderChunk.background_frag
  8844. },
  8845. /* -------------------------------------------------------------------------
  8846. // Cube map shader
  8847. ------------------------------------------------------------------------- */
  8848. cube: {
  8849. uniforms: mergeUniforms([UniformsLib.envmap, {
  8850. opacity: {
  8851. value: 1.0
  8852. }
  8853. }]),
  8854. vertexShader: ShaderChunk.cube_vert,
  8855. fragmentShader: ShaderChunk.cube_frag
  8856. },
  8857. equirect: {
  8858. uniforms: {
  8859. tEquirect: {
  8860. value: null
  8861. }
  8862. },
  8863. vertexShader: ShaderChunk.equirect_vert,
  8864. fragmentShader: ShaderChunk.equirect_frag
  8865. },
  8866. distanceRGBA: {
  8867. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  8868. referencePosition: {
  8869. value: new Vector3()
  8870. },
  8871. nearDistance: {
  8872. value: 1
  8873. },
  8874. farDistance: {
  8875. value: 1000
  8876. }
  8877. }]),
  8878. vertexShader: ShaderChunk.distanceRGBA_vert,
  8879. fragmentShader: ShaderChunk.distanceRGBA_frag
  8880. },
  8881. shadow: {
  8882. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  8883. color: {
  8884. value: new Color(0x00000)
  8885. },
  8886. opacity: {
  8887. value: 1.0
  8888. }
  8889. }]),
  8890. vertexShader: ShaderChunk.shadow_vert,
  8891. fragmentShader: ShaderChunk.shadow_frag
  8892. }
  8893. };
  8894. ShaderLib.physical = {
  8895. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  8896. clearcoat: {
  8897. value: 0
  8898. },
  8899. clearcoatMap: {
  8900. value: null
  8901. },
  8902. clearcoatRoughness: {
  8903. value: 0
  8904. },
  8905. clearcoatRoughnessMap: {
  8906. value: null
  8907. },
  8908. clearcoatNormalScale: {
  8909. value: new Vector2(1, 1)
  8910. },
  8911. clearcoatNormalMap: {
  8912. value: null
  8913. },
  8914. sheen: {
  8915. value: new Color(0x000000)
  8916. },
  8917. transmission: {
  8918. value: 0
  8919. },
  8920. transmissionMap: {
  8921. value: null
  8922. }
  8923. }]),
  8924. vertexShader: ShaderChunk.meshphysical_vert,
  8925. fragmentShader: ShaderChunk.meshphysical_frag
  8926. };
  8927. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  8928. var clearColor = new Color(0x000000);
  8929. var clearAlpha = 0;
  8930. var planeMesh;
  8931. var boxMesh;
  8932. var currentBackground = null;
  8933. var currentBackgroundVersion = 0;
  8934. var currentTonemapping = null;
  8935. function render(renderList, scene, camera, forceClear) {
  8936. var background = scene.isScene === true ? scene.background : null;
  8937. if (background && background.isTexture) {
  8938. background = cubemaps.get(background);
  8939. } // Ignore background in AR
  8940. // TODO: Reconsider this.
  8941. var xr = renderer.xr;
  8942. var session = xr.getSession && xr.getSession();
  8943. if (session && session.environmentBlendMode === 'additive') {
  8944. background = null;
  8945. }
  8946. if (background === null) {
  8947. setClear(clearColor, clearAlpha);
  8948. } else if (background && background.isColor) {
  8949. setClear(background, 1);
  8950. forceClear = true;
  8951. }
  8952. if (renderer.autoClear || forceClear) {
  8953. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  8954. }
  8955. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  8956. if (boxMesh === undefined) {
  8957. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  8958. name: 'BackgroundCubeMaterial',
  8959. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  8960. vertexShader: ShaderLib.cube.vertexShader,
  8961. fragmentShader: ShaderLib.cube.fragmentShader,
  8962. side: BackSide,
  8963. depthTest: false,
  8964. depthWrite: false,
  8965. fog: false
  8966. }));
  8967. boxMesh.geometry.deleteAttribute('normal');
  8968. boxMesh.geometry.deleteAttribute('uv');
  8969. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  8970. this.matrixWorld.copyPosition(camera.matrixWorld);
  8971. }; // enable code injection for non-built-in material
  8972. Object.defineProperty(boxMesh.material, 'envMap', {
  8973. get: function get() {
  8974. return this.uniforms.envMap.value;
  8975. }
  8976. });
  8977. objects.update(boxMesh);
  8978. }
  8979. if (background.isWebGLCubeRenderTarget) {
  8980. // TODO Deprecate
  8981. background = background.texture;
  8982. }
  8983. boxMesh.material.uniforms.envMap.value = background;
  8984. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  8985. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  8986. boxMesh.material.needsUpdate = true;
  8987. currentBackground = background;
  8988. currentBackgroundVersion = background.version;
  8989. currentTonemapping = renderer.toneMapping;
  8990. } // push to the pre-sorted opaque render list
  8991. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  8992. } else if (background && background.isTexture) {
  8993. if (planeMesh === undefined) {
  8994. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  8995. name: 'BackgroundMaterial',
  8996. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  8997. vertexShader: ShaderLib.background.vertexShader,
  8998. fragmentShader: ShaderLib.background.fragmentShader,
  8999. side: FrontSide,
  9000. depthTest: false,
  9001. depthWrite: false,
  9002. fog: false
  9003. }));
  9004. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9005. Object.defineProperty(planeMesh.material, 'map', {
  9006. get: function get() {
  9007. return this.uniforms.t2D.value;
  9008. }
  9009. });
  9010. objects.update(planeMesh);
  9011. }
  9012. planeMesh.material.uniforms.t2D.value = background;
  9013. if (background.matrixAutoUpdate === true) {
  9014. background.updateMatrix();
  9015. }
  9016. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9017. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9018. planeMesh.material.needsUpdate = true;
  9019. currentBackground = background;
  9020. currentBackgroundVersion = background.version;
  9021. currentTonemapping = renderer.toneMapping;
  9022. } // push to the pre-sorted opaque render list
  9023. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9024. }
  9025. }
  9026. function setClear(color, alpha) {
  9027. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9028. }
  9029. return {
  9030. getClearColor: function getClearColor() {
  9031. return clearColor;
  9032. },
  9033. setClearColor: function setClearColor(color, alpha) {
  9034. clearColor.set(color);
  9035. clearAlpha = alpha !== undefined ? alpha : 1;
  9036. setClear(clearColor, clearAlpha);
  9037. },
  9038. getClearAlpha: function getClearAlpha() {
  9039. return clearAlpha;
  9040. },
  9041. setClearAlpha: function setClearAlpha(alpha) {
  9042. clearAlpha = alpha;
  9043. setClear(clearColor, clearAlpha);
  9044. },
  9045. render: render
  9046. };
  9047. }
  9048. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9049. var maxVertexAttributes = gl.getParameter(34921);
  9050. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9051. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9052. var bindingStates = {};
  9053. var defaultState = createBindingState(null);
  9054. var currentState = defaultState;
  9055. function setup(object, material, program, geometry, index) {
  9056. var updateBuffers = false;
  9057. if (vaoAvailable) {
  9058. var state = getBindingState(geometry, program, material);
  9059. if (currentState !== state) {
  9060. currentState = state;
  9061. bindVertexArrayObject(currentState.object);
  9062. }
  9063. updateBuffers = needsUpdate(geometry, index);
  9064. if (updateBuffers) saveCache(geometry, index);
  9065. } else {
  9066. var wireframe = material.wireframe === true;
  9067. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9068. currentState.geometry = geometry.id;
  9069. currentState.program = program.id;
  9070. currentState.wireframe = wireframe;
  9071. updateBuffers = true;
  9072. }
  9073. }
  9074. if (object.isInstancedMesh === true) {
  9075. updateBuffers = true;
  9076. }
  9077. if (index !== null) {
  9078. attributes.update(index, 34963);
  9079. }
  9080. if (updateBuffers) {
  9081. setupVertexAttributes(object, material, program, geometry);
  9082. if (index !== null) {
  9083. gl.bindBuffer(34963, attributes.get(index).buffer);
  9084. }
  9085. }
  9086. }
  9087. function createVertexArrayObject() {
  9088. if (capabilities.isWebGL2) return gl.createVertexArray();
  9089. return extension.createVertexArrayOES();
  9090. }
  9091. function bindVertexArrayObject(vao) {
  9092. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9093. return extension.bindVertexArrayOES(vao);
  9094. }
  9095. function deleteVertexArrayObject(vao) {
  9096. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9097. return extension.deleteVertexArrayOES(vao);
  9098. }
  9099. function getBindingState(geometry, program, material) {
  9100. var wireframe = material.wireframe === true;
  9101. var programMap = bindingStates[geometry.id];
  9102. if (programMap === undefined) {
  9103. programMap = {};
  9104. bindingStates[geometry.id] = programMap;
  9105. }
  9106. var stateMap = programMap[program.id];
  9107. if (stateMap === undefined) {
  9108. stateMap = {};
  9109. programMap[program.id] = stateMap;
  9110. }
  9111. var state = stateMap[wireframe];
  9112. if (state === undefined) {
  9113. state = createBindingState(createVertexArrayObject());
  9114. stateMap[wireframe] = state;
  9115. }
  9116. return state;
  9117. }
  9118. function createBindingState(vao) {
  9119. var newAttributes = [];
  9120. var enabledAttributes = [];
  9121. var attributeDivisors = [];
  9122. for (var i = 0; i < maxVertexAttributes; i++) {
  9123. newAttributes[i] = 0;
  9124. enabledAttributes[i] = 0;
  9125. attributeDivisors[i] = 0;
  9126. }
  9127. return {
  9128. // for backward compatibility on non-VAO support browser
  9129. geometry: null,
  9130. program: null,
  9131. wireframe: false,
  9132. newAttributes: newAttributes,
  9133. enabledAttributes: enabledAttributes,
  9134. attributeDivisors: attributeDivisors,
  9135. object: vao,
  9136. attributes: {},
  9137. index: null
  9138. };
  9139. }
  9140. function needsUpdate(geometry, index) {
  9141. var cachedAttributes = currentState.attributes;
  9142. var geometryAttributes = geometry.attributes;
  9143. if (Object.keys(cachedAttributes).length !== Object.keys(geometryAttributes).length) return true;
  9144. for (var key in geometryAttributes) {
  9145. var cachedAttribute = cachedAttributes[key];
  9146. var geometryAttribute = geometryAttributes[key];
  9147. if (cachedAttribute === undefined) return true;
  9148. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9149. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9150. }
  9151. if (currentState.index !== index) return true;
  9152. return false;
  9153. }
  9154. function saveCache(geometry, index) {
  9155. var cache = {};
  9156. var attributes = geometry.attributes;
  9157. for (var key in attributes) {
  9158. var attribute = attributes[key];
  9159. var data = {};
  9160. data.attribute = attribute;
  9161. if (attribute.data) {
  9162. data.data = attribute.data;
  9163. }
  9164. cache[key] = data;
  9165. }
  9166. currentState.attributes = cache;
  9167. currentState.index = index;
  9168. }
  9169. function initAttributes() {
  9170. var newAttributes = currentState.newAttributes;
  9171. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9172. newAttributes[i] = 0;
  9173. }
  9174. }
  9175. function enableAttribute(attribute) {
  9176. enableAttributeAndDivisor(attribute, 0);
  9177. }
  9178. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9179. var newAttributes = currentState.newAttributes;
  9180. var enabledAttributes = currentState.enabledAttributes;
  9181. var attributeDivisors = currentState.attributeDivisors;
  9182. newAttributes[attribute] = 1;
  9183. if (enabledAttributes[attribute] === 0) {
  9184. gl.enableVertexAttribArray(attribute);
  9185. enabledAttributes[attribute] = 1;
  9186. }
  9187. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9188. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9189. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9190. attributeDivisors[attribute] = meshPerAttribute;
  9191. }
  9192. }
  9193. function disableUnusedAttributes() {
  9194. var newAttributes = currentState.newAttributes;
  9195. var enabledAttributes = currentState.enabledAttributes;
  9196. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9197. if (enabledAttributes[i] !== newAttributes[i]) {
  9198. gl.disableVertexAttribArray(i);
  9199. enabledAttributes[i] = 0;
  9200. }
  9201. }
  9202. }
  9203. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9204. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9205. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9206. } else {
  9207. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9208. }
  9209. }
  9210. function setupVertexAttributes(object, material, program, geometry) {
  9211. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9212. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9213. }
  9214. initAttributes();
  9215. var geometryAttributes = geometry.attributes;
  9216. var programAttributes = program.getAttributes();
  9217. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9218. for (var name in programAttributes) {
  9219. var programAttribute = programAttributes[name];
  9220. if (programAttribute >= 0) {
  9221. var geometryAttribute = geometryAttributes[name];
  9222. if (geometryAttribute !== undefined) {
  9223. var normalized = geometryAttribute.normalized;
  9224. var size = geometryAttribute.itemSize;
  9225. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9226. if (attribute === undefined) continue;
  9227. var buffer = attribute.buffer;
  9228. var type = attribute.type;
  9229. var bytesPerElement = attribute.bytesPerElement;
  9230. if (geometryAttribute.isInterleavedBufferAttribute) {
  9231. var data = geometryAttribute.data;
  9232. var stride = data.stride;
  9233. var offset = geometryAttribute.offset;
  9234. if (data && data.isInstancedInterleavedBuffer) {
  9235. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9236. if (geometry._maxInstanceCount === undefined) {
  9237. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9238. }
  9239. } else {
  9240. enableAttribute(programAttribute);
  9241. }
  9242. gl.bindBuffer(34962, buffer);
  9243. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9244. } else {
  9245. if (geometryAttribute.isInstancedBufferAttribute) {
  9246. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9247. if (geometry._maxInstanceCount === undefined) {
  9248. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9249. }
  9250. } else {
  9251. enableAttribute(programAttribute);
  9252. }
  9253. gl.bindBuffer(34962, buffer);
  9254. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9255. }
  9256. } else if (name === 'instanceMatrix') {
  9257. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9258. if (_attribute === undefined) continue;
  9259. var _buffer = _attribute.buffer;
  9260. var _type = _attribute.type;
  9261. enableAttributeAndDivisor(programAttribute + 0, 1);
  9262. enableAttributeAndDivisor(programAttribute + 1, 1);
  9263. enableAttributeAndDivisor(programAttribute + 2, 1);
  9264. enableAttributeAndDivisor(programAttribute + 3, 1);
  9265. gl.bindBuffer(34962, _buffer);
  9266. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9267. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9268. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9269. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9270. } else if (name === 'instanceColor') {
  9271. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9272. if (_attribute2 === undefined) continue;
  9273. var _buffer2 = _attribute2.buffer;
  9274. var _type2 = _attribute2.type;
  9275. enableAttributeAndDivisor(programAttribute, 1);
  9276. gl.bindBuffer(34962, _buffer2);
  9277. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9278. } else if (materialDefaultAttributeValues !== undefined) {
  9279. var value = materialDefaultAttributeValues[name];
  9280. if (value !== undefined) {
  9281. switch (value.length) {
  9282. case 2:
  9283. gl.vertexAttrib2fv(programAttribute, value);
  9284. break;
  9285. case 3:
  9286. gl.vertexAttrib3fv(programAttribute, value);
  9287. break;
  9288. case 4:
  9289. gl.vertexAttrib4fv(programAttribute, value);
  9290. break;
  9291. default:
  9292. gl.vertexAttrib1fv(programAttribute, value);
  9293. }
  9294. }
  9295. }
  9296. }
  9297. }
  9298. disableUnusedAttributes();
  9299. }
  9300. function dispose() {
  9301. reset();
  9302. for (var geometryId in bindingStates) {
  9303. var programMap = bindingStates[geometryId];
  9304. for (var programId in programMap) {
  9305. var stateMap = programMap[programId];
  9306. for (var wireframe in stateMap) {
  9307. deleteVertexArrayObject(stateMap[wireframe].object);
  9308. delete stateMap[wireframe];
  9309. }
  9310. delete programMap[programId];
  9311. }
  9312. delete bindingStates[geometryId];
  9313. }
  9314. }
  9315. function releaseStatesOfGeometry(geometry) {
  9316. if (bindingStates[geometry.id] === undefined) return;
  9317. var programMap = bindingStates[geometry.id];
  9318. for (var programId in programMap) {
  9319. var stateMap = programMap[programId];
  9320. for (var wireframe in stateMap) {
  9321. deleteVertexArrayObject(stateMap[wireframe].object);
  9322. delete stateMap[wireframe];
  9323. }
  9324. delete programMap[programId];
  9325. }
  9326. delete bindingStates[geometry.id];
  9327. }
  9328. function releaseStatesOfProgram(program) {
  9329. for (var geometryId in bindingStates) {
  9330. var programMap = bindingStates[geometryId];
  9331. if (programMap[program.id] === undefined) continue;
  9332. var stateMap = programMap[program.id];
  9333. for (var wireframe in stateMap) {
  9334. deleteVertexArrayObject(stateMap[wireframe].object);
  9335. delete stateMap[wireframe];
  9336. }
  9337. delete programMap[program.id];
  9338. }
  9339. }
  9340. function reset() {
  9341. resetDefaultState();
  9342. if (currentState === defaultState) return;
  9343. currentState = defaultState;
  9344. bindVertexArrayObject(currentState.object);
  9345. } // for backward-compatilibity
  9346. function resetDefaultState() {
  9347. defaultState.geometry = null;
  9348. defaultState.program = null;
  9349. defaultState.wireframe = false;
  9350. }
  9351. return {
  9352. setup: setup,
  9353. reset: reset,
  9354. resetDefaultState: resetDefaultState,
  9355. dispose: dispose,
  9356. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9357. releaseStatesOfProgram: releaseStatesOfProgram,
  9358. initAttributes: initAttributes,
  9359. enableAttribute: enableAttribute,
  9360. disableUnusedAttributes: disableUnusedAttributes
  9361. };
  9362. }
  9363. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9364. var isWebGL2 = capabilities.isWebGL2;
  9365. var mode;
  9366. function setMode(value) {
  9367. mode = value;
  9368. }
  9369. function render(start, count) {
  9370. gl.drawArrays(mode, start, count);
  9371. info.update(count, mode, 1);
  9372. }
  9373. function renderInstances(start, count, primcount) {
  9374. if (primcount === 0) return;
  9375. var extension, methodName;
  9376. if (isWebGL2) {
  9377. extension = gl;
  9378. methodName = 'drawArraysInstanced';
  9379. } else {
  9380. extension = extensions.get('ANGLE_instanced_arrays');
  9381. methodName = 'drawArraysInstancedANGLE';
  9382. if (extension === null) {
  9383. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9384. return;
  9385. }
  9386. }
  9387. extension[methodName](mode, start, count, primcount);
  9388. info.update(count, mode, primcount);
  9389. } //
  9390. this.setMode = setMode;
  9391. this.render = render;
  9392. this.renderInstances = renderInstances;
  9393. }
  9394. function WebGLCapabilities(gl, extensions, parameters) {
  9395. var maxAnisotropy;
  9396. function getMaxAnisotropy() {
  9397. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9398. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9399. if (extension !== null) {
  9400. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9401. } else {
  9402. maxAnisotropy = 0;
  9403. }
  9404. return maxAnisotropy;
  9405. }
  9406. function getMaxPrecision(precision) {
  9407. if (precision === 'highp') {
  9408. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9409. return 'highp';
  9410. }
  9411. precision = 'mediump';
  9412. }
  9413. if (precision === 'mediump') {
  9414. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9415. return 'mediump';
  9416. }
  9417. }
  9418. return 'lowp';
  9419. }
  9420. /* eslint-disable no-undef */
  9421. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9422. /* eslint-enable no-undef */
  9423. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9424. var maxPrecision = getMaxPrecision(precision);
  9425. if (maxPrecision !== precision) {
  9426. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9427. precision = maxPrecision;
  9428. }
  9429. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9430. var maxTextures = gl.getParameter(34930);
  9431. var maxVertexTextures = gl.getParameter(35660);
  9432. var maxTextureSize = gl.getParameter(3379);
  9433. var maxCubemapSize = gl.getParameter(34076);
  9434. var maxAttributes = gl.getParameter(34921);
  9435. var maxVertexUniforms = gl.getParameter(36347);
  9436. var maxVaryings = gl.getParameter(36348);
  9437. var maxFragmentUniforms = gl.getParameter(36349);
  9438. var vertexTextures = maxVertexTextures > 0;
  9439. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9440. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9441. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9442. return {
  9443. isWebGL2: isWebGL2,
  9444. getMaxAnisotropy: getMaxAnisotropy,
  9445. getMaxPrecision: getMaxPrecision,
  9446. precision: precision,
  9447. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9448. maxTextures: maxTextures,
  9449. maxVertexTextures: maxVertexTextures,
  9450. maxTextureSize: maxTextureSize,
  9451. maxCubemapSize: maxCubemapSize,
  9452. maxAttributes: maxAttributes,
  9453. maxVertexUniforms: maxVertexUniforms,
  9454. maxVaryings: maxVaryings,
  9455. maxFragmentUniforms: maxFragmentUniforms,
  9456. vertexTextures: vertexTextures,
  9457. floatFragmentTextures: floatFragmentTextures,
  9458. floatVertexTextures: floatVertexTextures,
  9459. maxSamples: maxSamples
  9460. };
  9461. }
  9462. function WebGLClipping(properties) {
  9463. var scope = this;
  9464. var globalState = null,
  9465. numGlobalPlanes = 0,
  9466. localClippingEnabled = false,
  9467. renderingShadows = false;
  9468. var plane = new Plane(),
  9469. viewNormalMatrix = new Matrix3(),
  9470. uniform = {
  9471. value: null,
  9472. needsUpdate: false
  9473. };
  9474. this.uniform = uniform;
  9475. this.numPlanes = 0;
  9476. this.numIntersection = 0;
  9477. this.init = function (planes, enableLocalClipping, camera) {
  9478. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9479. // run another frame in order to reset the state:
  9480. numGlobalPlanes !== 0 || localClippingEnabled;
  9481. localClippingEnabled = enableLocalClipping;
  9482. globalState = projectPlanes(planes, camera, 0);
  9483. numGlobalPlanes = planes.length;
  9484. return enabled;
  9485. };
  9486. this.beginShadows = function () {
  9487. renderingShadows = true;
  9488. projectPlanes(null);
  9489. };
  9490. this.endShadows = function () {
  9491. renderingShadows = false;
  9492. resetGlobalState();
  9493. };
  9494. this.setState = function (material, camera, useCache) {
  9495. var planes = material.clippingPlanes,
  9496. clipIntersection = material.clipIntersection,
  9497. clipShadows = material.clipShadows;
  9498. var materialProperties = properties.get(material);
  9499. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9500. // there's no local clipping
  9501. if (renderingShadows) {
  9502. // there's no global clipping
  9503. projectPlanes(null);
  9504. } else {
  9505. resetGlobalState();
  9506. }
  9507. } else {
  9508. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9509. lGlobal = nGlobal * 4;
  9510. var dstArray = materialProperties.clippingState || null;
  9511. uniform.value = dstArray; // ensure unique state
  9512. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9513. for (var i = 0; i !== lGlobal; ++i) {
  9514. dstArray[i] = globalState[i];
  9515. }
  9516. materialProperties.clippingState = dstArray;
  9517. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9518. this.numPlanes += nGlobal;
  9519. }
  9520. };
  9521. function resetGlobalState() {
  9522. if (uniform.value !== globalState) {
  9523. uniform.value = globalState;
  9524. uniform.needsUpdate = numGlobalPlanes > 0;
  9525. }
  9526. scope.numPlanes = numGlobalPlanes;
  9527. scope.numIntersection = 0;
  9528. }
  9529. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9530. var nPlanes = planes !== null ? planes.length : 0;
  9531. var dstArray = null;
  9532. if (nPlanes !== 0) {
  9533. dstArray = uniform.value;
  9534. if (skipTransform !== true || dstArray === null) {
  9535. var flatSize = dstOffset + nPlanes * 4,
  9536. viewMatrix = camera.matrixWorldInverse;
  9537. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9538. if (dstArray === null || dstArray.length < flatSize) {
  9539. dstArray = new Float32Array(flatSize);
  9540. }
  9541. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9542. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9543. plane.normal.toArray(dstArray, i4);
  9544. dstArray[i4 + 3] = plane.constant;
  9545. }
  9546. }
  9547. uniform.value = dstArray;
  9548. uniform.needsUpdate = true;
  9549. }
  9550. scope.numPlanes = nPlanes;
  9551. scope.numIntersection = 0;
  9552. return dstArray;
  9553. }
  9554. }
  9555. function WebGLCubeMaps(renderer) {
  9556. var cubemaps = new WeakMap();
  9557. function mapTextureMapping(texture, mapping) {
  9558. if (mapping === EquirectangularReflectionMapping) {
  9559. texture.mapping = CubeReflectionMapping;
  9560. } else if (mapping === EquirectangularRefractionMapping) {
  9561. texture.mapping = CubeRefractionMapping;
  9562. }
  9563. return texture;
  9564. }
  9565. function get(texture) {
  9566. if (texture && texture.isTexture) {
  9567. var mapping = texture.mapping;
  9568. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9569. if (cubemaps.has(texture)) {
  9570. var cubemap = cubemaps.get(texture).texture;
  9571. return mapTextureMapping(cubemap, texture.mapping);
  9572. } else {
  9573. var image = texture.image;
  9574. if (image && image.height > 0) {
  9575. var currentRenderList = renderer.getRenderList();
  9576. var currentRenderTarget = renderer.getRenderTarget();
  9577. var currentRenderState = renderer.getRenderState();
  9578. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9579. renderTarget.fromEquirectangularTexture(renderer, texture);
  9580. cubemaps.set(texture, renderTarget);
  9581. renderer.setRenderTarget(currentRenderTarget);
  9582. renderer.setRenderList(currentRenderList);
  9583. renderer.setRenderState(currentRenderState);
  9584. texture.addEventListener('dispose', onTextureDispose);
  9585. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9586. } else {
  9587. // image not yet ready. try the conversion next frame
  9588. return null;
  9589. }
  9590. }
  9591. }
  9592. }
  9593. return texture;
  9594. }
  9595. function onTextureDispose(event) {
  9596. var texture = event.target;
  9597. texture.removeEventListener('dispose', onTextureDispose);
  9598. var cubemap = cubemaps.get(texture);
  9599. if (cubemap !== undefined) {
  9600. cubemaps.delete(texture);
  9601. cubemap.dispose();
  9602. }
  9603. }
  9604. function dispose() {
  9605. cubemaps = new WeakMap();
  9606. }
  9607. return {
  9608. get: get,
  9609. dispose: dispose
  9610. };
  9611. }
  9612. function WebGLExtensions(gl) {
  9613. var extensions = {};
  9614. return {
  9615. has: function has(name) {
  9616. if (extensions[name] !== undefined) {
  9617. return extensions[name] !== null;
  9618. }
  9619. var extension;
  9620. switch (name) {
  9621. case 'WEBGL_depth_texture':
  9622. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9623. break;
  9624. case 'EXT_texture_filter_anisotropic':
  9625. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9626. break;
  9627. case 'WEBGL_compressed_texture_s3tc':
  9628. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9629. break;
  9630. case 'WEBGL_compressed_texture_pvrtc':
  9631. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9632. break;
  9633. default:
  9634. extension = gl.getExtension(name);
  9635. }
  9636. extensions[name] = extension;
  9637. return extension !== null;
  9638. },
  9639. get: function get(name) {
  9640. if (!this.has(name)) {
  9641. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9642. }
  9643. return extensions[name];
  9644. }
  9645. };
  9646. }
  9647. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9648. var geometries = new WeakMap();
  9649. var wireframeAttributes = new WeakMap();
  9650. function onGeometryDispose(event) {
  9651. var geometry = event.target;
  9652. var buffergeometry = geometries.get(geometry);
  9653. if (buffergeometry.index !== null) {
  9654. attributes.remove(buffergeometry.index);
  9655. }
  9656. for (var name in buffergeometry.attributes) {
  9657. attributes.remove(buffergeometry.attributes[name]);
  9658. }
  9659. geometry.removeEventListener('dispose', onGeometryDispose);
  9660. geometries.delete(geometry);
  9661. var attribute = wireframeAttributes.get(buffergeometry);
  9662. if (attribute) {
  9663. attributes.remove(attribute);
  9664. wireframeAttributes.delete(buffergeometry);
  9665. }
  9666. bindingStates.releaseStatesOfGeometry(buffergeometry);
  9667. if (geometry.isInstancedBufferGeometry === true) {
  9668. delete geometry._maxInstanceCount;
  9669. } //
  9670. info.memory.geometries--;
  9671. }
  9672. function get(object, geometry) {
  9673. var buffergeometry = geometries.get(geometry);
  9674. if (buffergeometry) return buffergeometry;
  9675. geometry.addEventListener('dispose', onGeometryDispose);
  9676. if (geometry.isBufferGeometry) {
  9677. buffergeometry = geometry;
  9678. } else if (geometry.isGeometry) {
  9679. if (geometry._bufferGeometry === undefined) {
  9680. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9681. }
  9682. buffergeometry = geometry._bufferGeometry;
  9683. }
  9684. geometries.set(geometry, buffergeometry);
  9685. info.memory.geometries++;
  9686. return buffergeometry;
  9687. }
  9688. function update(geometry) {
  9689. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9690. for (var name in geometryAttributes) {
  9691. attributes.update(geometryAttributes[name], 34962);
  9692. } // morph targets
  9693. var morphAttributes = geometry.morphAttributes;
  9694. for (var _name in morphAttributes) {
  9695. var array = morphAttributes[_name];
  9696. for (var i = 0, l = array.length; i < l; i++) {
  9697. attributes.update(array[i], 34962);
  9698. }
  9699. }
  9700. }
  9701. function updateWireframeAttribute(geometry) {
  9702. var indices = [];
  9703. var geometryIndex = geometry.index;
  9704. var geometryPosition = geometry.attributes.position;
  9705. var version = 0;
  9706. if (geometryIndex !== null) {
  9707. var array = geometryIndex.array;
  9708. version = geometryIndex.version;
  9709. for (var i = 0, l = array.length; i < l; i += 3) {
  9710. var a = array[i + 0];
  9711. var b = array[i + 1];
  9712. var c = array[i + 2];
  9713. indices.push(a, b, b, c, c, a);
  9714. }
  9715. } else {
  9716. var _array = geometryPosition.array;
  9717. version = geometryPosition.version;
  9718. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9719. var _a = _i + 0;
  9720. var _b = _i + 1;
  9721. var _c = _i + 2;
  9722. indices.push(_a, _b, _b, _c, _c, _a);
  9723. }
  9724. }
  9725. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9726. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9727. //
  9728. var previousAttribute = wireframeAttributes.get(geometry);
  9729. if (previousAttribute) attributes.remove(previousAttribute); //
  9730. wireframeAttributes.set(geometry, attribute);
  9731. }
  9732. function getWireframeAttribute(geometry) {
  9733. var currentAttribute = wireframeAttributes.get(geometry);
  9734. if (currentAttribute) {
  9735. var geometryIndex = geometry.index;
  9736. if (geometryIndex !== null) {
  9737. // if the attribute is obsolete, create a new one
  9738. if (currentAttribute.version < geometryIndex.version) {
  9739. updateWireframeAttribute(geometry);
  9740. }
  9741. }
  9742. } else {
  9743. updateWireframeAttribute(geometry);
  9744. }
  9745. return wireframeAttributes.get(geometry);
  9746. }
  9747. return {
  9748. get: get,
  9749. update: update,
  9750. getWireframeAttribute: getWireframeAttribute
  9751. };
  9752. }
  9753. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9754. var isWebGL2 = capabilities.isWebGL2;
  9755. var mode;
  9756. function setMode(value) {
  9757. mode = value;
  9758. }
  9759. var type, bytesPerElement;
  9760. function setIndex(value) {
  9761. type = value.type;
  9762. bytesPerElement = value.bytesPerElement;
  9763. }
  9764. function render(start, count) {
  9765. gl.drawElements(mode, count, type, start * bytesPerElement);
  9766. info.update(count, mode, 1);
  9767. }
  9768. function renderInstances(start, count, primcount) {
  9769. if (primcount === 0) return;
  9770. var extension, methodName;
  9771. if (isWebGL2) {
  9772. extension = gl;
  9773. methodName = 'drawElementsInstanced';
  9774. } else {
  9775. extension = extensions.get('ANGLE_instanced_arrays');
  9776. methodName = 'drawElementsInstancedANGLE';
  9777. if (extension === null) {
  9778. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9779. return;
  9780. }
  9781. }
  9782. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9783. info.update(count, mode, primcount);
  9784. } //
  9785. this.setMode = setMode;
  9786. this.setIndex = setIndex;
  9787. this.render = render;
  9788. this.renderInstances = renderInstances;
  9789. }
  9790. function WebGLInfo(gl) {
  9791. var memory = {
  9792. geometries: 0,
  9793. textures: 0
  9794. };
  9795. var render = {
  9796. frame: 0,
  9797. calls: 0,
  9798. triangles: 0,
  9799. points: 0,
  9800. lines: 0
  9801. };
  9802. function update(count, mode, instanceCount) {
  9803. render.calls++;
  9804. switch (mode) {
  9805. case 4:
  9806. render.triangles += instanceCount * (count / 3);
  9807. break;
  9808. case 1:
  9809. render.lines += instanceCount * (count / 2);
  9810. break;
  9811. case 3:
  9812. render.lines += instanceCount * (count - 1);
  9813. break;
  9814. case 2:
  9815. render.lines += instanceCount * count;
  9816. break;
  9817. case 0:
  9818. render.points += instanceCount * count;
  9819. break;
  9820. default:
  9821. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9822. break;
  9823. }
  9824. }
  9825. function reset() {
  9826. render.frame++;
  9827. render.calls = 0;
  9828. render.triangles = 0;
  9829. render.points = 0;
  9830. render.lines = 0;
  9831. }
  9832. return {
  9833. memory: memory,
  9834. render: render,
  9835. programs: null,
  9836. autoReset: true,
  9837. reset: reset,
  9838. update: update
  9839. };
  9840. }
  9841. function numericalSort(a, b) {
  9842. return a[0] - b[0];
  9843. }
  9844. function absNumericalSort(a, b) {
  9845. return Math.abs(b[1]) - Math.abs(a[1]);
  9846. }
  9847. function WebGLMorphtargets(gl) {
  9848. var influencesList = {};
  9849. var morphInfluences = new Float32Array(8);
  9850. var workInfluences = [];
  9851. for (var i = 0; i < 8; i++) {
  9852. workInfluences[i] = [i, 0];
  9853. }
  9854. function update(object, geometry, material, program) {
  9855. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9856. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9857. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9858. var influences = influencesList[geometry.id];
  9859. if (influences === undefined) {
  9860. // initialise list
  9861. influences = [];
  9862. for (var _i = 0; _i < length; _i++) {
  9863. influences[_i] = [_i, 0];
  9864. }
  9865. influencesList[geometry.id] = influences;
  9866. } // Collect influences
  9867. for (var _i2 = 0; _i2 < length; _i2++) {
  9868. var influence = influences[_i2];
  9869. influence[0] = _i2;
  9870. influence[1] = objectInfluences[_i2];
  9871. }
  9872. influences.sort(absNumericalSort);
  9873. for (var _i3 = 0; _i3 < 8; _i3++) {
  9874. if (_i3 < length && influences[_i3][1]) {
  9875. workInfluences[_i3][0] = influences[_i3][0];
  9876. workInfluences[_i3][1] = influences[_i3][1];
  9877. } else {
  9878. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  9879. workInfluences[_i3][1] = 0;
  9880. }
  9881. }
  9882. workInfluences.sort(numericalSort);
  9883. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9884. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9885. var morphInfluencesSum = 0;
  9886. for (var _i4 = 0; _i4 < 8; _i4++) {
  9887. var _influence = workInfluences[_i4];
  9888. var index = _influence[0];
  9889. var value = _influence[1];
  9890. if (index !== Number.MAX_SAFE_INTEGER && value) {
  9891. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  9892. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  9893. }
  9894. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  9895. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  9896. }
  9897. morphInfluences[_i4] = value;
  9898. morphInfluencesSum += value;
  9899. } else {
  9900. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== undefined) {
  9901. geometry.deleteAttribute('morphTarget' + _i4);
  9902. }
  9903. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== undefined) {
  9904. geometry.deleteAttribute('morphNormal' + _i4);
  9905. }
  9906. morphInfluences[_i4] = 0;
  9907. }
  9908. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9909. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9910. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9911. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9912. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  9913. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  9914. }
  9915. return {
  9916. update: update
  9917. };
  9918. }
  9919. function WebGLObjects(gl, geometries, attributes, info) {
  9920. var updateMap = new WeakMap();
  9921. function update(object) {
  9922. var frame = info.render.frame;
  9923. var geometry = object.geometry;
  9924. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  9925. if (updateMap.get(buffergeometry) !== frame) {
  9926. if (geometry.isGeometry) {
  9927. buffergeometry.updateFromObject(object);
  9928. }
  9929. geometries.update(buffergeometry);
  9930. updateMap.set(buffergeometry, frame);
  9931. }
  9932. if (object.isInstancedMesh) {
  9933. attributes.update(object.instanceMatrix, 34962);
  9934. if (object.instanceColor !== null) {
  9935. attributes.update(object.instanceColor, 34962);
  9936. }
  9937. }
  9938. return buffergeometry;
  9939. }
  9940. function dispose() {
  9941. updateMap = new WeakMap();
  9942. }
  9943. return {
  9944. update: update,
  9945. dispose: dispose
  9946. };
  9947. }
  9948. function DataTexture2DArray(data, width, height, depth) {
  9949. Texture.call(this, null);
  9950. this.image = {
  9951. data: data || null,
  9952. width: width || 1,
  9953. height: height || 1,
  9954. depth: depth || 1
  9955. };
  9956. this.magFilter = NearestFilter;
  9957. this.minFilter = NearestFilter;
  9958. this.wrapR = ClampToEdgeWrapping;
  9959. this.generateMipmaps = false;
  9960. this.flipY = false;
  9961. this.needsUpdate = true;
  9962. }
  9963. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  9964. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9965. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9966. function DataTexture3D(data, width, height, depth) {
  9967. // We're going to add .setXXX() methods for setting properties later.
  9968. // Users can still set in DataTexture3D directly.
  9969. //
  9970. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  9971. // texture.anisotropy = 16;
  9972. //
  9973. // See #14839
  9974. Texture.call(this, null);
  9975. this.image = {
  9976. data: data || null,
  9977. width: width || 1,
  9978. height: height || 1,
  9979. depth: depth || 1
  9980. };
  9981. this.magFilter = NearestFilter;
  9982. this.minFilter = NearestFilter;
  9983. this.wrapR = ClampToEdgeWrapping;
  9984. this.generateMipmaps = false;
  9985. this.flipY = false;
  9986. this.needsUpdate = true;
  9987. }
  9988. DataTexture3D.prototype = Object.create(Texture.prototype);
  9989. DataTexture3D.prototype.constructor = DataTexture3D;
  9990. DataTexture3D.prototype.isDataTexture3D = true;
  9991. /**
  9992. * Uniforms of a program.
  9993. * Those form a tree structure with a special top-level container for the root,
  9994. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9995. *
  9996. *
  9997. * Properties of inner nodes including the top-level container:
  9998. *
  9999. * .seq - array of nested uniforms
  10000. * .map - nested uniforms by name
  10001. *
  10002. *
  10003. * Methods of all nodes except the top-level container:
  10004. *
  10005. * .setValue( gl, value, [textures] )
  10006. *
  10007. * uploads a uniform value(s)
  10008. * the 'textures' parameter is needed for sampler uniforms
  10009. *
  10010. *
  10011. * Static methods of the top-level container (textures factorizations):
  10012. *
  10013. * .upload( gl, seq, values, textures )
  10014. *
  10015. * sets uniforms in 'seq' to 'values[id].value'
  10016. *
  10017. * .seqWithValue( seq, values ) : filteredSeq
  10018. *
  10019. * filters 'seq' entries with corresponding entry in values
  10020. *
  10021. *
  10022. * Methods of the top-level container (textures factorizations):
  10023. *
  10024. * .setValue( gl, name, value, textures )
  10025. *
  10026. * sets uniform with name 'name' to 'value'
  10027. *
  10028. * .setOptional( gl, obj, prop )
  10029. *
  10030. * like .set for an optional property of the object
  10031. *
  10032. */
  10033. var emptyTexture = new Texture();
  10034. var emptyTexture2dArray = new DataTexture2DArray();
  10035. var emptyTexture3d = new DataTexture3D();
  10036. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10037. // Array Caches (provide typed arrays for temporary by size)
  10038. var arrayCacheF32 = [];
  10039. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10040. var mat4array = new Float32Array(16);
  10041. var mat3array = new Float32Array(9);
  10042. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10043. function flatten(array, nBlocks, blockSize) {
  10044. var firstElem = array[0];
  10045. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10046. // see http://jacksondunstan.com/articles/983
  10047. var n = nBlocks * blockSize;
  10048. var r = arrayCacheF32[n];
  10049. if (r === undefined) {
  10050. r = new Float32Array(n);
  10051. arrayCacheF32[n] = r;
  10052. }
  10053. if (nBlocks !== 0) {
  10054. firstElem.toArray(r, 0);
  10055. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10056. offset += blockSize;
  10057. array[i].toArray(r, offset);
  10058. }
  10059. }
  10060. return r;
  10061. }
  10062. function arraysEqual(a, b) {
  10063. if (a.length !== b.length) return false;
  10064. for (var i = 0, l = a.length; i < l; i++) {
  10065. if (a[i] !== b[i]) return false;
  10066. }
  10067. return true;
  10068. }
  10069. function copyArray(a, b) {
  10070. for (var i = 0, l = b.length; i < l; i++) {
  10071. a[i] = b[i];
  10072. }
  10073. } // Texture unit allocation
  10074. function allocTexUnits(textures, n) {
  10075. var r = arrayCacheI32[n];
  10076. if (r === undefined) {
  10077. r = new Int32Array(n);
  10078. arrayCacheI32[n] = r;
  10079. }
  10080. for (var i = 0; i !== n; ++i) {
  10081. r[i] = textures.allocateTextureUnit();
  10082. }
  10083. return r;
  10084. } // --- Setters ---
  10085. // Note: Defining these methods externally, because they come in a bunch
  10086. // and this way their names minify.
  10087. // Single scalar
  10088. function setValueV1f(gl, v) {
  10089. var cache = this.cache;
  10090. if (cache[0] === v) return;
  10091. gl.uniform1f(this.addr, v);
  10092. cache[0] = v;
  10093. } // Single float vector (from flat array or THREE.VectorN)
  10094. function setValueV2f(gl, v) {
  10095. var cache = this.cache;
  10096. if (v.x !== undefined) {
  10097. if (cache[0] !== v.x || cache[1] !== v.y) {
  10098. gl.uniform2f(this.addr, v.x, v.y);
  10099. cache[0] = v.x;
  10100. cache[1] = v.y;
  10101. }
  10102. } else {
  10103. if (arraysEqual(cache, v)) return;
  10104. gl.uniform2fv(this.addr, v);
  10105. copyArray(cache, v);
  10106. }
  10107. }
  10108. function setValueV3f(gl, v) {
  10109. var cache = this.cache;
  10110. if (v.x !== undefined) {
  10111. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10112. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10113. cache[0] = v.x;
  10114. cache[1] = v.y;
  10115. cache[2] = v.z;
  10116. }
  10117. } else if (v.r !== undefined) {
  10118. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10119. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10120. cache[0] = v.r;
  10121. cache[1] = v.g;
  10122. cache[2] = v.b;
  10123. }
  10124. } else {
  10125. if (arraysEqual(cache, v)) return;
  10126. gl.uniform3fv(this.addr, v);
  10127. copyArray(cache, v);
  10128. }
  10129. }
  10130. function setValueV4f(gl, v) {
  10131. var cache = this.cache;
  10132. if (v.x !== undefined) {
  10133. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10134. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10135. cache[0] = v.x;
  10136. cache[1] = v.y;
  10137. cache[2] = v.z;
  10138. cache[3] = v.w;
  10139. }
  10140. } else {
  10141. if (arraysEqual(cache, v)) return;
  10142. gl.uniform4fv(this.addr, v);
  10143. copyArray(cache, v);
  10144. }
  10145. } // Single matrix (from flat array or MatrixN)
  10146. function setValueM2(gl, v) {
  10147. var cache = this.cache;
  10148. var elements = v.elements;
  10149. if (elements === undefined) {
  10150. if (arraysEqual(cache, v)) return;
  10151. gl.uniformMatrix2fv(this.addr, false, v);
  10152. copyArray(cache, v);
  10153. } else {
  10154. if (arraysEqual(cache, elements)) return;
  10155. mat2array.set(elements);
  10156. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10157. copyArray(cache, elements);
  10158. }
  10159. }
  10160. function setValueM3(gl, v) {
  10161. var cache = this.cache;
  10162. var elements = v.elements;
  10163. if (elements === undefined) {
  10164. if (arraysEqual(cache, v)) return;
  10165. gl.uniformMatrix3fv(this.addr, false, v);
  10166. copyArray(cache, v);
  10167. } else {
  10168. if (arraysEqual(cache, elements)) return;
  10169. mat3array.set(elements);
  10170. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10171. copyArray(cache, elements);
  10172. }
  10173. }
  10174. function setValueM4(gl, v) {
  10175. var cache = this.cache;
  10176. var elements = v.elements;
  10177. if (elements === undefined) {
  10178. if (arraysEqual(cache, v)) return;
  10179. gl.uniformMatrix4fv(this.addr, false, v);
  10180. copyArray(cache, v);
  10181. } else {
  10182. if (arraysEqual(cache, elements)) return;
  10183. mat4array.set(elements);
  10184. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10185. copyArray(cache, elements);
  10186. }
  10187. } // Single texture (2D / Cube)
  10188. function setValueT1(gl, v, textures) {
  10189. var cache = this.cache;
  10190. var unit = textures.allocateTextureUnit();
  10191. if (cache[0] !== unit) {
  10192. gl.uniform1i(this.addr, unit);
  10193. cache[0] = unit;
  10194. }
  10195. textures.safeSetTexture2D(v || emptyTexture, unit);
  10196. }
  10197. function setValueT2DArray1(gl, v, textures) {
  10198. var cache = this.cache;
  10199. var unit = textures.allocateTextureUnit();
  10200. if (cache[0] !== unit) {
  10201. gl.uniform1i(this.addr, unit);
  10202. cache[0] = unit;
  10203. }
  10204. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10205. }
  10206. function setValueT3D1(gl, v, textures) {
  10207. var cache = this.cache;
  10208. var unit = textures.allocateTextureUnit();
  10209. if (cache[0] !== unit) {
  10210. gl.uniform1i(this.addr, unit);
  10211. cache[0] = unit;
  10212. }
  10213. textures.setTexture3D(v || emptyTexture3d, unit);
  10214. }
  10215. function setValueT6(gl, v, textures) {
  10216. var cache = this.cache;
  10217. var unit = textures.allocateTextureUnit();
  10218. if (cache[0] !== unit) {
  10219. gl.uniform1i(this.addr, unit);
  10220. cache[0] = unit;
  10221. }
  10222. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10223. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10224. function setValueV1i(gl, v) {
  10225. var cache = this.cache;
  10226. if (cache[0] === v) return;
  10227. gl.uniform1i(this.addr, v);
  10228. cache[0] = v;
  10229. }
  10230. function setValueV2i(gl, v) {
  10231. var cache = this.cache;
  10232. if (arraysEqual(cache, v)) return;
  10233. gl.uniform2iv(this.addr, v);
  10234. copyArray(cache, v);
  10235. }
  10236. function setValueV3i(gl, v) {
  10237. var cache = this.cache;
  10238. if (arraysEqual(cache, v)) return;
  10239. gl.uniform3iv(this.addr, v);
  10240. copyArray(cache, v);
  10241. }
  10242. function setValueV4i(gl, v) {
  10243. var cache = this.cache;
  10244. if (arraysEqual(cache, v)) return;
  10245. gl.uniform4iv(this.addr, v);
  10246. copyArray(cache, v);
  10247. } // uint
  10248. function setValueV1ui(gl, v) {
  10249. var cache = this.cache;
  10250. if (cache[0] === v) return;
  10251. gl.uniform1ui(this.addr, v);
  10252. cache[0] = v;
  10253. } // Helper to pick the right setter for the singular case
  10254. function getSingularSetter(type) {
  10255. switch (type) {
  10256. case 0x1406:
  10257. return setValueV1f;
  10258. // FLOAT
  10259. case 0x8b50:
  10260. return setValueV2f;
  10261. // _VEC2
  10262. case 0x8b51:
  10263. return setValueV3f;
  10264. // _VEC3
  10265. case 0x8b52:
  10266. return setValueV4f;
  10267. // _VEC4
  10268. case 0x8b5a:
  10269. return setValueM2;
  10270. // _MAT2
  10271. case 0x8b5b:
  10272. return setValueM3;
  10273. // _MAT3
  10274. case 0x8b5c:
  10275. return setValueM4;
  10276. // _MAT4
  10277. case 0x1404:
  10278. case 0x8b56:
  10279. return setValueV1i;
  10280. // INT, BOOL
  10281. case 0x8b53:
  10282. case 0x8b57:
  10283. return setValueV2i;
  10284. // _VEC2
  10285. case 0x8b54:
  10286. case 0x8b58:
  10287. return setValueV3i;
  10288. // _VEC3
  10289. case 0x8b55:
  10290. case 0x8b59:
  10291. return setValueV4i;
  10292. // _VEC4
  10293. case 0x1405:
  10294. return setValueV1ui;
  10295. // UINT
  10296. case 0x8b5e: // SAMPLER_2D
  10297. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10298. case 0x8dca: // INT_SAMPLER_2D
  10299. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10300. case 0x8b62:
  10301. // SAMPLER_2D_SHADOW
  10302. return setValueT1;
  10303. case 0x8b5f: // SAMPLER_3D
  10304. case 0x8dcb: // INT_SAMPLER_3D
  10305. case 0x8dd3:
  10306. // UNSIGNED_INT_SAMPLER_3D
  10307. return setValueT3D1;
  10308. case 0x8b60: // SAMPLER_CUBE
  10309. case 0x8dcc: // INT_SAMPLER_CUBE
  10310. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10311. case 0x8dc5:
  10312. // SAMPLER_CUBE_SHADOW
  10313. return setValueT6;
  10314. case 0x8dc1: // SAMPLER_2D_ARRAY
  10315. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10316. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10317. case 0x8dc4:
  10318. // SAMPLER_2D_ARRAY_SHADOW
  10319. return setValueT2DArray1;
  10320. }
  10321. } // Array of scalars
  10322. function setValueV1fArray(gl, v) {
  10323. gl.uniform1fv(this.addr, v);
  10324. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10325. function setValueV1iArray(gl, v) {
  10326. gl.uniform1iv(this.addr, v);
  10327. }
  10328. function setValueV2iArray(gl, v) {
  10329. gl.uniform2iv(this.addr, v);
  10330. }
  10331. function setValueV3iArray(gl, v) {
  10332. gl.uniform3iv(this.addr, v);
  10333. }
  10334. function setValueV4iArray(gl, v) {
  10335. gl.uniform4iv(this.addr, v);
  10336. } // Array of vectors (flat or from THREE classes)
  10337. function setValueV2fArray(gl, v) {
  10338. var data = flatten(v, this.size, 2);
  10339. gl.uniform2fv(this.addr, data);
  10340. }
  10341. function setValueV3fArray(gl, v) {
  10342. var data = flatten(v, this.size, 3);
  10343. gl.uniform3fv(this.addr, data);
  10344. }
  10345. function setValueV4fArray(gl, v) {
  10346. var data = flatten(v, this.size, 4);
  10347. gl.uniform4fv(this.addr, data);
  10348. } // Array of matrices (flat or from THREE clases)
  10349. function setValueM2Array(gl, v) {
  10350. var data = flatten(v, this.size, 4);
  10351. gl.uniformMatrix2fv(this.addr, false, data);
  10352. }
  10353. function setValueM3Array(gl, v) {
  10354. var data = flatten(v, this.size, 9);
  10355. gl.uniformMatrix3fv(this.addr, false, data);
  10356. }
  10357. function setValueM4Array(gl, v) {
  10358. var data = flatten(v, this.size, 16);
  10359. gl.uniformMatrix4fv(this.addr, false, data);
  10360. } // Array of textures (2D / Cube)
  10361. function setValueT1Array(gl, v, textures) {
  10362. var n = v.length;
  10363. var units = allocTexUnits(textures, n);
  10364. gl.uniform1iv(this.addr, units);
  10365. for (var i = 0; i !== n; ++i) {
  10366. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10367. }
  10368. }
  10369. function setValueT6Array(gl, v, textures) {
  10370. var n = v.length;
  10371. var units = allocTexUnits(textures, n);
  10372. gl.uniform1iv(this.addr, units);
  10373. for (var i = 0; i !== n; ++i) {
  10374. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10375. }
  10376. } // Helper to pick the right setter for a pure (bottom-level) array
  10377. function getPureArraySetter(type) {
  10378. switch (type) {
  10379. case 0x1406:
  10380. return setValueV1fArray;
  10381. // FLOAT
  10382. case 0x8b50:
  10383. return setValueV2fArray;
  10384. // _VEC2
  10385. case 0x8b51:
  10386. return setValueV3fArray;
  10387. // _VEC3
  10388. case 0x8b52:
  10389. return setValueV4fArray;
  10390. // _VEC4
  10391. case 0x8b5a:
  10392. return setValueM2Array;
  10393. // _MAT2
  10394. case 0x8b5b:
  10395. return setValueM3Array;
  10396. // _MAT3
  10397. case 0x8b5c:
  10398. return setValueM4Array;
  10399. // _MAT4
  10400. case 0x1404:
  10401. case 0x8b56:
  10402. return setValueV1iArray;
  10403. // INT, BOOL
  10404. case 0x8b53:
  10405. case 0x8b57:
  10406. return setValueV2iArray;
  10407. // _VEC2
  10408. case 0x8b54:
  10409. case 0x8b58:
  10410. return setValueV3iArray;
  10411. // _VEC3
  10412. case 0x8b55:
  10413. case 0x8b59:
  10414. return setValueV4iArray;
  10415. // _VEC4
  10416. case 0x8b5e: // SAMPLER_2D
  10417. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10418. case 0x8dca: // INT_SAMPLER_2D
  10419. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10420. case 0x8b62:
  10421. // SAMPLER_2D_SHADOW
  10422. return setValueT1Array;
  10423. case 0x8b60: // SAMPLER_CUBE
  10424. case 0x8dcc: // INT_SAMPLER_CUBE
  10425. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10426. case 0x8dc5:
  10427. // SAMPLER_CUBE_SHADOW
  10428. return setValueT6Array;
  10429. }
  10430. } // --- Uniform Classes ---
  10431. function SingleUniform(id, activeInfo, addr) {
  10432. this.id = id;
  10433. this.addr = addr;
  10434. this.cache = [];
  10435. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10436. }
  10437. function PureArrayUniform(id, activeInfo, addr) {
  10438. this.id = id;
  10439. this.addr = addr;
  10440. this.cache = [];
  10441. this.size = activeInfo.size;
  10442. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10443. }
  10444. PureArrayUniform.prototype.updateCache = function (data) {
  10445. var cache = this.cache;
  10446. if (data instanceof Float32Array && cache.length !== data.length) {
  10447. this.cache = new Float32Array(data.length);
  10448. }
  10449. copyArray(cache, data);
  10450. };
  10451. function StructuredUniform(id) {
  10452. this.id = id;
  10453. this.seq = [];
  10454. this.map = {};
  10455. }
  10456. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10457. var seq = this.seq;
  10458. for (var i = 0, n = seq.length; i !== n; ++i) {
  10459. var u = seq[i];
  10460. u.setValue(gl, value[u.id], textures);
  10461. }
  10462. }; // --- Top-level ---
  10463. // Parser - builds up the property tree from the path strings
  10464. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; // extracts
  10465. // - the identifier (member name or array index)
  10466. // - followed by an optional right bracket (found when array index)
  10467. // - followed by an optional left bracket or dot (type of subscript)
  10468. //
  10469. // Note: These portions can be read in a non-overlapping fashion and
  10470. // allow straightforward parsing of the hierarchy that WebGL encodes
  10471. // in the uniform names.
  10472. function addUniform(container, uniformObject) {
  10473. container.seq.push(uniformObject);
  10474. container.map[uniformObject.id] = uniformObject;
  10475. }
  10476. function parseUniform(activeInfo, addr, container) {
  10477. var path = activeInfo.name,
  10478. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10479. RePathPart.lastIndex = 0;
  10480. while (true) {
  10481. var match = RePathPart.exec(path),
  10482. matchEnd = RePathPart.lastIndex;
  10483. var id = match[1];
  10484. var idIsIndex = match[2] === ']',
  10485. subscript = match[3];
  10486. if (idIsIndex) id = id | 0; // convert to integer
  10487. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10488. // bare name or "pure" bottom-level array "[0]" suffix
  10489. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10490. break;
  10491. } else {
  10492. // step into inner node / create it in case it doesn't exist
  10493. var map = container.map;
  10494. var next = map[id];
  10495. if (next === undefined) {
  10496. next = new StructuredUniform(id);
  10497. addUniform(container, next);
  10498. }
  10499. container = next;
  10500. }
  10501. }
  10502. } // Root Container
  10503. function WebGLUniforms(gl, program) {
  10504. this.seq = [];
  10505. this.map = {};
  10506. var n = gl.getProgramParameter(program, 35718);
  10507. for (var i = 0; i < n; ++i) {
  10508. var info = gl.getActiveUniform(program, i),
  10509. addr = gl.getUniformLocation(program, info.name);
  10510. parseUniform(info, addr, this);
  10511. }
  10512. }
  10513. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10514. var u = this.map[name];
  10515. if (u !== undefined) u.setValue(gl, value, textures);
  10516. };
  10517. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10518. var v = object[name];
  10519. if (v !== undefined) this.setValue(gl, name, v);
  10520. }; // Static interface
  10521. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10522. for (var i = 0, n = seq.length; i !== n; ++i) {
  10523. var u = seq[i],
  10524. v = values[u.id];
  10525. if (v.needsUpdate !== false) {
  10526. // note: always updating when .needsUpdate is undefined
  10527. u.setValue(gl, v.value, textures);
  10528. }
  10529. }
  10530. };
  10531. WebGLUniforms.seqWithValue = function (seq, values) {
  10532. var r = [];
  10533. for (var i = 0, n = seq.length; i !== n; ++i) {
  10534. var u = seq[i];
  10535. if (u.id in values) r.push(u);
  10536. }
  10537. return r;
  10538. };
  10539. function WebGLShader(gl, type, string) {
  10540. var shader = gl.createShader(type);
  10541. gl.shaderSource(shader, string);
  10542. gl.compileShader(shader);
  10543. return shader;
  10544. }
  10545. var programIdCount = 0;
  10546. function addLineNumbers(string) {
  10547. var lines = string.split('\n');
  10548. for (var i = 0; i < lines.length; i++) {
  10549. lines[i] = i + 1 + ': ' + lines[i];
  10550. }
  10551. return lines.join('\n');
  10552. }
  10553. function getEncodingComponents(encoding) {
  10554. switch (encoding) {
  10555. case LinearEncoding:
  10556. return ['Linear', '( value )'];
  10557. case sRGBEncoding:
  10558. return ['sRGB', '( value )'];
  10559. case RGBEEncoding:
  10560. return ['RGBE', '( value )'];
  10561. case RGBM7Encoding:
  10562. return ['RGBM', '( value, 7.0 )'];
  10563. case RGBM16Encoding:
  10564. return ['RGBM', '( value, 16.0 )'];
  10565. case RGBDEncoding:
  10566. return ['RGBD', '( value, 256.0 )'];
  10567. case GammaEncoding:
  10568. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10569. case LogLuvEncoding:
  10570. return ['LogLuv', '( value )'];
  10571. default:
  10572. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10573. return ['Linear', '( value )'];
  10574. }
  10575. }
  10576. function getShaderErrors(gl, shader, type) {
  10577. var status = gl.getShaderParameter(shader, 35713);
  10578. var log = gl.getShaderInfoLog(shader).trim();
  10579. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10580. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10581. var source = gl.getShaderSource(shader);
  10582. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10583. }
  10584. function getTexelDecodingFunction(functionName, encoding) {
  10585. var components = getEncodingComponents(encoding);
  10586. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10587. }
  10588. function getTexelEncodingFunction(functionName, encoding) {
  10589. var components = getEncodingComponents(encoding);
  10590. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10591. }
  10592. function getToneMappingFunction(functionName, toneMapping) {
  10593. var toneMappingName;
  10594. switch (toneMapping) {
  10595. case LinearToneMapping:
  10596. toneMappingName = 'Linear';
  10597. break;
  10598. case ReinhardToneMapping:
  10599. toneMappingName = 'Reinhard';
  10600. break;
  10601. case CineonToneMapping:
  10602. toneMappingName = 'OptimizedCineon';
  10603. break;
  10604. case ACESFilmicToneMapping:
  10605. toneMappingName = 'ACESFilmic';
  10606. break;
  10607. case CustomToneMapping:
  10608. toneMappingName = 'Custom';
  10609. break;
  10610. default:
  10611. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10612. toneMappingName = 'Linear';
  10613. }
  10614. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10615. }
  10616. function generateExtensions(parameters) {
  10617. 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' : ''];
  10618. return chunks.filter(filterEmptyLine).join('\n');
  10619. }
  10620. function generateDefines(defines) {
  10621. var chunks = [];
  10622. for (var name in defines) {
  10623. var value = defines[name];
  10624. if (value === false) continue;
  10625. chunks.push('#define ' + name + ' ' + value);
  10626. }
  10627. return chunks.join('\n');
  10628. }
  10629. function fetchAttributeLocations(gl, program) {
  10630. var attributes = {};
  10631. var n = gl.getProgramParameter(program, 35721);
  10632. for (var i = 0; i < n; i++) {
  10633. var info = gl.getActiveAttrib(program, i);
  10634. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10635. attributes[name] = gl.getAttribLocation(program, name);
  10636. }
  10637. return attributes;
  10638. }
  10639. function filterEmptyLine(string) {
  10640. return string !== '';
  10641. }
  10642. function replaceLightNums(string, parameters) {
  10643. 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);
  10644. }
  10645. function replaceClippingPlaneNums(string, parameters) {
  10646. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10647. } // Resolve Includes
  10648. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10649. function resolveIncludes(string) {
  10650. return string.replace(includePattern, includeReplacer);
  10651. }
  10652. function includeReplacer(match, include) {
  10653. var string = ShaderChunk[include];
  10654. if (string === undefined) {
  10655. throw new Error('Can not resolve #include <' + include + '>');
  10656. }
  10657. return resolveIncludes(string);
  10658. } // Unroll Loops
  10659. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10660. 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;
  10661. function unrollLoops(string) {
  10662. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10663. }
  10664. function deprecatedLoopReplacer(match, start, end, snippet) {
  10665. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10666. return loopReplacer(match, start, end, snippet);
  10667. }
  10668. function loopReplacer(match, start, end, snippet) {
  10669. var string = '';
  10670. for (var i = parseInt(start); i < parseInt(end); i++) {
  10671. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10672. }
  10673. return string;
  10674. } //
  10675. function generatePrecision(parameters) {
  10676. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  10677. if (parameters.precision === "highp") {
  10678. precisionstring += "\n#define HIGH_PRECISION";
  10679. } else if (parameters.precision === "mediump") {
  10680. precisionstring += "\n#define MEDIUM_PRECISION";
  10681. } else if (parameters.precision === "lowp") {
  10682. precisionstring += "\n#define LOW_PRECISION";
  10683. }
  10684. return precisionstring;
  10685. }
  10686. function generateShadowMapTypeDefine(parameters) {
  10687. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10688. if (parameters.shadowMapType === PCFShadowMap) {
  10689. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10690. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10691. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10692. } else if (parameters.shadowMapType === VSMShadowMap) {
  10693. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10694. }
  10695. return shadowMapTypeDefine;
  10696. }
  10697. function generateEnvMapTypeDefine(parameters) {
  10698. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10699. if (parameters.envMap) {
  10700. switch (parameters.envMapMode) {
  10701. case CubeReflectionMapping:
  10702. case CubeRefractionMapping:
  10703. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10704. break;
  10705. case CubeUVReflectionMapping:
  10706. case CubeUVRefractionMapping:
  10707. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10708. break;
  10709. }
  10710. }
  10711. return envMapTypeDefine;
  10712. }
  10713. function generateEnvMapModeDefine(parameters) {
  10714. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10715. if (parameters.envMap) {
  10716. switch (parameters.envMapMode) {
  10717. case CubeRefractionMapping:
  10718. case CubeUVRefractionMapping:
  10719. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10720. break;
  10721. }
  10722. }
  10723. return envMapModeDefine;
  10724. }
  10725. function generateEnvMapBlendingDefine(parameters) {
  10726. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10727. if (parameters.envMap) {
  10728. switch (parameters.combine) {
  10729. case MultiplyOperation:
  10730. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10731. break;
  10732. case MixOperation:
  10733. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10734. break;
  10735. case AddOperation:
  10736. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10737. break;
  10738. }
  10739. }
  10740. return envMapBlendingDefine;
  10741. }
  10742. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10743. var gl = renderer.getContext();
  10744. var defines = parameters.defines;
  10745. var vertexShader = parameters.vertexShader;
  10746. var fragmentShader = parameters.fragmentShader;
  10747. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10748. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10749. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10750. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10751. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10752. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10753. var customDefines = generateDefines(defines);
  10754. var program = gl.createProgram();
  10755. var prefixVertex, prefixFragment;
  10756. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + "\n" : '';
  10757. if (parameters.isRawShaderMaterial) {
  10758. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10759. if (prefixVertex.length > 0) {
  10760. prefixVertex += '\n';
  10761. }
  10762. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10763. if (prefixFragment.length > 0) {
  10764. prefixFragment += '\n';
  10765. }
  10766. } else {
  10767. 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');
  10768. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10769. '#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
  10770. 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
  10771. 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');
  10772. }
  10773. vertexShader = resolveIncludes(vertexShader);
  10774. vertexShader = replaceLightNums(vertexShader, parameters);
  10775. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10776. fragmentShader = resolveIncludes(fragmentShader);
  10777. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10778. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10779. vertexShader = unrollLoops(vertexShader);
  10780. fragmentShader = unrollLoops(fragmentShader);
  10781. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10782. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10783. versionString = '#version 300 es\n';
  10784. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10785. 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;
  10786. }
  10787. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10788. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10789. // console.log( '*FRAGMENT*', fragmentGlsl );
  10790. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10791. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10792. gl.attachShader(program, glVertexShader);
  10793. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10794. if (parameters.index0AttributeName !== undefined) {
  10795. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10796. } else if (parameters.morphTargets === true) {
  10797. // programs with morphTargets displace position out of attribute 0
  10798. gl.bindAttribLocation(program, 0, 'position');
  10799. }
  10800. gl.linkProgram(program); // check for link errors
  10801. if (renderer.debug.checkShaderErrors) {
  10802. var programLog = gl.getProgramInfoLog(program).trim();
  10803. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10804. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10805. var runnable = true;
  10806. var haveDiagnostics = true;
  10807. if (gl.getProgramParameter(program, 35714) === false) {
  10808. runnable = false;
  10809. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10810. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10811. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10812. } else if (programLog !== '') {
  10813. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10814. } else if (vertexLog === '' || fragmentLog === '') {
  10815. haveDiagnostics = false;
  10816. }
  10817. if (haveDiagnostics) {
  10818. this.diagnostics = {
  10819. runnable: runnable,
  10820. programLog: programLog,
  10821. vertexShader: {
  10822. log: vertexLog,
  10823. prefix: prefixVertex
  10824. },
  10825. fragmentShader: {
  10826. log: fragmentLog,
  10827. prefix: prefixFragment
  10828. }
  10829. };
  10830. }
  10831. } // Clean up
  10832. // Crashes in iOS9 and iOS10. #18402
  10833. // gl.detachShader( program, glVertexShader );
  10834. // gl.detachShader( program, glFragmentShader );
  10835. gl.deleteShader(glVertexShader);
  10836. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  10837. var cachedUniforms;
  10838. this.getUniforms = function () {
  10839. if (cachedUniforms === undefined) {
  10840. cachedUniforms = new WebGLUniforms(gl, program);
  10841. }
  10842. return cachedUniforms;
  10843. }; // set up caching for attribute locations
  10844. var cachedAttributes;
  10845. this.getAttributes = function () {
  10846. if (cachedAttributes === undefined) {
  10847. cachedAttributes = fetchAttributeLocations(gl, program);
  10848. }
  10849. return cachedAttributes;
  10850. }; // free resource
  10851. this.destroy = function () {
  10852. bindingStates.releaseStatesOfProgram(this);
  10853. gl.deleteProgram(program);
  10854. this.program = undefined;
  10855. }; //
  10856. this.name = parameters.shaderName;
  10857. this.id = programIdCount++;
  10858. this.cacheKey = cacheKey;
  10859. this.usedTimes = 1;
  10860. this.program = program;
  10861. this.vertexShader = glVertexShader;
  10862. this.fragmentShader = glFragmentShader;
  10863. return this;
  10864. }
  10865. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  10866. var programs = [];
  10867. var isWebGL2 = capabilities.isWebGL2;
  10868. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10869. var floatVertexTextures = capabilities.floatVertexTextures;
  10870. var maxVertexUniforms = capabilities.maxVertexUniforms;
  10871. var vertexTextures = capabilities.vertexTextures;
  10872. var precision = capabilities.precision;
  10873. var shaderIDs = {
  10874. MeshDepthMaterial: 'depth',
  10875. MeshDistanceMaterial: 'distanceRGBA',
  10876. MeshNormalMaterial: 'normal',
  10877. MeshBasicMaterial: 'basic',
  10878. MeshLambertMaterial: 'lambert',
  10879. MeshPhongMaterial: 'phong',
  10880. MeshToonMaterial: 'toon',
  10881. MeshStandardMaterial: 'physical',
  10882. MeshPhysicalMaterial: 'physical',
  10883. MeshMatcapMaterial: 'matcap',
  10884. LineBasicMaterial: 'basic',
  10885. LineDashedMaterial: 'dashed',
  10886. PointsMaterial: 'points',
  10887. ShadowMaterial: 'shadow',
  10888. SpriteMaterial: 'sprite'
  10889. };
  10890. 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"];
  10891. function getMaxBones(object) {
  10892. var skeleton = object.skeleton;
  10893. var bones = skeleton.bones;
  10894. if (floatVertexTextures) {
  10895. return 1024;
  10896. } else {
  10897. // default for when object is not specified
  10898. // ( for example when prebuilding shader to be used with multiple objects )
  10899. //
  10900. // - leave some extra space for other uniforms
  10901. // - limit here is ANGLE's 254 max uniform vectors
  10902. // (up to 54 should be safe)
  10903. var nVertexUniforms = maxVertexUniforms;
  10904. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  10905. var maxBones = Math.min(nVertexMatrices, bones.length);
  10906. if (maxBones < bones.length) {
  10907. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  10908. return 0;
  10909. }
  10910. return maxBones;
  10911. }
  10912. }
  10913. function getTextureEncodingFromMap(map) {
  10914. var encoding;
  10915. if (!map) {
  10916. encoding = LinearEncoding;
  10917. } else if (map.isTexture) {
  10918. encoding = map.encoding;
  10919. } else if (map.isWebGLRenderTarget) {
  10920. console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
  10921. encoding = map.texture.encoding;
  10922. }
  10923. return encoding;
  10924. }
  10925. function getParameters(material, lights, shadows, scene, object) {
  10926. var fog = scene.fog;
  10927. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  10928. var envMap = cubemaps.get(material.envMap || environment);
  10929. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  10930. // (not to blow over maxLights budget)
  10931. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  10932. if (material.precision !== null) {
  10933. precision = capabilities.getMaxPrecision(material.precision);
  10934. if (precision !== material.precision) {
  10935. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  10936. }
  10937. }
  10938. var vertexShader, fragmentShader;
  10939. if (shaderID) {
  10940. var shader = ShaderLib[shaderID];
  10941. vertexShader = shader.vertexShader;
  10942. fragmentShader = shader.fragmentShader;
  10943. } else {
  10944. vertexShader = material.vertexShader;
  10945. fragmentShader = material.fragmentShader;
  10946. }
  10947. var currentRenderTarget = renderer.getRenderTarget();
  10948. var parameters = {
  10949. isWebGL2: isWebGL2,
  10950. shaderID: shaderID,
  10951. shaderName: material.type,
  10952. vertexShader: vertexShader,
  10953. fragmentShader: fragmentShader,
  10954. defines: material.defines,
  10955. isRawShaderMaterial: material.isRawShaderMaterial === true,
  10956. glslVersion: material.glslVersion,
  10957. precision: precision,
  10958. instancing: object.isInstancedMesh === true,
  10959. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  10960. supportsVertexTextures: vertexTextures,
  10961. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  10962. map: !!material.map,
  10963. mapEncoding: getTextureEncodingFromMap(material.map),
  10964. matcap: !!material.matcap,
  10965. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  10966. envMap: !!envMap,
  10967. envMapMode: envMap && envMap.mapping,
  10968. envMapEncoding: getTextureEncodingFromMap(envMap),
  10969. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  10970. lightMap: !!material.lightMap,
  10971. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  10972. aoMap: !!material.aoMap,
  10973. emissiveMap: !!material.emissiveMap,
  10974. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  10975. bumpMap: !!material.bumpMap,
  10976. normalMap: !!material.normalMap,
  10977. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10978. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  10979. clearcoatMap: !!material.clearcoatMap,
  10980. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  10981. clearcoatNormalMap: !!material.clearcoatNormalMap,
  10982. displacementMap: !!material.displacementMap,
  10983. roughnessMap: !!material.roughnessMap,
  10984. metalnessMap: !!material.metalnessMap,
  10985. specularMap: !!material.specularMap,
  10986. alphaMap: !!material.alphaMap,
  10987. gradientMap: !!material.gradientMap,
  10988. sheen: !!material.sheen,
  10989. transmissionMap: !!material.transmissionMap,
  10990. combine: material.combine,
  10991. vertexTangents: material.normalMap && material.vertexTangents,
  10992. vertexColors: material.vertexColors,
  10993. 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,
  10994. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  10995. fog: !!fog,
  10996. useFog: material.fog,
  10997. fogExp2: fog && fog.isFogExp2,
  10998. flatShading: material.flatShading,
  10999. sizeAttenuation: material.sizeAttenuation,
  11000. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11001. skinning: material.skinning && maxBones > 0,
  11002. maxBones: maxBones,
  11003. useVertexTexture: floatVertexTextures,
  11004. morphTargets: material.morphTargets,
  11005. morphNormals: material.morphNormals,
  11006. maxMorphTargets: renderer.maxMorphTargets,
  11007. maxMorphNormals: renderer.maxMorphNormals,
  11008. numDirLights: lights.directional.length,
  11009. numPointLights: lights.point.length,
  11010. numSpotLights: lights.spot.length,
  11011. numRectAreaLights: lights.rectArea.length,
  11012. numHemiLights: lights.hemi.length,
  11013. numDirLightShadows: lights.directionalShadowMap.length,
  11014. numPointLightShadows: lights.pointShadowMap.length,
  11015. numSpotLightShadows: lights.spotShadowMap.length,
  11016. numClippingPlanes: clipping.numPlanes,
  11017. numClipIntersection: clipping.numIntersection,
  11018. dithering: material.dithering,
  11019. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11020. shadowMapType: renderer.shadowMap.type,
  11021. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11022. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11023. premultipliedAlpha: material.premultipliedAlpha,
  11024. alphaTest: material.alphaTest,
  11025. doubleSided: material.side === DoubleSide,
  11026. flipSided: material.side === BackSide,
  11027. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11028. index0AttributeName: material.index0AttributeName,
  11029. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11030. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11031. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11032. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11033. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11034. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11035. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11036. customProgramCacheKey: material.customProgramCacheKey()
  11037. };
  11038. return parameters;
  11039. }
  11040. function getProgramCacheKey(parameters) {
  11041. var array = [];
  11042. if (parameters.shaderID) {
  11043. array.push(parameters.shaderID);
  11044. } else {
  11045. array.push(parameters.fragmentShader);
  11046. array.push(parameters.vertexShader);
  11047. }
  11048. if (parameters.defines !== undefined) {
  11049. for (var name in parameters.defines) {
  11050. array.push(name);
  11051. array.push(parameters.defines[name]);
  11052. }
  11053. }
  11054. if (parameters.isRawShaderMaterial === false) {
  11055. for (var i = 0; i < parameterNames.length; i++) {
  11056. array.push(parameters[parameterNames[i]]);
  11057. }
  11058. array.push(renderer.outputEncoding);
  11059. array.push(renderer.gammaFactor);
  11060. }
  11061. array.push(parameters.customProgramCacheKey);
  11062. return array.join();
  11063. }
  11064. function getUniforms(material) {
  11065. var shaderID = shaderIDs[material.type];
  11066. var uniforms;
  11067. if (shaderID) {
  11068. var shader = ShaderLib[shaderID];
  11069. uniforms = UniformsUtils.clone(shader.uniforms);
  11070. } else {
  11071. uniforms = material.uniforms;
  11072. }
  11073. return uniforms;
  11074. }
  11075. function acquireProgram(parameters, cacheKey) {
  11076. var program; // Check if code has been already compiled
  11077. for (var p = 0, pl = programs.length; p < pl; p++) {
  11078. var preexistingProgram = programs[p];
  11079. if (preexistingProgram.cacheKey === cacheKey) {
  11080. program = preexistingProgram;
  11081. ++program.usedTimes;
  11082. break;
  11083. }
  11084. }
  11085. if (program === undefined) {
  11086. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11087. programs.push(program);
  11088. }
  11089. return program;
  11090. }
  11091. function releaseProgram(program) {
  11092. if (--program.usedTimes === 0) {
  11093. // Remove from unordered set
  11094. var i = programs.indexOf(program);
  11095. programs[i] = programs[programs.length - 1];
  11096. programs.pop(); // Free WebGL resources
  11097. program.destroy();
  11098. }
  11099. }
  11100. return {
  11101. getParameters: getParameters,
  11102. getProgramCacheKey: getProgramCacheKey,
  11103. getUniforms: getUniforms,
  11104. acquireProgram: acquireProgram,
  11105. releaseProgram: releaseProgram,
  11106. // Exposed for resource monitoring & error feedback via renderer.info:
  11107. programs: programs
  11108. };
  11109. }
  11110. function WebGLProperties() {
  11111. var properties = new WeakMap();
  11112. function get(object) {
  11113. var map = properties.get(object);
  11114. if (map === undefined) {
  11115. map = {};
  11116. properties.set(object, map);
  11117. }
  11118. return map;
  11119. }
  11120. function remove(object) {
  11121. properties.delete(object);
  11122. }
  11123. function update(object, key, value) {
  11124. properties.get(object)[key] = value;
  11125. }
  11126. function dispose() {
  11127. properties = new WeakMap();
  11128. }
  11129. return {
  11130. get: get,
  11131. remove: remove,
  11132. update: update,
  11133. dispose: dispose
  11134. };
  11135. }
  11136. function painterSortStable(a, b) {
  11137. if (a.groupOrder !== b.groupOrder) {
  11138. return a.groupOrder - b.groupOrder;
  11139. } else if (a.renderOrder !== b.renderOrder) {
  11140. return a.renderOrder - b.renderOrder;
  11141. } else if (a.program !== b.program) {
  11142. return a.program.id - b.program.id;
  11143. } else if (a.material.id !== b.material.id) {
  11144. return a.material.id - b.material.id;
  11145. } else if (a.z !== b.z) {
  11146. return a.z - b.z;
  11147. } else {
  11148. return a.id - b.id;
  11149. }
  11150. }
  11151. function reversePainterSortStable(a, b) {
  11152. if (a.groupOrder !== b.groupOrder) {
  11153. return a.groupOrder - b.groupOrder;
  11154. } else if (a.renderOrder !== b.renderOrder) {
  11155. return a.renderOrder - b.renderOrder;
  11156. } else if (a.z !== b.z) {
  11157. return b.z - a.z;
  11158. } else {
  11159. return a.id - b.id;
  11160. }
  11161. }
  11162. function WebGLRenderList(properties) {
  11163. var renderItems = [];
  11164. var renderItemsIndex = 0;
  11165. var opaque = [];
  11166. var transparent = [];
  11167. var defaultProgram = {
  11168. id: -1
  11169. };
  11170. function init() {
  11171. renderItemsIndex = 0;
  11172. opaque.length = 0;
  11173. transparent.length = 0;
  11174. }
  11175. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11176. var renderItem = renderItems[renderItemsIndex];
  11177. var materialProperties = properties.get(material);
  11178. if (renderItem === undefined) {
  11179. renderItem = {
  11180. id: object.id,
  11181. object: object,
  11182. geometry: geometry,
  11183. material: material,
  11184. program: materialProperties.program || defaultProgram,
  11185. groupOrder: groupOrder,
  11186. renderOrder: object.renderOrder,
  11187. z: z,
  11188. group: group
  11189. };
  11190. renderItems[renderItemsIndex] = renderItem;
  11191. } else {
  11192. renderItem.id = object.id;
  11193. renderItem.object = object;
  11194. renderItem.geometry = geometry;
  11195. renderItem.material = material;
  11196. renderItem.program = materialProperties.program || defaultProgram;
  11197. renderItem.groupOrder = groupOrder;
  11198. renderItem.renderOrder = object.renderOrder;
  11199. renderItem.z = z;
  11200. renderItem.group = group;
  11201. }
  11202. renderItemsIndex++;
  11203. return renderItem;
  11204. }
  11205. function push(object, geometry, material, groupOrder, z, group) {
  11206. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11207. (material.transparent === true ? transparent : opaque).push(renderItem);
  11208. }
  11209. function unshift(object, geometry, material, groupOrder, z, group) {
  11210. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11211. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11212. }
  11213. function sort(customOpaqueSort, customTransparentSort) {
  11214. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11215. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11216. }
  11217. function finish() {
  11218. // Clear references from inactive renderItems in the list
  11219. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11220. var renderItem = renderItems[i];
  11221. if (renderItem.id === null) break;
  11222. renderItem.id = null;
  11223. renderItem.object = null;
  11224. renderItem.geometry = null;
  11225. renderItem.material = null;
  11226. renderItem.program = null;
  11227. renderItem.group = null;
  11228. }
  11229. }
  11230. return {
  11231. opaque: opaque,
  11232. transparent: transparent,
  11233. init: init,
  11234. push: push,
  11235. unshift: unshift,
  11236. finish: finish,
  11237. sort: sort
  11238. };
  11239. }
  11240. function WebGLRenderLists(properties) {
  11241. var lists = new WeakMap();
  11242. function get(scene, camera) {
  11243. var cameras = lists.get(scene);
  11244. var list;
  11245. if (cameras === undefined) {
  11246. list = new WebGLRenderList(properties);
  11247. lists.set(scene, new WeakMap());
  11248. lists.get(scene).set(camera, list);
  11249. } else {
  11250. list = cameras.get(camera);
  11251. if (list === undefined) {
  11252. list = new WebGLRenderList(properties);
  11253. cameras.set(camera, list);
  11254. }
  11255. }
  11256. return list;
  11257. }
  11258. function dispose() {
  11259. lists = new WeakMap();
  11260. }
  11261. return {
  11262. get: get,
  11263. dispose: dispose
  11264. };
  11265. }
  11266. function UniformsCache() {
  11267. var lights = {};
  11268. return {
  11269. get: function get(light) {
  11270. if (lights[light.id] !== undefined) {
  11271. return lights[light.id];
  11272. }
  11273. var uniforms;
  11274. switch (light.type) {
  11275. case 'DirectionalLight':
  11276. uniforms = {
  11277. direction: new Vector3(),
  11278. color: new Color()
  11279. };
  11280. break;
  11281. case 'SpotLight':
  11282. uniforms = {
  11283. position: new Vector3(),
  11284. direction: new Vector3(),
  11285. color: new Color(),
  11286. distance: 0,
  11287. coneCos: 0,
  11288. penumbraCos: 0,
  11289. decay: 0
  11290. };
  11291. break;
  11292. case 'PointLight':
  11293. uniforms = {
  11294. position: new Vector3(),
  11295. color: new Color(),
  11296. distance: 0,
  11297. decay: 0
  11298. };
  11299. break;
  11300. case 'HemisphereLight':
  11301. uniforms = {
  11302. direction: new Vector3(),
  11303. skyColor: new Color(),
  11304. groundColor: new Color()
  11305. };
  11306. break;
  11307. case 'RectAreaLight':
  11308. uniforms = {
  11309. color: new Color(),
  11310. position: new Vector3(),
  11311. halfWidth: new Vector3(),
  11312. halfHeight: new Vector3()
  11313. };
  11314. break;
  11315. }
  11316. lights[light.id] = uniforms;
  11317. return uniforms;
  11318. }
  11319. };
  11320. }
  11321. function ShadowUniformsCache() {
  11322. var lights = {};
  11323. return {
  11324. get: function get(light) {
  11325. if (lights[light.id] !== undefined) {
  11326. return lights[light.id];
  11327. }
  11328. var uniforms;
  11329. switch (light.type) {
  11330. case 'DirectionalLight':
  11331. uniforms = {
  11332. shadowBias: 0,
  11333. shadowNormalBias: 0,
  11334. shadowRadius: 1,
  11335. shadowMapSize: new Vector2()
  11336. };
  11337. break;
  11338. case 'SpotLight':
  11339. uniforms = {
  11340. shadowBias: 0,
  11341. shadowNormalBias: 0,
  11342. shadowRadius: 1,
  11343. shadowMapSize: new Vector2()
  11344. };
  11345. break;
  11346. case 'PointLight':
  11347. uniforms = {
  11348. shadowBias: 0,
  11349. shadowNormalBias: 0,
  11350. shadowRadius: 1,
  11351. shadowMapSize: new Vector2(),
  11352. shadowCameraNear: 1,
  11353. shadowCameraFar: 1000
  11354. };
  11355. break;
  11356. // TODO (abelnation): set RectAreaLight shadow uniforms
  11357. }
  11358. lights[light.id] = uniforms;
  11359. return uniforms;
  11360. }
  11361. };
  11362. }
  11363. var nextVersion = 0;
  11364. function shadowCastingLightsFirst(lightA, lightB) {
  11365. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11366. }
  11367. function WebGLLights() {
  11368. var cache = new UniformsCache();
  11369. var shadowCache = ShadowUniformsCache();
  11370. var state = {
  11371. version: 0,
  11372. hash: {
  11373. directionalLength: -1,
  11374. pointLength: -1,
  11375. spotLength: -1,
  11376. rectAreaLength: -1,
  11377. hemiLength: -1,
  11378. numDirectionalShadows: -1,
  11379. numPointShadows: -1,
  11380. numSpotShadows: -1
  11381. },
  11382. ambient: [0, 0, 0],
  11383. probe: [],
  11384. directional: [],
  11385. directionalShadow: [],
  11386. directionalShadowMap: [],
  11387. directionalShadowMatrix: [],
  11388. spot: [],
  11389. spotShadow: [],
  11390. spotShadowMap: [],
  11391. spotShadowMatrix: [],
  11392. rectArea: [],
  11393. rectAreaLTC1: null,
  11394. rectAreaLTC2: null,
  11395. point: [],
  11396. pointShadow: [],
  11397. pointShadowMap: [],
  11398. pointShadowMatrix: [],
  11399. hemi: []
  11400. };
  11401. for (var i = 0; i < 9; i++) {
  11402. state.probe.push(new Vector3());
  11403. }
  11404. var vector3 = new Vector3();
  11405. var matrix4 = new Matrix4();
  11406. var matrix42 = new Matrix4();
  11407. function setup(lights, shadows, camera) {
  11408. var r = 0,
  11409. g = 0,
  11410. b = 0;
  11411. for (var _i = 0; _i < 9; _i++) {
  11412. state.probe[_i].set(0, 0, 0);
  11413. }
  11414. var directionalLength = 0;
  11415. var pointLength = 0;
  11416. var spotLength = 0;
  11417. var rectAreaLength = 0;
  11418. var hemiLength = 0;
  11419. var numDirectionalShadows = 0;
  11420. var numPointShadows = 0;
  11421. var numSpotShadows = 0;
  11422. var viewMatrix = camera.matrixWorldInverse;
  11423. lights.sort(shadowCastingLightsFirst);
  11424. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11425. var light = lights[_i2];
  11426. var color = light.color;
  11427. var intensity = light.intensity;
  11428. var distance = light.distance;
  11429. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11430. if (light.isAmbientLight) {
  11431. r += color.r * intensity;
  11432. g += color.g * intensity;
  11433. b += color.b * intensity;
  11434. } else if (light.isLightProbe) {
  11435. for (var j = 0; j < 9; j++) {
  11436. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11437. }
  11438. } else if (light.isDirectionalLight) {
  11439. var uniforms = cache.get(light);
  11440. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11441. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11442. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11443. uniforms.direction.sub(vector3);
  11444. uniforms.direction.transformDirection(viewMatrix);
  11445. if (light.castShadow) {
  11446. var shadow = light.shadow;
  11447. var shadowUniforms = shadowCache.get(light);
  11448. shadowUniforms.shadowBias = shadow.bias;
  11449. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11450. shadowUniforms.shadowRadius = shadow.radius;
  11451. shadowUniforms.shadowMapSize = shadow.mapSize;
  11452. state.directionalShadow[directionalLength] = shadowUniforms;
  11453. state.directionalShadowMap[directionalLength] = shadowMap;
  11454. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11455. numDirectionalShadows++;
  11456. }
  11457. state.directional[directionalLength] = uniforms;
  11458. directionalLength++;
  11459. } else if (light.isSpotLight) {
  11460. var _uniforms = cache.get(light);
  11461. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11462. _uniforms.position.applyMatrix4(viewMatrix);
  11463. _uniforms.color.copy(color).multiplyScalar(intensity);
  11464. _uniforms.distance = distance;
  11465. _uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11466. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11467. _uniforms.direction.sub(vector3);
  11468. _uniforms.direction.transformDirection(viewMatrix);
  11469. _uniforms.coneCos = Math.cos(light.angle);
  11470. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11471. _uniforms.decay = light.decay;
  11472. if (light.castShadow) {
  11473. var _shadow = light.shadow;
  11474. var _shadowUniforms = shadowCache.get(light);
  11475. _shadowUniforms.shadowBias = _shadow.bias;
  11476. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11477. _shadowUniforms.shadowRadius = _shadow.radius;
  11478. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11479. state.spotShadow[spotLength] = _shadowUniforms;
  11480. state.spotShadowMap[spotLength] = shadowMap;
  11481. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11482. numSpotShadows++;
  11483. }
  11484. state.spot[spotLength] = _uniforms;
  11485. spotLength++;
  11486. } else if (light.isRectAreaLight) {
  11487. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11488. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11489. // (b) intensity is the brightness of the light
  11490. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11491. _uniforms2.position.setFromMatrixPosition(light.matrixWorld);
  11492. _uniforms2.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11493. matrix42.identity();
  11494. matrix4.copy(light.matrixWorld);
  11495. matrix4.premultiply(viewMatrix);
  11496. matrix42.extractRotation(matrix4);
  11497. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11498. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11499. _uniforms2.halfWidth.applyMatrix4(matrix42);
  11500. _uniforms2.halfHeight.applyMatrix4(matrix42); // TODO (abelnation): RectAreaLight distance?
  11501. // uniforms.distance = distance;
  11502. state.rectArea[rectAreaLength] = _uniforms2;
  11503. rectAreaLength++;
  11504. } else if (light.isPointLight) {
  11505. var _uniforms3 = cache.get(light);
  11506. _uniforms3.position.setFromMatrixPosition(light.matrixWorld);
  11507. _uniforms3.position.applyMatrix4(viewMatrix);
  11508. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11509. _uniforms3.distance = light.distance;
  11510. _uniforms3.decay = light.decay;
  11511. if (light.castShadow) {
  11512. var _shadow2 = light.shadow;
  11513. var _shadowUniforms2 = shadowCache.get(light);
  11514. _shadowUniforms2.shadowBias = _shadow2.bias;
  11515. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11516. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11517. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11518. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11519. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11520. state.pointShadow[pointLength] = _shadowUniforms2;
  11521. state.pointShadowMap[pointLength] = shadowMap;
  11522. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11523. numPointShadows++;
  11524. }
  11525. state.point[pointLength] = _uniforms3;
  11526. pointLength++;
  11527. } else if (light.isHemisphereLight) {
  11528. var _uniforms4 = cache.get(light);
  11529. _uniforms4.direction.setFromMatrixPosition(light.matrixWorld);
  11530. _uniforms4.direction.transformDirection(viewMatrix);
  11531. _uniforms4.direction.normalize();
  11532. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11533. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11534. state.hemi[hemiLength] = _uniforms4;
  11535. hemiLength++;
  11536. }
  11537. }
  11538. if (rectAreaLength > 0) {
  11539. state.rectAreaLTC1 = UniformsLib.LTC_1;
  11540. state.rectAreaLTC2 = UniformsLib.LTC_2;
  11541. }
  11542. state.ambient[0] = r;
  11543. state.ambient[1] = g;
  11544. state.ambient[2] = b;
  11545. var hash = state.hash;
  11546. 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) {
  11547. state.directional.length = directionalLength;
  11548. state.spot.length = spotLength;
  11549. state.rectArea.length = rectAreaLength;
  11550. state.point.length = pointLength;
  11551. state.hemi.length = hemiLength;
  11552. state.directionalShadow.length = numDirectionalShadows;
  11553. state.directionalShadowMap.length = numDirectionalShadows;
  11554. state.pointShadow.length = numPointShadows;
  11555. state.pointShadowMap.length = numPointShadows;
  11556. state.spotShadow.length = numSpotShadows;
  11557. state.spotShadowMap.length = numSpotShadows;
  11558. state.directionalShadowMatrix.length = numDirectionalShadows;
  11559. state.pointShadowMatrix.length = numPointShadows;
  11560. state.spotShadowMatrix.length = numSpotShadows;
  11561. hash.directionalLength = directionalLength;
  11562. hash.pointLength = pointLength;
  11563. hash.spotLength = spotLength;
  11564. hash.rectAreaLength = rectAreaLength;
  11565. hash.hemiLength = hemiLength;
  11566. hash.numDirectionalShadows = numDirectionalShadows;
  11567. hash.numPointShadows = numPointShadows;
  11568. hash.numSpotShadows = numSpotShadows;
  11569. state.version = nextVersion++;
  11570. }
  11571. }
  11572. return {
  11573. setup: setup,
  11574. state: state
  11575. };
  11576. }
  11577. function WebGLRenderState() {
  11578. var lights = new WebGLLights();
  11579. var lightsArray = [];
  11580. var shadowsArray = [];
  11581. function init() {
  11582. lightsArray.length = 0;
  11583. shadowsArray.length = 0;
  11584. }
  11585. function pushLight(light) {
  11586. lightsArray.push(light);
  11587. }
  11588. function pushShadow(shadowLight) {
  11589. shadowsArray.push(shadowLight);
  11590. }
  11591. function setupLights(camera) {
  11592. lights.setup(lightsArray, shadowsArray, camera);
  11593. }
  11594. var state = {
  11595. lightsArray: lightsArray,
  11596. shadowsArray: shadowsArray,
  11597. lights: lights
  11598. };
  11599. return {
  11600. init: init,
  11601. state: state,
  11602. setupLights: setupLights,
  11603. pushLight: pushLight,
  11604. pushShadow: pushShadow
  11605. };
  11606. }
  11607. function WebGLRenderStates() {
  11608. var renderStates = new WeakMap();
  11609. function get(scene, camera) {
  11610. var renderState;
  11611. if (renderStates.has(scene) === false) {
  11612. renderState = new WebGLRenderState();
  11613. renderStates.set(scene, new WeakMap());
  11614. renderStates.get(scene).set(camera, renderState);
  11615. } else {
  11616. if (renderStates.get(scene).has(camera) === false) {
  11617. renderState = new WebGLRenderState();
  11618. renderStates.get(scene).set(camera, renderState);
  11619. } else {
  11620. renderState = renderStates.get(scene).get(camera);
  11621. }
  11622. }
  11623. return renderState;
  11624. }
  11625. function dispose() {
  11626. renderStates = new WeakMap();
  11627. }
  11628. return {
  11629. get: get,
  11630. dispose: dispose
  11631. };
  11632. }
  11633. /**
  11634. * parameters = {
  11635. *
  11636. * opacity: <float>,
  11637. *
  11638. * map: new THREE.Texture( <Image> ),
  11639. *
  11640. * alphaMap: new THREE.Texture( <Image> ),
  11641. *
  11642. * displacementMap: new THREE.Texture( <Image> ),
  11643. * displacementScale: <float>,
  11644. * displacementBias: <float>,
  11645. *
  11646. * wireframe: <boolean>,
  11647. * wireframeLinewidth: <float>
  11648. * }
  11649. */
  11650. function MeshDepthMaterial(parameters) {
  11651. Material.call(this);
  11652. this.type = 'MeshDepthMaterial';
  11653. this.depthPacking = BasicDepthPacking;
  11654. this.skinning = false;
  11655. this.morphTargets = false;
  11656. this.map = null;
  11657. this.alphaMap = null;
  11658. this.displacementMap = null;
  11659. this.displacementScale = 1;
  11660. this.displacementBias = 0;
  11661. this.wireframe = false;
  11662. this.wireframeLinewidth = 1;
  11663. this.fog = false;
  11664. this.setValues(parameters);
  11665. }
  11666. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11667. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11668. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11669. MeshDepthMaterial.prototype.copy = function (source) {
  11670. Material.prototype.copy.call(this, source);
  11671. this.depthPacking = source.depthPacking;
  11672. this.skinning = source.skinning;
  11673. this.morphTargets = source.morphTargets;
  11674. this.map = source.map;
  11675. this.alphaMap = source.alphaMap;
  11676. this.displacementMap = source.displacementMap;
  11677. this.displacementScale = source.displacementScale;
  11678. this.displacementBias = source.displacementBias;
  11679. this.wireframe = source.wireframe;
  11680. this.wireframeLinewidth = source.wireframeLinewidth;
  11681. return this;
  11682. };
  11683. /**
  11684. * parameters = {
  11685. *
  11686. * referencePosition: <float>,
  11687. * nearDistance: <float>,
  11688. * farDistance: <float>,
  11689. *
  11690. * skinning: <bool>,
  11691. * morphTargets: <bool>,
  11692. *
  11693. * map: new THREE.Texture( <Image> ),
  11694. *
  11695. * alphaMap: new THREE.Texture( <Image> ),
  11696. *
  11697. * displacementMap: new THREE.Texture( <Image> ),
  11698. * displacementScale: <float>,
  11699. * displacementBias: <float>
  11700. *
  11701. * }
  11702. */
  11703. function MeshDistanceMaterial(parameters) {
  11704. Material.call(this);
  11705. this.type = 'MeshDistanceMaterial';
  11706. this.referencePosition = new Vector3();
  11707. this.nearDistance = 1;
  11708. this.farDistance = 1000;
  11709. this.skinning = false;
  11710. this.morphTargets = false;
  11711. this.map = null;
  11712. this.alphaMap = null;
  11713. this.displacementMap = null;
  11714. this.displacementScale = 1;
  11715. this.displacementBias = 0;
  11716. this.fog = false;
  11717. this.setValues(parameters);
  11718. }
  11719. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11720. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11721. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11722. MeshDistanceMaterial.prototype.copy = function (source) {
  11723. Material.prototype.copy.call(this, source);
  11724. this.referencePosition.copy(source.referencePosition);
  11725. this.nearDistance = source.nearDistance;
  11726. this.farDistance = source.farDistance;
  11727. this.skinning = source.skinning;
  11728. this.morphTargets = source.morphTargets;
  11729. this.map = source.map;
  11730. this.alphaMap = source.alphaMap;
  11731. this.displacementMap = source.displacementMap;
  11732. this.displacementScale = source.displacementScale;
  11733. this.displacementBias = source.displacementBias;
  11734. return this;
  11735. };
  11736. 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}";
  11737. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11738. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11739. var _frustum = new Frustum();
  11740. var _shadowMapSize = new Vector2(),
  11741. _viewportSize = new Vector2(),
  11742. _viewport = new Vector4(),
  11743. _depthMaterials = [],
  11744. _distanceMaterials = [],
  11745. _materialCache = {};
  11746. var shadowSide = {
  11747. 0: BackSide,
  11748. 1: FrontSide,
  11749. 2: DoubleSide
  11750. };
  11751. var shadowMaterialVertical = new ShaderMaterial({
  11752. defines: {
  11753. SAMPLE_RATE: 2.0 / 8.0,
  11754. HALF_SAMPLE_RATE: 1.0 / 8.0
  11755. },
  11756. uniforms: {
  11757. shadow_pass: {
  11758. value: null
  11759. },
  11760. resolution: {
  11761. value: new Vector2()
  11762. },
  11763. radius: {
  11764. value: 4.0
  11765. }
  11766. },
  11767. vertexShader: vsm_vert,
  11768. fragmentShader: vsm_frag
  11769. });
  11770. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  11771. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  11772. var fullScreenTri = new BufferGeometry();
  11773. fullScreenTri.setAttribute("position", new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  11774. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  11775. var scope = this;
  11776. this.enabled = false;
  11777. this.autoUpdate = true;
  11778. this.needsUpdate = false;
  11779. this.type = PCFShadowMap;
  11780. this.render = function (lights, scene, camera) {
  11781. if (scope.enabled === false) return;
  11782. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  11783. if (lights.length === 0) return;
  11784. var currentRenderTarget = _renderer.getRenderTarget();
  11785. var activeCubeFace = _renderer.getActiveCubeFace();
  11786. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11787. var _state = _renderer.state; // Set GL state for depth map.
  11788. _state.setBlending(NoBlending);
  11789. _state.buffers.color.setClear(1, 1, 1, 1);
  11790. _state.buffers.depth.setTest(true);
  11791. _state.setScissorTest(false); // render depth map
  11792. for (var i = 0, il = lights.length; i < il; i++) {
  11793. var light = lights[i];
  11794. var shadow = light.shadow;
  11795. if (shadow === undefined) {
  11796. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  11797. continue;
  11798. }
  11799. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  11800. _shadowMapSize.copy(shadow.mapSize);
  11801. var shadowFrameExtents = shadow.getFrameExtents();
  11802. _shadowMapSize.multiply(shadowFrameExtents);
  11803. _viewportSize.copy(shadow.mapSize);
  11804. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  11805. if (_shadowMapSize.x > maxTextureSize) {
  11806. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  11807. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11808. shadow.mapSize.x = _viewportSize.x;
  11809. }
  11810. if (_shadowMapSize.y > maxTextureSize) {
  11811. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  11812. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11813. shadow.mapSize.y = _viewportSize.y;
  11814. }
  11815. }
  11816. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11817. var pars = {
  11818. minFilter: LinearFilter,
  11819. magFilter: LinearFilter,
  11820. format: RGBAFormat
  11821. };
  11822. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11823. shadow.map.texture.name = light.name + ".shadowMap";
  11824. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11825. shadow.camera.updateProjectionMatrix();
  11826. }
  11827. if (shadow.map === null) {
  11828. var _pars = {
  11829. minFilter: NearestFilter,
  11830. magFilter: NearestFilter,
  11831. format: RGBAFormat
  11832. };
  11833. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  11834. shadow.map.texture.name = light.name + ".shadowMap";
  11835. shadow.camera.updateProjectionMatrix();
  11836. }
  11837. _renderer.setRenderTarget(shadow.map);
  11838. _renderer.clear();
  11839. var viewportCount = shadow.getViewportCount();
  11840. for (var vp = 0; vp < viewportCount; vp++) {
  11841. var viewport = shadow.getViewport(vp);
  11842. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  11843. _state.viewport(_viewport);
  11844. shadow.updateMatrices(light, vp);
  11845. _frustum = shadow.getFrustum();
  11846. renderObject(scene, camera, shadow.camera, light, this.type);
  11847. } // do blur pass for VSM
  11848. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11849. VSMPass(shadow, camera);
  11850. }
  11851. shadow.needsUpdate = false;
  11852. }
  11853. scope.needsUpdate = false;
  11854. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  11855. };
  11856. function VSMPass(shadow, camera) {
  11857. var geometry = _objects.update(fullScreenMesh); // vertical pass
  11858. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11859. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11860. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11861. _renderer.setRenderTarget(shadow.mapPass);
  11862. _renderer.clear();
  11863. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizonal pass
  11864. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11865. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  11866. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  11867. _renderer.setRenderTarget(shadow.map);
  11868. _renderer.clear();
  11869. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null);
  11870. }
  11871. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11872. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11873. var material = _depthMaterials[index];
  11874. if (material === undefined) {
  11875. material = new MeshDepthMaterial({
  11876. depthPacking: RGBADepthPacking,
  11877. morphTargets: useMorphing,
  11878. skinning: useSkinning
  11879. });
  11880. _depthMaterials[index] = material;
  11881. }
  11882. return material;
  11883. }
  11884. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11885. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11886. var material = _distanceMaterials[index];
  11887. if (material === undefined) {
  11888. material = new MeshDistanceMaterial({
  11889. morphTargets: useMorphing,
  11890. skinning: useSkinning
  11891. });
  11892. _distanceMaterials[index] = material;
  11893. }
  11894. return material;
  11895. }
  11896. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  11897. var result = null;
  11898. var getMaterialVariant = getDepthMaterialVariant;
  11899. var customMaterial = object.customDepthMaterial;
  11900. if (light.isPointLight === true) {
  11901. getMaterialVariant = getDistanceMaterialVariant;
  11902. customMaterial = object.customDistanceMaterial;
  11903. }
  11904. if (customMaterial === undefined) {
  11905. var useMorphing = false;
  11906. if (material.morphTargets === true) {
  11907. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11908. }
  11909. var useSkinning = false;
  11910. if (object.isSkinnedMesh === true) {
  11911. if (material.skinning === true) {
  11912. useSkinning = true;
  11913. } else {
  11914. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  11915. }
  11916. }
  11917. var useInstancing = object.isInstancedMesh === true;
  11918. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  11919. } else {
  11920. result = customMaterial;
  11921. }
  11922. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  11923. // in this case we need a unique material instance reflecting the
  11924. // appropriate state
  11925. var keyA = result.uuid,
  11926. keyB = material.uuid;
  11927. var materialsForVariant = _materialCache[keyA];
  11928. if (materialsForVariant === undefined) {
  11929. materialsForVariant = {};
  11930. _materialCache[keyA] = materialsForVariant;
  11931. }
  11932. var cachedMaterial = materialsForVariant[keyB];
  11933. if (cachedMaterial === undefined) {
  11934. cachedMaterial = result.clone();
  11935. materialsForVariant[keyB] = cachedMaterial;
  11936. }
  11937. result = cachedMaterial;
  11938. }
  11939. result.visible = material.visible;
  11940. result.wireframe = material.wireframe;
  11941. if (type === VSMShadowMap) {
  11942. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  11943. } else {
  11944. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  11945. }
  11946. result.clipShadows = material.clipShadows;
  11947. result.clippingPlanes = material.clippingPlanes;
  11948. result.clipIntersection = material.clipIntersection;
  11949. result.wireframeLinewidth = material.wireframeLinewidth;
  11950. result.linewidth = material.linewidth;
  11951. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  11952. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  11953. result.nearDistance = shadowCameraNear;
  11954. result.farDistance = shadowCameraFar;
  11955. }
  11956. return result;
  11957. }
  11958. function renderObject(object, camera, shadowCamera, light, type) {
  11959. if (object.visible === false) return;
  11960. var visible = object.layers.test(camera.layers);
  11961. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  11962. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  11963. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  11964. var geometry = _objects.update(object);
  11965. var material = object.material;
  11966. if (Array.isArray(material)) {
  11967. var groups = geometry.groups;
  11968. for (var k = 0, kl = groups.length; k < kl; k++) {
  11969. var group = groups[k];
  11970. var groupMaterial = material[group.materialIndex];
  11971. if (groupMaterial && groupMaterial.visible) {
  11972. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  11973. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  11974. }
  11975. }
  11976. } else if (material.visible) {
  11977. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  11978. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  11979. }
  11980. }
  11981. }
  11982. var children = object.children;
  11983. for (var i = 0, l = children.length; i < l; i++) {
  11984. renderObject(children[i], camera, shadowCamera, light, type);
  11985. }
  11986. }
  11987. }
  11988. function WebGLState(gl, extensions, capabilities) {
  11989. var _equationToGL, _factorToGL;
  11990. var isWebGL2 = capabilities.isWebGL2;
  11991. function ColorBuffer() {
  11992. var locked = false;
  11993. var color = new Vector4();
  11994. var currentColorMask = null;
  11995. var currentColorClear = new Vector4(0, 0, 0, 0);
  11996. return {
  11997. setMask: function setMask(colorMask) {
  11998. if (currentColorMask !== colorMask && !locked) {
  11999. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12000. currentColorMask = colorMask;
  12001. }
  12002. },
  12003. setLocked: function setLocked(lock) {
  12004. locked = lock;
  12005. },
  12006. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12007. if (premultipliedAlpha === true) {
  12008. r *= a;
  12009. g *= a;
  12010. b *= a;
  12011. }
  12012. color.set(r, g, b, a);
  12013. if (currentColorClear.equals(color) === false) {
  12014. gl.clearColor(r, g, b, a);
  12015. currentColorClear.copy(color);
  12016. }
  12017. },
  12018. reset: function reset() {
  12019. locked = false;
  12020. currentColorMask = null;
  12021. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12022. }
  12023. };
  12024. }
  12025. function DepthBuffer() {
  12026. var locked = false;
  12027. var currentDepthMask = null;
  12028. var currentDepthFunc = null;
  12029. var currentDepthClear = null;
  12030. return {
  12031. setTest: function setTest(depthTest) {
  12032. if (depthTest) {
  12033. enable(2929);
  12034. } else {
  12035. disable(2929);
  12036. }
  12037. },
  12038. setMask: function setMask(depthMask) {
  12039. if (currentDepthMask !== depthMask && !locked) {
  12040. gl.depthMask(depthMask);
  12041. currentDepthMask = depthMask;
  12042. }
  12043. },
  12044. setFunc: function setFunc(depthFunc) {
  12045. if (currentDepthFunc !== depthFunc) {
  12046. if (depthFunc) {
  12047. switch (depthFunc) {
  12048. case NeverDepth:
  12049. gl.depthFunc(512);
  12050. break;
  12051. case AlwaysDepth:
  12052. gl.depthFunc(519);
  12053. break;
  12054. case LessDepth:
  12055. gl.depthFunc(513);
  12056. break;
  12057. case LessEqualDepth:
  12058. gl.depthFunc(515);
  12059. break;
  12060. case EqualDepth:
  12061. gl.depthFunc(514);
  12062. break;
  12063. case GreaterEqualDepth:
  12064. gl.depthFunc(518);
  12065. break;
  12066. case GreaterDepth:
  12067. gl.depthFunc(516);
  12068. break;
  12069. case NotEqualDepth:
  12070. gl.depthFunc(517);
  12071. break;
  12072. default:
  12073. gl.depthFunc(515);
  12074. }
  12075. } else {
  12076. gl.depthFunc(515);
  12077. }
  12078. currentDepthFunc = depthFunc;
  12079. }
  12080. },
  12081. setLocked: function setLocked(lock) {
  12082. locked = lock;
  12083. },
  12084. setClear: function setClear(depth) {
  12085. if (currentDepthClear !== depth) {
  12086. gl.clearDepth(depth);
  12087. currentDepthClear = depth;
  12088. }
  12089. },
  12090. reset: function reset() {
  12091. locked = false;
  12092. currentDepthMask = null;
  12093. currentDepthFunc = null;
  12094. currentDepthClear = null;
  12095. }
  12096. };
  12097. }
  12098. function StencilBuffer() {
  12099. var locked = false;
  12100. var currentStencilMask = null;
  12101. var currentStencilFunc = null;
  12102. var currentStencilRef = null;
  12103. var currentStencilFuncMask = null;
  12104. var currentStencilFail = null;
  12105. var currentStencilZFail = null;
  12106. var currentStencilZPass = null;
  12107. var currentStencilClear = null;
  12108. return {
  12109. setTest: function setTest(stencilTest) {
  12110. if (!locked) {
  12111. if (stencilTest) {
  12112. enable(2960);
  12113. } else {
  12114. disable(2960);
  12115. }
  12116. }
  12117. },
  12118. setMask: function setMask(stencilMask) {
  12119. if (currentStencilMask !== stencilMask && !locked) {
  12120. gl.stencilMask(stencilMask);
  12121. currentStencilMask = stencilMask;
  12122. }
  12123. },
  12124. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12125. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12126. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12127. currentStencilFunc = stencilFunc;
  12128. currentStencilRef = stencilRef;
  12129. currentStencilFuncMask = stencilMask;
  12130. }
  12131. },
  12132. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12133. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12134. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12135. currentStencilFail = stencilFail;
  12136. currentStencilZFail = stencilZFail;
  12137. currentStencilZPass = stencilZPass;
  12138. }
  12139. },
  12140. setLocked: function setLocked(lock) {
  12141. locked = lock;
  12142. },
  12143. setClear: function setClear(stencil) {
  12144. if (currentStencilClear !== stencil) {
  12145. gl.clearStencil(stencil);
  12146. currentStencilClear = stencil;
  12147. }
  12148. },
  12149. reset: function reset() {
  12150. locked = false;
  12151. currentStencilMask = null;
  12152. currentStencilFunc = null;
  12153. currentStencilRef = null;
  12154. currentStencilFuncMask = null;
  12155. currentStencilFail = null;
  12156. currentStencilZFail = null;
  12157. currentStencilZPass = null;
  12158. currentStencilClear = null;
  12159. }
  12160. };
  12161. } //
  12162. var colorBuffer = new ColorBuffer();
  12163. var depthBuffer = new DepthBuffer();
  12164. var stencilBuffer = new StencilBuffer();
  12165. var enabledCapabilities = {};
  12166. var currentProgram = null;
  12167. var currentBlendingEnabled = null;
  12168. var currentBlending = null;
  12169. var currentBlendEquation = null;
  12170. var currentBlendSrc = null;
  12171. var currentBlendDst = null;
  12172. var currentBlendEquationAlpha = null;
  12173. var currentBlendSrcAlpha = null;
  12174. var currentBlendDstAlpha = null;
  12175. var currentPremultipledAlpha = false;
  12176. var currentFlipSided = null;
  12177. var currentCullFace = null;
  12178. var currentLineWidth = null;
  12179. var currentPolygonOffsetFactor = null;
  12180. var currentPolygonOffsetUnits = null;
  12181. var maxTextures = gl.getParameter(35661);
  12182. var lineWidthAvailable = false;
  12183. var version = 0;
  12184. var glVersion = gl.getParameter(7938);
  12185. if (glVersion.indexOf('WebGL') !== -1) {
  12186. version = parseFloat(/^WebGL\ ([0-9])/.exec(glVersion)[1]);
  12187. lineWidthAvailable = version >= 1.0;
  12188. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12189. version = parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(glVersion)[1]);
  12190. lineWidthAvailable = version >= 2.0;
  12191. }
  12192. var currentTextureSlot = null;
  12193. var currentBoundTextures = {};
  12194. var currentScissor = new Vector4();
  12195. var currentViewport = new Vector4();
  12196. function createTexture(type, target, count) {
  12197. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12198. var texture = gl.createTexture();
  12199. gl.bindTexture(type, texture);
  12200. gl.texParameteri(type, 10241, 9728);
  12201. gl.texParameteri(type, 10240, 9728);
  12202. for (var i = 0; i < count; i++) {
  12203. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12204. }
  12205. return texture;
  12206. }
  12207. var emptyTextures = {};
  12208. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12209. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12210. colorBuffer.setClear(0, 0, 0, 1);
  12211. depthBuffer.setClear(1);
  12212. stencilBuffer.setClear(0);
  12213. enable(2929);
  12214. depthBuffer.setFunc(LessEqualDepth);
  12215. setFlipSided(false);
  12216. setCullFace(CullFaceBack);
  12217. enable(2884);
  12218. setBlending(NoBlending); //
  12219. function enable(id) {
  12220. if (enabledCapabilities[id] !== true) {
  12221. gl.enable(id);
  12222. enabledCapabilities[id] = true;
  12223. }
  12224. }
  12225. function disable(id) {
  12226. if (enabledCapabilities[id] !== false) {
  12227. gl.disable(id);
  12228. enabledCapabilities[id] = false;
  12229. }
  12230. }
  12231. function useProgram(program) {
  12232. if (currentProgram !== program) {
  12233. gl.useProgram(program);
  12234. currentProgram = program;
  12235. return true;
  12236. }
  12237. return false;
  12238. }
  12239. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12240. if (isWebGL2) {
  12241. equationToGL[MinEquation] = 32775;
  12242. equationToGL[MaxEquation] = 32776;
  12243. } else {
  12244. var extension = extensions.get('EXT_blend_minmax');
  12245. if (extension !== null) {
  12246. equationToGL[MinEquation] = extension.MIN_EXT;
  12247. equationToGL[MaxEquation] = extension.MAX_EXT;
  12248. }
  12249. }
  12250. 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);
  12251. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12252. if (blending === NoBlending) {
  12253. if (currentBlendingEnabled) {
  12254. disable(3042);
  12255. currentBlendingEnabled = false;
  12256. }
  12257. return;
  12258. }
  12259. if (!currentBlendingEnabled) {
  12260. enable(3042);
  12261. currentBlendingEnabled = true;
  12262. }
  12263. if (blending !== CustomBlending) {
  12264. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12265. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12266. gl.blendEquation(32774);
  12267. currentBlendEquation = AddEquation;
  12268. currentBlendEquationAlpha = AddEquation;
  12269. }
  12270. if (premultipliedAlpha) {
  12271. switch (blending) {
  12272. case NormalBlending:
  12273. gl.blendFuncSeparate(1, 771, 1, 771);
  12274. break;
  12275. case AdditiveBlending:
  12276. gl.blendFunc(1, 1);
  12277. break;
  12278. case SubtractiveBlending:
  12279. gl.blendFuncSeparate(0, 0, 769, 771);
  12280. break;
  12281. case MultiplyBlending:
  12282. gl.blendFuncSeparate(0, 768, 0, 770);
  12283. break;
  12284. default:
  12285. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12286. break;
  12287. }
  12288. } else {
  12289. switch (blending) {
  12290. case NormalBlending:
  12291. gl.blendFuncSeparate(770, 771, 1, 771);
  12292. break;
  12293. case AdditiveBlending:
  12294. gl.blendFunc(770, 1);
  12295. break;
  12296. case SubtractiveBlending:
  12297. gl.blendFunc(0, 769);
  12298. break;
  12299. case MultiplyBlending:
  12300. gl.blendFunc(0, 768);
  12301. break;
  12302. default:
  12303. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12304. break;
  12305. }
  12306. }
  12307. currentBlendSrc = null;
  12308. currentBlendDst = null;
  12309. currentBlendSrcAlpha = null;
  12310. currentBlendDstAlpha = null;
  12311. currentBlending = blending;
  12312. currentPremultipledAlpha = premultipliedAlpha;
  12313. }
  12314. return;
  12315. } // custom blending
  12316. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12317. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12318. blendDstAlpha = blendDstAlpha || blendDst;
  12319. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12320. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12321. currentBlendEquation = blendEquation;
  12322. currentBlendEquationAlpha = blendEquationAlpha;
  12323. }
  12324. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12325. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12326. currentBlendSrc = blendSrc;
  12327. currentBlendDst = blendDst;
  12328. currentBlendSrcAlpha = blendSrcAlpha;
  12329. currentBlendDstAlpha = blendDstAlpha;
  12330. }
  12331. currentBlending = blending;
  12332. currentPremultipledAlpha = null;
  12333. }
  12334. function setMaterial(material, frontFaceCW) {
  12335. material.side === DoubleSide ? disable(2884) : enable(2884);
  12336. var flipSided = material.side === BackSide;
  12337. if (frontFaceCW) flipSided = !flipSided;
  12338. setFlipSided(flipSided);
  12339. 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);
  12340. depthBuffer.setFunc(material.depthFunc);
  12341. depthBuffer.setTest(material.depthTest);
  12342. depthBuffer.setMask(material.depthWrite);
  12343. colorBuffer.setMask(material.colorWrite);
  12344. var stencilWrite = material.stencilWrite;
  12345. stencilBuffer.setTest(stencilWrite);
  12346. if (stencilWrite) {
  12347. stencilBuffer.setMask(material.stencilWriteMask);
  12348. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12349. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12350. }
  12351. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12352. } //
  12353. function setFlipSided(flipSided) {
  12354. if (currentFlipSided !== flipSided) {
  12355. if (flipSided) {
  12356. gl.frontFace(2304);
  12357. } else {
  12358. gl.frontFace(2305);
  12359. }
  12360. currentFlipSided = flipSided;
  12361. }
  12362. }
  12363. function setCullFace(cullFace) {
  12364. if (cullFace !== CullFaceNone) {
  12365. enable(2884);
  12366. if (cullFace !== currentCullFace) {
  12367. if (cullFace === CullFaceBack) {
  12368. gl.cullFace(1029);
  12369. } else if (cullFace === CullFaceFront) {
  12370. gl.cullFace(1028);
  12371. } else {
  12372. gl.cullFace(1032);
  12373. }
  12374. }
  12375. } else {
  12376. disable(2884);
  12377. }
  12378. currentCullFace = cullFace;
  12379. }
  12380. function setLineWidth(width) {
  12381. if (width !== currentLineWidth) {
  12382. if (lineWidthAvailable) gl.lineWidth(width);
  12383. currentLineWidth = width;
  12384. }
  12385. }
  12386. function setPolygonOffset(polygonOffset, factor, units) {
  12387. if (polygonOffset) {
  12388. enable(32823);
  12389. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12390. gl.polygonOffset(factor, units);
  12391. currentPolygonOffsetFactor = factor;
  12392. currentPolygonOffsetUnits = units;
  12393. }
  12394. } else {
  12395. disable(32823);
  12396. }
  12397. }
  12398. function setScissorTest(scissorTest) {
  12399. if (scissorTest) {
  12400. enable(3089);
  12401. } else {
  12402. disable(3089);
  12403. }
  12404. } // texture
  12405. function activeTexture(webglSlot) {
  12406. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12407. if (currentTextureSlot !== webglSlot) {
  12408. gl.activeTexture(webglSlot);
  12409. currentTextureSlot = webglSlot;
  12410. }
  12411. }
  12412. function bindTexture(webglType, webglTexture) {
  12413. if (currentTextureSlot === null) {
  12414. activeTexture();
  12415. }
  12416. var boundTexture = currentBoundTextures[currentTextureSlot];
  12417. if (boundTexture === undefined) {
  12418. boundTexture = {
  12419. type: undefined,
  12420. texture: undefined
  12421. };
  12422. currentBoundTextures[currentTextureSlot] = boundTexture;
  12423. }
  12424. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12425. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12426. boundTexture.type = webglType;
  12427. boundTexture.texture = webglTexture;
  12428. }
  12429. }
  12430. function unbindTexture() {
  12431. var boundTexture = currentBoundTextures[currentTextureSlot];
  12432. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12433. gl.bindTexture(boundTexture.type, null);
  12434. boundTexture.type = undefined;
  12435. boundTexture.texture = undefined;
  12436. }
  12437. }
  12438. function compressedTexImage2D() {
  12439. try {
  12440. gl.compressedTexImage2D.apply(gl, arguments);
  12441. } catch (error) {
  12442. console.error('THREE.WebGLState:', error);
  12443. }
  12444. }
  12445. function texImage2D() {
  12446. try {
  12447. gl.texImage2D.apply(gl, arguments);
  12448. } catch (error) {
  12449. console.error('THREE.WebGLState:', error);
  12450. }
  12451. }
  12452. function texImage3D() {
  12453. try {
  12454. gl.texImage3D.apply(gl, arguments);
  12455. } catch (error) {
  12456. console.error('THREE.WebGLState:', error);
  12457. }
  12458. } //
  12459. function scissor(scissor) {
  12460. if (currentScissor.equals(scissor) === false) {
  12461. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12462. currentScissor.copy(scissor);
  12463. }
  12464. }
  12465. function viewport(viewport) {
  12466. if (currentViewport.equals(viewport) === false) {
  12467. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12468. currentViewport.copy(viewport);
  12469. }
  12470. } //
  12471. function reset() {
  12472. enabledCapabilities = {};
  12473. currentTextureSlot = null;
  12474. currentBoundTextures = {};
  12475. currentProgram = null;
  12476. currentBlending = null;
  12477. currentFlipSided = null;
  12478. currentCullFace = null;
  12479. colorBuffer.reset();
  12480. depthBuffer.reset();
  12481. stencilBuffer.reset();
  12482. }
  12483. return {
  12484. buffers: {
  12485. color: colorBuffer,
  12486. depth: depthBuffer,
  12487. stencil: stencilBuffer
  12488. },
  12489. enable: enable,
  12490. disable: disable,
  12491. useProgram: useProgram,
  12492. setBlending: setBlending,
  12493. setMaterial: setMaterial,
  12494. setFlipSided: setFlipSided,
  12495. setCullFace: setCullFace,
  12496. setLineWidth: setLineWidth,
  12497. setPolygonOffset: setPolygonOffset,
  12498. setScissorTest: setScissorTest,
  12499. activeTexture: activeTexture,
  12500. bindTexture: bindTexture,
  12501. unbindTexture: unbindTexture,
  12502. compressedTexImage2D: compressedTexImage2D,
  12503. texImage2D: texImage2D,
  12504. texImage3D: texImage3D,
  12505. scissor: scissor,
  12506. viewport: viewport,
  12507. reset: reset
  12508. };
  12509. }
  12510. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12511. var _wrappingToGL, _filterToGL;
  12512. var isWebGL2 = capabilities.isWebGL2;
  12513. var maxTextures = capabilities.maxTextures;
  12514. var maxCubemapSize = capabilities.maxCubemapSize;
  12515. var maxTextureSize = capabilities.maxTextureSize;
  12516. var maxSamples = capabilities.maxSamples;
  12517. var _videoTextures = new WeakMap();
  12518. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12519. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12520. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12521. var useOffscreenCanvas = false;
  12522. try {
  12523. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext("2d") !== null;
  12524. } catch (err) {// Ignore any errors
  12525. }
  12526. function createCanvas(width, height) {
  12527. // Use OffscreenCanvas when available. Specially needed in web workers
  12528. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12529. }
  12530. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12531. var scale = 1; // handle case if texture exceeds max size
  12532. if (image.width > maxSize || image.height > maxSize) {
  12533. scale = maxSize / Math.max(image.width, image.height);
  12534. } // only perform resize if necessary
  12535. if (scale < 1 || needsPowerOfTwo === true) {
  12536. // only perform resize for certain image types
  12537. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12538. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12539. var width = floor(scale * image.width);
  12540. var height = floor(scale * image.height);
  12541. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12542. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12543. canvas.width = width;
  12544. canvas.height = height;
  12545. var context = canvas.getContext('2d');
  12546. context.drawImage(image, 0, 0, width, height);
  12547. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12548. return canvas;
  12549. } else {
  12550. if ('data' in image) {
  12551. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12552. }
  12553. return image;
  12554. }
  12555. }
  12556. return image;
  12557. }
  12558. function isPowerOfTwo(image) {
  12559. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12560. }
  12561. function textureNeedsPowerOfTwo(texture) {
  12562. if (isWebGL2) return false;
  12563. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12564. }
  12565. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12566. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12567. }
  12568. function generateMipmap(target, texture, width, height) {
  12569. _gl.generateMipmap(target);
  12570. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12571. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12572. }
  12573. function getInternalFormat(internalFormatName, glFormat, glType) {
  12574. if (isWebGL2 === false) return glFormat;
  12575. if (internalFormatName !== null) {
  12576. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12577. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12578. }
  12579. var internalFormat = glFormat;
  12580. if (glFormat === 6403) {
  12581. if (glType === 5126) internalFormat = 33326;
  12582. if (glType === 5131) internalFormat = 33325;
  12583. if (glType === 5121) internalFormat = 33321;
  12584. }
  12585. if (glFormat === 6407) {
  12586. if (glType === 5126) internalFormat = 34837;
  12587. if (glType === 5131) internalFormat = 34843;
  12588. if (glType === 5121) internalFormat = 32849;
  12589. }
  12590. if (glFormat === 6408) {
  12591. if (glType === 5126) internalFormat = 34836;
  12592. if (glType === 5131) internalFormat = 34842;
  12593. if (glType === 5121) internalFormat = 32856;
  12594. }
  12595. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12596. extensions.get('EXT_color_buffer_float');
  12597. }
  12598. return internalFormat;
  12599. } // Fallback filters for non-power-of-2 textures
  12600. function filterFallback(f) {
  12601. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12602. return 9728;
  12603. }
  12604. return 9729;
  12605. } //
  12606. function onTextureDispose(event) {
  12607. var texture = event.target;
  12608. texture.removeEventListener('dispose', onTextureDispose);
  12609. deallocateTexture(texture);
  12610. if (texture.isVideoTexture) {
  12611. _videoTextures.delete(texture);
  12612. }
  12613. info.memory.textures--;
  12614. }
  12615. function onRenderTargetDispose(event) {
  12616. var renderTarget = event.target;
  12617. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12618. deallocateRenderTarget(renderTarget);
  12619. info.memory.textures--;
  12620. } //
  12621. function deallocateTexture(texture) {
  12622. var textureProperties = properties.get(texture);
  12623. if (textureProperties.__webglInit === undefined) return;
  12624. _gl.deleteTexture(textureProperties.__webglTexture);
  12625. properties.remove(texture);
  12626. }
  12627. function deallocateRenderTarget(renderTarget) {
  12628. var renderTargetProperties = properties.get(renderTarget);
  12629. var textureProperties = properties.get(renderTarget.texture);
  12630. if (!renderTarget) return;
  12631. if (textureProperties.__webglTexture !== undefined) {
  12632. _gl.deleteTexture(textureProperties.__webglTexture);
  12633. }
  12634. if (renderTarget.depthTexture) {
  12635. renderTarget.depthTexture.dispose();
  12636. }
  12637. if (renderTarget.isWebGLCubeRenderTarget) {
  12638. for (var i = 0; i < 6; i++) {
  12639. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12640. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12641. }
  12642. } else {
  12643. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12644. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12645. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12646. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12647. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12648. }
  12649. properties.remove(renderTarget.texture);
  12650. properties.remove(renderTarget);
  12651. } //
  12652. var textureUnits = 0;
  12653. function resetTextureUnits() {
  12654. textureUnits = 0;
  12655. }
  12656. function allocateTextureUnit() {
  12657. var textureUnit = textureUnits;
  12658. if (textureUnit >= maxTextures) {
  12659. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12660. }
  12661. textureUnits += 1;
  12662. return textureUnit;
  12663. } //
  12664. function setTexture2D(texture, slot) {
  12665. var textureProperties = properties.get(texture);
  12666. if (texture.isVideoTexture) updateVideoTexture(texture);
  12667. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12668. var image = texture.image;
  12669. if (image === undefined) {
  12670. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12671. } else if (image.complete === false) {
  12672. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12673. } else {
  12674. uploadTexture(textureProperties, texture, slot);
  12675. return;
  12676. }
  12677. }
  12678. state.activeTexture(33984 + slot);
  12679. state.bindTexture(3553, textureProperties.__webglTexture);
  12680. }
  12681. function setTexture2DArray(texture, slot) {
  12682. var textureProperties = properties.get(texture);
  12683. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12684. uploadTexture(textureProperties, texture, slot);
  12685. return;
  12686. }
  12687. state.activeTexture(33984 + slot);
  12688. state.bindTexture(35866, textureProperties.__webglTexture);
  12689. }
  12690. function setTexture3D(texture, slot) {
  12691. var textureProperties = properties.get(texture);
  12692. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12693. uploadTexture(textureProperties, texture, slot);
  12694. return;
  12695. }
  12696. state.activeTexture(33984 + slot);
  12697. state.bindTexture(32879, textureProperties.__webglTexture);
  12698. }
  12699. function setTextureCube(texture, slot) {
  12700. var textureProperties = properties.get(texture);
  12701. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12702. uploadCubeTexture(textureProperties, texture, slot);
  12703. return;
  12704. }
  12705. state.activeTexture(33984 + slot);
  12706. state.bindTexture(34067, textureProperties.__webglTexture);
  12707. }
  12708. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12709. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12710. function setTextureParameters(textureType, texture, supportsMips) {
  12711. if (supportsMips) {
  12712. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12713. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12714. if (textureType === 32879 || textureType === 35866) {
  12715. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12716. }
  12717. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12718. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12719. } else {
  12720. _gl.texParameteri(textureType, 10242, 33071);
  12721. _gl.texParameteri(textureType, 10243, 33071);
  12722. if (textureType === 32879 || textureType === 35866) {
  12723. _gl.texParameteri(textureType, 32882, 33071);
  12724. }
  12725. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12726. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12727. }
  12728. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12729. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12730. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12731. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12732. }
  12733. }
  12734. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12735. if (extension) {
  12736. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12737. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12738. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12739. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12740. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12741. }
  12742. }
  12743. }
  12744. function initTexture(textureProperties, texture) {
  12745. if (textureProperties.__webglInit === undefined) {
  12746. textureProperties.__webglInit = true;
  12747. texture.addEventListener('dispose', onTextureDispose);
  12748. textureProperties.__webglTexture = _gl.createTexture();
  12749. info.memory.textures++;
  12750. }
  12751. }
  12752. function uploadTexture(textureProperties, texture, slot) {
  12753. var textureType = 3553;
  12754. if (texture.isDataTexture2DArray) textureType = 35866;
  12755. if (texture.isDataTexture3D) textureType = 32879;
  12756. initTexture(textureProperties, texture);
  12757. state.activeTexture(33984 + slot);
  12758. state.bindTexture(textureType, textureProperties.__webglTexture);
  12759. _gl.pixelStorei(37440, texture.flipY);
  12760. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  12761. _gl.pixelStorei(3317, texture.unpackAlignment);
  12762. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  12763. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  12764. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  12765. glFormat = utils.convert(texture.format);
  12766. var glType = utils.convert(texture.type),
  12767. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12768. setTextureParameters(textureType, texture, supportsMips);
  12769. var mipmap;
  12770. var mipmaps = texture.mipmaps;
  12771. if (texture.isDepthTexture) {
  12772. // populate depth texture with dummy data
  12773. glInternalFormat = 6402;
  12774. if (isWebGL2) {
  12775. if (texture.type === FloatType) {
  12776. glInternalFormat = 36012;
  12777. } else if (texture.type === UnsignedIntType) {
  12778. glInternalFormat = 33190;
  12779. } else if (texture.type === UnsignedInt248Type) {
  12780. glInternalFormat = 35056;
  12781. } else {
  12782. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12783. }
  12784. } else {
  12785. if (texture.type === FloatType) {
  12786. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  12787. }
  12788. } // validation checks for WebGL 1
  12789. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  12790. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12791. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12792. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12793. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  12794. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  12795. texture.type = UnsignedShortType;
  12796. glType = utils.convert(texture.type);
  12797. }
  12798. }
  12799. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  12800. // Depth stencil textures need the DEPTH_STENCIL internal format
  12801. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12802. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12803. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12804. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12805. if (texture.type !== UnsignedInt248Type) {
  12806. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  12807. texture.type = UnsignedInt248Type;
  12808. glType = utils.convert(texture.type);
  12809. }
  12810. } //
  12811. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  12812. } else if (texture.isDataTexture) {
  12813. // use manually created mipmaps if available
  12814. // if there are no manual mipmaps
  12815. // set 0 level mipmap and then use GL to generate other mipmap levels
  12816. if (mipmaps.length > 0 && supportsMips) {
  12817. for (var i = 0, il = mipmaps.length; i < il; i++) {
  12818. mipmap = mipmaps[i];
  12819. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12820. }
  12821. texture.generateMipmaps = false;
  12822. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12823. } else {
  12824. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  12825. textureProperties.__maxMipLevel = 0;
  12826. }
  12827. } else if (texture.isCompressedTexture) {
  12828. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  12829. mipmap = mipmaps[_i];
  12830. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12831. if (glFormat !== null) {
  12832. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12833. } else {
  12834. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  12835. }
  12836. } else {
  12837. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12838. }
  12839. }
  12840. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12841. } else if (texture.isDataTexture2DArray) {
  12842. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12843. textureProperties.__maxMipLevel = 0;
  12844. } else if (texture.isDataTexture3D) {
  12845. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12846. textureProperties.__maxMipLevel = 0;
  12847. } else {
  12848. // regular Texture (image, video, canvas)
  12849. // use manually created mipmaps if available
  12850. // if there are no manual mipmaps
  12851. // set 0 level mipmap and then use GL to generate other mipmap levels
  12852. if (mipmaps.length > 0 && supportsMips) {
  12853. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  12854. mipmap = mipmaps[_i2];
  12855. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  12856. }
  12857. texture.generateMipmaps = false;
  12858. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12859. } else {
  12860. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  12861. textureProperties.__maxMipLevel = 0;
  12862. }
  12863. }
  12864. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12865. generateMipmap(textureType, texture, image.width, image.height);
  12866. }
  12867. textureProperties.__version = texture.version;
  12868. if (texture.onUpdate) texture.onUpdate(texture);
  12869. }
  12870. function uploadCubeTexture(textureProperties, texture, slot) {
  12871. if (texture.image.length !== 6) return;
  12872. initTexture(textureProperties, texture);
  12873. state.activeTexture(33984 + slot);
  12874. state.bindTexture(34067, textureProperties.__webglTexture);
  12875. _gl.pixelStorei(37440, texture.flipY);
  12876. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  12877. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  12878. var cubeImage = [];
  12879. for (var i = 0; i < 6; i++) {
  12880. if (!isCompressed && !isDataTexture) {
  12881. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  12882. } else {
  12883. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  12884. }
  12885. }
  12886. var image = cubeImage[0],
  12887. supportsMips = isPowerOfTwo(image) || isWebGL2,
  12888. glFormat = utils.convert(texture.format),
  12889. glType = utils.convert(texture.type),
  12890. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12891. setTextureParameters(34067, texture, supportsMips);
  12892. var mipmaps;
  12893. if (isCompressed) {
  12894. for (var _i3 = 0; _i3 < 6; _i3++) {
  12895. mipmaps = cubeImage[_i3].mipmaps;
  12896. for (var j = 0; j < mipmaps.length; j++) {
  12897. var mipmap = mipmaps[j];
  12898. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12899. if (glFormat !== null) {
  12900. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12901. } else {
  12902. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  12903. }
  12904. } else {
  12905. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12906. }
  12907. }
  12908. }
  12909. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12910. } else {
  12911. mipmaps = texture.mipmaps;
  12912. for (var _i4 = 0; _i4 < 6; _i4++) {
  12913. if (isDataTexture) {
  12914. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  12915. for (var _j = 0; _j < mipmaps.length; _j++) {
  12916. var _mipmap = mipmaps[_j];
  12917. var mipmapImage = _mipmap.image[_i4].image;
  12918. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  12919. }
  12920. } else {
  12921. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  12922. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  12923. var _mipmap2 = mipmaps[_j2];
  12924. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  12925. }
  12926. }
  12927. }
  12928. textureProperties.__maxMipLevel = mipmaps.length;
  12929. }
  12930. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12931. // We assume images for cube map have the same size.
  12932. generateMipmap(34067, texture, image.width, image.height);
  12933. }
  12934. textureProperties.__version = texture.version;
  12935. if (texture.onUpdate) texture.onUpdate(texture);
  12936. } // Render targets
  12937. // Setup storage for target texture and bind it to correct framebuffer
  12938. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  12939. var glFormat = utils.convert(renderTarget.texture.format);
  12940. var glType = utils.convert(renderTarget.texture.type);
  12941. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12942. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  12943. _gl.bindFramebuffer(36160, framebuffer);
  12944. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  12945. _gl.bindFramebuffer(36160, null);
  12946. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12947. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  12948. _gl.bindRenderbuffer(36161, renderbuffer);
  12949. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  12950. var glInternalFormat = 33189;
  12951. if (isMultisample) {
  12952. var depthTexture = renderTarget.depthTexture;
  12953. if (depthTexture && depthTexture.isDepthTexture) {
  12954. if (depthTexture.type === FloatType) {
  12955. glInternalFormat = 36012;
  12956. } else if (depthTexture.type === UnsignedIntType) {
  12957. glInternalFormat = 33190;
  12958. }
  12959. }
  12960. var samples = getRenderTargetSamples(renderTarget);
  12961. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  12962. } else {
  12963. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  12964. }
  12965. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  12966. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  12967. if (isMultisample) {
  12968. var _samples = getRenderTargetSamples(renderTarget);
  12969. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  12970. } else {
  12971. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  12972. }
  12973. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  12974. } else {
  12975. var glFormat = utils.convert(renderTarget.texture.format);
  12976. var glType = utils.convert(renderTarget.texture.type);
  12977. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12978. if (isMultisample) {
  12979. var _samples2 = getRenderTargetSamples(renderTarget);
  12980. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  12981. } else {
  12982. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  12983. }
  12984. }
  12985. _gl.bindRenderbuffer(36161, null);
  12986. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  12987. function setupDepthTexture(framebuffer, renderTarget) {
  12988. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  12989. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  12990. _gl.bindFramebuffer(36160, framebuffer);
  12991. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  12992. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  12993. } // upload an empty depth texture with framebuffer size
  12994. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  12995. renderTarget.depthTexture.image.width = renderTarget.width;
  12996. renderTarget.depthTexture.image.height = renderTarget.height;
  12997. renderTarget.depthTexture.needsUpdate = true;
  12998. }
  12999. setTexture2D(renderTarget.depthTexture, 0);
  13000. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13001. if (renderTarget.depthTexture.format === DepthFormat) {
  13002. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13003. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13004. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13005. } else {
  13006. throw new Error('Unknown depthTexture format');
  13007. }
  13008. } // Setup GL resources for a non-texture depth buffer
  13009. function setupDepthRenderbuffer(renderTarget) {
  13010. var renderTargetProperties = properties.get(renderTarget);
  13011. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13012. if (renderTarget.depthTexture) {
  13013. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13014. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13015. } else {
  13016. if (isCube) {
  13017. renderTargetProperties.__webglDepthbuffer = [];
  13018. for (var i = 0; i < 6; i++) {
  13019. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13020. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13021. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13022. }
  13023. } else {
  13024. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13025. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13026. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13027. }
  13028. }
  13029. _gl.bindFramebuffer(36160, null);
  13030. } // Set up GL resources for the render target
  13031. function setupRenderTarget(renderTarget) {
  13032. var renderTargetProperties = properties.get(renderTarget);
  13033. var textureProperties = properties.get(renderTarget.texture);
  13034. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13035. textureProperties.__webglTexture = _gl.createTexture();
  13036. info.memory.textures++;
  13037. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13038. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13039. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13040. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13041. renderTarget.texture.format = RGBAFormat;
  13042. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13043. } // Setup framebuffer
  13044. if (isCube) {
  13045. renderTargetProperties.__webglFramebuffer = [];
  13046. for (var i = 0; i < 6; i++) {
  13047. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13048. }
  13049. } else {
  13050. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13051. if (isMultisample) {
  13052. if (isWebGL2) {
  13053. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13054. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13055. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13056. var glFormat = utils.convert(renderTarget.texture.format);
  13057. var glType = utils.convert(renderTarget.texture.type);
  13058. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13059. var samples = getRenderTargetSamples(renderTarget);
  13060. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13061. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13062. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13063. _gl.bindRenderbuffer(36161, null);
  13064. if (renderTarget.depthBuffer) {
  13065. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13066. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13067. }
  13068. _gl.bindFramebuffer(36160, null);
  13069. } else {
  13070. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13071. }
  13072. }
  13073. } // Setup color buffer
  13074. if (isCube) {
  13075. state.bindTexture(34067, textureProperties.__webglTexture);
  13076. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13077. for (var _i5 = 0; _i5 < 6; _i5++) {
  13078. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13079. }
  13080. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13081. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13082. }
  13083. state.bindTexture(34067, null);
  13084. } else {
  13085. state.bindTexture(3553, textureProperties.__webglTexture);
  13086. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13087. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13088. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13089. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13090. }
  13091. state.bindTexture(3553, null);
  13092. } // Setup depth and stencil buffers
  13093. if (renderTarget.depthBuffer) {
  13094. setupDepthRenderbuffer(renderTarget);
  13095. }
  13096. }
  13097. function updateRenderTargetMipmap(renderTarget) {
  13098. var texture = renderTarget.texture;
  13099. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13100. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13101. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13102. var webglTexture = properties.get(texture).__webglTexture;
  13103. state.bindTexture(target, webglTexture);
  13104. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13105. state.bindTexture(target, null);
  13106. }
  13107. }
  13108. function updateMultisampleRenderTarget(renderTarget) {
  13109. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13110. if (isWebGL2) {
  13111. var renderTargetProperties = properties.get(renderTarget);
  13112. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13113. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13114. var width = renderTarget.width;
  13115. var height = renderTarget.height;
  13116. var mask = 16384;
  13117. if (renderTarget.depthBuffer) mask |= 256;
  13118. if (renderTarget.stencilBuffer) mask |= 1024;
  13119. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13120. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13121. } else {
  13122. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13123. }
  13124. }
  13125. }
  13126. function getRenderTargetSamples(renderTarget) {
  13127. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13128. }
  13129. function updateVideoTexture(texture) {
  13130. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13131. if (_videoTextures.get(texture) !== frame) {
  13132. _videoTextures.set(texture, frame);
  13133. texture.update();
  13134. }
  13135. } // backwards compatibility
  13136. var warnedTexture2D = false;
  13137. var warnedTextureCube = false;
  13138. function safeSetTexture2D(texture, slot) {
  13139. if (texture && texture.isWebGLRenderTarget) {
  13140. if (warnedTexture2D === false) {
  13141. console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.");
  13142. warnedTexture2D = true;
  13143. }
  13144. texture = texture.texture;
  13145. }
  13146. setTexture2D(texture, slot);
  13147. }
  13148. function safeSetTextureCube(texture, slot) {
  13149. if (texture && texture.isWebGLCubeRenderTarget) {
  13150. if (warnedTextureCube === false) {
  13151. console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.");
  13152. warnedTextureCube = true;
  13153. }
  13154. texture = texture.texture;
  13155. }
  13156. setTextureCube(texture, slot);
  13157. } //
  13158. this.allocateTextureUnit = allocateTextureUnit;
  13159. this.resetTextureUnits = resetTextureUnits;
  13160. this.setTexture2D = setTexture2D;
  13161. this.setTexture2DArray = setTexture2DArray;
  13162. this.setTexture3D = setTexture3D;
  13163. this.setTextureCube = setTextureCube;
  13164. this.setupRenderTarget = setupRenderTarget;
  13165. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13166. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13167. this.safeSetTexture2D = safeSetTexture2D;
  13168. this.safeSetTextureCube = safeSetTextureCube;
  13169. }
  13170. function WebGLUtils(gl, extensions, capabilities) {
  13171. var isWebGL2 = capabilities.isWebGL2;
  13172. function convert(p) {
  13173. var extension;
  13174. if (p === UnsignedByteType) return 5121;
  13175. if (p === UnsignedShort4444Type) return 32819;
  13176. if (p === UnsignedShort5551Type) return 32820;
  13177. if (p === UnsignedShort565Type) return 33635;
  13178. if (p === ByteType) return 5120;
  13179. if (p === ShortType) return 5122;
  13180. if (p === UnsignedShortType) return 5123;
  13181. if (p === IntType) return 5124;
  13182. if (p === UnsignedIntType) return 5125;
  13183. if (p === FloatType) return 5126;
  13184. if (p === HalfFloatType) {
  13185. if (isWebGL2) return 5131;
  13186. extension = extensions.get('OES_texture_half_float');
  13187. if (extension !== null) {
  13188. return extension.HALF_FLOAT_OES;
  13189. } else {
  13190. return null;
  13191. }
  13192. }
  13193. if (p === AlphaFormat) return 6406;
  13194. if (p === RGBFormat) return 6407;
  13195. if (p === RGBAFormat) return 6408;
  13196. if (p === LuminanceFormat) return 6409;
  13197. if (p === LuminanceAlphaFormat) return 6410;
  13198. if (p === DepthFormat) return 6402;
  13199. if (p === DepthStencilFormat) return 34041;
  13200. if (p === RedFormat) return 6403; // WebGL2 formats.
  13201. if (p === RedIntegerFormat) return 36244;
  13202. if (p === RGFormat) return 33319;
  13203. if (p === RGIntegerFormat) return 33320;
  13204. if (p === RGBIntegerFormat) return 36248;
  13205. if (p === RGBAIntegerFormat) return 36249;
  13206. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13207. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13208. if (extension !== null) {
  13209. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13210. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13211. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13212. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13213. } else {
  13214. return null;
  13215. }
  13216. }
  13217. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13218. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13219. if (extension !== null) {
  13220. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13221. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13222. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13223. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13224. } else {
  13225. return null;
  13226. }
  13227. }
  13228. if (p === RGB_ETC1_Format) {
  13229. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13230. if (extension !== null) {
  13231. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13232. } else {
  13233. return null;
  13234. }
  13235. }
  13236. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13237. extension = extensions.get('WEBGL_compressed_texture_etc');
  13238. if (extension !== null) {
  13239. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13240. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13241. }
  13242. }
  13243. 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) {
  13244. extension = extensions.get('WEBGL_compressed_texture_astc');
  13245. if (extension !== null) {
  13246. // TODO Complete?
  13247. return p;
  13248. } else {
  13249. return null;
  13250. }
  13251. }
  13252. if (p === RGBA_BPTC_Format) {
  13253. extension = extensions.get('EXT_texture_compression_bptc');
  13254. if (extension !== null) {
  13255. // TODO Complete?
  13256. return p;
  13257. } else {
  13258. return null;
  13259. }
  13260. }
  13261. if (p === UnsignedInt248Type) {
  13262. if (isWebGL2) return 34042;
  13263. extension = extensions.get('WEBGL_depth_texture');
  13264. if (extension !== null) {
  13265. return extension.UNSIGNED_INT_24_8_WEBGL;
  13266. } else {
  13267. return null;
  13268. }
  13269. }
  13270. }
  13271. return {
  13272. convert: convert
  13273. };
  13274. }
  13275. function ArrayCamera(array) {
  13276. PerspectiveCamera.call(this);
  13277. this.cameras = array || [];
  13278. }
  13279. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13280. constructor: ArrayCamera,
  13281. isArrayCamera: true
  13282. });
  13283. function Group() {
  13284. Object3D.call(this);
  13285. this.type = 'Group';
  13286. }
  13287. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13288. constructor: Group,
  13289. isGroup: true
  13290. });
  13291. function WebXRController() {
  13292. this._targetRay = null;
  13293. this._grip = null;
  13294. this._hand = null;
  13295. }
  13296. Object.assign(WebXRController.prototype, {
  13297. constructor: WebXRController,
  13298. getHandSpace: function getHandSpace() {
  13299. if (this._hand === null) {
  13300. this._hand = new Group();
  13301. this._hand.matrixAutoUpdate = false;
  13302. this._hand.visible = false;
  13303. this._hand.joints = [];
  13304. this._hand.inputState = {
  13305. pinching: false
  13306. };
  13307. if (window.XRHand) {
  13308. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13309. // The transform of this joint will be updated with the joint pose on each frame
  13310. var joint = new Group();
  13311. joint.matrixAutoUpdate = false;
  13312. joint.visible = false;
  13313. this._hand.joints.push(joint); // ??
  13314. this._hand.add(joint);
  13315. }
  13316. }
  13317. }
  13318. return this._hand;
  13319. },
  13320. getTargetRaySpace: function getTargetRaySpace() {
  13321. if (this._targetRay === null) {
  13322. this._targetRay = new Group();
  13323. this._targetRay.matrixAutoUpdate = false;
  13324. this._targetRay.visible = false;
  13325. }
  13326. return this._targetRay;
  13327. },
  13328. getGripSpace: function getGripSpace() {
  13329. if (this._grip === null) {
  13330. this._grip = new Group();
  13331. this._grip.matrixAutoUpdate = false;
  13332. this._grip.visible = false;
  13333. }
  13334. return this._grip;
  13335. },
  13336. dispatchEvent: function dispatchEvent(event) {
  13337. if (this._targetRay !== null) {
  13338. this._targetRay.dispatchEvent(event);
  13339. }
  13340. if (this._grip !== null) {
  13341. this._grip.dispatchEvent(event);
  13342. }
  13343. if (this._hand !== null) {
  13344. this._hand.dispatchEvent(event);
  13345. }
  13346. return this;
  13347. },
  13348. disconnect: function disconnect(inputSource) {
  13349. this.dispatchEvent({
  13350. type: 'disconnected',
  13351. data: inputSource
  13352. });
  13353. if (this._targetRay !== null) {
  13354. this._targetRay.visible = false;
  13355. }
  13356. if (this._grip !== null) {
  13357. this._grip.visible = false;
  13358. }
  13359. if (this._hand !== null) {
  13360. this._hand.visible = false;
  13361. }
  13362. return this;
  13363. },
  13364. update: function update(inputSource, frame, referenceSpace) {
  13365. var inputPose = null;
  13366. var gripPose = null;
  13367. var handPose = null;
  13368. var targetRay = this._targetRay;
  13369. var grip = this._grip;
  13370. var hand = this._hand;
  13371. if (inputSource) {
  13372. if (hand && inputSource.hand) {
  13373. handPose = true;
  13374. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13375. if (inputSource.hand[i]) {
  13376. // Update the joints groups with the XRJoint poses
  13377. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13378. var joint = hand.joints[i];
  13379. if (jointPose !== null) {
  13380. joint.matrix.fromArray(jointPose.transform.matrix);
  13381. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13382. joint.jointRadius = jointPose.radius;
  13383. }
  13384. joint.visible = jointPose !== null; // Custom events
  13385. // Check pinch
  13386. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13387. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13388. var distance = indexTip.position.distanceTo(thumbTip.position);
  13389. var distanceToPinch = 0.02;
  13390. var threshold = 0.005;
  13391. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13392. hand.inputState.pinching = false;
  13393. this.dispatchEvent({
  13394. type: "pinchend",
  13395. handedness: inputSource.handedness,
  13396. target: this
  13397. });
  13398. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13399. hand.inputState.pinching = true;
  13400. this.dispatchEvent({
  13401. type: "pinchstart",
  13402. handedness: inputSource.handedness,
  13403. target: this
  13404. });
  13405. }
  13406. }
  13407. }
  13408. } else {
  13409. if (targetRay !== null) {
  13410. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13411. if (inputPose !== null) {
  13412. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13413. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13414. }
  13415. }
  13416. if (grip !== null && inputSource.gripSpace) {
  13417. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13418. if (gripPose !== null) {
  13419. grip.matrix.fromArray(gripPose.transform.matrix);
  13420. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13421. }
  13422. }
  13423. }
  13424. }
  13425. if (targetRay !== null) {
  13426. targetRay.visible = inputPose !== null;
  13427. }
  13428. if (grip !== null) {
  13429. grip.visible = gripPose !== null;
  13430. }
  13431. if (hand !== null) {
  13432. hand.visible = handPose !== null;
  13433. }
  13434. return this;
  13435. }
  13436. });
  13437. function WebXRManager(renderer, gl) {
  13438. var scope = this;
  13439. var session = null;
  13440. var framebufferScaleFactor = 1.0;
  13441. var referenceSpace = null;
  13442. var referenceSpaceType = 'local-floor';
  13443. var pose = null;
  13444. var controllers = [];
  13445. var inputSourcesMap = new Map(); //
  13446. var cameraL = new PerspectiveCamera();
  13447. cameraL.layers.enable(1);
  13448. cameraL.viewport = new Vector4();
  13449. var cameraR = new PerspectiveCamera();
  13450. cameraR.layers.enable(2);
  13451. cameraR.viewport = new Vector4();
  13452. var cameras = [cameraL, cameraR];
  13453. var cameraVR = new ArrayCamera();
  13454. cameraVR.layers.enable(1);
  13455. cameraVR.layers.enable(2);
  13456. var _currentDepthNear = null;
  13457. var _currentDepthFar = null; //
  13458. this.enabled = false;
  13459. this.isPresenting = false;
  13460. this.getController = function (index) {
  13461. var controller = controllers[index];
  13462. if (controller === undefined) {
  13463. controller = new WebXRController();
  13464. controllers[index] = controller;
  13465. }
  13466. return controller.getTargetRaySpace();
  13467. };
  13468. this.getControllerGrip = function (index) {
  13469. var controller = controllers[index];
  13470. if (controller === undefined) {
  13471. controller = new WebXRController();
  13472. controllers[index] = controller;
  13473. }
  13474. return controller.getGripSpace();
  13475. };
  13476. this.getHand = function (index) {
  13477. var controller = controllers[index];
  13478. if (controller === undefined) {
  13479. controller = new WebXRController();
  13480. controllers[index] = controller;
  13481. }
  13482. return controller.getHandSpace();
  13483. }; //
  13484. function onSessionEvent(event) {
  13485. var controller = inputSourcesMap.get(event.inputSource);
  13486. if (controller) {
  13487. controller.dispatchEvent({
  13488. type: event.type,
  13489. data: event.inputSource
  13490. });
  13491. }
  13492. }
  13493. function onSessionEnd() {
  13494. inputSourcesMap.forEach(function (controller, inputSource) {
  13495. controller.disconnect(inputSource);
  13496. });
  13497. inputSourcesMap.clear(); //
  13498. renderer.setFramebuffer(null);
  13499. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13500. animation.stop();
  13501. scope.isPresenting = false;
  13502. scope.dispatchEvent({
  13503. type: 'sessionend'
  13504. });
  13505. }
  13506. function onRequestReferenceSpace(value) {
  13507. referenceSpace = value;
  13508. animation.setContext(session);
  13509. animation.start();
  13510. scope.isPresenting = true;
  13511. scope.dispatchEvent({
  13512. type: 'sessionstart'
  13513. });
  13514. }
  13515. this.setFramebufferScaleFactor = function (value) {
  13516. framebufferScaleFactor = value;
  13517. if (scope.isPresenting === true) {
  13518. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13519. }
  13520. };
  13521. this.setReferenceSpaceType = function (value) {
  13522. referenceSpaceType = value;
  13523. if (scope.isPresenting === true) {
  13524. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13525. }
  13526. };
  13527. this.getReferenceSpace = function () {
  13528. return referenceSpace;
  13529. };
  13530. this.getSession = function () {
  13531. return session;
  13532. };
  13533. this.setSession = function (value) {
  13534. session = value;
  13535. if (session !== null) {
  13536. session.addEventListener('select', onSessionEvent);
  13537. session.addEventListener('selectstart', onSessionEvent);
  13538. session.addEventListener('selectend', onSessionEvent);
  13539. session.addEventListener('squeeze', onSessionEvent);
  13540. session.addEventListener('squeezestart', onSessionEvent);
  13541. session.addEventListener('squeezeend', onSessionEvent);
  13542. session.addEventListener('end', onSessionEnd);
  13543. var attributes = gl.getContextAttributes();
  13544. if (attributes.xrCompatible !== true) {
  13545. gl.makeXRCompatible();
  13546. }
  13547. var layerInit = {
  13548. antialias: attributes.antialias,
  13549. alpha: attributes.alpha,
  13550. depth: attributes.depth,
  13551. stencil: attributes.stencil,
  13552. framebufferScaleFactor: framebufferScaleFactor
  13553. }; // eslint-disable-next-line no-undef
  13554. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13555. session.updateRenderState({
  13556. baseLayer: baseLayer
  13557. });
  13558. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13559. session.addEventListener('inputsourceschange', updateInputSources);
  13560. }
  13561. };
  13562. function updateInputSources(event) {
  13563. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13564. for (var i = 0; i < controllers.length; i++) {
  13565. inputSourcesMap.set(inputSources[i], controllers[i]);
  13566. } // Notify disconnected
  13567. for (var _i = 0; _i < event.removed.length; _i++) {
  13568. var inputSource = event.removed[_i];
  13569. var controller = inputSourcesMap.get(inputSource);
  13570. if (controller) {
  13571. controller.dispatchEvent({
  13572. type: 'disconnected',
  13573. data: inputSource
  13574. });
  13575. inputSourcesMap.delete(inputSource);
  13576. }
  13577. } // Notify connected
  13578. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13579. var _inputSource = event.added[_i2];
  13580. var _controller = inputSourcesMap.get(_inputSource);
  13581. if (_controller) {
  13582. _controller.dispatchEvent({
  13583. type: 'connected',
  13584. data: _inputSource
  13585. });
  13586. }
  13587. }
  13588. } //
  13589. var cameraLPos = new Vector3();
  13590. var cameraRPos = new Vector3();
  13591. /**
  13592. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13593. * the cameras' projection and world matrices have already been set.
  13594. * And that near and far planes are identical for both cameras.
  13595. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13596. */
  13597. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13598. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13599. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13600. var ipd = cameraLPos.distanceTo(cameraRPos);
  13601. var projL = cameraL.projectionMatrix.elements;
  13602. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13603. // most likely identical top and bottom frustum extents.
  13604. // Use the left camera for these values.
  13605. var near = projL[14] / (projL[10] - 1);
  13606. var far = projL[14] / (projL[10] + 1);
  13607. var topFov = (projL[9] + 1) / projL[5];
  13608. var bottomFov = (projL[9] - 1) / projL[5];
  13609. var leftFov = (projL[8] - 1) / projL[0];
  13610. var rightFov = (projR[8] + 1) / projR[0];
  13611. var left = near * leftFov;
  13612. var right = near * rightFov; // Calculate the new camera's position offset from the
  13613. // left camera. xOffset should be roughly half `ipd`.
  13614. var zOffset = ipd / (-leftFov + rightFov);
  13615. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13616. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13617. camera.translateX(xOffset);
  13618. camera.translateZ(zOffset);
  13619. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13620. camera.matrixWorldInverse.getInverse(camera.matrixWorld); // Find the union of the frustum values of the cameras and scale
  13621. // the values so that the near plane's position does not change in world space,
  13622. // although must now be relative to the new union camera.
  13623. var near2 = near + zOffset;
  13624. var far2 = far + zOffset;
  13625. var left2 = left - xOffset;
  13626. var right2 = right + (ipd - xOffset);
  13627. var top2 = topFov * far / far2 * near2;
  13628. var bottom2 = bottomFov * far / far2 * near2;
  13629. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13630. }
  13631. function updateCamera(camera, parent) {
  13632. if (parent === null) {
  13633. camera.matrixWorld.copy(camera.matrix);
  13634. } else {
  13635. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13636. }
  13637. camera.matrixWorldInverse.getInverse(camera.matrixWorld);
  13638. }
  13639. this.getCamera = function (camera) {
  13640. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13641. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13642. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13643. // Note that the new renderState won't apply until the next frame. See #18320
  13644. session.updateRenderState({
  13645. depthNear: cameraVR.near,
  13646. depthFar: cameraVR.far
  13647. });
  13648. _currentDepthNear = cameraVR.near;
  13649. _currentDepthFar = cameraVR.far;
  13650. }
  13651. var parent = camera.parent;
  13652. var cameras = cameraVR.cameras;
  13653. updateCamera(cameraVR, parent);
  13654. for (var i = 0; i < cameras.length; i++) {
  13655. updateCamera(cameras[i], parent);
  13656. } // update camera and its children
  13657. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13658. var children = camera.children;
  13659. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13660. children[_i3].updateMatrixWorld(true);
  13661. } // update projection matrix for proper view frustum culling
  13662. if (cameras.length === 2) {
  13663. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13664. } else {
  13665. // assume single camera setup (AR)
  13666. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13667. }
  13668. return cameraVR;
  13669. }; // Animation Loop
  13670. var onAnimationFrameCallback = null;
  13671. function onAnimationFrame(time, frame) {
  13672. pose = frame.getViewerPose(referenceSpace);
  13673. if (pose !== null) {
  13674. var views = pose.views;
  13675. var baseLayer = session.renderState.baseLayer;
  13676. renderer.setFramebuffer(baseLayer.framebuffer);
  13677. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13678. if (views.length !== cameraVR.cameras.length) {
  13679. cameraVR.cameras.length = 0;
  13680. cameraVRNeedsUpdate = true;
  13681. }
  13682. for (var i = 0; i < views.length; i++) {
  13683. var view = views[i];
  13684. var viewport = baseLayer.getViewport(view);
  13685. var camera = cameras[i];
  13686. camera.matrix.fromArray(view.transform.matrix);
  13687. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13688. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13689. if (i === 0) {
  13690. cameraVR.matrix.copy(camera.matrix);
  13691. }
  13692. if (cameraVRNeedsUpdate === true) {
  13693. cameraVR.cameras.push(camera);
  13694. }
  13695. }
  13696. } //
  13697. var inputSources = session.inputSources;
  13698. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13699. var controller = controllers[_i4];
  13700. var inputSource = inputSources[_i4];
  13701. controller.update(inputSource, frame, referenceSpace);
  13702. }
  13703. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13704. }
  13705. var animation = new WebGLAnimation();
  13706. animation.setAnimationLoop(onAnimationFrame);
  13707. this.setAnimationLoop = function (callback) {
  13708. onAnimationFrameCallback = callback;
  13709. };
  13710. this.dispose = function () {};
  13711. }
  13712. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13713. function WebGLMaterials(properties) {
  13714. function refreshFogUniforms(uniforms, fog) {
  13715. uniforms.fogColor.value.copy(fog.color);
  13716. if (fog.isFog) {
  13717. uniforms.fogNear.value = fog.near;
  13718. uniforms.fogFar.value = fog.far;
  13719. } else if (fog.isFogExp2) {
  13720. uniforms.fogDensity.value = fog.density;
  13721. }
  13722. }
  13723. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13724. if (material.isMeshBasicMaterial) {
  13725. refreshUniformsCommon(uniforms, material);
  13726. } else if (material.isMeshLambertMaterial) {
  13727. refreshUniformsCommon(uniforms, material);
  13728. refreshUniformsLambert(uniforms, material);
  13729. } else if (material.isMeshToonMaterial) {
  13730. refreshUniformsCommon(uniforms, material);
  13731. refreshUniformsToon(uniforms, material);
  13732. } else if (material.isMeshPhongMaterial) {
  13733. refreshUniformsCommon(uniforms, material);
  13734. refreshUniformsPhong(uniforms, material);
  13735. } else if (material.isMeshStandardMaterial) {
  13736. refreshUniformsCommon(uniforms, material);
  13737. if (material.isMeshPhysicalMaterial) {
  13738. refreshUniformsPhysical(uniforms, material);
  13739. } else {
  13740. refreshUniformsStandard(uniforms, material);
  13741. }
  13742. } else if (material.isMeshMatcapMaterial) {
  13743. refreshUniformsCommon(uniforms, material);
  13744. refreshUniformsMatcap(uniforms, material);
  13745. } else if (material.isMeshDepthMaterial) {
  13746. refreshUniformsCommon(uniforms, material);
  13747. refreshUniformsDepth(uniforms, material);
  13748. } else if (material.isMeshDistanceMaterial) {
  13749. refreshUniformsCommon(uniforms, material);
  13750. refreshUniformsDistance(uniforms, material);
  13751. } else if (material.isMeshNormalMaterial) {
  13752. refreshUniformsCommon(uniforms, material);
  13753. refreshUniformsNormal(uniforms, material);
  13754. } else if (material.isLineBasicMaterial) {
  13755. refreshUniformsLine(uniforms, material);
  13756. if (material.isLineDashedMaterial) {
  13757. refreshUniformsDash(uniforms, material);
  13758. }
  13759. } else if (material.isPointsMaterial) {
  13760. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  13761. } else if (material.isSpriteMaterial) {
  13762. refreshUniformsSprites(uniforms, material);
  13763. } else if (material.isShadowMaterial) {
  13764. uniforms.color.value.copy(material.color);
  13765. uniforms.opacity.value = material.opacity;
  13766. } else if (material.isShaderMaterial) {
  13767. material.uniformsNeedUpdate = false; // #15581
  13768. }
  13769. }
  13770. function refreshUniformsCommon(uniforms, material) {
  13771. uniforms.opacity.value = material.opacity;
  13772. if (material.color) {
  13773. uniforms.diffuse.value.copy(material.color);
  13774. }
  13775. if (material.emissive) {
  13776. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  13777. }
  13778. if (material.map) {
  13779. uniforms.map.value = material.map;
  13780. }
  13781. if (material.alphaMap) {
  13782. uniforms.alphaMap.value = material.alphaMap;
  13783. }
  13784. if (material.specularMap) {
  13785. uniforms.specularMap.value = material.specularMap;
  13786. }
  13787. var envMap = properties.get(material).envMap;
  13788. if (envMap) {
  13789. uniforms.envMap.value = envMap;
  13790. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  13791. uniforms.reflectivity.value = material.reflectivity;
  13792. uniforms.refractionRatio.value = material.refractionRatio;
  13793. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  13794. if (maxMipLevel !== undefined) {
  13795. uniforms.maxMipLevel.value = maxMipLevel;
  13796. }
  13797. }
  13798. if (material.lightMap) {
  13799. uniforms.lightMap.value = material.lightMap;
  13800. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13801. }
  13802. if (material.aoMap) {
  13803. uniforms.aoMap.value = material.aoMap;
  13804. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13805. } // uv repeat and offset setting priorities
  13806. // 1. color map
  13807. // 2. specular map
  13808. // 3. displacementMap map
  13809. // 4. normal map
  13810. // 5. bump map
  13811. // 6. roughnessMap map
  13812. // 7. metalnessMap map
  13813. // 8. alphaMap map
  13814. // 9. emissiveMap map
  13815. // 10. clearcoat map
  13816. // 11. clearcoat normal map
  13817. // 12. clearcoat roughnessMap map
  13818. var uvScaleMap;
  13819. if (material.map) {
  13820. uvScaleMap = material.map;
  13821. } else if (material.specularMap) {
  13822. uvScaleMap = material.specularMap;
  13823. } else if (material.displacementMap) {
  13824. uvScaleMap = material.displacementMap;
  13825. } else if (material.normalMap) {
  13826. uvScaleMap = material.normalMap;
  13827. } else if (material.bumpMap) {
  13828. uvScaleMap = material.bumpMap;
  13829. } else if (material.roughnessMap) {
  13830. uvScaleMap = material.roughnessMap;
  13831. } else if (material.metalnessMap) {
  13832. uvScaleMap = material.metalnessMap;
  13833. } else if (material.alphaMap) {
  13834. uvScaleMap = material.alphaMap;
  13835. } else if (material.emissiveMap) {
  13836. uvScaleMap = material.emissiveMap;
  13837. } else if (material.clearcoatMap) {
  13838. uvScaleMap = material.clearcoatMap;
  13839. } else if (material.clearcoatNormalMap) {
  13840. uvScaleMap = material.clearcoatNormalMap;
  13841. } else if (material.clearcoatRoughnessMap) {
  13842. uvScaleMap = material.clearcoatRoughnessMap;
  13843. }
  13844. if (uvScaleMap !== undefined) {
  13845. // backwards compatibility
  13846. if (uvScaleMap.isWebGLRenderTarget) {
  13847. uvScaleMap = uvScaleMap.texture;
  13848. }
  13849. if (uvScaleMap.matrixAutoUpdate === true) {
  13850. uvScaleMap.updateMatrix();
  13851. }
  13852. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13853. } // uv repeat and offset setting priorities for uv2
  13854. // 1. ao map
  13855. // 2. light map
  13856. var uv2ScaleMap;
  13857. if (material.aoMap) {
  13858. uv2ScaleMap = material.aoMap;
  13859. } else if (material.lightMap) {
  13860. uv2ScaleMap = material.lightMap;
  13861. }
  13862. if (uv2ScaleMap !== undefined) {
  13863. // backwards compatibility
  13864. if (uv2ScaleMap.isWebGLRenderTarget) {
  13865. uv2ScaleMap = uv2ScaleMap.texture;
  13866. }
  13867. if (uv2ScaleMap.matrixAutoUpdate === true) {
  13868. uv2ScaleMap.updateMatrix();
  13869. }
  13870. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  13871. }
  13872. }
  13873. function refreshUniformsLine(uniforms, material) {
  13874. uniforms.diffuse.value.copy(material.color);
  13875. uniforms.opacity.value = material.opacity;
  13876. }
  13877. function refreshUniformsDash(uniforms, material) {
  13878. uniforms.dashSize.value = material.dashSize;
  13879. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13880. uniforms.scale.value = material.scale;
  13881. }
  13882. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  13883. uniforms.diffuse.value.copy(material.color);
  13884. uniforms.opacity.value = material.opacity;
  13885. uniforms.size.value = material.size * pixelRatio;
  13886. uniforms.scale.value = height * 0.5;
  13887. if (material.map) {
  13888. uniforms.map.value = material.map;
  13889. }
  13890. if (material.alphaMap) {
  13891. uniforms.alphaMap.value = material.alphaMap;
  13892. } // uv repeat and offset setting priorities
  13893. // 1. color map
  13894. // 2. alpha map
  13895. var uvScaleMap;
  13896. if (material.map) {
  13897. uvScaleMap = material.map;
  13898. } else if (material.alphaMap) {
  13899. uvScaleMap = material.alphaMap;
  13900. }
  13901. if (uvScaleMap !== undefined) {
  13902. if (uvScaleMap.matrixAutoUpdate === true) {
  13903. uvScaleMap.updateMatrix();
  13904. }
  13905. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13906. }
  13907. }
  13908. function refreshUniformsSprites(uniforms, material) {
  13909. uniforms.diffuse.value.copy(material.color);
  13910. uniforms.opacity.value = material.opacity;
  13911. uniforms.rotation.value = material.rotation;
  13912. if (material.map) {
  13913. uniforms.map.value = material.map;
  13914. }
  13915. if (material.alphaMap) {
  13916. uniforms.alphaMap.value = material.alphaMap;
  13917. } // uv repeat and offset setting priorities
  13918. // 1. color map
  13919. // 2. alpha map
  13920. var uvScaleMap;
  13921. if (material.map) {
  13922. uvScaleMap = material.map;
  13923. } else if (material.alphaMap) {
  13924. uvScaleMap = material.alphaMap;
  13925. }
  13926. if (uvScaleMap !== undefined) {
  13927. if (uvScaleMap.matrixAutoUpdate === true) {
  13928. uvScaleMap.updateMatrix();
  13929. }
  13930. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13931. }
  13932. }
  13933. function refreshUniformsLambert(uniforms, material) {
  13934. if (material.emissiveMap) {
  13935. uniforms.emissiveMap.value = material.emissiveMap;
  13936. }
  13937. }
  13938. function refreshUniformsPhong(uniforms, material) {
  13939. uniforms.specular.value.copy(material.specular);
  13940. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  13941. if (material.emissiveMap) {
  13942. uniforms.emissiveMap.value = material.emissiveMap;
  13943. }
  13944. if (material.bumpMap) {
  13945. uniforms.bumpMap.value = material.bumpMap;
  13946. uniforms.bumpScale.value = material.bumpScale;
  13947. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13948. }
  13949. if (material.normalMap) {
  13950. uniforms.normalMap.value = material.normalMap;
  13951. uniforms.normalScale.value.copy(material.normalScale);
  13952. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13953. }
  13954. if (material.displacementMap) {
  13955. uniforms.displacementMap.value = material.displacementMap;
  13956. uniforms.displacementScale.value = material.displacementScale;
  13957. uniforms.displacementBias.value = material.displacementBias;
  13958. }
  13959. }
  13960. function refreshUniformsToon(uniforms, material) {
  13961. if (material.gradientMap) {
  13962. uniforms.gradientMap.value = material.gradientMap;
  13963. }
  13964. if (material.emissiveMap) {
  13965. uniforms.emissiveMap.value = material.emissiveMap;
  13966. }
  13967. if (material.bumpMap) {
  13968. uniforms.bumpMap.value = material.bumpMap;
  13969. uniforms.bumpScale.value = material.bumpScale;
  13970. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13971. }
  13972. if (material.normalMap) {
  13973. uniforms.normalMap.value = material.normalMap;
  13974. uniforms.normalScale.value.copy(material.normalScale);
  13975. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13976. }
  13977. if (material.displacementMap) {
  13978. uniforms.displacementMap.value = material.displacementMap;
  13979. uniforms.displacementScale.value = material.displacementScale;
  13980. uniforms.displacementBias.value = material.displacementBias;
  13981. }
  13982. }
  13983. function refreshUniformsStandard(uniforms, material) {
  13984. uniforms.roughness.value = material.roughness;
  13985. uniforms.metalness.value = material.metalness;
  13986. if (material.roughnessMap) {
  13987. uniforms.roughnessMap.value = material.roughnessMap;
  13988. }
  13989. if (material.metalnessMap) {
  13990. uniforms.metalnessMap.value = material.metalnessMap;
  13991. }
  13992. if (material.emissiveMap) {
  13993. uniforms.emissiveMap.value = material.emissiveMap;
  13994. }
  13995. if (material.bumpMap) {
  13996. uniforms.bumpMap.value = material.bumpMap;
  13997. uniforms.bumpScale.value = material.bumpScale;
  13998. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13999. }
  14000. if (material.normalMap) {
  14001. uniforms.normalMap.value = material.normalMap;
  14002. uniforms.normalScale.value.copy(material.normalScale);
  14003. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14004. }
  14005. if (material.displacementMap) {
  14006. uniforms.displacementMap.value = material.displacementMap;
  14007. uniforms.displacementScale.value = material.displacementScale;
  14008. uniforms.displacementBias.value = material.displacementBias;
  14009. }
  14010. var envMap = properties.get(material).envMap;
  14011. if (envMap) {
  14012. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14013. uniforms.envMapIntensity.value = material.envMapIntensity;
  14014. }
  14015. }
  14016. function refreshUniformsPhysical(uniforms, material) {
  14017. refreshUniformsStandard(uniforms, material);
  14018. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14019. uniforms.clearcoat.value = material.clearcoat;
  14020. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14021. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14022. if (material.clearcoatMap) {
  14023. uniforms.clearcoatMap.value = material.clearcoatMap;
  14024. }
  14025. if (material.clearcoatRoughnessMap) {
  14026. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14027. }
  14028. if (material.clearcoatNormalMap) {
  14029. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14030. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14031. if (material.side === BackSide) {
  14032. uniforms.clearcoatNormalScale.value.negate();
  14033. }
  14034. }
  14035. uniforms.transmission.value = material.transmission;
  14036. if (material.transmissionMap) {
  14037. uniforms.transmissionMap.value = material.transmissionMap;
  14038. }
  14039. }
  14040. function refreshUniformsMatcap(uniforms, material) {
  14041. if (material.matcap) {
  14042. uniforms.matcap.value = material.matcap;
  14043. }
  14044. if (material.bumpMap) {
  14045. uniforms.bumpMap.value = material.bumpMap;
  14046. uniforms.bumpScale.value = material.bumpScale;
  14047. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14048. }
  14049. if (material.normalMap) {
  14050. uniforms.normalMap.value = material.normalMap;
  14051. uniforms.normalScale.value.copy(material.normalScale);
  14052. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14053. }
  14054. if (material.displacementMap) {
  14055. uniforms.displacementMap.value = material.displacementMap;
  14056. uniforms.displacementScale.value = material.displacementScale;
  14057. uniforms.displacementBias.value = material.displacementBias;
  14058. }
  14059. }
  14060. function refreshUniformsDepth(uniforms, material) {
  14061. if (material.displacementMap) {
  14062. uniforms.displacementMap.value = material.displacementMap;
  14063. uniforms.displacementScale.value = material.displacementScale;
  14064. uniforms.displacementBias.value = material.displacementBias;
  14065. }
  14066. }
  14067. function refreshUniformsDistance(uniforms, material) {
  14068. if (material.displacementMap) {
  14069. uniforms.displacementMap.value = material.displacementMap;
  14070. uniforms.displacementScale.value = material.displacementScale;
  14071. uniforms.displacementBias.value = material.displacementBias;
  14072. }
  14073. uniforms.referencePosition.value.copy(material.referencePosition);
  14074. uniforms.nearDistance.value = material.nearDistance;
  14075. uniforms.farDistance.value = material.farDistance;
  14076. }
  14077. function refreshUniformsNormal(uniforms, material) {
  14078. if (material.bumpMap) {
  14079. uniforms.bumpMap.value = material.bumpMap;
  14080. uniforms.bumpScale.value = material.bumpScale;
  14081. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14082. }
  14083. if (material.normalMap) {
  14084. uniforms.normalMap.value = material.normalMap;
  14085. uniforms.normalScale.value.copy(material.normalScale);
  14086. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14087. }
  14088. if (material.displacementMap) {
  14089. uniforms.displacementMap.value = material.displacementMap;
  14090. uniforms.displacementScale.value = material.displacementScale;
  14091. uniforms.displacementBias.value = material.displacementBias;
  14092. }
  14093. }
  14094. return {
  14095. refreshFogUniforms: refreshFogUniforms,
  14096. refreshMaterialUniforms: refreshMaterialUniforms
  14097. };
  14098. }
  14099. function WebGLRenderer(parameters) {
  14100. parameters = parameters || {};
  14101. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'),
  14102. _context = parameters.context !== undefined ? parameters.context : null,
  14103. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14104. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14105. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14106. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14107. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14108. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14109. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14110. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14111. var currentRenderList = null;
  14112. var currentRenderState = null; // public properties
  14113. this.domElement = _canvas; // Debug configuration container
  14114. this.debug = {
  14115. /**
  14116. * Enables error checking and reporting when shader programs are being compiled
  14117. * @type {boolean}
  14118. */
  14119. checkShaderErrors: true
  14120. }; // clearing
  14121. this.autoClear = true;
  14122. this.autoClearColor = true;
  14123. this.autoClearDepth = true;
  14124. this.autoClearStencil = true; // scene graph
  14125. this.sortObjects = true; // user-defined clipping
  14126. this.clippingPlanes = [];
  14127. this.localClippingEnabled = false; // physically based shading
  14128. this.gammaFactor = 2.0; // for backwards compatibility
  14129. this.outputEncoding = LinearEncoding; // physical lights
  14130. this.physicallyCorrectLights = false; // tone mapping
  14131. this.toneMapping = NoToneMapping;
  14132. this.toneMappingExposure = 1.0; // morphs
  14133. this.maxMorphTargets = 8;
  14134. this.maxMorphNormals = 4; // internal properties
  14135. var _this = this;
  14136. var _isContextLost = false; // internal state cache
  14137. var _framebuffer = null;
  14138. var _currentActiveCubeFace = 0;
  14139. var _currentActiveMipmapLevel = 0;
  14140. var _currentRenderTarget = null;
  14141. var _currentFramebuffer = null;
  14142. var _currentMaterialId = -1;
  14143. var _currentCamera = null;
  14144. var _currentArrayCamera = null;
  14145. var _currentViewport = new Vector4();
  14146. var _currentScissor = new Vector4();
  14147. var _currentScissorTest = null; //
  14148. var _width = _canvas.width;
  14149. var _height = _canvas.height;
  14150. var _pixelRatio = 1;
  14151. var _opaqueSort = null;
  14152. var _transparentSort = null;
  14153. var _viewport = new Vector4(0, 0, _width, _height);
  14154. var _scissor = new Vector4(0, 0, _width, _height);
  14155. var _scissorTest = false; // frustum
  14156. var _frustum = new Frustum(); // clipping
  14157. var _clippingEnabled = false;
  14158. var _localClippingEnabled = false; // camera matrices cache
  14159. var _projScreenMatrix = new Matrix4();
  14160. var _vector3 = new Vector3();
  14161. var _emptyScene = {
  14162. background: null,
  14163. fog: null,
  14164. environment: null,
  14165. overrideMaterial: null,
  14166. isScene: true
  14167. };
  14168. function getTargetPixelRatio() {
  14169. return _currentRenderTarget === null ? _pixelRatio : 1;
  14170. } // initialize
  14171. var _gl = _context;
  14172. function getContext(contextNames, contextAttributes) {
  14173. for (var i = 0; i < contextNames.length; i++) {
  14174. var contextName = contextNames[i];
  14175. var context = _canvas.getContext(contextName, contextAttributes);
  14176. if (context !== null) return context;
  14177. }
  14178. return null;
  14179. }
  14180. try {
  14181. var contextAttributes = {
  14182. alpha: _alpha,
  14183. depth: _depth,
  14184. stencil: _stencil,
  14185. antialias: _antialias,
  14186. premultipliedAlpha: _premultipliedAlpha,
  14187. preserveDrawingBuffer: _preserveDrawingBuffer,
  14188. powerPreference: _powerPreference,
  14189. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14190. }; // event listeners must be registered before WebGL context is created, see #12753
  14191. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14192. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14193. if (_gl === null) {
  14194. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14195. if (_this.isWebGL1Renderer === true) {
  14196. contextNames.shift();
  14197. }
  14198. _gl = getContext(contextNames, contextAttributes);
  14199. if (_gl === null) {
  14200. if (getContext(contextNames)) {
  14201. throw new Error('Error creating WebGL context with your selected attributes.');
  14202. } else {
  14203. throw new Error('Error creating WebGL context.');
  14204. }
  14205. }
  14206. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14207. if (_gl.getShaderPrecisionFormat === undefined) {
  14208. _gl.getShaderPrecisionFormat = function () {
  14209. return {
  14210. 'rangeMin': 1,
  14211. 'rangeMax': 1,
  14212. 'precision': 1
  14213. };
  14214. };
  14215. }
  14216. } catch (error) {
  14217. console.error('THREE.WebGLRenderer: ' + error.message);
  14218. throw error;
  14219. }
  14220. var extensions, capabilities, state, info;
  14221. var properties, textures, cubemaps, attributes, geometries, objects;
  14222. var programCache, materials, renderLists, renderStates, clipping;
  14223. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14224. var utils, bindingStates;
  14225. function initGLContext() {
  14226. extensions = new WebGLExtensions(_gl);
  14227. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14228. if (capabilities.isWebGL2 === false) {
  14229. extensions.get('WEBGL_depth_texture');
  14230. extensions.get('OES_texture_float');
  14231. extensions.get('OES_texture_half_float');
  14232. extensions.get('OES_texture_half_float_linear');
  14233. extensions.get('OES_standard_derivatives');
  14234. extensions.get('OES_element_index_uint');
  14235. extensions.get('OES_vertex_array_object');
  14236. extensions.get('ANGLE_instanced_arrays');
  14237. }
  14238. extensions.get('OES_texture_float_linear');
  14239. utils = new WebGLUtils(_gl, extensions, capabilities);
  14240. state = new WebGLState(_gl, extensions, capabilities);
  14241. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14242. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14243. info = new WebGLInfo(_gl);
  14244. properties = new WebGLProperties();
  14245. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14246. cubemaps = new WebGLCubeMaps(_this);
  14247. attributes = new WebGLAttributes(_gl, capabilities);
  14248. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14249. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14250. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14251. morphtargets = new WebGLMorphtargets(_gl);
  14252. clipping = new WebGLClipping(properties);
  14253. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14254. materials = new WebGLMaterials(properties);
  14255. renderLists = new WebGLRenderLists(properties);
  14256. renderStates = new WebGLRenderStates();
  14257. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14258. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14259. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14260. info.programs = programCache.programs;
  14261. _this.capabilities = capabilities;
  14262. _this.extensions = extensions;
  14263. _this.properties = properties;
  14264. _this.renderLists = renderLists;
  14265. _this.state = state;
  14266. _this.info = info;
  14267. }
  14268. initGLContext(); // xr
  14269. var xr = new WebXRManager(_this, _gl);
  14270. this.xr = xr; // shadow map
  14271. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14272. this.shadowMap = shadowMap; // API
  14273. this.getContext = function () {
  14274. return _gl;
  14275. };
  14276. this.getContextAttributes = function () {
  14277. return _gl.getContextAttributes();
  14278. };
  14279. this.forceContextLoss = function () {
  14280. var extension = extensions.get('WEBGL_lose_context');
  14281. if (extension) extension.loseContext();
  14282. };
  14283. this.forceContextRestore = function () {
  14284. var extension = extensions.get('WEBGL_lose_context');
  14285. if (extension) extension.restoreContext();
  14286. };
  14287. this.getPixelRatio = function () {
  14288. return _pixelRatio;
  14289. };
  14290. this.setPixelRatio = function (value) {
  14291. if (value === undefined) return;
  14292. _pixelRatio = value;
  14293. this.setSize(_width, _height, false);
  14294. };
  14295. this.getSize = function (target) {
  14296. if (target === undefined) {
  14297. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14298. target = new Vector2();
  14299. }
  14300. return target.set(_width, _height);
  14301. };
  14302. this.setSize = function (width, height, updateStyle) {
  14303. if (xr.isPresenting) {
  14304. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14305. return;
  14306. }
  14307. _width = width;
  14308. _height = height;
  14309. _canvas.width = Math.floor(width * _pixelRatio);
  14310. _canvas.height = Math.floor(height * _pixelRatio);
  14311. if (updateStyle !== false) {
  14312. _canvas.style.width = width + 'px';
  14313. _canvas.style.height = height + 'px';
  14314. }
  14315. this.setViewport(0, 0, width, height);
  14316. };
  14317. this.getDrawingBufferSize = function (target) {
  14318. if (target === undefined) {
  14319. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14320. target = new Vector2();
  14321. }
  14322. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14323. };
  14324. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14325. _width = width;
  14326. _height = height;
  14327. _pixelRatio = pixelRatio;
  14328. _canvas.width = Math.floor(width * pixelRatio);
  14329. _canvas.height = Math.floor(height * pixelRatio);
  14330. this.setViewport(0, 0, width, height);
  14331. };
  14332. this.getCurrentViewport = function (target) {
  14333. if (target === undefined) {
  14334. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14335. target = new Vector4();
  14336. }
  14337. return target.copy(_currentViewport);
  14338. };
  14339. this.getViewport = function (target) {
  14340. return target.copy(_viewport);
  14341. };
  14342. this.setViewport = function (x, y, width, height) {
  14343. if (x.isVector4) {
  14344. _viewport.set(x.x, x.y, x.z, x.w);
  14345. } else {
  14346. _viewport.set(x, y, width, height);
  14347. }
  14348. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14349. };
  14350. this.getScissor = function (target) {
  14351. return target.copy(_scissor);
  14352. };
  14353. this.setScissor = function (x, y, width, height) {
  14354. if (x.isVector4) {
  14355. _scissor.set(x.x, x.y, x.z, x.w);
  14356. } else {
  14357. _scissor.set(x, y, width, height);
  14358. }
  14359. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14360. };
  14361. this.getScissorTest = function () {
  14362. return _scissorTest;
  14363. };
  14364. this.setScissorTest = function (boolean) {
  14365. state.setScissorTest(_scissorTest = boolean);
  14366. };
  14367. this.setOpaqueSort = function (method) {
  14368. _opaqueSort = method;
  14369. };
  14370. this.setTransparentSort = function (method) {
  14371. _transparentSort = method;
  14372. }; // Clearing
  14373. this.getClearColor = function () {
  14374. return background.getClearColor();
  14375. };
  14376. this.setClearColor = function () {
  14377. background.setClearColor.apply(background, arguments);
  14378. };
  14379. this.getClearAlpha = function () {
  14380. return background.getClearAlpha();
  14381. };
  14382. this.setClearAlpha = function () {
  14383. background.setClearAlpha.apply(background, arguments);
  14384. };
  14385. this.clear = function (color, depth, stencil) {
  14386. var bits = 0;
  14387. if (color === undefined || color) bits |= 16384;
  14388. if (depth === undefined || depth) bits |= 256;
  14389. if (stencil === undefined || stencil) bits |= 1024;
  14390. _gl.clear(bits);
  14391. };
  14392. this.clearColor = function () {
  14393. this.clear(true, false, false);
  14394. };
  14395. this.clearDepth = function () {
  14396. this.clear(false, true, false);
  14397. };
  14398. this.clearStencil = function () {
  14399. this.clear(false, false, true);
  14400. }; //
  14401. this.dispose = function () {
  14402. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14403. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14404. renderLists.dispose();
  14405. renderStates.dispose();
  14406. properties.dispose();
  14407. cubemaps.dispose();
  14408. objects.dispose();
  14409. bindingStates.dispose();
  14410. xr.dispose();
  14411. animation.stop();
  14412. }; // Events
  14413. function onContextLost(event) {
  14414. event.preventDefault();
  14415. console.log('THREE.WebGLRenderer: Context Lost.');
  14416. _isContextLost = true;
  14417. }
  14418. function onContextRestore()
  14419. /* event */
  14420. {
  14421. console.log('THREE.WebGLRenderer: Context Restored.');
  14422. _isContextLost = false;
  14423. initGLContext();
  14424. }
  14425. function onMaterialDispose(event) {
  14426. var material = event.target;
  14427. material.removeEventListener('dispose', onMaterialDispose);
  14428. deallocateMaterial(material);
  14429. } // Buffer deallocation
  14430. function deallocateMaterial(material) {
  14431. releaseMaterialProgramReference(material);
  14432. properties.remove(material);
  14433. }
  14434. function releaseMaterialProgramReference(material) {
  14435. var programInfo = properties.get(material).program;
  14436. if (programInfo !== undefined) {
  14437. programCache.releaseProgram(programInfo);
  14438. }
  14439. } // Buffer rendering
  14440. function renderObjectImmediate(object, program) {
  14441. object.render(function (object) {
  14442. _this.renderBufferImmediate(object, program);
  14443. });
  14444. }
  14445. this.renderBufferImmediate = function (object, program) {
  14446. bindingStates.initAttributes();
  14447. var buffers = properties.get(object);
  14448. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14449. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14450. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14451. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14452. var programAttributes = program.getAttributes();
  14453. if (object.hasPositions) {
  14454. _gl.bindBuffer(34962, buffers.position);
  14455. _gl.bufferData(34962, object.positionArray, 35048);
  14456. bindingStates.enableAttribute(programAttributes.position);
  14457. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14458. }
  14459. if (object.hasNormals) {
  14460. _gl.bindBuffer(34962, buffers.normal);
  14461. _gl.bufferData(34962, object.normalArray, 35048);
  14462. bindingStates.enableAttribute(programAttributes.normal);
  14463. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14464. }
  14465. if (object.hasUvs) {
  14466. _gl.bindBuffer(34962, buffers.uv);
  14467. _gl.bufferData(34962, object.uvArray, 35048);
  14468. bindingStates.enableAttribute(programAttributes.uv);
  14469. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14470. }
  14471. if (object.hasColors) {
  14472. _gl.bindBuffer(34962, buffers.color);
  14473. _gl.bufferData(34962, object.colorArray, 35048);
  14474. bindingStates.enableAttribute(programAttributes.color);
  14475. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14476. }
  14477. bindingStates.disableUnusedAttributes();
  14478. _gl.drawArrays(4, 0, object.count);
  14479. object.count = 0;
  14480. };
  14481. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14482. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14483. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14484. var program = setProgram(camera, scene, material, object);
  14485. state.setMaterial(material, frontFaceCW); //
  14486. var index = geometry.index;
  14487. var position = geometry.attributes.position; //
  14488. if (index === null) {
  14489. if (position === undefined || position.count === 0) return;
  14490. } else if (index.count === 0) {
  14491. return;
  14492. } //
  14493. var rangeFactor = 1;
  14494. if (material.wireframe === true) {
  14495. index = geometries.getWireframeAttribute(geometry);
  14496. rangeFactor = 2;
  14497. }
  14498. if (material.morphTargets || material.morphNormals) {
  14499. morphtargets.update(object, geometry, material, program);
  14500. }
  14501. bindingStates.setup(object, material, program, geometry, index);
  14502. var attribute;
  14503. var renderer = bufferRenderer;
  14504. if (index !== null) {
  14505. attribute = attributes.get(index);
  14506. renderer = indexedBufferRenderer;
  14507. renderer.setIndex(attribute);
  14508. } //
  14509. var dataCount = index !== null ? index.count : position.count;
  14510. var rangeStart = geometry.drawRange.start * rangeFactor;
  14511. var rangeCount = geometry.drawRange.count * rangeFactor;
  14512. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14513. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14514. var drawStart = Math.max(rangeStart, groupStart);
  14515. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14516. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14517. if (drawCount === 0) return; //
  14518. if (object.isMesh) {
  14519. if (material.wireframe === true) {
  14520. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14521. renderer.setMode(1);
  14522. } else {
  14523. renderer.setMode(4);
  14524. }
  14525. } else if (object.isLine) {
  14526. var lineWidth = material.linewidth;
  14527. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14528. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14529. if (object.isLineSegments) {
  14530. renderer.setMode(1);
  14531. } else if (object.isLineLoop) {
  14532. renderer.setMode(2);
  14533. } else {
  14534. renderer.setMode(3);
  14535. }
  14536. } else if (object.isPoints) {
  14537. renderer.setMode(0);
  14538. } else if (object.isSprite) {
  14539. renderer.setMode(4);
  14540. }
  14541. if (object.isInstancedMesh) {
  14542. renderer.renderInstances(drawStart, drawCount, object.count);
  14543. } else if (geometry.isInstancedBufferGeometry) {
  14544. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14545. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14546. } else {
  14547. renderer.render(drawStart, drawCount);
  14548. }
  14549. }; // Compile
  14550. this.compile = function (scene, camera) {
  14551. currentRenderState = renderStates.get(scene, camera);
  14552. currentRenderState.init();
  14553. scene.traverseVisible(function (object) {
  14554. if (object.isLight && object.layers.test(camera.layers)) {
  14555. currentRenderState.pushLight(object);
  14556. if (object.castShadow) {
  14557. currentRenderState.pushShadow(object);
  14558. }
  14559. }
  14560. });
  14561. currentRenderState.setupLights(camera);
  14562. var compiled = new WeakMap();
  14563. scene.traverse(function (object) {
  14564. var material = object.material;
  14565. if (material) {
  14566. if (Array.isArray(material)) {
  14567. for (var i = 0; i < material.length; i++) {
  14568. var material2 = material[i];
  14569. if (compiled.has(material2) === false) {
  14570. initMaterial(material2, scene, object);
  14571. compiled.set(material2);
  14572. }
  14573. }
  14574. } else if (compiled.has(material) === false) {
  14575. initMaterial(material, scene, object);
  14576. compiled.set(material);
  14577. }
  14578. }
  14579. });
  14580. }; // Animation Loop
  14581. var onAnimationFrameCallback = null;
  14582. function onAnimationFrame(time) {
  14583. if (xr.isPresenting) return;
  14584. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14585. }
  14586. var animation = new WebGLAnimation();
  14587. animation.setAnimationLoop(onAnimationFrame);
  14588. if (typeof window !== 'undefined') animation.setContext(window);
  14589. this.setAnimationLoop = function (callback) {
  14590. onAnimationFrameCallback = callback;
  14591. xr.setAnimationLoop(callback);
  14592. callback === null ? animation.stop() : animation.start();
  14593. }; // Rendering
  14594. this.render = function (scene, camera) {
  14595. var renderTarget, forceClear;
  14596. if (arguments[2] !== undefined) {
  14597. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14598. renderTarget = arguments[2];
  14599. }
  14600. if (arguments[3] !== undefined) {
  14601. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14602. forceClear = arguments[3];
  14603. }
  14604. if (camera !== undefined && camera.isCamera !== true) {
  14605. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14606. return;
  14607. }
  14608. if (_isContextLost === true) return; // reset caching for this frame
  14609. bindingStates.resetDefaultState();
  14610. _currentMaterialId = -1;
  14611. _currentCamera = null; // update scene graph
  14612. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14613. if (camera.parent === null) camera.updateMatrixWorld();
  14614. if (xr.enabled === true && xr.isPresenting === true) {
  14615. camera = xr.getCamera(camera);
  14616. } //
  14617. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14618. currentRenderState = renderStates.get(scene, camera);
  14619. currentRenderState.init();
  14620. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14621. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14622. _localClippingEnabled = this.localClippingEnabled;
  14623. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14624. currentRenderList = renderLists.get(scene, camera);
  14625. currentRenderList.init();
  14626. projectObject(scene, camera, 0, _this.sortObjects);
  14627. currentRenderList.finish();
  14628. if (_this.sortObjects === true) {
  14629. currentRenderList.sort(_opaqueSort, _transparentSort);
  14630. } //
  14631. if (_clippingEnabled === true) clipping.beginShadows();
  14632. var shadowsArray = currentRenderState.state.shadowsArray;
  14633. shadowMap.render(shadowsArray, scene, camera);
  14634. currentRenderState.setupLights(camera);
  14635. if (_clippingEnabled === true) clipping.endShadows(); //
  14636. if (this.info.autoReset === true) this.info.reset();
  14637. if (renderTarget !== undefined) {
  14638. this.setRenderTarget(renderTarget);
  14639. } //
  14640. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14641. var opaqueObjects = currentRenderList.opaque;
  14642. var transparentObjects = currentRenderList.transparent;
  14643. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14644. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14645. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14646. if (_currentRenderTarget !== null) {
  14647. // Generate mipmap if we're using any kind of mipmap filtering
  14648. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14649. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14650. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14651. state.buffers.depth.setTest(true);
  14652. state.buffers.depth.setMask(true);
  14653. state.buffers.color.setMask(true);
  14654. state.setPolygonOffset(false); // _gl.finish();
  14655. currentRenderList = null;
  14656. currentRenderState = null;
  14657. };
  14658. function projectObject(object, camera, groupOrder, sortObjects) {
  14659. if (object.visible === false) return;
  14660. var visible = object.layers.test(camera.layers);
  14661. if (visible) {
  14662. if (object.isGroup) {
  14663. groupOrder = object.renderOrder;
  14664. } else if (object.isLOD) {
  14665. if (object.autoUpdate === true) object.update(camera);
  14666. } else if (object.isLight) {
  14667. currentRenderState.pushLight(object);
  14668. if (object.castShadow) {
  14669. currentRenderState.pushShadow(object);
  14670. }
  14671. } else if (object.isSprite) {
  14672. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14673. if (sortObjects) {
  14674. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14675. }
  14676. var geometry = objects.update(object);
  14677. var material = object.material;
  14678. if (material.visible) {
  14679. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14680. }
  14681. }
  14682. } else if (object.isImmediateRenderObject) {
  14683. if (sortObjects) {
  14684. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14685. }
  14686. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14687. } else if (object.isMesh || object.isLine || object.isPoints) {
  14688. if (object.isSkinnedMesh) {
  14689. // update skeleton only once in a frame
  14690. if (object.skeleton.frame !== info.render.frame) {
  14691. object.skeleton.update();
  14692. object.skeleton.frame = info.render.frame;
  14693. }
  14694. }
  14695. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14696. if (sortObjects) {
  14697. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14698. }
  14699. var _geometry = objects.update(object);
  14700. var _material = object.material;
  14701. if (Array.isArray(_material)) {
  14702. var groups = _geometry.groups;
  14703. for (var i = 0, l = groups.length; i < l; i++) {
  14704. var group = groups[i];
  14705. var groupMaterial = _material[group.materialIndex];
  14706. if (groupMaterial && groupMaterial.visible) {
  14707. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14708. }
  14709. }
  14710. } else if (_material.visible) {
  14711. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14712. }
  14713. }
  14714. }
  14715. }
  14716. var children = object.children;
  14717. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14718. projectObject(children[_i], camera, groupOrder, sortObjects);
  14719. }
  14720. }
  14721. function renderObjects(renderList, scene, camera) {
  14722. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14723. for (var i = 0, l = renderList.length; i < l; i++) {
  14724. var renderItem = renderList[i];
  14725. var object = renderItem.object;
  14726. var geometry = renderItem.geometry;
  14727. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14728. var group = renderItem.group;
  14729. if (camera.isArrayCamera) {
  14730. _currentArrayCamera = camera;
  14731. var cameras = camera.cameras;
  14732. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14733. var camera2 = cameras[j];
  14734. if (object.layers.test(camera2.layers)) {
  14735. state.viewport(_currentViewport.copy(camera2.viewport));
  14736. currentRenderState.setupLights(camera2);
  14737. renderObject(object, scene, camera2, geometry, material, group);
  14738. }
  14739. }
  14740. } else {
  14741. _currentArrayCamera = null;
  14742. renderObject(object, scene, camera, geometry, material, group);
  14743. }
  14744. }
  14745. }
  14746. function renderObject(object, scene, camera, geometry, material, group) {
  14747. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  14748. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14749. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  14750. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  14751. if (object.isImmediateRenderObject) {
  14752. var program = setProgram(camera, scene, material, object);
  14753. state.setMaterial(material);
  14754. bindingStates.reset();
  14755. renderObjectImmediate(object, program);
  14756. } else {
  14757. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  14758. }
  14759. object.onAfterRender(_this, scene, camera, geometry, material, group);
  14760. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14761. }
  14762. function initMaterial(material, scene, object) {
  14763. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14764. var materialProperties = properties.get(material);
  14765. var lights = currentRenderState.state.lights;
  14766. var shadowsArray = currentRenderState.state.shadowsArray;
  14767. var lightsStateVersion = lights.state.version;
  14768. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  14769. var programCacheKey = programCache.getProgramCacheKey(parameters);
  14770. var program = materialProperties.program;
  14771. var programChange = true;
  14772. if (program === undefined) {
  14773. // new material
  14774. material.addEventListener('dispose', onMaterialDispose);
  14775. } else if (program.cacheKey !== programCacheKey) {
  14776. // changed glsl or parameters
  14777. releaseMaterialProgramReference(material);
  14778. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  14779. programChange = false;
  14780. } else if (parameters.shaderID !== undefined) {
  14781. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  14782. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14783. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  14784. return;
  14785. } else {
  14786. // only rebuild uniform list
  14787. programChange = false;
  14788. }
  14789. if (programChange) {
  14790. parameters.uniforms = programCache.getUniforms(material);
  14791. material.onBeforeCompile(parameters, _this);
  14792. program = programCache.acquireProgram(parameters, programCacheKey);
  14793. materialProperties.program = program;
  14794. materialProperties.uniforms = parameters.uniforms;
  14795. materialProperties.outputEncoding = parameters.outputEncoding;
  14796. }
  14797. var uniforms = materialProperties.uniforms;
  14798. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  14799. materialProperties.numClippingPlanes = clipping.numPlanes;
  14800. materialProperties.numIntersection = clipping.numIntersection;
  14801. uniforms.clippingPlanes = clipping.uniform;
  14802. }
  14803. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  14804. materialProperties.fog = scene.fog;
  14805. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  14806. materialProperties.needsLights = materialNeedsLights(material);
  14807. materialProperties.lightsStateVersion = lightsStateVersion;
  14808. if (materialProperties.needsLights) {
  14809. // wire up the material to this renderer's lighting state
  14810. uniforms.ambientLightColor.value = lights.state.ambient;
  14811. uniforms.lightProbe.value = lights.state.probe;
  14812. uniforms.directionalLights.value = lights.state.directional;
  14813. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  14814. uniforms.spotLights.value = lights.state.spot;
  14815. uniforms.spotLightShadows.value = lights.state.spotShadow;
  14816. uniforms.rectAreaLights.value = lights.state.rectArea;
  14817. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  14818. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  14819. uniforms.pointLights.value = lights.state.point;
  14820. uniforms.pointLightShadows.value = lights.state.pointShadow;
  14821. uniforms.hemisphereLights.value = lights.state.hemi;
  14822. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14823. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14824. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14825. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14826. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14827. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  14828. }
  14829. var progUniforms = materialProperties.program.getUniforms();
  14830. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  14831. materialProperties.uniformsList = uniformsList;
  14832. }
  14833. function setProgram(camera, scene, material, object) {
  14834. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14835. textures.resetTextureUnits();
  14836. var fog = scene.fog;
  14837. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14838. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  14839. var envMap = cubemaps.get(material.envMap || environment);
  14840. var materialProperties = properties.get(material);
  14841. var lights = currentRenderState.state.lights;
  14842. if (_clippingEnabled === true) {
  14843. if (_localClippingEnabled === true || camera !== _currentCamera) {
  14844. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  14845. // object instead of the material, once it becomes feasible
  14846. // (#8465, #8379)
  14847. clipping.setState(material, camera, useCache);
  14848. }
  14849. }
  14850. if (material.version === materialProperties.__version) {
  14851. if (material.fog && materialProperties.fog !== fog) {
  14852. initMaterial(material, scene, object);
  14853. } else if (materialProperties.environment !== environment) {
  14854. initMaterial(material, scene, object);
  14855. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  14856. initMaterial(material, scene, object);
  14857. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  14858. initMaterial(material, scene, object);
  14859. } else if (materialProperties.outputEncoding !== encoding) {
  14860. initMaterial(material, scene, object);
  14861. } else if (materialProperties.envMap !== envMap) {
  14862. initMaterial(material, scene, object);
  14863. }
  14864. } else {
  14865. initMaterial(material, scene, object);
  14866. materialProperties.__version = material.version;
  14867. }
  14868. var refreshProgram = false;
  14869. var refreshMaterial = false;
  14870. var refreshLights = false;
  14871. var program = materialProperties.program,
  14872. p_uniforms = program.getUniforms(),
  14873. m_uniforms = materialProperties.uniforms;
  14874. if (state.useProgram(program.program)) {
  14875. refreshProgram = true;
  14876. refreshMaterial = true;
  14877. refreshLights = true;
  14878. }
  14879. if (material.id !== _currentMaterialId) {
  14880. _currentMaterialId = material.id;
  14881. refreshMaterial = true;
  14882. }
  14883. if (refreshProgram || _currentCamera !== camera) {
  14884. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  14885. if (capabilities.logarithmicDepthBuffer) {
  14886. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  14887. }
  14888. if (_currentCamera !== camera) {
  14889. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  14890. // now, in case this material supports lights - or later, when
  14891. // the next material that does gets activated:
  14892. refreshMaterial = true; // set to true on material change
  14893. refreshLights = true; // remains set until update done
  14894. } // load material specific uniforms
  14895. // (shader material also gets them for the sake of genericity)
  14896. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  14897. var uCamPos = p_uniforms.map.cameraPosition;
  14898. if (uCamPos !== undefined) {
  14899. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  14900. }
  14901. }
  14902. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  14903. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  14904. }
  14905. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  14906. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  14907. }
  14908. } // skinning uniforms must be set even if material didn't change
  14909. // auto-setting of texture unit for bone texture must go before other textures
  14910. // otherwise textures used for skinning can take over texture units reserved for other material textures
  14911. if (material.skinning) {
  14912. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  14913. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  14914. var skeleton = object.skeleton;
  14915. if (skeleton) {
  14916. var bones = skeleton.bones;
  14917. if (capabilities.floatVertexTextures) {
  14918. if (skeleton.boneTexture === undefined) {
  14919. // layout (1 matrix = 4 pixels)
  14920. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14921. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14922. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14923. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14924. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14925. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  14926. size = MathUtils.ceilPowerOfTwo(size);
  14927. size = Math.max(size, 4);
  14928. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  14929. boneMatrices.set(skeleton.boneMatrices); // copy current values
  14930. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  14931. skeleton.boneMatrices = boneMatrices;
  14932. skeleton.boneTexture = boneTexture;
  14933. skeleton.boneTextureSize = size;
  14934. }
  14935. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  14936. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  14937. } else {
  14938. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  14939. }
  14940. }
  14941. }
  14942. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  14943. materialProperties.receiveShadow = object.receiveShadow;
  14944. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  14945. }
  14946. if (refreshMaterial) {
  14947. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  14948. if (materialProperties.needsLights) {
  14949. // the current material requires lighting info
  14950. // note: all lighting uniforms are always set correctly
  14951. // they simply reference the renderer's state for their
  14952. // values
  14953. //
  14954. // use the current material's .needsUpdate flags to set
  14955. // the GL state when required
  14956. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  14957. } // refresh uniforms common to several materials
  14958. if (fog && material.fog) {
  14959. materials.refreshFogUniforms(m_uniforms, fog);
  14960. }
  14961. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  14962. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  14963. }
  14964. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  14965. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  14966. material.uniformsNeedUpdate = false;
  14967. }
  14968. if (material.isSpriteMaterial) {
  14969. p_uniforms.setValue(_gl, 'center', object.center);
  14970. } // common matrices
  14971. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  14972. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  14973. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  14974. return program;
  14975. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14976. function markUniformsLightsNeedsUpdate(uniforms, value) {
  14977. uniforms.ambientLightColor.needsUpdate = value;
  14978. uniforms.lightProbe.needsUpdate = value;
  14979. uniforms.directionalLights.needsUpdate = value;
  14980. uniforms.directionalLightShadows.needsUpdate = value;
  14981. uniforms.pointLights.needsUpdate = value;
  14982. uniforms.pointLightShadows.needsUpdate = value;
  14983. uniforms.spotLights.needsUpdate = value;
  14984. uniforms.spotLightShadows.needsUpdate = value;
  14985. uniforms.rectAreaLights.needsUpdate = value;
  14986. uniforms.hemisphereLights.needsUpdate = value;
  14987. }
  14988. function materialNeedsLights(material) {
  14989. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  14990. } //
  14991. this.setFramebuffer = function (value) {
  14992. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  14993. _framebuffer = value;
  14994. };
  14995. this.getActiveCubeFace = function () {
  14996. return _currentActiveCubeFace;
  14997. };
  14998. this.getActiveMipmapLevel = function () {
  14999. return _currentActiveMipmapLevel;
  15000. };
  15001. this.getRenderList = function () {
  15002. return currentRenderList;
  15003. };
  15004. this.setRenderList = function (renderList) {
  15005. currentRenderList = renderList;
  15006. };
  15007. this.getRenderState = function () {
  15008. return currentRenderState;
  15009. };
  15010. this.setRenderState = function (renderState) {
  15011. currentRenderState = renderState;
  15012. };
  15013. this.getRenderTarget = function () {
  15014. return _currentRenderTarget;
  15015. };
  15016. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15017. if (activeCubeFace === void 0) {
  15018. activeCubeFace = 0;
  15019. }
  15020. if (activeMipmapLevel === void 0) {
  15021. activeMipmapLevel = 0;
  15022. }
  15023. _currentRenderTarget = renderTarget;
  15024. _currentActiveCubeFace = activeCubeFace;
  15025. _currentActiveMipmapLevel = activeMipmapLevel;
  15026. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15027. textures.setupRenderTarget(renderTarget);
  15028. }
  15029. var framebuffer = _framebuffer;
  15030. var isCube = false;
  15031. if (renderTarget) {
  15032. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15033. if (renderTarget.isWebGLCubeRenderTarget) {
  15034. framebuffer = __webglFramebuffer[activeCubeFace];
  15035. isCube = true;
  15036. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15037. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15038. } else {
  15039. framebuffer = __webglFramebuffer;
  15040. }
  15041. _currentViewport.copy(renderTarget.viewport);
  15042. _currentScissor.copy(renderTarget.scissor);
  15043. _currentScissorTest = renderTarget.scissorTest;
  15044. } else {
  15045. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15046. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15047. _currentScissorTest = _scissorTest;
  15048. }
  15049. if (_currentFramebuffer !== framebuffer) {
  15050. _gl.bindFramebuffer(36160, framebuffer);
  15051. _currentFramebuffer = framebuffer;
  15052. }
  15053. state.viewport(_currentViewport);
  15054. state.scissor(_currentScissor);
  15055. state.setScissorTest(_currentScissorTest);
  15056. if (isCube) {
  15057. var textureProperties = properties.get(renderTarget.texture);
  15058. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15059. }
  15060. };
  15061. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15062. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15063. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15064. return;
  15065. }
  15066. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15067. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15068. framebuffer = framebuffer[activeCubeFaceIndex];
  15069. }
  15070. if (framebuffer) {
  15071. var restore = false;
  15072. if (framebuffer !== _currentFramebuffer) {
  15073. _gl.bindFramebuffer(36160, framebuffer);
  15074. restore = true;
  15075. }
  15076. try {
  15077. var texture = renderTarget.texture;
  15078. var textureFormat = texture.format;
  15079. var textureType = texture.type;
  15080. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15081. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15082. return;
  15083. }
  15084. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15085. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15086. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15087. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15088. return;
  15089. }
  15090. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15091. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15092. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15093. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15094. }
  15095. } else {
  15096. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15097. }
  15098. } finally {
  15099. if (restore) {
  15100. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15101. }
  15102. }
  15103. }
  15104. };
  15105. this.copyFramebufferToTexture = function (position, texture, level) {
  15106. if (level === undefined) level = 0;
  15107. var levelScale = Math.pow(2, -level);
  15108. var width = Math.floor(texture.image.width * levelScale);
  15109. var height = Math.floor(texture.image.height * levelScale);
  15110. var glFormat = utils.convert(texture.format);
  15111. textures.setTexture2D(texture, 0);
  15112. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15113. state.unbindTexture();
  15114. };
  15115. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15116. if (level === undefined) level = 0;
  15117. var width = srcTexture.image.width;
  15118. var height = srcTexture.image.height;
  15119. var glFormat = utils.convert(dstTexture.format);
  15120. var glType = utils.convert(dstTexture.type);
  15121. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15122. // parameters, make sure they are correct for the dstTexture
  15123. _gl.pixelStorei(37440, dstTexture.flipY);
  15124. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15125. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15126. if (srcTexture.isDataTexture) {
  15127. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15128. } else {
  15129. if (srcTexture.isCompressedTexture) {
  15130. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15131. } else {
  15132. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15133. }
  15134. } // Generate mipmaps only when copying level 0
  15135. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15136. state.unbindTexture();
  15137. };
  15138. this.initTexture = function (texture) {
  15139. textures.setTexture2D(texture, 0);
  15140. state.unbindTexture();
  15141. };
  15142. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15143. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15144. detail: this
  15145. })); // eslint-disable-line no-undef
  15146. }
  15147. }
  15148. function WebGL1Renderer(parameters) {
  15149. WebGLRenderer.call(this, parameters);
  15150. }
  15151. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15152. constructor: WebGL1Renderer,
  15153. isWebGL1Renderer: true
  15154. });
  15155. var FogExp2 = /*#__PURE__*/function () {
  15156. function FogExp2(color, density) {
  15157. Object.defineProperty(this, 'isFogExp2', {
  15158. value: true
  15159. });
  15160. this.name = '';
  15161. this.color = new Color(color);
  15162. this.density = density !== undefined ? density : 0.00025;
  15163. }
  15164. var _proto = FogExp2.prototype;
  15165. _proto.clone = function clone() {
  15166. return new FogExp2(this.color, this.density);
  15167. };
  15168. _proto.toJSON = function toJSON()
  15169. /* meta */
  15170. {
  15171. return {
  15172. type: 'FogExp2',
  15173. color: this.color.getHex(),
  15174. density: this.density
  15175. };
  15176. };
  15177. return FogExp2;
  15178. }();
  15179. var Fog = /*#__PURE__*/function () {
  15180. function Fog(color, near, far) {
  15181. Object.defineProperty(this, 'isFog', {
  15182. value: true
  15183. });
  15184. this.name = '';
  15185. this.color = new Color(color);
  15186. this.near = near !== undefined ? near : 1;
  15187. this.far = far !== undefined ? far : 1000;
  15188. }
  15189. var _proto = Fog.prototype;
  15190. _proto.clone = function clone() {
  15191. return new Fog(this.color, this.near, this.far);
  15192. };
  15193. _proto.toJSON = function toJSON()
  15194. /* meta */
  15195. {
  15196. return {
  15197. type: 'Fog',
  15198. color: this.color.getHex(),
  15199. near: this.near,
  15200. far: this.far
  15201. };
  15202. };
  15203. return Fog;
  15204. }();
  15205. var Scene = /*#__PURE__*/function (_Object3D) {
  15206. _inheritsLoose(Scene, _Object3D);
  15207. function Scene() {
  15208. var _this;
  15209. _this = _Object3D.call(this) || this;
  15210. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15211. value: true
  15212. });
  15213. _this.type = 'Scene';
  15214. _this.background = null;
  15215. _this.environment = null;
  15216. _this.fog = null;
  15217. _this.overrideMaterial = null;
  15218. _this.autoUpdate = true; // checked by the renderer
  15219. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15220. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15221. detail: _assertThisInitialized(_this)
  15222. })); // eslint-disable-line no-undef
  15223. }
  15224. return _this;
  15225. }
  15226. var _proto = Scene.prototype;
  15227. _proto.copy = function copy(source, recursive) {
  15228. _Object3D.prototype.copy.call(this, source, recursive);
  15229. if (source.background !== null) this.background = source.background.clone();
  15230. if (source.environment !== null) this.environment = source.environment.clone();
  15231. if (source.fog !== null) this.fog = source.fog.clone();
  15232. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15233. this.autoUpdate = source.autoUpdate;
  15234. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15235. return this;
  15236. };
  15237. _proto.toJSON = function toJSON(meta) {
  15238. var data = _Object3D.prototype.toJSON.call(this, meta);
  15239. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15240. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15241. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15242. return data;
  15243. };
  15244. return Scene;
  15245. }(Object3D);
  15246. function InterleavedBuffer(array, stride) {
  15247. this.array = array;
  15248. this.stride = stride;
  15249. this.count = array !== undefined ? array.length / stride : 0;
  15250. this.usage = StaticDrawUsage;
  15251. this.updateRange = {
  15252. offset: 0,
  15253. count: -1
  15254. };
  15255. this.version = 0;
  15256. this.uuid = MathUtils.generateUUID();
  15257. }
  15258. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15259. set: function set(value) {
  15260. if (value === true) this.version++;
  15261. }
  15262. });
  15263. Object.assign(InterleavedBuffer.prototype, {
  15264. isInterleavedBuffer: true,
  15265. onUploadCallback: function onUploadCallback() {},
  15266. setUsage: function setUsage(value) {
  15267. this.usage = value;
  15268. return this;
  15269. },
  15270. copy: function copy(source) {
  15271. this.array = new source.array.constructor(source.array);
  15272. this.count = source.count;
  15273. this.stride = source.stride;
  15274. this.usage = source.usage;
  15275. return this;
  15276. },
  15277. copyAt: function copyAt(index1, attribute, index2) {
  15278. index1 *= this.stride;
  15279. index2 *= attribute.stride;
  15280. for (var i = 0, l = this.stride; i < l; i++) {
  15281. this.array[index1 + i] = attribute.array[index2 + i];
  15282. }
  15283. return this;
  15284. },
  15285. set: function set(value, offset) {
  15286. if (offset === undefined) offset = 0;
  15287. this.array.set(value, offset);
  15288. return this;
  15289. },
  15290. clone: function clone(data) {
  15291. if (data.arrayBuffers === undefined) {
  15292. data.arrayBuffers = {};
  15293. }
  15294. if (this.array.buffer._uuid === undefined) {
  15295. this.array.buffer._uuid = MathUtils.generateUUID();
  15296. }
  15297. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15298. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15299. }
  15300. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15301. var ib = new InterleavedBuffer(array, this.stride);
  15302. ib.setUsage(this.usage);
  15303. return ib;
  15304. },
  15305. onUpload: function onUpload(callback) {
  15306. this.onUploadCallback = callback;
  15307. return this;
  15308. },
  15309. toJSON: function toJSON(data) {
  15310. if (data.arrayBuffers === undefined) {
  15311. data.arrayBuffers = {};
  15312. } // generate UUID for array buffer if necessary
  15313. if (this.array.buffer._uuid === undefined) {
  15314. this.array.buffer._uuid = MathUtils.generateUUID();
  15315. }
  15316. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15317. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15318. } //
  15319. return {
  15320. uuid: this.uuid,
  15321. buffer: this.array.buffer._uuid,
  15322. type: this.array.constructor.name,
  15323. stride: this.stride
  15324. };
  15325. }
  15326. });
  15327. var _vector$6 = new Vector3();
  15328. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15329. this.name = '';
  15330. this.data = interleavedBuffer;
  15331. this.itemSize = itemSize;
  15332. this.offset = offset;
  15333. this.normalized = normalized === true;
  15334. }
  15335. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15336. count: {
  15337. get: function get() {
  15338. return this.data.count;
  15339. }
  15340. },
  15341. array: {
  15342. get: function get() {
  15343. return this.data.array;
  15344. }
  15345. },
  15346. needsUpdate: {
  15347. set: function set(value) {
  15348. this.data.needsUpdate = value;
  15349. }
  15350. }
  15351. });
  15352. Object.assign(InterleavedBufferAttribute.prototype, {
  15353. isInterleavedBufferAttribute: true,
  15354. applyMatrix4: function applyMatrix4(m) {
  15355. for (var i = 0, l = this.data.count; i < l; i++) {
  15356. _vector$6.x = this.getX(i);
  15357. _vector$6.y = this.getY(i);
  15358. _vector$6.z = this.getZ(i);
  15359. _vector$6.applyMatrix4(m);
  15360. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15361. }
  15362. return this;
  15363. },
  15364. setX: function setX(index, x) {
  15365. this.data.array[index * this.data.stride + this.offset] = x;
  15366. return this;
  15367. },
  15368. setY: function setY(index, y) {
  15369. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15370. return this;
  15371. },
  15372. setZ: function setZ(index, z) {
  15373. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15374. return this;
  15375. },
  15376. setW: function setW(index, w) {
  15377. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15378. return this;
  15379. },
  15380. getX: function getX(index) {
  15381. return this.data.array[index * this.data.stride + this.offset];
  15382. },
  15383. getY: function getY(index) {
  15384. return this.data.array[index * this.data.stride + this.offset + 1];
  15385. },
  15386. getZ: function getZ(index) {
  15387. return this.data.array[index * this.data.stride + this.offset + 2];
  15388. },
  15389. getW: function getW(index) {
  15390. return this.data.array[index * this.data.stride + this.offset + 3];
  15391. },
  15392. setXY: function setXY(index, x, y) {
  15393. index = index * this.data.stride + this.offset;
  15394. this.data.array[index + 0] = x;
  15395. this.data.array[index + 1] = y;
  15396. return this;
  15397. },
  15398. setXYZ: function setXYZ(index, x, y, z) {
  15399. index = index * this.data.stride + this.offset;
  15400. this.data.array[index + 0] = x;
  15401. this.data.array[index + 1] = y;
  15402. this.data.array[index + 2] = z;
  15403. return this;
  15404. },
  15405. setXYZW: function setXYZW(index, x, y, z, w) {
  15406. index = index * this.data.stride + this.offset;
  15407. this.data.array[index + 0] = x;
  15408. this.data.array[index + 1] = y;
  15409. this.data.array[index + 2] = z;
  15410. this.data.array[index + 3] = w;
  15411. return this;
  15412. },
  15413. clone: function clone(data) {
  15414. if (data === undefined) {
  15415. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15416. var array = [];
  15417. for (var i = 0; i < this.count; i++) {
  15418. var index = i * this.data.stride + this.offset;
  15419. for (var j = 0; j < this.itemSize; j++) {
  15420. array.push(this.data.array[index + j]);
  15421. }
  15422. }
  15423. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15424. } else {
  15425. if (data.interleavedBuffers === undefined) {
  15426. data.interleavedBuffers = {};
  15427. }
  15428. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15429. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15430. }
  15431. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15432. }
  15433. },
  15434. toJSON: function toJSON(data) {
  15435. if (data === undefined) {
  15436. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15437. var array = [];
  15438. for (var i = 0; i < this.count; i++) {
  15439. var index = i * this.data.stride + this.offset;
  15440. for (var j = 0; j < this.itemSize; j++) {
  15441. array.push(this.data.array[index + j]);
  15442. }
  15443. } // deinterleave data and save it as an ordinary buffer attribute for now
  15444. return {
  15445. itemSize: this.itemSize,
  15446. type: this.array.constructor.name,
  15447. array: array,
  15448. normalized: this.normalized
  15449. };
  15450. } else {
  15451. // save as true interlaved attribtue
  15452. if (data.interleavedBuffers === undefined) {
  15453. data.interleavedBuffers = {};
  15454. }
  15455. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15456. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15457. }
  15458. return {
  15459. isInterleavedBufferAttribute: true,
  15460. itemSize: this.itemSize,
  15461. data: this.data.uuid,
  15462. offset: this.offset,
  15463. normalized: this.normalized
  15464. };
  15465. }
  15466. }
  15467. });
  15468. /**
  15469. * parameters = {
  15470. * color: <hex>,
  15471. * map: new THREE.Texture( <Image> ),
  15472. * alphaMap: new THREE.Texture( <Image> ),
  15473. * rotation: <float>,
  15474. * sizeAttenuation: <bool>
  15475. * }
  15476. */
  15477. function SpriteMaterial(parameters) {
  15478. Material.call(this);
  15479. this.type = 'SpriteMaterial';
  15480. this.color = new Color(0xffffff);
  15481. this.map = null;
  15482. this.alphaMap = null;
  15483. this.rotation = 0;
  15484. this.sizeAttenuation = true;
  15485. this.transparent = true;
  15486. this.setValues(parameters);
  15487. }
  15488. SpriteMaterial.prototype = Object.create(Material.prototype);
  15489. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15490. SpriteMaterial.prototype.isSpriteMaterial = true;
  15491. SpriteMaterial.prototype.copy = function (source) {
  15492. Material.prototype.copy.call(this, source);
  15493. this.color.copy(source.color);
  15494. this.map = source.map;
  15495. this.alphaMap = source.alphaMap;
  15496. this.rotation = source.rotation;
  15497. this.sizeAttenuation = source.sizeAttenuation;
  15498. return this;
  15499. };
  15500. var _geometry;
  15501. var _intersectPoint = new Vector3();
  15502. var _worldScale = new Vector3();
  15503. var _mvPosition = new Vector3();
  15504. var _alignedPosition = new Vector2();
  15505. var _rotatedPosition = new Vector2();
  15506. var _viewWorldMatrix = new Matrix4();
  15507. var _vA$1 = new Vector3();
  15508. var _vB$1 = new Vector3();
  15509. var _vC$1 = new Vector3();
  15510. var _uvA$1 = new Vector2();
  15511. var _uvB$1 = new Vector2();
  15512. var _uvC$1 = new Vector2();
  15513. function Sprite(material) {
  15514. Object3D.call(this);
  15515. this.type = 'Sprite';
  15516. if (_geometry === undefined) {
  15517. _geometry = new BufferGeometry();
  15518. 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]);
  15519. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15520. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15521. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15522. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15523. }
  15524. this.geometry = _geometry;
  15525. this.material = material !== undefined ? material : new SpriteMaterial();
  15526. this.center = new Vector2(0.5, 0.5);
  15527. }
  15528. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15529. constructor: Sprite,
  15530. isSprite: true,
  15531. raycast: function raycast(raycaster, intersects) {
  15532. if (raycaster.camera === null) {
  15533. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15534. }
  15535. _worldScale.setFromMatrixScale(this.matrixWorld);
  15536. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15537. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15538. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15539. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15540. _worldScale.multiplyScalar(-_mvPosition.z);
  15541. }
  15542. var rotation = this.material.rotation;
  15543. var sin, cos;
  15544. if (rotation !== 0) {
  15545. cos = Math.cos(rotation);
  15546. sin = Math.sin(rotation);
  15547. }
  15548. var center = this.center;
  15549. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15550. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15551. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15552. _uvA$1.set(0, 0);
  15553. _uvB$1.set(1, 0);
  15554. _uvC$1.set(1, 1); // check first triangle
  15555. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15556. if (intersect === null) {
  15557. // check second triangle
  15558. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15559. _uvB$1.set(0, 1);
  15560. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15561. if (intersect === null) {
  15562. return;
  15563. }
  15564. }
  15565. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15566. if (distance < raycaster.near || distance > raycaster.far) return;
  15567. intersects.push({
  15568. distance: distance,
  15569. point: _intersectPoint.clone(),
  15570. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15571. face: null,
  15572. object: this
  15573. });
  15574. },
  15575. copy: function copy(source) {
  15576. Object3D.prototype.copy.call(this, source);
  15577. if (source.center !== undefined) this.center.copy(source.center);
  15578. this.material = source.material;
  15579. return this;
  15580. }
  15581. });
  15582. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15583. // compute position in camera space
  15584. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15585. if (sin !== undefined) {
  15586. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15587. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15588. } else {
  15589. _rotatedPosition.copy(_alignedPosition);
  15590. }
  15591. vertexPosition.copy(mvPosition);
  15592. vertexPosition.x += _rotatedPosition.x;
  15593. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15594. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15595. }
  15596. var _v1$4 = new Vector3();
  15597. var _v2$2 = new Vector3();
  15598. function LOD() {
  15599. Object3D.call(this);
  15600. this._currentLevel = 0;
  15601. this.type = 'LOD';
  15602. Object.defineProperties(this, {
  15603. levels: {
  15604. enumerable: true,
  15605. value: []
  15606. }
  15607. });
  15608. this.autoUpdate = true;
  15609. }
  15610. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15611. constructor: LOD,
  15612. isLOD: true,
  15613. copy: function copy(source) {
  15614. Object3D.prototype.copy.call(this, source, false);
  15615. var levels = source.levels;
  15616. for (var i = 0, l = levels.length; i < l; i++) {
  15617. var level = levels[i];
  15618. this.addLevel(level.object.clone(), level.distance);
  15619. }
  15620. this.autoUpdate = source.autoUpdate;
  15621. return this;
  15622. },
  15623. addLevel: function addLevel(object, distance) {
  15624. if (distance === undefined) distance = 0;
  15625. distance = Math.abs(distance);
  15626. var levels = this.levels;
  15627. var l;
  15628. for (l = 0; l < levels.length; l++) {
  15629. if (distance < levels[l].distance) {
  15630. break;
  15631. }
  15632. }
  15633. levels.splice(l, 0, {
  15634. distance: distance,
  15635. object: object
  15636. });
  15637. this.add(object);
  15638. return this;
  15639. },
  15640. getCurrentLevel: function getCurrentLevel() {
  15641. return this._currentLevel;
  15642. },
  15643. getObjectForDistance: function getObjectForDistance(distance) {
  15644. var levels = this.levels;
  15645. if (levels.length > 0) {
  15646. var i, l;
  15647. for (i = 1, l = levels.length; i < l; i++) {
  15648. if (distance < levels[i].distance) {
  15649. break;
  15650. }
  15651. }
  15652. return levels[i - 1].object;
  15653. }
  15654. return null;
  15655. },
  15656. raycast: function raycast(raycaster, intersects) {
  15657. var levels = this.levels;
  15658. if (levels.length > 0) {
  15659. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15660. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15661. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15662. }
  15663. },
  15664. update: function update(camera) {
  15665. var levels = this.levels;
  15666. if (levels.length > 1) {
  15667. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15668. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15669. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15670. levels[0].object.visible = true;
  15671. var i, l;
  15672. for (i = 1, l = levels.length; i < l; i++) {
  15673. if (distance >= levels[i].distance) {
  15674. levels[i - 1].object.visible = false;
  15675. levels[i].object.visible = true;
  15676. } else {
  15677. break;
  15678. }
  15679. }
  15680. this._currentLevel = i - 1;
  15681. for (; i < l; i++) {
  15682. levels[i].object.visible = false;
  15683. }
  15684. }
  15685. },
  15686. toJSON: function toJSON(meta) {
  15687. var data = Object3D.prototype.toJSON.call(this, meta);
  15688. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15689. data.object.levels = [];
  15690. var levels = this.levels;
  15691. for (var i = 0, l = levels.length; i < l; i++) {
  15692. var level = levels[i];
  15693. data.object.levels.push({
  15694. object: level.object.uuid,
  15695. distance: level.distance
  15696. });
  15697. }
  15698. return data;
  15699. }
  15700. });
  15701. function SkinnedMesh(geometry, material) {
  15702. if (geometry && geometry.isGeometry) {
  15703. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15704. }
  15705. Mesh.call(this, geometry, material);
  15706. this.type = 'SkinnedMesh';
  15707. this.bindMode = 'attached';
  15708. this.bindMatrix = new Matrix4();
  15709. this.bindMatrixInverse = new Matrix4();
  15710. }
  15711. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15712. constructor: SkinnedMesh,
  15713. isSkinnedMesh: true,
  15714. copy: function copy(source) {
  15715. Mesh.prototype.copy.call(this, source);
  15716. this.bindMode = source.bindMode;
  15717. this.bindMatrix.copy(source.bindMatrix);
  15718. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15719. this.skeleton = source.skeleton;
  15720. return this;
  15721. },
  15722. bind: function bind(skeleton, bindMatrix) {
  15723. this.skeleton = skeleton;
  15724. if (bindMatrix === undefined) {
  15725. this.updateMatrixWorld(true);
  15726. this.skeleton.calculateInverses();
  15727. bindMatrix = this.matrixWorld;
  15728. }
  15729. this.bindMatrix.copy(bindMatrix);
  15730. this.bindMatrixInverse.getInverse(bindMatrix);
  15731. },
  15732. pose: function pose() {
  15733. this.skeleton.pose();
  15734. },
  15735. normalizeSkinWeights: function normalizeSkinWeights() {
  15736. var vector = new Vector4();
  15737. var skinWeight = this.geometry.attributes.skinWeight;
  15738. for (var i = 0, l = skinWeight.count; i < l; i++) {
  15739. vector.x = skinWeight.getX(i);
  15740. vector.y = skinWeight.getY(i);
  15741. vector.z = skinWeight.getZ(i);
  15742. vector.w = skinWeight.getW(i);
  15743. var scale = 1.0 / vector.manhattanLength();
  15744. if (scale !== Infinity) {
  15745. vector.multiplyScalar(scale);
  15746. } else {
  15747. vector.set(1, 0, 0, 0); // do something reasonable
  15748. }
  15749. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  15750. }
  15751. },
  15752. updateMatrixWorld: function updateMatrixWorld(force) {
  15753. Mesh.prototype.updateMatrixWorld.call(this, force);
  15754. if (this.bindMode === 'attached') {
  15755. this.bindMatrixInverse.getInverse(this.matrixWorld);
  15756. } else if (this.bindMode === 'detached') {
  15757. this.bindMatrixInverse.getInverse(this.bindMatrix);
  15758. } else {
  15759. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  15760. }
  15761. },
  15762. boneTransform: function () {
  15763. var basePosition = new Vector3();
  15764. var skinIndex = new Vector4();
  15765. var skinWeight = new Vector4();
  15766. var vector = new Vector3();
  15767. var matrix = new Matrix4();
  15768. return function (index, target) {
  15769. var skeleton = this.skeleton;
  15770. var geometry = this.geometry;
  15771. skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  15772. skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  15773. basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  15774. target.set(0, 0, 0);
  15775. for (var i = 0; i < 4; i++) {
  15776. var weight = skinWeight.getComponent(i);
  15777. if (weight !== 0) {
  15778. var boneIndex = skinIndex.getComponent(i);
  15779. matrix.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  15780. target.addScaledVector(vector.copy(basePosition).applyMatrix4(matrix), weight);
  15781. }
  15782. }
  15783. return target.applyMatrix4(this.bindMatrixInverse);
  15784. };
  15785. }()
  15786. });
  15787. var _offsetMatrix = new Matrix4();
  15788. var _identityMatrix = new Matrix4();
  15789. function Skeleton(bones, boneInverses) {
  15790. // copy the bone array
  15791. bones = bones || [];
  15792. this.bones = bones.slice(0);
  15793. this.boneMatrices = new Float32Array(this.bones.length * 16);
  15794. this.frame = -1; // use the supplied bone inverses or calculate the inverses
  15795. if (boneInverses === undefined) {
  15796. this.calculateInverses();
  15797. } else {
  15798. if (this.bones.length === boneInverses.length) {
  15799. this.boneInverses = boneInverses.slice(0);
  15800. } else {
  15801. console.warn('THREE.Skeleton boneInverses is the wrong length.');
  15802. this.boneInverses = [];
  15803. for (var i = 0, il = this.bones.length; i < il; i++) {
  15804. this.boneInverses.push(new Matrix4());
  15805. }
  15806. }
  15807. }
  15808. }
  15809. Object.assign(Skeleton.prototype, {
  15810. calculateInverses: function calculateInverses() {
  15811. this.boneInverses = [];
  15812. for (var i = 0, il = this.bones.length; i < il; i++) {
  15813. var inverse = new Matrix4();
  15814. if (this.bones[i]) {
  15815. inverse.getInverse(this.bones[i].matrixWorld);
  15816. }
  15817. this.boneInverses.push(inverse);
  15818. }
  15819. },
  15820. pose: function pose() {
  15821. // recover the bind-time world matrices
  15822. for (var i = 0, il = this.bones.length; i < il; i++) {
  15823. var bone = this.bones[i];
  15824. if (bone) {
  15825. bone.matrixWorld.getInverse(this.boneInverses[i]);
  15826. }
  15827. } // compute the local matrices, positions, rotations and scales
  15828. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  15829. var _bone = this.bones[_i];
  15830. if (_bone) {
  15831. if (_bone.parent && _bone.parent.isBone) {
  15832. _bone.matrix.getInverse(_bone.parent.matrixWorld);
  15833. _bone.matrix.multiply(_bone.matrixWorld);
  15834. } else {
  15835. _bone.matrix.copy(_bone.matrixWorld);
  15836. }
  15837. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  15838. }
  15839. }
  15840. },
  15841. update: function update() {
  15842. var bones = this.bones;
  15843. var boneInverses = this.boneInverses;
  15844. var boneMatrices = this.boneMatrices;
  15845. var boneTexture = this.boneTexture; // flatten bone matrices to array
  15846. for (var i = 0, il = bones.length; i < il; i++) {
  15847. // compute the offset between the current and the original transform
  15848. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  15849. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  15850. _offsetMatrix.toArray(boneMatrices, i * 16);
  15851. }
  15852. if (boneTexture !== undefined) {
  15853. boneTexture.needsUpdate = true;
  15854. }
  15855. },
  15856. clone: function clone() {
  15857. return new Skeleton(this.bones, this.boneInverses);
  15858. },
  15859. getBoneByName: function getBoneByName(name) {
  15860. for (var i = 0, il = this.bones.length; i < il; i++) {
  15861. var bone = this.bones[i];
  15862. if (bone.name === name) {
  15863. return bone;
  15864. }
  15865. }
  15866. return undefined;
  15867. },
  15868. dispose: function dispose() {
  15869. if (this.boneTexture) {
  15870. this.boneTexture.dispose();
  15871. this.boneTexture = undefined;
  15872. }
  15873. }
  15874. });
  15875. function Bone() {
  15876. Object3D.call(this);
  15877. this.type = 'Bone';
  15878. }
  15879. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  15880. constructor: Bone,
  15881. isBone: true
  15882. });
  15883. var _instanceLocalMatrix = new Matrix4();
  15884. var _instanceWorldMatrix = new Matrix4();
  15885. var _instanceIntersects = [];
  15886. var _mesh = new Mesh();
  15887. function InstancedMesh(geometry, material, count) {
  15888. Mesh.call(this, geometry, material);
  15889. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  15890. this.instanceColor = null;
  15891. this.count = count;
  15892. this.frustumCulled = false;
  15893. }
  15894. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15895. constructor: InstancedMesh,
  15896. isInstancedMesh: true,
  15897. copy: function copy(source) {
  15898. Mesh.prototype.copy.call(this, source);
  15899. this.instanceMatrix.copy(source.instanceMatrix);
  15900. this.count = source.count;
  15901. return this;
  15902. },
  15903. setColorAt: function setColorAt(index, color) {
  15904. if (this.instanceColor === null) {
  15905. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  15906. }
  15907. color.toArray(this.instanceColor.array, index * 3);
  15908. },
  15909. getMatrixAt: function getMatrixAt(index, matrix) {
  15910. matrix.fromArray(this.instanceMatrix.array, index * 16);
  15911. },
  15912. raycast: function raycast(raycaster, intersects) {
  15913. var matrixWorld = this.matrixWorld;
  15914. var raycastTimes = this.count;
  15915. _mesh.geometry = this.geometry;
  15916. _mesh.material = this.material;
  15917. if (_mesh.material === undefined) return;
  15918. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  15919. // calculate the world matrix for each instance
  15920. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  15921. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  15922. _mesh.matrixWorld = _instanceWorldMatrix;
  15923. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  15924. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  15925. var intersect = _instanceIntersects[i];
  15926. intersect.instanceId = instanceId;
  15927. intersect.object = this;
  15928. intersects.push(intersect);
  15929. }
  15930. _instanceIntersects.length = 0;
  15931. }
  15932. },
  15933. setMatrixAt: function setMatrixAt(index, matrix) {
  15934. matrix.toArray(this.instanceMatrix.array, index * 16);
  15935. },
  15936. updateMorphTargets: function updateMorphTargets() {}
  15937. });
  15938. /**
  15939. * parameters = {
  15940. * color: <hex>,
  15941. * opacity: <float>,
  15942. *
  15943. * linewidth: <float>,
  15944. * linecap: "round",
  15945. * linejoin: "round"
  15946. * }
  15947. */
  15948. function LineBasicMaterial(parameters) {
  15949. Material.call(this);
  15950. this.type = 'LineBasicMaterial';
  15951. this.color = new Color(0xffffff);
  15952. this.linewidth = 1;
  15953. this.linecap = 'round';
  15954. this.linejoin = 'round';
  15955. this.morphTargets = false;
  15956. this.setValues(parameters);
  15957. }
  15958. LineBasicMaterial.prototype = Object.create(Material.prototype);
  15959. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15960. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15961. LineBasicMaterial.prototype.copy = function (source) {
  15962. Material.prototype.copy.call(this, source);
  15963. this.color.copy(source.color);
  15964. this.linewidth = source.linewidth;
  15965. this.linecap = source.linecap;
  15966. this.linejoin = source.linejoin;
  15967. this.morphTargets = source.morphTargets;
  15968. return this;
  15969. };
  15970. var _start = new Vector3();
  15971. var _end = new Vector3();
  15972. var _inverseMatrix$1 = new Matrix4();
  15973. var _ray$1 = new Ray();
  15974. var _sphere$2 = new Sphere();
  15975. function Line(geometry, material, mode) {
  15976. if (mode === 1) {
  15977. console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');
  15978. }
  15979. Object3D.call(this);
  15980. this.type = 'Line';
  15981. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15982. this.material = material !== undefined ? material : new LineBasicMaterial();
  15983. this.updateMorphTargets();
  15984. }
  15985. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  15986. constructor: Line,
  15987. isLine: true,
  15988. copy: function copy(source) {
  15989. Object3D.prototype.copy.call(this, source);
  15990. this.material = source.material;
  15991. this.geometry = source.geometry;
  15992. return this;
  15993. },
  15994. computeLineDistances: function computeLineDistances() {
  15995. var geometry = this.geometry;
  15996. if (geometry.isBufferGeometry) {
  15997. // we assume non-indexed geometry
  15998. if (geometry.index === null) {
  15999. var positionAttribute = geometry.attributes.position;
  16000. var lineDistances = [0];
  16001. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16002. _start.fromBufferAttribute(positionAttribute, i - 1);
  16003. _end.fromBufferAttribute(positionAttribute, i);
  16004. lineDistances[i] = lineDistances[i - 1];
  16005. lineDistances[i] += _start.distanceTo(_end);
  16006. }
  16007. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16008. } else {
  16009. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16010. }
  16011. } else if (geometry.isGeometry) {
  16012. var vertices = geometry.vertices;
  16013. var _lineDistances = geometry.lineDistances;
  16014. _lineDistances[0] = 0;
  16015. for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
  16016. _lineDistances[_i] = _lineDistances[_i - 1];
  16017. _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
  16018. }
  16019. }
  16020. return this;
  16021. },
  16022. raycast: function raycast(raycaster, intersects) {
  16023. var geometry = this.geometry;
  16024. var matrixWorld = this.matrixWorld;
  16025. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16026. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16027. _sphere$2.copy(geometry.boundingSphere);
  16028. _sphere$2.applyMatrix4(matrixWorld);
  16029. _sphere$2.radius += threshold;
  16030. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16031. _inverseMatrix$1.getInverse(matrixWorld);
  16032. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16033. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16034. var localThresholdSq = localThreshold * localThreshold;
  16035. var vStart = new Vector3();
  16036. var vEnd = new Vector3();
  16037. var interSegment = new Vector3();
  16038. var interRay = new Vector3();
  16039. var step = this.isLineSegments ? 2 : 1;
  16040. if (geometry.isBufferGeometry) {
  16041. var index = geometry.index;
  16042. var attributes = geometry.attributes;
  16043. var positionAttribute = attributes.position;
  16044. if (index !== null) {
  16045. var indices = index.array;
  16046. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16047. var a = indices[i];
  16048. var b = indices[i + 1];
  16049. vStart.fromBufferAttribute(positionAttribute, a);
  16050. vEnd.fromBufferAttribute(positionAttribute, b);
  16051. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16052. if (distSq > localThresholdSq) continue;
  16053. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16054. var distance = raycaster.ray.origin.distanceTo(interRay);
  16055. if (distance < raycaster.near || distance > raycaster.far) continue;
  16056. intersects.push({
  16057. distance: distance,
  16058. // What do we want? intersection point on the ray or on the segment??
  16059. // point: raycaster.ray.at( distance ),
  16060. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16061. index: i,
  16062. face: null,
  16063. faceIndex: null,
  16064. object: this
  16065. });
  16066. }
  16067. } else {
  16068. for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
  16069. vStart.fromBufferAttribute(positionAttribute, _i2);
  16070. vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
  16071. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16072. if (_distSq > localThresholdSq) continue;
  16073. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16074. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16075. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16076. intersects.push({
  16077. distance: _distance,
  16078. // What do we want? intersection point on the ray or on the segment??
  16079. // point: raycaster.ray.at( distance ),
  16080. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16081. index: _i2,
  16082. face: null,
  16083. faceIndex: null,
  16084. object: this
  16085. });
  16086. }
  16087. }
  16088. } else if (geometry.isGeometry) {
  16089. var vertices = geometry.vertices;
  16090. var nbVertices = vertices.length;
  16091. for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
  16092. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
  16093. if (_distSq2 > localThresholdSq) continue;
  16094. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16095. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16096. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16097. intersects.push({
  16098. distance: _distance2,
  16099. // What do we want? intersection point on the ray or on the segment??
  16100. // point: raycaster.ray.at( distance ),
  16101. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16102. index: _i3,
  16103. face: null,
  16104. faceIndex: null,
  16105. object: this
  16106. });
  16107. }
  16108. }
  16109. },
  16110. updateMorphTargets: function updateMorphTargets() {
  16111. var geometry = this.geometry;
  16112. if (geometry.isBufferGeometry) {
  16113. var morphAttributes = geometry.morphAttributes;
  16114. var keys = Object.keys(morphAttributes);
  16115. if (keys.length > 0) {
  16116. var morphAttribute = morphAttributes[keys[0]];
  16117. if (morphAttribute !== undefined) {
  16118. this.morphTargetInfluences = [];
  16119. this.morphTargetDictionary = {};
  16120. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16121. var name = morphAttribute[m].name || String(m);
  16122. this.morphTargetInfluences.push(0);
  16123. this.morphTargetDictionary[name] = m;
  16124. }
  16125. }
  16126. }
  16127. } else {
  16128. var morphTargets = geometry.morphTargets;
  16129. if (morphTargets !== undefined && morphTargets.length > 0) {
  16130. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16131. }
  16132. }
  16133. }
  16134. });
  16135. var _start$1 = new Vector3();
  16136. var _end$1 = new Vector3();
  16137. function LineSegments(geometry, material) {
  16138. Line.call(this, geometry, material);
  16139. this.type = 'LineSegments';
  16140. }
  16141. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16142. constructor: LineSegments,
  16143. isLineSegments: true,
  16144. computeLineDistances: function computeLineDistances() {
  16145. var geometry = this.geometry;
  16146. if (geometry.isBufferGeometry) {
  16147. // we assume non-indexed geometry
  16148. if (geometry.index === null) {
  16149. var positionAttribute = geometry.attributes.position;
  16150. var lineDistances = [];
  16151. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16152. _start$1.fromBufferAttribute(positionAttribute, i);
  16153. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16154. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16155. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16156. }
  16157. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16158. } else {
  16159. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16160. }
  16161. } else if (geometry.isGeometry) {
  16162. var vertices = geometry.vertices;
  16163. var _lineDistances = geometry.lineDistances;
  16164. for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
  16165. _start$1.copy(vertices[_i]);
  16166. _end$1.copy(vertices[_i + 1]);
  16167. _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
  16168. _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
  16169. }
  16170. }
  16171. return this;
  16172. }
  16173. });
  16174. function LineLoop(geometry, material) {
  16175. Line.call(this, geometry, material);
  16176. this.type = 'LineLoop';
  16177. }
  16178. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16179. constructor: LineLoop,
  16180. isLineLoop: true
  16181. });
  16182. /**
  16183. * parameters = {
  16184. * color: <hex>,
  16185. * opacity: <float>,
  16186. * map: new THREE.Texture( <Image> ),
  16187. * alphaMap: new THREE.Texture( <Image> ),
  16188. *
  16189. * size: <float>,
  16190. * sizeAttenuation: <bool>
  16191. *
  16192. * morphTargets: <bool>
  16193. * }
  16194. */
  16195. function PointsMaterial(parameters) {
  16196. Material.call(this);
  16197. this.type = 'PointsMaterial';
  16198. this.color = new Color(0xffffff);
  16199. this.map = null;
  16200. this.alphaMap = null;
  16201. this.size = 1;
  16202. this.sizeAttenuation = true;
  16203. this.morphTargets = false;
  16204. this.setValues(parameters);
  16205. }
  16206. PointsMaterial.prototype = Object.create(Material.prototype);
  16207. PointsMaterial.prototype.constructor = PointsMaterial;
  16208. PointsMaterial.prototype.isPointsMaterial = true;
  16209. PointsMaterial.prototype.copy = function (source) {
  16210. Material.prototype.copy.call(this, source);
  16211. this.color.copy(source.color);
  16212. this.map = source.map;
  16213. this.alphaMap = source.alphaMap;
  16214. this.size = source.size;
  16215. this.sizeAttenuation = source.sizeAttenuation;
  16216. this.morphTargets = source.morphTargets;
  16217. return this;
  16218. };
  16219. var _inverseMatrix$2 = new Matrix4();
  16220. var _ray$2 = new Ray();
  16221. var _sphere$3 = new Sphere();
  16222. var _position$1 = new Vector3();
  16223. function Points(geometry, material) {
  16224. Object3D.call(this);
  16225. this.type = 'Points';
  16226. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16227. this.material = material !== undefined ? material : new PointsMaterial();
  16228. this.updateMorphTargets();
  16229. }
  16230. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16231. constructor: Points,
  16232. isPoints: true,
  16233. copy: function copy(source) {
  16234. Object3D.prototype.copy.call(this, source);
  16235. this.material = source.material;
  16236. this.geometry = source.geometry;
  16237. return this;
  16238. },
  16239. raycast: function raycast(raycaster, intersects) {
  16240. var geometry = this.geometry;
  16241. var matrixWorld = this.matrixWorld;
  16242. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16243. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16244. _sphere$3.copy(geometry.boundingSphere);
  16245. _sphere$3.applyMatrix4(matrixWorld);
  16246. _sphere$3.radius += threshold;
  16247. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16248. _inverseMatrix$2.getInverse(matrixWorld);
  16249. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16250. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16251. var localThresholdSq = localThreshold * localThreshold;
  16252. if (geometry.isBufferGeometry) {
  16253. var index = geometry.index;
  16254. var attributes = geometry.attributes;
  16255. var positionAttribute = attributes.position;
  16256. if (index !== null) {
  16257. var indices = index.array;
  16258. for (var i = 0, il = indices.length; i < il; i++) {
  16259. var a = indices[i];
  16260. _position$1.fromBufferAttribute(positionAttribute, a);
  16261. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16262. }
  16263. } else {
  16264. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16265. _position$1.fromBufferAttribute(positionAttribute, _i);
  16266. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16267. }
  16268. }
  16269. } else {
  16270. var vertices = geometry.vertices;
  16271. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16272. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16273. }
  16274. }
  16275. },
  16276. updateMorphTargets: function updateMorphTargets() {
  16277. var geometry = this.geometry;
  16278. if (geometry.isBufferGeometry) {
  16279. var morphAttributes = geometry.morphAttributes;
  16280. var keys = Object.keys(morphAttributes);
  16281. if (keys.length > 0) {
  16282. var morphAttribute = morphAttributes[keys[0]];
  16283. if (morphAttribute !== undefined) {
  16284. this.morphTargetInfluences = [];
  16285. this.morphTargetDictionary = {};
  16286. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16287. var name = morphAttribute[m].name || String(m);
  16288. this.morphTargetInfluences.push(0);
  16289. this.morphTargetDictionary[name] = m;
  16290. }
  16291. }
  16292. }
  16293. } else {
  16294. var morphTargets = geometry.morphTargets;
  16295. if (morphTargets !== undefined && morphTargets.length > 0) {
  16296. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16297. }
  16298. }
  16299. }
  16300. });
  16301. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16302. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16303. if (rayPointDistanceSq < localThresholdSq) {
  16304. var intersectPoint = new Vector3();
  16305. _ray$2.closestPointToPoint(point, intersectPoint);
  16306. intersectPoint.applyMatrix4(matrixWorld);
  16307. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16308. if (distance < raycaster.near || distance > raycaster.far) return;
  16309. intersects.push({
  16310. distance: distance,
  16311. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16312. point: intersectPoint,
  16313. index: index,
  16314. face: null,
  16315. object: object
  16316. });
  16317. }
  16318. }
  16319. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16320. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16321. this.format = format !== undefined ? format : RGBFormat;
  16322. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16323. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16324. this.generateMipmaps = false;
  16325. var scope = this;
  16326. function updateVideo() {
  16327. scope.needsUpdate = true;
  16328. video.requestVideoFrameCallback(updateVideo);
  16329. }
  16330. if ('requestVideoFrameCallback' in video) {
  16331. video.requestVideoFrameCallback(updateVideo);
  16332. }
  16333. }
  16334. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16335. constructor: VideoTexture,
  16336. isVideoTexture: true,
  16337. update: function update() {
  16338. var video = this.image;
  16339. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16340. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16341. this.needsUpdate = true;
  16342. }
  16343. }
  16344. });
  16345. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16346. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16347. this.image = {
  16348. width: width,
  16349. height: height
  16350. };
  16351. this.mipmaps = mipmaps; // no flipping for cube textures
  16352. // (also flipping doesn't work for compressed textures )
  16353. this.flipY = false; // can't generate mipmaps for compressed textures
  16354. // mips must be embedded in DDS files
  16355. this.generateMipmaps = false;
  16356. }
  16357. CompressedTexture.prototype = Object.create(Texture.prototype);
  16358. CompressedTexture.prototype.constructor = CompressedTexture;
  16359. CompressedTexture.prototype.isCompressedTexture = true;
  16360. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16361. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16362. this.needsUpdate = true;
  16363. }
  16364. CanvasTexture.prototype = Object.create(Texture.prototype);
  16365. CanvasTexture.prototype.constructor = CanvasTexture;
  16366. CanvasTexture.prototype.isCanvasTexture = true;
  16367. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16368. format = format !== undefined ? format : DepthFormat;
  16369. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16370. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16371. }
  16372. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16373. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16374. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16375. this.image = {
  16376. width: width,
  16377. height: height
  16378. };
  16379. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16380. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16381. this.flipY = false;
  16382. this.generateMipmaps = false;
  16383. }
  16384. DepthTexture.prototype = Object.create(Texture.prototype);
  16385. DepthTexture.prototype.constructor = DepthTexture;
  16386. DepthTexture.prototype.isDepthTexture = true;
  16387. var _geometryId = 0; // Geometry uses even numbers as Id
  16388. var _m1$3 = new Matrix4();
  16389. var _obj$1 = new Object3D();
  16390. var _offset$1 = new Vector3();
  16391. function Geometry() {
  16392. Object.defineProperty(this, 'id', {
  16393. value: _geometryId += 2
  16394. });
  16395. this.uuid = MathUtils.generateUUID();
  16396. this.name = '';
  16397. this.type = 'Geometry';
  16398. this.vertices = [];
  16399. this.colors = [];
  16400. this.faces = [];
  16401. this.faceVertexUvs = [[]];
  16402. this.morphTargets = [];
  16403. this.morphNormals = [];
  16404. this.skinWeights = [];
  16405. this.skinIndices = [];
  16406. this.lineDistances = [];
  16407. this.boundingBox = null;
  16408. this.boundingSphere = null; // update flags
  16409. this.elementsNeedUpdate = false;
  16410. this.verticesNeedUpdate = false;
  16411. this.uvsNeedUpdate = false;
  16412. this.normalsNeedUpdate = false;
  16413. this.colorsNeedUpdate = false;
  16414. this.lineDistancesNeedUpdate = false;
  16415. this.groupsNeedUpdate = false;
  16416. }
  16417. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16418. constructor: Geometry,
  16419. isGeometry: true,
  16420. applyMatrix4: function applyMatrix4(matrix) {
  16421. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16422. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16423. var vertex = this.vertices[i];
  16424. vertex.applyMatrix4(matrix);
  16425. }
  16426. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16427. var face = this.faces[_i];
  16428. face.normal.applyMatrix3(normalMatrix).normalize();
  16429. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16430. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16431. }
  16432. }
  16433. if (this.boundingBox !== null) {
  16434. this.computeBoundingBox();
  16435. }
  16436. if (this.boundingSphere !== null) {
  16437. this.computeBoundingSphere();
  16438. }
  16439. this.verticesNeedUpdate = true;
  16440. this.normalsNeedUpdate = true;
  16441. return this;
  16442. },
  16443. rotateX: function rotateX(angle) {
  16444. // rotate geometry around world x-axis
  16445. _m1$3.makeRotationX(angle);
  16446. this.applyMatrix4(_m1$3);
  16447. return this;
  16448. },
  16449. rotateY: function rotateY(angle) {
  16450. // rotate geometry around world y-axis
  16451. _m1$3.makeRotationY(angle);
  16452. this.applyMatrix4(_m1$3);
  16453. return this;
  16454. },
  16455. rotateZ: function rotateZ(angle) {
  16456. // rotate geometry around world z-axis
  16457. _m1$3.makeRotationZ(angle);
  16458. this.applyMatrix4(_m1$3);
  16459. return this;
  16460. },
  16461. translate: function translate(x, y, z) {
  16462. // translate geometry
  16463. _m1$3.makeTranslation(x, y, z);
  16464. this.applyMatrix4(_m1$3);
  16465. return this;
  16466. },
  16467. scale: function scale(x, y, z) {
  16468. // scale geometry
  16469. _m1$3.makeScale(x, y, z);
  16470. this.applyMatrix4(_m1$3);
  16471. return this;
  16472. },
  16473. lookAt: function lookAt(vector) {
  16474. _obj$1.lookAt(vector);
  16475. _obj$1.updateMatrix();
  16476. this.applyMatrix4(_obj$1.matrix);
  16477. return this;
  16478. },
  16479. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16480. var scope = this;
  16481. var index = geometry.index !== null ? geometry.index : undefined;
  16482. var attributes = geometry.attributes;
  16483. if (attributes.position === undefined) {
  16484. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16485. return this;
  16486. }
  16487. var position = attributes.position;
  16488. var normal = attributes.normal;
  16489. var color = attributes.color;
  16490. var uv = attributes.uv;
  16491. var uv2 = attributes.uv2;
  16492. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16493. for (var i = 0; i < position.count; i++) {
  16494. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16495. if (color !== undefined) {
  16496. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16497. }
  16498. }
  16499. function addFace(a, b, c, materialIndex) {
  16500. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16501. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16502. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16503. scope.faces.push(face);
  16504. if (uv !== undefined) {
  16505. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16506. }
  16507. if (uv2 !== undefined) {
  16508. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16509. }
  16510. }
  16511. var groups = geometry.groups;
  16512. if (groups.length > 0) {
  16513. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16514. var group = groups[_i2];
  16515. var start = group.start;
  16516. var count = group.count;
  16517. for (var j = start, jl = start + count; j < jl; j += 3) {
  16518. if (index !== undefined) {
  16519. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16520. } else {
  16521. addFace(j, j + 1, j + 2, group.materialIndex);
  16522. }
  16523. }
  16524. }
  16525. } else {
  16526. if (index !== undefined) {
  16527. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16528. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16529. }
  16530. } else {
  16531. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16532. addFace(_i4, _i4 + 1, _i4 + 2);
  16533. }
  16534. }
  16535. }
  16536. this.computeFaceNormals();
  16537. if (geometry.boundingBox !== null) {
  16538. this.boundingBox = geometry.boundingBox.clone();
  16539. }
  16540. if (geometry.boundingSphere !== null) {
  16541. this.boundingSphere = geometry.boundingSphere.clone();
  16542. }
  16543. return this;
  16544. },
  16545. center: function center() {
  16546. this.computeBoundingBox();
  16547. this.boundingBox.getCenter(_offset$1).negate();
  16548. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16549. return this;
  16550. },
  16551. normalize: function normalize() {
  16552. this.computeBoundingSphere();
  16553. var center = this.boundingSphere.center;
  16554. var radius = this.boundingSphere.radius;
  16555. var s = radius === 0 ? 1 : 1.0 / radius;
  16556. var matrix = new Matrix4();
  16557. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16558. this.applyMatrix4(matrix);
  16559. return this;
  16560. },
  16561. computeFaceNormals: function computeFaceNormals() {
  16562. var cb = new Vector3(),
  16563. ab = new Vector3();
  16564. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16565. var face = this.faces[f];
  16566. var vA = this.vertices[face.a];
  16567. var vB = this.vertices[face.b];
  16568. var vC = this.vertices[face.c];
  16569. cb.subVectors(vC, vB);
  16570. ab.subVectors(vA, vB);
  16571. cb.cross(ab);
  16572. cb.normalize();
  16573. face.normal.copy(cb);
  16574. }
  16575. },
  16576. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16577. if (areaWeighted === undefined) areaWeighted = true;
  16578. var vertices = new Array(this.vertices.length);
  16579. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16580. vertices[v] = new Vector3();
  16581. }
  16582. if (areaWeighted) {
  16583. // vertex normals weighted by triangle areas
  16584. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16585. var cb = new Vector3(),
  16586. ab = new Vector3();
  16587. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16588. var face = this.faces[f];
  16589. var vA = this.vertices[face.a];
  16590. var vB = this.vertices[face.b];
  16591. var vC = this.vertices[face.c];
  16592. cb.subVectors(vC, vB);
  16593. ab.subVectors(vA, vB);
  16594. cb.cross(ab);
  16595. vertices[face.a].add(cb);
  16596. vertices[face.b].add(cb);
  16597. vertices[face.c].add(cb);
  16598. }
  16599. } else {
  16600. this.computeFaceNormals();
  16601. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16602. var _face = this.faces[_f];
  16603. vertices[_face.a].add(_face.normal);
  16604. vertices[_face.b].add(_face.normal);
  16605. vertices[_face.c].add(_face.normal);
  16606. }
  16607. }
  16608. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16609. vertices[_v].normalize();
  16610. }
  16611. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16612. var _face2 = this.faces[_f2];
  16613. var vertexNormals = _face2.vertexNormals;
  16614. if (vertexNormals.length === 3) {
  16615. vertexNormals[0].copy(vertices[_face2.a]);
  16616. vertexNormals[1].copy(vertices[_face2.b]);
  16617. vertexNormals[2].copy(vertices[_face2.c]);
  16618. } else {
  16619. vertexNormals[0] = vertices[_face2.a].clone();
  16620. vertexNormals[1] = vertices[_face2.b].clone();
  16621. vertexNormals[2] = vertices[_face2.c].clone();
  16622. }
  16623. }
  16624. if (this.faces.length > 0) {
  16625. this.normalsNeedUpdate = true;
  16626. }
  16627. },
  16628. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16629. this.computeFaceNormals();
  16630. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16631. var face = this.faces[f];
  16632. var vertexNormals = face.vertexNormals;
  16633. if (vertexNormals.length === 3) {
  16634. vertexNormals[0].copy(face.normal);
  16635. vertexNormals[1].copy(face.normal);
  16636. vertexNormals[2].copy(face.normal);
  16637. } else {
  16638. vertexNormals[0] = face.normal.clone();
  16639. vertexNormals[1] = face.normal.clone();
  16640. vertexNormals[2] = face.normal.clone();
  16641. }
  16642. }
  16643. if (this.faces.length > 0) {
  16644. this.normalsNeedUpdate = true;
  16645. }
  16646. },
  16647. computeMorphNormals: function computeMorphNormals() {
  16648. // save original normals
  16649. // - create temp variables on first access
  16650. // otherwise just copy (for faster repeated calls)
  16651. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16652. var face = this.faces[f];
  16653. if (!face.__originalFaceNormal) {
  16654. face.__originalFaceNormal = face.normal.clone();
  16655. } else {
  16656. face.__originalFaceNormal.copy(face.normal);
  16657. }
  16658. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16659. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16660. if (!face.__originalVertexNormals[i]) {
  16661. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16662. } else {
  16663. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16664. }
  16665. }
  16666. } // use temp geometry to compute face and vertex normals for each morph
  16667. var tmpGeo = new Geometry();
  16668. tmpGeo.faces = this.faces;
  16669. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  16670. // create on first access
  16671. if (!this.morphNormals[_i5]) {
  16672. this.morphNormals[_i5] = {};
  16673. this.morphNormals[_i5].faceNormals = [];
  16674. this.morphNormals[_i5].vertexNormals = [];
  16675. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  16676. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  16677. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  16678. var faceNormal = new Vector3();
  16679. var vertexNormals = {
  16680. a: new Vector3(),
  16681. b: new Vector3(),
  16682. c: new Vector3()
  16683. };
  16684. dstNormalsFace.push(faceNormal);
  16685. dstNormalsVertex.push(vertexNormals);
  16686. }
  16687. }
  16688. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  16689. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  16690. tmpGeo.computeFaceNormals();
  16691. tmpGeo.computeVertexNormals(); // store morph normals
  16692. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  16693. var _face3 = this.faces[_f4];
  16694. var _faceNormal = morphNormals.faceNormals[_f4];
  16695. var _vertexNormals = morphNormals.vertexNormals[_f4];
  16696. _faceNormal.copy(_face3.normal);
  16697. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  16698. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  16699. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  16700. }
  16701. } // restore original normals
  16702. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  16703. var _face4 = this.faces[_f5];
  16704. _face4.normal = _face4.__originalFaceNormal;
  16705. _face4.vertexNormals = _face4.__originalVertexNormals;
  16706. }
  16707. },
  16708. computeBoundingBox: function computeBoundingBox() {
  16709. if (this.boundingBox === null) {
  16710. this.boundingBox = new Box3();
  16711. }
  16712. this.boundingBox.setFromPoints(this.vertices);
  16713. },
  16714. computeBoundingSphere: function computeBoundingSphere() {
  16715. if (this.boundingSphere === null) {
  16716. this.boundingSphere = new Sphere();
  16717. }
  16718. this.boundingSphere.setFromPoints(this.vertices);
  16719. },
  16720. merge: function merge(geometry, matrix, materialIndexOffset) {
  16721. if (!(geometry && geometry.isGeometry)) {
  16722. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  16723. return;
  16724. }
  16725. var normalMatrix;
  16726. var vertexOffset = this.vertices.length,
  16727. vertices1 = this.vertices,
  16728. vertices2 = geometry.vertices,
  16729. faces1 = this.faces,
  16730. faces2 = geometry.faces,
  16731. colors1 = this.colors,
  16732. colors2 = geometry.colors;
  16733. if (materialIndexOffset === undefined) materialIndexOffset = 0;
  16734. if (matrix !== undefined) {
  16735. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16736. } // vertices
  16737. for (var i = 0, il = vertices2.length; i < il; i++) {
  16738. var vertex = vertices2[i];
  16739. var vertexCopy = vertex.clone();
  16740. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  16741. vertices1.push(vertexCopy);
  16742. } // colors
  16743. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  16744. colors1.push(colors2[_i6].clone());
  16745. } // faces
  16746. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  16747. var face = faces2[_i7];
  16748. var normal = void 0,
  16749. color = void 0;
  16750. var faceVertexNormals = face.vertexNormals,
  16751. faceVertexColors = face.vertexColors;
  16752. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  16753. faceCopy.normal.copy(face.normal);
  16754. if (normalMatrix !== undefined) {
  16755. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  16756. }
  16757. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  16758. normal = faceVertexNormals[j].clone();
  16759. if (normalMatrix !== undefined) {
  16760. normal.applyMatrix3(normalMatrix).normalize();
  16761. }
  16762. faceCopy.vertexNormals.push(normal);
  16763. }
  16764. faceCopy.color.copy(face.color);
  16765. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  16766. color = faceVertexColors[_j];
  16767. faceCopy.vertexColors.push(color.clone());
  16768. }
  16769. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  16770. faces1.push(faceCopy);
  16771. } // uvs
  16772. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  16773. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  16774. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  16775. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  16776. var uvs2 = faceVertexUvs2[_j2],
  16777. uvsCopy = [];
  16778. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  16779. uvsCopy.push(uvs2[k].clone());
  16780. }
  16781. this.faceVertexUvs[_i8].push(uvsCopy);
  16782. }
  16783. }
  16784. },
  16785. mergeMesh: function mergeMesh(mesh) {
  16786. if (!(mesh && mesh.isMesh)) {
  16787. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  16788. return;
  16789. }
  16790. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  16791. this.merge(mesh.geometry, mesh.matrix);
  16792. },
  16793. /*
  16794. * Checks for duplicate vertices with hashmap.
  16795. * Duplicated vertices are removed
  16796. * and faces' vertices are updated.
  16797. */
  16798. mergeVertices: function mergeVertices() {
  16799. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  16800. var unique = [],
  16801. changes = [];
  16802. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  16803. var precision = Math.pow(10, precisionPoints);
  16804. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16805. var v = this.vertices[i];
  16806. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  16807. if (verticesMap[key] === undefined) {
  16808. verticesMap[key] = i;
  16809. unique.push(this.vertices[i]);
  16810. changes[i] = unique.length - 1;
  16811. } else {
  16812. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  16813. changes[i] = changes[verticesMap[key]];
  16814. }
  16815. } // if faces are completely degenerate after merging vertices, we
  16816. // have to remove them from the geometry.
  16817. var faceIndicesToRemove = [];
  16818. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  16819. var face = this.faces[_i9];
  16820. face.a = changes[face.a];
  16821. face.b = changes[face.b];
  16822. face.c = changes[face.c];
  16823. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  16824. // we have to remove the face as nothing can be saved
  16825. for (var n = 0; n < 3; n++) {
  16826. if (indices[n] === indices[(n + 1) % 3]) {
  16827. faceIndicesToRemove.push(_i9);
  16828. break;
  16829. }
  16830. }
  16831. }
  16832. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  16833. var idx = faceIndicesToRemove[_i10];
  16834. this.faces.splice(idx, 1);
  16835. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  16836. this.faceVertexUvs[j].splice(idx, 1);
  16837. }
  16838. } // Use unique set of vertices
  16839. var diff = this.vertices.length - unique.length;
  16840. this.vertices = unique;
  16841. return diff;
  16842. },
  16843. setFromPoints: function setFromPoints(points) {
  16844. this.vertices = [];
  16845. for (var i = 0, l = points.length; i < l; i++) {
  16846. var point = points[i];
  16847. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  16848. }
  16849. return this;
  16850. },
  16851. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  16852. var faces = this.faces;
  16853. var length = faces.length; // tag faces
  16854. for (var i = 0; i < length; i++) {
  16855. faces[i]._id = i;
  16856. } // sort faces
  16857. function materialIndexSort(a, b) {
  16858. return a.materialIndex - b.materialIndex;
  16859. }
  16860. faces.sort(materialIndexSort); // sort uvs
  16861. var uvs1 = this.faceVertexUvs[0];
  16862. var uvs2 = this.faceVertexUvs[1];
  16863. var newUvs1, newUvs2;
  16864. if (uvs1 && uvs1.length === length) newUvs1 = [];
  16865. if (uvs2 && uvs2.length === length) newUvs2 = [];
  16866. for (var _i11 = 0; _i11 < length; _i11++) {
  16867. var id = faces[_i11]._id;
  16868. if (newUvs1) newUvs1.push(uvs1[id]);
  16869. if (newUvs2) newUvs2.push(uvs2[id]);
  16870. }
  16871. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  16872. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  16873. },
  16874. toJSON: function toJSON() {
  16875. var data = {
  16876. metadata: {
  16877. version: 4.5,
  16878. type: 'Geometry',
  16879. generator: 'Geometry.toJSON'
  16880. }
  16881. }; // standard Geometry serialization
  16882. data.uuid = this.uuid;
  16883. data.type = this.type;
  16884. if (this.name !== '') data.name = this.name;
  16885. if (this.parameters !== undefined) {
  16886. var parameters = this.parameters;
  16887. for (var key in parameters) {
  16888. if (parameters[key] !== undefined) data[key] = parameters[key];
  16889. }
  16890. return data;
  16891. }
  16892. var vertices = [];
  16893. for (var i = 0; i < this.vertices.length; i++) {
  16894. var vertex = this.vertices[i];
  16895. vertices.push(vertex.x, vertex.y, vertex.z);
  16896. }
  16897. var faces = [];
  16898. var normals = [];
  16899. var normalsHash = {};
  16900. var colors = [];
  16901. var colorsHash = {};
  16902. var uvs = [];
  16903. var uvsHash = {};
  16904. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  16905. var face = this.faces[_i12];
  16906. var hasMaterial = true;
  16907. var hasFaceUv = false; // deprecated
  16908. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  16909. var hasFaceNormal = face.normal.length() > 0;
  16910. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  16911. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  16912. var hasFaceVertexColor = face.vertexColors.length > 0;
  16913. var faceType = 0;
  16914. faceType = setBit(faceType, 0, 0); // isQuad
  16915. faceType = setBit(faceType, 1, hasMaterial);
  16916. faceType = setBit(faceType, 2, hasFaceUv);
  16917. faceType = setBit(faceType, 3, hasFaceVertexUv);
  16918. faceType = setBit(faceType, 4, hasFaceNormal);
  16919. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  16920. faceType = setBit(faceType, 6, hasFaceColor);
  16921. faceType = setBit(faceType, 7, hasFaceVertexColor);
  16922. faces.push(faceType);
  16923. faces.push(face.a, face.b, face.c);
  16924. faces.push(face.materialIndex);
  16925. if (hasFaceVertexUv) {
  16926. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  16927. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  16928. }
  16929. if (hasFaceNormal) {
  16930. faces.push(getNormalIndex(face.normal));
  16931. }
  16932. if (hasFaceVertexNormal) {
  16933. var vertexNormals = face.vertexNormals;
  16934. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  16935. }
  16936. if (hasFaceColor) {
  16937. faces.push(getColorIndex(face.color));
  16938. }
  16939. if (hasFaceVertexColor) {
  16940. var vertexColors = face.vertexColors;
  16941. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  16942. }
  16943. }
  16944. function setBit(value, position, enabled) {
  16945. return enabled ? value | 1 << position : value & ~(1 << position);
  16946. }
  16947. function getNormalIndex(normal) {
  16948. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  16949. if (normalsHash[hash] !== undefined) {
  16950. return normalsHash[hash];
  16951. }
  16952. normalsHash[hash] = normals.length / 3;
  16953. normals.push(normal.x, normal.y, normal.z);
  16954. return normalsHash[hash];
  16955. }
  16956. function getColorIndex(color) {
  16957. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  16958. if (colorsHash[hash] !== undefined) {
  16959. return colorsHash[hash];
  16960. }
  16961. colorsHash[hash] = colors.length;
  16962. colors.push(color.getHex());
  16963. return colorsHash[hash];
  16964. }
  16965. function getUvIndex(uv) {
  16966. var hash = uv.x.toString() + uv.y.toString();
  16967. if (uvsHash[hash] !== undefined) {
  16968. return uvsHash[hash];
  16969. }
  16970. uvsHash[hash] = uvs.length / 2;
  16971. uvs.push(uv.x, uv.y);
  16972. return uvsHash[hash];
  16973. }
  16974. data.data = {};
  16975. data.data.vertices = vertices;
  16976. data.data.normals = normals;
  16977. if (colors.length > 0) data.data.colors = colors;
  16978. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  16979. data.data.faces = faces;
  16980. return data;
  16981. },
  16982. clone: function clone() {
  16983. /*
  16984. // Handle primitives
  16985. const parameters = this.parameters;
  16986. if ( parameters !== undefined ) {
  16987. const values = [];
  16988. for ( const key in parameters ) {
  16989. values.push( parameters[ key ] );
  16990. }
  16991. const geometry = Object.create( this.constructor.prototype );
  16992. this.constructor.apply( geometry, values );
  16993. return geometry;
  16994. }
  16995. return new this.constructor().copy( this );
  16996. */
  16997. return new Geometry().copy(this);
  16998. },
  16999. copy: function copy(source) {
  17000. // reset
  17001. this.vertices = [];
  17002. this.colors = [];
  17003. this.faces = [];
  17004. this.faceVertexUvs = [[]];
  17005. this.morphTargets = [];
  17006. this.morphNormals = [];
  17007. this.skinWeights = [];
  17008. this.skinIndices = [];
  17009. this.lineDistances = [];
  17010. this.boundingBox = null;
  17011. this.boundingSphere = null; // name
  17012. this.name = source.name; // vertices
  17013. var vertices = source.vertices;
  17014. for (var i = 0, il = vertices.length; i < il; i++) {
  17015. this.vertices.push(vertices[i].clone());
  17016. } // colors
  17017. var colors = source.colors;
  17018. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  17019. this.colors.push(colors[_i13].clone());
  17020. } // faces
  17021. var faces = source.faces;
  17022. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  17023. this.faces.push(faces[_i14].clone());
  17024. } // face vertex uvs
  17025. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  17026. var faceVertexUvs = source.faceVertexUvs[_i15];
  17027. if (this.faceVertexUvs[_i15] === undefined) {
  17028. this.faceVertexUvs[_i15] = [];
  17029. }
  17030. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  17031. var uvs = faceVertexUvs[j],
  17032. uvsCopy = [];
  17033. for (var k = 0, kl = uvs.length; k < kl; k++) {
  17034. var uv = uvs[k];
  17035. uvsCopy.push(uv.clone());
  17036. }
  17037. this.faceVertexUvs[_i15].push(uvsCopy);
  17038. }
  17039. } // morph targets
  17040. var morphTargets = source.morphTargets;
  17041. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  17042. var morphTarget = {};
  17043. morphTarget.name = morphTargets[_i16].name; // vertices
  17044. if (morphTargets[_i16].vertices !== undefined) {
  17045. morphTarget.vertices = [];
  17046. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  17047. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  17048. }
  17049. } // normals
  17050. if (morphTargets[_i16].normals !== undefined) {
  17051. morphTarget.normals = [];
  17052. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  17053. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  17054. }
  17055. }
  17056. this.morphTargets.push(morphTarget);
  17057. } // morph normals
  17058. var morphNormals = source.morphNormals;
  17059. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  17060. var morphNormal = {}; // vertex normals
  17061. if (morphNormals[_i17].vertexNormals !== undefined) {
  17062. morphNormal.vertexNormals = [];
  17063. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17064. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17065. var destVertexNormal = {};
  17066. destVertexNormal.a = srcVertexNormal.a.clone();
  17067. destVertexNormal.b = srcVertexNormal.b.clone();
  17068. destVertexNormal.c = srcVertexNormal.c.clone();
  17069. morphNormal.vertexNormals.push(destVertexNormal);
  17070. }
  17071. } // face normals
  17072. if (morphNormals[_i17].faceNormals !== undefined) {
  17073. morphNormal.faceNormals = [];
  17074. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17075. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17076. }
  17077. }
  17078. this.morphNormals.push(morphNormal);
  17079. } // skin weights
  17080. var skinWeights = source.skinWeights;
  17081. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17082. this.skinWeights.push(skinWeights[_i18].clone());
  17083. } // skin indices
  17084. var skinIndices = source.skinIndices;
  17085. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17086. this.skinIndices.push(skinIndices[_i19].clone());
  17087. } // line distances
  17088. var lineDistances = source.lineDistances;
  17089. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17090. this.lineDistances.push(lineDistances[_i20]);
  17091. } // bounding box
  17092. var boundingBox = source.boundingBox;
  17093. if (boundingBox !== null) {
  17094. this.boundingBox = boundingBox.clone();
  17095. } // bounding sphere
  17096. var boundingSphere = source.boundingSphere;
  17097. if (boundingSphere !== null) {
  17098. this.boundingSphere = boundingSphere.clone();
  17099. } // update flags
  17100. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17101. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17102. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17103. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17104. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17105. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17106. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17107. return this;
  17108. },
  17109. dispose: function dispose() {
  17110. this.dispatchEvent({
  17111. type: 'dispose'
  17112. });
  17113. }
  17114. });
  17115. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17116. _inheritsLoose(BoxGeometry, _Geometry);
  17117. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17118. var _this;
  17119. _this = _Geometry.call(this) || this;
  17120. _this.type = 'BoxGeometry';
  17121. _this.parameters = {
  17122. width: width,
  17123. height: height,
  17124. depth: depth,
  17125. widthSegments: widthSegments,
  17126. heightSegments: heightSegments,
  17127. depthSegments: depthSegments
  17128. };
  17129. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17130. _this.mergeVertices();
  17131. return _this;
  17132. }
  17133. return BoxGeometry;
  17134. }(Geometry);
  17135. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17136. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17137. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17138. var _this;
  17139. _this = _BufferGeometry.call(this) || this;
  17140. _this.type = 'CircleBufferGeometry';
  17141. _this.parameters = {
  17142. radius: radius,
  17143. segments: segments,
  17144. thetaStart: thetaStart,
  17145. thetaLength: thetaLength
  17146. };
  17147. radius = radius || 1;
  17148. segments = segments !== undefined ? Math.max(3, segments) : 8;
  17149. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17150. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17151. var indices = [];
  17152. var vertices = [];
  17153. var normals = [];
  17154. var uvs = []; // helper variables
  17155. var vertex = new Vector3();
  17156. var uv = new Vector2(); // center point
  17157. vertices.push(0, 0, 0);
  17158. normals.push(0, 0, 1);
  17159. uvs.push(0.5, 0.5);
  17160. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17161. var segment = thetaStart + s / segments * thetaLength; // vertex
  17162. vertex.x = radius * Math.cos(segment);
  17163. vertex.y = radius * Math.sin(segment);
  17164. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17165. normals.push(0, 0, 1); // uvs
  17166. uv.x = (vertices[i] / radius + 1) / 2;
  17167. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17168. uvs.push(uv.x, uv.y);
  17169. } // indices
  17170. for (var _i = 1; _i <= segments; _i++) {
  17171. indices.push(_i, _i + 1, 0);
  17172. } // build geometry
  17173. _this.setIndex(indices);
  17174. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17175. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17176. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17177. return _this;
  17178. }
  17179. return CircleBufferGeometry;
  17180. }(BufferGeometry);
  17181. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17182. _inheritsLoose(CircleGeometry, _Geometry);
  17183. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17184. var _this;
  17185. _this = _Geometry.call(this) || this;
  17186. _this.type = 'CircleGeometry';
  17187. _this.parameters = {
  17188. radius: radius,
  17189. segments: segments,
  17190. thetaStart: thetaStart,
  17191. thetaLength: thetaLength
  17192. };
  17193. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17194. _this.mergeVertices();
  17195. return _this;
  17196. }
  17197. return CircleGeometry;
  17198. }(Geometry);
  17199. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17200. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17201. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17202. var _this;
  17203. _this = _BufferGeometry.call(this) || this;
  17204. _this.type = 'CylinderBufferGeometry';
  17205. _this.parameters = {
  17206. radiusTop: radiusTop,
  17207. radiusBottom: radiusBottom,
  17208. height: height,
  17209. radialSegments: radialSegments,
  17210. heightSegments: heightSegments,
  17211. openEnded: openEnded,
  17212. thetaStart: thetaStart,
  17213. thetaLength: thetaLength
  17214. };
  17215. var scope = _assertThisInitialized(_this);
  17216. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17217. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17218. height = height || 1;
  17219. radialSegments = Math.floor(radialSegments) || 8;
  17220. heightSegments = Math.floor(heightSegments) || 1;
  17221. openEnded = openEnded !== undefined ? openEnded : false;
  17222. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17223. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17224. var indices = [];
  17225. var vertices = [];
  17226. var normals = [];
  17227. var uvs = []; // helper variables
  17228. var index = 0;
  17229. var indexArray = [];
  17230. var halfHeight = height / 2;
  17231. var groupStart = 0; // generate geometry
  17232. generateTorso();
  17233. if (openEnded === false) {
  17234. if (radiusTop > 0) generateCap(true);
  17235. if (radiusBottom > 0) generateCap(false);
  17236. } // build geometry
  17237. _this.setIndex(indices);
  17238. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17239. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17240. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17241. function generateTorso() {
  17242. var normal = new Vector3();
  17243. var vertex = new Vector3();
  17244. var groupCount = 0; // this will be used to calculate the normal
  17245. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17246. for (var y = 0; y <= heightSegments; y++) {
  17247. var indexRow = [];
  17248. var v = y / heightSegments; // calculate the radius of the current row
  17249. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17250. for (var x = 0; x <= radialSegments; x++) {
  17251. var u = x / radialSegments;
  17252. var theta = u * thetaLength + thetaStart;
  17253. var sinTheta = Math.sin(theta);
  17254. var cosTheta = Math.cos(theta); // vertex
  17255. vertex.x = radius * sinTheta;
  17256. vertex.y = -v * height + halfHeight;
  17257. vertex.z = radius * cosTheta;
  17258. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17259. normal.set(sinTheta, slope, cosTheta).normalize();
  17260. normals.push(normal.x, normal.y, normal.z); // uv
  17261. uvs.push(u, 1 - v); // save index of vertex in respective row
  17262. indexRow.push(index++);
  17263. } // now save vertices of the row in our index array
  17264. indexArray.push(indexRow);
  17265. } // generate indices
  17266. for (var _x = 0; _x < radialSegments; _x++) {
  17267. for (var _y = 0; _y < heightSegments; _y++) {
  17268. // we use the index array to access the correct indices
  17269. var a = indexArray[_y][_x];
  17270. var b = indexArray[_y + 1][_x];
  17271. var c = indexArray[_y + 1][_x + 1];
  17272. var d = indexArray[_y][_x + 1]; // faces
  17273. indices.push(a, b, d);
  17274. indices.push(b, c, d); // update group counter
  17275. groupCount += 6;
  17276. }
  17277. } // add a group to the geometry. this will ensure multi material support
  17278. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17279. groupStart += groupCount;
  17280. }
  17281. function generateCap(top) {
  17282. // save the index of the first center vertex
  17283. var centerIndexStart = index;
  17284. var uv = new Vector2();
  17285. var vertex = new Vector3();
  17286. var groupCount = 0;
  17287. var radius = top === true ? radiusTop : radiusBottom;
  17288. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17289. // because the geometry needs one set of uvs per face,
  17290. // we must generate a center vertex per face/segment
  17291. for (var x = 1; x <= radialSegments; x++) {
  17292. // vertex
  17293. vertices.push(0, halfHeight * sign, 0); // normal
  17294. normals.push(0, sign, 0); // uv
  17295. uvs.push(0.5, 0.5); // increase index
  17296. index++;
  17297. } // save the index of the last center vertex
  17298. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17299. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17300. var u = _x2 / radialSegments;
  17301. var theta = u * thetaLength + thetaStart;
  17302. var cosTheta = Math.cos(theta);
  17303. var sinTheta = Math.sin(theta); // vertex
  17304. vertex.x = radius * sinTheta;
  17305. vertex.y = halfHeight * sign;
  17306. vertex.z = radius * cosTheta;
  17307. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17308. normals.push(0, sign, 0); // uv
  17309. uv.x = cosTheta * 0.5 + 0.5;
  17310. uv.y = sinTheta * 0.5 * sign + 0.5;
  17311. uvs.push(uv.x, uv.y); // increase index
  17312. index++;
  17313. } // generate indices
  17314. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17315. var c = centerIndexStart + _x3;
  17316. var i = centerIndexEnd + _x3;
  17317. if (top === true) {
  17318. // face top
  17319. indices.push(i, i + 1, c);
  17320. } else {
  17321. // face bottom
  17322. indices.push(i + 1, i, c);
  17323. }
  17324. groupCount += 3;
  17325. } // add a group to the geometry. this will ensure multi material support
  17326. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17327. groupStart += groupCount;
  17328. }
  17329. return _this;
  17330. }
  17331. return CylinderBufferGeometry;
  17332. }(BufferGeometry);
  17333. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17334. _inheritsLoose(CylinderGeometry, _Geometry);
  17335. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17336. var _this;
  17337. _this = _Geometry.call(this) || this;
  17338. _this.type = 'CylinderGeometry';
  17339. _this.parameters = {
  17340. radiusTop: radiusTop,
  17341. radiusBottom: radiusBottom,
  17342. height: height,
  17343. radialSegments: radialSegments,
  17344. heightSegments: heightSegments,
  17345. openEnded: openEnded,
  17346. thetaStart: thetaStart,
  17347. thetaLength: thetaLength
  17348. };
  17349. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17350. _this.mergeVertices();
  17351. return _this;
  17352. }
  17353. return CylinderGeometry;
  17354. }(Geometry);
  17355. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17356. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17357. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17358. var _this;
  17359. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17360. _this.type = 'ConeGeometry';
  17361. _this.parameters = {
  17362. radius: radius,
  17363. height: height,
  17364. radialSegments: radialSegments,
  17365. heightSegments: heightSegments,
  17366. openEnded: openEnded,
  17367. thetaStart: thetaStart,
  17368. thetaLength: thetaLength
  17369. };
  17370. return _this;
  17371. }
  17372. return ConeGeometry;
  17373. }(CylinderGeometry);
  17374. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17375. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17376. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17377. var _this;
  17378. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17379. _this.type = 'ConeBufferGeometry';
  17380. _this.parameters = {
  17381. radius: radius,
  17382. height: height,
  17383. radialSegments: radialSegments,
  17384. heightSegments: heightSegments,
  17385. openEnded: openEnded,
  17386. thetaStart: thetaStart,
  17387. thetaLength: thetaLength
  17388. };
  17389. return _this;
  17390. }
  17391. return ConeBufferGeometry;
  17392. }(CylinderBufferGeometry);
  17393. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17394. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17395. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17396. var _this;
  17397. _this = _BufferGeometry.call(this) || this;
  17398. _this.type = 'PolyhedronBufferGeometry';
  17399. _this.parameters = {
  17400. vertices: vertices,
  17401. indices: indices,
  17402. radius: radius,
  17403. detail: detail
  17404. };
  17405. radius = radius || 1;
  17406. detail = detail || 0; // default buffer data
  17407. var vertexBuffer = [];
  17408. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17409. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17410. applyRadius(radius); // finally, create the uv data
  17411. generateUVs(); // build non-indexed geometry
  17412. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17413. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17414. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17415. if (detail === 0) {
  17416. _this.computeVertexNormals(); // flat normals
  17417. } else {
  17418. _this.normalizeNormals(); // smooth normals
  17419. } // helper functions
  17420. function subdivide(detail) {
  17421. var a = new Vector3();
  17422. var b = new Vector3();
  17423. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17424. for (var i = 0; i < indices.length; i += 3) {
  17425. // get the vertices of the face
  17426. getVertexByIndex(indices[i + 0], a);
  17427. getVertexByIndex(indices[i + 1], b);
  17428. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17429. subdivideFace(a, b, c, detail);
  17430. }
  17431. }
  17432. function subdivideFace(a, b, c, detail) {
  17433. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17434. var v = []; // construct all of the vertices for this subdivision
  17435. for (var i = 0; i <= cols; i++) {
  17436. v[i] = [];
  17437. var aj = a.clone().lerp(c, i / cols);
  17438. var bj = b.clone().lerp(c, i / cols);
  17439. var rows = cols - i;
  17440. for (var j = 0; j <= rows; j++) {
  17441. if (j === 0 && i === cols) {
  17442. v[i][j] = aj;
  17443. } else {
  17444. v[i][j] = aj.clone().lerp(bj, j / rows);
  17445. }
  17446. }
  17447. } // construct all of the faces
  17448. for (var _i = 0; _i < cols; _i++) {
  17449. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17450. var k = Math.floor(_j / 2);
  17451. if (_j % 2 === 0) {
  17452. pushVertex(v[_i][k + 1]);
  17453. pushVertex(v[_i + 1][k]);
  17454. pushVertex(v[_i][k]);
  17455. } else {
  17456. pushVertex(v[_i][k + 1]);
  17457. pushVertex(v[_i + 1][k + 1]);
  17458. pushVertex(v[_i + 1][k]);
  17459. }
  17460. }
  17461. }
  17462. }
  17463. function applyRadius(radius) {
  17464. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17465. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17466. vertex.x = vertexBuffer[i + 0];
  17467. vertex.y = vertexBuffer[i + 1];
  17468. vertex.z = vertexBuffer[i + 2];
  17469. vertex.normalize().multiplyScalar(radius);
  17470. vertexBuffer[i + 0] = vertex.x;
  17471. vertexBuffer[i + 1] = vertex.y;
  17472. vertexBuffer[i + 2] = vertex.z;
  17473. }
  17474. }
  17475. function generateUVs() {
  17476. var vertex = new Vector3();
  17477. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17478. vertex.x = vertexBuffer[i + 0];
  17479. vertex.y = vertexBuffer[i + 1];
  17480. vertex.z = vertexBuffer[i + 2];
  17481. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17482. var v = inclination(vertex) / Math.PI + 0.5;
  17483. uvBuffer.push(u, 1 - v);
  17484. }
  17485. correctUVs();
  17486. correctSeam();
  17487. }
  17488. function correctSeam() {
  17489. // handle case when face straddles the seam, see #3269
  17490. for (var i = 0; i < uvBuffer.length; i += 6) {
  17491. // uv data of a single face
  17492. var x0 = uvBuffer[i + 0];
  17493. var x1 = uvBuffer[i + 2];
  17494. var x2 = uvBuffer[i + 4];
  17495. var max = Math.max(x0, x1, x2);
  17496. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17497. if (max > 0.9 && min < 0.1) {
  17498. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17499. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17500. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17501. }
  17502. }
  17503. }
  17504. function pushVertex(vertex) {
  17505. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17506. }
  17507. function getVertexByIndex(index, vertex) {
  17508. var stride = index * 3;
  17509. vertex.x = vertices[stride + 0];
  17510. vertex.y = vertices[stride + 1];
  17511. vertex.z = vertices[stride + 2];
  17512. }
  17513. function correctUVs() {
  17514. var a = new Vector3();
  17515. var b = new Vector3();
  17516. var c = new Vector3();
  17517. var centroid = new Vector3();
  17518. var uvA = new Vector2();
  17519. var uvB = new Vector2();
  17520. var uvC = new Vector2();
  17521. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17522. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17523. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17524. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17525. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17526. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17527. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17528. centroid.copy(a).add(b).add(c).divideScalar(3);
  17529. var azi = azimuth(centroid);
  17530. correctUV(uvA, j + 0, a, azi);
  17531. correctUV(uvB, j + 2, b, azi);
  17532. correctUV(uvC, j + 4, c, azi);
  17533. }
  17534. }
  17535. function correctUV(uv, stride, vector, azimuth) {
  17536. if (azimuth < 0 && uv.x === 1) {
  17537. uvBuffer[stride] = uv.x - 1;
  17538. }
  17539. if (vector.x === 0 && vector.z === 0) {
  17540. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17541. }
  17542. } // Angle around the Y axis, counter-clockwise when looking from above.
  17543. function azimuth(vector) {
  17544. return Math.atan2(vector.z, -vector.x);
  17545. } // Angle above the XZ plane.
  17546. function inclination(vector) {
  17547. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17548. }
  17549. return _this;
  17550. }
  17551. return PolyhedronBufferGeometry;
  17552. }(BufferGeometry);
  17553. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17554. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17555. function DodecahedronBufferGeometry(radius, detail) {
  17556. var _this;
  17557. var t = (1 + Math.sqrt(5)) / 2;
  17558. var r = 1 / t;
  17559. var vertices = [// (±1, ±1, ±1)
  17560. -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/φ, ±φ)
  17561. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17562. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17563. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17564. 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];
  17565. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17566. _this.type = 'DodecahedronBufferGeometry';
  17567. _this.parameters = {
  17568. radius: radius,
  17569. detail: detail
  17570. };
  17571. return _this;
  17572. }
  17573. return DodecahedronBufferGeometry;
  17574. }(PolyhedronBufferGeometry);
  17575. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17576. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17577. function DodecahedronGeometry(radius, detail) {
  17578. var _this;
  17579. _this = _Geometry.call(this) || this;
  17580. _this.type = 'DodecahedronGeometry';
  17581. _this.parameters = {
  17582. radius: radius,
  17583. detail: detail
  17584. };
  17585. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17586. _this.mergeVertices();
  17587. return _this;
  17588. }
  17589. return DodecahedronGeometry;
  17590. }(Geometry);
  17591. var _v0$2 = new Vector3();
  17592. var _v1$5 = new Vector3();
  17593. var _normal$1 = new Vector3();
  17594. var _triangle = new Triangle();
  17595. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17596. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17597. function EdgesGeometry(geometry, thresholdAngle) {
  17598. var _this;
  17599. _this = _BufferGeometry.call(this) || this;
  17600. _this.type = 'EdgesGeometry';
  17601. _this.parameters = {
  17602. thresholdAngle: thresholdAngle
  17603. };
  17604. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17605. if (geometry.isGeometry) {
  17606. geometry = new BufferGeometry().fromGeometry(geometry);
  17607. }
  17608. var precisionPoints = 4;
  17609. var precision = Math.pow(10, precisionPoints);
  17610. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17611. var indexAttr = geometry.getIndex();
  17612. var positionAttr = geometry.getAttribute('position');
  17613. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17614. var indexArr = [0, 0, 0];
  17615. var vertKeys = ['a', 'b', 'c'];
  17616. var hashes = new Array(3);
  17617. var edgeData = {};
  17618. var vertices = [];
  17619. for (var i = 0; i < indexCount; i += 3) {
  17620. if (indexAttr) {
  17621. indexArr[0] = indexAttr.getX(i);
  17622. indexArr[1] = indexAttr.getX(i + 1);
  17623. indexArr[2] = indexAttr.getX(i + 2);
  17624. } else {
  17625. indexArr[0] = i;
  17626. indexArr[1] = i + 1;
  17627. indexArr[2] = i + 2;
  17628. }
  17629. var a = _triangle.a,
  17630. b = _triangle.b,
  17631. c = _triangle.c;
  17632. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17633. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17634. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17635. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17636. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17637. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17638. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17639. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17640. continue;
  17641. } // iterate over every edge
  17642. for (var j = 0; j < 3; j++) {
  17643. // get the first and next vertex making up the edge
  17644. var jNext = (j + 1) % 3;
  17645. var vecHash0 = hashes[j];
  17646. var vecHash1 = hashes[jNext];
  17647. var v0 = _triangle[vertKeys[j]];
  17648. var v1 = _triangle[vertKeys[jNext]];
  17649. var hash = vecHash0 + "_" + vecHash1;
  17650. var reverseHash = vecHash1 + "_" + vecHash0;
  17651. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17652. // if we found a sibling edge add it into the vertex array if
  17653. // it meets the angle threshold and delete the edge from the map.
  17654. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17655. vertices.push(v0.x, v0.y, v0.z);
  17656. vertices.push(v1.x, v1.y, v1.z);
  17657. }
  17658. edgeData[reverseHash] = null;
  17659. } else if (!(hash in edgeData)) {
  17660. // if we've already got an edge here then skip adding a new one
  17661. edgeData[hash] = {
  17662. index0: indexArr[j],
  17663. index1: indexArr[jNext],
  17664. normal: _normal$1.clone()
  17665. };
  17666. }
  17667. }
  17668. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17669. for (var key in edgeData) {
  17670. if (edgeData[key]) {
  17671. var _edgeData$key = edgeData[key],
  17672. index0 = _edgeData$key.index0,
  17673. index1 = _edgeData$key.index1;
  17674. _v0$2.fromBufferAttribute(positionAttr, index0);
  17675. _v1$5.fromBufferAttribute(positionAttr, index1);
  17676. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17677. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17678. }
  17679. }
  17680. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17681. return _this;
  17682. }
  17683. return EdgesGeometry;
  17684. }(BufferGeometry);
  17685. /**
  17686. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17687. */
  17688. var Earcut = {
  17689. triangulate: function triangulate(data, holeIndices, dim) {
  17690. dim = dim || 2;
  17691. var hasHoles = holeIndices && holeIndices.length;
  17692. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17693. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17694. var triangles = [];
  17695. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17696. var minX, minY, maxX, maxY, x, y, invSize;
  17697. 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
  17698. if (data.length > 80 * dim) {
  17699. minX = maxX = data[0];
  17700. minY = maxY = data[1];
  17701. for (var i = dim; i < outerLen; i += dim) {
  17702. x = data[i];
  17703. y = data[i + 1];
  17704. if (x < minX) minX = x;
  17705. if (y < minY) minY = y;
  17706. if (x > maxX) maxX = x;
  17707. if (y > maxY) maxY = y;
  17708. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17709. invSize = Math.max(maxX - minX, maxY - minY);
  17710. invSize = invSize !== 0 ? 1 / invSize : 0;
  17711. }
  17712. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17713. return triangles;
  17714. }
  17715. }; // create a circular doubly linked list from polygon points in the specified winding order
  17716. function linkedList(data, start, end, dim, clockwise) {
  17717. var i, last;
  17718. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17719. for (i = start; i < end; i += dim) {
  17720. last = insertNode(i, data[i], data[i + 1], last);
  17721. }
  17722. } else {
  17723. for (i = end - dim; i >= start; i -= dim) {
  17724. last = insertNode(i, data[i], data[i + 1], last);
  17725. }
  17726. }
  17727. if (last && equals(last, last.next)) {
  17728. removeNode(last);
  17729. last = last.next;
  17730. }
  17731. return last;
  17732. } // eliminate colinear or duplicate points
  17733. function filterPoints(start, end) {
  17734. if (!start) return start;
  17735. if (!end) end = start;
  17736. var p = start,
  17737. again;
  17738. do {
  17739. again = false;
  17740. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17741. removeNode(p);
  17742. p = end = p.prev;
  17743. if (p === p.next) break;
  17744. again = true;
  17745. } else {
  17746. p = p.next;
  17747. }
  17748. } while (again || p !== end);
  17749. return end;
  17750. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17751. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17752. if (!ear) return; // interlink polygon nodes in z-order
  17753. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17754. var stop = ear,
  17755. prev,
  17756. next; // iterate through ears, slicing them one by one
  17757. while (ear.prev !== ear.next) {
  17758. prev = ear.prev;
  17759. next = ear.next;
  17760. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17761. // cut off the triangle
  17762. triangles.push(prev.i / dim);
  17763. triangles.push(ear.i / dim);
  17764. triangles.push(next.i / dim);
  17765. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17766. ear = next.next;
  17767. stop = next.next;
  17768. continue;
  17769. }
  17770. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17771. if (ear === stop) {
  17772. // try filtering points and slicing again
  17773. if (!pass) {
  17774. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17775. } else if (pass === 1) {
  17776. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17777. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17778. } else if (pass === 2) {
  17779. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17780. }
  17781. break;
  17782. }
  17783. }
  17784. } // check whether a polygon node forms a valid ear with adjacent nodes
  17785. function isEar(ear) {
  17786. var a = ear.prev,
  17787. b = ear,
  17788. c = ear.next;
  17789. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17790. // now make sure we don't have other points inside the potential ear
  17791. var p = ear.next.next;
  17792. while (p !== ear.prev) {
  17793. 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;
  17794. p = p.next;
  17795. }
  17796. return true;
  17797. }
  17798. function isEarHashed(ear, minX, minY, invSize) {
  17799. var a = ear.prev,
  17800. b = ear,
  17801. c = ear.next;
  17802. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17803. // triangle bbox; min & max are calculated like this for speed
  17804. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17805. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17806. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17807. 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;
  17808. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17809. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17810. var p = ear.prevZ,
  17811. n = ear.nextZ; // look for points inside the triangle in both directions
  17812. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17813. if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
  17814. p = p.prevZ;
  17815. 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;
  17816. n = n.nextZ;
  17817. } // look for remaining points in decreasing z-order
  17818. while (p && p.z >= minZ) {
  17819. 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;
  17820. p = p.prevZ;
  17821. } // look for remaining points in increasing z-order
  17822. while (n && n.z <= maxZ) {
  17823. 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;
  17824. n = n.nextZ;
  17825. }
  17826. return true;
  17827. } // go through all polygon nodes and cure small local self-intersections
  17828. function cureLocalIntersections(start, triangles, dim) {
  17829. var p = start;
  17830. do {
  17831. var a = p.prev,
  17832. b = p.next.next;
  17833. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17834. triangles.push(a.i / dim);
  17835. triangles.push(p.i / dim);
  17836. triangles.push(b.i / dim); // remove two nodes involved
  17837. removeNode(p);
  17838. removeNode(p.next);
  17839. p = start = b;
  17840. }
  17841. p = p.next;
  17842. } while (p !== start);
  17843. return filterPoints(p);
  17844. } // try splitting polygon into two and triangulate them independently
  17845. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17846. // look for a valid diagonal that divides the polygon into two
  17847. var a = start;
  17848. do {
  17849. var b = a.next.next;
  17850. while (b !== a.prev) {
  17851. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17852. // split the polygon in two by the diagonal
  17853. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17854. a = filterPoints(a, a.next);
  17855. c = filterPoints(c, c.next); // run earcut on each half
  17856. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17857. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17858. return;
  17859. }
  17860. b = b.next;
  17861. }
  17862. a = a.next;
  17863. } while (a !== start);
  17864. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17865. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17866. var queue = [];
  17867. var i, len, start, end, list;
  17868. for (i = 0, len = holeIndices.length; i < len; i++) {
  17869. start = holeIndices[i] * dim;
  17870. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17871. list = linkedList(data, start, end, dim, false);
  17872. if (list === list.next) list.steiner = true;
  17873. queue.push(getLeftmost(list));
  17874. }
  17875. queue.sort(compareX); // process holes from left to right
  17876. for (i = 0; i < queue.length; i++) {
  17877. eliminateHole(queue[i], outerNode);
  17878. outerNode = filterPoints(outerNode, outerNode.next);
  17879. }
  17880. return outerNode;
  17881. }
  17882. function compareX(a, b) {
  17883. return a.x - b.x;
  17884. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17885. function eliminateHole(hole, outerNode) {
  17886. outerNode = findHoleBridge(hole, outerNode);
  17887. if (outerNode) {
  17888. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17889. filterPoints(outerNode, outerNode.next);
  17890. filterPoints(b, b.next);
  17891. }
  17892. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17893. function findHoleBridge(hole, outerNode) {
  17894. var p = outerNode;
  17895. var hx = hole.x;
  17896. var hy = hole.y;
  17897. var qx = -Infinity,
  17898. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17899. // segment's endpoint with lesser x will be potential connection point
  17900. do {
  17901. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17902. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17903. if (x <= hx && x > qx) {
  17904. qx = x;
  17905. if (x === hx) {
  17906. if (hy === p.y) return p;
  17907. if (hy === p.next.y) return p.next;
  17908. }
  17909. m = p.x < p.next.x ? p : p.next;
  17910. }
  17911. }
  17912. p = p.next;
  17913. } while (p !== outerNode);
  17914. if (!m) return null;
  17915. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17916. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17917. // if there are no points found, we have a valid connection;
  17918. // otherwise choose the point of the minimum angle with the ray as connection point
  17919. var stop = m,
  17920. mx = m.x,
  17921. my = m.y;
  17922. var tanMin = Infinity,
  17923. tan;
  17924. p = m;
  17925. do {
  17926. 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)) {
  17927. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17928. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17929. m = p;
  17930. tanMin = tan;
  17931. }
  17932. }
  17933. p = p.next;
  17934. } while (p !== stop);
  17935. return m;
  17936. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  17937. function sectorContainsSector(m, p) {
  17938. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  17939. } // interlink polygon nodes in z-order
  17940. function indexCurve(start, minX, minY, invSize) {
  17941. var p = start;
  17942. do {
  17943. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  17944. p.prevZ = p.prev;
  17945. p.nextZ = p.next;
  17946. p = p.next;
  17947. } while (p !== start);
  17948. p.prevZ.nextZ = null;
  17949. p.prevZ = null;
  17950. sortLinked(p);
  17951. } // Simon Tatham's linked list merge sort algorithm
  17952. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17953. function sortLinked(list) {
  17954. var i,
  17955. p,
  17956. q,
  17957. e,
  17958. tail,
  17959. numMerges,
  17960. pSize,
  17961. qSize,
  17962. inSize = 1;
  17963. do {
  17964. p = list;
  17965. list = null;
  17966. tail = null;
  17967. numMerges = 0;
  17968. while (p) {
  17969. numMerges++;
  17970. q = p;
  17971. pSize = 0;
  17972. for (i = 0; i < inSize; i++) {
  17973. pSize++;
  17974. q = q.nextZ;
  17975. if (!q) break;
  17976. }
  17977. qSize = inSize;
  17978. while (pSize > 0 || qSize > 0 && q) {
  17979. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  17980. e = p;
  17981. p = p.nextZ;
  17982. pSize--;
  17983. } else {
  17984. e = q;
  17985. q = q.nextZ;
  17986. qSize--;
  17987. }
  17988. if (tail) tail.nextZ = e;else list = e;
  17989. e.prevZ = tail;
  17990. tail = e;
  17991. }
  17992. p = q;
  17993. }
  17994. tail.nextZ = null;
  17995. inSize *= 2;
  17996. } while (numMerges > 1);
  17997. return list;
  17998. } // z-order of a point given coords and inverse of the longer side of data bbox
  17999. function zOrder(x, y, minX, minY, invSize) {
  18000. // coords are transformed into non-negative 15-bit integer range
  18001. x = 32767 * (x - minX) * invSize;
  18002. y = 32767 * (y - minY) * invSize;
  18003. x = (x | x << 8) & 0x00FF00FF;
  18004. x = (x | x << 4) & 0x0F0F0F0F;
  18005. x = (x | x << 2) & 0x33333333;
  18006. x = (x | x << 1) & 0x55555555;
  18007. y = (y | y << 8) & 0x00FF00FF;
  18008. y = (y | y << 4) & 0x0F0F0F0F;
  18009. y = (y | y << 2) & 0x33333333;
  18010. y = (y | y << 1) & 0x55555555;
  18011. return x | y << 1;
  18012. } // find the leftmost node of a polygon ring
  18013. function getLeftmost(start) {
  18014. var p = start,
  18015. leftmost = start;
  18016. do {
  18017. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18018. p = p.next;
  18019. } while (p !== start);
  18020. return leftmost;
  18021. } // check if a point lies within a convex triangle
  18022. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18023. 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;
  18024. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18025. function isValidDiagonal(a, b) {
  18026. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18027. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18028. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18029. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18030. } // signed area of a triangle
  18031. function area(p, q, r) {
  18032. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18033. } // check if two points are equal
  18034. function equals(p1, p2) {
  18035. return p1.x === p2.x && p1.y === p2.y;
  18036. } // check if two segments intersect
  18037. function intersects(p1, q1, p2, q2) {
  18038. var o1 = sign(area(p1, q1, p2));
  18039. var o2 = sign(area(p1, q1, q2));
  18040. var o3 = sign(area(p2, q2, p1));
  18041. var o4 = sign(area(p2, q2, q1));
  18042. if (o1 !== o2 && o3 !== o4) return true; // general case
  18043. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18044. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18045. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18046. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18047. return false;
  18048. } // for collinear points p, q, r, check if point q lies on segment pr
  18049. function onSegment(p, q, r) {
  18050. 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);
  18051. }
  18052. function sign(num) {
  18053. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18054. } // check if a polygon diagonal intersects any polygon segments
  18055. function intersectsPolygon(a, b) {
  18056. var p = a;
  18057. do {
  18058. 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;
  18059. p = p.next;
  18060. } while (p !== a);
  18061. return false;
  18062. } // check if a polygon diagonal is locally inside the polygon
  18063. function locallyInside(a, b) {
  18064. 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;
  18065. } // check if the middle point of a polygon diagonal is inside the polygon
  18066. function middleInside(a, b) {
  18067. var p = a,
  18068. inside = false;
  18069. var px = (a.x + b.x) / 2,
  18070. py = (a.y + b.y) / 2;
  18071. do {
  18072. 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;
  18073. p = p.next;
  18074. } while (p !== a);
  18075. return inside;
  18076. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18077. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18078. function splitPolygon(a, b) {
  18079. var a2 = new Node(a.i, a.x, a.y),
  18080. b2 = new Node(b.i, b.x, b.y),
  18081. an = a.next,
  18082. bp = b.prev;
  18083. a.next = b;
  18084. b.prev = a;
  18085. a2.next = an;
  18086. an.prev = a2;
  18087. b2.next = a2;
  18088. a2.prev = b2;
  18089. bp.next = b2;
  18090. b2.prev = bp;
  18091. return b2;
  18092. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18093. function insertNode(i, x, y, last) {
  18094. var p = new Node(i, x, y);
  18095. if (!last) {
  18096. p.prev = p;
  18097. p.next = p;
  18098. } else {
  18099. p.next = last.next;
  18100. p.prev = last;
  18101. last.next.prev = p;
  18102. last.next = p;
  18103. }
  18104. return p;
  18105. }
  18106. function removeNode(p) {
  18107. p.next.prev = p.prev;
  18108. p.prev.next = p.next;
  18109. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18110. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18111. }
  18112. function Node(i, x, y) {
  18113. // vertex index in coordinates array
  18114. this.i = i; // vertex coordinates
  18115. this.x = x;
  18116. this.y = y; // previous and next vertex nodes in a polygon ring
  18117. this.prev = null;
  18118. this.next = null; // z-order curve value
  18119. this.z = null; // previous and next nodes in z-order
  18120. this.prevZ = null;
  18121. this.nextZ = null; // indicates whether this is a steiner point
  18122. this.steiner = false;
  18123. }
  18124. function signedArea(data, start, end, dim) {
  18125. var sum = 0;
  18126. for (var i = start, j = end - dim; i < end; i += dim) {
  18127. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18128. j = i;
  18129. }
  18130. return sum;
  18131. }
  18132. var ShapeUtils = {
  18133. // calculate area of the contour polygon
  18134. area: function area(contour) {
  18135. var n = contour.length;
  18136. var a = 0.0;
  18137. for (var p = n - 1, q = 0; q < n; p = q++) {
  18138. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18139. }
  18140. return a * 0.5;
  18141. },
  18142. isClockWise: function isClockWise(pts) {
  18143. return ShapeUtils.area(pts) < 0;
  18144. },
  18145. triangulateShape: function triangulateShape(contour, holes) {
  18146. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18147. var holeIndices = []; // array of hole indices
  18148. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18149. removeDupEndPts(contour);
  18150. addContour(vertices, contour); //
  18151. var holeIndex = contour.length;
  18152. holes.forEach(removeDupEndPts);
  18153. for (var i = 0; i < holes.length; i++) {
  18154. holeIndices.push(holeIndex);
  18155. holeIndex += holes[i].length;
  18156. addContour(vertices, holes[i]);
  18157. } //
  18158. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18159. for (var _i = 0; _i < triangles.length; _i += 3) {
  18160. faces.push(triangles.slice(_i, _i + 3));
  18161. }
  18162. return faces;
  18163. }
  18164. };
  18165. function removeDupEndPts(points) {
  18166. var l = points.length;
  18167. if (l > 2 && points[l - 1].equals(points[0])) {
  18168. points.pop();
  18169. }
  18170. }
  18171. function addContour(vertices, contour) {
  18172. for (var i = 0; i < contour.length; i++) {
  18173. vertices.push(contour[i].x);
  18174. vertices.push(contour[i].y);
  18175. }
  18176. }
  18177. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18178. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18179. function ExtrudeBufferGeometry(shapes, options) {
  18180. var _this;
  18181. _this = _BufferGeometry.call(this) || this;
  18182. _this.type = 'ExtrudeBufferGeometry';
  18183. _this.parameters = {
  18184. shapes: shapes,
  18185. options: options
  18186. };
  18187. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18188. var scope = _assertThisInitialized(_this);
  18189. var verticesArray = [];
  18190. var uvArray = [];
  18191. for (var i = 0, l = shapes.length; i < l; i++) {
  18192. var shape = shapes[i];
  18193. addShape(shape);
  18194. } // build geometry
  18195. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18196. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18197. _this.computeVertexNormals(); // functions
  18198. function addShape(shape) {
  18199. var placeholder = []; // options
  18200. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18201. var steps = options.steps !== undefined ? options.steps : 1;
  18202. var depth = options.depth !== undefined ? options.depth : 100;
  18203. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18204. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18205. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18206. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18207. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18208. var extrudePath = options.extrudePath;
  18209. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18210. if (options.amount !== undefined) {
  18211. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18212. depth = options.amount;
  18213. } //
  18214. var extrudePts,
  18215. extrudeByPath = false;
  18216. var splineTube, binormal, normal, position2;
  18217. if (extrudePath) {
  18218. extrudePts = extrudePath.getSpacedPoints(steps);
  18219. extrudeByPath = true;
  18220. bevelEnabled = false; // bevels not supported for path extrusion
  18221. // SETUP TNB variables
  18222. // TODO1 - have a .isClosed in spline?
  18223. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18224. binormal = new Vector3();
  18225. normal = new Vector3();
  18226. position2 = new Vector3();
  18227. } // Safeguards if bevels are not enabled
  18228. if (!bevelEnabled) {
  18229. bevelSegments = 0;
  18230. bevelThickness = 0;
  18231. bevelSize = 0;
  18232. bevelOffset = 0;
  18233. } // Variables initialization
  18234. var shapePoints = shape.extractPoints(curveSegments);
  18235. var vertices = shapePoints.shape;
  18236. var holes = shapePoints.holes;
  18237. var reverse = !ShapeUtils.isClockWise(vertices);
  18238. if (reverse) {
  18239. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18240. for (var h = 0, hl = holes.length; h < hl; h++) {
  18241. var ahole = holes[h];
  18242. if (ShapeUtils.isClockWise(ahole)) {
  18243. holes[h] = ahole.reverse();
  18244. }
  18245. }
  18246. }
  18247. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18248. /* Vertices */
  18249. var contour = vertices; // vertices has all points but contour has only points of circumference
  18250. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18251. var _ahole = holes[_h];
  18252. vertices = vertices.concat(_ahole);
  18253. }
  18254. function scalePt2(pt, vec, size) {
  18255. if (!vec) console.error("THREE.ExtrudeGeometry: vec does not exist");
  18256. return vec.clone().multiplyScalar(size).add(pt);
  18257. }
  18258. var vlen = vertices.length,
  18259. flen = faces.length; // Find directions for point movement
  18260. function getBevelVec(inPt, inPrev, inNext) {
  18261. // computes for inPt the corresponding point inPt' on a new contour
  18262. // shifted by 1 unit (length of normalized vector) to the left
  18263. // if we walk along contour clockwise, this new contour is outside the old one
  18264. //
  18265. // inPt' is the intersection of the two lines parallel to the two
  18266. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18267. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18268. // good reading for geometry algorithms (here: line-line intersection)
  18269. // http://geomalgorithms.com/a05-_intersect-1.html
  18270. var v_prev_x = inPt.x - inPrev.x,
  18271. v_prev_y = inPt.y - inPrev.y;
  18272. var v_next_x = inNext.x - inPt.x,
  18273. v_next_y = inNext.y - inPt.y;
  18274. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18275. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18276. if (Math.abs(collinear0) > Number.EPSILON) {
  18277. // not collinear
  18278. // length of vectors for normalizing
  18279. var v_prev_len = Math.sqrt(v_prev_lensq);
  18280. 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
  18281. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18282. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18283. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18284. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18285. 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
  18286. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18287. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18288. // but prevent crazy spikes
  18289. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18290. if (v_trans_lensq <= 2) {
  18291. return new Vector2(v_trans_x, v_trans_y);
  18292. } else {
  18293. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18294. }
  18295. } else {
  18296. // handle special case of collinear edges
  18297. var direction_eq = false; // assumes: opposite
  18298. if (v_prev_x > Number.EPSILON) {
  18299. if (v_next_x > Number.EPSILON) {
  18300. direction_eq = true;
  18301. }
  18302. } else {
  18303. if (v_prev_x < -Number.EPSILON) {
  18304. if (v_next_x < -Number.EPSILON) {
  18305. direction_eq = true;
  18306. }
  18307. } else {
  18308. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18309. direction_eq = true;
  18310. }
  18311. }
  18312. }
  18313. if (direction_eq) {
  18314. // console.log("Warning: lines are a straight sequence");
  18315. v_trans_x = -v_prev_y;
  18316. v_trans_y = v_prev_x;
  18317. shrink_by = Math.sqrt(v_prev_lensq);
  18318. } else {
  18319. // console.log("Warning: lines are a straight spike");
  18320. v_trans_x = v_prev_x;
  18321. v_trans_y = v_prev_y;
  18322. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18323. }
  18324. }
  18325. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18326. }
  18327. var contourMovements = [];
  18328. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18329. if (j === il) j = 0;
  18330. if (k === il) k = 0; // (j)---(i)---(k)
  18331. // console.log('i,j,k', i, j , k)
  18332. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18333. }
  18334. var holesMovements = [];
  18335. var oneHoleMovements,
  18336. verticesMovements = contourMovements.concat();
  18337. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18338. var _ahole2 = holes[_h2];
  18339. oneHoleMovements = [];
  18340. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18341. if (_j === _il) _j = 0;
  18342. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18343. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18344. }
  18345. holesMovements.push(oneHoleMovements);
  18346. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18347. } // Loop bevelSegments, 1 for the front, 1 for the back
  18348. for (var b = 0; b < bevelSegments; b++) {
  18349. //for ( b = bevelSegments; b > 0; b -- ) {
  18350. var t = b / bevelSegments;
  18351. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18352. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18353. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18354. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18355. v(vert.x, vert.y, -z);
  18356. } // expand holes
  18357. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18358. var _ahole3 = holes[_h3];
  18359. oneHoleMovements = holesMovements[_h3];
  18360. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18361. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18362. v(_vert.x, _vert.y, -z);
  18363. }
  18364. }
  18365. }
  18366. var bs = bevelSize + bevelOffset; // Back facing vertices
  18367. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18368. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18369. if (!extrudeByPath) {
  18370. v(_vert2.x, _vert2.y, 0);
  18371. } else {
  18372. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18373. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18374. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18375. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18376. v(position2.x, position2.y, position2.z);
  18377. }
  18378. } // Add stepped vertices...
  18379. // Including front facing vertices
  18380. for (var s = 1; s <= steps; s++) {
  18381. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18382. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18383. if (!extrudeByPath) {
  18384. v(_vert3.x, _vert3.y, depth / steps * s);
  18385. } else {
  18386. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18387. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18388. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18389. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18390. v(position2.x, position2.y, position2.z);
  18391. }
  18392. }
  18393. } // Add bevel segments planes
  18394. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18395. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18396. var _t = _b / bevelSegments;
  18397. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18398. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18399. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18400. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18401. v(_vert4.x, _vert4.y, depth + _z);
  18402. } // expand holes
  18403. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18404. var _ahole4 = holes[_h4];
  18405. oneHoleMovements = holesMovements[_h4];
  18406. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18407. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18408. if (!extrudeByPath) {
  18409. v(_vert5.x, _vert5.y, depth + _z);
  18410. } else {
  18411. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18412. }
  18413. }
  18414. }
  18415. }
  18416. /* Faces */
  18417. // Top and bottom faces
  18418. buildLidFaces(); // Sides faces
  18419. buildSideFaces(); ///// Internal functions
  18420. function buildLidFaces() {
  18421. var start = verticesArray.length / 3;
  18422. if (bevelEnabled) {
  18423. var layer = 0; // steps + 1
  18424. var offset = vlen * layer; // Bottom faces
  18425. for (var _i9 = 0; _i9 < flen; _i9++) {
  18426. var face = faces[_i9];
  18427. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18428. }
  18429. layer = steps + bevelSegments * 2;
  18430. offset = vlen * layer; // Top faces
  18431. for (var _i10 = 0; _i10 < flen; _i10++) {
  18432. var _face = faces[_i10];
  18433. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18434. }
  18435. } else {
  18436. // Bottom faces
  18437. for (var _i11 = 0; _i11 < flen; _i11++) {
  18438. var _face2 = faces[_i11];
  18439. f3(_face2[2], _face2[1], _face2[0]);
  18440. } // Top faces
  18441. for (var _i12 = 0; _i12 < flen; _i12++) {
  18442. var _face3 = faces[_i12];
  18443. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18444. }
  18445. }
  18446. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18447. } // Create faces for the z-sides of the shape
  18448. function buildSideFaces() {
  18449. var start = verticesArray.length / 3;
  18450. var layeroffset = 0;
  18451. sidewalls(contour, layeroffset);
  18452. layeroffset += contour.length;
  18453. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18454. var _ahole5 = holes[_h5];
  18455. sidewalls(_ahole5, layeroffset); //, true
  18456. layeroffset += _ahole5.length;
  18457. }
  18458. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18459. }
  18460. function sidewalls(contour, layeroffset) {
  18461. var i = contour.length;
  18462. while (--i >= 0) {
  18463. var _j2 = i;
  18464. var _k2 = i - 1;
  18465. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18466. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18467. var slen1 = vlen * _s;
  18468. var slen2 = vlen * (_s + 1);
  18469. var a = layeroffset + _j2 + slen1,
  18470. _b2 = layeroffset + _k2 + slen1,
  18471. c = layeroffset + _k2 + slen2,
  18472. d = layeroffset + _j2 + slen2;
  18473. f4(a, _b2, c, d);
  18474. }
  18475. }
  18476. }
  18477. function v(x, y, z) {
  18478. placeholder.push(x);
  18479. placeholder.push(y);
  18480. placeholder.push(z);
  18481. }
  18482. function f3(a, b, c) {
  18483. addVertex(a);
  18484. addVertex(b);
  18485. addVertex(c);
  18486. var nextIndex = verticesArray.length / 3;
  18487. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18488. addUV(uvs[0]);
  18489. addUV(uvs[1]);
  18490. addUV(uvs[2]);
  18491. }
  18492. function f4(a, b, c, d) {
  18493. addVertex(a);
  18494. addVertex(b);
  18495. addVertex(d);
  18496. addVertex(b);
  18497. addVertex(c);
  18498. addVertex(d);
  18499. var nextIndex = verticesArray.length / 3;
  18500. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18501. addUV(uvs[0]);
  18502. addUV(uvs[1]);
  18503. addUV(uvs[3]);
  18504. addUV(uvs[1]);
  18505. addUV(uvs[2]);
  18506. addUV(uvs[3]);
  18507. }
  18508. function addVertex(index) {
  18509. verticesArray.push(placeholder[index * 3 + 0]);
  18510. verticesArray.push(placeholder[index * 3 + 1]);
  18511. verticesArray.push(placeholder[index * 3 + 2]);
  18512. }
  18513. function addUV(vector2) {
  18514. uvArray.push(vector2.x);
  18515. uvArray.push(vector2.y);
  18516. }
  18517. }
  18518. return _this;
  18519. }
  18520. var _proto = ExtrudeBufferGeometry.prototype;
  18521. _proto.toJSON = function toJSON() {
  18522. var data = BufferGeometry.prototype.toJSON.call(this);
  18523. var shapes = this.parameters.shapes;
  18524. var options = this.parameters.options;
  18525. return _toJSON(shapes, options, data);
  18526. };
  18527. return ExtrudeBufferGeometry;
  18528. }(BufferGeometry);
  18529. var WorldUVGenerator = {
  18530. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18531. var a_x = vertices[indexA * 3];
  18532. var a_y = vertices[indexA * 3 + 1];
  18533. var b_x = vertices[indexB * 3];
  18534. var b_y = vertices[indexB * 3 + 1];
  18535. var c_x = vertices[indexC * 3];
  18536. var c_y = vertices[indexC * 3 + 1];
  18537. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18538. },
  18539. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18540. var a_x = vertices[indexA * 3];
  18541. var a_y = vertices[indexA * 3 + 1];
  18542. var a_z = vertices[indexA * 3 + 2];
  18543. var b_x = vertices[indexB * 3];
  18544. var b_y = vertices[indexB * 3 + 1];
  18545. var b_z = vertices[indexB * 3 + 2];
  18546. var c_x = vertices[indexC * 3];
  18547. var c_y = vertices[indexC * 3 + 1];
  18548. var c_z = vertices[indexC * 3 + 2];
  18549. var d_x = vertices[indexD * 3];
  18550. var d_y = vertices[indexD * 3 + 1];
  18551. var d_z = vertices[indexD * 3 + 2];
  18552. if (Math.abs(a_y - b_y) < 0.01) {
  18553. 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)];
  18554. } else {
  18555. 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)];
  18556. }
  18557. }
  18558. };
  18559. function _toJSON(shapes, options, data) {
  18560. data.shapes = [];
  18561. if (Array.isArray(shapes)) {
  18562. for (var i = 0, l = shapes.length; i < l; i++) {
  18563. var shape = shapes[i];
  18564. data.shapes.push(shape.uuid);
  18565. }
  18566. } else {
  18567. data.shapes.push(shapes.uuid);
  18568. }
  18569. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18570. return data;
  18571. }
  18572. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18573. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18574. function ExtrudeGeometry(shapes, options) {
  18575. var _this;
  18576. _this = _Geometry.call(this) || this;
  18577. _this.type = 'ExtrudeGeometry';
  18578. _this.parameters = {
  18579. shapes: shapes,
  18580. options: options
  18581. };
  18582. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18583. _this.mergeVertices();
  18584. return _this;
  18585. }
  18586. var _proto = ExtrudeGeometry.prototype;
  18587. _proto.toJSON = function toJSON() {
  18588. var data = _Geometry.prototype.toJSON.call(this);
  18589. var shapes = this.parameters.shapes;
  18590. var options = this.parameters.options;
  18591. return _toJSON$1(shapes, options, data);
  18592. };
  18593. return ExtrudeGeometry;
  18594. }(Geometry);
  18595. function _toJSON$1(shapes, options, data) {
  18596. data.shapes = [];
  18597. if (Array.isArray(shapes)) {
  18598. for (var i = 0, l = shapes.length; i < l; i++) {
  18599. var shape = shapes[i];
  18600. data.shapes.push(shape.uuid);
  18601. }
  18602. } else {
  18603. data.shapes.push(shapes.uuid);
  18604. }
  18605. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18606. return data;
  18607. }
  18608. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18609. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  18610. function IcosahedronBufferGeometry(radius, detail) {
  18611. var _this;
  18612. var t = (1 + Math.sqrt(5)) / 2;
  18613. 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];
  18614. 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];
  18615. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18616. _this.type = 'IcosahedronBufferGeometry';
  18617. _this.parameters = {
  18618. radius: radius,
  18619. detail: detail
  18620. };
  18621. return _this;
  18622. }
  18623. return IcosahedronBufferGeometry;
  18624. }(PolyhedronBufferGeometry);
  18625. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18626. _inheritsLoose(IcosahedronGeometry, _Geometry);
  18627. function IcosahedronGeometry(radius, detail) {
  18628. var _this;
  18629. _this = _Geometry.call(this) || this;
  18630. _this.type = 'IcosahedronGeometry';
  18631. _this.parameters = {
  18632. radius: radius,
  18633. detail: detail
  18634. };
  18635. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  18636. _this.mergeVertices();
  18637. return _this;
  18638. }
  18639. return IcosahedronGeometry;
  18640. }(Geometry);
  18641. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18642. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  18643. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  18644. var _this;
  18645. _this = _BufferGeometry.call(this) || this;
  18646. _this.type = 'LatheBufferGeometry';
  18647. _this.parameters = {
  18648. points: points,
  18649. segments: segments,
  18650. phiStart: phiStart,
  18651. phiLength: phiLength
  18652. };
  18653. segments = Math.floor(segments) || 12;
  18654. phiStart = phiStart || 0;
  18655. phiLength = phiLength || Math.PI * 2; // clamp phiLength so it's in range of [ 0, 2PI ]
  18656. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18657. var indices = [];
  18658. var vertices = [];
  18659. var uvs = []; // helper variables
  18660. var inverseSegments = 1.0 / segments;
  18661. var vertex = new Vector3();
  18662. var uv = new Vector2(); // generate vertices and uvs
  18663. for (var i = 0; i <= segments; i++) {
  18664. var phi = phiStart + i * inverseSegments * phiLength;
  18665. var sin = Math.sin(phi);
  18666. var cos = Math.cos(phi);
  18667. for (var j = 0; j <= points.length - 1; j++) {
  18668. // vertex
  18669. vertex.x = points[j].x * sin;
  18670. vertex.y = points[j].y;
  18671. vertex.z = points[j].x * cos;
  18672. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18673. uv.x = i / segments;
  18674. uv.y = j / (points.length - 1);
  18675. uvs.push(uv.x, uv.y);
  18676. }
  18677. } // indices
  18678. for (var _i = 0; _i < segments; _i++) {
  18679. for (var _j = 0; _j < points.length - 1; _j++) {
  18680. var base = _j + _i * points.length;
  18681. var a = base;
  18682. var b = base + points.length;
  18683. var c = base + points.length + 1;
  18684. var d = base + 1; // faces
  18685. indices.push(a, b, d);
  18686. indices.push(b, c, d);
  18687. }
  18688. } // build geometry
  18689. _this.setIndex(indices);
  18690. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18691. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18692. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18693. // because the corresponding vertices are identical (but still have different UVs).
  18694. if (phiLength === Math.PI * 2) {
  18695. var normals = _this.attributes.normal.array;
  18696. var n1 = new Vector3();
  18697. var n2 = new Vector3();
  18698. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18699. var _base = segments * points.length * 3;
  18700. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18701. // select the normal of the vertex in the first line
  18702. n1.x = normals[_j2 + 0];
  18703. n1.y = normals[_j2 + 1];
  18704. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18705. n2.x = normals[_base + _j2 + 0];
  18706. n2.y = normals[_base + _j2 + 1];
  18707. n2.z = normals[_base + _j2 + 2]; // average normals
  18708. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18709. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18710. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18711. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18712. }
  18713. }
  18714. return _this;
  18715. }
  18716. return LatheBufferGeometry;
  18717. }(BufferGeometry);
  18718. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  18719. _inheritsLoose(LatheGeometry, _Geometry);
  18720. function LatheGeometry(points, segments, phiStart, phiLength) {
  18721. var _this;
  18722. _this = _Geometry.call(this) || this;
  18723. _this.type = 'LatheGeometry';
  18724. _this.parameters = {
  18725. points: points,
  18726. segments: segments,
  18727. phiStart: phiStart,
  18728. phiLength: phiLength
  18729. };
  18730. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  18731. _this.mergeVertices();
  18732. return _this;
  18733. }
  18734. return LatheGeometry;
  18735. }(Geometry);
  18736. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18737. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  18738. function OctahedronBufferGeometry(radius, detail) {
  18739. var _this;
  18740. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18741. 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];
  18742. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18743. _this.type = 'OctahedronBufferGeometry';
  18744. _this.parameters = {
  18745. radius: radius,
  18746. detail: detail
  18747. };
  18748. return _this;
  18749. }
  18750. return OctahedronBufferGeometry;
  18751. }(PolyhedronBufferGeometry);
  18752. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18753. _inheritsLoose(OctahedronGeometry, _Geometry);
  18754. function OctahedronGeometry(radius, detail) {
  18755. var _this;
  18756. _this = _Geometry.call(this) || this;
  18757. _this.type = 'OctahedronGeometry';
  18758. _this.parameters = {
  18759. radius: radius,
  18760. detail: detail
  18761. };
  18762. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  18763. _this.mergeVertices();
  18764. return _this;
  18765. }
  18766. return OctahedronGeometry;
  18767. }(Geometry);
  18768. /**
  18769. * Parametric Surfaces Geometry
  18770. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18771. */
  18772. function ParametricBufferGeometry(func, slices, stacks) {
  18773. BufferGeometry.call(this);
  18774. this.type = 'ParametricBufferGeometry';
  18775. this.parameters = {
  18776. func: func,
  18777. slices: slices,
  18778. stacks: stacks
  18779. }; // buffers
  18780. var indices = [];
  18781. var vertices = [];
  18782. var normals = [];
  18783. var uvs = [];
  18784. var EPS = 0.00001;
  18785. var normal = new Vector3();
  18786. var p0 = new Vector3(),
  18787. p1 = new Vector3();
  18788. var pu = new Vector3(),
  18789. pv = new Vector3();
  18790. if (func.length < 3) {
  18791. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18792. } // generate vertices, normals and uvs
  18793. var sliceCount = slices + 1;
  18794. for (var i = 0; i <= stacks; i++) {
  18795. var v = i / stacks;
  18796. for (var j = 0; j <= slices; j++) {
  18797. var u = j / slices; // vertex
  18798. func(u, v, p0);
  18799. vertices.push(p0.x, p0.y, p0.z); // normal
  18800. // approximate tangent vectors via finite differences
  18801. if (u - EPS >= 0) {
  18802. func(u - EPS, v, p1);
  18803. pu.subVectors(p0, p1);
  18804. } else {
  18805. func(u + EPS, v, p1);
  18806. pu.subVectors(p1, p0);
  18807. }
  18808. if (v - EPS >= 0) {
  18809. func(u, v - EPS, p1);
  18810. pv.subVectors(p0, p1);
  18811. } else {
  18812. func(u, v + EPS, p1);
  18813. pv.subVectors(p1, p0);
  18814. } // cross product of tangent vectors returns surface normal
  18815. normal.crossVectors(pu, pv).normalize();
  18816. normals.push(normal.x, normal.y, normal.z); // uv
  18817. uvs.push(u, v);
  18818. }
  18819. } // generate indices
  18820. for (var _i = 0; _i < stacks; _i++) {
  18821. for (var _j = 0; _j < slices; _j++) {
  18822. var a = _i * sliceCount + _j;
  18823. var b = _i * sliceCount + _j + 1;
  18824. var c = (_i + 1) * sliceCount + _j + 1;
  18825. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18826. indices.push(a, b, d);
  18827. indices.push(b, c, d);
  18828. }
  18829. } // build geometry
  18830. this.setIndex(indices);
  18831. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18832. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18833. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18834. }
  18835. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  18836. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  18837. /**
  18838. * Parametric Surfaces Geometry
  18839. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18840. */
  18841. function ParametricGeometry(func, slices, stacks) {
  18842. Geometry.call(this);
  18843. this.type = 'ParametricGeometry';
  18844. this.parameters = {
  18845. func: func,
  18846. slices: slices,
  18847. stacks: stacks
  18848. };
  18849. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  18850. this.mergeVertices();
  18851. }
  18852. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  18853. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18854. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  18855. _inheritsLoose(PlaneGeometry, _Geometry);
  18856. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  18857. var _this;
  18858. _this = _Geometry.call(this) || this;
  18859. _this.type = 'PlaneGeometry';
  18860. _this.parameters = {
  18861. width: width,
  18862. height: height,
  18863. widthSegments: widthSegments,
  18864. heightSegments: heightSegments
  18865. };
  18866. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  18867. _this.mergeVertices();
  18868. return _this;
  18869. }
  18870. return PlaneGeometry;
  18871. }(Geometry);
  18872. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  18873. _inheritsLoose(PolyhedronGeometry, _Geometry);
  18874. function PolyhedronGeometry(vertices, indices, radius, detail) {
  18875. var _this;
  18876. _this = _Geometry.call(this) || this;
  18877. _this.type = 'PolyhedronGeometry';
  18878. _this.parameters = {
  18879. vertices: vertices,
  18880. indices: indices,
  18881. radius: radius,
  18882. detail: detail
  18883. };
  18884. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  18885. _this.mergeVertices();
  18886. return _this;
  18887. }
  18888. return PolyhedronGeometry;
  18889. }(Geometry);
  18890. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18891. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  18892. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18893. var _this;
  18894. _this = _BufferGeometry.call(this) || this;
  18895. _this.type = 'RingBufferGeometry';
  18896. _this.parameters = {
  18897. innerRadius: innerRadius,
  18898. outerRadius: outerRadius,
  18899. thetaSegments: thetaSegments,
  18900. phiSegments: phiSegments,
  18901. thetaStart: thetaStart,
  18902. thetaLength: thetaLength
  18903. };
  18904. innerRadius = innerRadius || 0.5;
  18905. outerRadius = outerRadius || 1;
  18906. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18907. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18908. thetaSegments = thetaSegments !== undefined ? Math.max(3, thetaSegments) : 8;
  18909. phiSegments = phiSegments !== undefined ? Math.max(1, phiSegments) : 1; // buffers
  18910. var indices = [];
  18911. var vertices = [];
  18912. var normals = [];
  18913. var uvs = []; // some helper variables
  18914. var radius = innerRadius;
  18915. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18916. var vertex = new Vector3();
  18917. var uv = new Vector2(); // generate vertices, normals and uvs
  18918. for (var j = 0; j <= phiSegments; j++) {
  18919. for (var i = 0; i <= thetaSegments; i++) {
  18920. // values are generate from the inside of the ring to the outside
  18921. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18922. vertex.x = radius * Math.cos(segment);
  18923. vertex.y = radius * Math.sin(segment);
  18924. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18925. normals.push(0, 0, 1); // uv
  18926. uv.x = (vertex.x / outerRadius + 1) / 2;
  18927. uv.y = (vertex.y / outerRadius + 1) / 2;
  18928. uvs.push(uv.x, uv.y);
  18929. } // increase the radius for next row of vertices
  18930. radius += radiusStep;
  18931. } // indices
  18932. for (var _j = 0; _j < phiSegments; _j++) {
  18933. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18934. for (var _i = 0; _i < thetaSegments; _i++) {
  18935. var _segment = _i + thetaSegmentLevel;
  18936. var a = _segment;
  18937. var b = _segment + thetaSegments + 1;
  18938. var c = _segment + thetaSegments + 2;
  18939. var d = _segment + 1; // faces
  18940. indices.push(a, b, d);
  18941. indices.push(b, c, d);
  18942. }
  18943. } // build geometry
  18944. _this.setIndex(indices);
  18945. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18946. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18947. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18948. return _this;
  18949. }
  18950. return RingBufferGeometry;
  18951. }(BufferGeometry);
  18952. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  18953. _inheritsLoose(RingGeometry, _Geometry);
  18954. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18955. var _this;
  18956. _this = _Geometry.call(this) || this;
  18957. _this.type = 'RingGeometry';
  18958. _this.parameters = {
  18959. innerRadius: innerRadius,
  18960. outerRadius: outerRadius,
  18961. thetaSegments: thetaSegments,
  18962. phiSegments: phiSegments,
  18963. thetaStart: thetaStart,
  18964. thetaLength: thetaLength
  18965. };
  18966. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  18967. _this.mergeVertices();
  18968. return _this;
  18969. }
  18970. return RingGeometry;
  18971. }(Geometry);
  18972. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18973. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  18974. function ShapeBufferGeometry(shapes, curveSegments) {
  18975. var _this;
  18976. _this = _BufferGeometry.call(this) || this;
  18977. _this.type = 'ShapeBufferGeometry';
  18978. _this.parameters = {
  18979. shapes: shapes,
  18980. curveSegments: curveSegments
  18981. };
  18982. curveSegments = curveSegments || 12; // buffers
  18983. var indices = [];
  18984. var vertices = [];
  18985. var normals = [];
  18986. var uvs = []; // helper variables
  18987. var groupStart = 0;
  18988. var groupCount = 0; // allow single and array values for "shapes" parameter
  18989. if (Array.isArray(shapes) === false) {
  18990. addShape(shapes);
  18991. } else {
  18992. for (var i = 0; i < shapes.length; i++) {
  18993. addShape(shapes[i]);
  18994. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18995. groupStart += groupCount;
  18996. groupCount = 0;
  18997. }
  18998. } // build geometry
  18999. _this.setIndex(indices);
  19000. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19001. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19002. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19003. function addShape(shape) {
  19004. var indexOffset = vertices.length / 3;
  19005. var points = shape.extractPoints(curveSegments);
  19006. var shapeVertices = points.shape;
  19007. var shapeHoles = points.holes; // check direction of vertices
  19008. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19009. shapeVertices = shapeVertices.reverse();
  19010. }
  19011. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19012. var shapeHole = shapeHoles[_i];
  19013. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19014. shapeHoles[_i] = shapeHole.reverse();
  19015. }
  19016. }
  19017. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19018. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19019. var _shapeHole = shapeHoles[_i2];
  19020. shapeVertices = shapeVertices.concat(_shapeHole);
  19021. } // vertices, normals, uvs
  19022. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19023. var vertex = shapeVertices[_i3];
  19024. vertices.push(vertex.x, vertex.y, 0);
  19025. normals.push(0, 0, 1);
  19026. uvs.push(vertex.x, vertex.y); // world uvs
  19027. } // incides
  19028. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19029. var face = faces[_i4];
  19030. var a = face[0] + indexOffset;
  19031. var b = face[1] + indexOffset;
  19032. var c = face[2] + indexOffset;
  19033. indices.push(a, b, c);
  19034. groupCount += 3;
  19035. }
  19036. }
  19037. return _this;
  19038. }
  19039. var _proto = ShapeBufferGeometry.prototype;
  19040. _proto.toJSON = function toJSON() {
  19041. var data = BufferGeometry.prototype.toJSON.call(this);
  19042. var shapes = this.parameters.shapes;
  19043. return _toJSON$2(shapes, data);
  19044. };
  19045. return ShapeBufferGeometry;
  19046. }(BufferGeometry);
  19047. function _toJSON$2(shapes, data) {
  19048. data.shapes = [];
  19049. if (Array.isArray(shapes)) {
  19050. for (var i = 0, l = shapes.length; i < l; i++) {
  19051. var shape = shapes[i];
  19052. data.shapes.push(shape.uuid);
  19053. }
  19054. } else {
  19055. data.shapes.push(shapes.uuid);
  19056. }
  19057. return data;
  19058. }
  19059. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  19060. _inheritsLoose(ShapeGeometry, _Geometry);
  19061. function ShapeGeometry(shapes, curveSegments) {
  19062. var _this;
  19063. _this = _Geometry.call(this) || this;
  19064. _this.type = 'ShapeGeometry';
  19065. if (typeof curveSegments === 'object') {
  19066. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19067. curveSegments = curveSegments.curveSegments;
  19068. }
  19069. _this.parameters = {
  19070. shapes: shapes,
  19071. curveSegments: curveSegments
  19072. };
  19073. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19074. _this.mergeVertices();
  19075. return _this;
  19076. }
  19077. var _proto = ShapeGeometry.prototype;
  19078. _proto.toJSON = function toJSON() {
  19079. var data = Geometry.prototype.toJSON.call(this);
  19080. var shapes = this.parameters.shapes;
  19081. return _toJSON$3(shapes, data);
  19082. };
  19083. return ShapeGeometry;
  19084. }(Geometry);
  19085. function _toJSON$3(shapes, data) {
  19086. data.shapes = [];
  19087. if (Array.isArray(shapes)) {
  19088. for (var i = 0, l = shapes.length; i < l; i++) {
  19089. var shape = shapes[i];
  19090. data.shapes.push(shape.uuid);
  19091. }
  19092. } else {
  19093. data.shapes.push(shapes.uuid);
  19094. }
  19095. return data;
  19096. }
  19097. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19098. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19099. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19100. var _this;
  19101. _this = _BufferGeometry.call(this) || this;
  19102. _this.type = 'SphereBufferGeometry';
  19103. _this.parameters = {
  19104. radius: radius,
  19105. widthSegments: widthSegments,
  19106. heightSegments: heightSegments,
  19107. phiStart: phiStart,
  19108. phiLength: phiLength,
  19109. thetaStart: thetaStart,
  19110. thetaLength: thetaLength
  19111. };
  19112. radius = radius || 1;
  19113. widthSegments = Math.max(3, Math.floor(widthSegments) || 8);
  19114. heightSegments = Math.max(2, Math.floor(heightSegments) || 6);
  19115. phiStart = phiStart !== undefined ? phiStart : 0;
  19116. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19117. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19118. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19119. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19120. var index = 0;
  19121. var grid = [];
  19122. var vertex = new Vector3();
  19123. var normal = new Vector3(); // buffers
  19124. var indices = [];
  19125. var vertices = [];
  19126. var normals = [];
  19127. var uvs = []; // generate vertices, normals and uvs
  19128. for (var iy = 0; iy <= heightSegments; iy++) {
  19129. var verticesRow = [];
  19130. var v = iy / heightSegments; // special case for the poles
  19131. var uOffset = 0;
  19132. if (iy == 0 && thetaStart == 0) {
  19133. uOffset = 0.5 / widthSegments;
  19134. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19135. uOffset = -0.5 / widthSegments;
  19136. }
  19137. for (var ix = 0; ix <= widthSegments; ix++) {
  19138. var u = ix / widthSegments; // vertex
  19139. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19140. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19141. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19142. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19143. normal.copy(vertex).normalize();
  19144. normals.push(normal.x, normal.y, normal.z); // uv
  19145. uvs.push(u + uOffset, 1 - v);
  19146. verticesRow.push(index++);
  19147. }
  19148. grid.push(verticesRow);
  19149. } // indices
  19150. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19151. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19152. var a = grid[_iy][_ix + 1];
  19153. var b = grid[_iy][_ix];
  19154. var c = grid[_iy + 1][_ix];
  19155. var d = grid[_iy + 1][_ix + 1];
  19156. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19157. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19158. }
  19159. } // build geometry
  19160. _this.setIndex(indices);
  19161. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19162. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19163. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19164. return _this;
  19165. }
  19166. return SphereBufferGeometry;
  19167. }(BufferGeometry);
  19168. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19169. _inheritsLoose(SphereGeometry, _Geometry);
  19170. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19171. var _this;
  19172. _this = _Geometry.call(this) || this;
  19173. _this.type = 'SphereGeometry';
  19174. _this.parameters = {
  19175. radius: radius,
  19176. widthSegments: widthSegments,
  19177. heightSegments: heightSegments,
  19178. phiStart: phiStart,
  19179. phiLength: phiLength,
  19180. thetaStart: thetaStart,
  19181. thetaLength: thetaLength
  19182. };
  19183. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19184. _this.mergeVertices();
  19185. return _this;
  19186. }
  19187. return SphereGeometry;
  19188. }(Geometry);
  19189. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19190. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19191. function TetrahedronBufferGeometry(radius, detail) {
  19192. var _this;
  19193. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19194. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19195. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19196. _this.type = 'TetrahedronBufferGeometry';
  19197. _this.parameters = {
  19198. radius: radius,
  19199. detail: detail
  19200. };
  19201. return _this;
  19202. }
  19203. return TetrahedronBufferGeometry;
  19204. }(PolyhedronBufferGeometry);
  19205. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19206. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19207. function TetrahedronGeometry(radius, detail) {
  19208. var _this;
  19209. _this = _Geometry.call(this) || this;
  19210. _this.type = 'TetrahedronGeometry';
  19211. _this.parameters = {
  19212. radius: radius,
  19213. detail: detail
  19214. };
  19215. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19216. _this.mergeVertices();
  19217. return _this;
  19218. }
  19219. return TetrahedronGeometry;
  19220. }(Geometry);
  19221. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19222. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19223. function TextBufferGeometry(text, parameters) {
  19224. var _this;
  19225. parameters = parameters || {};
  19226. var font = parameters.font;
  19227. if (!(font && font.isFont)) {
  19228. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19229. return new BufferGeometry() || _assertThisInitialized(_this);
  19230. }
  19231. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19232. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19233. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19234. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19235. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19236. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19237. _this.type = 'TextBufferGeometry';
  19238. return _this;
  19239. }
  19240. return TextBufferGeometry;
  19241. }(ExtrudeBufferGeometry);
  19242. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19243. _inheritsLoose(TextGeometry, _Geometry);
  19244. function TextGeometry(text, parameters) {
  19245. var _this;
  19246. _this = _Geometry.call(this) || this;
  19247. _this.type = 'TextGeometry';
  19248. _this.parameters = {
  19249. text: text,
  19250. parameters: parameters
  19251. };
  19252. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19253. _this.mergeVertices();
  19254. return _this;
  19255. }
  19256. return TextGeometry;
  19257. }(Geometry);
  19258. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19259. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19260. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19261. var _this;
  19262. _this = _BufferGeometry.call(this) || this;
  19263. _this.type = 'TorusBufferGeometry';
  19264. _this.parameters = {
  19265. radius: radius,
  19266. tube: tube,
  19267. radialSegments: radialSegments,
  19268. tubularSegments: tubularSegments,
  19269. arc: arc
  19270. };
  19271. radius = radius || 1;
  19272. tube = tube || 0.4;
  19273. radialSegments = Math.floor(radialSegments) || 8;
  19274. tubularSegments = Math.floor(tubularSegments) || 6;
  19275. arc = arc || Math.PI * 2; // buffers
  19276. var indices = [];
  19277. var vertices = [];
  19278. var normals = [];
  19279. var uvs = []; // helper variables
  19280. var center = new Vector3();
  19281. var vertex = new Vector3();
  19282. var normal = new Vector3(); // generate vertices, normals and uvs
  19283. for (var j = 0; j <= radialSegments; j++) {
  19284. for (var i = 0; i <= tubularSegments; i++) {
  19285. var u = i / tubularSegments * arc;
  19286. var v = j / radialSegments * Math.PI * 2; // vertex
  19287. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19288. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19289. vertex.z = tube * Math.sin(v);
  19290. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19291. center.x = radius * Math.cos(u);
  19292. center.y = radius * Math.sin(u);
  19293. normal.subVectors(vertex, center).normalize();
  19294. normals.push(normal.x, normal.y, normal.z); // uv
  19295. uvs.push(i / tubularSegments);
  19296. uvs.push(j / radialSegments);
  19297. }
  19298. } // generate indices
  19299. for (var _j = 1; _j <= radialSegments; _j++) {
  19300. for (var _i = 1; _i <= tubularSegments; _i++) {
  19301. // indices
  19302. var a = (tubularSegments + 1) * _j + _i - 1;
  19303. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19304. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19305. var d = (tubularSegments + 1) * _j + _i; // faces
  19306. indices.push(a, b, d);
  19307. indices.push(b, c, d);
  19308. }
  19309. } // build geometry
  19310. _this.setIndex(indices);
  19311. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19312. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19313. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19314. return _this;
  19315. }
  19316. return TorusBufferGeometry;
  19317. }(BufferGeometry);
  19318. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19319. _inheritsLoose(TorusGeometry, _Geometry);
  19320. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19321. var _this;
  19322. _this = _Geometry.call(this) || this;
  19323. _this.type = 'TorusGeometry';
  19324. _this.parameters = {
  19325. radius: radius,
  19326. tube: tube,
  19327. radialSegments: radialSegments,
  19328. tubularSegments: tubularSegments,
  19329. arc: arc
  19330. };
  19331. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19332. _this.mergeVertices();
  19333. return _this;
  19334. }
  19335. return TorusGeometry;
  19336. }(Geometry);
  19337. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19338. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19339. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19340. var _this;
  19341. _this = _BufferGeometry.call(this) || this;
  19342. _this.type = 'TorusKnotBufferGeometry';
  19343. _this.parameters = {
  19344. radius: radius,
  19345. tube: tube,
  19346. tubularSegments: tubularSegments,
  19347. radialSegments: radialSegments,
  19348. p: p,
  19349. q: q
  19350. };
  19351. radius = radius || 1;
  19352. tube = tube || 0.4;
  19353. tubularSegments = Math.floor(tubularSegments) || 64;
  19354. radialSegments = Math.floor(radialSegments) || 8;
  19355. p = p || 2;
  19356. q = q || 3; // buffers
  19357. var indices = [];
  19358. var vertices = [];
  19359. var normals = [];
  19360. var uvs = []; // helper variables
  19361. var vertex = new Vector3();
  19362. var normal = new Vector3();
  19363. var P1 = new Vector3();
  19364. var P2 = new Vector3();
  19365. var B = new Vector3();
  19366. var T = new Vector3();
  19367. var N = new Vector3(); // generate vertices, normals and uvs
  19368. for (var i = 0; i <= tubularSegments; ++i) {
  19369. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19370. 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.
  19371. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19372. calculatePositionOnCurve(u, p, q, radius, P1);
  19373. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19374. T.subVectors(P2, P1);
  19375. N.addVectors(P2, P1);
  19376. B.crossVectors(T, N);
  19377. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19378. B.normalize();
  19379. N.normalize();
  19380. for (var j = 0; j <= radialSegments; ++j) {
  19381. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19382. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19383. var v = j / radialSegments * Math.PI * 2;
  19384. var cx = -tube * Math.cos(v);
  19385. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19386. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19387. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19388. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19389. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19390. 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)
  19391. normal.subVectors(vertex, P1).normalize();
  19392. normals.push(normal.x, normal.y, normal.z); // uv
  19393. uvs.push(i / tubularSegments);
  19394. uvs.push(j / radialSegments);
  19395. }
  19396. } // generate indices
  19397. for (var _j = 1; _j <= tubularSegments; _j++) {
  19398. for (var _i = 1; _i <= radialSegments; _i++) {
  19399. // indices
  19400. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19401. var b = (radialSegments + 1) * _j + (_i - 1);
  19402. var c = (radialSegments + 1) * _j + _i;
  19403. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19404. indices.push(a, b, d);
  19405. indices.push(b, c, d);
  19406. }
  19407. } // build geometry
  19408. _this.setIndex(indices);
  19409. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19410. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19411. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19412. function calculatePositionOnCurve(u, p, q, radius, position) {
  19413. var cu = Math.cos(u);
  19414. var su = Math.sin(u);
  19415. var quOverP = q / p * u;
  19416. var cs = Math.cos(quOverP);
  19417. position.x = radius * (2 + cs) * 0.5 * cu;
  19418. position.y = radius * (2 + cs) * su * 0.5;
  19419. position.z = radius * Math.sin(quOverP) * 0.5;
  19420. }
  19421. return _this;
  19422. }
  19423. return TorusKnotBufferGeometry;
  19424. }(BufferGeometry);
  19425. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19426. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19427. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19428. var _this;
  19429. _this = _Geometry.call(this) || this;
  19430. _this.type = 'TorusKnotGeometry';
  19431. _this.parameters = {
  19432. radius: radius,
  19433. tube: tube,
  19434. tubularSegments: tubularSegments,
  19435. radialSegments: radialSegments,
  19436. p: p,
  19437. q: q
  19438. };
  19439. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19440. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19441. _this.mergeVertices();
  19442. return _this;
  19443. }
  19444. return TorusKnotGeometry;
  19445. }(Geometry);
  19446. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19447. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19448. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19449. var _this;
  19450. _this = _BufferGeometry.call(this) || this;
  19451. _this.type = 'TubeBufferGeometry';
  19452. _this.parameters = {
  19453. path: path,
  19454. tubularSegments: tubularSegments,
  19455. radius: radius,
  19456. radialSegments: radialSegments,
  19457. closed: closed
  19458. };
  19459. tubularSegments = tubularSegments || 64;
  19460. radius = radius || 1;
  19461. radialSegments = radialSegments || 8;
  19462. closed = closed || false;
  19463. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19464. _this.tangents = frames.tangents;
  19465. _this.normals = frames.normals;
  19466. _this.binormals = frames.binormals; // helper variables
  19467. var vertex = new Vector3();
  19468. var normal = new Vector3();
  19469. var uv = new Vector2();
  19470. var P = new Vector3(); // buffer
  19471. var vertices = [];
  19472. var normals = [];
  19473. var uvs = [];
  19474. var indices = []; // create buffer data
  19475. generateBufferData(); // build geometry
  19476. _this.setIndex(indices);
  19477. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19478. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19479. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19480. function generateBufferData() {
  19481. for (var i = 0; i < tubularSegments; i++) {
  19482. generateSegment(i);
  19483. } // if the geometry is not closed, generate the last row of vertices and normals
  19484. // at the regular position on the given path
  19485. //
  19486. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19487. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19488. // this makes it easy compute correct values for closed geometries
  19489. generateUVs(); // finally create faces
  19490. generateIndices();
  19491. }
  19492. function generateSegment(i) {
  19493. // we use getPointAt to sample evenly distributed points from the given path
  19494. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19495. var N = frames.normals[i];
  19496. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19497. for (var j = 0; j <= radialSegments; j++) {
  19498. var v = j / radialSegments * Math.PI * 2;
  19499. var sin = Math.sin(v);
  19500. var cos = -Math.cos(v); // normal
  19501. normal.x = cos * N.x + sin * B.x;
  19502. normal.y = cos * N.y + sin * B.y;
  19503. normal.z = cos * N.z + sin * B.z;
  19504. normal.normalize();
  19505. normals.push(normal.x, normal.y, normal.z); // vertex
  19506. vertex.x = P.x + radius * normal.x;
  19507. vertex.y = P.y + radius * normal.y;
  19508. vertex.z = P.z + radius * normal.z;
  19509. vertices.push(vertex.x, vertex.y, vertex.z);
  19510. }
  19511. }
  19512. function generateIndices() {
  19513. for (var j = 1; j <= tubularSegments; j++) {
  19514. for (var i = 1; i <= radialSegments; i++) {
  19515. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19516. var b = (radialSegments + 1) * j + (i - 1);
  19517. var c = (radialSegments + 1) * j + i;
  19518. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19519. indices.push(a, b, d);
  19520. indices.push(b, c, d);
  19521. }
  19522. }
  19523. }
  19524. function generateUVs() {
  19525. for (var i = 0; i <= tubularSegments; i++) {
  19526. for (var j = 0; j <= radialSegments; j++) {
  19527. uv.x = i / tubularSegments;
  19528. uv.y = j / radialSegments;
  19529. uvs.push(uv.x, uv.y);
  19530. }
  19531. }
  19532. }
  19533. return _this;
  19534. }
  19535. var _proto = TubeBufferGeometry.prototype;
  19536. _proto.toJSON = function toJSON() {
  19537. var data = BufferGeometry.prototype.toJSON.call(this);
  19538. data.path = this.parameters.path.toJSON();
  19539. return data;
  19540. };
  19541. return TubeBufferGeometry;
  19542. }(BufferGeometry);
  19543. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  19544. _inheritsLoose(TubeGeometry, _Geometry);
  19545. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  19546. var _this;
  19547. _this = _Geometry.call(this) || this;
  19548. _this.type = 'TubeGeometry';
  19549. _this.parameters = {
  19550. path: path,
  19551. tubularSegments: tubularSegments,
  19552. radius: radius,
  19553. radialSegments: radialSegments,
  19554. closed: closed
  19555. };
  19556. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  19557. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  19558. _this.tangents = bufferGeometry.tangents;
  19559. _this.normals = bufferGeometry.normals;
  19560. _this.binormals = bufferGeometry.binormals; // create geometry
  19561. _this.fromBufferGeometry(bufferGeometry);
  19562. _this.mergeVertices();
  19563. return _this;
  19564. }
  19565. return TubeGeometry;
  19566. }(Geometry);
  19567. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19568. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19569. function WireframeGeometry(geometry) {
  19570. var _this;
  19571. _this = _BufferGeometry.call(this) || this;
  19572. _this.type = 'WireframeGeometry'; // buffer
  19573. var vertices = []; // helper variables
  19574. var edge = [0, 0],
  19575. edges = {};
  19576. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  19577. if (geometry && geometry.isGeometry) {
  19578. // create a data structure that contains all edges without duplicates
  19579. var faces = geometry.faces;
  19580. for (var i = 0, l = faces.length; i < l; i++) {
  19581. var face = faces[i];
  19582. for (var j = 0; j < 3; j++) {
  19583. var edge1 = face[keys[j]];
  19584. var edge2 = face[keys[(j + 1) % 3]];
  19585. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19586. edge[1] = Math.max(edge1, edge2);
  19587. var key = edge[0] + ',' + edge[1];
  19588. if (edges[key] === undefined) {
  19589. edges[key] = {
  19590. index1: edge[0],
  19591. index2: edge[1]
  19592. };
  19593. }
  19594. }
  19595. } // generate vertices
  19596. for (var _key in edges) {
  19597. var e = edges[_key];
  19598. var vertex = geometry.vertices[e.index1];
  19599. vertices.push(vertex.x, vertex.y, vertex.z);
  19600. vertex = geometry.vertices[e.index2];
  19601. vertices.push(vertex.x, vertex.y, vertex.z);
  19602. }
  19603. } else if (geometry && geometry.isBufferGeometry) {
  19604. var _vertex = new Vector3();
  19605. if (geometry.index !== null) {
  19606. // indexed BufferGeometry
  19607. var position = geometry.attributes.position;
  19608. var indices = geometry.index;
  19609. var groups = geometry.groups;
  19610. if (groups.length === 0) {
  19611. groups = [{
  19612. start: 0,
  19613. count: indices.count,
  19614. materialIndex: 0
  19615. }];
  19616. } // create a data structure that contains all eges without duplicates
  19617. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19618. var group = groups[o];
  19619. var start = group.start;
  19620. var count = group.count;
  19621. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  19622. for (var _j = 0; _j < 3; _j++) {
  19623. var _edge = indices.getX(_i + _j);
  19624. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  19625. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  19626. edge[1] = Math.max(_edge, _edge2);
  19627. var _key2 = edge[0] + ',' + edge[1];
  19628. if (edges[_key2] === undefined) {
  19629. edges[_key2] = {
  19630. index1: edge[0],
  19631. index2: edge[1]
  19632. };
  19633. }
  19634. }
  19635. }
  19636. } // generate vertices
  19637. for (var _key3 in edges) {
  19638. var _e = edges[_key3];
  19639. _vertex.fromBufferAttribute(position, _e.index1);
  19640. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19641. _vertex.fromBufferAttribute(position, _e.index2);
  19642. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19643. }
  19644. } else {
  19645. // non-indexed BufferGeometry
  19646. var _position = geometry.attributes.position;
  19647. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  19648. for (var _j2 = 0; _j2 < 3; _j2++) {
  19649. // three edges per triangle, an edge is represented as (index1, index2)
  19650. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19651. var index1 = 3 * _i2 + _j2;
  19652. _vertex.fromBufferAttribute(_position, index1);
  19653. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19654. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  19655. _vertex.fromBufferAttribute(_position, index2);
  19656. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19657. }
  19658. }
  19659. }
  19660. } // build geometry
  19661. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19662. return _this;
  19663. }
  19664. return WireframeGeometry;
  19665. }(BufferGeometry);
  19666. var Geometries = /*#__PURE__*/Object.freeze({
  19667. __proto__: null,
  19668. BoxGeometry: BoxGeometry,
  19669. BoxBufferGeometry: BoxBufferGeometry,
  19670. CircleGeometry: CircleGeometry,
  19671. CircleBufferGeometry: CircleBufferGeometry,
  19672. ConeGeometry: ConeGeometry,
  19673. ConeBufferGeometry: ConeBufferGeometry,
  19674. CylinderGeometry: CylinderGeometry,
  19675. CylinderBufferGeometry: CylinderBufferGeometry,
  19676. DodecahedronGeometry: DodecahedronGeometry,
  19677. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19678. EdgesGeometry: EdgesGeometry,
  19679. ExtrudeGeometry: ExtrudeGeometry,
  19680. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19681. IcosahedronGeometry: IcosahedronGeometry,
  19682. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19683. LatheGeometry: LatheGeometry,
  19684. LatheBufferGeometry: LatheBufferGeometry,
  19685. OctahedronGeometry: OctahedronGeometry,
  19686. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19687. ParametricGeometry: ParametricGeometry,
  19688. ParametricBufferGeometry: ParametricBufferGeometry,
  19689. PlaneGeometry: PlaneGeometry,
  19690. PlaneBufferGeometry: PlaneBufferGeometry,
  19691. PolyhedronGeometry: PolyhedronGeometry,
  19692. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19693. RingGeometry: RingGeometry,
  19694. RingBufferGeometry: RingBufferGeometry,
  19695. ShapeGeometry: ShapeGeometry,
  19696. ShapeBufferGeometry: ShapeBufferGeometry,
  19697. SphereGeometry: SphereGeometry,
  19698. SphereBufferGeometry: SphereBufferGeometry,
  19699. TetrahedronGeometry: TetrahedronGeometry,
  19700. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19701. TextGeometry: TextGeometry,
  19702. TextBufferGeometry: TextBufferGeometry,
  19703. TorusGeometry: TorusGeometry,
  19704. TorusBufferGeometry: TorusBufferGeometry,
  19705. TorusKnotGeometry: TorusKnotGeometry,
  19706. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19707. TubeGeometry: TubeGeometry,
  19708. TubeBufferGeometry: TubeBufferGeometry,
  19709. WireframeGeometry: WireframeGeometry
  19710. });
  19711. /**
  19712. * parameters = {
  19713. * color: <THREE.Color>
  19714. * }
  19715. */
  19716. function ShadowMaterial(parameters) {
  19717. Material.call(this);
  19718. this.type = 'ShadowMaterial';
  19719. this.color = new Color(0x000000);
  19720. this.transparent = true;
  19721. this.setValues(parameters);
  19722. }
  19723. ShadowMaterial.prototype = Object.create(Material.prototype);
  19724. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19725. ShadowMaterial.prototype.isShadowMaterial = true;
  19726. ShadowMaterial.prototype.copy = function (source) {
  19727. Material.prototype.copy.call(this, source);
  19728. this.color.copy(source.color);
  19729. return this;
  19730. };
  19731. function RawShaderMaterial(parameters) {
  19732. ShaderMaterial.call(this, parameters);
  19733. this.type = 'RawShaderMaterial';
  19734. }
  19735. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19736. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19737. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19738. /**
  19739. * parameters = {
  19740. * color: <hex>,
  19741. * roughness: <float>,
  19742. * metalness: <float>,
  19743. * opacity: <float>,
  19744. *
  19745. * map: new THREE.Texture( <Image> ),
  19746. *
  19747. * lightMap: new THREE.Texture( <Image> ),
  19748. * lightMapIntensity: <float>
  19749. *
  19750. * aoMap: new THREE.Texture( <Image> ),
  19751. * aoMapIntensity: <float>
  19752. *
  19753. * emissive: <hex>,
  19754. * emissiveIntensity: <float>
  19755. * emissiveMap: new THREE.Texture( <Image> ),
  19756. *
  19757. * bumpMap: new THREE.Texture( <Image> ),
  19758. * bumpScale: <float>,
  19759. *
  19760. * normalMap: new THREE.Texture( <Image> ),
  19761. * normalMapType: THREE.TangentSpaceNormalMap,
  19762. * normalScale: <Vector2>,
  19763. *
  19764. * displacementMap: new THREE.Texture( <Image> ),
  19765. * displacementScale: <float>,
  19766. * displacementBias: <float>,
  19767. *
  19768. * roughnessMap: new THREE.Texture( <Image> ),
  19769. *
  19770. * metalnessMap: new THREE.Texture( <Image> ),
  19771. *
  19772. * alphaMap: new THREE.Texture( <Image> ),
  19773. *
  19774. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19775. * envMapIntensity: <float>
  19776. *
  19777. * refractionRatio: <float>,
  19778. *
  19779. * wireframe: <boolean>,
  19780. * wireframeLinewidth: <float>,
  19781. *
  19782. * skinning: <bool>,
  19783. * morphTargets: <bool>,
  19784. * morphNormals: <bool>
  19785. * }
  19786. */
  19787. function MeshStandardMaterial(parameters) {
  19788. Material.call(this);
  19789. this.defines = {
  19790. 'STANDARD': ''
  19791. };
  19792. this.type = 'MeshStandardMaterial';
  19793. this.color = new Color(0xffffff); // diffuse
  19794. this.roughness = 1.0;
  19795. this.metalness = 0.0;
  19796. this.map = null;
  19797. this.lightMap = null;
  19798. this.lightMapIntensity = 1.0;
  19799. this.aoMap = null;
  19800. this.aoMapIntensity = 1.0;
  19801. this.emissive = new Color(0x000000);
  19802. this.emissiveIntensity = 1.0;
  19803. this.emissiveMap = null;
  19804. this.bumpMap = null;
  19805. this.bumpScale = 1;
  19806. this.normalMap = null;
  19807. this.normalMapType = TangentSpaceNormalMap;
  19808. this.normalScale = new Vector2(1, 1);
  19809. this.displacementMap = null;
  19810. this.displacementScale = 1;
  19811. this.displacementBias = 0;
  19812. this.roughnessMap = null;
  19813. this.metalnessMap = null;
  19814. this.alphaMap = null;
  19815. this.envMap = null;
  19816. this.envMapIntensity = 1.0;
  19817. this.refractionRatio = 0.98;
  19818. this.wireframe = false;
  19819. this.wireframeLinewidth = 1;
  19820. this.wireframeLinecap = 'round';
  19821. this.wireframeLinejoin = 'round';
  19822. this.skinning = false;
  19823. this.morphTargets = false;
  19824. this.morphNormals = false;
  19825. this.vertexTangents = false;
  19826. this.setValues(parameters);
  19827. }
  19828. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19829. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19830. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19831. MeshStandardMaterial.prototype.copy = function (source) {
  19832. Material.prototype.copy.call(this, source);
  19833. this.defines = {
  19834. 'STANDARD': ''
  19835. };
  19836. this.color.copy(source.color);
  19837. this.roughness = source.roughness;
  19838. this.metalness = source.metalness;
  19839. this.map = source.map;
  19840. this.lightMap = source.lightMap;
  19841. this.lightMapIntensity = source.lightMapIntensity;
  19842. this.aoMap = source.aoMap;
  19843. this.aoMapIntensity = source.aoMapIntensity;
  19844. this.emissive.copy(source.emissive);
  19845. this.emissiveMap = source.emissiveMap;
  19846. this.emissiveIntensity = source.emissiveIntensity;
  19847. this.bumpMap = source.bumpMap;
  19848. this.bumpScale = source.bumpScale;
  19849. this.normalMap = source.normalMap;
  19850. this.normalMapType = source.normalMapType;
  19851. this.normalScale.copy(source.normalScale);
  19852. this.displacementMap = source.displacementMap;
  19853. this.displacementScale = source.displacementScale;
  19854. this.displacementBias = source.displacementBias;
  19855. this.roughnessMap = source.roughnessMap;
  19856. this.metalnessMap = source.metalnessMap;
  19857. this.alphaMap = source.alphaMap;
  19858. this.envMap = source.envMap;
  19859. this.envMapIntensity = source.envMapIntensity;
  19860. this.refractionRatio = source.refractionRatio;
  19861. this.wireframe = source.wireframe;
  19862. this.wireframeLinewidth = source.wireframeLinewidth;
  19863. this.wireframeLinecap = source.wireframeLinecap;
  19864. this.wireframeLinejoin = source.wireframeLinejoin;
  19865. this.skinning = source.skinning;
  19866. this.morphTargets = source.morphTargets;
  19867. this.morphNormals = source.morphNormals;
  19868. this.vertexTangents = source.vertexTangents;
  19869. return this;
  19870. };
  19871. /**
  19872. * parameters = {
  19873. * clearcoat: <float>,
  19874. * clearcoatMap: new THREE.Texture( <Image> ),
  19875. * clearcoatRoughness: <float>,
  19876. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19877. * clearcoatNormalScale: <Vector2>,
  19878. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19879. *
  19880. * reflectivity: <float>,
  19881. * ior: <float>,
  19882. *
  19883. * sheen: <Color>,
  19884. *
  19885. * transmission: <float>,
  19886. * transmissionMap: new THREE.Texture( <Image> )
  19887. * }
  19888. */
  19889. function MeshPhysicalMaterial(parameters) {
  19890. MeshStandardMaterial.call(this);
  19891. this.defines = {
  19892. 'STANDARD': '',
  19893. 'PHYSICAL': ''
  19894. };
  19895. this.type = 'MeshPhysicalMaterial';
  19896. this.clearcoat = 0.0;
  19897. this.clearcoatMap = null;
  19898. this.clearcoatRoughness = 0.0;
  19899. this.clearcoatRoughnessMap = null;
  19900. this.clearcoatNormalScale = new Vector2(1, 1);
  19901. this.clearcoatNormalMap = null;
  19902. this.reflectivity = 0.5; // maps to F0 = 0.04
  19903. Object.defineProperty(this, 'ior', {
  19904. get: function get() {
  19905. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19906. },
  19907. set: function set(ior) {
  19908. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19909. }
  19910. });
  19911. this.sheen = null; // null will disable sheen bsdf
  19912. this.transmission = 0.0;
  19913. this.transmissionMap = null;
  19914. this.setValues(parameters);
  19915. }
  19916. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19917. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19918. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19919. MeshPhysicalMaterial.prototype.copy = function (source) {
  19920. MeshStandardMaterial.prototype.copy.call(this, source);
  19921. this.defines = {
  19922. 'STANDARD': '',
  19923. 'PHYSICAL': ''
  19924. };
  19925. this.clearcoat = source.clearcoat;
  19926. this.clearcoatMap = source.clearcoatMap;
  19927. this.clearcoatRoughness = source.clearcoatRoughness;
  19928. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19929. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19930. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19931. this.reflectivity = source.reflectivity;
  19932. if (source.sheen) {
  19933. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19934. } else {
  19935. this.sheen = null;
  19936. }
  19937. this.transmission = source.transmission;
  19938. this.transmissionMap = source.transmissionMap;
  19939. return this;
  19940. };
  19941. /**
  19942. * parameters = {
  19943. * color: <hex>,
  19944. * specular: <hex>,
  19945. * shininess: <float>,
  19946. * opacity: <float>,
  19947. *
  19948. * map: new THREE.Texture( <Image> ),
  19949. *
  19950. * lightMap: new THREE.Texture( <Image> ),
  19951. * lightMapIntensity: <float>
  19952. *
  19953. * aoMap: new THREE.Texture( <Image> ),
  19954. * aoMapIntensity: <float>
  19955. *
  19956. * emissive: <hex>,
  19957. * emissiveIntensity: <float>
  19958. * emissiveMap: new THREE.Texture( <Image> ),
  19959. *
  19960. * bumpMap: new THREE.Texture( <Image> ),
  19961. * bumpScale: <float>,
  19962. *
  19963. * normalMap: new THREE.Texture( <Image> ),
  19964. * normalMapType: THREE.TangentSpaceNormalMap,
  19965. * normalScale: <Vector2>,
  19966. *
  19967. * displacementMap: new THREE.Texture( <Image> ),
  19968. * displacementScale: <float>,
  19969. * displacementBias: <float>,
  19970. *
  19971. * specularMap: new THREE.Texture( <Image> ),
  19972. *
  19973. * alphaMap: new THREE.Texture( <Image> ),
  19974. *
  19975. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19976. * combine: THREE.MultiplyOperation,
  19977. * reflectivity: <float>,
  19978. * refractionRatio: <float>,
  19979. *
  19980. * wireframe: <boolean>,
  19981. * wireframeLinewidth: <float>,
  19982. *
  19983. * skinning: <bool>,
  19984. * morphTargets: <bool>,
  19985. * morphNormals: <bool>
  19986. * }
  19987. */
  19988. function MeshPhongMaterial(parameters) {
  19989. Material.call(this);
  19990. this.type = 'MeshPhongMaterial';
  19991. this.color = new Color(0xffffff); // diffuse
  19992. this.specular = new Color(0x111111);
  19993. this.shininess = 30;
  19994. this.map = null;
  19995. this.lightMap = null;
  19996. this.lightMapIntensity = 1.0;
  19997. this.aoMap = null;
  19998. this.aoMapIntensity = 1.0;
  19999. this.emissive = new Color(0x000000);
  20000. this.emissiveIntensity = 1.0;
  20001. this.emissiveMap = null;
  20002. this.bumpMap = null;
  20003. this.bumpScale = 1;
  20004. this.normalMap = null;
  20005. this.normalMapType = TangentSpaceNormalMap;
  20006. this.normalScale = new Vector2(1, 1);
  20007. this.displacementMap = null;
  20008. this.displacementScale = 1;
  20009. this.displacementBias = 0;
  20010. this.specularMap = null;
  20011. this.alphaMap = null;
  20012. this.envMap = null;
  20013. this.combine = MultiplyOperation;
  20014. this.reflectivity = 1;
  20015. this.refractionRatio = 0.98;
  20016. this.wireframe = false;
  20017. this.wireframeLinewidth = 1;
  20018. this.wireframeLinecap = 'round';
  20019. this.wireframeLinejoin = 'round';
  20020. this.skinning = false;
  20021. this.morphTargets = false;
  20022. this.morphNormals = false;
  20023. this.setValues(parameters);
  20024. }
  20025. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  20026. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20027. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20028. MeshPhongMaterial.prototype.copy = function (source) {
  20029. Material.prototype.copy.call(this, source);
  20030. this.color.copy(source.color);
  20031. this.specular.copy(source.specular);
  20032. this.shininess = source.shininess;
  20033. this.map = source.map;
  20034. this.lightMap = source.lightMap;
  20035. this.lightMapIntensity = source.lightMapIntensity;
  20036. this.aoMap = source.aoMap;
  20037. this.aoMapIntensity = source.aoMapIntensity;
  20038. this.emissive.copy(source.emissive);
  20039. this.emissiveMap = source.emissiveMap;
  20040. this.emissiveIntensity = source.emissiveIntensity;
  20041. this.bumpMap = source.bumpMap;
  20042. this.bumpScale = source.bumpScale;
  20043. this.normalMap = source.normalMap;
  20044. this.normalMapType = source.normalMapType;
  20045. this.normalScale.copy(source.normalScale);
  20046. this.displacementMap = source.displacementMap;
  20047. this.displacementScale = source.displacementScale;
  20048. this.displacementBias = source.displacementBias;
  20049. this.specularMap = source.specularMap;
  20050. this.alphaMap = source.alphaMap;
  20051. this.envMap = source.envMap;
  20052. this.combine = source.combine;
  20053. this.reflectivity = source.reflectivity;
  20054. this.refractionRatio = source.refractionRatio;
  20055. this.wireframe = source.wireframe;
  20056. this.wireframeLinewidth = source.wireframeLinewidth;
  20057. this.wireframeLinecap = source.wireframeLinecap;
  20058. this.wireframeLinejoin = source.wireframeLinejoin;
  20059. this.skinning = source.skinning;
  20060. this.morphTargets = source.morphTargets;
  20061. this.morphNormals = source.morphNormals;
  20062. return this;
  20063. };
  20064. /**
  20065. * parameters = {
  20066. * color: <hex>,
  20067. *
  20068. * map: new THREE.Texture( <Image> ),
  20069. * gradientMap: new THREE.Texture( <Image> ),
  20070. *
  20071. * lightMap: new THREE.Texture( <Image> ),
  20072. * lightMapIntensity: <float>
  20073. *
  20074. * aoMap: new THREE.Texture( <Image> ),
  20075. * aoMapIntensity: <float>
  20076. *
  20077. * emissive: <hex>,
  20078. * emissiveIntensity: <float>
  20079. * emissiveMap: new THREE.Texture( <Image> ),
  20080. *
  20081. * bumpMap: new THREE.Texture( <Image> ),
  20082. * bumpScale: <float>,
  20083. *
  20084. * normalMap: new THREE.Texture( <Image> ),
  20085. * normalMapType: THREE.TangentSpaceNormalMap,
  20086. * normalScale: <Vector2>,
  20087. *
  20088. * displacementMap: new THREE.Texture( <Image> ),
  20089. * displacementScale: <float>,
  20090. * displacementBias: <float>,
  20091. *
  20092. * alphaMap: new THREE.Texture( <Image> ),
  20093. *
  20094. * wireframe: <boolean>,
  20095. * wireframeLinewidth: <float>,
  20096. *
  20097. * skinning: <bool>,
  20098. * morphTargets: <bool>,
  20099. * morphNormals: <bool>
  20100. * }
  20101. */
  20102. function MeshToonMaterial(parameters) {
  20103. Material.call(this);
  20104. this.defines = {
  20105. 'TOON': ''
  20106. };
  20107. this.type = 'MeshToonMaterial';
  20108. this.color = new Color(0xffffff);
  20109. this.map = null;
  20110. this.gradientMap = null;
  20111. this.lightMap = null;
  20112. this.lightMapIntensity = 1.0;
  20113. this.aoMap = null;
  20114. this.aoMapIntensity = 1.0;
  20115. this.emissive = new Color(0x000000);
  20116. this.emissiveIntensity = 1.0;
  20117. this.emissiveMap = null;
  20118. this.bumpMap = null;
  20119. this.bumpScale = 1;
  20120. this.normalMap = null;
  20121. this.normalMapType = TangentSpaceNormalMap;
  20122. this.normalScale = new Vector2(1, 1);
  20123. this.displacementMap = null;
  20124. this.displacementScale = 1;
  20125. this.displacementBias = 0;
  20126. this.alphaMap = null;
  20127. this.wireframe = false;
  20128. this.wireframeLinewidth = 1;
  20129. this.wireframeLinecap = 'round';
  20130. this.wireframeLinejoin = 'round';
  20131. this.skinning = false;
  20132. this.morphTargets = false;
  20133. this.morphNormals = false;
  20134. this.setValues(parameters);
  20135. }
  20136. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20137. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20138. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20139. MeshToonMaterial.prototype.copy = function (source) {
  20140. Material.prototype.copy.call(this, source);
  20141. this.color.copy(source.color);
  20142. this.map = source.map;
  20143. this.gradientMap = source.gradientMap;
  20144. this.lightMap = source.lightMap;
  20145. this.lightMapIntensity = source.lightMapIntensity;
  20146. this.aoMap = source.aoMap;
  20147. this.aoMapIntensity = source.aoMapIntensity;
  20148. this.emissive.copy(source.emissive);
  20149. this.emissiveMap = source.emissiveMap;
  20150. this.emissiveIntensity = source.emissiveIntensity;
  20151. this.bumpMap = source.bumpMap;
  20152. this.bumpScale = source.bumpScale;
  20153. this.normalMap = source.normalMap;
  20154. this.normalMapType = source.normalMapType;
  20155. this.normalScale.copy(source.normalScale);
  20156. this.displacementMap = source.displacementMap;
  20157. this.displacementScale = source.displacementScale;
  20158. this.displacementBias = source.displacementBias;
  20159. this.alphaMap = source.alphaMap;
  20160. this.wireframe = source.wireframe;
  20161. this.wireframeLinewidth = source.wireframeLinewidth;
  20162. this.wireframeLinecap = source.wireframeLinecap;
  20163. this.wireframeLinejoin = source.wireframeLinejoin;
  20164. this.skinning = source.skinning;
  20165. this.morphTargets = source.morphTargets;
  20166. this.morphNormals = source.morphNormals;
  20167. return this;
  20168. };
  20169. /**
  20170. * parameters = {
  20171. * opacity: <float>,
  20172. *
  20173. * bumpMap: new THREE.Texture( <Image> ),
  20174. * bumpScale: <float>,
  20175. *
  20176. * normalMap: new THREE.Texture( <Image> ),
  20177. * normalMapType: THREE.TangentSpaceNormalMap,
  20178. * normalScale: <Vector2>,
  20179. *
  20180. * displacementMap: new THREE.Texture( <Image> ),
  20181. * displacementScale: <float>,
  20182. * displacementBias: <float>,
  20183. *
  20184. * wireframe: <boolean>,
  20185. * wireframeLinewidth: <float>
  20186. *
  20187. * skinning: <bool>,
  20188. * morphTargets: <bool>,
  20189. * morphNormals: <bool>
  20190. * }
  20191. */
  20192. function MeshNormalMaterial(parameters) {
  20193. Material.call(this);
  20194. this.type = 'MeshNormalMaterial';
  20195. this.bumpMap = null;
  20196. this.bumpScale = 1;
  20197. this.normalMap = null;
  20198. this.normalMapType = TangentSpaceNormalMap;
  20199. this.normalScale = new Vector2(1, 1);
  20200. this.displacementMap = null;
  20201. this.displacementScale = 1;
  20202. this.displacementBias = 0;
  20203. this.wireframe = false;
  20204. this.wireframeLinewidth = 1;
  20205. this.fog = false;
  20206. this.skinning = false;
  20207. this.morphTargets = false;
  20208. this.morphNormals = false;
  20209. this.setValues(parameters);
  20210. }
  20211. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20212. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20213. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20214. MeshNormalMaterial.prototype.copy = function (source) {
  20215. Material.prototype.copy.call(this, source);
  20216. this.bumpMap = source.bumpMap;
  20217. this.bumpScale = source.bumpScale;
  20218. this.normalMap = source.normalMap;
  20219. this.normalMapType = source.normalMapType;
  20220. this.normalScale.copy(source.normalScale);
  20221. this.displacementMap = source.displacementMap;
  20222. this.displacementScale = source.displacementScale;
  20223. this.displacementBias = source.displacementBias;
  20224. this.wireframe = source.wireframe;
  20225. this.wireframeLinewidth = source.wireframeLinewidth;
  20226. this.skinning = source.skinning;
  20227. this.morphTargets = source.morphTargets;
  20228. this.morphNormals = source.morphNormals;
  20229. return this;
  20230. };
  20231. /**
  20232. * parameters = {
  20233. * color: <hex>,
  20234. * opacity: <float>,
  20235. *
  20236. * map: new THREE.Texture( <Image> ),
  20237. *
  20238. * lightMap: new THREE.Texture( <Image> ),
  20239. * lightMapIntensity: <float>
  20240. *
  20241. * aoMap: new THREE.Texture( <Image> ),
  20242. * aoMapIntensity: <float>
  20243. *
  20244. * emissive: <hex>,
  20245. * emissiveIntensity: <float>
  20246. * emissiveMap: new THREE.Texture( <Image> ),
  20247. *
  20248. * specularMap: new THREE.Texture( <Image> ),
  20249. *
  20250. * alphaMap: new THREE.Texture( <Image> ),
  20251. *
  20252. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20253. * combine: THREE.Multiply,
  20254. * reflectivity: <float>,
  20255. * refractionRatio: <float>,
  20256. *
  20257. * wireframe: <boolean>,
  20258. * wireframeLinewidth: <float>,
  20259. *
  20260. * skinning: <bool>,
  20261. * morphTargets: <bool>,
  20262. * morphNormals: <bool>
  20263. * }
  20264. */
  20265. function MeshLambertMaterial(parameters) {
  20266. Material.call(this);
  20267. this.type = 'MeshLambertMaterial';
  20268. this.color = new Color(0xffffff); // diffuse
  20269. this.map = null;
  20270. this.lightMap = null;
  20271. this.lightMapIntensity = 1.0;
  20272. this.aoMap = null;
  20273. this.aoMapIntensity = 1.0;
  20274. this.emissive = new Color(0x000000);
  20275. this.emissiveIntensity = 1.0;
  20276. this.emissiveMap = null;
  20277. this.specularMap = null;
  20278. this.alphaMap = null;
  20279. this.envMap = null;
  20280. this.combine = MultiplyOperation;
  20281. this.reflectivity = 1;
  20282. this.refractionRatio = 0.98;
  20283. this.wireframe = false;
  20284. this.wireframeLinewidth = 1;
  20285. this.wireframeLinecap = 'round';
  20286. this.wireframeLinejoin = 'round';
  20287. this.skinning = false;
  20288. this.morphTargets = false;
  20289. this.morphNormals = false;
  20290. this.setValues(parameters);
  20291. }
  20292. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20293. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20294. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20295. MeshLambertMaterial.prototype.copy = function (source) {
  20296. Material.prototype.copy.call(this, source);
  20297. this.color.copy(source.color);
  20298. this.map = source.map;
  20299. this.lightMap = source.lightMap;
  20300. this.lightMapIntensity = source.lightMapIntensity;
  20301. this.aoMap = source.aoMap;
  20302. this.aoMapIntensity = source.aoMapIntensity;
  20303. this.emissive.copy(source.emissive);
  20304. this.emissiveMap = source.emissiveMap;
  20305. this.emissiveIntensity = source.emissiveIntensity;
  20306. this.specularMap = source.specularMap;
  20307. this.alphaMap = source.alphaMap;
  20308. this.envMap = source.envMap;
  20309. this.combine = source.combine;
  20310. this.reflectivity = source.reflectivity;
  20311. this.refractionRatio = source.refractionRatio;
  20312. this.wireframe = source.wireframe;
  20313. this.wireframeLinewidth = source.wireframeLinewidth;
  20314. this.wireframeLinecap = source.wireframeLinecap;
  20315. this.wireframeLinejoin = source.wireframeLinejoin;
  20316. this.skinning = source.skinning;
  20317. this.morphTargets = source.morphTargets;
  20318. this.morphNormals = source.morphNormals;
  20319. return this;
  20320. };
  20321. /**
  20322. * parameters = {
  20323. * color: <hex>,
  20324. * opacity: <float>,
  20325. *
  20326. * matcap: new THREE.Texture( <Image> ),
  20327. *
  20328. * map: new THREE.Texture( <Image> ),
  20329. *
  20330. * bumpMap: new THREE.Texture( <Image> ),
  20331. * bumpScale: <float>,
  20332. *
  20333. * normalMap: new THREE.Texture( <Image> ),
  20334. * normalMapType: THREE.TangentSpaceNormalMap,
  20335. * normalScale: <Vector2>,
  20336. *
  20337. * displacementMap: new THREE.Texture( <Image> ),
  20338. * displacementScale: <float>,
  20339. * displacementBias: <float>,
  20340. *
  20341. * alphaMap: new THREE.Texture( <Image> ),
  20342. *
  20343. * skinning: <bool>,
  20344. * morphTargets: <bool>,
  20345. * morphNormals: <bool>
  20346. * }
  20347. */
  20348. function MeshMatcapMaterial(parameters) {
  20349. Material.call(this);
  20350. this.defines = {
  20351. 'MATCAP': ''
  20352. };
  20353. this.type = 'MeshMatcapMaterial';
  20354. this.color = new Color(0xffffff); // diffuse
  20355. this.matcap = null;
  20356. this.map = null;
  20357. this.bumpMap = null;
  20358. this.bumpScale = 1;
  20359. this.normalMap = null;
  20360. this.normalMapType = TangentSpaceNormalMap;
  20361. this.normalScale = new Vector2(1, 1);
  20362. this.displacementMap = null;
  20363. this.displacementScale = 1;
  20364. this.displacementBias = 0;
  20365. this.alphaMap = null;
  20366. this.skinning = false;
  20367. this.morphTargets = false;
  20368. this.morphNormals = false;
  20369. this.setValues(parameters);
  20370. }
  20371. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20372. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20373. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20374. MeshMatcapMaterial.prototype.copy = function (source) {
  20375. Material.prototype.copy.call(this, source);
  20376. this.defines = {
  20377. 'MATCAP': ''
  20378. };
  20379. this.color.copy(source.color);
  20380. this.matcap = source.matcap;
  20381. this.map = source.map;
  20382. this.bumpMap = source.bumpMap;
  20383. this.bumpScale = source.bumpScale;
  20384. this.normalMap = source.normalMap;
  20385. this.normalMapType = source.normalMapType;
  20386. this.normalScale.copy(source.normalScale);
  20387. this.displacementMap = source.displacementMap;
  20388. this.displacementScale = source.displacementScale;
  20389. this.displacementBias = source.displacementBias;
  20390. this.alphaMap = source.alphaMap;
  20391. this.skinning = source.skinning;
  20392. this.morphTargets = source.morphTargets;
  20393. this.morphNormals = source.morphNormals;
  20394. return this;
  20395. };
  20396. /**
  20397. * parameters = {
  20398. * color: <hex>,
  20399. * opacity: <float>,
  20400. *
  20401. * linewidth: <float>,
  20402. *
  20403. * scale: <float>,
  20404. * dashSize: <float>,
  20405. * gapSize: <float>
  20406. * }
  20407. */
  20408. function LineDashedMaterial(parameters) {
  20409. LineBasicMaterial.call(this);
  20410. this.type = 'LineDashedMaterial';
  20411. this.scale = 1;
  20412. this.dashSize = 3;
  20413. this.gapSize = 1;
  20414. this.setValues(parameters);
  20415. }
  20416. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20417. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20418. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20419. LineDashedMaterial.prototype.copy = function (source) {
  20420. LineBasicMaterial.prototype.copy.call(this, source);
  20421. this.scale = source.scale;
  20422. this.dashSize = source.dashSize;
  20423. this.gapSize = source.gapSize;
  20424. return this;
  20425. };
  20426. var Materials = /*#__PURE__*/Object.freeze({
  20427. __proto__: null,
  20428. ShadowMaterial: ShadowMaterial,
  20429. SpriteMaterial: SpriteMaterial,
  20430. RawShaderMaterial: RawShaderMaterial,
  20431. ShaderMaterial: ShaderMaterial,
  20432. PointsMaterial: PointsMaterial,
  20433. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20434. MeshStandardMaterial: MeshStandardMaterial,
  20435. MeshPhongMaterial: MeshPhongMaterial,
  20436. MeshToonMaterial: MeshToonMaterial,
  20437. MeshNormalMaterial: MeshNormalMaterial,
  20438. MeshLambertMaterial: MeshLambertMaterial,
  20439. MeshDepthMaterial: MeshDepthMaterial,
  20440. MeshDistanceMaterial: MeshDistanceMaterial,
  20441. MeshBasicMaterial: MeshBasicMaterial,
  20442. MeshMatcapMaterial: MeshMatcapMaterial,
  20443. LineDashedMaterial: LineDashedMaterial,
  20444. LineBasicMaterial: LineBasicMaterial,
  20445. Material: Material
  20446. });
  20447. var AnimationUtils = {
  20448. // same as Array.prototype.slice, but also works on typed arrays
  20449. arraySlice: function arraySlice(array, from, to) {
  20450. if (AnimationUtils.isTypedArray(array)) {
  20451. // in ios9 array.subarray(from, undefined) will return empty array
  20452. // but array.subarray(from) or array.subarray(from, len) is correct
  20453. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20454. }
  20455. return array.slice(from, to);
  20456. },
  20457. // converts an array to a specific type
  20458. convertArray: function convertArray(array, type, forceClone) {
  20459. if (!array || // let 'undefined' and 'null' pass
  20460. !forceClone && array.constructor === type) return array;
  20461. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20462. return new type(array); // create typed array
  20463. }
  20464. return Array.prototype.slice.call(array); // create Array
  20465. },
  20466. isTypedArray: function isTypedArray(object) {
  20467. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20468. },
  20469. // returns an array by which times and values can be sorted
  20470. getKeyframeOrder: function getKeyframeOrder(times) {
  20471. function compareTime(i, j) {
  20472. return times[i] - times[j];
  20473. }
  20474. var n = times.length;
  20475. var result = new Array(n);
  20476. for (var i = 0; i !== n; ++i) {
  20477. result[i] = i;
  20478. }
  20479. result.sort(compareTime);
  20480. return result;
  20481. },
  20482. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20483. sortedArray: function sortedArray(values, stride, order) {
  20484. var nValues = values.length;
  20485. var result = new values.constructor(nValues);
  20486. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20487. var srcOffset = order[i] * stride;
  20488. for (var j = 0; j !== stride; ++j) {
  20489. result[dstOffset++] = values[srcOffset + j];
  20490. }
  20491. }
  20492. return result;
  20493. },
  20494. // function for parsing AOS keyframe formats
  20495. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20496. var i = 1,
  20497. key = jsonKeys[0];
  20498. while (key !== undefined && key[valuePropertyName] === undefined) {
  20499. key = jsonKeys[i++];
  20500. }
  20501. if (key === undefined) return; // no data
  20502. var value = key[valuePropertyName];
  20503. if (value === undefined) return; // no data
  20504. if (Array.isArray(value)) {
  20505. do {
  20506. value = key[valuePropertyName];
  20507. if (value !== undefined) {
  20508. times.push(key.time);
  20509. values.push.apply(values, value); // push all elements
  20510. }
  20511. key = jsonKeys[i++];
  20512. } while (key !== undefined);
  20513. } else if (value.toArray !== undefined) {
  20514. // ...assume THREE.Math-ish
  20515. do {
  20516. value = key[valuePropertyName];
  20517. if (value !== undefined) {
  20518. times.push(key.time);
  20519. value.toArray(values, values.length);
  20520. }
  20521. key = jsonKeys[i++];
  20522. } while (key !== undefined);
  20523. } else {
  20524. // otherwise push as-is
  20525. do {
  20526. value = key[valuePropertyName];
  20527. if (value !== undefined) {
  20528. times.push(key.time);
  20529. values.push(value);
  20530. }
  20531. key = jsonKeys[i++];
  20532. } while (key !== undefined);
  20533. }
  20534. },
  20535. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20536. fps = fps || 30;
  20537. var clip = sourceClip.clone();
  20538. clip.name = name;
  20539. var tracks = [];
  20540. for (var i = 0; i < clip.tracks.length; ++i) {
  20541. var track = clip.tracks[i];
  20542. var valueSize = track.getValueSize();
  20543. var times = [];
  20544. var values = [];
  20545. for (var j = 0; j < track.times.length; ++j) {
  20546. var frame = track.times[j] * fps;
  20547. if (frame < startFrame || frame >= endFrame) continue;
  20548. times.push(track.times[j]);
  20549. for (var k = 0; k < valueSize; ++k) {
  20550. values.push(track.values[j * valueSize + k]);
  20551. }
  20552. }
  20553. if (times.length === 0) continue;
  20554. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20555. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20556. tracks.push(track);
  20557. }
  20558. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20559. var minStartTime = Infinity;
  20560. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20561. if (minStartTime > clip.tracks[_i].times[0]) {
  20562. minStartTime = clip.tracks[_i].times[0];
  20563. }
  20564. } // shift all tracks such that clip begins at t=0
  20565. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20566. clip.tracks[_i2].shift(-1 * minStartTime);
  20567. }
  20568. clip.resetDuration();
  20569. return clip;
  20570. },
  20571. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20572. if (referenceFrame === undefined) referenceFrame = 0;
  20573. if (referenceClip === undefined) referenceClip = targetClip;
  20574. if (fps === undefined || fps <= 0) fps = 30;
  20575. var numTracks = referenceClip.tracks.length;
  20576. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20577. var _loop = function _loop(i) {
  20578. var referenceTrack = referenceClip.tracks[i];
  20579. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20580. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20581. var targetTrack = targetClip.tracks.find(function (track) {
  20582. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20583. });
  20584. if (targetTrack === undefined) return "continue";
  20585. var referenceOffset = 0;
  20586. var referenceValueSize = referenceTrack.getValueSize();
  20587. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20588. referenceOffset = referenceValueSize / 3;
  20589. }
  20590. var targetOffset = 0;
  20591. var targetValueSize = targetTrack.getValueSize();
  20592. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20593. targetOffset = targetValueSize / 3;
  20594. }
  20595. var lastIndex = referenceTrack.times.length - 1;
  20596. var referenceValue = void 0; // Find the value to subtract out of the track
  20597. if (referenceTime <= referenceTrack.times[0]) {
  20598. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20599. var startIndex = referenceOffset;
  20600. var endIndex = referenceValueSize - referenceOffset;
  20601. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20602. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20603. // Reference frame is after the last keyframe, so just use the last keyframe
  20604. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20605. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20606. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20607. } else {
  20608. // Interpolate to the reference value
  20609. var interpolant = referenceTrack.createInterpolant();
  20610. var _startIndex2 = referenceOffset;
  20611. var _endIndex2 = referenceValueSize - referenceOffset;
  20612. interpolant.evaluate(referenceTime);
  20613. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20614. } // Conjugate the quaternion
  20615. if (referenceTrackType === 'quaternion') {
  20616. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20617. referenceQuat.toArray(referenceValue);
  20618. } // Subtract the reference value from all of the track values
  20619. var numTimes = targetTrack.times.length;
  20620. for (var j = 0; j < numTimes; ++j) {
  20621. var valueStart = j * targetValueSize + targetOffset;
  20622. if (referenceTrackType === 'quaternion') {
  20623. // Multiply the conjugate for quaternion track types
  20624. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20625. } else {
  20626. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20627. for (var k = 0; k < valueEnd; ++k) {
  20628. targetTrack.values[valueStart + k] -= referenceValue[k];
  20629. }
  20630. }
  20631. }
  20632. };
  20633. for (var i = 0; i < numTracks; ++i) {
  20634. var _ret = _loop(i);
  20635. if (_ret === "continue") continue;
  20636. }
  20637. targetClip.blendMode = AdditiveAnimationBlendMode;
  20638. return targetClip;
  20639. }
  20640. };
  20641. /**
  20642. * Abstract base class of interpolants over parametric samples.
  20643. *
  20644. * The parameter domain is one dimensional, typically the time or a path
  20645. * along a curve defined by the data.
  20646. *
  20647. * The sample values can have any dimensionality and derived classes may
  20648. * apply special interpretations to the data.
  20649. *
  20650. * This class provides the interval seek in a Template Method, deferring
  20651. * the actual interpolation to derived classes.
  20652. *
  20653. * Time complexity is O(1) for linear access crossing at most two points
  20654. * and O(log N) for random access, where N is the number of positions.
  20655. *
  20656. * References:
  20657. *
  20658. * http://www.oodesign.com/template-method-pattern.html
  20659. *
  20660. */
  20661. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20662. this.parameterPositions = parameterPositions;
  20663. this._cachedIndex = 0;
  20664. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20665. this.sampleValues = sampleValues;
  20666. this.valueSize = sampleSize;
  20667. }
  20668. Object.assign(Interpolant.prototype, {
  20669. evaluate: function evaluate(t) {
  20670. var pp = this.parameterPositions;
  20671. var i1 = this._cachedIndex,
  20672. t1 = pp[i1],
  20673. t0 = pp[i1 - 1];
  20674. validate_interval: {
  20675. seek: {
  20676. var right;
  20677. linear_scan: {
  20678. //- See http://jsperf.com/comparison-to-undefined/3
  20679. //- slower code:
  20680. //-
  20681. //- if ( t >= t1 || t1 === undefined ) {
  20682. forward_scan: if (!(t < t1)) {
  20683. for (var giveUpAt = i1 + 2;;) {
  20684. if (t1 === undefined) {
  20685. if (t < t0) break forward_scan; // after end
  20686. i1 = pp.length;
  20687. this._cachedIndex = i1;
  20688. return this.afterEnd_(i1 - 1, t, t0);
  20689. }
  20690. if (i1 === giveUpAt) break; // this loop
  20691. t0 = t1;
  20692. t1 = pp[++i1];
  20693. if (t < t1) {
  20694. // we have arrived at the sought interval
  20695. break seek;
  20696. }
  20697. } // prepare binary search on the right side of the index
  20698. right = pp.length;
  20699. break linear_scan;
  20700. } //- slower code:
  20701. //- if ( t < t0 || t0 === undefined ) {
  20702. if (!(t >= t0)) {
  20703. // looping?
  20704. var t1global = pp[1];
  20705. if (t < t1global) {
  20706. i1 = 2; // + 1, using the scan for the details
  20707. t0 = t1global;
  20708. } // linear reverse scan
  20709. for (var _giveUpAt = i1 - 2;;) {
  20710. if (t0 === undefined) {
  20711. // before start
  20712. this._cachedIndex = 0;
  20713. return this.beforeStart_(0, t, t1);
  20714. }
  20715. if (i1 === _giveUpAt) break; // this loop
  20716. t1 = t0;
  20717. t0 = pp[--i1 - 1];
  20718. if (t >= t0) {
  20719. // we have arrived at the sought interval
  20720. break seek;
  20721. }
  20722. } // prepare binary search on the left side of the index
  20723. right = i1;
  20724. i1 = 0;
  20725. break linear_scan;
  20726. } // the interval is valid
  20727. break validate_interval;
  20728. } // linear scan
  20729. // binary search
  20730. while (i1 < right) {
  20731. var mid = i1 + right >>> 1;
  20732. if (t < pp[mid]) {
  20733. right = mid;
  20734. } else {
  20735. i1 = mid + 1;
  20736. }
  20737. }
  20738. t1 = pp[i1];
  20739. t0 = pp[i1 - 1]; // check boundary cases, again
  20740. if (t0 === undefined) {
  20741. this._cachedIndex = 0;
  20742. return this.beforeStart_(0, t, t1);
  20743. }
  20744. if (t1 === undefined) {
  20745. i1 = pp.length;
  20746. this._cachedIndex = i1;
  20747. return this.afterEnd_(i1 - 1, t0, t);
  20748. }
  20749. } // seek
  20750. this._cachedIndex = i1;
  20751. this.intervalChanged_(i1, t0, t1);
  20752. } // validate_interval
  20753. return this.interpolate_(i1, t0, t, t1);
  20754. },
  20755. settings: null,
  20756. // optional, subclass-specific settings structure
  20757. // Note: The indirection allows central control of many interpolants.
  20758. // --- Protected interface
  20759. DefaultSettings_: {},
  20760. getSettings_: function getSettings_() {
  20761. return this.settings || this.DefaultSettings_;
  20762. },
  20763. copySampleValue_: function copySampleValue_(index) {
  20764. // copies a sample value to the result buffer
  20765. var result = this.resultBuffer,
  20766. values = this.sampleValues,
  20767. stride = this.valueSize,
  20768. offset = index * stride;
  20769. for (var i = 0; i !== stride; ++i) {
  20770. result[i] = values[offset + i];
  20771. }
  20772. return result;
  20773. },
  20774. // Template methods for derived classes:
  20775. interpolate_: function interpolate_()
  20776. /* i1, t0, t, t1 */
  20777. {
  20778. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20779. },
  20780. intervalChanged_: function intervalChanged_()
  20781. /* i1, t0, t1 */
  20782. {// empty
  20783. }
  20784. }); // DECLARE ALIAS AFTER assign prototype
  20785. Object.assign(Interpolant.prototype, {
  20786. //( 0, t, t0 ), returns this.resultBuffer
  20787. beforeStart_: Interpolant.prototype.copySampleValue_,
  20788. //( N-1, tN-1, t ), returns this.resultBuffer
  20789. afterEnd_: Interpolant.prototype.copySampleValue_
  20790. });
  20791. /**
  20792. * Fast and simple cubic spline interpolant.
  20793. *
  20794. * It was derived from a Hermitian construction setting the first derivative
  20795. * at each sample position to the linear slope between neighboring positions
  20796. * over their parameter interval.
  20797. */
  20798. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20799. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20800. this._weightPrev = -0;
  20801. this._offsetPrev = -0;
  20802. this._weightNext = -0;
  20803. this._offsetNext = -0;
  20804. }
  20805. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20806. constructor: CubicInterpolant,
  20807. DefaultSettings_: {
  20808. endingStart: ZeroCurvatureEnding,
  20809. endingEnd: ZeroCurvatureEnding
  20810. },
  20811. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20812. var pp = this.parameterPositions;
  20813. var iPrev = i1 - 2,
  20814. iNext = i1 + 1,
  20815. tPrev = pp[iPrev],
  20816. tNext = pp[iNext];
  20817. if (tPrev === undefined) {
  20818. switch (this.getSettings_().endingStart) {
  20819. case ZeroSlopeEnding:
  20820. // f'(t0) = 0
  20821. iPrev = i1;
  20822. tPrev = 2 * t0 - t1;
  20823. break;
  20824. case WrapAroundEnding:
  20825. // use the other end of the curve
  20826. iPrev = pp.length - 2;
  20827. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20828. break;
  20829. default:
  20830. // ZeroCurvatureEnding
  20831. // f''(t0) = 0 a.k.a. Natural Spline
  20832. iPrev = i1;
  20833. tPrev = t1;
  20834. }
  20835. }
  20836. if (tNext === undefined) {
  20837. switch (this.getSettings_().endingEnd) {
  20838. case ZeroSlopeEnding:
  20839. // f'(tN) = 0
  20840. iNext = i1;
  20841. tNext = 2 * t1 - t0;
  20842. break;
  20843. case WrapAroundEnding:
  20844. // use the other end of the curve
  20845. iNext = 1;
  20846. tNext = t1 + pp[1] - pp[0];
  20847. break;
  20848. default:
  20849. // ZeroCurvatureEnding
  20850. // f''(tN) = 0, a.k.a. Natural Spline
  20851. iNext = i1 - 1;
  20852. tNext = t0;
  20853. }
  20854. }
  20855. var halfDt = (t1 - t0) * 0.5,
  20856. stride = this.valueSize;
  20857. this._weightPrev = halfDt / (t0 - tPrev);
  20858. this._weightNext = halfDt / (tNext - t1);
  20859. this._offsetPrev = iPrev * stride;
  20860. this._offsetNext = iNext * stride;
  20861. },
  20862. interpolate_: function interpolate_(i1, t0, t, t1) {
  20863. var result = this.resultBuffer,
  20864. values = this.sampleValues,
  20865. stride = this.valueSize,
  20866. o1 = i1 * stride,
  20867. o0 = o1 - stride,
  20868. oP = this._offsetPrev,
  20869. oN = this._offsetNext,
  20870. wP = this._weightPrev,
  20871. wN = this._weightNext,
  20872. p = (t - t0) / (t1 - t0),
  20873. pp = p * p,
  20874. ppp = pp * p; // evaluate polynomials
  20875. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20876. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20877. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20878. var sN = wN * ppp - wN * pp; // combine data linearly
  20879. for (var i = 0; i !== stride; ++i) {
  20880. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20881. }
  20882. return result;
  20883. }
  20884. });
  20885. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20886. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20887. }
  20888. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20889. constructor: LinearInterpolant,
  20890. interpolate_: function interpolate_(i1, t0, t, t1) {
  20891. var result = this.resultBuffer,
  20892. values = this.sampleValues,
  20893. stride = this.valueSize,
  20894. offset1 = i1 * stride,
  20895. offset0 = offset1 - stride,
  20896. weight1 = (t - t0) / (t1 - t0),
  20897. weight0 = 1 - weight1;
  20898. for (var i = 0; i !== stride; ++i) {
  20899. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20900. }
  20901. return result;
  20902. }
  20903. });
  20904. /**
  20905. *
  20906. * Interpolant that evaluates to the sample value at the position preceeding
  20907. * the parameter.
  20908. */
  20909. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20910. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20911. }
  20912. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20913. constructor: DiscreteInterpolant,
  20914. interpolate_: function interpolate_(i1
  20915. /*, t0, t, t1 */
  20916. ) {
  20917. return this.copySampleValue_(i1 - 1);
  20918. }
  20919. });
  20920. function KeyframeTrack(name, times, values, interpolation) {
  20921. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20922. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20923. this.name = name;
  20924. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20925. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20926. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20927. } // Static methods
  20928. Object.assign(KeyframeTrack, {
  20929. // Serialization (in static context, because of constructor invocation
  20930. // and automatic invocation of .toJSON):
  20931. toJSON: function toJSON(track) {
  20932. var trackType = track.constructor;
  20933. var json; // derived classes can define a static toJSON method
  20934. if (trackType.toJSON !== undefined) {
  20935. json = trackType.toJSON(track);
  20936. } else {
  20937. // by default, we assume the data can be serialized as-is
  20938. json = {
  20939. 'name': track.name,
  20940. 'times': AnimationUtils.convertArray(track.times, Array),
  20941. 'values': AnimationUtils.convertArray(track.values, Array)
  20942. };
  20943. var interpolation = track.getInterpolation();
  20944. if (interpolation !== track.DefaultInterpolation) {
  20945. json.interpolation = interpolation;
  20946. }
  20947. }
  20948. json.type = track.ValueTypeName; // mandatory
  20949. return json;
  20950. }
  20951. });
  20952. Object.assign(KeyframeTrack.prototype, {
  20953. constructor: KeyframeTrack,
  20954. TimeBufferType: Float32Array,
  20955. ValueBufferType: Float32Array,
  20956. DefaultInterpolation: InterpolateLinear,
  20957. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20958. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20959. },
  20960. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20961. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20962. },
  20963. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20964. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20965. },
  20966. setInterpolation: function setInterpolation(interpolation) {
  20967. var factoryMethod;
  20968. switch (interpolation) {
  20969. case InterpolateDiscrete:
  20970. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20971. break;
  20972. case InterpolateLinear:
  20973. factoryMethod = this.InterpolantFactoryMethodLinear;
  20974. break;
  20975. case InterpolateSmooth:
  20976. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20977. break;
  20978. }
  20979. if (factoryMethod === undefined) {
  20980. var message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
  20981. if (this.createInterpolant === undefined) {
  20982. // fall back to default, unless the default itself is messed up
  20983. if (interpolation !== this.DefaultInterpolation) {
  20984. this.setInterpolation(this.DefaultInterpolation);
  20985. } else {
  20986. throw new Error(message); // fatal, in this case
  20987. }
  20988. }
  20989. console.warn('THREE.KeyframeTrack:', message);
  20990. return this;
  20991. }
  20992. this.createInterpolant = factoryMethod;
  20993. return this;
  20994. },
  20995. getInterpolation: function getInterpolation() {
  20996. switch (this.createInterpolant) {
  20997. case this.InterpolantFactoryMethodDiscrete:
  20998. return InterpolateDiscrete;
  20999. case this.InterpolantFactoryMethodLinear:
  21000. return InterpolateLinear;
  21001. case this.InterpolantFactoryMethodSmooth:
  21002. return InterpolateSmooth;
  21003. }
  21004. },
  21005. getValueSize: function getValueSize() {
  21006. return this.values.length / this.times.length;
  21007. },
  21008. // move all keyframes either forwards or backwards in time
  21009. shift: function shift(timeOffset) {
  21010. if (timeOffset !== 0.0) {
  21011. var times = this.times;
  21012. for (var i = 0, n = times.length; i !== n; ++i) {
  21013. times[i] += timeOffset;
  21014. }
  21015. }
  21016. return this;
  21017. },
  21018. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21019. scale: function scale(timeScale) {
  21020. if (timeScale !== 1.0) {
  21021. var times = this.times;
  21022. for (var i = 0, n = times.length; i !== n; ++i) {
  21023. times[i] *= timeScale;
  21024. }
  21025. }
  21026. return this;
  21027. },
  21028. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21029. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21030. trim: function trim(startTime, endTime) {
  21031. var times = this.times,
  21032. nKeys = times.length;
  21033. var from = 0,
  21034. to = nKeys - 1;
  21035. while (from !== nKeys && times[from] < startTime) {
  21036. ++from;
  21037. }
  21038. while (to !== -1 && times[to] > endTime) {
  21039. --to;
  21040. }
  21041. ++to; // inclusive -> exclusive bound
  21042. if (from !== 0 || to !== nKeys) {
  21043. // empty tracks are forbidden, so keep at least one keyframe
  21044. if (from >= to) {
  21045. to = Math.max(to, 1);
  21046. from = to - 1;
  21047. }
  21048. var stride = this.getValueSize();
  21049. this.times = AnimationUtils.arraySlice(times, from, to);
  21050. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21051. }
  21052. return this;
  21053. },
  21054. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21055. validate: function validate() {
  21056. var valid = true;
  21057. var valueSize = this.getValueSize();
  21058. if (valueSize - Math.floor(valueSize) !== 0) {
  21059. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21060. valid = false;
  21061. }
  21062. var times = this.times,
  21063. values = this.values,
  21064. nKeys = times.length;
  21065. if (nKeys === 0) {
  21066. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21067. valid = false;
  21068. }
  21069. var prevTime = null;
  21070. for (var i = 0; i !== nKeys; i++) {
  21071. var currTime = times[i];
  21072. if (typeof currTime === 'number' && isNaN(currTime)) {
  21073. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21074. valid = false;
  21075. break;
  21076. }
  21077. if (prevTime !== null && prevTime > currTime) {
  21078. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21079. valid = false;
  21080. break;
  21081. }
  21082. prevTime = currTime;
  21083. }
  21084. if (values !== undefined) {
  21085. if (AnimationUtils.isTypedArray(values)) {
  21086. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21087. var value = values[_i];
  21088. if (isNaN(value)) {
  21089. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21090. valid = false;
  21091. break;
  21092. }
  21093. }
  21094. }
  21095. }
  21096. return valid;
  21097. },
  21098. // removes equivalent sequential keys as common in morph target sequences
  21099. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21100. optimize: function optimize() {
  21101. // times or values may be shared with other tracks, so overwriting is unsafe
  21102. var times = AnimationUtils.arraySlice(this.times),
  21103. values = AnimationUtils.arraySlice(this.values),
  21104. stride = this.getValueSize(),
  21105. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21106. lastIndex = times.length - 1;
  21107. var writeIndex = 1;
  21108. for (var i = 1; i < lastIndex; ++i) {
  21109. var keep = false;
  21110. var time = times[i];
  21111. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21112. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21113. if (!smoothInterpolation) {
  21114. // remove unnecessary keyframes same as their neighbors
  21115. var offset = i * stride,
  21116. offsetP = offset - stride,
  21117. offsetN = offset + stride;
  21118. for (var j = 0; j !== stride; ++j) {
  21119. var value = values[offset + j];
  21120. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21121. keep = true;
  21122. break;
  21123. }
  21124. }
  21125. } else {
  21126. keep = true;
  21127. }
  21128. } // in-place compaction
  21129. if (keep) {
  21130. if (i !== writeIndex) {
  21131. times[writeIndex] = times[i];
  21132. var readOffset = i * stride,
  21133. writeOffset = writeIndex * stride;
  21134. for (var _j = 0; _j !== stride; ++_j) {
  21135. values[writeOffset + _j] = values[readOffset + _j];
  21136. }
  21137. }
  21138. ++writeIndex;
  21139. }
  21140. } // flush last keyframe (compaction looks ahead)
  21141. if (lastIndex > 0) {
  21142. times[writeIndex] = times[lastIndex];
  21143. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21144. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21145. }
  21146. ++writeIndex;
  21147. }
  21148. if (writeIndex !== times.length) {
  21149. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21150. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21151. } else {
  21152. this.times = times;
  21153. this.values = values;
  21154. }
  21155. return this;
  21156. },
  21157. clone: function clone() {
  21158. var times = AnimationUtils.arraySlice(this.times, 0);
  21159. var values = AnimationUtils.arraySlice(this.values, 0);
  21160. var TypedKeyframeTrack = this.constructor;
  21161. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21162. track.createInterpolant = this.createInterpolant;
  21163. return track;
  21164. }
  21165. });
  21166. /**
  21167. * A Track of Boolean keyframe values.
  21168. */
  21169. function BooleanKeyframeTrack(name, times, values) {
  21170. KeyframeTrack.call(this, name, times, values);
  21171. }
  21172. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21173. constructor: BooleanKeyframeTrack,
  21174. ValueTypeName: 'bool',
  21175. ValueBufferType: Array,
  21176. DefaultInterpolation: InterpolateDiscrete,
  21177. InterpolantFactoryMethodLinear: undefined,
  21178. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21179. // representation of a single value and a custom interpolant that
  21180. // computes "firstValue ^ isOdd( index )".
  21181. });
  21182. /**
  21183. * A Track of keyframe values that represent color.
  21184. */
  21185. function ColorKeyframeTrack(name, times, values, interpolation) {
  21186. KeyframeTrack.call(this, name, times, values, interpolation);
  21187. }
  21188. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21189. constructor: ColorKeyframeTrack,
  21190. ValueTypeName: 'color' // ValueBufferType is inherited
  21191. // DefaultInterpolation is inherited
  21192. // Note: Very basic implementation and nothing special yet.
  21193. // However, this is the place for color space parameterization.
  21194. });
  21195. /**
  21196. * A Track of numeric keyframe values.
  21197. */
  21198. function NumberKeyframeTrack(name, times, values, interpolation) {
  21199. KeyframeTrack.call(this, name, times, values, interpolation);
  21200. }
  21201. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21202. constructor: NumberKeyframeTrack,
  21203. ValueTypeName: 'number' // ValueBufferType is inherited
  21204. // DefaultInterpolation is inherited
  21205. });
  21206. /**
  21207. * Spherical linear unit quaternion interpolant.
  21208. */
  21209. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21210. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21211. }
  21212. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21213. constructor: QuaternionLinearInterpolant,
  21214. interpolate_: function interpolate_(i1, t0, t, t1) {
  21215. var result = this.resultBuffer,
  21216. values = this.sampleValues,
  21217. stride = this.valueSize,
  21218. alpha = (t - t0) / (t1 - t0);
  21219. var offset = i1 * stride;
  21220. for (var end = offset + stride; offset !== end; offset += 4) {
  21221. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21222. }
  21223. return result;
  21224. }
  21225. });
  21226. /**
  21227. * A Track of quaternion keyframe values.
  21228. */
  21229. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21230. KeyframeTrack.call(this, name, times, values, interpolation);
  21231. }
  21232. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21233. constructor: QuaternionKeyframeTrack,
  21234. ValueTypeName: 'quaternion',
  21235. // ValueBufferType is inherited
  21236. DefaultInterpolation: InterpolateLinear,
  21237. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21238. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21239. },
  21240. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21241. });
  21242. /**
  21243. * A Track that interpolates Strings
  21244. */
  21245. function StringKeyframeTrack(name, times, values, interpolation) {
  21246. KeyframeTrack.call(this, name, times, values, interpolation);
  21247. }
  21248. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21249. constructor: StringKeyframeTrack,
  21250. ValueTypeName: 'string',
  21251. ValueBufferType: Array,
  21252. DefaultInterpolation: InterpolateDiscrete,
  21253. InterpolantFactoryMethodLinear: undefined,
  21254. InterpolantFactoryMethodSmooth: undefined
  21255. });
  21256. /**
  21257. * A Track of vectored keyframe values.
  21258. */
  21259. function VectorKeyframeTrack(name, times, values, interpolation) {
  21260. KeyframeTrack.call(this, name, times, values, interpolation);
  21261. }
  21262. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21263. constructor: VectorKeyframeTrack,
  21264. ValueTypeName: 'vector' // ValueBufferType is inherited
  21265. // DefaultInterpolation is inherited
  21266. });
  21267. function AnimationClip(name, duration, tracks, blendMode) {
  21268. this.name = name;
  21269. this.tracks = tracks;
  21270. this.duration = duration !== undefined ? duration : -1;
  21271. this.blendMode = blendMode !== undefined ? blendMode : NormalAnimationBlendMode;
  21272. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21273. if (this.duration < 0) {
  21274. this.resetDuration();
  21275. }
  21276. }
  21277. function getTrackTypeForValueTypeName(typeName) {
  21278. switch (typeName.toLowerCase()) {
  21279. case 'scalar':
  21280. case 'double':
  21281. case 'float':
  21282. case 'number':
  21283. case 'integer':
  21284. return NumberKeyframeTrack;
  21285. case 'vector':
  21286. case 'vector2':
  21287. case 'vector3':
  21288. case 'vector4':
  21289. return VectorKeyframeTrack;
  21290. case 'color':
  21291. return ColorKeyframeTrack;
  21292. case 'quaternion':
  21293. return QuaternionKeyframeTrack;
  21294. case 'bool':
  21295. case 'boolean':
  21296. return BooleanKeyframeTrack;
  21297. case 'string':
  21298. return StringKeyframeTrack;
  21299. }
  21300. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21301. }
  21302. function parseKeyframeTrack(json) {
  21303. if (json.type === undefined) {
  21304. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21305. }
  21306. var trackType = getTrackTypeForValueTypeName(json.type);
  21307. if (json.times === undefined) {
  21308. var times = [],
  21309. values = [];
  21310. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21311. json.times = times;
  21312. json.values = values;
  21313. } // derived classes can define a static parse method
  21314. if (trackType.parse !== undefined) {
  21315. return trackType.parse(json);
  21316. } else {
  21317. // by default, we assume a constructor compatible with the base
  21318. return new trackType(json.name, json.times, json.values, json.interpolation);
  21319. }
  21320. }
  21321. Object.assign(AnimationClip, {
  21322. parse: function parse(json) {
  21323. var tracks = [],
  21324. jsonTracks = json.tracks,
  21325. frameTime = 1.0 / (json.fps || 1.0);
  21326. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21327. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21328. }
  21329. return new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21330. },
  21331. toJSON: function toJSON(clip) {
  21332. var tracks = [],
  21333. clipTracks = clip.tracks;
  21334. var json = {
  21335. 'name': clip.name,
  21336. 'duration': clip.duration,
  21337. 'tracks': tracks,
  21338. 'uuid': clip.uuid,
  21339. 'blendMode': clip.blendMode
  21340. };
  21341. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21342. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21343. }
  21344. return json;
  21345. },
  21346. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21347. var numMorphTargets = morphTargetSequence.length;
  21348. var tracks = [];
  21349. for (var i = 0; i < numMorphTargets; i++) {
  21350. var times = [];
  21351. var values = [];
  21352. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21353. values.push(0, 1, 0);
  21354. var order = AnimationUtils.getKeyframeOrder(times);
  21355. times = AnimationUtils.sortedArray(times, 1, order);
  21356. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21357. // last frame as well for perfect loop.
  21358. if (!noLoop && times[0] === 0) {
  21359. times.push(numMorphTargets);
  21360. values.push(values[0]);
  21361. }
  21362. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21363. }
  21364. return new AnimationClip(name, -1, tracks);
  21365. },
  21366. findByName: function findByName(objectOrClipArray, name) {
  21367. var clipArray = objectOrClipArray;
  21368. if (!Array.isArray(objectOrClipArray)) {
  21369. var o = objectOrClipArray;
  21370. clipArray = o.geometry && o.geometry.animations || o.animations;
  21371. }
  21372. for (var i = 0; i < clipArray.length; i++) {
  21373. if (clipArray[i].name === name) {
  21374. return clipArray[i];
  21375. }
  21376. }
  21377. return null;
  21378. },
  21379. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21380. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21381. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21382. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21383. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21384. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21385. var morphTarget = morphTargets[i];
  21386. var parts = morphTarget.name.match(pattern);
  21387. if (parts && parts.length > 1) {
  21388. var name = parts[1];
  21389. var animationMorphTargets = animationToMorphTargets[name];
  21390. if (!animationMorphTargets) {
  21391. animationToMorphTargets[name] = animationMorphTargets = [];
  21392. }
  21393. animationMorphTargets.push(morphTarget);
  21394. }
  21395. }
  21396. var clips = [];
  21397. for (var _name in animationToMorphTargets) {
  21398. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21399. }
  21400. return clips;
  21401. },
  21402. // parse the animation.hierarchy format
  21403. parseAnimation: function parseAnimation(animation, bones) {
  21404. if (!animation) {
  21405. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21406. return null;
  21407. }
  21408. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21409. // only return track if there are actually keys.
  21410. if (animationKeys.length !== 0) {
  21411. var times = [];
  21412. var values = [];
  21413. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21414. if (times.length !== 0) {
  21415. destTracks.push(new trackType(trackName, times, values));
  21416. }
  21417. }
  21418. };
  21419. var tracks = [];
  21420. var clipName = animation.name || 'default';
  21421. var fps = animation.fps || 30;
  21422. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21423. var duration = animation.length || -1;
  21424. var hierarchyTracks = animation.hierarchy || [];
  21425. for (var h = 0; h < hierarchyTracks.length; h++) {
  21426. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21427. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21428. if (animationKeys[0].morphTargets) {
  21429. // figure out all morph targets used in this track
  21430. var morphTargetNames = {};
  21431. var k = void 0;
  21432. for (k = 0; k < animationKeys.length; k++) {
  21433. if (animationKeys[k].morphTargets) {
  21434. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21435. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21436. }
  21437. }
  21438. } // create a track for each morph target with all zero
  21439. // morphTargetInfluences except for the keys in which
  21440. // the morphTarget is named.
  21441. for (var morphTargetName in morphTargetNames) {
  21442. var times = [];
  21443. var values = [];
  21444. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21445. var animationKey = animationKeys[k];
  21446. times.push(animationKey.time);
  21447. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21448. }
  21449. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21450. }
  21451. duration = morphTargetNames.length * (fps || 1.0);
  21452. } else {
  21453. // ...assume skeletal animation
  21454. var boneName = '.bones[' + bones[h].name + ']';
  21455. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21456. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21457. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21458. }
  21459. }
  21460. if (tracks.length === 0) {
  21461. return null;
  21462. }
  21463. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21464. return clip;
  21465. }
  21466. });
  21467. Object.assign(AnimationClip.prototype, {
  21468. resetDuration: function resetDuration() {
  21469. var tracks = this.tracks;
  21470. var duration = 0;
  21471. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21472. var track = this.tracks[i];
  21473. duration = Math.max(duration, track.times[track.times.length - 1]);
  21474. }
  21475. this.duration = duration;
  21476. return this;
  21477. },
  21478. trim: function trim() {
  21479. for (var i = 0; i < this.tracks.length; i++) {
  21480. this.tracks[i].trim(0, this.duration);
  21481. }
  21482. return this;
  21483. },
  21484. validate: function validate() {
  21485. var valid = true;
  21486. for (var i = 0; i < this.tracks.length; i++) {
  21487. valid = valid && this.tracks[i].validate();
  21488. }
  21489. return valid;
  21490. },
  21491. optimize: function optimize() {
  21492. for (var i = 0; i < this.tracks.length; i++) {
  21493. this.tracks[i].optimize();
  21494. }
  21495. return this;
  21496. },
  21497. clone: function clone() {
  21498. var tracks = [];
  21499. for (var i = 0; i < this.tracks.length; i++) {
  21500. tracks.push(this.tracks[i].clone());
  21501. }
  21502. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21503. }
  21504. });
  21505. var Cache = {
  21506. enabled: false,
  21507. files: {},
  21508. add: function add(key, file) {
  21509. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21510. this.files[key] = file;
  21511. },
  21512. get: function get(key) {
  21513. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21514. return this.files[key];
  21515. },
  21516. remove: function remove(key) {
  21517. delete this.files[key];
  21518. },
  21519. clear: function clear() {
  21520. this.files = {};
  21521. }
  21522. };
  21523. function LoadingManager(onLoad, onProgress, onError) {
  21524. var scope = this;
  21525. var isLoading = false;
  21526. var itemsLoaded = 0;
  21527. var itemsTotal = 0;
  21528. var urlModifier = undefined;
  21529. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21530. // in the constructor
  21531. this.onStart = undefined;
  21532. this.onLoad = onLoad;
  21533. this.onProgress = onProgress;
  21534. this.onError = onError;
  21535. this.itemStart = function (url) {
  21536. itemsTotal++;
  21537. if (isLoading === false) {
  21538. if (scope.onStart !== undefined) {
  21539. scope.onStart(url, itemsLoaded, itemsTotal);
  21540. }
  21541. }
  21542. isLoading = true;
  21543. };
  21544. this.itemEnd = function (url) {
  21545. itemsLoaded++;
  21546. if (scope.onProgress !== undefined) {
  21547. scope.onProgress(url, itemsLoaded, itemsTotal);
  21548. }
  21549. if (itemsLoaded === itemsTotal) {
  21550. isLoading = false;
  21551. if (scope.onLoad !== undefined) {
  21552. scope.onLoad();
  21553. }
  21554. }
  21555. };
  21556. this.itemError = function (url) {
  21557. if (scope.onError !== undefined) {
  21558. scope.onError(url);
  21559. }
  21560. };
  21561. this.resolveURL = function (url) {
  21562. if (urlModifier) {
  21563. return urlModifier(url);
  21564. }
  21565. return url;
  21566. };
  21567. this.setURLModifier = function (transform) {
  21568. urlModifier = transform;
  21569. return this;
  21570. };
  21571. this.addHandler = function (regex, loader) {
  21572. handlers.push(regex, loader);
  21573. return this;
  21574. };
  21575. this.removeHandler = function (regex) {
  21576. var index = handlers.indexOf(regex);
  21577. if (index !== -1) {
  21578. handlers.splice(index, 2);
  21579. }
  21580. return this;
  21581. };
  21582. this.getHandler = function (file) {
  21583. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21584. var regex = handlers[i];
  21585. var loader = handlers[i + 1];
  21586. if (regex.global) regex.lastIndex = 0; // see #17920
  21587. if (regex.test(file)) {
  21588. return loader;
  21589. }
  21590. }
  21591. return null;
  21592. };
  21593. }
  21594. var DefaultLoadingManager = new LoadingManager();
  21595. function Loader(manager) {
  21596. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21597. this.crossOrigin = 'anonymous';
  21598. this.withCredentials = false;
  21599. this.path = '';
  21600. this.resourcePath = '';
  21601. this.requestHeader = {};
  21602. }
  21603. Object.assign(Loader.prototype, {
  21604. load: function load()
  21605. /* url, onLoad, onProgress, onError */
  21606. {},
  21607. loadAsync: function loadAsync(url, onProgress) {
  21608. var scope = this;
  21609. return new Promise(function (resolve, reject) {
  21610. scope.load(url, resolve, onProgress, reject);
  21611. });
  21612. },
  21613. parse: function parse()
  21614. /* data */
  21615. {},
  21616. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21617. this.crossOrigin = crossOrigin;
  21618. return this;
  21619. },
  21620. setWithCredentials: function setWithCredentials(value) {
  21621. this.withCredentials = value;
  21622. return this;
  21623. },
  21624. setPath: function setPath(path) {
  21625. this.path = path;
  21626. return this;
  21627. },
  21628. setResourcePath: function setResourcePath(resourcePath) {
  21629. this.resourcePath = resourcePath;
  21630. return this;
  21631. },
  21632. setRequestHeader: function setRequestHeader(requestHeader) {
  21633. this.requestHeader = requestHeader;
  21634. return this;
  21635. }
  21636. });
  21637. var loading = {};
  21638. function FileLoader(manager) {
  21639. Loader.call(this, manager);
  21640. }
  21641. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21642. constructor: FileLoader,
  21643. load: function load(url, onLoad, onProgress, onError) {
  21644. if (url === undefined) url = '';
  21645. if (this.path !== undefined) url = this.path + url;
  21646. url = this.manager.resolveURL(url);
  21647. var scope = this;
  21648. var cached = Cache.get(url);
  21649. if (cached !== undefined) {
  21650. scope.manager.itemStart(url);
  21651. setTimeout(function () {
  21652. if (onLoad) onLoad(cached);
  21653. scope.manager.itemEnd(url);
  21654. }, 0);
  21655. return cached;
  21656. } // Check if request is duplicate
  21657. if (loading[url] !== undefined) {
  21658. loading[url].push({
  21659. onLoad: onLoad,
  21660. onProgress: onProgress,
  21661. onError: onError
  21662. });
  21663. return;
  21664. } // Check for data: URI
  21665. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21666. var dataUriRegexResult = url.match(dataUriRegex);
  21667. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21668. if (dataUriRegexResult) {
  21669. var mimeType = dataUriRegexResult[1];
  21670. var isBase64 = !!dataUriRegexResult[2];
  21671. var data = dataUriRegexResult[3];
  21672. data = decodeURIComponent(data);
  21673. if (isBase64) data = atob(data);
  21674. try {
  21675. var response;
  21676. var responseType = (this.responseType || '').toLowerCase();
  21677. switch (responseType) {
  21678. case 'arraybuffer':
  21679. case 'blob':
  21680. var view = new Uint8Array(data.length);
  21681. for (var i = 0; i < data.length; i++) {
  21682. view[i] = data.charCodeAt(i);
  21683. }
  21684. if (responseType === 'blob') {
  21685. response = new Blob([view.buffer], {
  21686. type: mimeType
  21687. });
  21688. } else {
  21689. response = view.buffer;
  21690. }
  21691. break;
  21692. case 'document':
  21693. var parser = new DOMParser();
  21694. response = parser.parseFromString(data, mimeType);
  21695. break;
  21696. case 'json':
  21697. response = JSON.parse(data);
  21698. break;
  21699. default:
  21700. // 'text' or other
  21701. response = data;
  21702. break;
  21703. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21704. setTimeout(function () {
  21705. if (onLoad) onLoad(response);
  21706. scope.manager.itemEnd(url);
  21707. }, 0);
  21708. } catch (error) {
  21709. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21710. setTimeout(function () {
  21711. if (onError) onError(error);
  21712. scope.manager.itemError(url);
  21713. scope.manager.itemEnd(url);
  21714. }, 0);
  21715. }
  21716. } else {
  21717. // Initialise array for duplicate requests
  21718. loading[url] = [];
  21719. loading[url].push({
  21720. onLoad: onLoad,
  21721. onProgress: onProgress,
  21722. onError: onError
  21723. });
  21724. request = new XMLHttpRequest();
  21725. request.open('GET', url, true);
  21726. request.addEventListener('load', function (event) {
  21727. var response = this.response;
  21728. var callbacks = loading[url];
  21729. delete loading[url];
  21730. if (this.status === 200 || this.status === 0) {
  21731. // Some browsers return HTTP Status 0 when using non-http protocol
  21732. // e.g. 'file://' or 'data://'. Handle as success.
  21733. 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
  21734. // error response bodies as proper responses to requests.
  21735. Cache.add(url, response);
  21736. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21737. var callback = callbacks[_i];
  21738. if (callback.onLoad) callback.onLoad(response);
  21739. }
  21740. scope.manager.itemEnd(url);
  21741. } else {
  21742. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21743. var _callback = callbacks[_i2];
  21744. if (_callback.onError) _callback.onError(event);
  21745. }
  21746. scope.manager.itemError(url);
  21747. scope.manager.itemEnd(url);
  21748. }
  21749. }, false);
  21750. request.addEventListener('progress', function (event) {
  21751. var callbacks = loading[url];
  21752. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21753. var callback = callbacks[_i3];
  21754. if (callback.onProgress) callback.onProgress(event);
  21755. }
  21756. }, false);
  21757. request.addEventListener('error', function (event) {
  21758. var callbacks = loading[url];
  21759. delete loading[url];
  21760. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21761. var callback = callbacks[_i4];
  21762. if (callback.onError) callback.onError(event);
  21763. }
  21764. scope.manager.itemError(url);
  21765. scope.manager.itemEnd(url);
  21766. }, false);
  21767. request.addEventListener('abort', function (event) {
  21768. var callbacks = loading[url];
  21769. delete loading[url];
  21770. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21771. var callback = callbacks[_i5];
  21772. if (callback.onError) callback.onError(event);
  21773. }
  21774. scope.manager.itemError(url);
  21775. scope.manager.itemEnd(url);
  21776. }, false);
  21777. if (this.responseType !== undefined) request.responseType = this.responseType;
  21778. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21779. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21780. for (var header in this.requestHeader) {
  21781. request.setRequestHeader(header, this.requestHeader[header]);
  21782. }
  21783. request.send(null);
  21784. }
  21785. scope.manager.itemStart(url);
  21786. return request;
  21787. },
  21788. setResponseType: function setResponseType(value) {
  21789. this.responseType = value;
  21790. return this;
  21791. },
  21792. setMimeType: function setMimeType(value) {
  21793. this.mimeType = value;
  21794. return this;
  21795. }
  21796. });
  21797. function AnimationLoader(manager) {
  21798. Loader.call(this, manager);
  21799. }
  21800. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21801. constructor: AnimationLoader,
  21802. load: function load(url, onLoad, onProgress, onError) {
  21803. var scope = this;
  21804. var loader = new FileLoader(scope.manager);
  21805. loader.setPath(scope.path);
  21806. loader.setRequestHeader(scope.requestHeader);
  21807. loader.setWithCredentials(scope.withCredentials);
  21808. loader.load(url, function (text) {
  21809. try {
  21810. onLoad(scope.parse(JSON.parse(text)));
  21811. } catch (e) {
  21812. if (onError) {
  21813. onError(e);
  21814. } else {
  21815. console.error(e);
  21816. }
  21817. scope.manager.itemError(url);
  21818. }
  21819. }, onProgress, onError);
  21820. },
  21821. parse: function parse(json) {
  21822. var animations = [];
  21823. for (var i = 0; i < json.length; i++) {
  21824. var clip = AnimationClip.parse(json[i]);
  21825. animations.push(clip);
  21826. }
  21827. return animations;
  21828. }
  21829. });
  21830. /**
  21831. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21832. *
  21833. * Sub classes have to implement the parse() method which will be used in load().
  21834. */
  21835. function CompressedTextureLoader(manager) {
  21836. Loader.call(this, manager);
  21837. }
  21838. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21839. constructor: CompressedTextureLoader,
  21840. load: function load(url, onLoad, onProgress, onError) {
  21841. var scope = this;
  21842. var images = [];
  21843. var texture = new CompressedTexture();
  21844. texture.image = images;
  21845. var loader = new FileLoader(this.manager);
  21846. loader.setPath(this.path);
  21847. loader.setResponseType('arraybuffer');
  21848. loader.setRequestHeader(this.requestHeader);
  21849. loader.setWithCredentials(scope.withCredentials);
  21850. var loaded = 0;
  21851. function loadTexture(i) {
  21852. loader.load(url[i], function (buffer) {
  21853. var texDatas = scope.parse(buffer, true);
  21854. images[i] = {
  21855. width: texDatas.width,
  21856. height: texDatas.height,
  21857. format: texDatas.format,
  21858. mipmaps: texDatas.mipmaps
  21859. };
  21860. loaded += 1;
  21861. if (loaded === 6) {
  21862. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21863. texture.format = texDatas.format;
  21864. texture.needsUpdate = true;
  21865. if (onLoad) onLoad(texture);
  21866. }
  21867. }, onProgress, onError);
  21868. }
  21869. if (Array.isArray(url)) {
  21870. for (var i = 0, il = url.length; i < il; ++i) {
  21871. loadTexture(i);
  21872. }
  21873. } else {
  21874. // compressed cubemap texture stored in a single DDS file
  21875. loader.load(url, function (buffer) {
  21876. var texDatas = scope.parse(buffer, true);
  21877. if (texDatas.isCubemap) {
  21878. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21879. for (var f = 0; f < faces; f++) {
  21880. images[f] = {
  21881. mipmaps: []
  21882. };
  21883. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21884. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21885. images[f].format = texDatas.format;
  21886. images[f].width = texDatas.width;
  21887. images[f].height = texDatas.height;
  21888. }
  21889. }
  21890. } else {
  21891. texture.image.width = texDatas.width;
  21892. texture.image.height = texDatas.height;
  21893. texture.mipmaps = texDatas.mipmaps;
  21894. }
  21895. if (texDatas.mipmapCount === 1) {
  21896. texture.minFilter = LinearFilter;
  21897. }
  21898. texture.format = texDatas.format;
  21899. texture.needsUpdate = true;
  21900. if (onLoad) onLoad(texture);
  21901. }, onProgress, onError);
  21902. }
  21903. return texture;
  21904. }
  21905. });
  21906. function ImageLoader(manager) {
  21907. Loader.call(this, manager);
  21908. }
  21909. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21910. constructor: ImageLoader,
  21911. load: function load(url, onLoad, onProgress, onError) {
  21912. if (this.path !== undefined) url = this.path + url;
  21913. url = this.manager.resolveURL(url);
  21914. var scope = this;
  21915. var cached = Cache.get(url);
  21916. if (cached !== undefined) {
  21917. scope.manager.itemStart(url);
  21918. setTimeout(function () {
  21919. if (onLoad) onLoad(cached);
  21920. scope.manager.itemEnd(url);
  21921. }, 0);
  21922. return cached;
  21923. }
  21924. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21925. function onImageLoad() {
  21926. image.removeEventListener('load', onImageLoad, false);
  21927. image.removeEventListener('error', onImageError, false);
  21928. Cache.add(url, this);
  21929. if (onLoad) onLoad(this);
  21930. scope.manager.itemEnd(url);
  21931. }
  21932. function onImageError(event) {
  21933. image.removeEventListener('load', onImageLoad, false);
  21934. image.removeEventListener('error', onImageError, false);
  21935. if (onError) onError(event);
  21936. scope.manager.itemError(url);
  21937. scope.manager.itemEnd(url);
  21938. }
  21939. image.addEventListener('load', onImageLoad, false);
  21940. image.addEventListener('error', onImageError, false);
  21941. if (url.substr(0, 5) !== 'data:') {
  21942. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21943. }
  21944. scope.manager.itemStart(url);
  21945. image.src = url;
  21946. return image;
  21947. }
  21948. });
  21949. function CubeTextureLoader(manager) {
  21950. Loader.call(this, manager);
  21951. }
  21952. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21953. constructor: CubeTextureLoader,
  21954. load: function load(urls, onLoad, onProgress, onError) {
  21955. var texture = new CubeTexture();
  21956. var loader = new ImageLoader(this.manager);
  21957. loader.setCrossOrigin(this.crossOrigin);
  21958. loader.setPath(this.path);
  21959. var loaded = 0;
  21960. function loadTexture(i) {
  21961. loader.load(urls[i], function (image) {
  21962. texture.images[i] = image;
  21963. loaded++;
  21964. if (loaded === 6) {
  21965. texture.needsUpdate = true;
  21966. if (onLoad) onLoad(texture);
  21967. }
  21968. }, undefined, onError);
  21969. }
  21970. for (var i = 0; i < urls.length; ++i) {
  21971. loadTexture(i);
  21972. }
  21973. return texture;
  21974. }
  21975. });
  21976. /**
  21977. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21978. *
  21979. * Sub classes have to implement the parse() method which will be used in load().
  21980. */
  21981. function DataTextureLoader(manager) {
  21982. Loader.call(this, manager);
  21983. }
  21984. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21985. constructor: DataTextureLoader,
  21986. load: function load(url, onLoad, onProgress, onError) {
  21987. var scope = this;
  21988. var texture = new DataTexture();
  21989. var loader = new FileLoader(this.manager);
  21990. loader.setResponseType('arraybuffer');
  21991. loader.setRequestHeader(this.requestHeader);
  21992. loader.setPath(this.path);
  21993. loader.setWithCredentials(scope.withCredentials);
  21994. loader.load(url, function (buffer) {
  21995. var texData = scope.parse(buffer);
  21996. if (!texData) return;
  21997. if (texData.image !== undefined) {
  21998. texture.image = texData.image;
  21999. } else if (texData.data !== undefined) {
  22000. texture.image.width = texData.width;
  22001. texture.image.height = texData.height;
  22002. texture.image.data = texData.data;
  22003. }
  22004. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22005. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22006. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22007. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22008. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22009. if (texData.format !== undefined) {
  22010. texture.format = texData.format;
  22011. }
  22012. if (texData.type !== undefined) {
  22013. texture.type = texData.type;
  22014. }
  22015. if (texData.mipmaps !== undefined) {
  22016. texture.mipmaps = texData.mipmaps;
  22017. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22018. }
  22019. if (texData.mipmapCount === 1) {
  22020. texture.minFilter = LinearFilter;
  22021. }
  22022. texture.needsUpdate = true;
  22023. if (onLoad) onLoad(texture, texData);
  22024. }, onProgress, onError);
  22025. return texture;
  22026. }
  22027. });
  22028. function TextureLoader(manager) {
  22029. Loader.call(this, manager);
  22030. }
  22031. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22032. constructor: TextureLoader,
  22033. load: function load(url, onLoad, onProgress, onError) {
  22034. var texture = new Texture();
  22035. var loader = new ImageLoader(this.manager);
  22036. loader.setCrossOrigin(this.crossOrigin);
  22037. loader.setPath(this.path);
  22038. loader.load(url, function (image) {
  22039. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22040. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22041. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22042. texture.needsUpdate = true;
  22043. if (onLoad !== undefined) {
  22044. onLoad(texture);
  22045. }
  22046. }, onProgress, onError);
  22047. return texture;
  22048. }
  22049. });
  22050. /**
  22051. * Extensible curve object.
  22052. *
  22053. * Some common of curve methods:
  22054. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22055. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22056. * .getPoints(), .getSpacedPoints()
  22057. * .getLength()
  22058. * .updateArcLengths()
  22059. *
  22060. * This following curves inherit from THREE.Curve:
  22061. *
  22062. * -- 2D curves --
  22063. * THREE.ArcCurve
  22064. * THREE.CubicBezierCurve
  22065. * THREE.EllipseCurve
  22066. * THREE.LineCurve
  22067. * THREE.QuadraticBezierCurve
  22068. * THREE.SplineCurve
  22069. *
  22070. * -- 3D curves --
  22071. * THREE.CatmullRomCurve3
  22072. * THREE.CubicBezierCurve3
  22073. * THREE.LineCurve3
  22074. * THREE.QuadraticBezierCurve3
  22075. *
  22076. * A series of curves can be represented as a THREE.CurvePath.
  22077. *
  22078. **/
  22079. function Curve() {
  22080. this.type = 'Curve';
  22081. this.arcLengthDivisions = 200;
  22082. }
  22083. Object.assign(Curve.prototype, {
  22084. // Virtual base class method to overwrite and implement in subclasses
  22085. // - t [0 .. 1]
  22086. getPoint: function getPoint()
  22087. /* t, optionalTarget */
  22088. {
  22089. console.warn('THREE.Curve: .getPoint() not implemented.');
  22090. return null;
  22091. },
  22092. // Get point at relative position in curve according to arc length
  22093. // - u [0 .. 1]
  22094. getPointAt: function getPointAt(u, optionalTarget) {
  22095. var t = this.getUtoTmapping(u);
  22096. return this.getPoint(t, optionalTarget);
  22097. },
  22098. // Get sequence of points using getPoint( t )
  22099. getPoints: function getPoints(divisions) {
  22100. if (divisions === undefined) divisions = 5;
  22101. var points = [];
  22102. for (var d = 0; d <= divisions; d++) {
  22103. points.push(this.getPoint(d / divisions));
  22104. }
  22105. return points;
  22106. },
  22107. // Get sequence of points using getPointAt( u )
  22108. getSpacedPoints: function getSpacedPoints(divisions) {
  22109. if (divisions === undefined) divisions = 5;
  22110. var points = [];
  22111. for (var d = 0; d <= divisions; d++) {
  22112. points.push(this.getPointAt(d / divisions));
  22113. }
  22114. return points;
  22115. },
  22116. // Get total curve arc length
  22117. getLength: function getLength() {
  22118. var lengths = this.getLengths();
  22119. return lengths[lengths.length - 1];
  22120. },
  22121. // Get list of cumulative segment lengths
  22122. getLengths: function getLengths(divisions) {
  22123. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22124. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22125. return this.cacheArcLengths;
  22126. }
  22127. this.needsUpdate = false;
  22128. var cache = [];
  22129. var current,
  22130. last = this.getPoint(0);
  22131. var sum = 0;
  22132. cache.push(0);
  22133. for (var p = 1; p <= divisions; p++) {
  22134. current = this.getPoint(p / divisions);
  22135. sum += current.distanceTo(last);
  22136. cache.push(sum);
  22137. last = current;
  22138. }
  22139. this.cacheArcLengths = cache;
  22140. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22141. },
  22142. updateArcLengths: function updateArcLengths() {
  22143. this.needsUpdate = true;
  22144. this.getLengths();
  22145. },
  22146. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22147. getUtoTmapping: function getUtoTmapping(u, distance) {
  22148. var arcLengths = this.getLengths();
  22149. var i = 0;
  22150. var il = arcLengths.length;
  22151. var targetArcLength; // The targeted u distance value to get
  22152. if (distance) {
  22153. targetArcLength = distance;
  22154. } else {
  22155. targetArcLength = u * arcLengths[il - 1];
  22156. } // binary search for the index with largest value smaller than target u distance
  22157. var low = 0,
  22158. high = il - 1,
  22159. comparison;
  22160. while (low <= high) {
  22161. 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
  22162. comparison = arcLengths[i] - targetArcLength;
  22163. if (comparison < 0) {
  22164. low = i + 1;
  22165. } else if (comparison > 0) {
  22166. high = i - 1;
  22167. } else {
  22168. high = i;
  22169. break; // DONE
  22170. }
  22171. }
  22172. i = high;
  22173. if (arcLengths[i] === targetArcLength) {
  22174. return i / (il - 1);
  22175. } // we could get finer grain at lengths, or use simple interpolation between two points
  22176. var lengthBefore = arcLengths[i];
  22177. var lengthAfter = arcLengths[i + 1];
  22178. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22179. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22180. var t = (i + segmentFraction) / (il - 1);
  22181. return t;
  22182. },
  22183. // Returns a unit vector tangent at t
  22184. // In case any sub curve does not implement its tangent derivation,
  22185. // 2 points a small delta apart will be used to find its gradient
  22186. // which seems to give a reasonable approximation
  22187. getTangent: function getTangent(t, optionalTarget) {
  22188. var delta = 0.0001;
  22189. var t1 = t - delta;
  22190. var t2 = t + delta; // Capping in case of danger
  22191. if (t1 < 0) t1 = 0;
  22192. if (t2 > 1) t2 = 1;
  22193. var pt1 = this.getPoint(t1);
  22194. var pt2 = this.getPoint(t2);
  22195. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22196. tangent.copy(pt2).sub(pt1).normalize();
  22197. return tangent;
  22198. },
  22199. getTangentAt: function getTangentAt(u, optionalTarget) {
  22200. var t = this.getUtoTmapping(u);
  22201. return this.getTangent(t, optionalTarget);
  22202. },
  22203. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22204. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22205. var normal = new Vector3();
  22206. var tangents = [];
  22207. var normals = [];
  22208. var binormals = [];
  22209. var vec = new Vector3();
  22210. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22211. for (var i = 0; i <= segments; i++) {
  22212. var u = i / segments;
  22213. tangents[i] = this.getTangentAt(u, new Vector3());
  22214. tangents[i].normalize();
  22215. } // select an initial normal vector perpendicular to the first tangent vector,
  22216. // and in the direction of the minimum tangent xyz component
  22217. normals[0] = new Vector3();
  22218. binormals[0] = new Vector3();
  22219. var min = Number.MAX_VALUE;
  22220. var tx = Math.abs(tangents[0].x);
  22221. var ty = Math.abs(tangents[0].y);
  22222. var tz = Math.abs(tangents[0].z);
  22223. if (tx <= min) {
  22224. min = tx;
  22225. normal.set(1, 0, 0);
  22226. }
  22227. if (ty <= min) {
  22228. min = ty;
  22229. normal.set(0, 1, 0);
  22230. }
  22231. if (tz <= min) {
  22232. normal.set(0, 0, 1);
  22233. }
  22234. vec.crossVectors(tangents[0], normal).normalize();
  22235. normals[0].crossVectors(tangents[0], vec);
  22236. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22237. for (var _i = 1; _i <= segments; _i++) {
  22238. normals[_i] = normals[_i - 1].clone();
  22239. binormals[_i] = binormals[_i - 1].clone();
  22240. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22241. if (vec.length() > Number.EPSILON) {
  22242. vec.normalize();
  22243. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22244. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22245. }
  22246. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22247. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22248. if (closed === true) {
  22249. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22250. _theta /= segments;
  22251. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22252. _theta = -_theta;
  22253. }
  22254. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22255. // twist a little...
  22256. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22257. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22258. }
  22259. }
  22260. return {
  22261. tangents: tangents,
  22262. normals: normals,
  22263. binormals: binormals
  22264. };
  22265. },
  22266. clone: function clone() {
  22267. return new this.constructor().copy(this);
  22268. },
  22269. copy: function copy(source) {
  22270. this.arcLengthDivisions = source.arcLengthDivisions;
  22271. return this;
  22272. },
  22273. toJSON: function toJSON() {
  22274. var data = {
  22275. metadata: {
  22276. version: 4.5,
  22277. type: 'Curve',
  22278. generator: 'Curve.toJSON'
  22279. }
  22280. };
  22281. data.arcLengthDivisions = this.arcLengthDivisions;
  22282. data.type = this.type;
  22283. return data;
  22284. },
  22285. fromJSON: function fromJSON(json) {
  22286. this.arcLengthDivisions = json.arcLengthDivisions;
  22287. return this;
  22288. }
  22289. });
  22290. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22291. Curve.call(this);
  22292. this.type = 'EllipseCurve';
  22293. this.aX = aX || 0;
  22294. this.aY = aY || 0;
  22295. this.xRadius = xRadius || 1;
  22296. this.yRadius = yRadius || 1;
  22297. this.aStartAngle = aStartAngle || 0;
  22298. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22299. this.aClockwise = aClockwise || false;
  22300. this.aRotation = aRotation || 0;
  22301. }
  22302. EllipseCurve.prototype = Object.create(Curve.prototype);
  22303. EllipseCurve.prototype.constructor = EllipseCurve;
  22304. EllipseCurve.prototype.isEllipseCurve = true;
  22305. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22306. var point = optionalTarget || new Vector2();
  22307. var twoPi = Math.PI * 2;
  22308. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22309. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22310. while (deltaAngle < 0) {
  22311. deltaAngle += twoPi;
  22312. }
  22313. while (deltaAngle > twoPi) {
  22314. deltaAngle -= twoPi;
  22315. }
  22316. if (deltaAngle < Number.EPSILON) {
  22317. if (samePoints) {
  22318. deltaAngle = 0;
  22319. } else {
  22320. deltaAngle = twoPi;
  22321. }
  22322. }
  22323. if (this.aClockwise === true && !samePoints) {
  22324. if (deltaAngle === twoPi) {
  22325. deltaAngle = -twoPi;
  22326. } else {
  22327. deltaAngle = deltaAngle - twoPi;
  22328. }
  22329. }
  22330. var angle = this.aStartAngle + t * deltaAngle;
  22331. var x = this.aX + this.xRadius * Math.cos(angle);
  22332. var y = this.aY + this.yRadius * Math.sin(angle);
  22333. if (this.aRotation !== 0) {
  22334. var cos = Math.cos(this.aRotation);
  22335. var sin = Math.sin(this.aRotation);
  22336. var tx = x - this.aX;
  22337. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22338. x = tx * cos - ty * sin + this.aX;
  22339. y = tx * sin + ty * cos + this.aY;
  22340. }
  22341. return point.set(x, y);
  22342. };
  22343. EllipseCurve.prototype.copy = function (source) {
  22344. Curve.prototype.copy.call(this, source);
  22345. this.aX = source.aX;
  22346. this.aY = source.aY;
  22347. this.xRadius = source.xRadius;
  22348. this.yRadius = source.yRadius;
  22349. this.aStartAngle = source.aStartAngle;
  22350. this.aEndAngle = source.aEndAngle;
  22351. this.aClockwise = source.aClockwise;
  22352. this.aRotation = source.aRotation;
  22353. return this;
  22354. };
  22355. EllipseCurve.prototype.toJSON = function () {
  22356. var data = Curve.prototype.toJSON.call(this);
  22357. data.aX = this.aX;
  22358. data.aY = this.aY;
  22359. data.xRadius = this.xRadius;
  22360. data.yRadius = this.yRadius;
  22361. data.aStartAngle = this.aStartAngle;
  22362. data.aEndAngle = this.aEndAngle;
  22363. data.aClockwise = this.aClockwise;
  22364. data.aRotation = this.aRotation;
  22365. return data;
  22366. };
  22367. EllipseCurve.prototype.fromJSON = function (json) {
  22368. Curve.prototype.fromJSON.call(this, json);
  22369. this.aX = json.aX;
  22370. this.aY = json.aY;
  22371. this.xRadius = json.xRadius;
  22372. this.yRadius = json.yRadius;
  22373. this.aStartAngle = json.aStartAngle;
  22374. this.aEndAngle = json.aEndAngle;
  22375. this.aClockwise = json.aClockwise;
  22376. this.aRotation = json.aRotation;
  22377. return this;
  22378. };
  22379. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22380. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22381. this.type = 'ArcCurve';
  22382. }
  22383. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22384. ArcCurve.prototype.constructor = ArcCurve;
  22385. ArcCurve.prototype.isArcCurve = true;
  22386. /**
  22387. * Centripetal CatmullRom Curve - which is useful for avoiding
  22388. * cusps and self-intersections in non-uniform catmull rom curves.
  22389. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22390. *
  22391. * curve.type accepts centripetal(default), chordal and catmullrom
  22392. * curve.tension is used for catmullrom which defaults to 0.5
  22393. */
  22394. /*
  22395. Based on an optimized c++ solution in
  22396. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22397. - http://ideone.com/NoEbVM
  22398. This CubicPoly class could be used for reusing some variables and calculations,
  22399. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22400. which can be placed in CurveUtils.
  22401. */
  22402. function CubicPoly() {
  22403. var c0 = 0,
  22404. c1 = 0,
  22405. c2 = 0,
  22406. c3 = 0;
  22407. /*
  22408. * Compute coefficients for a cubic polynomial
  22409. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22410. * such that
  22411. * p(0) = x0, p(1) = x1
  22412. * and
  22413. * p'(0) = t0, p'(1) = t1.
  22414. */
  22415. function init(x0, x1, t0, t1) {
  22416. c0 = x0;
  22417. c1 = t0;
  22418. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22419. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22420. }
  22421. return {
  22422. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22423. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22424. },
  22425. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22426. // compute tangents when parameterized in [t1,t2]
  22427. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22428. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22429. t1 *= dt1;
  22430. t2 *= dt1;
  22431. init(x1, x2, t1, t2);
  22432. },
  22433. calc: function calc(t) {
  22434. var t2 = t * t;
  22435. var t3 = t2 * t;
  22436. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22437. }
  22438. };
  22439. } //
  22440. var tmp = new Vector3();
  22441. var px = new CubicPoly(),
  22442. py = new CubicPoly(),
  22443. pz = new CubicPoly();
  22444. function CatmullRomCurve3(points, closed, curveType, tension) {
  22445. Curve.call(this);
  22446. this.type = 'CatmullRomCurve3';
  22447. this.points = points || [];
  22448. this.closed = closed || false;
  22449. this.curveType = curveType || 'centripetal';
  22450. this.tension = tension !== undefined ? tension : 0.5;
  22451. }
  22452. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22453. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22454. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22455. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22456. var point = optionalTarget || new Vector3();
  22457. var points = this.points;
  22458. var l = points.length;
  22459. var p = (l - (this.closed ? 0 : 1)) * t;
  22460. var intPoint = Math.floor(p);
  22461. var weight = p - intPoint;
  22462. if (this.closed) {
  22463. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22464. } else if (weight === 0 && intPoint === l - 1) {
  22465. intPoint = l - 2;
  22466. weight = 1;
  22467. }
  22468. var p0, p3; // 4 points (p1 & p2 defined below)
  22469. if (this.closed || intPoint > 0) {
  22470. p0 = points[(intPoint - 1) % l];
  22471. } else {
  22472. // extrapolate first point
  22473. tmp.subVectors(points[0], points[1]).add(points[0]);
  22474. p0 = tmp;
  22475. }
  22476. var p1 = points[intPoint % l];
  22477. var p2 = points[(intPoint + 1) % l];
  22478. if (this.closed || intPoint + 2 < l) {
  22479. p3 = points[(intPoint + 2) % l];
  22480. } else {
  22481. // extrapolate last point
  22482. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22483. p3 = tmp;
  22484. }
  22485. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22486. // init Centripetal / Chordal Catmull-Rom
  22487. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22488. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22489. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22490. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22491. if (dt1 < 1e-4) dt1 = 1.0;
  22492. if (dt0 < 1e-4) dt0 = dt1;
  22493. if (dt2 < 1e-4) dt2 = dt1;
  22494. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22495. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22496. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22497. } else if (this.curveType === 'catmullrom') {
  22498. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22499. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22500. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22501. }
  22502. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22503. return point;
  22504. };
  22505. CatmullRomCurve3.prototype.copy = function (source) {
  22506. Curve.prototype.copy.call(this, source);
  22507. this.points = [];
  22508. for (var i = 0, l = source.points.length; i < l; i++) {
  22509. var point = source.points[i];
  22510. this.points.push(point.clone());
  22511. }
  22512. this.closed = source.closed;
  22513. this.curveType = source.curveType;
  22514. this.tension = source.tension;
  22515. return this;
  22516. };
  22517. CatmullRomCurve3.prototype.toJSON = function () {
  22518. var data = Curve.prototype.toJSON.call(this);
  22519. data.points = [];
  22520. for (var i = 0, l = this.points.length; i < l; i++) {
  22521. var point = this.points[i];
  22522. data.points.push(point.toArray());
  22523. }
  22524. data.closed = this.closed;
  22525. data.curveType = this.curveType;
  22526. data.tension = this.tension;
  22527. return data;
  22528. };
  22529. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22530. Curve.prototype.fromJSON.call(this, json);
  22531. this.points = [];
  22532. for (var i = 0, l = json.points.length; i < l; i++) {
  22533. var point = json.points[i];
  22534. this.points.push(new Vector3().fromArray(point));
  22535. }
  22536. this.closed = json.closed;
  22537. this.curveType = json.curveType;
  22538. this.tension = json.tension;
  22539. return this;
  22540. };
  22541. /**
  22542. * Bezier Curves formulas obtained from
  22543. * http://en.wikipedia.org/wiki/Bézier_curve
  22544. */
  22545. function CatmullRom(t, p0, p1, p2, p3) {
  22546. var v0 = (p2 - p0) * 0.5;
  22547. var v1 = (p3 - p1) * 0.5;
  22548. var t2 = t * t;
  22549. var t3 = t * t2;
  22550. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22551. } //
  22552. function QuadraticBezierP0(t, p) {
  22553. var k = 1 - t;
  22554. return k * k * p;
  22555. }
  22556. function QuadraticBezierP1(t, p) {
  22557. return 2 * (1 - t) * t * p;
  22558. }
  22559. function QuadraticBezierP2(t, p) {
  22560. return t * t * p;
  22561. }
  22562. function QuadraticBezier(t, p0, p1, p2) {
  22563. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22564. } //
  22565. function CubicBezierP0(t, p) {
  22566. var k = 1 - t;
  22567. return k * k * k * p;
  22568. }
  22569. function CubicBezierP1(t, p) {
  22570. var k = 1 - t;
  22571. return 3 * k * k * t * p;
  22572. }
  22573. function CubicBezierP2(t, p) {
  22574. return 3 * (1 - t) * t * t * p;
  22575. }
  22576. function CubicBezierP3(t, p) {
  22577. return t * t * t * p;
  22578. }
  22579. function CubicBezier(t, p0, p1, p2, p3) {
  22580. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22581. }
  22582. function CubicBezierCurve(v0, v1, v2, v3) {
  22583. Curve.call(this);
  22584. this.type = 'CubicBezierCurve';
  22585. this.v0 = v0 || new Vector2();
  22586. this.v1 = v1 || new Vector2();
  22587. this.v2 = v2 || new Vector2();
  22588. this.v3 = v3 || new Vector2();
  22589. }
  22590. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  22591. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22592. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22593. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22594. var point = optionalTarget || new Vector2();
  22595. var v0 = this.v0,
  22596. v1 = this.v1,
  22597. v2 = this.v2,
  22598. v3 = this.v3;
  22599. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22600. return point;
  22601. };
  22602. CubicBezierCurve.prototype.copy = function (source) {
  22603. Curve.prototype.copy.call(this, source);
  22604. this.v0.copy(source.v0);
  22605. this.v1.copy(source.v1);
  22606. this.v2.copy(source.v2);
  22607. this.v3.copy(source.v3);
  22608. return this;
  22609. };
  22610. CubicBezierCurve.prototype.toJSON = function () {
  22611. var data = Curve.prototype.toJSON.call(this);
  22612. data.v0 = this.v0.toArray();
  22613. data.v1 = this.v1.toArray();
  22614. data.v2 = this.v2.toArray();
  22615. data.v3 = this.v3.toArray();
  22616. return data;
  22617. };
  22618. CubicBezierCurve.prototype.fromJSON = function (json) {
  22619. Curve.prototype.fromJSON.call(this, json);
  22620. this.v0.fromArray(json.v0);
  22621. this.v1.fromArray(json.v1);
  22622. this.v2.fromArray(json.v2);
  22623. this.v3.fromArray(json.v3);
  22624. return this;
  22625. };
  22626. function CubicBezierCurve3(v0, v1, v2, v3) {
  22627. Curve.call(this);
  22628. this.type = 'CubicBezierCurve3';
  22629. this.v0 = v0 || new Vector3();
  22630. this.v1 = v1 || new Vector3();
  22631. this.v2 = v2 || new Vector3();
  22632. this.v3 = v3 || new Vector3();
  22633. }
  22634. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  22635. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22636. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22637. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22638. var point = optionalTarget || new Vector3();
  22639. var v0 = this.v0,
  22640. v1 = this.v1,
  22641. v2 = this.v2,
  22642. v3 = this.v3;
  22643. 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));
  22644. return point;
  22645. };
  22646. CubicBezierCurve3.prototype.copy = function (source) {
  22647. Curve.prototype.copy.call(this, source);
  22648. this.v0.copy(source.v0);
  22649. this.v1.copy(source.v1);
  22650. this.v2.copy(source.v2);
  22651. this.v3.copy(source.v3);
  22652. return this;
  22653. };
  22654. CubicBezierCurve3.prototype.toJSON = function () {
  22655. var data = Curve.prototype.toJSON.call(this);
  22656. data.v0 = this.v0.toArray();
  22657. data.v1 = this.v1.toArray();
  22658. data.v2 = this.v2.toArray();
  22659. data.v3 = this.v3.toArray();
  22660. return data;
  22661. };
  22662. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22663. Curve.prototype.fromJSON.call(this, json);
  22664. this.v0.fromArray(json.v0);
  22665. this.v1.fromArray(json.v1);
  22666. this.v2.fromArray(json.v2);
  22667. this.v3.fromArray(json.v3);
  22668. return this;
  22669. };
  22670. function LineCurve(v1, v2) {
  22671. Curve.call(this);
  22672. this.type = 'LineCurve';
  22673. this.v1 = v1 || new Vector2();
  22674. this.v2 = v2 || new Vector2();
  22675. }
  22676. LineCurve.prototype = Object.create(Curve.prototype);
  22677. LineCurve.prototype.constructor = LineCurve;
  22678. LineCurve.prototype.isLineCurve = true;
  22679. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22680. var point = optionalTarget || new Vector2();
  22681. if (t === 1) {
  22682. point.copy(this.v2);
  22683. } else {
  22684. point.copy(this.v2).sub(this.v1);
  22685. point.multiplyScalar(t).add(this.v1);
  22686. }
  22687. return point;
  22688. }; // Line curve is linear, so we can overwrite default getPointAt
  22689. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22690. return this.getPoint(u, optionalTarget);
  22691. };
  22692. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22693. var tangent = optionalTarget || new Vector2();
  22694. tangent.copy(this.v2).sub(this.v1).normalize();
  22695. return tangent;
  22696. };
  22697. LineCurve.prototype.copy = function (source) {
  22698. Curve.prototype.copy.call(this, source);
  22699. this.v1.copy(source.v1);
  22700. this.v2.copy(source.v2);
  22701. return this;
  22702. };
  22703. LineCurve.prototype.toJSON = function () {
  22704. var data = Curve.prototype.toJSON.call(this);
  22705. data.v1 = this.v1.toArray();
  22706. data.v2 = this.v2.toArray();
  22707. return data;
  22708. };
  22709. LineCurve.prototype.fromJSON = function (json) {
  22710. Curve.prototype.fromJSON.call(this, json);
  22711. this.v1.fromArray(json.v1);
  22712. this.v2.fromArray(json.v2);
  22713. return this;
  22714. };
  22715. function LineCurve3(v1, v2) {
  22716. Curve.call(this);
  22717. this.type = 'LineCurve3';
  22718. this.v1 = v1 || new Vector3();
  22719. this.v2 = v2 || new Vector3();
  22720. }
  22721. LineCurve3.prototype = Object.create(Curve.prototype);
  22722. LineCurve3.prototype.constructor = LineCurve3;
  22723. LineCurve3.prototype.isLineCurve3 = true;
  22724. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22725. var point = optionalTarget || new Vector3();
  22726. if (t === 1) {
  22727. point.copy(this.v2);
  22728. } else {
  22729. point.copy(this.v2).sub(this.v1);
  22730. point.multiplyScalar(t).add(this.v1);
  22731. }
  22732. return point;
  22733. }; // Line curve is linear, so we can overwrite default getPointAt
  22734. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22735. return this.getPoint(u, optionalTarget);
  22736. };
  22737. LineCurve3.prototype.copy = function (source) {
  22738. Curve.prototype.copy.call(this, source);
  22739. this.v1.copy(source.v1);
  22740. this.v2.copy(source.v2);
  22741. return this;
  22742. };
  22743. LineCurve3.prototype.toJSON = function () {
  22744. var data = Curve.prototype.toJSON.call(this);
  22745. data.v1 = this.v1.toArray();
  22746. data.v2 = this.v2.toArray();
  22747. return data;
  22748. };
  22749. LineCurve3.prototype.fromJSON = function (json) {
  22750. Curve.prototype.fromJSON.call(this, json);
  22751. this.v1.fromArray(json.v1);
  22752. this.v2.fromArray(json.v2);
  22753. return this;
  22754. };
  22755. function QuadraticBezierCurve(v0, v1, v2) {
  22756. Curve.call(this);
  22757. this.type = 'QuadraticBezierCurve';
  22758. this.v0 = v0 || new Vector2();
  22759. this.v1 = v1 || new Vector2();
  22760. this.v2 = v2 || new Vector2();
  22761. }
  22762. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22763. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22764. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22765. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22766. var point = optionalTarget || new Vector2();
  22767. var v0 = this.v0,
  22768. v1 = this.v1,
  22769. v2 = this.v2;
  22770. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22771. return point;
  22772. };
  22773. QuadraticBezierCurve.prototype.copy = function (source) {
  22774. Curve.prototype.copy.call(this, source);
  22775. this.v0.copy(source.v0);
  22776. this.v1.copy(source.v1);
  22777. this.v2.copy(source.v2);
  22778. return this;
  22779. };
  22780. QuadraticBezierCurve.prototype.toJSON = function () {
  22781. var data = Curve.prototype.toJSON.call(this);
  22782. data.v0 = this.v0.toArray();
  22783. data.v1 = this.v1.toArray();
  22784. data.v2 = this.v2.toArray();
  22785. return data;
  22786. };
  22787. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22788. Curve.prototype.fromJSON.call(this, json);
  22789. this.v0.fromArray(json.v0);
  22790. this.v1.fromArray(json.v1);
  22791. this.v2.fromArray(json.v2);
  22792. return this;
  22793. };
  22794. function QuadraticBezierCurve3(v0, v1, v2) {
  22795. Curve.call(this);
  22796. this.type = 'QuadraticBezierCurve3';
  22797. this.v0 = v0 || new Vector3();
  22798. this.v1 = v1 || new Vector3();
  22799. this.v2 = v2 || new Vector3();
  22800. }
  22801. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22802. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22803. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22804. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22805. var point = optionalTarget || new Vector3();
  22806. var v0 = this.v0,
  22807. v1 = this.v1,
  22808. v2 = this.v2;
  22809. 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));
  22810. return point;
  22811. };
  22812. QuadraticBezierCurve3.prototype.copy = function (source) {
  22813. Curve.prototype.copy.call(this, source);
  22814. this.v0.copy(source.v0);
  22815. this.v1.copy(source.v1);
  22816. this.v2.copy(source.v2);
  22817. return this;
  22818. };
  22819. QuadraticBezierCurve3.prototype.toJSON = function () {
  22820. var data = Curve.prototype.toJSON.call(this);
  22821. data.v0 = this.v0.toArray();
  22822. data.v1 = this.v1.toArray();
  22823. data.v2 = this.v2.toArray();
  22824. return data;
  22825. };
  22826. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  22827. Curve.prototype.fromJSON.call(this, json);
  22828. this.v0.fromArray(json.v0);
  22829. this.v1.fromArray(json.v1);
  22830. this.v2.fromArray(json.v2);
  22831. return this;
  22832. };
  22833. function SplineCurve(points) {
  22834. Curve.call(this);
  22835. this.type = 'SplineCurve';
  22836. this.points = points || [];
  22837. }
  22838. SplineCurve.prototype = Object.create(Curve.prototype);
  22839. SplineCurve.prototype.constructor = SplineCurve;
  22840. SplineCurve.prototype.isSplineCurve = true;
  22841. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  22842. var point = optionalTarget || new Vector2();
  22843. var points = this.points;
  22844. var p = (points.length - 1) * t;
  22845. var intPoint = Math.floor(p);
  22846. var weight = p - intPoint;
  22847. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22848. var p1 = points[intPoint];
  22849. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22850. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22851. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22852. return point;
  22853. };
  22854. SplineCurve.prototype.copy = function (source) {
  22855. Curve.prototype.copy.call(this, source);
  22856. this.points = [];
  22857. for (var i = 0, l = source.points.length; i < l; i++) {
  22858. var point = source.points[i];
  22859. this.points.push(point.clone());
  22860. }
  22861. return this;
  22862. };
  22863. SplineCurve.prototype.toJSON = function () {
  22864. var data = Curve.prototype.toJSON.call(this);
  22865. data.points = [];
  22866. for (var i = 0, l = this.points.length; i < l; i++) {
  22867. var point = this.points[i];
  22868. data.points.push(point.toArray());
  22869. }
  22870. return data;
  22871. };
  22872. SplineCurve.prototype.fromJSON = function (json) {
  22873. Curve.prototype.fromJSON.call(this, json);
  22874. this.points = [];
  22875. for (var i = 0, l = json.points.length; i < l; i++) {
  22876. var point = json.points[i];
  22877. this.points.push(new Vector2().fromArray(point));
  22878. }
  22879. return this;
  22880. };
  22881. var Curves = /*#__PURE__*/Object.freeze({
  22882. __proto__: null,
  22883. ArcCurve: ArcCurve,
  22884. CatmullRomCurve3: CatmullRomCurve3,
  22885. CubicBezierCurve: CubicBezierCurve,
  22886. CubicBezierCurve3: CubicBezierCurve3,
  22887. EllipseCurve: EllipseCurve,
  22888. LineCurve: LineCurve,
  22889. LineCurve3: LineCurve3,
  22890. QuadraticBezierCurve: QuadraticBezierCurve,
  22891. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22892. SplineCurve: SplineCurve
  22893. });
  22894. /**************************************************************
  22895. * Curved Path - a curve path is simply a array of connected
  22896. * curves, but retains the api of a curve
  22897. **************************************************************/
  22898. function CurvePath() {
  22899. Curve.call(this);
  22900. this.type = 'CurvePath';
  22901. this.curves = [];
  22902. this.autoClose = false; // Automatically closes the path
  22903. }
  22904. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  22905. constructor: CurvePath,
  22906. add: function add(curve) {
  22907. this.curves.push(curve);
  22908. },
  22909. closePath: function closePath() {
  22910. // Add a line curve if start and end of lines are not connected
  22911. var startPoint = this.curves[0].getPoint(0);
  22912. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22913. if (!startPoint.equals(endPoint)) {
  22914. this.curves.push(new LineCurve(endPoint, startPoint));
  22915. }
  22916. },
  22917. // To get accurate point with reference to
  22918. // entire path distance at time t,
  22919. // following has to be done:
  22920. // 1. Length of each sub path have to be known
  22921. // 2. Locate and identify type of curve
  22922. // 3. Get t for the curve
  22923. // 4. Return curve.getPointAt(t')
  22924. getPoint: function getPoint(t) {
  22925. var d = t * this.getLength();
  22926. var curveLengths = this.getCurveLengths();
  22927. var i = 0; // To think about boundaries points.
  22928. while (i < curveLengths.length) {
  22929. if (curveLengths[i] >= d) {
  22930. var diff = curveLengths[i] - d;
  22931. var curve = this.curves[i];
  22932. var segmentLength = curve.getLength();
  22933. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22934. return curve.getPointAt(u);
  22935. }
  22936. i++;
  22937. }
  22938. return null; // loop where sum != 0, sum > d , sum+1 <d
  22939. },
  22940. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22941. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22942. // getPoint() depends on getLength
  22943. getLength: function getLength() {
  22944. var lens = this.getCurveLengths();
  22945. return lens[lens.length - 1];
  22946. },
  22947. // cacheLengths must be recalculated.
  22948. updateArcLengths: function updateArcLengths() {
  22949. this.needsUpdate = true;
  22950. this.cacheLengths = null;
  22951. this.getCurveLengths();
  22952. },
  22953. // Compute lengths and cache them
  22954. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22955. getCurveLengths: function getCurveLengths() {
  22956. // We use cache values if curves and cache array are same length
  22957. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22958. return this.cacheLengths;
  22959. } // Get length of sub-curve
  22960. // Push sums into cached array
  22961. var lengths = [];
  22962. var sums = 0;
  22963. for (var i = 0, l = this.curves.length; i < l; i++) {
  22964. sums += this.curves[i].getLength();
  22965. lengths.push(sums);
  22966. }
  22967. this.cacheLengths = lengths;
  22968. return lengths;
  22969. },
  22970. getSpacedPoints: function getSpacedPoints(divisions) {
  22971. if (divisions === undefined) divisions = 40;
  22972. var points = [];
  22973. for (var i = 0; i <= divisions; i++) {
  22974. points.push(this.getPoint(i / divisions));
  22975. }
  22976. if (this.autoClose) {
  22977. points.push(points[0]);
  22978. }
  22979. return points;
  22980. },
  22981. getPoints: function getPoints(divisions) {
  22982. divisions = divisions || 12;
  22983. var points = [];
  22984. var last;
  22985. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  22986. var curve = curves[i];
  22987. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  22988. var pts = curve.getPoints(resolution);
  22989. for (var j = 0; j < pts.length; j++) {
  22990. var point = pts[j];
  22991. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  22992. points.push(point);
  22993. last = point;
  22994. }
  22995. }
  22996. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  22997. points.push(points[0]);
  22998. }
  22999. return points;
  23000. },
  23001. copy: function copy(source) {
  23002. Curve.prototype.copy.call(this, source);
  23003. this.curves = [];
  23004. for (var i = 0, l = source.curves.length; i < l; i++) {
  23005. var curve = source.curves[i];
  23006. this.curves.push(curve.clone());
  23007. }
  23008. this.autoClose = source.autoClose;
  23009. return this;
  23010. },
  23011. toJSON: function toJSON() {
  23012. var data = Curve.prototype.toJSON.call(this);
  23013. data.autoClose = this.autoClose;
  23014. data.curves = [];
  23015. for (var i = 0, l = this.curves.length; i < l; i++) {
  23016. var curve = this.curves[i];
  23017. data.curves.push(curve.toJSON());
  23018. }
  23019. return data;
  23020. },
  23021. fromJSON: function fromJSON(json) {
  23022. Curve.prototype.fromJSON.call(this, json);
  23023. this.autoClose = json.autoClose;
  23024. this.curves = [];
  23025. for (var i = 0, l = json.curves.length; i < l; i++) {
  23026. var curve = json.curves[i];
  23027. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23028. }
  23029. return this;
  23030. }
  23031. });
  23032. function Path(points) {
  23033. CurvePath.call(this);
  23034. this.type = 'Path';
  23035. this.currentPoint = new Vector2();
  23036. if (points) {
  23037. this.setFromPoints(points);
  23038. }
  23039. }
  23040. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  23041. constructor: Path,
  23042. setFromPoints: function setFromPoints(points) {
  23043. this.moveTo(points[0].x, points[0].y);
  23044. for (var i = 1, l = points.length; i < l; i++) {
  23045. this.lineTo(points[i].x, points[i].y);
  23046. }
  23047. return this;
  23048. },
  23049. moveTo: function moveTo(x, y) {
  23050. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23051. return this;
  23052. },
  23053. lineTo: function lineTo(x, y) {
  23054. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23055. this.curves.push(curve);
  23056. this.currentPoint.set(x, y);
  23057. return this;
  23058. },
  23059. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23060. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23061. this.curves.push(curve);
  23062. this.currentPoint.set(aX, aY);
  23063. return this;
  23064. },
  23065. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23066. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23067. this.curves.push(curve);
  23068. this.currentPoint.set(aX, aY);
  23069. return this;
  23070. },
  23071. splineThru: function splineThru(pts
  23072. /*Array of Vector*/
  23073. ) {
  23074. var npts = [this.currentPoint.clone()].concat(pts);
  23075. var curve = new SplineCurve(npts);
  23076. this.curves.push(curve);
  23077. this.currentPoint.copy(pts[pts.length - 1]);
  23078. return this;
  23079. },
  23080. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23081. var x0 = this.currentPoint.x;
  23082. var y0 = this.currentPoint.y;
  23083. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23084. return this;
  23085. },
  23086. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23087. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23088. return this;
  23089. },
  23090. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23091. var x0 = this.currentPoint.x;
  23092. var y0 = this.currentPoint.y;
  23093. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23094. return this;
  23095. },
  23096. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23097. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23098. if (this.curves.length > 0) {
  23099. // if a previous curve is present, attempt to join
  23100. var firstPoint = curve.getPoint(0);
  23101. if (!firstPoint.equals(this.currentPoint)) {
  23102. this.lineTo(firstPoint.x, firstPoint.y);
  23103. }
  23104. }
  23105. this.curves.push(curve);
  23106. var lastPoint = curve.getPoint(1);
  23107. this.currentPoint.copy(lastPoint);
  23108. return this;
  23109. },
  23110. copy: function copy(source) {
  23111. CurvePath.prototype.copy.call(this, source);
  23112. this.currentPoint.copy(source.currentPoint);
  23113. return this;
  23114. },
  23115. toJSON: function toJSON() {
  23116. var data = CurvePath.prototype.toJSON.call(this);
  23117. data.currentPoint = this.currentPoint.toArray();
  23118. return data;
  23119. },
  23120. fromJSON: function fromJSON(json) {
  23121. CurvePath.prototype.fromJSON.call(this, json);
  23122. this.currentPoint.fromArray(json.currentPoint);
  23123. return this;
  23124. }
  23125. });
  23126. function Shape(points) {
  23127. Path.call(this, points);
  23128. this.uuid = MathUtils.generateUUID();
  23129. this.type = 'Shape';
  23130. this.holes = [];
  23131. }
  23132. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23133. constructor: Shape,
  23134. getPointsHoles: function getPointsHoles(divisions) {
  23135. var holesPts = [];
  23136. for (var i = 0, l = this.holes.length; i < l; i++) {
  23137. holesPts[i] = this.holes[i].getPoints(divisions);
  23138. }
  23139. return holesPts;
  23140. },
  23141. // get points of shape and holes (keypoints based on segments parameter)
  23142. extractPoints: function extractPoints(divisions) {
  23143. return {
  23144. shape: this.getPoints(divisions),
  23145. holes: this.getPointsHoles(divisions)
  23146. };
  23147. },
  23148. copy: function copy(source) {
  23149. Path.prototype.copy.call(this, source);
  23150. this.holes = [];
  23151. for (var i = 0, l = source.holes.length; i < l; i++) {
  23152. var hole = source.holes[i];
  23153. this.holes.push(hole.clone());
  23154. }
  23155. return this;
  23156. },
  23157. toJSON: function toJSON() {
  23158. var data = Path.prototype.toJSON.call(this);
  23159. data.uuid = this.uuid;
  23160. data.holes = [];
  23161. for (var i = 0, l = this.holes.length; i < l; i++) {
  23162. var hole = this.holes[i];
  23163. data.holes.push(hole.toJSON());
  23164. }
  23165. return data;
  23166. },
  23167. fromJSON: function fromJSON(json) {
  23168. Path.prototype.fromJSON.call(this, json);
  23169. this.uuid = json.uuid;
  23170. this.holes = [];
  23171. for (var i = 0, l = json.holes.length; i < l; i++) {
  23172. var hole = json.holes[i];
  23173. this.holes.push(new Path().fromJSON(hole));
  23174. }
  23175. return this;
  23176. }
  23177. });
  23178. function Light(color, intensity) {
  23179. Object3D.call(this);
  23180. this.type = 'Light';
  23181. this.color = new Color(color);
  23182. this.intensity = intensity !== undefined ? intensity : 1;
  23183. }
  23184. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23185. constructor: Light,
  23186. isLight: true,
  23187. copy: function copy(source) {
  23188. Object3D.prototype.copy.call(this, source);
  23189. this.color.copy(source.color);
  23190. this.intensity = source.intensity;
  23191. return this;
  23192. },
  23193. toJSON: function toJSON(meta) {
  23194. var data = Object3D.prototype.toJSON.call(this, meta);
  23195. data.object.color = this.color.getHex();
  23196. data.object.intensity = this.intensity;
  23197. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23198. if (this.distance !== undefined) data.object.distance = this.distance;
  23199. if (this.angle !== undefined) data.object.angle = this.angle;
  23200. if (this.decay !== undefined) data.object.decay = this.decay;
  23201. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23202. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23203. return data;
  23204. }
  23205. });
  23206. function HemisphereLight(skyColor, groundColor, intensity) {
  23207. Light.call(this, skyColor, intensity);
  23208. this.type = 'HemisphereLight';
  23209. this.position.copy(Object3D.DefaultUp);
  23210. this.updateMatrix();
  23211. this.groundColor = new Color(groundColor);
  23212. }
  23213. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23214. constructor: HemisphereLight,
  23215. isHemisphereLight: true,
  23216. copy: function copy(source) {
  23217. Light.prototype.copy.call(this, source);
  23218. this.groundColor.copy(source.groundColor);
  23219. return this;
  23220. }
  23221. });
  23222. function LightShadow(camera) {
  23223. this.camera = camera;
  23224. this.bias = 0;
  23225. this.normalBias = 0;
  23226. this.radius = 1;
  23227. this.mapSize = new Vector2(512, 512);
  23228. this.map = null;
  23229. this.mapPass = null;
  23230. this.matrix = new Matrix4();
  23231. this.autoUpdate = true;
  23232. this.needsUpdate = false;
  23233. this._frustum = new Frustum();
  23234. this._frameExtents = new Vector2(1, 1);
  23235. this._viewportCount = 1;
  23236. this._viewports = [new Vector4(0, 0, 1, 1)];
  23237. }
  23238. Object.assign(LightShadow.prototype, {
  23239. _projScreenMatrix: new Matrix4(),
  23240. _lightPositionWorld: new Vector3(),
  23241. _lookTarget: new Vector3(),
  23242. getViewportCount: function getViewportCount() {
  23243. return this._viewportCount;
  23244. },
  23245. getFrustum: function getFrustum() {
  23246. return this._frustum;
  23247. },
  23248. updateMatrices: function updateMatrices(light) {
  23249. var shadowCamera = this.camera,
  23250. shadowMatrix = this.matrix,
  23251. projScreenMatrix = this._projScreenMatrix,
  23252. lookTarget = this._lookTarget,
  23253. lightPositionWorld = this._lightPositionWorld;
  23254. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23255. shadowCamera.position.copy(lightPositionWorld);
  23256. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23257. shadowCamera.lookAt(lookTarget);
  23258. shadowCamera.updateMatrixWorld();
  23259. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23260. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23261. 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);
  23262. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23263. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23264. },
  23265. getViewport: function getViewport(viewportIndex) {
  23266. return this._viewports[viewportIndex];
  23267. },
  23268. getFrameExtents: function getFrameExtents() {
  23269. return this._frameExtents;
  23270. },
  23271. copy: function copy(source) {
  23272. this.camera = source.camera.clone();
  23273. this.bias = source.bias;
  23274. this.radius = source.radius;
  23275. this.mapSize.copy(source.mapSize);
  23276. return this;
  23277. },
  23278. clone: function clone() {
  23279. return new this.constructor().copy(this);
  23280. },
  23281. toJSON: function toJSON() {
  23282. var object = {};
  23283. if (this.bias !== 0) object.bias = this.bias;
  23284. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23285. if (this.radius !== 1) object.radius = this.radius;
  23286. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23287. object.camera = this.camera.toJSON(false).object;
  23288. delete object.camera.matrix;
  23289. return object;
  23290. }
  23291. });
  23292. function SpotLightShadow() {
  23293. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23294. this.focus = 1;
  23295. }
  23296. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23297. constructor: SpotLightShadow,
  23298. isSpotLightShadow: true,
  23299. updateMatrices: function updateMatrices(light) {
  23300. var camera = this.camera;
  23301. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23302. var aspect = this.mapSize.width / this.mapSize.height;
  23303. var far = light.distance || camera.far;
  23304. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23305. camera.fov = fov;
  23306. camera.aspect = aspect;
  23307. camera.far = far;
  23308. camera.updateProjectionMatrix();
  23309. }
  23310. LightShadow.prototype.updateMatrices.call(this, light);
  23311. }
  23312. });
  23313. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23314. Light.call(this, color, intensity);
  23315. this.type = 'SpotLight';
  23316. this.position.copy(Object3D.DefaultUp);
  23317. this.updateMatrix();
  23318. this.target = new Object3D();
  23319. Object.defineProperty(this, 'power', {
  23320. get: function get() {
  23321. // intensity = power per solid angle.
  23322. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23323. return this.intensity * Math.PI;
  23324. },
  23325. set: function set(power) {
  23326. // intensity = power per solid angle.
  23327. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23328. this.intensity = power / Math.PI;
  23329. }
  23330. });
  23331. this.distance = distance !== undefined ? distance : 0;
  23332. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23333. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23334. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23335. this.shadow = new SpotLightShadow();
  23336. }
  23337. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23338. constructor: SpotLight,
  23339. isSpotLight: true,
  23340. copy: function copy(source) {
  23341. Light.prototype.copy.call(this, source);
  23342. this.distance = source.distance;
  23343. this.angle = source.angle;
  23344. this.penumbra = source.penumbra;
  23345. this.decay = source.decay;
  23346. this.target = source.target.clone();
  23347. this.shadow = source.shadow.clone();
  23348. return this;
  23349. }
  23350. });
  23351. function PointLightShadow() {
  23352. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23353. this._frameExtents = new Vector2(4, 2);
  23354. this._viewportCount = 6;
  23355. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23356. // following orientation:
  23357. //
  23358. // xzXZ
  23359. // y Y
  23360. //
  23361. // X - Positive x direction
  23362. // x - Negative x direction
  23363. // Y - Positive y direction
  23364. // y - Negative y direction
  23365. // Z - Positive z direction
  23366. // z - Negative z direction
  23367. // positive X
  23368. new Vector4(2, 1, 1, 1), // negative X
  23369. new Vector4(0, 1, 1, 1), // positive Z
  23370. new Vector4(3, 1, 1, 1), // negative Z
  23371. new Vector4(1, 1, 1, 1), // positive Y
  23372. new Vector4(3, 0, 1, 1), // negative Y
  23373. new Vector4(1, 0, 1, 1)];
  23374. 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)];
  23375. 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)];
  23376. }
  23377. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23378. constructor: PointLightShadow,
  23379. isPointLightShadow: true,
  23380. updateMatrices: function updateMatrices(light, viewportIndex) {
  23381. if (viewportIndex === undefined) viewportIndex = 0;
  23382. var camera = this.camera,
  23383. shadowMatrix = this.matrix,
  23384. lightPositionWorld = this._lightPositionWorld,
  23385. lookTarget = this._lookTarget,
  23386. projScreenMatrix = this._projScreenMatrix;
  23387. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23388. camera.position.copy(lightPositionWorld);
  23389. lookTarget.copy(camera.position);
  23390. lookTarget.add(this._cubeDirections[viewportIndex]);
  23391. camera.up.copy(this._cubeUps[viewportIndex]);
  23392. camera.lookAt(lookTarget);
  23393. camera.updateMatrixWorld();
  23394. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23395. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23396. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23397. }
  23398. });
  23399. function PointLight(color, intensity, distance, decay) {
  23400. Light.call(this, color, intensity);
  23401. this.type = 'PointLight';
  23402. Object.defineProperty(this, 'power', {
  23403. get: function get() {
  23404. // intensity = power per solid angle.
  23405. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23406. return this.intensity * 4 * Math.PI;
  23407. },
  23408. set: function set(power) {
  23409. // intensity = power per solid angle.
  23410. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23411. this.intensity = power / (4 * Math.PI);
  23412. }
  23413. });
  23414. this.distance = distance !== undefined ? distance : 0;
  23415. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23416. this.shadow = new PointLightShadow();
  23417. }
  23418. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23419. constructor: PointLight,
  23420. isPointLight: true,
  23421. copy: function copy(source) {
  23422. Light.prototype.copy.call(this, source);
  23423. this.distance = source.distance;
  23424. this.decay = source.decay;
  23425. this.shadow = source.shadow.clone();
  23426. return this;
  23427. }
  23428. });
  23429. function OrthographicCamera(left, right, top, bottom, near, far) {
  23430. Camera.call(this);
  23431. this.type = 'OrthographicCamera';
  23432. this.zoom = 1;
  23433. this.view = null;
  23434. this.left = left !== undefined ? left : -1;
  23435. this.right = right !== undefined ? right : 1;
  23436. this.top = top !== undefined ? top : 1;
  23437. this.bottom = bottom !== undefined ? bottom : -1;
  23438. this.near = near !== undefined ? near : 0.1;
  23439. this.far = far !== undefined ? far : 2000;
  23440. this.updateProjectionMatrix();
  23441. }
  23442. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23443. constructor: OrthographicCamera,
  23444. isOrthographicCamera: true,
  23445. copy: function copy(source, recursive) {
  23446. Camera.prototype.copy.call(this, source, recursive);
  23447. this.left = source.left;
  23448. this.right = source.right;
  23449. this.top = source.top;
  23450. this.bottom = source.bottom;
  23451. this.near = source.near;
  23452. this.far = source.far;
  23453. this.zoom = source.zoom;
  23454. this.view = source.view === null ? null : Object.assign({}, source.view);
  23455. return this;
  23456. },
  23457. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23458. if (this.view === null) {
  23459. this.view = {
  23460. enabled: true,
  23461. fullWidth: 1,
  23462. fullHeight: 1,
  23463. offsetX: 0,
  23464. offsetY: 0,
  23465. width: 1,
  23466. height: 1
  23467. };
  23468. }
  23469. this.view.enabled = true;
  23470. this.view.fullWidth = fullWidth;
  23471. this.view.fullHeight = fullHeight;
  23472. this.view.offsetX = x;
  23473. this.view.offsetY = y;
  23474. this.view.width = width;
  23475. this.view.height = height;
  23476. this.updateProjectionMatrix();
  23477. },
  23478. clearViewOffset: function clearViewOffset() {
  23479. if (this.view !== null) {
  23480. this.view.enabled = false;
  23481. }
  23482. this.updateProjectionMatrix();
  23483. },
  23484. updateProjectionMatrix: function updateProjectionMatrix() {
  23485. var dx = (this.right - this.left) / (2 * this.zoom);
  23486. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23487. var cx = (this.right + this.left) / 2;
  23488. var cy = (this.top + this.bottom) / 2;
  23489. var left = cx - dx;
  23490. var right = cx + dx;
  23491. var top = cy + dy;
  23492. var bottom = cy - dy;
  23493. if (this.view !== null && this.view.enabled) {
  23494. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23495. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23496. left += scaleW * this.view.offsetX;
  23497. right = left + scaleW * this.view.width;
  23498. top -= scaleH * this.view.offsetY;
  23499. bottom = top - scaleH * this.view.height;
  23500. }
  23501. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23502. this.projectionMatrixInverse.getInverse(this.projectionMatrix);
  23503. },
  23504. toJSON: function toJSON(meta) {
  23505. var data = Object3D.prototype.toJSON.call(this, meta);
  23506. data.object.zoom = this.zoom;
  23507. data.object.left = this.left;
  23508. data.object.right = this.right;
  23509. data.object.top = this.top;
  23510. data.object.bottom = this.bottom;
  23511. data.object.near = this.near;
  23512. data.object.far = this.far;
  23513. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23514. return data;
  23515. }
  23516. });
  23517. function DirectionalLightShadow() {
  23518. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23519. }
  23520. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23521. constructor: DirectionalLightShadow,
  23522. isDirectionalLightShadow: true,
  23523. updateMatrices: function updateMatrices(light) {
  23524. LightShadow.prototype.updateMatrices.call(this, light);
  23525. }
  23526. });
  23527. function DirectionalLight(color, intensity) {
  23528. Light.call(this, color, intensity);
  23529. this.type = 'DirectionalLight';
  23530. this.position.copy(Object3D.DefaultUp);
  23531. this.updateMatrix();
  23532. this.target = new Object3D();
  23533. this.shadow = new DirectionalLightShadow();
  23534. }
  23535. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23536. constructor: DirectionalLight,
  23537. isDirectionalLight: true,
  23538. copy: function copy(source) {
  23539. Light.prototype.copy.call(this, source);
  23540. this.target = source.target.clone();
  23541. this.shadow = source.shadow.clone();
  23542. return this;
  23543. }
  23544. });
  23545. function AmbientLight(color, intensity) {
  23546. Light.call(this, color, intensity);
  23547. this.type = 'AmbientLight';
  23548. }
  23549. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23550. constructor: AmbientLight,
  23551. isAmbientLight: true
  23552. });
  23553. function RectAreaLight(color, intensity, width, height) {
  23554. Light.call(this, color, intensity);
  23555. this.type = 'RectAreaLight';
  23556. this.width = width !== undefined ? width : 10;
  23557. this.height = height !== undefined ? height : 10;
  23558. }
  23559. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23560. constructor: RectAreaLight,
  23561. isRectAreaLight: true,
  23562. copy: function copy(source) {
  23563. Light.prototype.copy.call(this, source);
  23564. this.width = source.width;
  23565. this.height = source.height;
  23566. return this;
  23567. },
  23568. toJSON: function toJSON(meta) {
  23569. var data = Light.prototype.toJSON.call(this, meta);
  23570. data.object.width = this.width;
  23571. data.object.height = this.height;
  23572. return data;
  23573. }
  23574. });
  23575. /**
  23576. * Primary reference:
  23577. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23578. *
  23579. * Secondary reference:
  23580. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23581. */
  23582. // 3-band SH defined by 9 coefficients
  23583. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23584. function SphericalHarmonics3() {
  23585. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23586. value: true
  23587. });
  23588. this.coefficients = [];
  23589. for (var i = 0; i < 9; i++) {
  23590. this.coefficients.push(new Vector3());
  23591. }
  23592. }
  23593. var _proto = SphericalHarmonics3.prototype;
  23594. _proto.set = function set(coefficients) {
  23595. for (var i = 0; i < 9; i++) {
  23596. this.coefficients[i].copy(coefficients[i]);
  23597. }
  23598. return this;
  23599. };
  23600. _proto.zero = function zero() {
  23601. for (var i = 0; i < 9; i++) {
  23602. this.coefficients[i].set(0, 0, 0);
  23603. }
  23604. return this;
  23605. } // get the radiance in the direction of the normal
  23606. // target is a Vector3
  23607. ;
  23608. _proto.getAt = function getAt(normal, target) {
  23609. // normal is assumed to be unit length
  23610. var x = normal.x,
  23611. y = normal.y,
  23612. z = normal.z;
  23613. var coeff = this.coefficients; // band 0
  23614. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23615. target.addScaledVector(coeff[1], 0.488603 * y);
  23616. target.addScaledVector(coeff[2], 0.488603 * z);
  23617. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23618. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23619. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23620. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23621. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23622. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23623. return target;
  23624. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23625. // target is a Vector3
  23626. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23627. ;
  23628. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23629. // normal is assumed to be unit length
  23630. var x = normal.x,
  23631. y = normal.y,
  23632. z = normal.z;
  23633. var coeff = this.coefficients; // band 0
  23634. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23635. // band 1
  23636. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23637. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23638. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23639. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23640. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23641. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23642. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23643. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23644. return target;
  23645. };
  23646. _proto.add = function add(sh) {
  23647. for (var i = 0; i < 9; i++) {
  23648. this.coefficients[i].add(sh.coefficients[i]);
  23649. }
  23650. return this;
  23651. };
  23652. _proto.addScaledSH = function addScaledSH(sh, s) {
  23653. for (var i = 0; i < 9; i++) {
  23654. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23655. }
  23656. return this;
  23657. };
  23658. _proto.scale = function scale(s) {
  23659. for (var i = 0; i < 9; i++) {
  23660. this.coefficients[i].multiplyScalar(s);
  23661. }
  23662. return this;
  23663. };
  23664. _proto.lerp = function lerp(sh, alpha) {
  23665. for (var i = 0; i < 9; i++) {
  23666. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23667. }
  23668. return this;
  23669. };
  23670. _proto.equals = function equals(sh) {
  23671. for (var i = 0; i < 9; i++) {
  23672. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23673. return false;
  23674. }
  23675. }
  23676. return true;
  23677. };
  23678. _proto.copy = function copy(sh) {
  23679. return this.set(sh.coefficients);
  23680. };
  23681. _proto.clone = function clone() {
  23682. return new this.constructor().copy(this);
  23683. };
  23684. _proto.fromArray = function fromArray(array, offset) {
  23685. if (offset === void 0) {
  23686. offset = 0;
  23687. }
  23688. var coefficients = this.coefficients;
  23689. for (var i = 0; i < 9; i++) {
  23690. coefficients[i].fromArray(array, offset + i * 3);
  23691. }
  23692. return this;
  23693. };
  23694. _proto.toArray = function toArray(array, offset) {
  23695. if (array === void 0) {
  23696. array = [];
  23697. }
  23698. if (offset === void 0) {
  23699. offset = 0;
  23700. }
  23701. var coefficients = this.coefficients;
  23702. for (var i = 0; i < 9; i++) {
  23703. coefficients[i].toArray(array, offset + i * 3);
  23704. }
  23705. return array;
  23706. } // evaluate the basis functions
  23707. // shBasis is an Array[ 9 ]
  23708. ;
  23709. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23710. // normal is assumed to be unit length
  23711. var x = normal.x,
  23712. y = normal.y,
  23713. z = normal.z; // band 0
  23714. shBasis[0] = 0.282095; // band 1
  23715. shBasis[1] = 0.488603 * y;
  23716. shBasis[2] = 0.488603 * z;
  23717. shBasis[3] = 0.488603 * x; // band 2
  23718. shBasis[4] = 1.092548 * x * y;
  23719. shBasis[5] = 1.092548 * y * z;
  23720. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23721. shBasis[7] = 1.092548 * x * z;
  23722. shBasis[8] = 0.546274 * (x * x - y * y);
  23723. };
  23724. return SphericalHarmonics3;
  23725. }();
  23726. function LightProbe(sh, intensity) {
  23727. Light.call(this, undefined, intensity);
  23728. this.type = 'LightProbe';
  23729. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23730. }
  23731. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23732. constructor: LightProbe,
  23733. isLightProbe: true,
  23734. copy: function copy(source) {
  23735. Light.prototype.copy.call(this, source);
  23736. this.sh.copy(source.sh);
  23737. return this;
  23738. },
  23739. fromJSON: function fromJSON(json) {
  23740. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23741. this.sh.fromArray(json.sh);
  23742. return this;
  23743. },
  23744. toJSON: function toJSON(meta) {
  23745. var data = Light.prototype.toJSON.call(this, meta);
  23746. data.object.sh = this.sh.toArray();
  23747. return data;
  23748. }
  23749. });
  23750. function MaterialLoader(manager) {
  23751. Loader.call(this, manager);
  23752. this.textures = {};
  23753. }
  23754. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23755. constructor: MaterialLoader,
  23756. load: function load(url, onLoad, onProgress, onError) {
  23757. var scope = this;
  23758. var loader = new FileLoader(scope.manager);
  23759. loader.setPath(scope.path);
  23760. loader.setRequestHeader(scope.requestHeader);
  23761. loader.setWithCredentials(scope.withCredentials);
  23762. loader.load(url, function (text) {
  23763. try {
  23764. onLoad(scope.parse(JSON.parse(text)));
  23765. } catch (e) {
  23766. if (onError) {
  23767. onError(e);
  23768. } else {
  23769. console.error(e);
  23770. }
  23771. scope.manager.itemError(url);
  23772. }
  23773. }, onProgress, onError);
  23774. },
  23775. parse: function parse(json) {
  23776. var textures = this.textures;
  23777. function getTexture(name) {
  23778. if (textures[name] === undefined) {
  23779. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23780. }
  23781. return textures[name];
  23782. }
  23783. var material = new Materials[json.type]();
  23784. if (json.uuid !== undefined) material.uuid = json.uuid;
  23785. if (json.name !== undefined) material.name = json.name;
  23786. if (json.color !== undefined) material.color.setHex(json.color);
  23787. if (json.roughness !== undefined) material.roughness = json.roughness;
  23788. if (json.metalness !== undefined) material.metalness = json.metalness;
  23789. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23790. if (json.emissive !== undefined) material.emissive.setHex(json.emissive);
  23791. if (json.specular !== undefined) material.specular.setHex(json.specular);
  23792. if (json.shininess !== undefined) material.shininess = json.shininess;
  23793. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23794. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23795. if (json.fog !== undefined) material.fog = json.fog;
  23796. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23797. if (json.blending !== undefined) material.blending = json.blending;
  23798. if (json.combine !== undefined) material.combine = json.combine;
  23799. if (json.side !== undefined) material.side = json.side;
  23800. if (json.opacity !== undefined) material.opacity = json.opacity;
  23801. if (json.transparent !== undefined) material.transparent = json.transparent;
  23802. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23803. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23804. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23805. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23806. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23807. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23808. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23809. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23810. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23811. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23812. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23813. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23814. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23815. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23816. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23817. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23818. if (json.rotation !== undefined) material.rotation = json.rotation;
  23819. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23820. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23821. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23822. if (json.scale !== undefined) material.scale = json.scale;
  23823. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23824. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23825. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23826. if (json.skinning !== undefined) material.skinning = json.skinning;
  23827. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23828. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23829. if (json.dithering !== undefined) material.dithering = json.dithering;
  23830. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23831. if (json.visible !== undefined) material.visible = json.visible;
  23832. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23833. if (json.userData !== undefined) material.userData = json.userData;
  23834. if (json.vertexColors !== undefined) {
  23835. if (typeof json.vertexColors === 'number') {
  23836. material.vertexColors = json.vertexColors > 0 ? true : false;
  23837. } else {
  23838. material.vertexColors = json.vertexColors;
  23839. }
  23840. } // Shader Material
  23841. if (json.uniforms !== undefined) {
  23842. for (var name in json.uniforms) {
  23843. var uniform = json.uniforms[name];
  23844. material.uniforms[name] = {};
  23845. switch (uniform.type) {
  23846. case 't':
  23847. material.uniforms[name].value = getTexture(uniform.value);
  23848. break;
  23849. case 'c':
  23850. material.uniforms[name].value = new Color().setHex(uniform.value);
  23851. break;
  23852. case 'v2':
  23853. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23854. break;
  23855. case 'v3':
  23856. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23857. break;
  23858. case 'v4':
  23859. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23860. break;
  23861. case 'm3':
  23862. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23863. break;
  23864. case 'm4':
  23865. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23866. break;
  23867. default:
  23868. material.uniforms[name].value = uniform.value;
  23869. }
  23870. }
  23871. }
  23872. if (json.defines !== undefined) material.defines = json.defines;
  23873. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23874. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23875. if (json.extensions !== undefined) {
  23876. for (var key in json.extensions) {
  23877. material.extensions[key] = json.extensions[key];
  23878. }
  23879. } // Deprecated
  23880. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23881. // for PointsMaterial
  23882. if (json.size !== undefined) material.size = json.size;
  23883. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23884. if (json.map !== undefined) material.map = getTexture(json.map);
  23885. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23886. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23887. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23888. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23889. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23890. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23891. if (json.normalScale !== undefined) {
  23892. var normalScale = json.normalScale;
  23893. if (Array.isArray(normalScale) === false) {
  23894. // Blender exporter used to export a scalar. See #7459
  23895. normalScale = [normalScale, normalScale];
  23896. }
  23897. material.normalScale = new Vector2().fromArray(normalScale);
  23898. }
  23899. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23900. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23901. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23902. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23903. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23904. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23905. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23906. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23907. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23908. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23909. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23910. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23911. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23912. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23913. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23914. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23915. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23916. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23917. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23918. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23919. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  23920. if (json.transmission !== undefined) material.transmission = json.transmission;
  23921. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  23922. return material;
  23923. },
  23924. setTextures: function setTextures(value) {
  23925. this.textures = value;
  23926. return this;
  23927. }
  23928. });
  23929. var LoaderUtils = {
  23930. decodeText: function decodeText(array) {
  23931. if (typeof TextDecoder !== 'undefined') {
  23932. return new TextDecoder().decode(array);
  23933. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23934. // throws a "maximum call stack size exceeded" error for large arrays.
  23935. var s = '';
  23936. for (var i = 0, il = array.length; i < il; i++) {
  23937. // Implicitly assumes little-endian.
  23938. s += String.fromCharCode(array[i]);
  23939. }
  23940. try {
  23941. // merges multi-byte utf-8 characters.
  23942. return decodeURIComponent(escape(s));
  23943. } catch (e) {
  23944. // see #16358
  23945. return s;
  23946. }
  23947. },
  23948. extractUrlBase: function extractUrlBase(url) {
  23949. var index = url.lastIndexOf('/');
  23950. if (index === -1) return './';
  23951. return url.substr(0, index + 1);
  23952. }
  23953. };
  23954. function InstancedBufferGeometry() {
  23955. BufferGeometry.call(this);
  23956. this.type = 'InstancedBufferGeometry';
  23957. this.instanceCount = Infinity;
  23958. }
  23959. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  23960. constructor: InstancedBufferGeometry,
  23961. isInstancedBufferGeometry: true,
  23962. copy: function copy(source) {
  23963. BufferGeometry.prototype.copy.call(this, source);
  23964. this.instanceCount = source.instanceCount;
  23965. return this;
  23966. },
  23967. clone: function clone() {
  23968. return new this.constructor().copy(this);
  23969. },
  23970. toJSON: function toJSON() {
  23971. var data = BufferGeometry.prototype.toJSON.call(this);
  23972. data.instanceCount = this.instanceCount;
  23973. data.isInstancedBufferGeometry = true;
  23974. return data;
  23975. }
  23976. });
  23977. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  23978. if (typeof normalized === 'number') {
  23979. meshPerAttribute = normalized;
  23980. normalized = false;
  23981. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  23982. }
  23983. BufferAttribute.call(this, array, itemSize, normalized);
  23984. this.meshPerAttribute = meshPerAttribute || 1;
  23985. }
  23986. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  23987. constructor: InstancedBufferAttribute,
  23988. isInstancedBufferAttribute: true,
  23989. copy: function copy(source) {
  23990. BufferAttribute.prototype.copy.call(this, source);
  23991. this.meshPerAttribute = source.meshPerAttribute;
  23992. return this;
  23993. },
  23994. toJSON: function toJSON() {
  23995. var data = BufferAttribute.prototype.toJSON.call(this);
  23996. data.meshPerAttribute = this.meshPerAttribute;
  23997. data.isInstancedBufferAttribute = true;
  23998. return data;
  23999. }
  24000. });
  24001. function BufferGeometryLoader(manager) {
  24002. Loader.call(this, manager);
  24003. }
  24004. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24005. constructor: BufferGeometryLoader,
  24006. load: function load(url, onLoad, onProgress, onError) {
  24007. var scope = this;
  24008. var loader = new FileLoader(scope.manager);
  24009. loader.setPath(scope.path);
  24010. loader.setRequestHeader(scope.requestHeader);
  24011. loader.setWithCredentials(scope.withCredentials);
  24012. loader.load(url, function (text) {
  24013. try {
  24014. onLoad(scope.parse(JSON.parse(text)));
  24015. } catch (e) {
  24016. if (onError) {
  24017. onError(e);
  24018. } else {
  24019. console.error(e);
  24020. }
  24021. scope.manager.itemError(url);
  24022. }
  24023. }, onProgress, onError);
  24024. },
  24025. parse: function parse(json) {
  24026. var interleavedBufferMap = {};
  24027. var arrayBufferMap = {};
  24028. function getInterleavedBuffer(json, uuid) {
  24029. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24030. var interleavedBuffers = json.interleavedBuffers;
  24031. var interleavedBuffer = interleavedBuffers[uuid];
  24032. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24033. var array = new TYPED_ARRAYS[interleavedBuffer.type](buffer);
  24034. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24035. ib.uuid = interleavedBuffer.uuid;
  24036. interleavedBufferMap[uuid] = ib;
  24037. return ib;
  24038. }
  24039. function getArrayBuffer(json, uuid) {
  24040. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24041. var arrayBuffers = json.arrayBuffers;
  24042. var arrayBuffer = arrayBuffers[uuid];
  24043. var ab = new Uint32Array(arrayBuffer).buffer;
  24044. arrayBufferMap[uuid] = ab;
  24045. return ab;
  24046. }
  24047. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24048. var index = json.data.index;
  24049. if (index !== undefined) {
  24050. var typedArray = new TYPED_ARRAYS[index.type](index.array);
  24051. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24052. }
  24053. var attributes = json.data.attributes;
  24054. for (var key in attributes) {
  24055. var attribute = attributes[key];
  24056. var bufferAttribute = void 0;
  24057. if (attribute.isInterleavedBufferAttribute) {
  24058. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24059. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24060. } else {
  24061. var _typedArray = new TYPED_ARRAYS[attribute.type](attribute.array);
  24062. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24063. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24064. }
  24065. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24066. geometry.setAttribute(key, bufferAttribute);
  24067. }
  24068. var morphAttributes = json.data.morphAttributes;
  24069. if (morphAttributes) {
  24070. for (var _key in morphAttributes) {
  24071. var attributeArray = morphAttributes[_key];
  24072. var array = [];
  24073. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24074. var _attribute = attributeArray[i];
  24075. var _bufferAttribute = void 0;
  24076. if (_attribute.isInterleavedBufferAttribute) {
  24077. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24078. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24079. } else {
  24080. var _typedArray2 = new TYPED_ARRAYS[_attribute.type](_attribute.array);
  24081. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24082. }
  24083. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24084. array.push(_bufferAttribute);
  24085. }
  24086. geometry.morphAttributes[_key] = array;
  24087. }
  24088. }
  24089. var morphTargetsRelative = json.data.morphTargetsRelative;
  24090. if (morphTargetsRelative) {
  24091. geometry.morphTargetsRelative = true;
  24092. }
  24093. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24094. if (groups !== undefined) {
  24095. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24096. var group = groups[_i];
  24097. geometry.addGroup(group.start, group.count, group.materialIndex);
  24098. }
  24099. }
  24100. var boundingSphere = json.data.boundingSphere;
  24101. if (boundingSphere !== undefined) {
  24102. var center = new Vector3();
  24103. if (boundingSphere.center !== undefined) {
  24104. center.fromArray(boundingSphere.center);
  24105. }
  24106. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24107. }
  24108. if (json.name) geometry.name = json.name;
  24109. if (json.userData) geometry.userData = json.userData;
  24110. return geometry;
  24111. }
  24112. });
  24113. var TYPED_ARRAYS = {
  24114. Int8Array: Int8Array,
  24115. Uint8Array: Uint8Array,
  24116. // Workaround for IE11 pre KB2929437. See #11440
  24117. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  24118. Int16Array: Int16Array,
  24119. Uint16Array: Uint16Array,
  24120. Int32Array: Int32Array,
  24121. Uint32Array: Uint32Array,
  24122. Float32Array: Float32Array,
  24123. Float64Array: Float64Array
  24124. };
  24125. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24126. _inheritsLoose(ObjectLoader, _Loader);
  24127. function ObjectLoader(manager) {
  24128. return _Loader.call(this, manager) || this;
  24129. }
  24130. var _proto = ObjectLoader.prototype;
  24131. _proto.load = function load(url, onLoad, onProgress, onError) {
  24132. var scope = this;
  24133. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24134. this.resourcePath = this.resourcePath || path;
  24135. var loader = new FileLoader(this.manager);
  24136. loader.setPath(this.path);
  24137. loader.setRequestHeader(this.requestHeader);
  24138. loader.setWithCredentials(this.withCredentials);
  24139. loader.load(url, function (text) {
  24140. var json = null;
  24141. try {
  24142. json = JSON.parse(text);
  24143. } catch (error) {
  24144. if (onError !== undefined) onError(error);
  24145. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24146. return;
  24147. }
  24148. var metadata = json.metadata;
  24149. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24150. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24151. return;
  24152. }
  24153. scope.parse(json, onLoad);
  24154. }, onProgress, onError);
  24155. };
  24156. _proto.parse = function parse(json, onLoad) {
  24157. var shapes = this.parseShape(json.shapes);
  24158. var geometries = this.parseGeometries(json.geometries, shapes);
  24159. var images = this.parseImages(json.images, function () {
  24160. if (onLoad !== undefined) onLoad(object);
  24161. });
  24162. var textures = this.parseTextures(json.textures, images);
  24163. var materials = this.parseMaterials(json.materials, textures);
  24164. var object = this.parseObject(json.object, geometries, materials);
  24165. if (json.animations) {
  24166. object.animations = this.parseAnimations(json.animations);
  24167. }
  24168. if (json.images === undefined || json.images.length === 0) {
  24169. if (onLoad !== undefined) onLoad(object);
  24170. }
  24171. return object;
  24172. };
  24173. _proto.parseShape = function parseShape(json) {
  24174. var shapes = {};
  24175. if (json !== undefined) {
  24176. for (var i = 0, l = json.length; i < l; i++) {
  24177. var shape = new Shape().fromJSON(json[i]);
  24178. shapes[shape.uuid] = shape;
  24179. }
  24180. }
  24181. return shapes;
  24182. };
  24183. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24184. var geometries = {};
  24185. var geometryShapes;
  24186. if (json !== undefined) {
  24187. var bufferGeometryLoader = new BufferGeometryLoader();
  24188. for (var i = 0, l = json.length; i < l; i++) {
  24189. var geometry = void 0;
  24190. var data = json[i];
  24191. switch (data.type) {
  24192. case 'PlaneGeometry':
  24193. case 'PlaneBufferGeometry':
  24194. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24195. break;
  24196. case 'BoxGeometry':
  24197. case 'BoxBufferGeometry':
  24198. case 'CubeGeometry':
  24199. // backwards compatible
  24200. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24201. break;
  24202. case 'CircleGeometry':
  24203. case 'CircleBufferGeometry':
  24204. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24205. break;
  24206. case 'CylinderGeometry':
  24207. case 'CylinderBufferGeometry':
  24208. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24209. break;
  24210. case 'ConeGeometry':
  24211. case 'ConeBufferGeometry':
  24212. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24213. break;
  24214. case 'SphereGeometry':
  24215. case 'SphereBufferGeometry':
  24216. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24217. break;
  24218. case 'DodecahedronGeometry':
  24219. case 'DodecahedronBufferGeometry':
  24220. case 'IcosahedronGeometry':
  24221. case 'IcosahedronBufferGeometry':
  24222. case 'OctahedronGeometry':
  24223. case 'OctahedronBufferGeometry':
  24224. case 'TetrahedronGeometry':
  24225. case 'TetrahedronBufferGeometry':
  24226. geometry = new Geometries[data.type](data.radius, data.detail);
  24227. break;
  24228. case 'RingGeometry':
  24229. case 'RingBufferGeometry':
  24230. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24231. break;
  24232. case 'TorusGeometry':
  24233. case 'TorusBufferGeometry':
  24234. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24235. break;
  24236. case 'TorusKnotGeometry':
  24237. case 'TorusKnotBufferGeometry':
  24238. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24239. break;
  24240. case 'TubeGeometry':
  24241. case 'TubeBufferGeometry':
  24242. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24243. // User defined curves or instances of CurvePath will not be deserialized.
  24244. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24245. break;
  24246. case 'LatheGeometry':
  24247. case 'LatheBufferGeometry':
  24248. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24249. break;
  24250. case 'PolyhedronGeometry':
  24251. case 'PolyhedronBufferGeometry':
  24252. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24253. break;
  24254. case 'ShapeGeometry':
  24255. case 'ShapeBufferGeometry':
  24256. geometryShapes = [];
  24257. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24258. var shape = shapes[data.shapes[j]];
  24259. geometryShapes.push(shape);
  24260. }
  24261. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24262. break;
  24263. case 'ExtrudeGeometry':
  24264. case 'ExtrudeBufferGeometry':
  24265. geometryShapes = [];
  24266. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24267. var _shape = shapes[data.shapes[_j]];
  24268. geometryShapes.push(_shape);
  24269. }
  24270. var extrudePath = data.options.extrudePath;
  24271. if (extrudePath !== undefined) {
  24272. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24273. }
  24274. geometry = new Geometries[data.type](geometryShapes, data.options);
  24275. break;
  24276. case 'BufferGeometry':
  24277. case 'InstancedBufferGeometry':
  24278. geometry = bufferGeometryLoader.parse(data);
  24279. break;
  24280. case 'Geometry':
  24281. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24282. break;
  24283. default:
  24284. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24285. continue;
  24286. }
  24287. geometry.uuid = data.uuid;
  24288. if (data.name !== undefined) geometry.name = data.name;
  24289. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24290. geometries[data.uuid] = geometry;
  24291. }
  24292. }
  24293. return geometries;
  24294. };
  24295. _proto.parseMaterials = function parseMaterials(json, textures) {
  24296. var cache = {}; // MultiMaterial
  24297. var materials = {};
  24298. if (json !== undefined) {
  24299. var loader = new MaterialLoader();
  24300. loader.setTextures(textures);
  24301. for (var i = 0, l = json.length; i < l; i++) {
  24302. var data = json[i];
  24303. if (data.type === 'MultiMaterial') {
  24304. // Deprecated
  24305. var array = [];
  24306. for (var j = 0; j < data.materials.length; j++) {
  24307. var material = data.materials[j];
  24308. if (cache[material.uuid] === undefined) {
  24309. cache[material.uuid] = loader.parse(material);
  24310. }
  24311. array.push(cache[material.uuid]);
  24312. }
  24313. materials[data.uuid] = array;
  24314. } else {
  24315. if (cache[data.uuid] === undefined) {
  24316. cache[data.uuid] = loader.parse(data);
  24317. }
  24318. materials[data.uuid] = cache[data.uuid];
  24319. }
  24320. }
  24321. }
  24322. return materials;
  24323. };
  24324. _proto.parseAnimations = function parseAnimations(json) {
  24325. var animations = [];
  24326. for (var i = 0; i < json.length; i++) {
  24327. var data = json[i];
  24328. var clip = AnimationClip.parse(data);
  24329. if (data.uuid !== undefined) clip.uuid = data.uuid;
  24330. animations.push(clip);
  24331. }
  24332. return animations;
  24333. };
  24334. _proto.parseImages = function parseImages(json, onLoad) {
  24335. var scope = this;
  24336. var images = {};
  24337. var loader;
  24338. function loadImage(url) {
  24339. scope.manager.itemStart(url);
  24340. return loader.load(url, function () {
  24341. scope.manager.itemEnd(url);
  24342. }, undefined, function () {
  24343. scope.manager.itemError(url);
  24344. scope.manager.itemEnd(url);
  24345. });
  24346. }
  24347. if (json !== undefined && json.length > 0) {
  24348. var manager = new LoadingManager(onLoad);
  24349. loader = new ImageLoader(manager);
  24350. loader.setCrossOrigin(this.crossOrigin);
  24351. for (var i = 0, il = json.length; i < il; i++) {
  24352. var image = json[i];
  24353. var url = image.url;
  24354. if (Array.isArray(url)) {
  24355. // load array of images e.g CubeTexture
  24356. images[image.uuid] = [];
  24357. for (var j = 0, jl = url.length; j < jl; j++) {
  24358. var currentUrl = url[j];
  24359. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(currentUrl) ? currentUrl : scope.resourcePath + currentUrl;
  24360. images[image.uuid].push(loadImage(path));
  24361. }
  24362. } else {
  24363. // load single image
  24364. var _path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(image.url) ? image.url : scope.resourcePath + image.url;
  24365. images[image.uuid] = loadImage(_path);
  24366. }
  24367. }
  24368. }
  24369. return images;
  24370. };
  24371. _proto.parseTextures = function parseTextures(json, images) {
  24372. function parseConstant(value, type) {
  24373. if (typeof value === 'number') return value;
  24374. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24375. return type[value];
  24376. }
  24377. var textures = {};
  24378. if (json !== undefined) {
  24379. for (var i = 0, l = json.length; i < l; i++) {
  24380. var data = json[i];
  24381. if (data.image === undefined) {
  24382. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24383. }
  24384. if (images[data.image] === undefined) {
  24385. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24386. }
  24387. var texture = void 0;
  24388. if (Array.isArray(images[data.image])) {
  24389. texture = new CubeTexture(images[data.image]);
  24390. } else {
  24391. texture = new Texture(images[data.image]);
  24392. }
  24393. texture.needsUpdate = true;
  24394. texture.uuid = data.uuid;
  24395. if (data.name !== undefined) texture.name = data.name;
  24396. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24397. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24398. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24399. if (data.center !== undefined) texture.center.fromArray(data.center);
  24400. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24401. if (data.wrap !== undefined) {
  24402. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24403. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24404. }
  24405. if (data.format !== undefined) texture.format = data.format;
  24406. if (data.type !== undefined) texture.type = data.type;
  24407. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24408. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24409. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24410. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24411. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24412. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24413. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24414. textures[data.uuid] = texture;
  24415. }
  24416. }
  24417. return textures;
  24418. };
  24419. _proto.parseObject = function parseObject(data, geometries, materials) {
  24420. var object;
  24421. function getGeometry(name) {
  24422. if (geometries[name] === undefined) {
  24423. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24424. }
  24425. return geometries[name];
  24426. }
  24427. function getMaterial(name) {
  24428. if (name === undefined) return undefined;
  24429. if (Array.isArray(name)) {
  24430. var array = [];
  24431. for (var i = 0, l = name.length; i < l; i++) {
  24432. var uuid = name[i];
  24433. if (materials[uuid] === undefined) {
  24434. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24435. }
  24436. array.push(materials[uuid]);
  24437. }
  24438. return array;
  24439. }
  24440. if (materials[name] === undefined) {
  24441. console.warn('THREE.ObjectLoader: Undefined material', name);
  24442. }
  24443. return materials[name];
  24444. }
  24445. var geometry, material;
  24446. switch (data.type) {
  24447. case 'Scene':
  24448. object = new Scene();
  24449. if (data.background !== undefined) {
  24450. if (Number.isInteger(data.background)) {
  24451. object.background = new Color(data.background);
  24452. }
  24453. }
  24454. if (data.fog !== undefined) {
  24455. if (data.fog.type === 'Fog') {
  24456. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24457. } else if (data.fog.type === 'FogExp2') {
  24458. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24459. }
  24460. }
  24461. break;
  24462. case 'PerspectiveCamera':
  24463. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24464. if (data.focus !== undefined) object.focus = data.focus;
  24465. if (data.zoom !== undefined) object.zoom = data.zoom;
  24466. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24467. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24468. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24469. break;
  24470. case 'OrthographicCamera':
  24471. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24472. if (data.zoom !== undefined) object.zoom = data.zoom;
  24473. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24474. break;
  24475. case 'AmbientLight':
  24476. object = new AmbientLight(data.color, data.intensity);
  24477. break;
  24478. case 'DirectionalLight':
  24479. object = new DirectionalLight(data.color, data.intensity);
  24480. break;
  24481. case 'PointLight':
  24482. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24483. break;
  24484. case 'RectAreaLight':
  24485. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24486. break;
  24487. case 'SpotLight':
  24488. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24489. break;
  24490. case 'HemisphereLight':
  24491. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24492. break;
  24493. case 'LightProbe':
  24494. object = new LightProbe().fromJSON(data);
  24495. break;
  24496. case 'SkinnedMesh':
  24497. console.warn('THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.');
  24498. case 'Mesh':
  24499. geometry = getGeometry(data.geometry);
  24500. material = getMaterial(data.material);
  24501. object = new Mesh(geometry, material);
  24502. break;
  24503. case 'InstancedMesh':
  24504. geometry = getGeometry(data.geometry);
  24505. material = getMaterial(data.material);
  24506. var count = data.count;
  24507. var instanceMatrix = data.instanceMatrix;
  24508. object = new InstancedMesh(geometry, material, count);
  24509. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24510. break;
  24511. case 'LOD':
  24512. object = new LOD();
  24513. break;
  24514. case 'Line':
  24515. object = new Line(getGeometry(data.geometry), getMaterial(data.material), data.mode);
  24516. break;
  24517. case 'LineLoop':
  24518. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24519. break;
  24520. case 'LineSegments':
  24521. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24522. break;
  24523. case 'PointCloud':
  24524. case 'Points':
  24525. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24526. break;
  24527. case 'Sprite':
  24528. object = new Sprite(getMaterial(data.material));
  24529. break;
  24530. case 'Group':
  24531. object = new Group();
  24532. break;
  24533. default:
  24534. object = new Object3D();
  24535. }
  24536. object.uuid = data.uuid;
  24537. if (data.name !== undefined) object.name = data.name;
  24538. if (data.matrix !== undefined) {
  24539. object.matrix.fromArray(data.matrix);
  24540. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24541. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24542. } else {
  24543. if (data.position !== undefined) object.position.fromArray(data.position);
  24544. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24545. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24546. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24547. }
  24548. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24549. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24550. if (data.shadow) {
  24551. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24552. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24553. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24554. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24555. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24556. }
  24557. if (data.visible !== undefined) object.visible = data.visible;
  24558. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24559. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24560. if (data.userData !== undefined) object.userData = data.userData;
  24561. if (data.layers !== undefined) object.layers.mask = data.layers;
  24562. if (data.children !== undefined) {
  24563. var children = data.children;
  24564. for (var i = 0; i < children.length; i++) {
  24565. object.add(this.parseObject(children[i], geometries, materials));
  24566. }
  24567. }
  24568. if (data.type === 'LOD') {
  24569. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24570. var levels = data.levels;
  24571. for (var l = 0; l < levels.length; l++) {
  24572. var level = levels[l];
  24573. var child = object.getObjectByProperty('uuid', level.object);
  24574. if (child !== undefined) {
  24575. object.addLevel(child, level.distance);
  24576. }
  24577. }
  24578. }
  24579. return object;
  24580. }
  24581. /* DEPRECATED */
  24582. ;
  24583. _proto.setTexturePath = function setTexturePath(value) {
  24584. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24585. return this.setResourcePath(value);
  24586. };
  24587. return ObjectLoader;
  24588. }(Loader);
  24589. var TEXTURE_MAPPING = {
  24590. UVMapping: UVMapping,
  24591. CubeReflectionMapping: CubeReflectionMapping,
  24592. CubeRefractionMapping: CubeRefractionMapping,
  24593. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24594. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24595. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24596. CubeUVRefractionMapping: CubeUVRefractionMapping
  24597. };
  24598. var TEXTURE_WRAPPING = {
  24599. RepeatWrapping: RepeatWrapping,
  24600. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24601. MirroredRepeatWrapping: MirroredRepeatWrapping
  24602. };
  24603. var TEXTURE_FILTER = {
  24604. NearestFilter: NearestFilter,
  24605. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24606. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24607. LinearFilter: LinearFilter,
  24608. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24609. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24610. };
  24611. function ImageBitmapLoader(manager) {
  24612. if (typeof createImageBitmap === 'undefined') {
  24613. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24614. }
  24615. if (typeof fetch === 'undefined') {
  24616. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24617. }
  24618. Loader.call(this, manager);
  24619. this.options = {
  24620. premultiplyAlpha: 'none'
  24621. };
  24622. }
  24623. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24624. constructor: ImageBitmapLoader,
  24625. isImageBitmapLoader: true,
  24626. setOptions: function setOptions(options) {
  24627. this.options = options;
  24628. return this;
  24629. },
  24630. load: function load(url, onLoad, onProgress, onError) {
  24631. if (url === undefined) url = '';
  24632. if (this.path !== undefined) url = this.path + url;
  24633. url = this.manager.resolveURL(url);
  24634. var scope = this;
  24635. var cached = Cache.get(url);
  24636. if (cached !== undefined) {
  24637. scope.manager.itemStart(url);
  24638. setTimeout(function () {
  24639. if (onLoad) onLoad(cached);
  24640. scope.manager.itemEnd(url);
  24641. }, 0);
  24642. return cached;
  24643. }
  24644. var fetchOptions = {};
  24645. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24646. fetch(url, fetchOptions).then(function (res) {
  24647. return res.blob();
  24648. }).then(function (blob) {
  24649. return createImageBitmap(blob, scope.options);
  24650. }).then(function (imageBitmap) {
  24651. Cache.add(url, imageBitmap);
  24652. if (onLoad) onLoad(imageBitmap);
  24653. scope.manager.itemEnd(url);
  24654. }).catch(function (e) {
  24655. if (onError) onError(e);
  24656. scope.manager.itemError(url);
  24657. scope.manager.itemEnd(url);
  24658. });
  24659. scope.manager.itemStart(url);
  24660. }
  24661. });
  24662. function ShapePath() {
  24663. this.type = 'ShapePath';
  24664. this.color = new Color();
  24665. this.subPaths = [];
  24666. this.currentPath = null;
  24667. }
  24668. Object.assign(ShapePath.prototype, {
  24669. moveTo: function moveTo(x, y) {
  24670. this.currentPath = new Path();
  24671. this.subPaths.push(this.currentPath);
  24672. this.currentPath.moveTo(x, y);
  24673. return this;
  24674. },
  24675. lineTo: function lineTo(x, y) {
  24676. this.currentPath.lineTo(x, y);
  24677. return this;
  24678. },
  24679. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24680. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24681. return this;
  24682. },
  24683. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24684. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24685. return this;
  24686. },
  24687. splineThru: function splineThru(pts) {
  24688. this.currentPath.splineThru(pts);
  24689. return this;
  24690. },
  24691. toShapes: function toShapes(isCCW, noHoles) {
  24692. function toShapesNoHoles(inSubpaths) {
  24693. var shapes = [];
  24694. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24695. var _tmpPath = inSubpaths[i];
  24696. var _tmpShape = new Shape();
  24697. _tmpShape.curves = _tmpPath.curves;
  24698. shapes.push(_tmpShape);
  24699. }
  24700. return shapes;
  24701. }
  24702. function isPointInsidePolygon(inPt, inPolygon) {
  24703. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24704. // toggling of inside/outside at every single! intersection point of an edge
  24705. // with the horizontal line through inPt, left of inPt
  24706. // not counting lowerY endpoints of edges and whole edges on that line
  24707. var inside = false;
  24708. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24709. var edgeLowPt = inPolygon[p];
  24710. var edgeHighPt = inPolygon[q];
  24711. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24712. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24713. if (Math.abs(edgeDy) > Number.EPSILON) {
  24714. // not parallel
  24715. if (edgeDy < 0) {
  24716. edgeLowPt = inPolygon[q];
  24717. edgeDx = -edgeDx;
  24718. edgeHighPt = inPolygon[p];
  24719. edgeDy = -edgeDy;
  24720. }
  24721. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24722. if (inPt.y === edgeLowPt.y) {
  24723. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24724. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24725. } else {
  24726. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24727. if (perpEdge === 0) return true; // inPt is on contour ?
  24728. if (perpEdge < 0) continue;
  24729. inside = !inside; // true intersection left of inPt
  24730. }
  24731. } else {
  24732. // parallel or collinear
  24733. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24734. // edge lies on the same horizontal line as inPt
  24735. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24736. // continue;
  24737. }
  24738. }
  24739. return inside;
  24740. }
  24741. var isClockWise = ShapeUtils.isClockWise;
  24742. var subPaths = this.subPaths;
  24743. if (subPaths.length === 0) return [];
  24744. if (noHoles === true) return toShapesNoHoles(subPaths);
  24745. var solid, tmpPath, tmpShape;
  24746. var shapes = [];
  24747. if (subPaths.length === 1) {
  24748. tmpPath = subPaths[0];
  24749. tmpShape = new Shape();
  24750. tmpShape.curves = tmpPath.curves;
  24751. shapes.push(tmpShape);
  24752. return shapes;
  24753. }
  24754. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24755. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24756. var betterShapeHoles = [];
  24757. var newShapes = [];
  24758. var newShapeHoles = [];
  24759. var mainIdx = 0;
  24760. var tmpPoints;
  24761. newShapes[mainIdx] = undefined;
  24762. newShapeHoles[mainIdx] = [];
  24763. for (var i = 0, l = subPaths.length; i < l; i++) {
  24764. tmpPath = subPaths[i];
  24765. tmpPoints = tmpPath.getPoints();
  24766. solid = isClockWise(tmpPoints);
  24767. solid = isCCW ? !solid : solid;
  24768. if (solid) {
  24769. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24770. newShapes[mainIdx] = {
  24771. s: new Shape(),
  24772. p: tmpPoints
  24773. };
  24774. newShapes[mainIdx].s.curves = tmpPath.curves;
  24775. if (holesFirst) mainIdx++;
  24776. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24777. } else {
  24778. newShapeHoles[mainIdx].push({
  24779. h: tmpPath,
  24780. p: tmpPoints[0]
  24781. }); //console.log('ccw', i);
  24782. }
  24783. } // only Holes? -> probably all Shapes with wrong orientation
  24784. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24785. if (newShapes.length > 1) {
  24786. var ambiguous = false;
  24787. var toChange = [];
  24788. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24789. betterShapeHoles[sIdx] = [];
  24790. }
  24791. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24792. var sho = newShapeHoles[_sIdx];
  24793. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24794. var ho = sho[hIdx];
  24795. var hole_unassigned = true;
  24796. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24797. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24798. if (_sIdx !== s2Idx) toChange.push({
  24799. froms: _sIdx,
  24800. tos: s2Idx,
  24801. hole: hIdx
  24802. });
  24803. if (hole_unassigned) {
  24804. hole_unassigned = false;
  24805. betterShapeHoles[s2Idx].push(ho);
  24806. } else {
  24807. ambiguous = true;
  24808. }
  24809. }
  24810. }
  24811. if (hole_unassigned) {
  24812. betterShapeHoles[_sIdx].push(ho);
  24813. }
  24814. }
  24815. } // console.log("ambiguous: ", ambiguous);
  24816. if (toChange.length > 0) {
  24817. // console.log("to change: ", toChange);
  24818. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24819. }
  24820. }
  24821. var tmpHoles;
  24822. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24823. tmpShape = newShapes[_i].s;
  24824. shapes.push(tmpShape);
  24825. tmpHoles = newShapeHoles[_i];
  24826. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24827. tmpShape.holes.push(tmpHoles[j].h);
  24828. }
  24829. } //console.log("shape", shapes);
  24830. return shapes;
  24831. }
  24832. });
  24833. function Font(data) {
  24834. this.type = 'Font';
  24835. this.data = data;
  24836. }
  24837. Object.assign(Font.prototype, {
  24838. isFont: true,
  24839. generateShapes: function generateShapes(text, size) {
  24840. if (size === undefined) size = 100;
  24841. var shapes = [];
  24842. var paths = createPaths(text, size, this.data);
  24843. for (var p = 0, pl = paths.length; p < pl; p++) {
  24844. Array.prototype.push.apply(shapes, paths[p].toShapes());
  24845. }
  24846. return shapes;
  24847. }
  24848. });
  24849. function createPaths(text, size, data) {
  24850. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  24851. var scale = size / data.resolution;
  24852. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  24853. var paths = [];
  24854. var offsetX = 0,
  24855. offsetY = 0;
  24856. for (var i = 0; i < chars.length; i++) {
  24857. var char = chars[i];
  24858. if (char === '\n') {
  24859. offsetX = 0;
  24860. offsetY -= line_height;
  24861. } else {
  24862. var ret = createPath(char, scale, offsetX, offsetY, data);
  24863. offsetX += ret.offsetX;
  24864. paths.push(ret.path);
  24865. }
  24866. }
  24867. return paths;
  24868. }
  24869. function createPath(char, scale, offsetX, offsetY, data) {
  24870. var glyph = data.glyphs[char] || data.glyphs['?'];
  24871. if (!glyph) {
  24872. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  24873. return;
  24874. }
  24875. var path = new ShapePath();
  24876. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24877. if (glyph.o) {
  24878. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  24879. for (var i = 0, l = outline.length; i < l;) {
  24880. var action = outline[i++];
  24881. switch (action) {
  24882. case 'm':
  24883. // moveTo
  24884. x = outline[i++] * scale + offsetX;
  24885. y = outline[i++] * scale + offsetY;
  24886. path.moveTo(x, y);
  24887. break;
  24888. case 'l':
  24889. // lineTo
  24890. x = outline[i++] * scale + offsetX;
  24891. y = outline[i++] * scale + offsetY;
  24892. path.lineTo(x, y);
  24893. break;
  24894. case 'q':
  24895. // quadraticCurveTo
  24896. cpx = outline[i++] * scale + offsetX;
  24897. cpy = outline[i++] * scale + offsetY;
  24898. cpx1 = outline[i++] * scale + offsetX;
  24899. cpy1 = outline[i++] * scale + offsetY;
  24900. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  24901. break;
  24902. case 'b':
  24903. // bezierCurveTo
  24904. cpx = outline[i++] * scale + offsetX;
  24905. cpy = outline[i++] * scale + offsetY;
  24906. cpx1 = outline[i++] * scale + offsetX;
  24907. cpy1 = outline[i++] * scale + offsetY;
  24908. cpx2 = outline[i++] * scale + offsetX;
  24909. cpy2 = outline[i++] * scale + offsetY;
  24910. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  24911. break;
  24912. }
  24913. }
  24914. }
  24915. return {
  24916. offsetX: glyph.ha * scale,
  24917. path: path
  24918. };
  24919. }
  24920. function FontLoader(manager) {
  24921. Loader.call(this, manager);
  24922. }
  24923. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24924. constructor: FontLoader,
  24925. load: function load(url, onLoad, onProgress, onError) {
  24926. var scope = this;
  24927. var loader = new FileLoader(this.manager);
  24928. loader.setPath(this.path);
  24929. loader.setRequestHeader(this.requestHeader);
  24930. loader.setWithCredentials(scope.withCredentials);
  24931. loader.load(url, function (text) {
  24932. var json;
  24933. try {
  24934. json = JSON.parse(text);
  24935. } catch (e) {
  24936. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  24937. json = JSON.parse(text.substring(65, text.length - 2));
  24938. }
  24939. var font = scope.parse(json);
  24940. if (onLoad) onLoad(font);
  24941. }, onProgress, onError);
  24942. },
  24943. parse: function parse(json) {
  24944. return new Font(json);
  24945. }
  24946. });
  24947. var _context;
  24948. var AudioContext = {
  24949. getContext: function getContext() {
  24950. if (_context === undefined) {
  24951. _context = new (window.AudioContext || window.webkitAudioContext)();
  24952. }
  24953. return _context;
  24954. },
  24955. setContext: function setContext(value) {
  24956. _context = value;
  24957. }
  24958. };
  24959. function AudioLoader(manager) {
  24960. Loader.call(this, manager);
  24961. }
  24962. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24963. constructor: AudioLoader,
  24964. load: function load(url, onLoad, onProgress, onError) {
  24965. var scope = this;
  24966. var loader = new FileLoader(scope.manager);
  24967. loader.setResponseType('arraybuffer');
  24968. loader.setPath(scope.path);
  24969. loader.setRequestHeader(scope.requestHeader);
  24970. loader.setWithCredentials(scope.withCredentials);
  24971. loader.load(url, function (buffer) {
  24972. try {
  24973. // Create a copy of the buffer. The `decodeAudioData` method
  24974. // detaches the buffer when complete, preventing reuse.
  24975. var bufferCopy = buffer.slice(0);
  24976. var context = AudioContext.getContext();
  24977. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  24978. onLoad(audioBuffer);
  24979. });
  24980. } catch (e) {
  24981. if (onError) {
  24982. onError(e);
  24983. } else {
  24984. console.error(e);
  24985. }
  24986. scope.manager.itemError(url);
  24987. }
  24988. }, onProgress, onError);
  24989. }
  24990. });
  24991. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  24992. LightProbe.call(this, undefined, intensity);
  24993. var color1 = new Color().set(skyColor);
  24994. var color2 = new Color().set(groundColor);
  24995. var sky = new Vector3(color1.r, color1.g, color1.b);
  24996. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24997. var c0 = Math.sqrt(Math.PI);
  24998. var c1 = c0 * Math.sqrt(0.75);
  24999. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25000. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25001. }
  25002. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25003. constructor: HemisphereLightProbe,
  25004. isHemisphereLightProbe: true,
  25005. copy: function copy(source) {
  25006. // modifying colors not currently supported
  25007. LightProbe.prototype.copy.call(this, source);
  25008. return this;
  25009. },
  25010. toJSON: function toJSON(meta) {
  25011. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25012. return data;
  25013. }
  25014. });
  25015. function AmbientLightProbe(color, intensity) {
  25016. LightProbe.call(this, undefined, intensity);
  25017. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25018. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25019. }
  25020. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25021. constructor: AmbientLightProbe,
  25022. isAmbientLightProbe: true,
  25023. copy: function copy(source) {
  25024. // modifying color not currently supported
  25025. LightProbe.prototype.copy.call(this, source);
  25026. return this;
  25027. },
  25028. toJSON: function toJSON(meta) {
  25029. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25030. return data;
  25031. }
  25032. });
  25033. var _eyeRight = new Matrix4();
  25034. var _eyeLeft = new Matrix4();
  25035. function StereoCamera() {
  25036. this.type = 'StereoCamera';
  25037. this.aspect = 1;
  25038. this.eyeSep = 0.064;
  25039. this.cameraL = new PerspectiveCamera();
  25040. this.cameraL.layers.enable(1);
  25041. this.cameraL.matrixAutoUpdate = false;
  25042. this.cameraR = new PerspectiveCamera();
  25043. this.cameraR.layers.enable(2);
  25044. this.cameraR.matrixAutoUpdate = false;
  25045. this._cache = {
  25046. focus: null,
  25047. fov: null,
  25048. aspect: null,
  25049. near: null,
  25050. far: null,
  25051. zoom: null,
  25052. eyeSep: null
  25053. };
  25054. }
  25055. Object.assign(StereoCamera.prototype, {
  25056. update: function update(camera) {
  25057. var cache = this._cache;
  25058. 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;
  25059. if (needsUpdate) {
  25060. cache.focus = camera.focus;
  25061. cache.fov = camera.fov;
  25062. cache.aspect = camera.aspect * this.aspect;
  25063. cache.near = camera.near;
  25064. cache.far = camera.far;
  25065. cache.zoom = camera.zoom;
  25066. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25067. // http://paulbourke.net/stereographics/stereorender/
  25068. var projectionMatrix = camera.projectionMatrix.clone();
  25069. var eyeSepHalf = cache.eyeSep / 2;
  25070. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25071. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25072. var xmin, xmax; // translate xOffset
  25073. _eyeLeft.elements[12] = -eyeSepHalf;
  25074. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25075. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25076. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25077. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25078. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25079. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25080. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25081. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25082. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25083. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25084. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25085. }
  25086. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25087. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25088. }
  25089. });
  25090. var Clock = /*#__PURE__*/function () {
  25091. function Clock(autoStart) {
  25092. this.autoStart = autoStart !== undefined ? autoStart : true;
  25093. this.startTime = 0;
  25094. this.oldTime = 0;
  25095. this.elapsedTime = 0;
  25096. this.running = false;
  25097. }
  25098. var _proto = Clock.prototype;
  25099. _proto.start = function start() {
  25100. this.startTime = (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25101. this.oldTime = this.startTime;
  25102. this.elapsedTime = 0;
  25103. this.running = true;
  25104. };
  25105. _proto.stop = function stop() {
  25106. this.getElapsedTime();
  25107. this.running = false;
  25108. this.autoStart = false;
  25109. };
  25110. _proto.getElapsedTime = function getElapsedTime() {
  25111. this.getDelta();
  25112. return this.elapsedTime;
  25113. };
  25114. _proto.getDelta = function getDelta() {
  25115. var diff = 0;
  25116. if (this.autoStart && !this.running) {
  25117. this.start();
  25118. return 0;
  25119. }
  25120. if (this.running) {
  25121. var newTime = (typeof performance === 'undefined' ? Date : performance).now();
  25122. diff = (newTime - this.oldTime) / 1000;
  25123. this.oldTime = newTime;
  25124. this.elapsedTime += diff;
  25125. }
  25126. return diff;
  25127. };
  25128. return Clock;
  25129. }();
  25130. var _position$2 = /*@__PURE__*/new Vector3();
  25131. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25132. var _scale$1 = /*@__PURE__*/new Vector3();
  25133. var _orientation = /*@__PURE__*/new Vector3();
  25134. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25135. _inheritsLoose(AudioListener, _Object3D);
  25136. function AudioListener() {
  25137. var _this;
  25138. _this = _Object3D.call(this) || this;
  25139. _this.type = 'AudioListener';
  25140. _this.context = AudioContext.getContext();
  25141. _this.gain = _this.context.createGain();
  25142. _this.gain.connect(_this.context.destination);
  25143. _this.filter = null;
  25144. _this.timeDelta = 0; // private
  25145. _this._clock = new Clock();
  25146. return _this;
  25147. }
  25148. var _proto = AudioListener.prototype;
  25149. _proto.getInput = function getInput() {
  25150. return this.gain;
  25151. };
  25152. _proto.removeFilter = function removeFilter() {
  25153. if (this.filter !== null) {
  25154. this.gain.disconnect(this.filter);
  25155. this.filter.disconnect(this.context.destination);
  25156. this.gain.connect(this.context.destination);
  25157. this.filter = null;
  25158. }
  25159. return this;
  25160. };
  25161. _proto.getFilter = function getFilter() {
  25162. return this.filter;
  25163. };
  25164. _proto.setFilter = function setFilter(value) {
  25165. if (this.filter !== null) {
  25166. this.gain.disconnect(this.filter);
  25167. this.filter.disconnect(this.context.destination);
  25168. } else {
  25169. this.gain.disconnect(this.context.destination);
  25170. }
  25171. this.filter = value;
  25172. this.gain.connect(this.filter);
  25173. this.filter.connect(this.context.destination);
  25174. return this;
  25175. };
  25176. _proto.getMasterVolume = function getMasterVolume() {
  25177. return this.gain.gain.value;
  25178. };
  25179. _proto.setMasterVolume = function setMasterVolume(value) {
  25180. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25181. return this;
  25182. };
  25183. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25184. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25185. var listener = this.context.listener;
  25186. var up = this.up;
  25187. this.timeDelta = this._clock.getDelta();
  25188. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25189. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25190. if (listener.positionX) {
  25191. // code path for Chrome (see #14393)
  25192. var endTime = this.context.currentTime + this.timeDelta;
  25193. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25194. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25195. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25196. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25197. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25198. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25199. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25200. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25201. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25202. } else {
  25203. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25204. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25205. }
  25206. };
  25207. return AudioListener;
  25208. }(Object3D);
  25209. var Audio = /*#__PURE__*/function (_Object3D) {
  25210. _inheritsLoose(Audio, _Object3D);
  25211. function Audio(listener) {
  25212. var _this;
  25213. _this = _Object3D.call(this) || this;
  25214. _this.type = 'Audio';
  25215. _this.listener = listener;
  25216. _this.context = listener.context;
  25217. _this.gain = _this.context.createGain();
  25218. _this.gain.connect(listener.getInput());
  25219. _this.autoplay = false;
  25220. _this.buffer = null;
  25221. _this.detune = 0;
  25222. _this.loop = false;
  25223. _this.loopStart = 0;
  25224. _this.loopEnd = 0;
  25225. _this.offset = 0;
  25226. _this.duration = undefined;
  25227. _this.playbackRate = 1;
  25228. _this.isPlaying = false;
  25229. _this.hasPlaybackControl = true;
  25230. _this.source = null;
  25231. _this.sourceType = 'empty';
  25232. _this._startedAt = 0;
  25233. _this._progress = 0;
  25234. _this._connected = false;
  25235. _this.filters = [];
  25236. return _this;
  25237. }
  25238. var _proto = Audio.prototype;
  25239. _proto.getOutput = function getOutput() {
  25240. return this.gain;
  25241. };
  25242. _proto.setNodeSource = function setNodeSource(audioNode) {
  25243. this.hasPlaybackControl = false;
  25244. this.sourceType = 'audioNode';
  25245. this.source = audioNode;
  25246. this.connect();
  25247. return this;
  25248. };
  25249. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25250. this.hasPlaybackControl = false;
  25251. this.sourceType = 'mediaNode';
  25252. this.source = this.context.createMediaElementSource(mediaElement);
  25253. this.connect();
  25254. return this;
  25255. };
  25256. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25257. this.hasPlaybackControl = false;
  25258. this.sourceType = 'mediaStreamNode';
  25259. this.source = this.context.createMediaStreamSource(mediaStream);
  25260. this.connect();
  25261. return this;
  25262. };
  25263. _proto.setBuffer = function setBuffer(audioBuffer) {
  25264. this.buffer = audioBuffer;
  25265. this.sourceType = 'buffer';
  25266. if (this.autoplay) this.play();
  25267. return this;
  25268. };
  25269. _proto.play = function play(delay) {
  25270. if (delay === undefined) delay = 0;
  25271. if (this.isPlaying === true) {
  25272. console.warn('THREE.Audio: Audio is already playing.');
  25273. return;
  25274. }
  25275. if (this.hasPlaybackControl === false) {
  25276. console.warn('THREE.Audio: this Audio has no playback control.');
  25277. return;
  25278. }
  25279. this._startedAt = this.context.currentTime + delay;
  25280. var source = this.context.createBufferSource();
  25281. source.buffer = this.buffer;
  25282. source.loop = this.loop;
  25283. source.loopStart = this.loopStart;
  25284. source.loopEnd = this.loopEnd;
  25285. source.onended = this.onEnded.bind(this);
  25286. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25287. this.isPlaying = true;
  25288. this.source = source;
  25289. this.setDetune(this.detune);
  25290. this.setPlaybackRate(this.playbackRate);
  25291. return this.connect();
  25292. };
  25293. _proto.pause = function pause() {
  25294. if (this.hasPlaybackControl === false) {
  25295. console.warn('THREE.Audio: this Audio has no playback control.');
  25296. return;
  25297. }
  25298. if (this.isPlaying === true) {
  25299. // update current progress
  25300. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25301. if (this.loop === true) {
  25302. // ensure _progress does not exceed duration with looped audios
  25303. this._progress = this._progress % (this.duration || this.buffer.duration);
  25304. }
  25305. this.source.stop();
  25306. this.source.onended = null;
  25307. this.isPlaying = false;
  25308. }
  25309. return this;
  25310. };
  25311. _proto.stop = function stop() {
  25312. if (this.hasPlaybackControl === false) {
  25313. console.warn('THREE.Audio: this Audio has no playback control.');
  25314. return;
  25315. }
  25316. this._progress = 0;
  25317. this.source.stop();
  25318. this.source.onended = null;
  25319. this.isPlaying = false;
  25320. return this;
  25321. };
  25322. _proto.connect = function connect() {
  25323. if (this.filters.length > 0) {
  25324. this.source.connect(this.filters[0]);
  25325. for (var i = 1, l = this.filters.length; i < l; i++) {
  25326. this.filters[i - 1].connect(this.filters[i]);
  25327. }
  25328. this.filters[this.filters.length - 1].connect(this.getOutput());
  25329. } else {
  25330. this.source.connect(this.getOutput());
  25331. }
  25332. this._connected = true;
  25333. return this;
  25334. };
  25335. _proto.disconnect = function disconnect() {
  25336. if (this.filters.length > 0) {
  25337. this.source.disconnect(this.filters[0]);
  25338. for (var i = 1, l = this.filters.length; i < l; i++) {
  25339. this.filters[i - 1].disconnect(this.filters[i]);
  25340. }
  25341. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25342. } else {
  25343. this.source.disconnect(this.getOutput());
  25344. }
  25345. this._connected = false;
  25346. return this;
  25347. };
  25348. _proto.getFilters = function getFilters() {
  25349. return this.filters;
  25350. };
  25351. _proto.setFilters = function setFilters(value) {
  25352. if (!value) value = [];
  25353. if (this._connected === true) {
  25354. this.disconnect();
  25355. this.filters = value;
  25356. this.connect();
  25357. } else {
  25358. this.filters = value;
  25359. }
  25360. return this;
  25361. };
  25362. _proto.setDetune = function setDetune(value) {
  25363. this.detune = value;
  25364. if (this.source.detune === undefined) return; // only set detune when available
  25365. if (this.isPlaying === true) {
  25366. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25367. }
  25368. return this;
  25369. };
  25370. _proto.getDetune = function getDetune() {
  25371. return this.detune;
  25372. };
  25373. _proto.getFilter = function getFilter() {
  25374. return this.getFilters()[0];
  25375. };
  25376. _proto.setFilter = function setFilter(filter) {
  25377. return this.setFilters(filter ? [filter] : []);
  25378. };
  25379. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25380. if (this.hasPlaybackControl === false) {
  25381. console.warn('THREE.Audio: this Audio has no playback control.');
  25382. return;
  25383. }
  25384. this.playbackRate = value;
  25385. if (this.isPlaying === true) {
  25386. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25387. }
  25388. return this;
  25389. };
  25390. _proto.getPlaybackRate = function getPlaybackRate() {
  25391. return this.playbackRate;
  25392. };
  25393. _proto.onEnded = function onEnded() {
  25394. this.isPlaying = false;
  25395. };
  25396. _proto.getLoop = function getLoop() {
  25397. if (this.hasPlaybackControl === false) {
  25398. console.warn('THREE.Audio: this Audio has no playback control.');
  25399. return false;
  25400. }
  25401. return this.loop;
  25402. };
  25403. _proto.setLoop = function setLoop(value) {
  25404. if (this.hasPlaybackControl === false) {
  25405. console.warn('THREE.Audio: this Audio has no playback control.');
  25406. return;
  25407. }
  25408. this.loop = value;
  25409. if (this.isPlaying === true) {
  25410. this.source.loop = this.loop;
  25411. }
  25412. return this;
  25413. };
  25414. _proto.setLoopStart = function setLoopStart(value) {
  25415. this.loopStart = value;
  25416. return this;
  25417. };
  25418. _proto.setLoopEnd = function setLoopEnd(value) {
  25419. this.loopEnd = value;
  25420. return this;
  25421. };
  25422. _proto.getVolume = function getVolume() {
  25423. return this.gain.gain.value;
  25424. };
  25425. _proto.setVolume = function setVolume(value) {
  25426. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25427. return this;
  25428. };
  25429. return Audio;
  25430. }(Object3D);
  25431. var _position$3 = /*@__PURE__*/new Vector3();
  25432. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25433. var _scale$2 = /*@__PURE__*/new Vector3();
  25434. var _orientation$1 = /*@__PURE__*/new Vector3();
  25435. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25436. _inheritsLoose(PositionalAudio, _Audio);
  25437. function PositionalAudio(listener) {
  25438. var _this;
  25439. _this = _Audio.call(this, listener) || this;
  25440. _this.panner = _this.context.createPanner();
  25441. _this.panner.panningModel = 'HRTF';
  25442. _this.panner.connect(_this.gain);
  25443. return _this;
  25444. }
  25445. var _proto = PositionalAudio.prototype;
  25446. _proto.getOutput = function getOutput() {
  25447. return this.panner;
  25448. };
  25449. _proto.getRefDistance = function getRefDistance() {
  25450. return this.panner.refDistance;
  25451. };
  25452. _proto.setRefDistance = function setRefDistance(value) {
  25453. this.panner.refDistance = value;
  25454. return this;
  25455. };
  25456. _proto.getRolloffFactor = function getRolloffFactor() {
  25457. return this.panner.rolloffFactor;
  25458. };
  25459. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25460. this.panner.rolloffFactor = value;
  25461. return this;
  25462. };
  25463. _proto.getDistanceModel = function getDistanceModel() {
  25464. return this.panner.distanceModel;
  25465. };
  25466. _proto.setDistanceModel = function setDistanceModel(value) {
  25467. this.panner.distanceModel = value;
  25468. return this;
  25469. };
  25470. _proto.getMaxDistance = function getMaxDistance() {
  25471. return this.panner.maxDistance;
  25472. };
  25473. _proto.setMaxDistance = function setMaxDistance(value) {
  25474. this.panner.maxDistance = value;
  25475. return this;
  25476. };
  25477. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25478. this.panner.coneInnerAngle = coneInnerAngle;
  25479. this.panner.coneOuterAngle = coneOuterAngle;
  25480. this.panner.coneOuterGain = coneOuterGain;
  25481. return this;
  25482. };
  25483. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25484. _Audio.prototype.updateMatrixWorld.call(this, force);
  25485. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25486. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25487. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25488. var panner = this.panner;
  25489. if (panner.positionX) {
  25490. // code path for Chrome and Firefox (see #14393)
  25491. var endTime = this.context.currentTime + this.listener.timeDelta;
  25492. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25493. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25494. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25495. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25496. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25497. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25498. } else {
  25499. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25500. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25501. }
  25502. };
  25503. return PositionalAudio;
  25504. }(Audio);
  25505. var AudioAnalyser = /*#__PURE__*/function () {
  25506. function AudioAnalyser(audio, fftSize) {
  25507. this.analyser = audio.context.createAnalyser();
  25508. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25509. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25510. audio.getOutput().connect(this.analyser);
  25511. }
  25512. var _proto = AudioAnalyser.prototype;
  25513. _proto.getFrequencyData = function getFrequencyData() {
  25514. this.analyser.getByteFrequencyData(this.data);
  25515. return this.data;
  25516. };
  25517. _proto.getAverageFrequency = function getAverageFrequency() {
  25518. var value = 0;
  25519. var data = this.getFrequencyData();
  25520. for (var i = 0; i < data.length; i++) {
  25521. value += data[i];
  25522. }
  25523. return value / data.length;
  25524. };
  25525. return AudioAnalyser;
  25526. }();
  25527. function PropertyMixer(binding, typeName, valueSize) {
  25528. this.binding = binding;
  25529. this.valueSize = valueSize;
  25530. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25531. //
  25532. // interpolators can use .buffer as their .result
  25533. // the data then goes to 'incoming'
  25534. //
  25535. // 'accu0' and 'accu1' are used frame-interleaved for
  25536. // the cumulative result and are compared to detect
  25537. // changes
  25538. //
  25539. // 'orig' stores the original state of the property
  25540. //
  25541. // 'add' is used for additive cumulative results
  25542. //
  25543. // 'work' is optional and is only present for quaternion types. It is used
  25544. // to store intermediate quaternion multiplication results
  25545. switch (typeName) {
  25546. case 'quaternion':
  25547. mixFunction = this._slerp;
  25548. mixFunctionAdditive = this._slerpAdditive;
  25549. setIdentity = this._setAdditiveIdentityQuaternion;
  25550. this.buffer = new Float64Array(valueSize * 6);
  25551. this._workIndex = 5;
  25552. break;
  25553. case 'string':
  25554. case 'bool':
  25555. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25556. // additive is not relevant for non-numeric types
  25557. mixFunctionAdditive = this._select;
  25558. setIdentity = this._setAdditiveIdentityOther;
  25559. this.buffer = new Array(valueSize * 5);
  25560. break;
  25561. default:
  25562. mixFunction = this._lerp;
  25563. mixFunctionAdditive = this._lerpAdditive;
  25564. setIdentity = this._setAdditiveIdentityNumeric;
  25565. this.buffer = new Float64Array(valueSize * 5);
  25566. }
  25567. this._mixBufferRegion = mixFunction;
  25568. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25569. this._setIdentity = setIdentity;
  25570. this._origIndex = 3;
  25571. this._addIndex = 4;
  25572. this.cumulativeWeight = 0;
  25573. this.cumulativeWeightAdditive = 0;
  25574. this.useCount = 0;
  25575. this.referenceCount = 0;
  25576. }
  25577. Object.assign(PropertyMixer.prototype, {
  25578. // accumulate data in the 'incoming' region into 'accu<i>'
  25579. accumulate: function accumulate(accuIndex, weight) {
  25580. // note: happily accumulating nothing when weight = 0, the caller knows
  25581. // the weight and shouldn't have made the call in the first place
  25582. var buffer = this.buffer,
  25583. stride = this.valueSize,
  25584. offset = accuIndex * stride + stride;
  25585. var currentWeight = this.cumulativeWeight;
  25586. if (currentWeight === 0) {
  25587. // accuN := incoming * weight
  25588. for (var i = 0; i !== stride; ++i) {
  25589. buffer[offset + i] = buffer[i];
  25590. }
  25591. currentWeight = weight;
  25592. } else {
  25593. // accuN := accuN + incoming * weight
  25594. currentWeight += weight;
  25595. var mix = weight / currentWeight;
  25596. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25597. }
  25598. this.cumulativeWeight = currentWeight;
  25599. },
  25600. // accumulate data in the 'incoming' region into 'add'
  25601. accumulateAdditive: function accumulateAdditive(weight) {
  25602. var buffer = this.buffer,
  25603. stride = this.valueSize,
  25604. offset = stride * this._addIndex;
  25605. if (this.cumulativeWeightAdditive === 0) {
  25606. // add = identity
  25607. this._setIdentity();
  25608. } // add := add + incoming * weight
  25609. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25610. this.cumulativeWeightAdditive += weight;
  25611. },
  25612. // apply the state of 'accu<i>' to the binding when accus differ
  25613. apply: function apply(accuIndex) {
  25614. var stride = this.valueSize,
  25615. buffer = this.buffer,
  25616. offset = accuIndex * stride + stride,
  25617. weight = this.cumulativeWeight,
  25618. weightAdditive = this.cumulativeWeightAdditive,
  25619. binding = this.binding;
  25620. this.cumulativeWeight = 0;
  25621. this.cumulativeWeightAdditive = 0;
  25622. if (weight < 1) {
  25623. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25624. var originalValueOffset = stride * this._origIndex;
  25625. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25626. }
  25627. if (weightAdditive > 0) {
  25628. // accuN := accuN + additive accuN
  25629. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25630. }
  25631. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25632. if (buffer[i] !== buffer[i + stride]) {
  25633. // value has changed -> update scene graph
  25634. binding.setValue(buffer, offset);
  25635. break;
  25636. }
  25637. }
  25638. },
  25639. // remember the state of the bound property and copy it to both accus
  25640. saveOriginalState: function saveOriginalState() {
  25641. var binding = this.binding;
  25642. var buffer = this.buffer,
  25643. stride = this.valueSize,
  25644. originalValueOffset = stride * this._origIndex;
  25645. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25646. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25647. buffer[i] = buffer[originalValueOffset + i % stride];
  25648. } // Add to identity for additive
  25649. this._setIdentity();
  25650. this.cumulativeWeight = 0;
  25651. this.cumulativeWeightAdditive = 0;
  25652. },
  25653. // apply the state previously taken via 'saveOriginalState' to the binding
  25654. restoreOriginalState: function restoreOriginalState() {
  25655. var originalValueOffset = this.valueSize * 3;
  25656. this.binding.setValue(this.buffer, originalValueOffset);
  25657. },
  25658. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25659. var startIndex = this._addIndex * this.valueSize;
  25660. var endIndex = startIndex + this.valueSize;
  25661. for (var i = startIndex; i < endIndex; i++) {
  25662. this.buffer[i] = 0;
  25663. }
  25664. },
  25665. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25666. this._setAdditiveIdentityNumeric();
  25667. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25668. },
  25669. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25670. var startIndex = this._origIndex * this.valueSize;
  25671. var targetIndex = this._addIndex * this.valueSize;
  25672. for (var i = 0; i < this.valueSize; i++) {
  25673. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25674. }
  25675. },
  25676. // mix functions
  25677. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25678. if (t >= 0.5) {
  25679. for (var i = 0; i !== stride; ++i) {
  25680. buffer[dstOffset + i] = buffer[srcOffset + i];
  25681. }
  25682. }
  25683. },
  25684. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25685. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25686. },
  25687. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25688. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25689. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25690. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25691. },
  25692. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25693. var s = 1 - t;
  25694. for (var i = 0; i !== stride; ++i) {
  25695. var j = dstOffset + i;
  25696. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25697. }
  25698. },
  25699. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25700. for (var i = 0; i !== stride; ++i) {
  25701. var j = dstOffset + i;
  25702. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25703. }
  25704. }
  25705. });
  25706. // Characters [].:/ are reserved for track binding syntax.
  25707. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25708. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25709. // only latin characters, and the unicode \p{L} is not yet supported. So
  25710. // instead, we exclude reserved characters and match everything else.
  25711. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25712. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25713. // be matched to parse the rest of the track name.
  25714. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25715. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25716. // characters. Accessor may contain any character except closing bracket.
  25717. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25718. // contain any non-bracket characters.
  25719. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25720. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25721. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25722. function Composite(targetGroup, path, optionalParsedPath) {
  25723. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25724. this._targetGroup = targetGroup;
  25725. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25726. }
  25727. Object.assign(Composite.prototype, {
  25728. getValue: function getValue(array, offset) {
  25729. this.bind(); // bind all binding
  25730. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25731. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25732. if (binding !== undefined) binding.getValue(array, offset);
  25733. },
  25734. setValue: function setValue(array, offset) {
  25735. var bindings = this._bindings;
  25736. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25737. bindings[i].setValue(array, offset);
  25738. }
  25739. },
  25740. bind: function bind() {
  25741. var bindings = this._bindings;
  25742. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25743. bindings[i].bind();
  25744. }
  25745. },
  25746. unbind: function unbind() {
  25747. var bindings = this._bindings;
  25748. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25749. bindings[i].unbind();
  25750. }
  25751. }
  25752. });
  25753. function PropertyBinding(rootNode, path, parsedPath) {
  25754. this.path = path;
  25755. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25756. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25757. this.rootNode = rootNode;
  25758. }
  25759. Object.assign(PropertyBinding, {
  25760. Composite: Composite,
  25761. create: function create(root, path, parsedPath) {
  25762. if (!(root && root.isAnimationObjectGroup)) {
  25763. return new PropertyBinding(root, path, parsedPath);
  25764. } else {
  25765. return new PropertyBinding.Composite(root, path, parsedPath);
  25766. }
  25767. },
  25768. /**
  25769. * Replaces spaces with underscores and removes unsupported characters from
  25770. * node names, to ensure compatibility with parseTrackName().
  25771. *
  25772. * @param {string} name Node name to be sanitized.
  25773. * @return {string}
  25774. */
  25775. sanitizeNodeName: function sanitizeNodeName(name) {
  25776. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25777. },
  25778. parseTrackName: function parseTrackName(trackName) {
  25779. var matches = _trackRe.exec(trackName);
  25780. if (!matches) {
  25781. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25782. }
  25783. var results = {
  25784. // directoryName: matches[ 1 ], // (tschw) currently unused
  25785. nodeName: matches[2],
  25786. objectName: matches[3],
  25787. objectIndex: matches[4],
  25788. propertyName: matches[5],
  25789. // required
  25790. propertyIndex: matches[6]
  25791. };
  25792. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25793. if (lastDot !== undefined && lastDot !== -1) {
  25794. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25795. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25796. // 'bar' could be the objectName, or part of a nodeName (which can
  25797. // include '.' characters).
  25798. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25799. results.nodeName = results.nodeName.substring(0, lastDot);
  25800. results.objectName = objectName;
  25801. }
  25802. }
  25803. if (results.propertyName === null || results.propertyName.length === 0) {
  25804. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25805. }
  25806. return results;
  25807. },
  25808. findNode: function findNode(root, nodeName) {
  25809. if (!nodeName || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25810. return root;
  25811. } // search into skeleton bones.
  25812. if (root.skeleton) {
  25813. var bone = root.skeleton.getBoneByName(nodeName);
  25814. if (bone !== undefined) {
  25815. return bone;
  25816. }
  25817. } // search into node subtree.
  25818. if (root.children) {
  25819. var searchNodeSubtree = function searchNodeSubtree(children) {
  25820. for (var i = 0; i < children.length; i++) {
  25821. var childNode = children[i];
  25822. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25823. return childNode;
  25824. }
  25825. var result = searchNodeSubtree(childNode.children);
  25826. if (result) return result;
  25827. }
  25828. return null;
  25829. };
  25830. var subTreeNode = searchNodeSubtree(root.children);
  25831. if (subTreeNode) {
  25832. return subTreeNode;
  25833. }
  25834. }
  25835. return null;
  25836. }
  25837. });
  25838. Object.assign(PropertyBinding.prototype, {
  25839. // prototype, continued
  25840. // these are used to "bind" a nonexistent property
  25841. _getValue_unavailable: function _getValue_unavailable() {},
  25842. _setValue_unavailable: function _setValue_unavailable() {},
  25843. BindingType: {
  25844. Direct: 0,
  25845. EntireArray: 1,
  25846. ArrayElement: 2,
  25847. HasFromToArray: 3
  25848. },
  25849. Versioning: {
  25850. None: 0,
  25851. NeedsUpdate: 1,
  25852. MatrixWorldNeedsUpdate: 2
  25853. },
  25854. GetterByBindingType: [function getValue_direct(buffer, offset) {
  25855. buffer[offset] = this.node[this.propertyName];
  25856. }, function getValue_array(buffer, offset) {
  25857. var source = this.resolvedProperty;
  25858. for (var i = 0, n = source.length; i !== n; ++i) {
  25859. buffer[offset++] = source[i];
  25860. }
  25861. }, function getValue_arrayElement(buffer, offset) {
  25862. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  25863. }, function getValue_toArray(buffer, offset) {
  25864. this.resolvedProperty.toArray(buffer, offset);
  25865. }],
  25866. SetterByBindingTypeAndVersioning: [[// Direct
  25867. function setValue_direct(buffer, offset) {
  25868. this.targetObject[this.propertyName] = buffer[offset];
  25869. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  25870. this.targetObject[this.propertyName] = buffer[offset];
  25871. this.targetObject.needsUpdate = true;
  25872. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  25873. this.targetObject[this.propertyName] = buffer[offset];
  25874. this.targetObject.matrixWorldNeedsUpdate = true;
  25875. }], [// EntireArray
  25876. function setValue_array(buffer, offset) {
  25877. var dest = this.resolvedProperty;
  25878. for (var i = 0, n = dest.length; i !== n; ++i) {
  25879. dest[i] = buffer[offset++];
  25880. }
  25881. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  25882. var dest = this.resolvedProperty;
  25883. for (var i = 0, n = dest.length; i !== n; ++i) {
  25884. dest[i] = buffer[offset++];
  25885. }
  25886. this.targetObject.needsUpdate = true;
  25887. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  25888. var dest = this.resolvedProperty;
  25889. for (var i = 0, n = dest.length; i !== n; ++i) {
  25890. dest[i] = buffer[offset++];
  25891. }
  25892. this.targetObject.matrixWorldNeedsUpdate = true;
  25893. }], [// ArrayElement
  25894. function setValue_arrayElement(buffer, offset) {
  25895. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25896. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  25897. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25898. this.targetObject.needsUpdate = true;
  25899. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  25900. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25901. this.targetObject.matrixWorldNeedsUpdate = true;
  25902. }], [// HasToFromArray
  25903. function setValue_fromArray(buffer, offset) {
  25904. this.resolvedProperty.fromArray(buffer, offset);
  25905. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  25906. this.resolvedProperty.fromArray(buffer, offset);
  25907. this.targetObject.needsUpdate = true;
  25908. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  25909. this.resolvedProperty.fromArray(buffer, offset);
  25910. this.targetObject.matrixWorldNeedsUpdate = true;
  25911. }]],
  25912. getValue: function getValue_unbound(targetArray, offset) {
  25913. this.bind();
  25914. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  25915. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25916. // prototype version of these methods with one that represents
  25917. // the bound state. When the property is not found, the methods
  25918. // become no-ops.
  25919. },
  25920. setValue: function getValue_unbound(sourceArray, offset) {
  25921. this.bind();
  25922. this.setValue(sourceArray, offset);
  25923. },
  25924. // create getter / setter pair for a property in the scene graph
  25925. bind: function bind() {
  25926. var targetObject = this.node;
  25927. var parsedPath = this.parsedPath;
  25928. var objectName = parsedPath.objectName;
  25929. var propertyName = parsedPath.propertyName;
  25930. var propertyIndex = parsedPath.propertyIndex;
  25931. if (!targetObject) {
  25932. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  25933. this.node = targetObject;
  25934. } // set fail state so we can just 'return' on error
  25935. this.getValue = this._getValue_unavailable;
  25936. this.setValue = this._setValue_unavailable; // ensure there is a value node
  25937. if (!targetObject) {
  25938. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  25939. return;
  25940. }
  25941. if (objectName) {
  25942. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25943. switch (objectName) {
  25944. case 'materials':
  25945. if (!targetObject.material) {
  25946. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  25947. return;
  25948. }
  25949. if (!targetObject.material.materials) {
  25950. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  25951. return;
  25952. }
  25953. targetObject = targetObject.material.materials;
  25954. break;
  25955. case 'bones':
  25956. if (!targetObject.skeleton) {
  25957. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  25958. return;
  25959. } // potential future optimization: skip this if propertyIndex is already an integer
  25960. // and convert the integer string to a true integer.
  25961. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  25962. for (var i = 0; i < targetObject.length; i++) {
  25963. if (targetObject[i].name === objectIndex) {
  25964. objectIndex = i;
  25965. break;
  25966. }
  25967. }
  25968. break;
  25969. default:
  25970. if (targetObject[objectName] === undefined) {
  25971. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  25972. return;
  25973. }
  25974. targetObject = targetObject[objectName];
  25975. }
  25976. if (objectIndex !== undefined) {
  25977. if (targetObject[objectIndex] === undefined) {
  25978. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  25979. return;
  25980. }
  25981. targetObject = targetObject[objectIndex];
  25982. }
  25983. } // resolve property
  25984. var nodeProperty = targetObject[propertyName];
  25985. if (nodeProperty === undefined) {
  25986. var nodeName = parsedPath.nodeName;
  25987. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  25988. return;
  25989. } // determine versioning scheme
  25990. var versioning = this.Versioning.None;
  25991. this.targetObject = targetObject;
  25992. if (targetObject.needsUpdate !== undefined) {
  25993. // material
  25994. versioning = this.Versioning.NeedsUpdate;
  25995. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  25996. // node transform
  25997. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25998. } // determine how the property gets bound
  25999. var bindingType = this.BindingType.Direct;
  26000. if (propertyIndex !== undefined) {
  26001. // access a sub element of the property array (only primitives are supported right now)
  26002. if (propertyName === "morphTargetInfluences") {
  26003. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26004. // support resolving morphTarget names into indices.
  26005. if (!targetObject.geometry) {
  26006. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26007. return;
  26008. }
  26009. if (targetObject.geometry.isBufferGeometry) {
  26010. if (!targetObject.geometry.morphAttributes) {
  26011. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26012. return;
  26013. }
  26014. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26015. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26016. }
  26017. } else {
  26018. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26019. return;
  26020. }
  26021. }
  26022. bindingType = this.BindingType.ArrayElement;
  26023. this.resolvedProperty = nodeProperty;
  26024. this.propertyIndex = propertyIndex;
  26025. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26026. // must use copy for Object3D.Euler/Quaternion
  26027. bindingType = this.BindingType.HasFromToArray;
  26028. this.resolvedProperty = nodeProperty;
  26029. } else if (Array.isArray(nodeProperty)) {
  26030. bindingType = this.BindingType.EntireArray;
  26031. this.resolvedProperty = nodeProperty;
  26032. } else {
  26033. this.propertyName = propertyName;
  26034. } // select getter / setter
  26035. this.getValue = this.GetterByBindingType[bindingType];
  26036. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26037. },
  26038. unbind: function unbind() {
  26039. this.node = null; // back to the prototype version of getValue / setValue
  26040. // note: avoiding to mutate the shape of 'this' via 'delete'
  26041. this.getValue = this._getValue_unbound;
  26042. this.setValue = this._setValue_unbound;
  26043. }
  26044. }); // DECLARE ALIAS AFTER assign prototype
  26045. Object.assign(PropertyBinding.prototype, {
  26046. // initial state of these methods that calls 'bind'
  26047. _getValue_unbound: PropertyBinding.prototype.getValue,
  26048. _setValue_unbound: PropertyBinding.prototype.setValue
  26049. });
  26050. /**
  26051. *
  26052. * A group of objects that receives a shared animation state.
  26053. *
  26054. * Usage:
  26055. *
  26056. * - Add objects you would otherwise pass as 'root' to the
  26057. * constructor or the .clipAction method of AnimationMixer.
  26058. *
  26059. * - Instead pass this object as 'root'.
  26060. *
  26061. * - You can also add and remove objects later when the mixer
  26062. * is running.
  26063. *
  26064. * Note:
  26065. *
  26066. * Objects of this class appear as one object to the mixer,
  26067. * so cache control of the individual objects must be done
  26068. * on the group.
  26069. *
  26070. * Limitation:
  26071. *
  26072. * - The animated properties must be compatible among the
  26073. * all objects in the group.
  26074. *
  26075. * - A single property can either be controlled through a
  26076. * target group or directly, but not both.
  26077. */
  26078. function AnimationObjectGroup() {
  26079. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26080. this._objects = Array.prototype.slice.call(arguments);
  26081. this.nCachedObjects_ = 0; // threshold
  26082. // note: read by PropertyBinding.Composite
  26083. var indices = {};
  26084. this._indicesByUUID = indices; // for bookkeeping
  26085. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26086. indices[arguments[i].uuid] = i;
  26087. }
  26088. this._paths = []; // inside: string
  26089. this._parsedPaths = []; // inside: { we don't care, here }
  26090. this._bindings = []; // inside: Array< PropertyBinding >
  26091. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26092. var scope = this;
  26093. this.stats = {
  26094. objects: {
  26095. get total() {
  26096. return scope._objects.length;
  26097. },
  26098. get inUse() {
  26099. return this.total - scope.nCachedObjects_;
  26100. }
  26101. },
  26102. get bindingsPerObject() {
  26103. return scope._bindings.length;
  26104. }
  26105. };
  26106. }
  26107. Object.assign(AnimationObjectGroup.prototype, {
  26108. isAnimationObjectGroup: true,
  26109. add: function add() {
  26110. var objects = this._objects,
  26111. indicesByUUID = this._indicesByUUID,
  26112. paths = this._paths,
  26113. parsedPaths = this._parsedPaths,
  26114. bindings = this._bindings,
  26115. nBindings = bindings.length;
  26116. var knownObject = undefined,
  26117. nObjects = objects.length,
  26118. nCachedObjects = this.nCachedObjects_;
  26119. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26120. var object = arguments[i],
  26121. uuid = object.uuid;
  26122. var index = indicesByUUID[uuid];
  26123. if (index === undefined) {
  26124. // unknown object -> add it to the ACTIVE region
  26125. index = nObjects++;
  26126. indicesByUUID[uuid] = index;
  26127. objects.push(object); // accounting is done, now do the same for all bindings
  26128. for (var j = 0, m = nBindings; j !== m; ++j) {
  26129. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26130. }
  26131. } else if (index < nCachedObjects) {
  26132. knownObject = objects[index]; // move existing object to the ACTIVE region
  26133. var firstActiveIndex = --nCachedObjects,
  26134. lastCachedObject = objects[firstActiveIndex];
  26135. indicesByUUID[lastCachedObject.uuid] = index;
  26136. objects[index] = lastCachedObject;
  26137. indicesByUUID[uuid] = firstActiveIndex;
  26138. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26139. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26140. var bindingsForPath = bindings[_j],
  26141. lastCached = bindingsForPath[firstActiveIndex];
  26142. var binding = bindingsForPath[index];
  26143. bindingsForPath[index] = lastCached;
  26144. if (binding === undefined) {
  26145. // since we do not bother to create new bindings
  26146. // for objects that are cached, the binding may
  26147. // or may not exist
  26148. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26149. }
  26150. bindingsForPath[firstActiveIndex] = binding;
  26151. }
  26152. } else if (objects[index] !== knownObject) {
  26153. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26154. } // else the object is already where we want it to be
  26155. } // for arguments
  26156. this.nCachedObjects_ = nCachedObjects;
  26157. },
  26158. remove: function remove() {
  26159. var objects = this._objects,
  26160. indicesByUUID = this._indicesByUUID,
  26161. bindings = this._bindings,
  26162. nBindings = bindings.length;
  26163. var nCachedObjects = this.nCachedObjects_;
  26164. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26165. var object = arguments[i],
  26166. uuid = object.uuid,
  26167. index = indicesByUUID[uuid];
  26168. if (index !== undefined && index >= nCachedObjects) {
  26169. // move existing object into the CACHED region
  26170. var lastCachedIndex = nCachedObjects++,
  26171. firstActiveObject = objects[lastCachedIndex];
  26172. indicesByUUID[firstActiveObject.uuid] = index;
  26173. objects[index] = firstActiveObject;
  26174. indicesByUUID[uuid] = lastCachedIndex;
  26175. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26176. for (var j = 0, m = nBindings; j !== m; ++j) {
  26177. var bindingsForPath = bindings[j],
  26178. firstActive = bindingsForPath[lastCachedIndex],
  26179. binding = bindingsForPath[index];
  26180. bindingsForPath[index] = firstActive;
  26181. bindingsForPath[lastCachedIndex] = binding;
  26182. }
  26183. }
  26184. } // for arguments
  26185. this.nCachedObjects_ = nCachedObjects;
  26186. },
  26187. // remove & forget
  26188. uncache: function uncache() {
  26189. var objects = this._objects,
  26190. indicesByUUID = this._indicesByUUID,
  26191. bindings = this._bindings,
  26192. nBindings = bindings.length;
  26193. var nCachedObjects = this.nCachedObjects_,
  26194. nObjects = objects.length;
  26195. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26196. var object = arguments[i],
  26197. uuid = object.uuid,
  26198. index = indicesByUUID[uuid];
  26199. if (index !== undefined) {
  26200. delete indicesByUUID[uuid];
  26201. if (index < nCachedObjects) {
  26202. // object is cached, shrink the CACHED region
  26203. var firstActiveIndex = --nCachedObjects,
  26204. lastCachedObject = objects[firstActiveIndex],
  26205. lastIndex = --nObjects,
  26206. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26207. indicesByUUID[lastCachedObject.uuid] = index;
  26208. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26209. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26210. objects[firstActiveIndex] = lastObject;
  26211. objects.pop(); // accounting is done, now do the same for all bindings
  26212. for (var j = 0, m = nBindings; j !== m; ++j) {
  26213. var bindingsForPath = bindings[j],
  26214. lastCached = bindingsForPath[firstActiveIndex],
  26215. last = bindingsForPath[lastIndex];
  26216. bindingsForPath[index] = lastCached;
  26217. bindingsForPath[firstActiveIndex] = last;
  26218. bindingsForPath.pop();
  26219. }
  26220. } else {
  26221. // object is active, just swap with the last and pop
  26222. var _lastIndex = --nObjects,
  26223. _lastObject = objects[_lastIndex];
  26224. indicesByUUID[_lastObject.uuid] = index;
  26225. objects[index] = _lastObject;
  26226. objects.pop(); // accounting is done, now do the same for all bindings
  26227. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26228. var _bindingsForPath = bindings[_j2];
  26229. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26230. _bindingsForPath.pop();
  26231. }
  26232. } // cached or active
  26233. } // if object is known
  26234. } // for arguments
  26235. this.nCachedObjects_ = nCachedObjects;
  26236. },
  26237. // Internal interface used by befriended PropertyBinding.Composite:
  26238. subscribe_: function subscribe_(path, parsedPath) {
  26239. // returns an array of bindings for the given path that is changed
  26240. // according to the contained objects in the group
  26241. var indicesByPath = this._bindingsIndicesByPath;
  26242. var index = indicesByPath[path];
  26243. var bindings = this._bindings;
  26244. if (index !== undefined) return bindings[index];
  26245. var paths = this._paths,
  26246. parsedPaths = this._parsedPaths,
  26247. objects = this._objects,
  26248. nObjects = objects.length,
  26249. nCachedObjects = this.nCachedObjects_,
  26250. bindingsForPath = new Array(nObjects);
  26251. index = bindings.length;
  26252. indicesByPath[path] = index;
  26253. paths.push(path);
  26254. parsedPaths.push(parsedPath);
  26255. bindings.push(bindingsForPath);
  26256. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26257. var object = objects[i];
  26258. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26259. }
  26260. return bindingsForPath;
  26261. },
  26262. unsubscribe_: function unsubscribe_(path) {
  26263. // tells the group to forget about a property path and no longer
  26264. // update the array previously obtained with 'subscribe_'
  26265. var indicesByPath = this._bindingsIndicesByPath,
  26266. index = indicesByPath[path];
  26267. if (index !== undefined) {
  26268. var paths = this._paths,
  26269. parsedPaths = this._parsedPaths,
  26270. bindings = this._bindings,
  26271. lastBindingsIndex = bindings.length - 1,
  26272. lastBindings = bindings[lastBindingsIndex],
  26273. lastBindingsPath = path[lastBindingsIndex];
  26274. indicesByPath[lastBindingsPath] = index;
  26275. bindings[index] = lastBindings;
  26276. bindings.pop();
  26277. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26278. parsedPaths.pop();
  26279. paths[index] = paths[lastBindingsIndex];
  26280. paths.pop();
  26281. }
  26282. }
  26283. });
  26284. var AnimationAction = /*#__PURE__*/function () {
  26285. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26286. this._mixer = mixer;
  26287. this._clip = clip;
  26288. this._localRoot = localRoot || null;
  26289. this.blendMode = blendMode || clip.blendMode;
  26290. var tracks = clip.tracks,
  26291. nTracks = tracks.length,
  26292. interpolants = new Array(nTracks);
  26293. var interpolantSettings = {
  26294. endingStart: ZeroCurvatureEnding,
  26295. endingEnd: ZeroCurvatureEnding
  26296. };
  26297. for (var i = 0; i !== nTracks; ++i) {
  26298. var interpolant = tracks[i].createInterpolant(null);
  26299. interpolants[i] = interpolant;
  26300. interpolant.settings = interpolantSettings;
  26301. }
  26302. this._interpolantSettings = interpolantSettings;
  26303. this._interpolants = interpolants; // bound by the mixer
  26304. // inside: PropertyMixer (managed by the mixer)
  26305. this._propertyBindings = new Array(nTracks);
  26306. this._cacheIndex = null; // for the memory manager
  26307. this._byClipCacheIndex = null; // for the memory manager
  26308. this._timeScaleInterpolant = null;
  26309. this._weightInterpolant = null;
  26310. this.loop = LoopRepeat;
  26311. this._loopCount = -1; // global mixer time when the action is to be started
  26312. // it's set back to 'null' upon start of the action
  26313. this._startTime = null; // scaled local time of the action
  26314. // gets clamped or wrapped to 0..clip.duration according to loop
  26315. this.time = 0;
  26316. this.timeScale = 1;
  26317. this._effectiveTimeScale = 1;
  26318. this.weight = 1;
  26319. this._effectiveWeight = 1;
  26320. this.repetitions = Infinity; // no. of repetitions when looping
  26321. this.paused = false; // true -> zero effective time scale
  26322. this.enabled = true; // false -> zero effective weight
  26323. this.clampWhenFinished = false; // keep feeding the last frame?
  26324. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26325. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26326. } // State & Scheduling
  26327. var _proto = AnimationAction.prototype;
  26328. _proto.play = function play() {
  26329. this._mixer._activateAction(this);
  26330. return this;
  26331. };
  26332. _proto.stop = function stop() {
  26333. this._mixer._deactivateAction(this);
  26334. return this.reset();
  26335. };
  26336. _proto.reset = function reset() {
  26337. this.paused = false;
  26338. this.enabled = true;
  26339. this.time = 0; // restart clip
  26340. this._loopCount = -1; // forget previous loops
  26341. this._startTime = null; // forget scheduling
  26342. return this.stopFading().stopWarping();
  26343. };
  26344. _proto.isRunning = function isRunning() {
  26345. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26346. } // return true when play has been called
  26347. ;
  26348. _proto.isScheduled = function isScheduled() {
  26349. return this._mixer._isActiveAction(this);
  26350. };
  26351. _proto.startAt = function startAt(time) {
  26352. this._startTime = time;
  26353. return this;
  26354. };
  26355. _proto.setLoop = function setLoop(mode, repetitions) {
  26356. this.loop = mode;
  26357. this.repetitions = repetitions;
  26358. return this;
  26359. } // Weight
  26360. // set the weight stopping any scheduled fading
  26361. // although .enabled = false yields an effective weight of zero, this
  26362. // method does *not* change .enabled, because it would be confusing
  26363. ;
  26364. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26365. this.weight = weight; // note: same logic as when updated at runtime
  26366. this._effectiveWeight = this.enabled ? weight : 0;
  26367. return this.stopFading();
  26368. } // return the weight considering fading and .enabled
  26369. ;
  26370. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26371. return this._effectiveWeight;
  26372. };
  26373. _proto.fadeIn = function fadeIn(duration) {
  26374. return this._scheduleFading(duration, 0, 1);
  26375. };
  26376. _proto.fadeOut = function fadeOut(duration) {
  26377. return this._scheduleFading(duration, 1, 0);
  26378. };
  26379. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26380. fadeOutAction.fadeOut(duration);
  26381. this.fadeIn(duration);
  26382. if (warp) {
  26383. var fadeInDuration = this._clip.duration,
  26384. fadeOutDuration = fadeOutAction._clip.duration,
  26385. startEndRatio = fadeOutDuration / fadeInDuration,
  26386. endStartRatio = fadeInDuration / fadeOutDuration;
  26387. fadeOutAction.warp(1.0, startEndRatio, duration);
  26388. this.warp(endStartRatio, 1.0, duration);
  26389. }
  26390. return this;
  26391. };
  26392. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26393. return fadeInAction.crossFadeFrom(this, duration, warp);
  26394. };
  26395. _proto.stopFading = function stopFading() {
  26396. var weightInterpolant = this._weightInterpolant;
  26397. if (weightInterpolant !== null) {
  26398. this._weightInterpolant = null;
  26399. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26400. }
  26401. return this;
  26402. } // Time Scale Control
  26403. // set the time scale stopping any scheduled warping
  26404. // although .paused = true yields an effective time scale of zero, this
  26405. // method does *not* change .paused, because it would be confusing
  26406. ;
  26407. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26408. this.timeScale = timeScale;
  26409. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26410. return this.stopWarping();
  26411. } // return the time scale considering warping and .paused
  26412. ;
  26413. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26414. return this._effectiveTimeScale;
  26415. };
  26416. _proto.setDuration = function setDuration(duration) {
  26417. this.timeScale = this._clip.duration / duration;
  26418. return this.stopWarping();
  26419. };
  26420. _proto.syncWith = function syncWith(action) {
  26421. this.time = action.time;
  26422. this.timeScale = action.timeScale;
  26423. return this.stopWarping();
  26424. };
  26425. _proto.halt = function halt(duration) {
  26426. return this.warp(this._effectiveTimeScale, 0, duration);
  26427. };
  26428. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26429. var mixer = this._mixer,
  26430. now = mixer.time,
  26431. timeScale = this.timeScale;
  26432. var interpolant = this._timeScaleInterpolant;
  26433. if (interpolant === null) {
  26434. interpolant = mixer._lendControlInterpolant();
  26435. this._timeScaleInterpolant = interpolant;
  26436. }
  26437. var times = interpolant.parameterPositions,
  26438. values = interpolant.sampleValues;
  26439. times[0] = now;
  26440. times[1] = now + duration;
  26441. values[0] = startTimeScale / timeScale;
  26442. values[1] = endTimeScale / timeScale;
  26443. return this;
  26444. };
  26445. _proto.stopWarping = function stopWarping() {
  26446. var timeScaleInterpolant = this._timeScaleInterpolant;
  26447. if (timeScaleInterpolant !== null) {
  26448. this._timeScaleInterpolant = null;
  26449. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26450. }
  26451. return this;
  26452. } // Object Accessors
  26453. ;
  26454. _proto.getMixer = function getMixer() {
  26455. return this._mixer;
  26456. };
  26457. _proto.getClip = function getClip() {
  26458. return this._clip;
  26459. };
  26460. _proto.getRoot = function getRoot() {
  26461. return this._localRoot || this._mixer._root;
  26462. } // Interna
  26463. ;
  26464. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26465. // called by the mixer
  26466. if (!this.enabled) {
  26467. // call ._updateWeight() to update ._effectiveWeight
  26468. this._updateWeight(time);
  26469. return;
  26470. }
  26471. var startTime = this._startTime;
  26472. if (startTime !== null) {
  26473. // check for scheduled start of action
  26474. var timeRunning = (time - startTime) * timeDirection;
  26475. if (timeRunning < 0 || timeDirection === 0) {
  26476. return; // yet to come / don't decide when delta = 0
  26477. } // start
  26478. this._startTime = null; // unschedule
  26479. deltaTime = timeDirection * timeRunning;
  26480. } // apply time scale and advance time
  26481. deltaTime *= this._updateTimeScale(time);
  26482. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26483. // an effective weight of 0
  26484. var weight = this._updateWeight(time);
  26485. if (weight > 0) {
  26486. var _interpolants = this._interpolants;
  26487. var propertyMixers = this._propertyBindings;
  26488. switch (this.blendMode) {
  26489. case AdditiveAnimationBlendMode:
  26490. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26491. _interpolants[j].evaluate(clipTime);
  26492. propertyMixers[j].accumulateAdditive(weight);
  26493. }
  26494. break;
  26495. case NormalAnimationBlendMode:
  26496. default:
  26497. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26498. _interpolants[_j].evaluate(clipTime);
  26499. propertyMixers[_j].accumulate(accuIndex, weight);
  26500. }
  26501. }
  26502. }
  26503. };
  26504. _proto._updateWeight = function _updateWeight(time) {
  26505. var weight = 0;
  26506. if (this.enabled) {
  26507. weight = this.weight;
  26508. var interpolant = this._weightInterpolant;
  26509. if (interpolant !== null) {
  26510. var interpolantValue = interpolant.evaluate(time)[0];
  26511. weight *= interpolantValue;
  26512. if (time > interpolant.parameterPositions[1]) {
  26513. this.stopFading();
  26514. if (interpolantValue === 0) {
  26515. // faded out, disable
  26516. this.enabled = false;
  26517. }
  26518. }
  26519. }
  26520. }
  26521. this._effectiveWeight = weight;
  26522. return weight;
  26523. };
  26524. _proto._updateTimeScale = function _updateTimeScale(time) {
  26525. var timeScale = 0;
  26526. if (!this.paused) {
  26527. timeScale = this.timeScale;
  26528. var interpolant = this._timeScaleInterpolant;
  26529. if (interpolant !== null) {
  26530. var interpolantValue = interpolant.evaluate(time)[0];
  26531. timeScale *= interpolantValue;
  26532. if (time > interpolant.parameterPositions[1]) {
  26533. this.stopWarping();
  26534. if (timeScale === 0) {
  26535. // motion has halted, pause
  26536. this.paused = true;
  26537. } else {
  26538. // warp done - apply final time scale
  26539. this.timeScale = timeScale;
  26540. }
  26541. }
  26542. }
  26543. }
  26544. this._effectiveTimeScale = timeScale;
  26545. return timeScale;
  26546. };
  26547. _proto._updateTime = function _updateTime(deltaTime) {
  26548. var duration = this._clip.duration;
  26549. var loop = this.loop;
  26550. var time = this.time + deltaTime;
  26551. var loopCount = this._loopCount;
  26552. var pingPong = loop === LoopPingPong;
  26553. if (deltaTime === 0) {
  26554. if (loopCount === -1) return time;
  26555. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26556. }
  26557. if (loop === LoopOnce) {
  26558. if (loopCount === -1) {
  26559. // just started
  26560. this._loopCount = 0;
  26561. this._setEndings(true, true, false);
  26562. }
  26563. handle_stop: {
  26564. if (time >= duration) {
  26565. time = duration;
  26566. } else if (time < 0) {
  26567. time = 0;
  26568. } else {
  26569. this.time = time;
  26570. break handle_stop;
  26571. }
  26572. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26573. this.time = time;
  26574. this._mixer.dispatchEvent({
  26575. type: 'finished',
  26576. action: this,
  26577. direction: deltaTime < 0 ? -1 : 1
  26578. });
  26579. }
  26580. } else {
  26581. // repetitive Repeat or PingPong
  26582. if (loopCount === -1) {
  26583. // just started
  26584. if (deltaTime >= 0) {
  26585. loopCount = 0;
  26586. this._setEndings(true, this.repetitions === 0, pingPong);
  26587. } else {
  26588. // when looping in reverse direction, the initial
  26589. // transition through zero counts as a repetition,
  26590. // so leave loopCount at -1
  26591. this._setEndings(this.repetitions === 0, true, pingPong);
  26592. }
  26593. }
  26594. if (time >= duration || time < 0) {
  26595. // wrap around
  26596. var loopDelta = Math.floor(time / duration); // signed
  26597. time -= duration * loopDelta;
  26598. loopCount += Math.abs(loopDelta);
  26599. var pending = this.repetitions - loopCount;
  26600. if (pending <= 0) {
  26601. // have to stop (switch state, clamp time, fire event)
  26602. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26603. time = deltaTime > 0 ? duration : 0;
  26604. this.time = time;
  26605. this._mixer.dispatchEvent({
  26606. type: 'finished',
  26607. action: this,
  26608. direction: deltaTime > 0 ? 1 : -1
  26609. });
  26610. } else {
  26611. // keep running
  26612. if (pending === 1) {
  26613. // entering the last round
  26614. var atStart = deltaTime < 0;
  26615. this._setEndings(atStart, !atStart, pingPong);
  26616. } else {
  26617. this._setEndings(false, false, pingPong);
  26618. }
  26619. this._loopCount = loopCount;
  26620. this.time = time;
  26621. this._mixer.dispatchEvent({
  26622. type: 'loop',
  26623. action: this,
  26624. loopDelta: loopDelta
  26625. });
  26626. }
  26627. } else {
  26628. this.time = time;
  26629. }
  26630. if (pingPong && (loopCount & 1) === 1) {
  26631. // invert time for the "pong round"
  26632. return duration - time;
  26633. }
  26634. }
  26635. return time;
  26636. };
  26637. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26638. var settings = this._interpolantSettings;
  26639. if (pingPong) {
  26640. settings.endingStart = ZeroSlopeEnding;
  26641. settings.endingEnd = ZeroSlopeEnding;
  26642. } else {
  26643. // assuming for LoopOnce atStart == atEnd == true
  26644. if (atStart) {
  26645. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26646. } else {
  26647. settings.endingStart = WrapAroundEnding;
  26648. }
  26649. if (atEnd) {
  26650. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26651. } else {
  26652. settings.endingEnd = WrapAroundEnding;
  26653. }
  26654. }
  26655. };
  26656. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26657. var mixer = this._mixer,
  26658. now = mixer.time;
  26659. var interpolant = this._weightInterpolant;
  26660. if (interpolant === null) {
  26661. interpolant = mixer._lendControlInterpolant();
  26662. this._weightInterpolant = interpolant;
  26663. }
  26664. var times = interpolant.parameterPositions,
  26665. values = interpolant.sampleValues;
  26666. times[0] = now;
  26667. values[0] = weightNow;
  26668. times[1] = now + duration;
  26669. values[1] = weightThen;
  26670. return this;
  26671. };
  26672. return AnimationAction;
  26673. }();
  26674. function AnimationMixer(root) {
  26675. this._root = root;
  26676. this._initMemoryManager();
  26677. this._accuIndex = 0;
  26678. this.time = 0;
  26679. this.timeScale = 1.0;
  26680. }
  26681. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26682. constructor: AnimationMixer,
  26683. _bindAction: function _bindAction(action, prototypeAction) {
  26684. var root = action._localRoot || this._root,
  26685. tracks = action._clip.tracks,
  26686. nTracks = tracks.length,
  26687. bindings = action._propertyBindings,
  26688. interpolants = action._interpolants,
  26689. rootUuid = root.uuid,
  26690. bindingsByRoot = this._bindingsByRootAndName;
  26691. var bindingsByName = bindingsByRoot[rootUuid];
  26692. if (bindingsByName === undefined) {
  26693. bindingsByName = {};
  26694. bindingsByRoot[rootUuid] = bindingsByName;
  26695. }
  26696. for (var i = 0; i !== nTracks; ++i) {
  26697. var track = tracks[i],
  26698. trackName = track.name;
  26699. var binding = bindingsByName[trackName];
  26700. if (binding !== undefined) {
  26701. bindings[i] = binding;
  26702. } else {
  26703. binding = bindings[i];
  26704. if (binding !== undefined) {
  26705. // existing binding, make sure the cache knows
  26706. if (binding._cacheIndex === null) {
  26707. ++binding.referenceCount;
  26708. this._addInactiveBinding(binding, rootUuid, trackName);
  26709. }
  26710. continue;
  26711. }
  26712. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26713. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26714. ++binding.referenceCount;
  26715. this._addInactiveBinding(binding, rootUuid, trackName);
  26716. bindings[i] = binding;
  26717. }
  26718. interpolants[i].resultBuffer = binding.buffer;
  26719. }
  26720. },
  26721. _activateAction: function _activateAction(action) {
  26722. if (!this._isActiveAction(action)) {
  26723. if (action._cacheIndex === null) {
  26724. // this action has been forgotten by the cache, but the user
  26725. // appears to be still using it -> rebind
  26726. var rootUuid = (action._localRoot || this._root).uuid,
  26727. clipUuid = action._clip.uuid,
  26728. actionsForClip = this._actionsByClip[clipUuid];
  26729. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26730. this._addInactiveAction(action, clipUuid, rootUuid);
  26731. }
  26732. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26733. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26734. var binding = bindings[i];
  26735. if (binding.useCount++ === 0) {
  26736. this._lendBinding(binding);
  26737. binding.saveOriginalState();
  26738. }
  26739. }
  26740. this._lendAction(action);
  26741. }
  26742. },
  26743. _deactivateAction: function _deactivateAction(action) {
  26744. if (this._isActiveAction(action)) {
  26745. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26746. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26747. var binding = bindings[i];
  26748. if (--binding.useCount === 0) {
  26749. binding.restoreOriginalState();
  26750. this._takeBackBinding(binding);
  26751. }
  26752. }
  26753. this._takeBackAction(action);
  26754. }
  26755. },
  26756. // Memory manager
  26757. _initMemoryManager: function _initMemoryManager() {
  26758. this._actions = []; // 'nActiveActions' followed by inactive ones
  26759. this._nActiveActions = 0;
  26760. this._actionsByClip = {}; // inside:
  26761. // {
  26762. // knownActions: Array< AnimationAction > - used as prototypes
  26763. // actionByRoot: AnimationAction - lookup
  26764. // }
  26765. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26766. this._nActiveBindings = 0;
  26767. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26768. this._controlInterpolants = []; // same game as above
  26769. this._nActiveControlInterpolants = 0;
  26770. var scope = this;
  26771. this.stats = {
  26772. actions: {
  26773. get total() {
  26774. return scope._actions.length;
  26775. },
  26776. get inUse() {
  26777. return scope._nActiveActions;
  26778. }
  26779. },
  26780. bindings: {
  26781. get total() {
  26782. return scope._bindings.length;
  26783. },
  26784. get inUse() {
  26785. return scope._nActiveBindings;
  26786. }
  26787. },
  26788. controlInterpolants: {
  26789. get total() {
  26790. return scope._controlInterpolants.length;
  26791. },
  26792. get inUse() {
  26793. return scope._nActiveControlInterpolants;
  26794. }
  26795. }
  26796. };
  26797. },
  26798. // Memory management for AnimationAction objects
  26799. _isActiveAction: function _isActiveAction(action) {
  26800. var index = action._cacheIndex;
  26801. return index !== null && index < this._nActiveActions;
  26802. },
  26803. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26804. var actions = this._actions,
  26805. actionsByClip = this._actionsByClip;
  26806. var actionsForClip = actionsByClip[clipUuid];
  26807. if (actionsForClip === undefined) {
  26808. actionsForClip = {
  26809. knownActions: [action],
  26810. actionByRoot: {}
  26811. };
  26812. action._byClipCacheIndex = 0;
  26813. actionsByClip[clipUuid] = actionsForClip;
  26814. } else {
  26815. var knownActions = actionsForClip.knownActions;
  26816. action._byClipCacheIndex = knownActions.length;
  26817. knownActions.push(action);
  26818. }
  26819. action._cacheIndex = actions.length;
  26820. actions.push(action);
  26821. actionsForClip.actionByRoot[rootUuid] = action;
  26822. },
  26823. _removeInactiveAction: function _removeInactiveAction(action) {
  26824. var actions = this._actions,
  26825. lastInactiveAction = actions[actions.length - 1],
  26826. cacheIndex = action._cacheIndex;
  26827. lastInactiveAction._cacheIndex = cacheIndex;
  26828. actions[cacheIndex] = lastInactiveAction;
  26829. actions.pop();
  26830. action._cacheIndex = null;
  26831. var clipUuid = action._clip.uuid,
  26832. actionsByClip = this._actionsByClip,
  26833. actionsForClip = actionsByClip[clipUuid],
  26834. knownActionsForClip = actionsForClip.knownActions,
  26835. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  26836. byClipCacheIndex = action._byClipCacheIndex;
  26837. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26838. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  26839. knownActionsForClip.pop();
  26840. action._byClipCacheIndex = null;
  26841. var actionByRoot = actionsForClip.actionByRoot,
  26842. rootUuid = (action._localRoot || this._root).uuid;
  26843. delete actionByRoot[rootUuid];
  26844. if (knownActionsForClip.length === 0) {
  26845. delete actionsByClip[clipUuid];
  26846. }
  26847. this._removeInactiveBindingsForAction(action);
  26848. },
  26849. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  26850. var bindings = action._propertyBindings;
  26851. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26852. var binding = bindings[i];
  26853. if (--binding.referenceCount === 0) {
  26854. this._removeInactiveBinding(binding);
  26855. }
  26856. }
  26857. },
  26858. _lendAction: function _lendAction(action) {
  26859. // [ active actions | inactive actions ]
  26860. // [ active actions >| inactive actions ]
  26861. // s a
  26862. // <-swap->
  26863. // a s
  26864. var actions = this._actions,
  26865. prevIndex = action._cacheIndex,
  26866. lastActiveIndex = this._nActiveActions++,
  26867. firstInactiveAction = actions[lastActiveIndex];
  26868. action._cacheIndex = lastActiveIndex;
  26869. actions[lastActiveIndex] = action;
  26870. firstInactiveAction._cacheIndex = prevIndex;
  26871. actions[prevIndex] = firstInactiveAction;
  26872. },
  26873. _takeBackAction: function _takeBackAction(action) {
  26874. // [ active actions | inactive actions ]
  26875. // [ active actions |< inactive actions ]
  26876. // a s
  26877. // <-swap->
  26878. // s a
  26879. var actions = this._actions,
  26880. prevIndex = action._cacheIndex,
  26881. firstInactiveIndex = --this._nActiveActions,
  26882. lastActiveAction = actions[firstInactiveIndex];
  26883. action._cacheIndex = firstInactiveIndex;
  26884. actions[firstInactiveIndex] = action;
  26885. lastActiveAction._cacheIndex = prevIndex;
  26886. actions[prevIndex] = lastActiveAction;
  26887. },
  26888. // Memory management for PropertyMixer objects
  26889. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  26890. var bindingsByRoot = this._bindingsByRootAndName,
  26891. bindings = this._bindings;
  26892. var bindingByName = bindingsByRoot[rootUuid];
  26893. if (bindingByName === undefined) {
  26894. bindingByName = {};
  26895. bindingsByRoot[rootUuid] = bindingByName;
  26896. }
  26897. bindingByName[trackName] = binding;
  26898. binding._cacheIndex = bindings.length;
  26899. bindings.push(binding);
  26900. },
  26901. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  26902. var bindings = this._bindings,
  26903. propBinding = binding.binding,
  26904. rootUuid = propBinding.rootNode.uuid,
  26905. trackName = propBinding.path,
  26906. bindingsByRoot = this._bindingsByRootAndName,
  26907. bindingByName = bindingsByRoot[rootUuid],
  26908. lastInactiveBinding = bindings[bindings.length - 1],
  26909. cacheIndex = binding._cacheIndex;
  26910. lastInactiveBinding._cacheIndex = cacheIndex;
  26911. bindings[cacheIndex] = lastInactiveBinding;
  26912. bindings.pop();
  26913. delete bindingByName[trackName];
  26914. if (Object.keys(bindingByName).length === 0) {
  26915. delete bindingsByRoot[rootUuid];
  26916. }
  26917. },
  26918. _lendBinding: function _lendBinding(binding) {
  26919. var bindings = this._bindings,
  26920. prevIndex = binding._cacheIndex,
  26921. lastActiveIndex = this._nActiveBindings++,
  26922. firstInactiveBinding = bindings[lastActiveIndex];
  26923. binding._cacheIndex = lastActiveIndex;
  26924. bindings[lastActiveIndex] = binding;
  26925. firstInactiveBinding._cacheIndex = prevIndex;
  26926. bindings[prevIndex] = firstInactiveBinding;
  26927. },
  26928. _takeBackBinding: function _takeBackBinding(binding) {
  26929. var bindings = this._bindings,
  26930. prevIndex = binding._cacheIndex,
  26931. firstInactiveIndex = --this._nActiveBindings,
  26932. lastActiveBinding = bindings[firstInactiveIndex];
  26933. binding._cacheIndex = firstInactiveIndex;
  26934. bindings[firstInactiveIndex] = binding;
  26935. lastActiveBinding._cacheIndex = prevIndex;
  26936. bindings[prevIndex] = lastActiveBinding;
  26937. },
  26938. // Memory management of Interpolants for weight and time scale
  26939. _lendControlInterpolant: function _lendControlInterpolant() {
  26940. var interpolants = this._controlInterpolants,
  26941. lastActiveIndex = this._nActiveControlInterpolants++;
  26942. var interpolant = interpolants[lastActiveIndex];
  26943. if (interpolant === undefined) {
  26944. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  26945. interpolant.__cacheIndex = lastActiveIndex;
  26946. interpolants[lastActiveIndex] = interpolant;
  26947. }
  26948. return interpolant;
  26949. },
  26950. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  26951. var interpolants = this._controlInterpolants,
  26952. prevIndex = interpolant.__cacheIndex,
  26953. firstInactiveIndex = --this._nActiveControlInterpolants,
  26954. lastActiveInterpolant = interpolants[firstInactiveIndex];
  26955. interpolant.__cacheIndex = firstInactiveIndex;
  26956. interpolants[firstInactiveIndex] = interpolant;
  26957. lastActiveInterpolant.__cacheIndex = prevIndex;
  26958. interpolants[prevIndex] = lastActiveInterpolant;
  26959. },
  26960. _controlInterpolantsResultBuffer: new Float32Array(1),
  26961. // return an action for a clip optionally using a custom root target
  26962. // object (this method allocates a lot of dynamic memory in case a
  26963. // previously unknown clip/root combination is specified)
  26964. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  26965. var root = optionalRoot || this._root,
  26966. rootUuid = root.uuid;
  26967. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  26968. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  26969. var actionsForClip = this._actionsByClip[clipUuid];
  26970. var prototypeAction = null;
  26971. if (blendMode === undefined) {
  26972. if (clipObject !== null) {
  26973. blendMode = clipObject.blendMode;
  26974. } else {
  26975. blendMode = NormalAnimationBlendMode;
  26976. }
  26977. }
  26978. if (actionsForClip !== undefined) {
  26979. var existingAction = actionsForClip.actionByRoot[rootUuid];
  26980. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  26981. return existingAction;
  26982. } // we know the clip, so we don't have to parse all
  26983. // the bindings again but can just copy
  26984. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  26985. if (clipObject === null) clipObject = prototypeAction._clip;
  26986. } // clip must be known when specified via string
  26987. if (clipObject === null) return null; // allocate all resources required to run it
  26988. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  26989. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  26990. this._addInactiveAction(newAction, clipUuid, rootUuid);
  26991. return newAction;
  26992. },
  26993. // get an existing action
  26994. existingAction: function existingAction(clip, optionalRoot) {
  26995. var root = optionalRoot || this._root,
  26996. rootUuid = root.uuid,
  26997. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  26998. clipUuid = clipObject ? clipObject.uuid : clip,
  26999. actionsForClip = this._actionsByClip[clipUuid];
  27000. if (actionsForClip !== undefined) {
  27001. return actionsForClip.actionByRoot[rootUuid] || null;
  27002. }
  27003. return null;
  27004. },
  27005. // deactivates all previously scheduled actions
  27006. stopAllAction: function stopAllAction() {
  27007. var actions = this._actions,
  27008. nActions = this._nActiveActions;
  27009. for (var i = nActions - 1; i >= 0; --i) {
  27010. actions[i].stop();
  27011. }
  27012. return this;
  27013. },
  27014. // advance the time and update apply the animation
  27015. update: function update(deltaTime) {
  27016. deltaTime *= this.timeScale;
  27017. var actions = this._actions,
  27018. nActions = this._nActiveActions,
  27019. time = this.time += deltaTime,
  27020. timeDirection = Math.sign(deltaTime),
  27021. accuIndex = this._accuIndex ^= 1; // run active actions
  27022. for (var i = 0; i !== nActions; ++i) {
  27023. var action = actions[i];
  27024. action._update(time, deltaTime, timeDirection, accuIndex);
  27025. } // update scene graph
  27026. var bindings = this._bindings,
  27027. nBindings = this._nActiveBindings;
  27028. for (var _i = 0; _i !== nBindings; ++_i) {
  27029. bindings[_i].apply(accuIndex);
  27030. }
  27031. return this;
  27032. },
  27033. // Allows you to seek to a specific time in an animation.
  27034. setTime: function setTime(timeInSeconds) {
  27035. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27036. for (var i = 0; i < this._actions.length; i++) {
  27037. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27038. }
  27039. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27040. },
  27041. // return this mixer's root target object
  27042. getRoot: function getRoot() {
  27043. return this._root;
  27044. },
  27045. // free all resources specific to a particular clip
  27046. uncacheClip: function uncacheClip(clip) {
  27047. var actions = this._actions,
  27048. clipUuid = clip.uuid,
  27049. actionsByClip = this._actionsByClip,
  27050. actionsForClip = actionsByClip[clipUuid];
  27051. if (actionsForClip !== undefined) {
  27052. // note: just calling _removeInactiveAction would mess up the
  27053. // iteration state and also require updating the state we can
  27054. // just throw away
  27055. var actionsToRemove = actionsForClip.knownActions;
  27056. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27057. var action = actionsToRemove[i];
  27058. this._deactivateAction(action);
  27059. var cacheIndex = action._cacheIndex,
  27060. lastInactiveAction = actions[actions.length - 1];
  27061. action._cacheIndex = null;
  27062. action._byClipCacheIndex = null;
  27063. lastInactiveAction._cacheIndex = cacheIndex;
  27064. actions[cacheIndex] = lastInactiveAction;
  27065. actions.pop();
  27066. this._removeInactiveBindingsForAction(action);
  27067. }
  27068. delete actionsByClip[clipUuid];
  27069. }
  27070. },
  27071. // free all resources specific to a particular root target object
  27072. uncacheRoot: function uncacheRoot(root) {
  27073. var rootUuid = root.uuid,
  27074. actionsByClip = this._actionsByClip;
  27075. for (var clipUuid in actionsByClip) {
  27076. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27077. action = actionByRoot[rootUuid];
  27078. if (action !== undefined) {
  27079. this._deactivateAction(action);
  27080. this._removeInactiveAction(action);
  27081. }
  27082. }
  27083. var bindingsByRoot = this._bindingsByRootAndName,
  27084. bindingByName = bindingsByRoot[rootUuid];
  27085. if (bindingByName !== undefined) {
  27086. for (var trackName in bindingByName) {
  27087. var binding = bindingByName[trackName];
  27088. binding.restoreOriginalState();
  27089. this._removeInactiveBinding(binding);
  27090. }
  27091. }
  27092. },
  27093. // remove a targeted clip from the cache
  27094. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27095. var action = this.existingAction(clip, optionalRoot);
  27096. if (action !== null) {
  27097. this._deactivateAction(action);
  27098. this._removeInactiveAction(action);
  27099. }
  27100. }
  27101. });
  27102. var Uniform = /*#__PURE__*/function () {
  27103. function Uniform(value) {
  27104. if (typeof value === 'string') {
  27105. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27106. value = arguments[1];
  27107. }
  27108. this.value = value;
  27109. }
  27110. var _proto = Uniform.prototype;
  27111. _proto.clone = function clone() {
  27112. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27113. };
  27114. return Uniform;
  27115. }();
  27116. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27117. InterleavedBuffer.call(this, array, stride);
  27118. this.meshPerAttribute = meshPerAttribute || 1;
  27119. }
  27120. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27121. constructor: InstancedInterleavedBuffer,
  27122. isInstancedInterleavedBuffer: true,
  27123. copy: function copy(source) {
  27124. InterleavedBuffer.prototype.copy.call(this, source);
  27125. this.meshPerAttribute = source.meshPerAttribute;
  27126. return this;
  27127. },
  27128. clone: function clone(data) {
  27129. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27130. ib.meshPerAttribute = this.meshPerAttribute;
  27131. return ib;
  27132. },
  27133. toJSON: function toJSON(data) {
  27134. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27135. json.isInstancedInterleavedBuffer = true;
  27136. json.meshPerAttribute = this.meshPerAttribute;
  27137. return json;
  27138. }
  27139. });
  27140. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27141. this.buffer = buffer;
  27142. this.type = type;
  27143. this.itemSize = itemSize;
  27144. this.elementSize = elementSize;
  27145. this.count = count;
  27146. this.version = 0;
  27147. }
  27148. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27149. set: function set(value) {
  27150. if (value === true) this.version++;
  27151. }
  27152. });
  27153. Object.assign(GLBufferAttribute.prototype, {
  27154. isGLBufferAttribute: true,
  27155. setBuffer: function setBuffer(buffer) {
  27156. this.buffer = buffer;
  27157. return this;
  27158. },
  27159. setType: function setType(type, elementSize) {
  27160. this.type = type;
  27161. this.elementSize = elementSize;
  27162. return this;
  27163. },
  27164. setItemSize: function setItemSize(itemSize) {
  27165. this.itemSize = itemSize;
  27166. return this;
  27167. },
  27168. setCount: function setCount(count) {
  27169. this.count = count;
  27170. return this;
  27171. }
  27172. });
  27173. function Raycaster(origin, direction, near, far) {
  27174. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27175. this.near = near || 0;
  27176. this.far = far || Infinity;
  27177. this.camera = null;
  27178. this.layers = new Layers();
  27179. this.params = {
  27180. Mesh: {},
  27181. Line: {
  27182. threshold: 1
  27183. },
  27184. LOD: {},
  27185. Points: {
  27186. threshold: 1
  27187. },
  27188. Sprite: {}
  27189. };
  27190. Object.defineProperties(this.params, {
  27191. PointCloud: {
  27192. get: function get() {
  27193. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27194. return this.Points;
  27195. }
  27196. }
  27197. });
  27198. }
  27199. function ascSort(a, b) {
  27200. return a.distance - b.distance;
  27201. }
  27202. function _intersectObject(object, raycaster, intersects, recursive) {
  27203. if (object.layers.test(raycaster.layers)) {
  27204. object.raycast(raycaster, intersects);
  27205. }
  27206. if (recursive === true) {
  27207. var children = object.children;
  27208. for (var i = 0, l = children.length; i < l; i++) {
  27209. _intersectObject(children[i], raycaster, intersects, true);
  27210. }
  27211. }
  27212. }
  27213. Object.assign(Raycaster.prototype, {
  27214. set: function set(origin, direction) {
  27215. // direction is assumed to be normalized (for accurate distance calculations)
  27216. this.ray.set(origin, direction);
  27217. },
  27218. setFromCamera: function setFromCamera(coords, camera) {
  27219. if (camera && camera.isPerspectiveCamera) {
  27220. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27221. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27222. this.camera = camera;
  27223. } else if (camera && camera.isOrthographicCamera) {
  27224. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27225. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27226. this.camera = camera;
  27227. } else {
  27228. console.error('THREE.Raycaster: Unsupported camera type.');
  27229. }
  27230. },
  27231. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27232. var intersects = optionalTarget || [];
  27233. _intersectObject(object, this, intersects, recursive);
  27234. intersects.sort(ascSort);
  27235. return intersects;
  27236. },
  27237. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27238. var intersects = optionalTarget || [];
  27239. if (Array.isArray(objects) === false) {
  27240. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27241. return intersects;
  27242. }
  27243. for (var i = 0, l = objects.length; i < l; i++) {
  27244. _intersectObject(objects[i], this, intersects, recursive);
  27245. }
  27246. intersects.sort(ascSort);
  27247. return intersects;
  27248. }
  27249. });
  27250. /**
  27251. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27252. *
  27253. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27254. * The azimuthal angle (theta) is measured from the positive z-axis.
  27255. */
  27256. var Spherical = /*#__PURE__*/function () {
  27257. function Spherical(radius, phi, theta) {
  27258. if (radius === void 0) {
  27259. radius = 1;
  27260. }
  27261. if (phi === void 0) {
  27262. phi = 0;
  27263. }
  27264. if (theta === void 0) {
  27265. theta = 0;
  27266. }
  27267. this.radius = radius;
  27268. this.phi = phi; // polar angle
  27269. this.theta = theta; // azimuthal angle
  27270. return this;
  27271. }
  27272. var _proto = Spherical.prototype;
  27273. _proto.set = function set(radius, phi, theta) {
  27274. this.radius = radius;
  27275. this.phi = phi;
  27276. this.theta = theta;
  27277. return this;
  27278. };
  27279. _proto.clone = function clone() {
  27280. return new this.constructor().copy(this);
  27281. };
  27282. _proto.copy = function copy(other) {
  27283. this.radius = other.radius;
  27284. this.phi = other.phi;
  27285. this.theta = other.theta;
  27286. return this;
  27287. } // restrict phi to be betwee EPS and PI-EPS
  27288. ;
  27289. _proto.makeSafe = function makeSafe() {
  27290. var EPS = 0.000001;
  27291. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27292. return this;
  27293. };
  27294. _proto.setFromVector3 = function setFromVector3(v) {
  27295. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27296. };
  27297. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27298. this.radius = Math.sqrt(x * x + y * y + z * z);
  27299. if (this.radius === 0) {
  27300. this.theta = 0;
  27301. this.phi = 0;
  27302. } else {
  27303. this.theta = Math.atan2(x, z);
  27304. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27305. }
  27306. return this;
  27307. };
  27308. return Spherical;
  27309. }();
  27310. /**
  27311. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27312. */
  27313. var Cylindrical = /*#__PURE__*/function () {
  27314. function Cylindrical(radius, theta, y) {
  27315. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27316. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27317. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27318. return this;
  27319. }
  27320. var _proto = Cylindrical.prototype;
  27321. _proto.set = function set(radius, theta, y) {
  27322. this.radius = radius;
  27323. this.theta = theta;
  27324. this.y = y;
  27325. return this;
  27326. };
  27327. _proto.clone = function clone() {
  27328. return new this.constructor().copy(this);
  27329. };
  27330. _proto.copy = function copy(other) {
  27331. this.radius = other.radius;
  27332. this.theta = other.theta;
  27333. this.y = other.y;
  27334. return this;
  27335. };
  27336. _proto.setFromVector3 = function setFromVector3(v) {
  27337. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27338. };
  27339. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27340. this.radius = Math.sqrt(x * x + z * z);
  27341. this.theta = Math.atan2(x, z);
  27342. this.y = y;
  27343. return this;
  27344. };
  27345. return Cylindrical;
  27346. }();
  27347. var _vector$7 = /*@__PURE__*/new Vector2();
  27348. var Box2 = /*#__PURE__*/function () {
  27349. function Box2(min, max) {
  27350. Object.defineProperty(this, 'isBox2', {
  27351. value: true
  27352. });
  27353. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27354. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27355. }
  27356. var _proto = Box2.prototype;
  27357. _proto.set = function set(min, max) {
  27358. this.min.copy(min);
  27359. this.max.copy(max);
  27360. return this;
  27361. };
  27362. _proto.setFromPoints = function setFromPoints(points) {
  27363. this.makeEmpty();
  27364. for (var i = 0, il = points.length; i < il; i++) {
  27365. this.expandByPoint(points[i]);
  27366. }
  27367. return this;
  27368. };
  27369. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27370. var halfSize = _vector$7.copy(size).multiplyScalar(0.5);
  27371. this.min.copy(center).sub(halfSize);
  27372. this.max.copy(center).add(halfSize);
  27373. return this;
  27374. };
  27375. _proto.clone = function clone() {
  27376. return new this.constructor().copy(this);
  27377. };
  27378. _proto.copy = function copy(box) {
  27379. this.min.copy(box.min);
  27380. this.max.copy(box.max);
  27381. return this;
  27382. };
  27383. _proto.makeEmpty = function makeEmpty() {
  27384. this.min.x = this.min.y = +Infinity;
  27385. this.max.x = this.max.y = -Infinity;
  27386. return this;
  27387. };
  27388. _proto.isEmpty = function isEmpty() {
  27389. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27390. return this.max.x < this.min.x || this.max.y < this.min.y;
  27391. };
  27392. _proto.getCenter = function getCenter(target) {
  27393. if (target === undefined) {
  27394. console.warn('THREE.Box2: .getCenter() target is now required');
  27395. target = new Vector2();
  27396. }
  27397. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27398. };
  27399. _proto.getSize = function getSize(target) {
  27400. if (target === undefined) {
  27401. console.warn('THREE.Box2: .getSize() target is now required');
  27402. target = new Vector2();
  27403. }
  27404. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27405. };
  27406. _proto.expandByPoint = function expandByPoint(point) {
  27407. this.min.min(point);
  27408. this.max.max(point);
  27409. return this;
  27410. };
  27411. _proto.expandByVector = function expandByVector(vector) {
  27412. this.min.sub(vector);
  27413. this.max.add(vector);
  27414. return this;
  27415. };
  27416. _proto.expandByScalar = function expandByScalar(scalar) {
  27417. this.min.addScalar(-scalar);
  27418. this.max.addScalar(scalar);
  27419. return this;
  27420. };
  27421. _proto.containsPoint = function containsPoint(point) {
  27422. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27423. };
  27424. _proto.containsBox = function containsBox(box) {
  27425. 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;
  27426. };
  27427. _proto.getParameter = function getParameter(point, target) {
  27428. // This can potentially have a divide by zero if the box
  27429. // has a size dimension of 0.
  27430. if (target === undefined) {
  27431. console.warn('THREE.Box2: .getParameter() target is now required');
  27432. target = new Vector2();
  27433. }
  27434. 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));
  27435. };
  27436. _proto.intersectsBox = function intersectsBox(box) {
  27437. // using 4 splitting planes to rule out intersections
  27438. 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;
  27439. };
  27440. _proto.clampPoint = function clampPoint(point, target) {
  27441. if (target === undefined) {
  27442. console.warn('THREE.Box2: .clampPoint() target is now required');
  27443. target = new Vector2();
  27444. }
  27445. return target.copy(point).clamp(this.min, this.max);
  27446. };
  27447. _proto.distanceToPoint = function distanceToPoint(point) {
  27448. var clampedPoint = _vector$7.copy(point).clamp(this.min, this.max);
  27449. return clampedPoint.sub(point).length();
  27450. };
  27451. _proto.intersect = function intersect(box) {
  27452. this.min.max(box.min);
  27453. this.max.min(box.max);
  27454. return this;
  27455. };
  27456. _proto.union = function union(box) {
  27457. this.min.min(box.min);
  27458. this.max.max(box.max);
  27459. return this;
  27460. };
  27461. _proto.translate = function translate(offset) {
  27462. this.min.add(offset);
  27463. this.max.add(offset);
  27464. return this;
  27465. };
  27466. _proto.equals = function equals(box) {
  27467. return box.min.equals(this.min) && box.max.equals(this.max);
  27468. };
  27469. return Box2;
  27470. }();
  27471. var _startP = /*@__PURE__*/new Vector3();
  27472. var _startEnd = /*@__PURE__*/new Vector3();
  27473. var Line3 = /*#__PURE__*/function () {
  27474. function Line3(start, end) {
  27475. this.start = start !== undefined ? start : new Vector3();
  27476. this.end = end !== undefined ? end : new Vector3();
  27477. }
  27478. var _proto = Line3.prototype;
  27479. _proto.set = function set(start, end) {
  27480. this.start.copy(start);
  27481. this.end.copy(end);
  27482. return this;
  27483. };
  27484. _proto.clone = function clone() {
  27485. return new this.constructor().copy(this);
  27486. };
  27487. _proto.copy = function copy(line) {
  27488. this.start.copy(line.start);
  27489. this.end.copy(line.end);
  27490. return this;
  27491. };
  27492. _proto.getCenter = function getCenter(target) {
  27493. if (target === undefined) {
  27494. console.warn('THREE.Line3: .getCenter() target is now required');
  27495. target = new Vector3();
  27496. }
  27497. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27498. };
  27499. _proto.delta = function delta(target) {
  27500. if (target === undefined) {
  27501. console.warn('THREE.Line3: .delta() target is now required');
  27502. target = new Vector3();
  27503. }
  27504. return target.subVectors(this.end, this.start);
  27505. };
  27506. _proto.distanceSq = function distanceSq() {
  27507. return this.start.distanceToSquared(this.end);
  27508. };
  27509. _proto.distance = function distance() {
  27510. return this.start.distanceTo(this.end);
  27511. };
  27512. _proto.at = function at(t, target) {
  27513. if (target === undefined) {
  27514. console.warn('THREE.Line3: .at() target is now required');
  27515. target = new Vector3();
  27516. }
  27517. return this.delta(target).multiplyScalar(t).add(this.start);
  27518. };
  27519. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27520. _startP.subVectors(point, this.start);
  27521. _startEnd.subVectors(this.end, this.start);
  27522. var startEnd2 = _startEnd.dot(_startEnd);
  27523. var startEnd_startP = _startEnd.dot(_startP);
  27524. var t = startEnd_startP / startEnd2;
  27525. if (clampToLine) {
  27526. t = MathUtils.clamp(t, 0, 1);
  27527. }
  27528. return t;
  27529. };
  27530. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27531. var t = this.closestPointToPointParameter(point, clampToLine);
  27532. if (target === undefined) {
  27533. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27534. target = new Vector3();
  27535. }
  27536. return this.delta(target).multiplyScalar(t).add(this.start);
  27537. };
  27538. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27539. this.start.applyMatrix4(matrix);
  27540. this.end.applyMatrix4(matrix);
  27541. return this;
  27542. };
  27543. _proto.equals = function equals(line) {
  27544. return line.start.equals(this.start) && line.end.equals(this.end);
  27545. };
  27546. return Line3;
  27547. }();
  27548. function ImmediateRenderObject(material) {
  27549. Object3D.call(this);
  27550. this.material = material;
  27551. this.render = function ()
  27552. /* renderCallback */
  27553. {};
  27554. this.hasPositions = false;
  27555. this.hasNormals = false;
  27556. this.hasColors = false;
  27557. this.hasUvs = false;
  27558. this.positionArray = null;
  27559. this.normalArray = null;
  27560. this.colorArray = null;
  27561. this.uvArray = null;
  27562. this.count = 0;
  27563. }
  27564. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27565. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27566. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27567. var _vector$8 = /*@__PURE__*/new Vector3();
  27568. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27569. _inheritsLoose(SpotLightHelper, _Object3D);
  27570. function SpotLightHelper(light, color) {
  27571. var _this;
  27572. _this = _Object3D.call(this) || this;
  27573. _this.light = light;
  27574. _this.light.updateMatrixWorld();
  27575. _this.matrix = light.matrixWorld;
  27576. _this.matrixAutoUpdate = false;
  27577. _this.color = color;
  27578. var geometry = new BufferGeometry();
  27579. 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];
  27580. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27581. var p1 = i / l * Math.PI * 2;
  27582. var p2 = j / l * Math.PI * 2;
  27583. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27584. }
  27585. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27586. var material = new LineBasicMaterial({
  27587. fog: false,
  27588. toneMapped: false
  27589. });
  27590. _this.cone = new LineSegments(geometry, material);
  27591. _this.add(_this.cone);
  27592. _this.update();
  27593. return _this;
  27594. }
  27595. var _proto = SpotLightHelper.prototype;
  27596. _proto.dispose = function dispose() {
  27597. this.cone.geometry.dispose();
  27598. this.cone.material.dispose();
  27599. };
  27600. _proto.update = function update() {
  27601. this.light.updateMatrixWorld();
  27602. var coneLength = this.light.distance ? this.light.distance : 1000;
  27603. var coneWidth = coneLength * Math.tan(this.light.angle);
  27604. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27605. _vector$8.setFromMatrixPosition(this.light.target.matrixWorld);
  27606. this.cone.lookAt(_vector$8);
  27607. if (this.color !== undefined) {
  27608. this.cone.material.color.set(this.color);
  27609. } else {
  27610. this.cone.material.color.copy(this.light.color);
  27611. }
  27612. };
  27613. return SpotLightHelper;
  27614. }(Object3D);
  27615. var _vector$9 = /*@__PURE__*/new Vector3();
  27616. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27617. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27618. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27619. _inheritsLoose(SkeletonHelper, _LineSegments);
  27620. function SkeletonHelper(object) {
  27621. var _this;
  27622. var bones = getBoneList(object);
  27623. var geometry = new BufferGeometry();
  27624. var vertices = [];
  27625. var colors = [];
  27626. var color1 = new Color(0, 0, 1);
  27627. var color2 = new Color(0, 1, 0);
  27628. for (var i = 0; i < bones.length; i++) {
  27629. var bone = bones[i];
  27630. if (bone.parent && bone.parent.isBone) {
  27631. vertices.push(0, 0, 0);
  27632. vertices.push(0, 0, 0);
  27633. colors.push(color1.r, color1.g, color1.b);
  27634. colors.push(color2.r, color2.g, color2.b);
  27635. }
  27636. }
  27637. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27638. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27639. var material = new LineBasicMaterial({
  27640. vertexColors: true,
  27641. depthTest: false,
  27642. depthWrite: false,
  27643. toneMapped: false,
  27644. transparent: true
  27645. });
  27646. _this = _LineSegments.call(this, geometry, material) || this;
  27647. _this.type = 'SkeletonHelper';
  27648. _this.isSkeletonHelper = true;
  27649. _this.root = object;
  27650. _this.bones = bones;
  27651. _this.matrix = object.matrixWorld;
  27652. _this.matrixAutoUpdate = false;
  27653. return _this;
  27654. }
  27655. var _proto = SkeletonHelper.prototype;
  27656. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27657. var bones = this.bones;
  27658. var geometry = this.geometry;
  27659. var position = geometry.getAttribute('position');
  27660. _matrixWorldInv.getInverse(this.root.matrixWorld);
  27661. for (var i = 0, j = 0; i < bones.length; i++) {
  27662. var bone = bones[i];
  27663. if (bone.parent && bone.parent.isBone) {
  27664. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27665. _vector$9.setFromMatrixPosition(_boneMatrix);
  27666. position.setXYZ(j, _vector$9.x, _vector$9.y, _vector$9.z);
  27667. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27668. _vector$9.setFromMatrixPosition(_boneMatrix);
  27669. position.setXYZ(j + 1, _vector$9.x, _vector$9.y, _vector$9.z);
  27670. j += 2;
  27671. }
  27672. }
  27673. geometry.getAttribute('position').needsUpdate = true;
  27674. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27675. };
  27676. return SkeletonHelper;
  27677. }(LineSegments);
  27678. function getBoneList(object) {
  27679. var boneList = [];
  27680. if (object && object.isBone) {
  27681. boneList.push(object);
  27682. }
  27683. for (var i = 0; i < object.children.length; i++) {
  27684. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27685. }
  27686. return boneList;
  27687. }
  27688. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27689. _inheritsLoose(PointLightHelper, _Mesh);
  27690. function PointLightHelper(light, sphereSize, color) {
  27691. var _this;
  27692. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  27693. var material = new MeshBasicMaterial({
  27694. wireframe: true,
  27695. fog: false,
  27696. toneMapped: false
  27697. });
  27698. _this = _Mesh.call(this, geometry, material) || this;
  27699. _this.light = light;
  27700. _this.light.updateMatrixWorld();
  27701. _this.color = color;
  27702. _this.type = 'PointLightHelper';
  27703. _this.matrix = _this.light.matrixWorld;
  27704. _this.matrixAutoUpdate = false;
  27705. _this.update();
  27706. /*
  27707. // TODO: delete this comment?
  27708. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27709. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27710. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27711. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27712. const d = light.distance;
  27713. if ( d === 0.0 ) {
  27714. this.lightDistance.visible = false;
  27715. } else {
  27716. this.lightDistance.scale.set( d, d, d );
  27717. }
  27718. this.add( this.lightDistance );
  27719. */
  27720. return _this;
  27721. }
  27722. var _proto = PointLightHelper.prototype;
  27723. _proto.dispose = function dispose() {
  27724. this.geometry.dispose();
  27725. this.material.dispose();
  27726. };
  27727. _proto.update = function update() {
  27728. if (this.color !== undefined) {
  27729. this.material.color.set(this.color);
  27730. } else {
  27731. this.material.color.copy(this.light.color);
  27732. }
  27733. /*
  27734. const d = this.light.distance;
  27735. if ( d === 0.0 ) {
  27736. this.lightDistance.visible = false;
  27737. } else {
  27738. this.lightDistance.visible = true;
  27739. this.lightDistance.scale.set( d, d, d );
  27740. }
  27741. */
  27742. };
  27743. return PointLightHelper;
  27744. }(Mesh);
  27745. var _vector$a = /*@__PURE__*/new Vector3();
  27746. var _color1 = /*@__PURE__*/new Color();
  27747. var _color2 = /*@__PURE__*/new Color();
  27748. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27749. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27750. function HemisphereLightHelper(light, size, color) {
  27751. var _this;
  27752. _this = _Object3D.call(this) || this;
  27753. _this.light = light;
  27754. _this.light.updateMatrixWorld();
  27755. _this.matrix = light.matrixWorld;
  27756. _this.matrixAutoUpdate = false;
  27757. _this.color = color;
  27758. var geometry = new OctahedronBufferGeometry(size);
  27759. geometry.rotateY(Math.PI * 0.5);
  27760. _this.material = new MeshBasicMaterial({
  27761. wireframe: true,
  27762. fog: false,
  27763. toneMapped: false
  27764. });
  27765. if (_this.color === undefined) _this.material.vertexColors = true;
  27766. var position = geometry.getAttribute('position');
  27767. var colors = new Float32Array(position.count * 3);
  27768. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27769. _this.add(new Mesh(geometry, _this.material));
  27770. _this.update();
  27771. return _this;
  27772. }
  27773. var _proto = HemisphereLightHelper.prototype;
  27774. _proto.dispose = function dispose() {
  27775. this.children[0].geometry.dispose();
  27776. this.children[0].material.dispose();
  27777. };
  27778. _proto.update = function update() {
  27779. var mesh = this.children[0];
  27780. if (this.color !== undefined) {
  27781. this.material.color.set(this.color);
  27782. } else {
  27783. var colors = mesh.geometry.getAttribute('color');
  27784. _color1.copy(this.light.color);
  27785. _color2.copy(this.light.groundColor);
  27786. for (var i = 0, l = colors.count; i < l; i++) {
  27787. var color = i < l / 2 ? _color1 : _color2;
  27788. colors.setXYZ(i, color.r, color.g, color.b);
  27789. }
  27790. colors.needsUpdate = true;
  27791. }
  27792. mesh.lookAt(_vector$a.setFromMatrixPosition(this.light.matrixWorld).negate());
  27793. };
  27794. return HemisphereLightHelper;
  27795. }(Object3D);
  27796. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27797. _inheritsLoose(GridHelper, _LineSegments);
  27798. function GridHelper(size, divisions, color1, color2) {
  27799. var _this;
  27800. size = size || 10;
  27801. divisions = divisions || 10;
  27802. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  27803. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  27804. var center = divisions / 2;
  27805. var step = size / divisions;
  27806. var halfSize = size / 2;
  27807. var vertices = [],
  27808. colors = [];
  27809. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  27810. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  27811. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  27812. var color = i === center ? color1 : color2;
  27813. color.toArray(colors, j);
  27814. j += 3;
  27815. color.toArray(colors, j);
  27816. j += 3;
  27817. color.toArray(colors, j);
  27818. j += 3;
  27819. color.toArray(colors, j);
  27820. j += 3;
  27821. }
  27822. var geometry = new BufferGeometry();
  27823. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27824. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27825. var material = new LineBasicMaterial({
  27826. vertexColors: true,
  27827. toneMapped: false
  27828. });
  27829. _this = _LineSegments.call(this, geometry, material) || this;
  27830. _this.type = 'GridHelper';
  27831. return _this;
  27832. }
  27833. return GridHelper;
  27834. }(LineSegments);
  27835. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  27836. _inheritsLoose(PolarGridHelper, _LineSegments);
  27837. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  27838. var _this;
  27839. radius = radius || 10;
  27840. radials = radials || 16;
  27841. circles = circles || 8;
  27842. divisions = divisions || 64;
  27843. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  27844. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  27845. var vertices = [];
  27846. var colors = []; // create the radials
  27847. for (var i = 0; i <= radials; i++) {
  27848. var v = i / radials * (Math.PI * 2);
  27849. var x = Math.sin(v) * radius;
  27850. var z = Math.cos(v) * radius;
  27851. vertices.push(0, 0, 0);
  27852. vertices.push(x, 0, z);
  27853. var color = i & 1 ? color1 : color2;
  27854. colors.push(color.r, color.g, color.b);
  27855. colors.push(color.r, color.g, color.b);
  27856. } // create the circles
  27857. for (var _i = 0; _i <= circles; _i++) {
  27858. var _color = _i & 1 ? color1 : color2;
  27859. var r = radius - radius / circles * _i;
  27860. for (var j = 0; j < divisions; j++) {
  27861. // first vertex
  27862. var _v = j / divisions * (Math.PI * 2);
  27863. var _x = Math.sin(_v) * r;
  27864. var _z = Math.cos(_v) * r;
  27865. vertices.push(_x, 0, _z);
  27866. colors.push(_color.r, _color.g, _color.b); // second vertex
  27867. _v = (j + 1) / divisions * (Math.PI * 2);
  27868. _x = Math.sin(_v) * r;
  27869. _z = Math.cos(_v) * r;
  27870. vertices.push(_x, 0, _z);
  27871. colors.push(_color.r, _color.g, _color.b);
  27872. }
  27873. }
  27874. var geometry = new BufferGeometry();
  27875. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27876. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27877. var material = new LineBasicMaterial({
  27878. vertexColors: true,
  27879. toneMapped: false
  27880. });
  27881. _this = _LineSegments.call(this, geometry, material) || this;
  27882. _this.type = 'PolarGridHelper';
  27883. return _this;
  27884. }
  27885. return PolarGridHelper;
  27886. }(LineSegments);
  27887. var _v1$6 = /*@__PURE__*/new Vector3();
  27888. var _v2$3 = /*@__PURE__*/new Vector3();
  27889. var _v3$1 = /*@__PURE__*/new Vector3();
  27890. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  27891. _inheritsLoose(DirectionalLightHelper, _Object3D);
  27892. function DirectionalLightHelper(light, size, color) {
  27893. var _this;
  27894. _this = _Object3D.call(this) || this;
  27895. _this.light = light;
  27896. _this.light.updateMatrixWorld();
  27897. _this.matrix = light.matrixWorld;
  27898. _this.matrixAutoUpdate = false;
  27899. _this.color = color;
  27900. if (size === undefined) size = 1;
  27901. var geometry = new BufferGeometry();
  27902. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  27903. var material = new LineBasicMaterial({
  27904. fog: false,
  27905. toneMapped: false
  27906. });
  27907. _this.lightPlane = new Line(geometry, material);
  27908. _this.add(_this.lightPlane);
  27909. geometry = new BufferGeometry();
  27910. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  27911. _this.targetLine = new Line(geometry, material);
  27912. _this.add(_this.targetLine);
  27913. _this.update();
  27914. return _this;
  27915. }
  27916. var _proto = DirectionalLightHelper.prototype;
  27917. _proto.dispose = function dispose() {
  27918. this.lightPlane.geometry.dispose();
  27919. this.lightPlane.material.dispose();
  27920. this.targetLine.geometry.dispose();
  27921. this.targetLine.material.dispose();
  27922. };
  27923. _proto.update = function update() {
  27924. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  27925. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  27926. _v3$1.subVectors(_v2$3, _v1$6);
  27927. this.lightPlane.lookAt(_v2$3);
  27928. if (this.color !== undefined) {
  27929. this.lightPlane.material.color.set(this.color);
  27930. this.targetLine.material.color.set(this.color);
  27931. } else {
  27932. this.lightPlane.material.color.copy(this.light.color);
  27933. this.targetLine.material.color.copy(this.light.color);
  27934. }
  27935. this.targetLine.lookAt(_v2$3);
  27936. this.targetLine.scale.z = _v3$1.length();
  27937. };
  27938. return DirectionalLightHelper;
  27939. }(Object3D);
  27940. var _vector$b = /*@__PURE__*/new Vector3();
  27941. var _camera = /*@__PURE__*/new Camera();
  27942. /**
  27943. * - shows frustum, line of sight and up of the camera
  27944. * - suitable for fast updates
  27945. * - based on frustum visualization in lightgl.js shadowmap example
  27946. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27947. */
  27948. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  27949. _inheritsLoose(CameraHelper, _LineSegments);
  27950. function CameraHelper(camera) {
  27951. var _this;
  27952. var geometry = new BufferGeometry();
  27953. var material = new LineBasicMaterial({
  27954. color: 0xffffff,
  27955. vertexColors: true,
  27956. toneMapped: false
  27957. });
  27958. var vertices = [];
  27959. var colors = [];
  27960. var pointMap = {}; // colors
  27961. var colorFrustum = new Color(0xffaa00);
  27962. var colorCone = new Color(0xff0000);
  27963. var colorUp = new Color(0x00aaff);
  27964. var colorTarget = new Color(0xffffff);
  27965. var colorCross = new Color(0x333333); // near
  27966. addLine('n1', 'n2', colorFrustum);
  27967. addLine('n2', 'n4', colorFrustum);
  27968. addLine('n4', 'n3', colorFrustum);
  27969. addLine('n3', 'n1', colorFrustum); // far
  27970. addLine('f1', 'f2', colorFrustum);
  27971. addLine('f2', 'f4', colorFrustum);
  27972. addLine('f4', 'f3', colorFrustum);
  27973. addLine('f3', 'f1', colorFrustum); // sides
  27974. addLine('n1', 'f1', colorFrustum);
  27975. addLine('n2', 'f2', colorFrustum);
  27976. addLine('n3', 'f3', colorFrustum);
  27977. addLine('n4', 'f4', colorFrustum); // cone
  27978. addLine('p', 'n1', colorCone);
  27979. addLine('p', 'n2', colorCone);
  27980. addLine('p', 'n3', colorCone);
  27981. addLine('p', 'n4', colorCone); // up
  27982. addLine('u1', 'u2', colorUp);
  27983. addLine('u2', 'u3', colorUp);
  27984. addLine('u3', 'u1', colorUp); // target
  27985. addLine('c', 't', colorTarget);
  27986. addLine('p', 'c', colorCross); // cross
  27987. addLine('cn1', 'cn2', colorCross);
  27988. addLine('cn3', 'cn4', colorCross);
  27989. addLine('cf1', 'cf2', colorCross);
  27990. addLine('cf3', 'cf4', colorCross);
  27991. function addLine(a, b, color) {
  27992. addPoint(a, color);
  27993. addPoint(b, color);
  27994. }
  27995. function addPoint(id, color) {
  27996. vertices.push(0, 0, 0);
  27997. colors.push(color.r, color.g, color.b);
  27998. if (pointMap[id] === undefined) {
  27999. pointMap[id] = [];
  28000. }
  28001. pointMap[id].push(vertices.length / 3 - 1);
  28002. }
  28003. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28004. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28005. _this = _LineSegments.call(this, geometry, material) || this;
  28006. _this.type = 'CameraHelper';
  28007. _this.camera = camera;
  28008. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28009. _this.matrix = camera.matrixWorld;
  28010. _this.matrixAutoUpdate = false;
  28011. _this.pointMap = pointMap;
  28012. _this.update();
  28013. return _this;
  28014. }
  28015. var _proto = CameraHelper.prototype;
  28016. _proto.update = function update() {
  28017. var geometry = this.geometry;
  28018. var pointMap = this.pointMap;
  28019. var w = 1,
  28020. h = 1; // we need just camera projection matrix inverse
  28021. // world matrix must be identity
  28022. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28023. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28024. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28025. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28026. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28027. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28028. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28029. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28030. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28031. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28032. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28033. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28034. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28035. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28036. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28037. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28038. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28039. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28040. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28041. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28042. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28043. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28044. geometry.getAttribute('position').needsUpdate = true;
  28045. };
  28046. return CameraHelper;
  28047. }(LineSegments);
  28048. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28049. _vector$b.set(x, y, z).unproject(camera);
  28050. var points = pointMap[point];
  28051. if (points !== undefined) {
  28052. var position = geometry.getAttribute('position');
  28053. for (var i = 0, l = points.length; i < l; i++) {
  28054. position.setXYZ(points[i], _vector$b.x, _vector$b.y, _vector$b.z);
  28055. }
  28056. }
  28057. }
  28058. var _box$3 = /*@__PURE__*/new Box3();
  28059. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28060. _inheritsLoose(BoxHelper, _LineSegments);
  28061. function BoxHelper(object, color) {
  28062. var _this;
  28063. if (color === void 0) {
  28064. color = 0xffff00;
  28065. }
  28066. 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]);
  28067. var positions = new Float32Array(8 * 3);
  28068. var geometry = new BufferGeometry();
  28069. geometry.setIndex(new BufferAttribute(indices, 1));
  28070. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28071. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28072. color: color,
  28073. toneMapped: false
  28074. })) || this;
  28075. _this.object = object;
  28076. _this.type = 'BoxHelper';
  28077. _this.matrixAutoUpdate = false;
  28078. _this.update();
  28079. return _this;
  28080. }
  28081. var _proto = BoxHelper.prototype;
  28082. _proto.update = function update(object) {
  28083. if (object !== undefined) {
  28084. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28085. }
  28086. if (this.object !== undefined) {
  28087. _box$3.setFromObject(this.object);
  28088. }
  28089. if (_box$3.isEmpty()) return;
  28090. var min = _box$3.min;
  28091. var max = _box$3.max;
  28092. /*
  28093. 5____4
  28094. 1/___0/|
  28095. | 6__|_7
  28096. 2/___3/
  28097. 0: max.x, max.y, max.z
  28098. 1: min.x, max.y, max.z
  28099. 2: min.x, min.y, max.z
  28100. 3: max.x, min.y, max.z
  28101. 4: max.x, max.y, min.z
  28102. 5: min.x, max.y, min.z
  28103. 6: min.x, min.y, min.z
  28104. 7: max.x, min.y, min.z
  28105. */
  28106. var position = this.geometry.attributes.position;
  28107. var array = position.array;
  28108. array[0] = max.x;
  28109. array[1] = max.y;
  28110. array[2] = max.z;
  28111. array[3] = min.x;
  28112. array[4] = max.y;
  28113. array[5] = max.z;
  28114. array[6] = min.x;
  28115. array[7] = min.y;
  28116. array[8] = max.z;
  28117. array[9] = max.x;
  28118. array[10] = min.y;
  28119. array[11] = max.z;
  28120. array[12] = max.x;
  28121. array[13] = max.y;
  28122. array[14] = min.z;
  28123. array[15] = min.x;
  28124. array[16] = max.y;
  28125. array[17] = min.z;
  28126. array[18] = min.x;
  28127. array[19] = min.y;
  28128. array[20] = min.z;
  28129. array[21] = max.x;
  28130. array[22] = min.y;
  28131. array[23] = min.z;
  28132. position.needsUpdate = true;
  28133. this.geometry.computeBoundingSphere();
  28134. };
  28135. _proto.setFromObject = function setFromObject(object) {
  28136. this.object = object;
  28137. this.update();
  28138. return this;
  28139. };
  28140. _proto.copy = function copy(source) {
  28141. LineSegments.prototype.copy.call(this, source);
  28142. this.object = source.object;
  28143. return this;
  28144. };
  28145. return BoxHelper;
  28146. }(LineSegments);
  28147. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28148. _inheritsLoose(Box3Helper, _LineSegments);
  28149. function Box3Helper(box, color) {
  28150. var _this;
  28151. if (color === void 0) {
  28152. color = 0xffff00;
  28153. }
  28154. 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]);
  28155. 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];
  28156. var geometry = new BufferGeometry();
  28157. geometry.setIndex(new BufferAttribute(indices, 1));
  28158. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28159. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28160. color: color,
  28161. toneMapped: false
  28162. })) || this;
  28163. _this.box = box;
  28164. _this.type = 'Box3Helper';
  28165. _this.geometry.computeBoundingSphere();
  28166. return _this;
  28167. }
  28168. var _proto = Box3Helper.prototype;
  28169. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28170. var box = this.box;
  28171. if (box.isEmpty()) return;
  28172. box.getCenter(this.position);
  28173. box.getSize(this.scale);
  28174. this.scale.multiplyScalar(0.5);
  28175. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28176. };
  28177. return Box3Helper;
  28178. }(LineSegments);
  28179. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28180. _inheritsLoose(PlaneHelper, _Line);
  28181. function PlaneHelper(plane, size, hex) {
  28182. var _this;
  28183. var color = hex !== undefined ? hex : 0xffff00;
  28184. 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];
  28185. var geometry = new BufferGeometry();
  28186. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28187. geometry.computeBoundingSphere();
  28188. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28189. color: color,
  28190. toneMapped: false
  28191. })) || this;
  28192. _this.type = 'PlaneHelper';
  28193. _this.plane = plane;
  28194. _this.size = size === undefined ? 1 : size;
  28195. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28196. var geometry2 = new BufferGeometry();
  28197. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28198. geometry2.computeBoundingSphere();
  28199. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28200. color: color,
  28201. opacity: 0.2,
  28202. transparent: true,
  28203. depthWrite: false,
  28204. toneMapped: false
  28205. })));
  28206. return _this;
  28207. }
  28208. var _proto = PlaneHelper.prototype;
  28209. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28210. var scale = -this.plane.constant;
  28211. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28212. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28213. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28214. this.lookAt(this.plane.normal);
  28215. _Line.prototype.updateMatrixWorld.call(this, force);
  28216. };
  28217. return PlaneHelper;
  28218. }(Line);
  28219. var _axis = /*@__PURE__*/new Vector3();
  28220. var _lineGeometry, _coneGeometry;
  28221. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28222. _inheritsLoose(ArrowHelper, _Object3D);
  28223. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28224. var _this;
  28225. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28226. _this.type = 'ArrowHelper';
  28227. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28228. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28229. if (length === undefined) length = 1;
  28230. if (color === undefined) color = 0xffff00;
  28231. if (headLength === undefined) headLength = 0.2 * length;
  28232. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28233. if (_lineGeometry === undefined) {
  28234. _lineGeometry = new BufferGeometry();
  28235. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28236. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28237. _coneGeometry.translate(0, -0.5, 0);
  28238. }
  28239. _this.position.copy(origin);
  28240. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28241. color: color,
  28242. toneMapped: false
  28243. }));
  28244. _this.line.matrixAutoUpdate = false;
  28245. _this.add(_this.line);
  28246. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28247. color: color,
  28248. toneMapped: false
  28249. }));
  28250. _this.cone.matrixAutoUpdate = false;
  28251. _this.add(_this.cone);
  28252. _this.setDirection(dir);
  28253. _this.setLength(length, headLength, headWidth);
  28254. return _this;
  28255. }
  28256. var _proto = ArrowHelper.prototype;
  28257. _proto.setDirection = function setDirection(dir) {
  28258. // dir is assumed to be normalized
  28259. if (dir.y > 0.99999) {
  28260. this.quaternion.set(0, 0, 0, 1);
  28261. } else if (dir.y < -0.99999) {
  28262. this.quaternion.set(1, 0, 0, 0);
  28263. } else {
  28264. _axis.set(dir.z, 0, -dir.x).normalize();
  28265. var radians = Math.acos(dir.y);
  28266. this.quaternion.setFromAxisAngle(_axis, radians);
  28267. }
  28268. };
  28269. _proto.setLength = function setLength(length, headLength, headWidth) {
  28270. if (headLength === undefined) headLength = 0.2 * length;
  28271. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28272. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28273. this.line.updateMatrix();
  28274. this.cone.scale.set(headWidth, headLength, headWidth);
  28275. this.cone.position.y = length;
  28276. this.cone.updateMatrix();
  28277. };
  28278. _proto.setColor = function setColor(color) {
  28279. this.line.material.color.set(color);
  28280. this.cone.material.color.set(color);
  28281. };
  28282. _proto.copy = function copy(source) {
  28283. _Object3D.prototype.copy.call(this, source, false);
  28284. this.line.copy(source.line);
  28285. this.cone.copy(source.cone);
  28286. return this;
  28287. };
  28288. return ArrowHelper;
  28289. }(Object3D);
  28290. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28291. _inheritsLoose(AxesHelper, _LineSegments);
  28292. function AxesHelper(size) {
  28293. var _this;
  28294. if (size === void 0) {
  28295. size = 1;
  28296. }
  28297. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28298. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28299. var geometry = new BufferGeometry();
  28300. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28301. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28302. var material = new LineBasicMaterial({
  28303. vertexColors: true,
  28304. toneMapped: false
  28305. });
  28306. _this = _LineSegments.call(this, geometry, material) || this;
  28307. _this.type = 'AxesHelper';
  28308. return _this;
  28309. }
  28310. return AxesHelper;
  28311. }(LineSegments);
  28312. var _ENCODINGS;
  28313. var LOD_MIN = 4;
  28314. var LOD_MAX = 8;
  28315. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28316. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28317. // geometric shadowing function. These sigma values squared must match the
  28318. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28319. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28320. 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
  28321. // samples and exit early, but not recompile the shader.
  28322. var MAX_SAMPLES = 20;
  28323. 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);
  28324. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28325. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28326. _lodPlanes = _createPlanes2._lodPlanes,
  28327. _sizeLods = _createPlanes2._sizeLods,
  28328. _sigmas = _createPlanes2._sigmas;
  28329. var _oldTarget = null; // Golden Ratio
  28330. var PHI = (1 + Math.sqrt(5)) / 2;
  28331. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28332. // same axis), used as axis directions evenly spread on a sphere.
  28333. 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)];
  28334. /**
  28335. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28336. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28337. * blur to be quickly accessed based on material roughness. It is packed into a
  28338. * special CubeUV format that allows us to perform custom interpolation so that
  28339. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28340. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28341. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28342. * higher roughness levels. In this way we maintain resolution to smoothly
  28343. * interpolate diffuse lighting while limiting sampling computation.
  28344. */
  28345. var PMREMGenerator = /*#__PURE__*/function () {
  28346. function PMREMGenerator(renderer) {
  28347. this._renderer = renderer;
  28348. this._pingPongRenderTarget = null;
  28349. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28350. this._equirectShader = null;
  28351. this._cubemapShader = null;
  28352. this._compileMaterial(this._blurMaterial);
  28353. }
  28354. /**
  28355. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28356. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28357. * in radians to be applied to the scene before PMREM generation. Optional near
  28358. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28359. * is placed at the origin).
  28360. */
  28361. var _proto = PMREMGenerator.prototype;
  28362. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28363. if (sigma === void 0) {
  28364. sigma = 0;
  28365. }
  28366. if (near === void 0) {
  28367. near = 0.1;
  28368. }
  28369. if (far === void 0) {
  28370. far = 100;
  28371. }
  28372. _oldTarget = this._renderer.getRenderTarget();
  28373. var cubeUVRenderTarget = this._allocateTargets();
  28374. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28375. if (sigma > 0) {
  28376. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28377. }
  28378. this._applyPMREM(cubeUVRenderTarget);
  28379. this._cleanup(cubeUVRenderTarget);
  28380. return cubeUVRenderTarget;
  28381. }
  28382. /**
  28383. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28384. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28385. * as this matches best with the 256 x 256 cubemap output.
  28386. */
  28387. ;
  28388. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28389. return this._fromTexture(equirectangular);
  28390. }
  28391. /**
  28392. * Generates a PMREM from an cubemap texture, which can be either LDR
  28393. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28394. * as this matches best with the 256 x 256 cubemap output.
  28395. */
  28396. ;
  28397. _proto.fromCubemap = function fromCubemap(cubemap) {
  28398. return this._fromTexture(cubemap);
  28399. }
  28400. /**
  28401. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28402. * your texture's network fetch for increased concurrency.
  28403. */
  28404. ;
  28405. _proto.compileCubemapShader = function compileCubemapShader() {
  28406. if (this._cubemapShader === null) {
  28407. this._cubemapShader = _getCubemapShader();
  28408. this._compileMaterial(this._cubemapShader);
  28409. }
  28410. }
  28411. /**
  28412. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28413. * your texture's network fetch for increased concurrency.
  28414. */
  28415. ;
  28416. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28417. if (this._equirectShader === null) {
  28418. this._equirectShader = _getEquirectShader();
  28419. this._compileMaterial(this._equirectShader);
  28420. }
  28421. }
  28422. /**
  28423. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28424. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28425. * one of them will cause any others to also become unusable.
  28426. */
  28427. ;
  28428. _proto.dispose = function dispose() {
  28429. this._blurMaterial.dispose();
  28430. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28431. if (this._equirectShader !== null) this._equirectShader.dispose();
  28432. for (var i = 0; i < _lodPlanes.length; i++) {
  28433. _lodPlanes[i].dispose();
  28434. }
  28435. } // private interface
  28436. ;
  28437. _proto._cleanup = function _cleanup(outputTarget) {
  28438. this._pingPongRenderTarget.dispose();
  28439. this._renderer.setRenderTarget(_oldTarget);
  28440. outputTarget.scissorTest = false;
  28441. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28442. };
  28443. _proto._fromTexture = function _fromTexture(texture) {
  28444. _oldTarget = this._renderer.getRenderTarget();
  28445. var cubeUVRenderTarget = this._allocateTargets(texture);
  28446. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28447. this._applyPMREM(cubeUVRenderTarget);
  28448. this._cleanup(cubeUVRenderTarget);
  28449. return cubeUVRenderTarget;
  28450. };
  28451. _proto._allocateTargets = function _allocateTargets(texture) {
  28452. // warning: null texture is valid
  28453. var params = {
  28454. magFilter: NearestFilter,
  28455. minFilter: NearestFilter,
  28456. generateMipmaps: false,
  28457. type: UnsignedByteType,
  28458. format: RGBEFormat,
  28459. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28460. depthBuffer: false
  28461. };
  28462. var cubeUVRenderTarget = _createRenderTarget(params);
  28463. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28464. this._pingPongRenderTarget = _createRenderTarget(params);
  28465. return cubeUVRenderTarget;
  28466. };
  28467. _proto._compileMaterial = function _compileMaterial(material) {
  28468. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28469. this._renderer.compile(tmpMesh, _flatCamera);
  28470. };
  28471. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28472. var fov = 90;
  28473. var aspect = 1;
  28474. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28475. var upSign = [1, -1, 1, 1, 1, 1];
  28476. var forwardSign = [1, 1, 1, -1, -1, -1];
  28477. var renderer = this._renderer;
  28478. var outputEncoding = renderer.outputEncoding;
  28479. var toneMapping = renderer.toneMapping;
  28480. var clearColor = renderer.getClearColor();
  28481. var clearAlpha = renderer.getClearAlpha();
  28482. renderer.toneMapping = NoToneMapping;
  28483. renderer.outputEncoding = LinearEncoding;
  28484. var background = scene.background;
  28485. if (background && background.isColor) {
  28486. background.convertSRGBToLinear(); // Convert linear to RGBE
  28487. var maxComponent = Math.max(background.r, background.g, background.b);
  28488. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28489. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  28490. var alpha = (fExp + 128.0) / 255.0;
  28491. renderer.setClearColor(background, alpha);
  28492. scene.background = null;
  28493. }
  28494. for (var i = 0; i < 6; i++) {
  28495. var col = i % 3;
  28496. if (col == 0) {
  28497. cubeCamera.up.set(0, upSign[i], 0);
  28498. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28499. } else if (col == 1) {
  28500. cubeCamera.up.set(0, 0, upSign[i]);
  28501. cubeCamera.lookAt(0, forwardSign[i], 0);
  28502. } else {
  28503. cubeCamera.up.set(0, upSign[i], 0);
  28504. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28505. }
  28506. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28507. renderer.setRenderTarget(cubeUVRenderTarget);
  28508. renderer.render(scene, cubeCamera);
  28509. }
  28510. renderer.toneMapping = toneMapping;
  28511. renderer.outputEncoding = outputEncoding;
  28512. renderer.setClearColor(clearColor, clearAlpha);
  28513. };
  28514. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28515. var renderer = this._renderer;
  28516. if (texture.isCubeTexture) {
  28517. if (this._cubemapShader == null) {
  28518. this._cubemapShader = _getCubemapShader();
  28519. }
  28520. } else {
  28521. if (this._equirectShader == null) {
  28522. this._equirectShader = _getEquirectShader();
  28523. }
  28524. }
  28525. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28526. var mesh = new Mesh(_lodPlanes[0], material);
  28527. var uniforms = material.uniforms;
  28528. uniforms['envMap'].value = texture;
  28529. if (!texture.isCubeTexture) {
  28530. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28531. }
  28532. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28533. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28534. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28535. renderer.setRenderTarget(cubeUVRenderTarget);
  28536. renderer.render(mesh, _flatCamera);
  28537. };
  28538. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28539. var renderer = this._renderer;
  28540. var autoClear = renderer.autoClear;
  28541. renderer.autoClear = false;
  28542. for (var i = 1; i < TOTAL_LODS; i++) {
  28543. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28544. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28545. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28546. }
  28547. renderer.autoClear = autoClear;
  28548. }
  28549. /**
  28550. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28551. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28552. * the blur latitudinally (around the poles), and then longitudinally (towards
  28553. * the poles) to approximate the orthogonally-separable blur. It is least
  28554. * accurate at the poles, but still does a decent job.
  28555. */
  28556. ;
  28557. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28558. var pingPongRenderTarget = this._pingPongRenderTarget;
  28559. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28560. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28561. };
  28562. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28563. var renderer = this._renderer;
  28564. var blurMaterial = this._blurMaterial;
  28565. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28566. console.error('blur direction must be either latitudinal or longitudinal!');
  28567. } // Number of standard deviations at which to cut off the discrete approximation.
  28568. var STANDARD_DEVIATIONS = 3;
  28569. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28570. var blurUniforms = blurMaterial.uniforms;
  28571. var pixels = _sizeLods[lodIn] - 1;
  28572. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28573. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28574. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28575. if (samples > MAX_SAMPLES) {
  28576. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28577. }
  28578. var weights = [];
  28579. var sum = 0;
  28580. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28581. var _x = i / sigmaPixels;
  28582. var weight = Math.exp(-_x * _x / 2);
  28583. weights.push(weight);
  28584. if (i == 0) {
  28585. sum += weight;
  28586. } else if (i < samples) {
  28587. sum += 2 * weight;
  28588. }
  28589. }
  28590. for (var _i = 0; _i < weights.length; _i++) {
  28591. weights[_i] = weights[_i] / sum;
  28592. }
  28593. blurUniforms['envMap'].value = targetIn.texture;
  28594. blurUniforms['samples'].value = samples;
  28595. blurUniforms['weights'].value = weights;
  28596. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28597. if (poleAxis) {
  28598. blurUniforms['poleAxis'].value = poleAxis;
  28599. }
  28600. blurUniforms['dTheta'].value = radiansPerPixel;
  28601. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28602. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28603. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28604. var outputSize = _sizeLods[lodOut];
  28605. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28606. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28607. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28608. renderer.setRenderTarget(targetOut);
  28609. renderer.render(blurMesh, _flatCamera);
  28610. };
  28611. return PMREMGenerator;
  28612. }();
  28613. function _isLDR(texture) {
  28614. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28615. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28616. }
  28617. function _createPlanes() {
  28618. var _lodPlanes = [];
  28619. var _sizeLods = [];
  28620. var _sigmas = [];
  28621. var lod = LOD_MAX;
  28622. for (var i = 0; i < TOTAL_LODS; i++) {
  28623. var sizeLod = Math.pow(2, lod);
  28624. _sizeLods.push(sizeLod);
  28625. var sigma = 1.0 / sizeLod;
  28626. if (i > LOD_MAX - LOD_MIN) {
  28627. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28628. } else if (i == 0) {
  28629. sigma = 0;
  28630. }
  28631. _sigmas.push(sigma);
  28632. var texelSize = 1.0 / (sizeLod - 1);
  28633. var min = -texelSize / 2;
  28634. var max = 1 + texelSize / 2;
  28635. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28636. var cubeFaces = 6;
  28637. var vertices = 6;
  28638. var positionSize = 3;
  28639. var uvSize = 2;
  28640. var faceIndexSize = 1;
  28641. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28642. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28643. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28644. for (var face = 0; face < cubeFaces; face++) {
  28645. var x = face % 3 * 2 / 3 - 1;
  28646. var y = face > 2 ? 0 : -1;
  28647. 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];
  28648. position.set(coordinates, positionSize * vertices * face);
  28649. uv.set(uv1, uvSize * vertices * face);
  28650. var fill = [face, face, face, face, face, face];
  28651. faceIndex.set(fill, faceIndexSize * vertices * face);
  28652. }
  28653. var planes = new BufferGeometry();
  28654. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28655. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28656. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28657. _lodPlanes.push(planes);
  28658. if (lod > LOD_MIN) {
  28659. lod--;
  28660. }
  28661. }
  28662. return {
  28663. _lodPlanes: _lodPlanes,
  28664. _sizeLods: _sizeLods,
  28665. _sigmas: _sigmas
  28666. };
  28667. }
  28668. function _createRenderTarget(params) {
  28669. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28670. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28671. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28672. cubeUVRenderTarget.scissorTest = true;
  28673. return cubeUVRenderTarget;
  28674. }
  28675. function _setViewport(target, x, y, width, height) {
  28676. target.viewport.set(x, y, width, height);
  28677. target.scissor.set(x, y, width, height);
  28678. }
  28679. function _getBlurShader(maxSamples) {
  28680. var weights = new Float32Array(maxSamples);
  28681. var poleAxis = new Vector3(0, 1, 0);
  28682. var shaderMaterial = new RawShaderMaterial({
  28683. name: 'SphericalGaussianBlur',
  28684. defines: {
  28685. 'n': maxSamples
  28686. },
  28687. uniforms: {
  28688. 'envMap': {
  28689. value: null
  28690. },
  28691. 'samples': {
  28692. value: 1
  28693. },
  28694. 'weights': {
  28695. value: weights
  28696. },
  28697. 'latitudinal': {
  28698. value: false
  28699. },
  28700. 'dTheta': {
  28701. value: 0
  28702. },
  28703. 'mipInt': {
  28704. value: 0
  28705. },
  28706. 'poleAxis': {
  28707. value: poleAxis
  28708. },
  28709. 'inputEncoding': {
  28710. value: ENCODINGS[LinearEncoding]
  28711. },
  28712. 'outputEncoding': {
  28713. value: ENCODINGS[LinearEncoding]
  28714. }
  28715. },
  28716. vertexShader: _getCommonVertexShader(),
  28717. fragmentShader:
  28718. /* glsl */
  28719. "\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",
  28720. blending: NoBlending,
  28721. depthTest: false,
  28722. depthWrite: false
  28723. });
  28724. return shaderMaterial;
  28725. }
  28726. function _getEquirectShader() {
  28727. var texelSize = new Vector2(1, 1);
  28728. var shaderMaterial = new RawShaderMaterial({
  28729. name: 'EquirectangularToCubeUV',
  28730. uniforms: {
  28731. 'envMap': {
  28732. value: null
  28733. },
  28734. 'texelSize': {
  28735. value: texelSize
  28736. },
  28737. 'inputEncoding': {
  28738. value: ENCODINGS[LinearEncoding]
  28739. },
  28740. 'outputEncoding': {
  28741. value: ENCODINGS[LinearEncoding]
  28742. }
  28743. },
  28744. vertexShader: _getCommonVertexShader(),
  28745. fragmentShader:
  28746. /* glsl */
  28747. "\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",
  28748. blending: NoBlending,
  28749. depthTest: false,
  28750. depthWrite: false
  28751. });
  28752. return shaderMaterial;
  28753. }
  28754. function _getCubemapShader() {
  28755. var shaderMaterial = new RawShaderMaterial({
  28756. name: 'CubemapToCubeUV',
  28757. uniforms: {
  28758. 'envMap': {
  28759. value: null
  28760. },
  28761. 'inputEncoding': {
  28762. value: ENCODINGS[LinearEncoding]
  28763. },
  28764. 'outputEncoding': {
  28765. value: ENCODINGS[LinearEncoding]
  28766. }
  28767. },
  28768. vertexShader: _getCommonVertexShader(),
  28769. fragmentShader:
  28770. /* glsl */
  28771. "\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",
  28772. blending: NoBlending,
  28773. depthTest: false,
  28774. depthWrite: false
  28775. });
  28776. return shaderMaterial;
  28777. }
  28778. function _getCommonVertexShader() {
  28779. return (
  28780. /* glsl */
  28781. "\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"
  28782. );
  28783. }
  28784. function _getEncodings() {
  28785. return (
  28786. /* glsl */
  28787. "\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"
  28788. );
  28789. }
  28790. function Face4(a, b, c, d, normal, color, materialIndex) {
  28791. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  28792. return new Face3(a, b, c, normal, color, materialIndex);
  28793. }
  28794. var LineStrip = 0;
  28795. var LinePieces = 1;
  28796. var NoColors = 0;
  28797. var FaceColors = 1;
  28798. var VertexColors = 2;
  28799. function MeshFaceMaterial(materials) {
  28800. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  28801. return materials;
  28802. }
  28803. function MultiMaterial(materials) {
  28804. if (materials === undefined) materials = [];
  28805. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  28806. materials.isMultiMaterial = true;
  28807. materials.materials = materials;
  28808. materials.clone = function () {
  28809. return materials.slice();
  28810. };
  28811. return materials;
  28812. }
  28813. function PointCloud(geometry, material) {
  28814. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  28815. return new Points(geometry, material);
  28816. }
  28817. function Particle(material) {
  28818. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  28819. return new Sprite(material);
  28820. }
  28821. function ParticleSystem(geometry, material) {
  28822. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  28823. return new Points(geometry, material);
  28824. }
  28825. function PointCloudMaterial(parameters) {
  28826. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  28827. return new PointsMaterial(parameters);
  28828. }
  28829. function ParticleBasicMaterial(parameters) {
  28830. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  28831. return new PointsMaterial(parameters);
  28832. }
  28833. function ParticleSystemMaterial(parameters) {
  28834. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  28835. return new PointsMaterial(parameters);
  28836. }
  28837. function Vertex(x, y, z) {
  28838. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  28839. return new Vector3(x, y, z);
  28840. } //
  28841. function DynamicBufferAttribute(array, itemSize) {
  28842. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  28843. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  28844. }
  28845. function Int8Attribute(array, itemSize) {
  28846. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  28847. return new Int8BufferAttribute(array, itemSize);
  28848. }
  28849. function Uint8Attribute(array, itemSize) {
  28850. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  28851. return new Uint8BufferAttribute(array, itemSize);
  28852. }
  28853. function Uint8ClampedAttribute(array, itemSize) {
  28854. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  28855. return new Uint8ClampedBufferAttribute(array, itemSize);
  28856. }
  28857. function Int16Attribute(array, itemSize) {
  28858. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  28859. return new Int16BufferAttribute(array, itemSize);
  28860. }
  28861. function Uint16Attribute(array, itemSize) {
  28862. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  28863. return new Uint16BufferAttribute(array, itemSize);
  28864. }
  28865. function Int32Attribute(array, itemSize) {
  28866. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  28867. return new Int32BufferAttribute(array, itemSize);
  28868. }
  28869. function Uint32Attribute(array, itemSize) {
  28870. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  28871. return new Uint32BufferAttribute(array, itemSize);
  28872. }
  28873. function Float32Attribute(array, itemSize) {
  28874. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  28875. return new Float32BufferAttribute(array, itemSize);
  28876. }
  28877. function Float64Attribute(array, itemSize) {
  28878. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  28879. return new Float64BufferAttribute(array, itemSize);
  28880. } //
  28881. Curve.create = function (construct, getPoint) {
  28882. console.log('THREE.Curve.create() has been deprecated');
  28883. construct.prototype = Object.create(Curve.prototype);
  28884. construct.prototype.constructor = construct;
  28885. construct.prototype.getPoint = getPoint;
  28886. return construct;
  28887. }; //
  28888. Object.assign(CurvePath.prototype, {
  28889. createPointsGeometry: function createPointsGeometry(divisions) {
  28890. 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)
  28891. var pts = this.getPoints(divisions);
  28892. return this.createGeometry(pts);
  28893. },
  28894. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  28895. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  28896. var pts = this.getSpacedPoints(divisions);
  28897. return this.createGeometry(pts);
  28898. },
  28899. createGeometry: function createGeometry(points) {
  28900. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  28901. var geometry = new Geometry();
  28902. for (var i = 0, l = points.length; i < l; i++) {
  28903. var point = points[i];
  28904. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  28905. }
  28906. return geometry;
  28907. }
  28908. }); //
  28909. Object.assign(Path.prototype, {
  28910. fromPoints: function fromPoints(points) {
  28911. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  28912. return this.setFromPoints(points);
  28913. }
  28914. }); //
  28915. function ClosedSplineCurve3(points) {
  28916. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28917. CatmullRomCurve3.call(this, points);
  28918. this.type = 'catmullrom';
  28919. this.closed = true;
  28920. }
  28921. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28922. function SplineCurve3(points) {
  28923. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28924. CatmullRomCurve3.call(this, points);
  28925. this.type = 'catmullrom';
  28926. }
  28927. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28928. function Spline(points) {
  28929. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  28930. CatmullRomCurve3.call(this, points);
  28931. this.type = 'catmullrom';
  28932. }
  28933. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  28934. Object.assign(Spline.prototype, {
  28935. initFromArray: function initFromArray()
  28936. /* a */
  28937. {
  28938. console.error('THREE.Spline: .initFromArray() has been removed.');
  28939. },
  28940. getControlPointsArray: function getControlPointsArray()
  28941. /* optionalTarget */
  28942. {
  28943. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  28944. },
  28945. reparametrizeByArcLength: function reparametrizeByArcLength()
  28946. /* samplingCoef */
  28947. {
  28948. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  28949. }
  28950. }); //
  28951. function AxisHelper(size) {
  28952. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  28953. return new AxesHelper(size);
  28954. }
  28955. function BoundingBoxHelper(object, color) {
  28956. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  28957. return new BoxHelper(object, color);
  28958. }
  28959. function EdgesHelper(object, hex) {
  28960. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  28961. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  28962. color: hex !== undefined ? hex : 0xffffff
  28963. }));
  28964. }
  28965. GridHelper.prototype.setColors = function () {
  28966. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  28967. };
  28968. SkeletonHelper.prototype.update = function () {
  28969. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  28970. };
  28971. function WireframeHelper(object, hex) {
  28972. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  28973. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  28974. color: hex !== undefined ? hex : 0xffffff
  28975. }));
  28976. } //
  28977. Object.assign(Loader.prototype, {
  28978. extractUrlBase: function extractUrlBase(url) {
  28979. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  28980. return LoaderUtils.extractUrlBase(url);
  28981. }
  28982. });
  28983. Loader.Handlers = {
  28984. add: function add()
  28985. /* regex, loader */
  28986. {
  28987. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  28988. },
  28989. get: function get()
  28990. /* file */
  28991. {
  28992. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  28993. }
  28994. };
  28995. function XHRLoader(manager) {
  28996. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  28997. return new FileLoader(manager);
  28998. }
  28999. function BinaryTextureLoader(manager) {
  29000. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29001. return new DataTextureLoader(manager);
  29002. } //
  29003. Object.assign(Box2.prototype, {
  29004. center: function center(optionalTarget) {
  29005. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29006. return this.getCenter(optionalTarget);
  29007. },
  29008. empty: function empty() {
  29009. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29010. return this.isEmpty();
  29011. },
  29012. isIntersectionBox: function isIntersectionBox(box) {
  29013. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29014. return this.intersectsBox(box);
  29015. },
  29016. size: function size(optionalTarget) {
  29017. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29018. return this.getSize(optionalTarget);
  29019. }
  29020. });
  29021. Object.assign(Box3.prototype, {
  29022. center: function center(optionalTarget) {
  29023. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29024. return this.getCenter(optionalTarget);
  29025. },
  29026. empty: function empty() {
  29027. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29028. return this.isEmpty();
  29029. },
  29030. isIntersectionBox: function isIntersectionBox(box) {
  29031. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29032. return this.intersectsBox(box);
  29033. },
  29034. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29035. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29036. return this.intersectsSphere(sphere);
  29037. },
  29038. size: function size(optionalTarget) {
  29039. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29040. return this.getSize(optionalTarget);
  29041. }
  29042. });
  29043. Object.assign(Sphere.prototype, {
  29044. empty: function empty() {
  29045. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29046. return this.isEmpty();
  29047. }
  29048. });
  29049. Frustum.prototype.setFromMatrix = function (m) {
  29050. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29051. return this.setFromProjectionMatrix(m);
  29052. };
  29053. Line3.prototype.center = function (optionalTarget) {
  29054. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29055. return this.getCenter(optionalTarget);
  29056. };
  29057. Object.assign(MathUtils, {
  29058. random16: function random16() {
  29059. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29060. return Math.random();
  29061. },
  29062. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29063. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29064. return MathUtils.floorPowerOfTwo(value);
  29065. },
  29066. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29067. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29068. return MathUtils.ceilPowerOfTwo(value);
  29069. }
  29070. });
  29071. Object.assign(Matrix3.prototype, {
  29072. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29073. console.warn("THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29074. return this.toArray(array, offset);
  29075. },
  29076. multiplyVector3: function multiplyVector3(vector) {
  29077. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29078. return vector.applyMatrix3(this);
  29079. },
  29080. multiplyVector3Array: function multiplyVector3Array()
  29081. /* a */
  29082. {
  29083. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29084. },
  29085. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29086. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29087. return attribute.applyMatrix3(this);
  29088. },
  29089. applyToVector3Array: function applyToVector3Array()
  29090. /* array, offset, length */
  29091. {
  29092. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29093. }
  29094. });
  29095. Object.assign(Matrix4.prototype, {
  29096. extractPosition: function extractPosition(m) {
  29097. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29098. return this.copyPosition(m);
  29099. },
  29100. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29101. console.warn("THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29102. return this.toArray(array, offset);
  29103. },
  29104. getPosition: function getPosition() {
  29105. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29106. return new Vector3().setFromMatrixColumn(this, 3);
  29107. },
  29108. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29109. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29110. return this.makeRotationFromQuaternion(q);
  29111. },
  29112. multiplyToArray: function multiplyToArray() {
  29113. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29114. },
  29115. multiplyVector3: function multiplyVector3(vector) {
  29116. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29117. return vector.applyMatrix4(this);
  29118. },
  29119. multiplyVector4: function multiplyVector4(vector) {
  29120. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29121. return vector.applyMatrix4(this);
  29122. },
  29123. multiplyVector3Array: function multiplyVector3Array()
  29124. /* a */
  29125. {
  29126. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29127. },
  29128. rotateAxis: function rotateAxis(v) {
  29129. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29130. v.transformDirection(this);
  29131. },
  29132. crossVector: function crossVector(vector) {
  29133. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29134. return vector.applyMatrix4(this);
  29135. },
  29136. translate: function translate() {
  29137. console.error('THREE.Matrix4: .translate() has been removed.');
  29138. },
  29139. rotateX: function rotateX() {
  29140. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29141. },
  29142. rotateY: function rotateY() {
  29143. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29144. },
  29145. rotateZ: function rotateZ() {
  29146. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29147. },
  29148. rotateByAxis: function rotateByAxis() {
  29149. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29150. },
  29151. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29152. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29153. return attribute.applyMatrix4(this);
  29154. },
  29155. applyToVector3Array: function applyToVector3Array()
  29156. /* array, offset, length */
  29157. {
  29158. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29159. },
  29160. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29161. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29162. return this.makePerspective(left, right, top, bottom, near, far);
  29163. }
  29164. });
  29165. Plane.prototype.isIntersectionLine = function (line) {
  29166. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29167. return this.intersectsLine(line);
  29168. };
  29169. Quaternion.prototype.multiplyVector3 = function (vector) {
  29170. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29171. return vector.applyQuaternion(this);
  29172. };
  29173. Object.assign(Ray.prototype, {
  29174. isIntersectionBox: function isIntersectionBox(box) {
  29175. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29176. return this.intersectsBox(box);
  29177. },
  29178. isIntersectionPlane: function isIntersectionPlane(plane) {
  29179. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29180. return this.intersectsPlane(plane);
  29181. },
  29182. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29183. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29184. return this.intersectsSphere(sphere);
  29185. }
  29186. });
  29187. Object.assign(Triangle.prototype, {
  29188. area: function area() {
  29189. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29190. return this.getArea();
  29191. },
  29192. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29193. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29194. return this.getBarycoord(point, target);
  29195. },
  29196. midpoint: function midpoint(target) {
  29197. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29198. return this.getMidpoint(target);
  29199. },
  29200. normal: function normal(target) {
  29201. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29202. return this.getNormal(target);
  29203. },
  29204. plane: function plane(target) {
  29205. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29206. return this.getPlane(target);
  29207. }
  29208. });
  29209. Object.assign(Triangle, {
  29210. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29211. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29212. return Triangle.getBarycoord(point, a, b, c, target);
  29213. },
  29214. normal: function normal(a, b, c, target) {
  29215. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29216. return Triangle.getNormal(a, b, c, target);
  29217. }
  29218. });
  29219. Object.assign(Shape.prototype, {
  29220. extractAllPoints: function extractAllPoints(divisions) {
  29221. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29222. return this.extractPoints(divisions);
  29223. },
  29224. extrude: function extrude(options) {
  29225. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29226. return new ExtrudeGeometry(this, options);
  29227. },
  29228. makeGeometry: function makeGeometry(options) {
  29229. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29230. return new ShapeGeometry(this, options);
  29231. }
  29232. });
  29233. Object.assign(Vector2.prototype, {
  29234. fromAttribute: function fromAttribute(attribute, index, offset) {
  29235. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29236. return this.fromBufferAttribute(attribute, index, offset);
  29237. },
  29238. distanceToManhattan: function distanceToManhattan(v) {
  29239. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29240. return this.manhattanDistanceTo(v);
  29241. },
  29242. lengthManhattan: function lengthManhattan() {
  29243. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29244. return this.manhattanLength();
  29245. }
  29246. });
  29247. Object.assign(Vector3.prototype, {
  29248. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29249. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29250. },
  29251. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29252. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29253. },
  29254. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29255. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29256. return this.setFromMatrixPosition(m);
  29257. },
  29258. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29259. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29260. return this.setFromMatrixScale(m);
  29261. },
  29262. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29263. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29264. return this.setFromMatrixColumn(matrix, index);
  29265. },
  29266. applyProjection: function applyProjection(m) {
  29267. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29268. return this.applyMatrix4(m);
  29269. },
  29270. fromAttribute: function fromAttribute(attribute, index, offset) {
  29271. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29272. return this.fromBufferAttribute(attribute, index, offset);
  29273. },
  29274. distanceToManhattan: function distanceToManhattan(v) {
  29275. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29276. return this.manhattanDistanceTo(v);
  29277. },
  29278. lengthManhattan: function lengthManhattan() {
  29279. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29280. return this.manhattanLength();
  29281. }
  29282. });
  29283. Object.assign(Vector4.prototype, {
  29284. fromAttribute: function fromAttribute(attribute, index, offset) {
  29285. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29286. return this.fromBufferAttribute(attribute, index, offset);
  29287. },
  29288. lengthManhattan: function lengthManhattan() {
  29289. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29290. return this.manhattanLength();
  29291. }
  29292. }); //
  29293. Object.assign(Geometry.prototype, {
  29294. computeTangents: function computeTangents() {
  29295. console.error('THREE.Geometry: .computeTangents() has been removed.');
  29296. },
  29297. computeLineDistances: function computeLineDistances() {
  29298. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  29299. },
  29300. applyMatrix: function applyMatrix(matrix) {
  29301. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29302. return this.applyMatrix4(matrix);
  29303. }
  29304. });
  29305. Object.assign(Object3D.prototype, {
  29306. getChildByName: function getChildByName(name) {
  29307. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29308. return this.getObjectByName(name);
  29309. },
  29310. renderDepth: function renderDepth() {
  29311. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29312. },
  29313. translate: function translate(distance, axis) {
  29314. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29315. return this.translateOnAxis(axis, distance);
  29316. },
  29317. getWorldRotation: function getWorldRotation() {
  29318. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29319. },
  29320. applyMatrix: function applyMatrix(matrix) {
  29321. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29322. return this.applyMatrix4(matrix);
  29323. }
  29324. });
  29325. Object.defineProperties(Object3D.prototype, {
  29326. eulerOrder: {
  29327. get: function get() {
  29328. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29329. return this.rotation.order;
  29330. },
  29331. set: function set(value) {
  29332. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29333. this.rotation.order = value;
  29334. }
  29335. },
  29336. useQuaternion: {
  29337. get: function get() {
  29338. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29339. },
  29340. set: function set() {
  29341. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29342. }
  29343. }
  29344. });
  29345. Object.assign(Mesh.prototype, {
  29346. setDrawMode: function setDrawMode() {
  29347. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29348. }
  29349. });
  29350. Object.defineProperties(Mesh.prototype, {
  29351. drawMode: {
  29352. get: function get() {
  29353. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29354. return TrianglesDrawMode;
  29355. },
  29356. set: function set() {
  29357. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29358. }
  29359. }
  29360. });
  29361. Object.defineProperties(LOD.prototype, {
  29362. objects: {
  29363. get: function get() {
  29364. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29365. return this.levels;
  29366. }
  29367. }
  29368. });
  29369. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29370. get: function get() {
  29371. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29372. },
  29373. set: function set() {
  29374. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29375. }
  29376. });
  29377. SkinnedMesh.prototype.initBones = function () {
  29378. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29379. };
  29380. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29381. get: function get() {
  29382. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29383. return this.arcLengthDivisions;
  29384. },
  29385. set: function set(value) {
  29386. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29387. this.arcLengthDivisions = value;
  29388. }
  29389. }); //
  29390. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29391. console.warn("THREE.PerspectiveCamera.setLens is deprecated. " + "Use .setFocalLength and .filmGauge for a photographic setup.");
  29392. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29393. this.setFocalLength(focalLength);
  29394. }; //
  29395. Object.defineProperties(Light.prototype, {
  29396. onlyShadow: {
  29397. set: function set() {
  29398. console.warn('THREE.Light: .onlyShadow has been removed.');
  29399. }
  29400. },
  29401. shadowCameraFov: {
  29402. set: function set(value) {
  29403. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29404. this.shadow.camera.fov = value;
  29405. }
  29406. },
  29407. shadowCameraLeft: {
  29408. set: function set(value) {
  29409. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29410. this.shadow.camera.left = value;
  29411. }
  29412. },
  29413. shadowCameraRight: {
  29414. set: function set(value) {
  29415. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29416. this.shadow.camera.right = value;
  29417. }
  29418. },
  29419. shadowCameraTop: {
  29420. set: function set(value) {
  29421. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29422. this.shadow.camera.top = value;
  29423. }
  29424. },
  29425. shadowCameraBottom: {
  29426. set: function set(value) {
  29427. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29428. this.shadow.camera.bottom = value;
  29429. }
  29430. },
  29431. shadowCameraNear: {
  29432. set: function set(value) {
  29433. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29434. this.shadow.camera.near = value;
  29435. }
  29436. },
  29437. shadowCameraFar: {
  29438. set: function set(value) {
  29439. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29440. this.shadow.camera.far = value;
  29441. }
  29442. },
  29443. shadowCameraVisible: {
  29444. set: function set() {
  29445. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29446. }
  29447. },
  29448. shadowBias: {
  29449. set: function set(value) {
  29450. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29451. this.shadow.bias = value;
  29452. }
  29453. },
  29454. shadowDarkness: {
  29455. set: function set() {
  29456. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29457. }
  29458. },
  29459. shadowMapWidth: {
  29460. set: function set(value) {
  29461. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29462. this.shadow.mapSize.width = value;
  29463. }
  29464. },
  29465. shadowMapHeight: {
  29466. set: function set(value) {
  29467. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29468. this.shadow.mapSize.height = value;
  29469. }
  29470. }
  29471. }); //
  29472. Object.defineProperties(BufferAttribute.prototype, {
  29473. length: {
  29474. get: function get() {
  29475. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29476. return this.array.length;
  29477. }
  29478. },
  29479. dynamic: {
  29480. get: function get() {
  29481. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29482. return this.usage === DynamicDrawUsage;
  29483. },
  29484. set: function set()
  29485. /* value */
  29486. {
  29487. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29488. this.setUsage(DynamicDrawUsage);
  29489. }
  29490. }
  29491. });
  29492. Object.assign(BufferAttribute.prototype, {
  29493. setDynamic: function setDynamic(value) {
  29494. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29495. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29496. return this;
  29497. },
  29498. copyIndicesArray: function copyIndicesArray()
  29499. /* indices */
  29500. {
  29501. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29502. },
  29503. setArray: function setArray()
  29504. /* array */
  29505. {
  29506. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29507. }
  29508. });
  29509. Object.assign(BufferGeometry.prototype, {
  29510. addIndex: function addIndex(index) {
  29511. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29512. this.setIndex(index);
  29513. },
  29514. addAttribute: function addAttribute(name, attribute) {
  29515. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29516. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29517. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29518. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29519. }
  29520. if (name === 'index') {
  29521. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29522. this.setIndex(attribute);
  29523. return this;
  29524. }
  29525. return this.setAttribute(name, attribute);
  29526. },
  29527. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29528. if (indexOffset !== undefined) {
  29529. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29530. }
  29531. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29532. this.addGroup(start, count);
  29533. },
  29534. clearDrawCalls: function clearDrawCalls() {
  29535. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29536. this.clearGroups();
  29537. },
  29538. computeTangents: function computeTangents() {
  29539. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  29540. },
  29541. computeOffsets: function computeOffsets() {
  29542. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29543. },
  29544. removeAttribute: function removeAttribute(name) {
  29545. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29546. return this.deleteAttribute(name);
  29547. },
  29548. applyMatrix: function applyMatrix(matrix) {
  29549. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29550. return this.applyMatrix4(matrix);
  29551. }
  29552. });
  29553. Object.defineProperties(BufferGeometry.prototype, {
  29554. drawcalls: {
  29555. get: function get() {
  29556. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29557. return this.groups;
  29558. }
  29559. },
  29560. offsets: {
  29561. get: function get() {
  29562. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29563. return this.groups;
  29564. }
  29565. }
  29566. });
  29567. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29568. maxInstancedCount: {
  29569. get: function get() {
  29570. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29571. return this.instanceCount;
  29572. },
  29573. set: function set(value) {
  29574. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29575. this.instanceCount = value;
  29576. }
  29577. }
  29578. });
  29579. Object.defineProperties(Raycaster.prototype, {
  29580. linePrecision: {
  29581. get: function get() {
  29582. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29583. return this.params.Line.threshold;
  29584. },
  29585. set: function set(value) {
  29586. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29587. this.params.Line.threshold = value;
  29588. }
  29589. }
  29590. });
  29591. Object.defineProperties(InterleavedBuffer.prototype, {
  29592. dynamic: {
  29593. get: function get() {
  29594. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29595. return this.usage === DynamicDrawUsage;
  29596. },
  29597. set: function set(value) {
  29598. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29599. this.setUsage(value);
  29600. }
  29601. }
  29602. });
  29603. Object.assign(InterleavedBuffer.prototype, {
  29604. setDynamic: function setDynamic(value) {
  29605. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29606. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29607. return this;
  29608. },
  29609. setArray: function setArray()
  29610. /* array */
  29611. {
  29612. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29613. }
  29614. }); //
  29615. Object.assign(ExtrudeBufferGeometry.prototype, {
  29616. getArrays: function getArrays() {
  29617. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  29618. },
  29619. addShapeList: function addShapeList() {
  29620. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  29621. },
  29622. addShape: function addShape() {
  29623. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  29624. }
  29625. }); //
  29626. Object.assign(Scene.prototype, {
  29627. dispose: function dispose() {
  29628. console.error('THREE.Scene: .dispose() has been removed.');
  29629. }
  29630. }); //
  29631. Object.defineProperties(Uniform.prototype, {
  29632. dynamic: {
  29633. set: function set() {
  29634. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29635. }
  29636. },
  29637. onUpdate: {
  29638. value: function value() {
  29639. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29640. return this;
  29641. }
  29642. }
  29643. }); //
  29644. Object.defineProperties(Material.prototype, {
  29645. wrapAround: {
  29646. get: function get() {
  29647. console.warn('THREE.Material: .wrapAround has been removed.');
  29648. },
  29649. set: function set() {
  29650. console.warn('THREE.Material: .wrapAround has been removed.');
  29651. }
  29652. },
  29653. overdraw: {
  29654. get: function get() {
  29655. console.warn('THREE.Material: .overdraw has been removed.');
  29656. },
  29657. set: function set() {
  29658. console.warn('THREE.Material: .overdraw has been removed.');
  29659. }
  29660. },
  29661. wrapRGB: {
  29662. get: function get() {
  29663. console.warn('THREE.Material: .wrapRGB has been removed.');
  29664. return new Color();
  29665. }
  29666. },
  29667. shading: {
  29668. get: function get() {
  29669. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29670. },
  29671. set: function set(value) {
  29672. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29673. this.flatShading = value === FlatShading;
  29674. }
  29675. },
  29676. stencilMask: {
  29677. get: function get() {
  29678. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29679. return this.stencilFuncMask;
  29680. },
  29681. set: function set(value) {
  29682. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29683. this.stencilFuncMask = value;
  29684. }
  29685. }
  29686. });
  29687. Object.defineProperties(MeshPhongMaterial.prototype, {
  29688. metal: {
  29689. get: function get() {
  29690. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29691. return false;
  29692. },
  29693. set: function set() {
  29694. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29695. }
  29696. }
  29697. });
  29698. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29699. transparency: {
  29700. get: function get() {
  29701. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29702. return this.transmission;
  29703. },
  29704. set: function set(value) {
  29705. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29706. this.transmission = value;
  29707. }
  29708. }
  29709. });
  29710. Object.defineProperties(ShaderMaterial.prototype, {
  29711. derivatives: {
  29712. get: function get() {
  29713. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29714. return this.extensions.derivatives;
  29715. },
  29716. set: function set(value) {
  29717. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29718. this.extensions.derivatives = value;
  29719. }
  29720. }
  29721. }); //
  29722. Object.assign(WebGLRenderer.prototype, {
  29723. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29724. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29725. this.setRenderTarget(renderTarget);
  29726. this.clear(color, depth, stencil);
  29727. },
  29728. animate: function animate(callback) {
  29729. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29730. this.setAnimationLoop(callback);
  29731. },
  29732. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29733. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29734. return this.getRenderTarget();
  29735. },
  29736. getMaxAnisotropy: function getMaxAnisotropy() {
  29737. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29738. return this.capabilities.getMaxAnisotropy();
  29739. },
  29740. getPrecision: function getPrecision() {
  29741. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29742. return this.capabilities.precision;
  29743. },
  29744. resetGLState: function resetGLState() {
  29745. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29746. return this.state.reset();
  29747. },
  29748. supportsFloatTextures: function supportsFloatTextures() {
  29749. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  29750. return this.extensions.get('OES_texture_float');
  29751. },
  29752. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  29753. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  29754. return this.extensions.get('OES_texture_half_float');
  29755. },
  29756. supportsStandardDerivatives: function supportsStandardDerivatives() {
  29757. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  29758. return this.extensions.get('OES_standard_derivatives');
  29759. },
  29760. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  29761. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  29762. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  29763. },
  29764. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  29765. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  29766. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  29767. },
  29768. supportsBlendMinMax: function supportsBlendMinMax() {
  29769. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  29770. return this.extensions.get('EXT_blend_minmax');
  29771. },
  29772. supportsVertexTextures: function supportsVertexTextures() {
  29773. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  29774. return this.capabilities.vertexTextures;
  29775. },
  29776. supportsInstancedArrays: function supportsInstancedArrays() {
  29777. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  29778. return this.extensions.get('ANGLE_instanced_arrays');
  29779. },
  29780. enableScissorTest: function enableScissorTest(boolean) {
  29781. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  29782. this.setScissorTest(boolean);
  29783. },
  29784. initMaterial: function initMaterial() {
  29785. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  29786. },
  29787. addPrePlugin: function addPrePlugin() {
  29788. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  29789. },
  29790. addPostPlugin: function addPostPlugin() {
  29791. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  29792. },
  29793. updateShadowMap: function updateShadowMap() {
  29794. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  29795. },
  29796. setFaceCulling: function setFaceCulling() {
  29797. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  29798. },
  29799. allocTextureUnit: function allocTextureUnit() {
  29800. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  29801. },
  29802. setTexture: function setTexture() {
  29803. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  29804. },
  29805. setTexture2D: function setTexture2D() {
  29806. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  29807. },
  29808. setTextureCube: function setTextureCube() {
  29809. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  29810. },
  29811. getActiveMipMapLevel: function getActiveMipMapLevel() {
  29812. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  29813. return this.getActiveMipmapLevel();
  29814. }
  29815. });
  29816. Object.defineProperties(WebGLRenderer.prototype, {
  29817. shadowMapEnabled: {
  29818. get: function get() {
  29819. return this.shadowMap.enabled;
  29820. },
  29821. set: function set(value) {
  29822. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  29823. this.shadowMap.enabled = value;
  29824. }
  29825. },
  29826. shadowMapType: {
  29827. get: function get() {
  29828. return this.shadowMap.type;
  29829. },
  29830. set: function set(value) {
  29831. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  29832. this.shadowMap.type = value;
  29833. }
  29834. },
  29835. shadowMapCullFace: {
  29836. get: function get() {
  29837. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29838. return undefined;
  29839. },
  29840. set: function set()
  29841. /* value */
  29842. {
  29843. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29844. }
  29845. },
  29846. context: {
  29847. get: function get() {
  29848. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  29849. return this.getContext();
  29850. }
  29851. },
  29852. vr: {
  29853. get: function get() {
  29854. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  29855. return this.xr;
  29856. }
  29857. },
  29858. gammaInput: {
  29859. get: function get() {
  29860. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29861. return false;
  29862. },
  29863. set: function set() {
  29864. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29865. }
  29866. },
  29867. gammaOutput: {
  29868. get: function get() {
  29869. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29870. return false;
  29871. },
  29872. set: function set(value) {
  29873. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29874. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  29875. }
  29876. },
  29877. toneMappingWhitePoint: {
  29878. get: function get() {
  29879. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29880. return 1.0;
  29881. },
  29882. set: function set() {
  29883. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29884. }
  29885. }
  29886. });
  29887. Object.defineProperties(WebGLShadowMap.prototype, {
  29888. cullFace: {
  29889. get: function get() {
  29890. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29891. return undefined;
  29892. },
  29893. set: function set()
  29894. /* cullFace */
  29895. {
  29896. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29897. }
  29898. },
  29899. renderReverseSided: {
  29900. get: function get() {
  29901. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29902. return undefined;
  29903. },
  29904. set: function set() {
  29905. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29906. }
  29907. },
  29908. renderSingleSided: {
  29909. get: function get() {
  29910. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29911. return undefined;
  29912. },
  29913. set: function set() {
  29914. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29915. }
  29916. }
  29917. });
  29918. function WebGLRenderTargetCube(width, height, options) {
  29919. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  29920. return new WebGLCubeRenderTarget(width, options);
  29921. } //
  29922. Object.defineProperties(WebGLRenderTarget.prototype, {
  29923. wrapS: {
  29924. get: function get() {
  29925. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29926. return this.texture.wrapS;
  29927. },
  29928. set: function set(value) {
  29929. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29930. this.texture.wrapS = value;
  29931. }
  29932. },
  29933. wrapT: {
  29934. get: function get() {
  29935. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29936. return this.texture.wrapT;
  29937. },
  29938. set: function set(value) {
  29939. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29940. this.texture.wrapT = value;
  29941. }
  29942. },
  29943. magFilter: {
  29944. get: function get() {
  29945. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  29946. return this.texture.magFilter;
  29947. },
  29948. set: function set(value) {
  29949. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  29950. this.texture.magFilter = value;
  29951. }
  29952. },
  29953. minFilter: {
  29954. get: function get() {
  29955. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  29956. return this.texture.minFilter;
  29957. },
  29958. set: function set(value) {
  29959. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  29960. this.texture.minFilter = value;
  29961. }
  29962. },
  29963. anisotropy: {
  29964. get: function get() {
  29965. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  29966. return this.texture.anisotropy;
  29967. },
  29968. set: function set(value) {
  29969. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  29970. this.texture.anisotropy = value;
  29971. }
  29972. },
  29973. offset: {
  29974. get: function get() {
  29975. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  29976. return this.texture.offset;
  29977. },
  29978. set: function set(value) {
  29979. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  29980. this.texture.offset = value;
  29981. }
  29982. },
  29983. repeat: {
  29984. get: function get() {
  29985. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  29986. return this.texture.repeat;
  29987. },
  29988. set: function set(value) {
  29989. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  29990. this.texture.repeat = value;
  29991. }
  29992. },
  29993. format: {
  29994. get: function get() {
  29995. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  29996. return this.texture.format;
  29997. },
  29998. set: function set(value) {
  29999. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30000. this.texture.format = value;
  30001. }
  30002. },
  30003. type: {
  30004. get: function get() {
  30005. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30006. return this.texture.type;
  30007. },
  30008. set: function set(value) {
  30009. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30010. this.texture.type = value;
  30011. }
  30012. },
  30013. generateMipmaps: {
  30014. get: function get() {
  30015. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30016. return this.texture.generateMipmaps;
  30017. },
  30018. set: function set(value) {
  30019. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30020. this.texture.generateMipmaps = value;
  30021. }
  30022. }
  30023. }); //
  30024. Object.defineProperties(Audio.prototype, {
  30025. load: {
  30026. value: function value(file) {
  30027. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30028. var scope = this;
  30029. var audioLoader = new AudioLoader();
  30030. audioLoader.load(file, function (buffer) {
  30031. scope.setBuffer(buffer);
  30032. });
  30033. return this;
  30034. }
  30035. },
  30036. startTime: {
  30037. set: function set() {
  30038. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30039. }
  30040. }
  30041. });
  30042. AudioAnalyser.prototype.getData = function () {
  30043. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30044. return this.getFrequencyData();
  30045. }; //
  30046. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30047. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30048. return this.update(renderer, scene);
  30049. }; //
  30050. var GeometryUtils = {
  30051. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30052. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30053. var matrix;
  30054. if (geometry2.isMesh) {
  30055. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30056. matrix = geometry2.matrix;
  30057. geometry2 = geometry2.geometry;
  30058. }
  30059. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30060. },
  30061. center: function center(geometry) {
  30062. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30063. return geometry.center();
  30064. }
  30065. };
  30066. ImageUtils.crossOrigin = undefined;
  30067. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30068. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30069. var loader = new TextureLoader();
  30070. loader.setCrossOrigin(this.crossOrigin);
  30071. var texture = loader.load(url, onLoad, undefined, onError);
  30072. if (mapping) texture.mapping = mapping;
  30073. return texture;
  30074. };
  30075. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30076. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30077. var loader = new CubeTextureLoader();
  30078. loader.setCrossOrigin(this.crossOrigin);
  30079. var texture = loader.load(urls, onLoad, undefined, onError);
  30080. if (mapping) texture.mapping = mapping;
  30081. return texture;
  30082. };
  30083. ImageUtils.loadCompressedTexture = function () {
  30084. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30085. };
  30086. ImageUtils.loadCompressedTextureCube = function () {
  30087. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30088. }; //
  30089. function CanvasRenderer() {
  30090. console.error('THREE.CanvasRenderer has been removed');
  30091. } //
  30092. function JSONLoader() {
  30093. console.error('THREE.JSONLoader has been removed.');
  30094. } //
  30095. var SceneUtils = {
  30096. createMultiMaterialObject: function createMultiMaterialObject()
  30097. /* geometry, materials */
  30098. {
  30099. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30100. },
  30101. detach: function detach()
  30102. /* child, parent, scene */
  30103. {
  30104. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30105. },
  30106. attach: function attach()
  30107. /* child, scene, parent */
  30108. {
  30109. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30110. }
  30111. }; //
  30112. function LensFlare() {
  30113. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30114. }
  30115. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30116. /* eslint-disable no-undef */
  30117. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30118. detail: {
  30119. revision: REVISION
  30120. }
  30121. }));
  30122. /* eslint-enable no-undef */
  30123. }
  30124. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30125. exports.AddEquation = AddEquation;
  30126. exports.AddOperation = AddOperation;
  30127. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30128. exports.AdditiveBlending = AdditiveBlending;
  30129. exports.AlphaFormat = AlphaFormat;
  30130. exports.AlwaysDepth = AlwaysDepth;
  30131. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30132. exports.AmbientLight = AmbientLight;
  30133. exports.AmbientLightProbe = AmbientLightProbe;
  30134. exports.AnimationClip = AnimationClip;
  30135. exports.AnimationLoader = AnimationLoader;
  30136. exports.AnimationMixer = AnimationMixer;
  30137. exports.AnimationObjectGroup = AnimationObjectGroup;
  30138. exports.AnimationUtils = AnimationUtils;
  30139. exports.ArcCurve = ArcCurve;
  30140. exports.ArrayCamera = ArrayCamera;
  30141. exports.ArrowHelper = ArrowHelper;
  30142. exports.Audio = Audio;
  30143. exports.AudioAnalyser = AudioAnalyser;
  30144. exports.AudioContext = AudioContext;
  30145. exports.AudioListener = AudioListener;
  30146. exports.AudioLoader = AudioLoader;
  30147. exports.AxesHelper = AxesHelper;
  30148. exports.AxisHelper = AxisHelper;
  30149. exports.BackSide = BackSide;
  30150. exports.BasicDepthPacking = BasicDepthPacking;
  30151. exports.BasicShadowMap = BasicShadowMap;
  30152. exports.BinaryTextureLoader = BinaryTextureLoader;
  30153. exports.Bone = Bone;
  30154. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30155. exports.BoundingBoxHelper = BoundingBoxHelper;
  30156. exports.Box2 = Box2;
  30157. exports.Box3 = Box3;
  30158. exports.Box3Helper = Box3Helper;
  30159. exports.BoxBufferGeometry = BoxBufferGeometry;
  30160. exports.BoxGeometry = BoxGeometry;
  30161. exports.BoxHelper = BoxHelper;
  30162. exports.BufferAttribute = BufferAttribute;
  30163. exports.BufferGeometry = BufferGeometry;
  30164. exports.BufferGeometryLoader = BufferGeometryLoader;
  30165. exports.ByteType = ByteType;
  30166. exports.Cache = Cache;
  30167. exports.Camera = Camera;
  30168. exports.CameraHelper = CameraHelper;
  30169. exports.CanvasRenderer = CanvasRenderer;
  30170. exports.CanvasTexture = CanvasTexture;
  30171. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30172. exports.CineonToneMapping = CineonToneMapping;
  30173. exports.CircleBufferGeometry = CircleBufferGeometry;
  30174. exports.CircleGeometry = CircleGeometry;
  30175. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30176. exports.Clock = Clock;
  30177. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30178. exports.Color = Color;
  30179. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30180. exports.CompressedTexture = CompressedTexture;
  30181. exports.CompressedTextureLoader = CompressedTextureLoader;
  30182. exports.ConeBufferGeometry = ConeBufferGeometry;
  30183. exports.ConeGeometry = ConeGeometry;
  30184. exports.CubeCamera = CubeCamera;
  30185. exports.CubeGeometry = BoxGeometry;
  30186. exports.CubeReflectionMapping = CubeReflectionMapping;
  30187. exports.CubeRefractionMapping = CubeRefractionMapping;
  30188. exports.CubeTexture = CubeTexture;
  30189. exports.CubeTextureLoader = CubeTextureLoader;
  30190. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30191. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30192. exports.CubicBezierCurve = CubicBezierCurve;
  30193. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30194. exports.CubicInterpolant = CubicInterpolant;
  30195. exports.CullFaceBack = CullFaceBack;
  30196. exports.CullFaceFront = CullFaceFront;
  30197. exports.CullFaceFrontBack = CullFaceFrontBack;
  30198. exports.CullFaceNone = CullFaceNone;
  30199. exports.Curve = Curve;
  30200. exports.CurvePath = CurvePath;
  30201. exports.CustomBlending = CustomBlending;
  30202. exports.CustomToneMapping = CustomToneMapping;
  30203. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  30204. exports.CylinderGeometry = CylinderGeometry;
  30205. exports.Cylindrical = Cylindrical;
  30206. exports.DataTexture = DataTexture;
  30207. exports.DataTexture2DArray = DataTexture2DArray;
  30208. exports.DataTexture3D = DataTexture3D;
  30209. exports.DataTextureLoader = DataTextureLoader;
  30210. exports.DecrementStencilOp = DecrementStencilOp;
  30211. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30212. exports.DefaultLoadingManager = DefaultLoadingManager;
  30213. exports.DepthFormat = DepthFormat;
  30214. exports.DepthStencilFormat = DepthStencilFormat;
  30215. exports.DepthTexture = DepthTexture;
  30216. exports.DirectionalLight = DirectionalLight;
  30217. exports.DirectionalLightHelper = DirectionalLightHelper;
  30218. exports.DiscreteInterpolant = DiscreteInterpolant;
  30219. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  30220. exports.DodecahedronGeometry = DodecahedronGeometry;
  30221. exports.DoubleSide = DoubleSide;
  30222. exports.DstAlphaFactor = DstAlphaFactor;
  30223. exports.DstColorFactor = DstColorFactor;
  30224. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30225. exports.DynamicCopyUsage = DynamicCopyUsage;
  30226. exports.DynamicDrawUsage = DynamicDrawUsage;
  30227. exports.DynamicReadUsage = DynamicReadUsage;
  30228. exports.EdgesGeometry = EdgesGeometry;
  30229. exports.EdgesHelper = EdgesHelper;
  30230. exports.EllipseCurve = EllipseCurve;
  30231. exports.EqualDepth = EqualDepth;
  30232. exports.EqualStencilFunc = EqualStencilFunc;
  30233. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30234. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30235. exports.Euler = Euler;
  30236. exports.EventDispatcher = EventDispatcher;
  30237. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  30238. exports.ExtrudeGeometry = ExtrudeGeometry;
  30239. exports.Face3 = Face3;
  30240. exports.Face4 = Face4;
  30241. exports.FaceColors = FaceColors;
  30242. exports.FileLoader = FileLoader;
  30243. exports.FlatShading = FlatShading;
  30244. exports.Float32Attribute = Float32Attribute;
  30245. exports.Float32BufferAttribute = Float32BufferAttribute;
  30246. exports.Float64Attribute = Float64Attribute;
  30247. exports.Float64BufferAttribute = Float64BufferAttribute;
  30248. exports.FloatType = FloatType;
  30249. exports.Fog = Fog;
  30250. exports.FogExp2 = FogExp2;
  30251. exports.Font = Font;
  30252. exports.FontLoader = FontLoader;
  30253. exports.FrontSide = FrontSide;
  30254. exports.Frustum = Frustum;
  30255. exports.GLBufferAttribute = GLBufferAttribute;
  30256. exports.GLSL1 = GLSL1;
  30257. exports.GLSL3 = GLSL3;
  30258. exports.GammaEncoding = GammaEncoding;
  30259. exports.Geometry = Geometry;
  30260. exports.GeometryUtils = GeometryUtils;
  30261. exports.GreaterDepth = GreaterDepth;
  30262. exports.GreaterEqualDepth = GreaterEqualDepth;
  30263. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30264. exports.GreaterStencilFunc = GreaterStencilFunc;
  30265. exports.GridHelper = GridHelper;
  30266. exports.Group = Group;
  30267. exports.HalfFloatType = HalfFloatType;
  30268. exports.HemisphereLight = HemisphereLight;
  30269. exports.HemisphereLightHelper = HemisphereLightHelper;
  30270. exports.HemisphereLightProbe = HemisphereLightProbe;
  30271. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  30272. exports.IcosahedronGeometry = IcosahedronGeometry;
  30273. exports.ImageBitmapLoader = ImageBitmapLoader;
  30274. exports.ImageLoader = ImageLoader;
  30275. exports.ImageUtils = ImageUtils;
  30276. exports.ImmediateRenderObject = ImmediateRenderObject;
  30277. exports.IncrementStencilOp = IncrementStencilOp;
  30278. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30279. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30280. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30281. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30282. exports.InstancedMesh = InstancedMesh;
  30283. exports.Int16Attribute = Int16Attribute;
  30284. exports.Int16BufferAttribute = Int16BufferAttribute;
  30285. exports.Int32Attribute = Int32Attribute;
  30286. exports.Int32BufferAttribute = Int32BufferAttribute;
  30287. exports.Int8Attribute = Int8Attribute;
  30288. exports.Int8BufferAttribute = Int8BufferAttribute;
  30289. exports.IntType = IntType;
  30290. exports.InterleavedBuffer = InterleavedBuffer;
  30291. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30292. exports.Interpolant = Interpolant;
  30293. exports.InterpolateDiscrete = InterpolateDiscrete;
  30294. exports.InterpolateLinear = InterpolateLinear;
  30295. exports.InterpolateSmooth = InterpolateSmooth;
  30296. exports.InvertStencilOp = InvertStencilOp;
  30297. exports.JSONLoader = JSONLoader;
  30298. exports.KeepStencilOp = KeepStencilOp;
  30299. exports.KeyframeTrack = KeyframeTrack;
  30300. exports.LOD = LOD;
  30301. exports.LatheBufferGeometry = LatheBufferGeometry;
  30302. exports.LatheGeometry = LatheGeometry;
  30303. exports.Layers = Layers;
  30304. exports.LensFlare = LensFlare;
  30305. exports.LessDepth = LessDepth;
  30306. exports.LessEqualDepth = LessEqualDepth;
  30307. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30308. exports.LessStencilFunc = LessStencilFunc;
  30309. exports.Light = Light;
  30310. exports.LightProbe = LightProbe;
  30311. exports.Line = Line;
  30312. exports.Line3 = Line3;
  30313. exports.LineBasicMaterial = LineBasicMaterial;
  30314. exports.LineCurve = LineCurve;
  30315. exports.LineCurve3 = LineCurve3;
  30316. exports.LineDashedMaterial = LineDashedMaterial;
  30317. exports.LineLoop = LineLoop;
  30318. exports.LinePieces = LinePieces;
  30319. exports.LineSegments = LineSegments;
  30320. exports.LineStrip = LineStrip;
  30321. exports.LinearEncoding = LinearEncoding;
  30322. exports.LinearFilter = LinearFilter;
  30323. exports.LinearInterpolant = LinearInterpolant;
  30324. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30325. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30326. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30327. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30328. exports.LinearToneMapping = LinearToneMapping;
  30329. exports.Loader = Loader;
  30330. exports.LoaderUtils = LoaderUtils;
  30331. exports.LoadingManager = LoadingManager;
  30332. exports.LogLuvEncoding = LogLuvEncoding;
  30333. exports.LoopOnce = LoopOnce;
  30334. exports.LoopPingPong = LoopPingPong;
  30335. exports.LoopRepeat = LoopRepeat;
  30336. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30337. exports.LuminanceFormat = LuminanceFormat;
  30338. exports.MOUSE = MOUSE;
  30339. exports.Material = Material;
  30340. exports.MaterialLoader = MaterialLoader;
  30341. exports.Math = MathUtils;
  30342. exports.MathUtils = MathUtils;
  30343. exports.Matrix3 = Matrix3;
  30344. exports.Matrix4 = Matrix4;
  30345. exports.MaxEquation = MaxEquation;
  30346. exports.Mesh = Mesh;
  30347. exports.MeshBasicMaterial = MeshBasicMaterial;
  30348. exports.MeshDepthMaterial = MeshDepthMaterial;
  30349. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30350. exports.MeshFaceMaterial = MeshFaceMaterial;
  30351. exports.MeshLambertMaterial = MeshLambertMaterial;
  30352. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30353. exports.MeshNormalMaterial = MeshNormalMaterial;
  30354. exports.MeshPhongMaterial = MeshPhongMaterial;
  30355. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30356. exports.MeshStandardMaterial = MeshStandardMaterial;
  30357. exports.MeshToonMaterial = MeshToonMaterial;
  30358. exports.MinEquation = MinEquation;
  30359. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30360. exports.MixOperation = MixOperation;
  30361. exports.MultiMaterial = MultiMaterial;
  30362. exports.MultiplyBlending = MultiplyBlending;
  30363. exports.MultiplyOperation = MultiplyOperation;
  30364. exports.NearestFilter = NearestFilter;
  30365. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30366. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30367. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30368. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30369. exports.NeverDepth = NeverDepth;
  30370. exports.NeverStencilFunc = NeverStencilFunc;
  30371. exports.NoBlending = NoBlending;
  30372. exports.NoColors = NoColors;
  30373. exports.NoToneMapping = NoToneMapping;
  30374. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30375. exports.NormalBlending = NormalBlending;
  30376. exports.NotEqualDepth = NotEqualDepth;
  30377. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30378. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30379. exports.Object3D = Object3D;
  30380. exports.ObjectLoader = ObjectLoader;
  30381. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30382. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  30383. exports.OctahedronGeometry = OctahedronGeometry;
  30384. exports.OneFactor = OneFactor;
  30385. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30386. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30387. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30388. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30389. exports.OrthographicCamera = OrthographicCamera;
  30390. exports.PCFShadowMap = PCFShadowMap;
  30391. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30392. exports.PMREMGenerator = PMREMGenerator;
  30393. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  30394. exports.ParametricGeometry = ParametricGeometry;
  30395. exports.Particle = Particle;
  30396. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30397. exports.ParticleSystem = ParticleSystem;
  30398. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30399. exports.Path = Path;
  30400. exports.PerspectiveCamera = PerspectiveCamera;
  30401. exports.Plane = Plane;
  30402. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  30403. exports.PlaneGeometry = PlaneGeometry;
  30404. exports.PlaneHelper = PlaneHelper;
  30405. exports.PointCloud = PointCloud;
  30406. exports.PointCloudMaterial = PointCloudMaterial;
  30407. exports.PointLight = PointLight;
  30408. exports.PointLightHelper = PointLightHelper;
  30409. exports.Points = Points;
  30410. exports.PointsMaterial = PointsMaterial;
  30411. exports.PolarGridHelper = PolarGridHelper;
  30412. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  30413. exports.PolyhedronGeometry = PolyhedronGeometry;
  30414. exports.PositionalAudio = PositionalAudio;
  30415. exports.PropertyBinding = PropertyBinding;
  30416. exports.PropertyMixer = PropertyMixer;
  30417. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30418. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30419. exports.Quaternion = Quaternion;
  30420. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30421. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30422. exports.REVISION = REVISION;
  30423. exports.RGBADepthPacking = RGBADepthPacking;
  30424. exports.RGBAFormat = RGBAFormat;
  30425. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30426. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30427. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30428. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30429. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30430. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30431. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30432. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30433. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30434. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30435. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30436. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30437. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30438. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30439. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30440. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30441. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30442. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30443. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30444. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30445. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30446. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30447. exports.RGBDEncoding = RGBDEncoding;
  30448. exports.RGBEEncoding = RGBEEncoding;
  30449. exports.RGBEFormat = RGBEFormat;
  30450. exports.RGBFormat = RGBFormat;
  30451. exports.RGBIntegerFormat = RGBIntegerFormat;
  30452. exports.RGBM16Encoding = RGBM16Encoding;
  30453. exports.RGBM7Encoding = RGBM7Encoding;
  30454. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30455. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30456. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30457. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30458. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30459. exports.RGFormat = RGFormat;
  30460. exports.RGIntegerFormat = RGIntegerFormat;
  30461. exports.RawShaderMaterial = RawShaderMaterial;
  30462. exports.Ray = Ray;
  30463. exports.Raycaster = Raycaster;
  30464. exports.RectAreaLight = RectAreaLight;
  30465. exports.RedFormat = RedFormat;
  30466. exports.RedIntegerFormat = RedIntegerFormat;
  30467. exports.ReinhardToneMapping = ReinhardToneMapping;
  30468. exports.RepeatWrapping = RepeatWrapping;
  30469. exports.ReplaceStencilOp = ReplaceStencilOp;
  30470. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30471. exports.RingBufferGeometry = RingBufferGeometry;
  30472. exports.RingGeometry = RingGeometry;
  30473. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30474. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30475. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30476. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30477. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30478. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30479. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30480. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30481. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30482. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30483. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30484. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30485. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30486. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30487. exports.Scene = Scene;
  30488. exports.SceneUtils = SceneUtils;
  30489. exports.ShaderChunk = ShaderChunk;
  30490. exports.ShaderLib = ShaderLib;
  30491. exports.ShaderMaterial = ShaderMaterial;
  30492. exports.ShadowMaterial = ShadowMaterial;
  30493. exports.Shape = Shape;
  30494. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  30495. exports.ShapeGeometry = ShapeGeometry;
  30496. exports.ShapePath = ShapePath;
  30497. exports.ShapeUtils = ShapeUtils;
  30498. exports.ShortType = ShortType;
  30499. exports.Skeleton = Skeleton;
  30500. exports.SkeletonHelper = SkeletonHelper;
  30501. exports.SkinnedMesh = SkinnedMesh;
  30502. exports.SmoothShading = SmoothShading;
  30503. exports.Sphere = Sphere;
  30504. exports.SphereBufferGeometry = SphereBufferGeometry;
  30505. exports.SphereGeometry = SphereGeometry;
  30506. exports.Spherical = Spherical;
  30507. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30508. exports.Spline = Spline;
  30509. exports.SplineCurve = SplineCurve;
  30510. exports.SplineCurve3 = SplineCurve3;
  30511. exports.SpotLight = SpotLight;
  30512. exports.SpotLightHelper = SpotLightHelper;
  30513. exports.Sprite = Sprite;
  30514. exports.SpriteMaterial = SpriteMaterial;
  30515. exports.SrcAlphaFactor = SrcAlphaFactor;
  30516. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30517. exports.SrcColorFactor = SrcColorFactor;
  30518. exports.StaticCopyUsage = StaticCopyUsage;
  30519. exports.StaticDrawUsage = StaticDrawUsage;
  30520. exports.StaticReadUsage = StaticReadUsage;
  30521. exports.StereoCamera = StereoCamera;
  30522. exports.StreamCopyUsage = StreamCopyUsage;
  30523. exports.StreamDrawUsage = StreamDrawUsage;
  30524. exports.StreamReadUsage = StreamReadUsage;
  30525. exports.StringKeyframeTrack = StringKeyframeTrack;
  30526. exports.SubtractEquation = SubtractEquation;
  30527. exports.SubtractiveBlending = SubtractiveBlending;
  30528. exports.TOUCH = TOUCH;
  30529. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30530. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  30531. exports.TetrahedronGeometry = TetrahedronGeometry;
  30532. exports.TextBufferGeometry = TextBufferGeometry;
  30533. exports.TextGeometry = TextGeometry;
  30534. exports.Texture = Texture;
  30535. exports.TextureLoader = TextureLoader;
  30536. exports.TorusBufferGeometry = TorusBufferGeometry;
  30537. exports.TorusGeometry = TorusGeometry;
  30538. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  30539. exports.TorusKnotGeometry = TorusKnotGeometry;
  30540. exports.Triangle = Triangle;
  30541. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30542. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30543. exports.TrianglesDrawMode = TrianglesDrawMode;
  30544. exports.TubeBufferGeometry = TubeBufferGeometry;
  30545. exports.TubeGeometry = TubeGeometry;
  30546. exports.UVMapping = UVMapping;
  30547. exports.Uint16Attribute = Uint16Attribute;
  30548. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30549. exports.Uint32Attribute = Uint32Attribute;
  30550. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30551. exports.Uint8Attribute = Uint8Attribute;
  30552. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30553. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30554. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30555. exports.Uniform = Uniform;
  30556. exports.UniformsLib = UniformsLib;
  30557. exports.UniformsUtils = UniformsUtils;
  30558. exports.UnsignedByteType = UnsignedByteType;
  30559. exports.UnsignedInt248Type = UnsignedInt248Type;
  30560. exports.UnsignedIntType = UnsignedIntType;
  30561. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30562. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30563. exports.UnsignedShort565Type = UnsignedShort565Type;
  30564. exports.UnsignedShortType = UnsignedShortType;
  30565. exports.VSMShadowMap = VSMShadowMap;
  30566. exports.Vector2 = Vector2;
  30567. exports.Vector3 = Vector3;
  30568. exports.Vector4 = Vector4;
  30569. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30570. exports.Vertex = Vertex;
  30571. exports.VertexColors = VertexColors;
  30572. exports.VideoTexture = VideoTexture;
  30573. exports.WebGL1Renderer = WebGL1Renderer;
  30574. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30575. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30576. exports.WebGLRenderTarget = WebGLRenderTarget;
  30577. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30578. exports.WebGLRenderer = WebGLRenderer;
  30579. exports.WebGLUtils = WebGLUtils;
  30580. exports.WireframeGeometry = WireframeGeometry;
  30581. exports.WireframeHelper = WireframeHelper;
  30582. exports.WrapAroundEnding = WrapAroundEnding;
  30583. exports.XHRLoader = XHRLoader;
  30584. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30585. exports.ZeroFactor = ZeroFactor;
  30586. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30587. exports.ZeroStencilOp = ZeroStencilOp;
  30588. exports.sRGBEncoding = sRGBEncoding;
  30589. Object.defineProperty(exports, '__esModule', { value: true });
  30590. })));