three.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. /**
  55. * Copyright (c) 2014-present, Facebook, Inc.
  56. *
  57. * This source code is licensed under the MIT license found in the
  58. * LICENSE file in the root directory of this source tree.
  59. */
  60. var runtime = function (exports) {
  61. var Op = Object.prototype;
  62. var hasOwn = Op.hasOwnProperty;
  63. var undefined$1; // More compressible than void 0.
  64. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  65. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  66. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  67. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  68. function define(obj, key, value) {
  69. Object.defineProperty(obj, key, {
  70. value: value,
  71. enumerable: true,
  72. configurable: true,
  73. writable: true
  74. });
  75. return obj[key];
  76. }
  77. try {
  78. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  79. define({}, "");
  80. } catch (err) {
  81. define = function define(obj, key, value) {
  82. return obj[key] = value;
  83. };
  84. }
  85. function wrap(innerFn, outerFn, self, tryLocsList) {
  86. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  87. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  88. var generator = Object.create(protoGenerator.prototype);
  89. var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
  90. // .throw, and .return methods.
  91. generator._invoke = makeInvokeMethod(innerFn, self, context);
  92. return generator;
  93. }
  94. exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
  95. // record like context.tryEntries[i].completion. This interface could
  96. // have been (and was previously) designed to take a closure to be
  97. // invoked without arguments, but in all the cases we care about we
  98. // already have an existing method we want to call, so there's no need
  99. // to create a new function object. We can even get away with assuming
  100. // the method takes exactly one argument, since that happens to be true
  101. // in every case, so we don't have to touch the arguments object. The
  102. // only additional allocation required is the completion record, which
  103. // has a stable shape and so hopefully should be cheap to allocate.
  104. function tryCatch(fn, obj, arg) {
  105. try {
  106. return {
  107. type: "normal",
  108. arg: fn.call(obj, arg)
  109. };
  110. } catch (err) {
  111. return {
  112. type: "throw",
  113. arg: err
  114. };
  115. }
  116. }
  117. var GenStateSuspendedStart = "suspendedStart";
  118. var GenStateSuspendedYield = "suspendedYield";
  119. var GenStateExecuting = "executing";
  120. var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
  121. // breaking out of the dispatch switch statement.
  122. var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
  123. // .constructor.prototype properties for functions that return Generator
  124. // objects. For full spec compliance, you may wish to configure your
  125. // minifier not to mangle the names of these two functions.
  126. function Generator() {}
  127. function GeneratorFunction() {}
  128. function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
  129. // don't natively support it.
  130. var IteratorPrototype = {};
  131. IteratorPrototype[iteratorSymbol] = function () {
  132. return this;
  133. };
  134. var getProto = Object.getPrototypeOf;
  135. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  136. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  137. // This environment has a native %IteratorPrototype%; use it instead
  138. // of the polyfill.
  139. IteratorPrototype = NativeIteratorPrototype;
  140. }
  141. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  142. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  143. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  144. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
  145. // Iterator interface in terms of a single ._invoke method.
  146. function defineIteratorMethods(prototype) {
  147. ["next", "throw", "return"].forEach(function (method) {
  148. define(prototype, method, function (arg) {
  149. return this._invoke(method, arg);
  150. });
  151. });
  152. }
  153. exports.isGeneratorFunction = function (genFun) {
  154. var ctor = typeof genFun === "function" && genFun.constructor;
  155. return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
  156. // do is to check its .name property.
  157. (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  158. };
  159. exports.mark = function (genFun) {
  160. if (Object.setPrototypeOf) {
  161. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  162. } else {
  163. genFun.__proto__ = GeneratorFunctionPrototype;
  164. define(genFun, toStringTagSymbol, "GeneratorFunction");
  165. }
  166. genFun.prototype = Object.create(Gp);
  167. return genFun;
  168. }; // Within the body of any async function, `await x` is transformed to
  169. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  170. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  171. // meant to be awaited.
  172. exports.awrap = function (arg) {
  173. return {
  174. __await: arg
  175. };
  176. };
  177. function AsyncIterator(generator, PromiseImpl) {
  178. function invoke(method, arg, resolve, reject) {
  179. var record = tryCatch(generator[method], generator, arg);
  180. if (record.type === "throw") {
  181. reject(record.arg);
  182. } else {
  183. var result = record.arg;
  184. var value = result.value;
  185. if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
  186. return PromiseImpl.resolve(value.__await).then(function (value) {
  187. invoke("next", value, resolve, reject);
  188. }, function (err) {
  189. invoke("throw", err, resolve, reject);
  190. });
  191. }
  192. return PromiseImpl.resolve(value).then(function (unwrapped) {
  193. // When a yielded Promise is resolved, its final value becomes
  194. // the .value of the Promise<{value,done}> result for the
  195. // current iteration.
  196. result.value = unwrapped;
  197. resolve(result);
  198. }, function (error) {
  199. // If a rejected Promise was yielded, throw the rejection back
  200. // into the async generator function so it can be handled there.
  201. return invoke("throw", error, resolve, reject);
  202. });
  203. }
  204. }
  205. var previousPromise;
  206. function enqueue(method, arg) {
  207. function callInvokeWithMethodAndArg() {
  208. return new PromiseImpl(function (resolve, reject) {
  209. invoke(method, arg, resolve, reject);
  210. });
  211. }
  212. return previousPromise = // If enqueue has been called before, then we want to wait until
  213. // all previous Promises have been resolved before calling invoke,
  214. // so that results are always delivered in the correct order. If
  215. // enqueue has not been called before, then it is important to
  216. // call invoke immediately, without waiting on a callback to fire,
  217. // so that the async generator function has the opportunity to do
  218. // any necessary setup in a predictable way. This predictability
  219. // is why the Promise constructor synchronously invokes its
  220. // executor callback, and why async functions synchronously
  221. // execute code before the first await. Since we implement simple
  222. // async functions in terms of async generators, it is especially
  223. // important to get this right, even though it requires care.
  224. previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
  225. // invocations of the iterator.
  226. callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  227. } // Define the unified helper method that is used to implement .next,
  228. // .throw, and .return (see defineIteratorMethods).
  229. this._invoke = enqueue;
  230. }
  231. defineIteratorMethods(AsyncIterator.prototype);
  232. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  233. return this;
  234. };
  235. exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
  236. // AsyncIterator objects; they just return a Promise for the value of
  237. // the final result produced by the iterator.
  238. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  239. if (PromiseImpl === void 0) PromiseImpl = Promise;
  240. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  241. return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
  242. : iter.next().then(function (result) {
  243. return result.done ? result.value : iter.next();
  244. });
  245. };
  246. function makeInvokeMethod(innerFn, self, context) {
  247. var state = GenStateSuspendedStart;
  248. return function invoke(method, arg) {
  249. if (state === GenStateExecuting) {
  250. throw new Error("Generator is already running");
  251. }
  252. if (state === GenStateCompleted) {
  253. if (method === "throw") {
  254. throw arg;
  255. } // Be forgiving, per 25.3.3.3.3 of the spec:
  256. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  257. return doneResult();
  258. }
  259. context.method = method;
  260. context.arg = arg;
  261. while (true) {
  262. var delegate = context.delegate;
  263. if (delegate) {
  264. var delegateResult = maybeInvokeDelegate(delegate, context);
  265. if (delegateResult) {
  266. if (delegateResult === ContinueSentinel) continue;
  267. return delegateResult;
  268. }
  269. }
  270. if (context.method === "next") {
  271. // Setting context._sent for legacy support of Babel's
  272. // function.sent implementation.
  273. context.sent = context._sent = context.arg;
  274. } else if (context.method === "throw") {
  275. if (state === GenStateSuspendedStart) {
  276. state = GenStateCompleted;
  277. throw context.arg;
  278. }
  279. context.dispatchException(context.arg);
  280. } else if (context.method === "return") {
  281. context.abrupt("return", context.arg);
  282. }
  283. state = GenStateExecuting;
  284. var record = tryCatch(innerFn, self, context);
  285. if (record.type === "normal") {
  286. // If an exception is thrown from innerFn, we leave state ===
  287. // GenStateExecuting and loop back for another invocation.
  288. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  289. if (record.arg === ContinueSentinel) {
  290. continue;
  291. }
  292. return {
  293. value: record.arg,
  294. done: context.done
  295. };
  296. } else if (record.type === "throw") {
  297. state = GenStateCompleted; // Dispatch the exception by looping back around to the
  298. // context.dispatchException(context.arg) call above.
  299. context.method = "throw";
  300. context.arg = record.arg;
  301. }
  302. }
  303. };
  304. } // Call delegate.iterator[context.method](context.arg) and handle the
  305. // result, either by returning a { value, done } result from the
  306. // delegate iterator, or by modifying context.method and context.arg,
  307. // setting context.delegate to null, and returning the ContinueSentinel.
  308. function maybeInvokeDelegate(delegate, context) {
  309. var method = delegate.iterator[context.method];
  310. if (method === undefined$1) {
  311. // A .throw or .return when the delegate iterator has no .throw
  312. // method always terminates the yield* loop.
  313. context.delegate = null;
  314. if (context.method === "throw") {
  315. // Note: ["return"] must be used for ES3 parsing compatibility.
  316. if (delegate.iterator["return"]) {
  317. // If the delegate iterator has a return method, give it a
  318. // chance to clean up.
  319. context.method = "return";
  320. context.arg = undefined$1;
  321. maybeInvokeDelegate(delegate, context);
  322. if (context.method === "throw") {
  323. // If maybeInvokeDelegate(context) changed context.method from
  324. // "return" to "throw", let that override the TypeError below.
  325. return ContinueSentinel;
  326. }
  327. }
  328. context.method = "throw";
  329. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  330. }
  331. return ContinueSentinel;
  332. }
  333. var record = tryCatch(method, delegate.iterator, context.arg);
  334. if (record.type === "throw") {
  335. context.method = "throw";
  336. context.arg = record.arg;
  337. context.delegate = null;
  338. return ContinueSentinel;
  339. }
  340. var info = record.arg;
  341. if (!info) {
  342. context.method = "throw";
  343. context.arg = new TypeError("iterator result is not an object");
  344. context.delegate = null;
  345. return ContinueSentinel;
  346. }
  347. if (info.done) {
  348. // Assign the result of the finished delegate to the temporary
  349. // variable specified by delegate.resultName (see delegateYield).
  350. context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
  351. context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
  352. // exception, let the outer generator proceed normally. If
  353. // context.method was "next", forget context.arg since it has been
  354. // "consumed" by the delegate iterator. If context.method was
  355. // "return", allow the original .return call to continue in the
  356. // outer generator.
  357. if (context.method !== "return") {
  358. context.method = "next";
  359. context.arg = undefined$1;
  360. }
  361. } else {
  362. // Re-yield the result returned by the delegate method.
  363. return info;
  364. } // The delegate iterator is finished, so forget it and continue with
  365. // the outer generator.
  366. context.delegate = null;
  367. return ContinueSentinel;
  368. } // Define Generator.prototype.{next,throw,return} in terms of the
  369. // unified ._invoke helper method.
  370. defineIteratorMethods(Gp);
  371. define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
  372. // @@iterator function is called on it. Some browsers' implementations of the
  373. // iterator prototype chain incorrectly implement this, causing the Generator
  374. // object to not be returned from this call. This ensures that doesn't happen.
  375. // See https://github.com/facebook/regenerator/issues/274 for more details.
  376. Gp[iteratorSymbol] = function () {
  377. return this;
  378. };
  379. Gp.toString = function () {
  380. return "[object Generator]";
  381. };
  382. function pushTryEntry(locs) {
  383. var entry = {
  384. tryLoc: locs[0]
  385. };
  386. if (1 in locs) {
  387. entry.catchLoc = locs[1];
  388. }
  389. if (2 in locs) {
  390. entry.finallyLoc = locs[2];
  391. entry.afterLoc = locs[3];
  392. }
  393. this.tryEntries.push(entry);
  394. }
  395. function resetTryEntry(entry) {
  396. var record = entry.completion || {};
  397. record.type = "normal";
  398. delete record.arg;
  399. entry.completion = record;
  400. }
  401. function Context(tryLocsList) {
  402. // The root entry object (effectively a try statement without a catch
  403. // or a finally block) gives us a place to store values thrown from
  404. // locations where there is no enclosing try statement.
  405. this.tryEntries = [{
  406. tryLoc: "root"
  407. }];
  408. tryLocsList.forEach(pushTryEntry, this);
  409. this.reset(true);
  410. }
  411. exports.keys = function (object) {
  412. var keys = [];
  413. for (var key in object) {
  414. keys.push(key);
  415. }
  416. keys.reverse(); // Rather than returning an object with a next method, we keep
  417. // things simple and return the next function itself.
  418. return function next() {
  419. while (keys.length) {
  420. var key = keys.pop();
  421. if (key in object) {
  422. next.value = key;
  423. next.done = false;
  424. return next;
  425. }
  426. } // To avoid creating an additional object, we just hang the .value
  427. // and .done properties off the next function object itself. This
  428. // also ensures that the minifier will not anonymize the function.
  429. next.done = true;
  430. return next;
  431. };
  432. };
  433. function values(iterable) {
  434. if (iterable) {
  435. var iteratorMethod = iterable[iteratorSymbol];
  436. if (iteratorMethod) {
  437. return iteratorMethod.call(iterable);
  438. }
  439. if (typeof iterable.next === "function") {
  440. return iterable;
  441. }
  442. if (!isNaN(iterable.length)) {
  443. var i = -1,
  444. next = function next() {
  445. while (++i < iterable.length) {
  446. if (hasOwn.call(iterable, i)) {
  447. next.value = iterable[i];
  448. next.done = false;
  449. return next;
  450. }
  451. }
  452. next.value = undefined$1;
  453. next.done = true;
  454. return next;
  455. };
  456. return next.next = next;
  457. }
  458. } // Return an iterator with no values.
  459. return {
  460. next: doneResult
  461. };
  462. }
  463. exports.values = values;
  464. function doneResult() {
  465. return {
  466. value: undefined$1,
  467. done: true
  468. };
  469. }
  470. Context.prototype = {
  471. constructor: Context,
  472. reset: function reset(skipTempReset) {
  473. this.prev = 0;
  474. this.next = 0; // Resetting context._sent for legacy support of Babel's
  475. // function.sent implementation.
  476. this.sent = this._sent = undefined$1;
  477. this.done = false;
  478. this.delegate = null;
  479. this.method = "next";
  480. this.arg = undefined$1;
  481. this.tryEntries.forEach(resetTryEntry);
  482. if (!skipTempReset) {
  483. for (var name in this) {
  484. // Not sure about the optimal order of these conditions:
  485. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  486. this[name] = undefined$1;
  487. }
  488. }
  489. }
  490. },
  491. stop: function stop() {
  492. this.done = true;
  493. var rootEntry = this.tryEntries[0];
  494. var rootRecord = rootEntry.completion;
  495. if (rootRecord.type === "throw") {
  496. throw rootRecord.arg;
  497. }
  498. return this.rval;
  499. },
  500. dispatchException: function dispatchException(exception) {
  501. if (this.done) {
  502. throw exception;
  503. }
  504. var context = this;
  505. function handle(loc, caught) {
  506. record.type = "throw";
  507. record.arg = exception;
  508. context.next = loc;
  509. if (caught) {
  510. // If the dispatched exception was caught by a catch block,
  511. // then let that catch block handle the exception normally.
  512. context.method = "next";
  513. context.arg = undefined$1;
  514. }
  515. return !!caught;
  516. }
  517. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  518. var entry = this.tryEntries[i];
  519. var record = entry.completion;
  520. if (entry.tryLoc === "root") {
  521. // Exception thrown outside of any try block that could handle
  522. // it, so set the completion value of the entire function to
  523. // throw the exception.
  524. return handle("end");
  525. }
  526. if (entry.tryLoc <= this.prev) {
  527. var hasCatch = hasOwn.call(entry, "catchLoc");
  528. var hasFinally = hasOwn.call(entry, "finallyLoc");
  529. if (hasCatch && hasFinally) {
  530. if (this.prev < entry.catchLoc) {
  531. return handle(entry.catchLoc, true);
  532. } else if (this.prev < entry.finallyLoc) {
  533. return handle(entry.finallyLoc);
  534. }
  535. } else if (hasCatch) {
  536. if (this.prev < entry.catchLoc) {
  537. return handle(entry.catchLoc, true);
  538. }
  539. } else if (hasFinally) {
  540. if (this.prev < entry.finallyLoc) {
  541. return handle(entry.finallyLoc);
  542. }
  543. } else {
  544. throw new Error("try statement without catch or finally");
  545. }
  546. }
  547. }
  548. },
  549. abrupt: function abrupt(type, arg) {
  550. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  551. var entry = this.tryEntries[i];
  552. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  553. var finallyEntry = entry;
  554. break;
  555. }
  556. }
  557. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  558. // Ignore the finally entry if control is not jumping to a
  559. // location outside the try/catch block.
  560. finallyEntry = null;
  561. }
  562. var record = finallyEntry ? finallyEntry.completion : {};
  563. record.type = type;
  564. record.arg = arg;
  565. if (finallyEntry) {
  566. this.method = "next";
  567. this.next = finallyEntry.finallyLoc;
  568. return ContinueSentinel;
  569. }
  570. return this.complete(record);
  571. },
  572. complete: function complete(record, afterLoc) {
  573. if (record.type === "throw") {
  574. throw record.arg;
  575. }
  576. if (record.type === "break" || record.type === "continue") {
  577. this.next = record.arg;
  578. } else if (record.type === "return") {
  579. this.rval = this.arg = record.arg;
  580. this.method = "return";
  581. this.next = "end";
  582. } else if (record.type === "normal" && afterLoc) {
  583. this.next = afterLoc;
  584. }
  585. return ContinueSentinel;
  586. },
  587. finish: function finish(finallyLoc) {
  588. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  589. var entry = this.tryEntries[i];
  590. if (entry.finallyLoc === finallyLoc) {
  591. this.complete(entry.completion, entry.afterLoc);
  592. resetTryEntry(entry);
  593. return ContinueSentinel;
  594. }
  595. }
  596. },
  597. "catch": function _catch(tryLoc) {
  598. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  599. var entry = this.tryEntries[i];
  600. if (entry.tryLoc === tryLoc) {
  601. var record = entry.completion;
  602. if (record.type === "throw") {
  603. var thrown = record.arg;
  604. resetTryEntry(entry);
  605. }
  606. return thrown;
  607. }
  608. } // The context.catch method must only be called with a location
  609. // argument that corresponds to a known catch block.
  610. throw new Error("illegal catch attempt");
  611. },
  612. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  613. this.delegate = {
  614. iterator: values(iterable),
  615. resultName: resultName,
  616. nextLoc: nextLoc
  617. };
  618. if (this.method === "next") {
  619. // Deliberately forget the last sent value so that we don't
  620. // accidentally pass it on to the delegate.
  621. this.arg = undefined$1;
  622. }
  623. return ContinueSentinel;
  624. }
  625. }; // Regardless of whether this script is executing as a CommonJS module
  626. // or not, return the runtime object so that we can declare the variable
  627. // regeneratorRuntime in the outer scope, which allows this module to be
  628. // injected easily by `bin/regenerator --include-runtime script.js`.
  629. return exports;
  630. }( // If this script is executing as a CommonJS module, use module.exports
  631. // as the regeneratorRuntime namespace. Otherwise create a new empty
  632. // object. Either way, the resulting object will be used to initialize
  633. // the regeneratorRuntime variable at the top of this file.
  634. typeof module === "object" ? module.exports : {});
  635. try {
  636. regeneratorRuntime = runtime;
  637. } catch (accidentalStrictMode) {
  638. // This module should not be running in strict mode, so the above
  639. // assignment should always work unless something is misconfigured. Just
  640. // in case runtime.js accidentally runs in strict mode, we can escape
  641. // strict mode using a global Function call. This could conceivably fail
  642. // if a Content Security Policy forbids using Function, but in that case
  643. // the proper solution is to fix the accidental strict mode problem. If
  644. // you've misconfigured your bundler to force strict mode and applied a
  645. // CSP to forbid Function, and you're not willing to fix either of those
  646. // problems, please detail your unique predicament in a GitHub issue.
  647. Function("r", "regeneratorRuntime = r")(runtime);
  648. }
  649. var REVISION = '126dev';
  650. var MOUSE = {
  651. LEFT: 0,
  652. MIDDLE: 1,
  653. RIGHT: 2,
  654. ROTATE: 0,
  655. DOLLY: 1,
  656. PAN: 2
  657. };
  658. var TOUCH = {
  659. ROTATE: 0,
  660. PAN: 1,
  661. DOLLY_PAN: 2,
  662. DOLLY_ROTATE: 3
  663. };
  664. var CullFaceNone = 0;
  665. var CullFaceBack = 1;
  666. var CullFaceFront = 2;
  667. var CullFaceFrontBack = 3;
  668. var BasicShadowMap = 0;
  669. var PCFShadowMap = 1;
  670. var PCFSoftShadowMap = 2;
  671. var VSMShadowMap = 3;
  672. var FrontSide = 0;
  673. var BackSide = 1;
  674. var DoubleSide = 2;
  675. var FlatShading = 1;
  676. var SmoothShading = 2;
  677. var NoBlending = 0;
  678. var NormalBlending = 1;
  679. var AdditiveBlending = 2;
  680. var SubtractiveBlending = 3;
  681. var MultiplyBlending = 4;
  682. var CustomBlending = 5;
  683. var AddEquation = 100;
  684. var SubtractEquation = 101;
  685. var ReverseSubtractEquation = 102;
  686. var MinEquation = 103;
  687. var MaxEquation = 104;
  688. var ZeroFactor = 200;
  689. var OneFactor = 201;
  690. var SrcColorFactor = 202;
  691. var OneMinusSrcColorFactor = 203;
  692. var SrcAlphaFactor = 204;
  693. var OneMinusSrcAlphaFactor = 205;
  694. var DstAlphaFactor = 206;
  695. var OneMinusDstAlphaFactor = 207;
  696. var DstColorFactor = 208;
  697. var OneMinusDstColorFactor = 209;
  698. var SrcAlphaSaturateFactor = 210;
  699. var NeverDepth = 0;
  700. var AlwaysDepth = 1;
  701. var LessDepth = 2;
  702. var LessEqualDepth = 3;
  703. var EqualDepth = 4;
  704. var GreaterEqualDepth = 5;
  705. var GreaterDepth = 6;
  706. var NotEqualDepth = 7;
  707. var MultiplyOperation = 0;
  708. var MixOperation = 1;
  709. var AddOperation = 2;
  710. var NoToneMapping = 0;
  711. var LinearToneMapping = 1;
  712. var ReinhardToneMapping = 2;
  713. var CineonToneMapping = 3;
  714. var ACESFilmicToneMapping = 4;
  715. var CustomToneMapping = 5;
  716. var UVMapping = 300;
  717. var CubeReflectionMapping = 301;
  718. var CubeRefractionMapping = 302;
  719. var EquirectangularReflectionMapping = 303;
  720. var EquirectangularRefractionMapping = 304;
  721. var CubeUVReflectionMapping = 306;
  722. var CubeUVRefractionMapping = 307;
  723. var RepeatWrapping = 1000;
  724. var ClampToEdgeWrapping = 1001;
  725. var MirroredRepeatWrapping = 1002;
  726. var NearestFilter = 1003;
  727. var NearestMipmapNearestFilter = 1004;
  728. var NearestMipMapNearestFilter = 1004;
  729. var NearestMipmapLinearFilter = 1005;
  730. var NearestMipMapLinearFilter = 1005;
  731. var LinearFilter = 1006;
  732. var LinearMipmapNearestFilter = 1007;
  733. var LinearMipMapNearestFilter = 1007;
  734. var LinearMipmapLinearFilter = 1008;
  735. var LinearMipMapLinearFilter = 1008;
  736. var UnsignedByteType = 1009;
  737. var ByteType = 1010;
  738. var ShortType = 1011;
  739. var UnsignedShortType = 1012;
  740. var IntType = 1013;
  741. var UnsignedIntType = 1014;
  742. var FloatType = 1015;
  743. var HalfFloatType = 1016;
  744. var UnsignedShort4444Type = 1017;
  745. var UnsignedShort5551Type = 1018;
  746. var UnsignedShort565Type = 1019;
  747. var UnsignedInt248Type = 1020;
  748. var AlphaFormat = 1021;
  749. var RGBFormat = 1022;
  750. var RGBAFormat = 1023;
  751. var LuminanceFormat = 1024;
  752. var LuminanceAlphaFormat = 1025;
  753. var RGBEFormat = RGBAFormat;
  754. var DepthFormat = 1026;
  755. var DepthStencilFormat = 1027;
  756. var RedFormat = 1028;
  757. var RedIntegerFormat = 1029;
  758. var RGFormat = 1030;
  759. var RGIntegerFormat = 1031;
  760. var RGBIntegerFormat = 1032;
  761. var RGBAIntegerFormat = 1033;
  762. var RGB_S3TC_DXT1_Format = 33776;
  763. var RGBA_S3TC_DXT1_Format = 33777;
  764. var RGBA_S3TC_DXT3_Format = 33778;
  765. var RGBA_S3TC_DXT5_Format = 33779;
  766. var RGB_PVRTC_4BPPV1_Format = 35840;
  767. var RGB_PVRTC_2BPPV1_Format = 35841;
  768. var RGBA_PVRTC_4BPPV1_Format = 35842;
  769. var RGBA_PVRTC_2BPPV1_Format = 35843;
  770. var RGB_ETC1_Format = 36196;
  771. var RGB_ETC2_Format = 37492;
  772. var RGBA_ETC2_EAC_Format = 37496;
  773. var RGBA_ASTC_4x4_Format = 37808;
  774. var RGBA_ASTC_5x4_Format = 37809;
  775. var RGBA_ASTC_5x5_Format = 37810;
  776. var RGBA_ASTC_6x5_Format = 37811;
  777. var RGBA_ASTC_6x6_Format = 37812;
  778. var RGBA_ASTC_8x5_Format = 37813;
  779. var RGBA_ASTC_8x6_Format = 37814;
  780. var RGBA_ASTC_8x8_Format = 37815;
  781. var RGBA_ASTC_10x5_Format = 37816;
  782. var RGBA_ASTC_10x6_Format = 37817;
  783. var RGBA_ASTC_10x8_Format = 37818;
  784. var RGBA_ASTC_10x10_Format = 37819;
  785. var RGBA_ASTC_12x10_Format = 37820;
  786. var RGBA_ASTC_12x12_Format = 37821;
  787. var RGBA_BPTC_Format = 36492;
  788. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  789. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  790. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  791. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  792. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  793. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  794. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  795. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  796. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  797. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  798. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  799. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  800. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  801. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  802. var LoopOnce = 2200;
  803. var LoopRepeat = 2201;
  804. var LoopPingPong = 2202;
  805. var InterpolateDiscrete = 2300;
  806. var InterpolateLinear = 2301;
  807. var InterpolateSmooth = 2302;
  808. var ZeroCurvatureEnding = 2400;
  809. var ZeroSlopeEnding = 2401;
  810. var WrapAroundEnding = 2402;
  811. var NormalAnimationBlendMode = 2500;
  812. var AdditiveAnimationBlendMode = 2501;
  813. var TrianglesDrawMode = 0;
  814. var TriangleStripDrawMode = 1;
  815. var TriangleFanDrawMode = 2;
  816. var LinearEncoding = 3000;
  817. var sRGBEncoding = 3001;
  818. var GammaEncoding = 3007;
  819. var RGBEEncoding = 3002;
  820. var LogLuvEncoding = 3003;
  821. var RGBM7Encoding = 3004;
  822. var RGBM16Encoding = 3005;
  823. var RGBDEncoding = 3006;
  824. var BasicDepthPacking = 3200;
  825. var RGBADepthPacking = 3201;
  826. var TangentSpaceNormalMap = 0;
  827. var ObjectSpaceNormalMap = 1;
  828. var ZeroStencilOp = 0;
  829. var KeepStencilOp = 7680;
  830. var ReplaceStencilOp = 7681;
  831. var IncrementStencilOp = 7682;
  832. var DecrementStencilOp = 7683;
  833. var IncrementWrapStencilOp = 34055;
  834. var DecrementWrapStencilOp = 34056;
  835. var InvertStencilOp = 5386;
  836. var NeverStencilFunc = 512;
  837. var LessStencilFunc = 513;
  838. var EqualStencilFunc = 514;
  839. var LessEqualStencilFunc = 515;
  840. var GreaterStencilFunc = 516;
  841. var NotEqualStencilFunc = 517;
  842. var GreaterEqualStencilFunc = 518;
  843. var AlwaysStencilFunc = 519;
  844. var StaticDrawUsage = 35044;
  845. var DynamicDrawUsage = 35048;
  846. var StreamDrawUsage = 35040;
  847. var StaticReadUsage = 35045;
  848. var DynamicReadUsage = 35049;
  849. var StreamReadUsage = 35041;
  850. var StaticCopyUsage = 35046;
  851. var DynamicCopyUsage = 35050;
  852. var StreamCopyUsage = 35042;
  853. var GLSL1 = '100';
  854. var GLSL3 = '300 es';
  855. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  856. try {
  857. var info = gen[key](arg);
  858. var value = info.value;
  859. } catch (error) {
  860. reject(error);
  861. return;
  862. }
  863. if (info.done) {
  864. resolve(value);
  865. } else {
  866. Promise.resolve(value).then(_next, _throw);
  867. }
  868. }
  869. function _asyncToGenerator(fn) {
  870. return function () {
  871. var self = this,
  872. args = arguments;
  873. return new Promise(function (resolve, reject) {
  874. var gen = fn.apply(self, args);
  875. function _next(value) {
  876. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  877. }
  878. function _throw(err) {
  879. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  880. }
  881. _next(undefined);
  882. });
  883. };
  884. }
  885. function _defineProperties(target, props) {
  886. for (var i = 0; i < props.length; i++) {
  887. var descriptor = props[i];
  888. descriptor.enumerable = descriptor.enumerable || false;
  889. descriptor.configurable = true;
  890. if ("value" in descriptor) descriptor.writable = true;
  891. Object.defineProperty(target, descriptor.key, descriptor);
  892. }
  893. }
  894. function _createClass(Constructor, protoProps, staticProps) {
  895. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  896. if (staticProps) _defineProperties(Constructor, staticProps);
  897. return Constructor;
  898. }
  899. function _inheritsLoose(subClass, superClass) {
  900. subClass.prototype = Object.create(superClass.prototype);
  901. subClass.prototype.constructor = subClass;
  902. subClass.__proto__ = superClass;
  903. }
  904. function _assertThisInitialized(self) {
  905. if (self === void 0) {
  906. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  907. }
  908. return self;
  909. }
  910. function _unsupportedIterableToArray(o, minLen) {
  911. if (!o) return;
  912. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  913. var n = Object.prototype.toString.call(o).slice(8, -1);
  914. if (n === "Object" && o.constructor) n = o.constructor.name;
  915. if (n === "Map" || n === "Set") return Array.from(o);
  916. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  917. }
  918. function _arrayLikeToArray(arr, len) {
  919. if (len == null || len > arr.length) len = arr.length;
  920. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  921. return arr2;
  922. }
  923. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  924. var it;
  925. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  926. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  927. if (it) o = it;
  928. var i = 0;
  929. return function () {
  930. if (i >= o.length) return {
  931. done: true
  932. };
  933. return {
  934. done: false,
  935. value: o[i++]
  936. };
  937. };
  938. }
  939. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  940. }
  941. it = o[Symbol.iterator]();
  942. return it.next.bind(it);
  943. }
  944. /**
  945. * https://github.com/mrdoob/eventdispatcher.js/
  946. */
  947. function EventDispatcher() {}
  948. Object.assign(EventDispatcher.prototype, {
  949. addEventListener: function addEventListener(type, listener) {
  950. if (this._listeners === undefined) this._listeners = {};
  951. var listeners = this._listeners;
  952. if (listeners[type] === undefined) {
  953. listeners[type] = [];
  954. }
  955. if (listeners[type].indexOf(listener) === -1) {
  956. listeners[type].push(listener);
  957. }
  958. },
  959. hasEventListener: function hasEventListener(type, listener) {
  960. if (this._listeners === undefined) return false;
  961. var listeners = this._listeners;
  962. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  963. },
  964. removeEventListener: function removeEventListener(type, listener) {
  965. if (this._listeners === undefined) return;
  966. var listeners = this._listeners;
  967. var listenerArray = listeners[type];
  968. if (listenerArray !== undefined) {
  969. var index = listenerArray.indexOf(listener);
  970. if (index !== -1) {
  971. listenerArray.splice(index, 1);
  972. }
  973. }
  974. },
  975. dispatchEvent: function dispatchEvent(event) {
  976. if (this._listeners === undefined) return;
  977. var listeners = this._listeners;
  978. var listenerArray = listeners[event.type];
  979. if (listenerArray !== undefined) {
  980. event.target = this; // Make a copy, in case listeners are removed while iterating.
  981. var array = listenerArray.slice(0);
  982. for (var i = 0, l = array.length; i < l; i++) {
  983. array[i].call(this, event);
  984. }
  985. }
  986. }
  987. });
  988. var _lut = [];
  989. for (var i = 0; i < 256; i++) {
  990. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  991. }
  992. var _seed = 1234567;
  993. var MathUtils = {
  994. DEG2RAD: Math.PI / 180,
  995. RAD2DEG: 180 / Math.PI,
  996. generateUUID: function generateUUID() {
  997. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  998. var d0 = Math.random() * 0xffffffff | 0;
  999. var d1 = Math.random() * 0xffffffff | 0;
  1000. var d2 = Math.random() * 0xffffffff | 0;
  1001. var d3 = Math.random() * 0xffffffff | 0;
  1002. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  1003. return uuid.toUpperCase();
  1004. },
  1005. clamp: function clamp(value, min, max) {
  1006. return Math.max(min, Math.min(max, value));
  1007. },
  1008. // compute euclidian modulo of m % n
  1009. // https://en.wikipedia.org/wiki/Modulo_operation
  1010. euclideanModulo: function euclideanModulo(n, m) {
  1011. return (n % m + m) % m;
  1012. },
  1013. // Linear mapping from range <a1, a2> to range <b1, b2>
  1014. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  1015. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  1016. },
  1017. // https://en.wikipedia.org/wiki/Linear_interpolation
  1018. lerp: function lerp(x, y, t) {
  1019. return (1 - t) * x + t * y;
  1020. },
  1021. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  1022. damp: function damp(x, y, lambda, dt) {
  1023. return MathUtils.lerp(x, y, 1 - Math.exp(-lambda * dt));
  1024. },
  1025. // https://www.desmos.com/calculator/vcsjnyz7x4
  1026. pingpong: function pingpong(x, length) {
  1027. if (length === void 0) {
  1028. length = 1;
  1029. }
  1030. return length - Math.abs(MathUtils.euclideanModulo(x, length * 2) - length);
  1031. },
  1032. // http://en.wikipedia.org/wiki/Smoothstep
  1033. smoothstep: function smoothstep(x, min, max) {
  1034. if (x <= min) return 0;
  1035. if (x >= max) return 1;
  1036. x = (x - min) / (max - min);
  1037. return x * x * (3 - 2 * x);
  1038. },
  1039. smootherstep: function smootherstep(x, min, max) {
  1040. if (x <= min) return 0;
  1041. if (x >= max) return 1;
  1042. x = (x - min) / (max - min);
  1043. return x * x * x * (x * (x * 6 - 15) + 10);
  1044. },
  1045. // Random integer from <low, high> interval
  1046. randInt: function randInt(low, high) {
  1047. return low + Math.floor(Math.random() * (high - low + 1));
  1048. },
  1049. // Random float from <low, high> interval
  1050. randFloat: function randFloat(low, high) {
  1051. return low + Math.random() * (high - low);
  1052. },
  1053. // Random float from <-range/2, range/2> interval
  1054. randFloatSpread: function randFloatSpread(range) {
  1055. return range * (0.5 - Math.random());
  1056. },
  1057. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  1058. seededRandom: function seededRandom(s) {
  1059. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  1060. _seed = _seed * 16807 % 2147483647;
  1061. return (_seed - 1) / 2147483646;
  1062. },
  1063. degToRad: function degToRad(degrees) {
  1064. return degrees * MathUtils.DEG2RAD;
  1065. },
  1066. radToDeg: function radToDeg(radians) {
  1067. return radians * MathUtils.RAD2DEG;
  1068. },
  1069. isPowerOfTwo: function isPowerOfTwo(value) {
  1070. return (value & value - 1) === 0 && value !== 0;
  1071. },
  1072. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  1073. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  1074. },
  1075. floorPowerOfTwo: function floorPowerOfTwo(value) {
  1076. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  1077. },
  1078. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  1079. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  1080. // rotations are applied to the axes in the order specified by 'order'
  1081. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  1082. // angles are in radians
  1083. var cos = Math.cos;
  1084. var sin = Math.sin;
  1085. var c2 = cos(b / 2);
  1086. var s2 = sin(b / 2);
  1087. var c13 = cos((a + c) / 2);
  1088. var s13 = sin((a + c) / 2);
  1089. var c1_3 = cos((a - c) / 2);
  1090. var s1_3 = sin((a - c) / 2);
  1091. var c3_1 = cos((c - a) / 2);
  1092. var s3_1 = sin((c - a) / 2);
  1093. switch (order) {
  1094. case 'XYX':
  1095. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  1096. break;
  1097. case 'YZY':
  1098. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  1099. break;
  1100. case 'ZXZ':
  1101. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  1102. break;
  1103. case 'XZX':
  1104. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  1105. break;
  1106. case 'YXY':
  1107. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  1108. break;
  1109. case 'ZYZ':
  1110. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  1111. break;
  1112. default:
  1113. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  1114. }
  1115. }
  1116. };
  1117. var Vector2 = /*#__PURE__*/function () {
  1118. function Vector2(x, y) {
  1119. if (x === void 0) {
  1120. x = 0;
  1121. }
  1122. if (y === void 0) {
  1123. y = 0;
  1124. }
  1125. Object.defineProperty(this, 'isVector2', {
  1126. value: true
  1127. });
  1128. this.x = x;
  1129. this.y = y;
  1130. }
  1131. var _proto = Vector2.prototype;
  1132. _proto.set = function set(x, y) {
  1133. this.x = x;
  1134. this.y = y;
  1135. return this;
  1136. };
  1137. _proto.setScalar = function setScalar(scalar) {
  1138. this.x = scalar;
  1139. this.y = scalar;
  1140. return this;
  1141. };
  1142. _proto.setX = function setX(x) {
  1143. this.x = x;
  1144. return this;
  1145. };
  1146. _proto.setY = function setY(y) {
  1147. this.y = y;
  1148. return this;
  1149. };
  1150. _proto.setComponent = function setComponent(index, value) {
  1151. switch (index) {
  1152. case 0:
  1153. this.x = value;
  1154. break;
  1155. case 1:
  1156. this.y = value;
  1157. break;
  1158. default:
  1159. throw new Error('index is out of range: ' + index);
  1160. }
  1161. return this;
  1162. };
  1163. _proto.getComponent = function getComponent(index) {
  1164. switch (index) {
  1165. case 0:
  1166. return this.x;
  1167. case 1:
  1168. return this.y;
  1169. default:
  1170. throw new Error('index is out of range: ' + index);
  1171. }
  1172. };
  1173. _proto.clone = function clone() {
  1174. return new this.constructor(this.x, this.y);
  1175. };
  1176. _proto.copy = function copy(v) {
  1177. this.x = v.x;
  1178. this.y = v.y;
  1179. return this;
  1180. };
  1181. _proto.add = function add(v, w) {
  1182. if (w !== undefined) {
  1183. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1184. return this.addVectors(v, w);
  1185. }
  1186. this.x += v.x;
  1187. this.y += v.y;
  1188. return this;
  1189. };
  1190. _proto.addScalar = function addScalar(s) {
  1191. this.x += s;
  1192. this.y += s;
  1193. return this;
  1194. };
  1195. _proto.addVectors = function addVectors(a, b) {
  1196. this.x = a.x + b.x;
  1197. this.y = a.y + b.y;
  1198. return this;
  1199. };
  1200. _proto.addScaledVector = function addScaledVector(v, s) {
  1201. this.x += v.x * s;
  1202. this.y += v.y * s;
  1203. return this;
  1204. };
  1205. _proto.sub = function sub(v, w) {
  1206. if (w !== undefined) {
  1207. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1208. return this.subVectors(v, w);
  1209. }
  1210. this.x -= v.x;
  1211. this.y -= v.y;
  1212. return this;
  1213. };
  1214. _proto.subScalar = function subScalar(s) {
  1215. this.x -= s;
  1216. this.y -= s;
  1217. return this;
  1218. };
  1219. _proto.subVectors = function subVectors(a, b) {
  1220. this.x = a.x - b.x;
  1221. this.y = a.y - b.y;
  1222. return this;
  1223. };
  1224. _proto.multiply = function multiply(v) {
  1225. this.x *= v.x;
  1226. this.y *= v.y;
  1227. return this;
  1228. };
  1229. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1230. this.x *= scalar;
  1231. this.y *= scalar;
  1232. return this;
  1233. };
  1234. _proto.divide = function divide(v) {
  1235. this.x /= v.x;
  1236. this.y /= v.y;
  1237. return this;
  1238. };
  1239. _proto.divideScalar = function divideScalar(scalar) {
  1240. return this.multiplyScalar(1 / scalar);
  1241. };
  1242. _proto.applyMatrix3 = function applyMatrix3(m) {
  1243. var x = this.x,
  1244. y = this.y;
  1245. var e = m.elements;
  1246. this.x = e[0] * x + e[3] * y + e[6];
  1247. this.y = e[1] * x + e[4] * y + e[7];
  1248. return this;
  1249. };
  1250. _proto.min = function min(v) {
  1251. this.x = Math.min(this.x, v.x);
  1252. this.y = Math.min(this.y, v.y);
  1253. return this;
  1254. };
  1255. _proto.max = function max(v) {
  1256. this.x = Math.max(this.x, v.x);
  1257. this.y = Math.max(this.y, v.y);
  1258. return this;
  1259. };
  1260. _proto.clamp = function clamp(min, max) {
  1261. // assumes min < max, componentwise
  1262. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1263. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1264. return this;
  1265. };
  1266. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1267. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1268. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1269. return this;
  1270. };
  1271. _proto.clampLength = function clampLength(min, max) {
  1272. var length = this.length();
  1273. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1274. };
  1275. _proto.floor = function floor() {
  1276. this.x = Math.floor(this.x);
  1277. this.y = Math.floor(this.y);
  1278. return this;
  1279. };
  1280. _proto.ceil = function ceil() {
  1281. this.x = Math.ceil(this.x);
  1282. this.y = Math.ceil(this.y);
  1283. return this;
  1284. };
  1285. _proto.round = function round() {
  1286. this.x = Math.round(this.x);
  1287. this.y = Math.round(this.y);
  1288. return this;
  1289. };
  1290. _proto.roundToZero = function roundToZero() {
  1291. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1292. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1293. return this;
  1294. };
  1295. _proto.negate = function negate() {
  1296. this.x = -this.x;
  1297. this.y = -this.y;
  1298. return this;
  1299. };
  1300. _proto.dot = function dot(v) {
  1301. return this.x * v.x + this.y * v.y;
  1302. };
  1303. _proto.cross = function cross(v) {
  1304. return this.x * v.y - this.y * v.x;
  1305. };
  1306. _proto.lengthSq = function lengthSq() {
  1307. return this.x * this.x + this.y * this.y;
  1308. };
  1309. _proto.length = function length() {
  1310. return Math.sqrt(this.x * this.x + this.y * this.y);
  1311. };
  1312. _proto.manhattanLength = function manhattanLength() {
  1313. return Math.abs(this.x) + Math.abs(this.y);
  1314. };
  1315. _proto.normalize = function normalize() {
  1316. return this.divideScalar(this.length() || 1);
  1317. };
  1318. _proto.angle = function angle() {
  1319. // computes the angle in radians with respect to the positive x-axis
  1320. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  1321. return angle;
  1322. };
  1323. _proto.distanceTo = function distanceTo(v) {
  1324. return Math.sqrt(this.distanceToSquared(v));
  1325. };
  1326. _proto.distanceToSquared = function distanceToSquared(v) {
  1327. var dx = this.x - v.x,
  1328. dy = this.y - v.y;
  1329. return dx * dx + dy * dy;
  1330. };
  1331. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  1332. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  1333. };
  1334. _proto.setLength = function setLength(length) {
  1335. return this.normalize().multiplyScalar(length);
  1336. };
  1337. _proto.lerp = function lerp(v, alpha) {
  1338. this.x += (v.x - this.x) * alpha;
  1339. this.y += (v.y - this.y) * alpha;
  1340. return this;
  1341. };
  1342. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1343. this.x = v1.x + (v2.x - v1.x) * alpha;
  1344. this.y = v1.y + (v2.y - v1.y) * alpha;
  1345. return this;
  1346. };
  1347. _proto.equals = function equals(v) {
  1348. return v.x === this.x && v.y === this.y;
  1349. };
  1350. _proto.fromArray = function fromArray(array, offset) {
  1351. if (offset === void 0) {
  1352. offset = 0;
  1353. }
  1354. this.x = array[offset];
  1355. this.y = array[offset + 1];
  1356. return this;
  1357. };
  1358. _proto.toArray = function toArray(array, offset) {
  1359. if (array === void 0) {
  1360. array = [];
  1361. }
  1362. if (offset === void 0) {
  1363. offset = 0;
  1364. }
  1365. array[offset] = this.x;
  1366. array[offset + 1] = this.y;
  1367. return array;
  1368. };
  1369. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1370. if (offset !== undefined) {
  1371. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  1372. }
  1373. this.x = attribute.getX(index);
  1374. this.y = attribute.getY(index);
  1375. return this;
  1376. };
  1377. _proto.rotateAround = function rotateAround(center, angle) {
  1378. var c = Math.cos(angle),
  1379. s = Math.sin(angle);
  1380. var x = this.x - center.x;
  1381. var y = this.y - center.y;
  1382. this.x = x * c - y * s + center.x;
  1383. this.y = x * s + y * c + center.y;
  1384. return this;
  1385. };
  1386. _proto.random = function random() {
  1387. this.x = Math.random();
  1388. this.y = Math.random();
  1389. return this;
  1390. };
  1391. _createClass(Vector2, [{
  1392. key: "width",
  1393. get: function get() {
  1394. return this.x;
  1395. },
  1396. set: function set(value) {
  1397. this.x = value;
  1398. }
  1399. }, {
  1400. key: "height",
  1401. get: function get() {
  1402. return this.y;
  1403. },
  1404. set: function set(value) {
  1405. this.y = value;
  1406. }
  1407. }]);
  1408. return Vector2;
  1409. }();
  1410. var Matrix3 = /*#__PURE__*/function () {
  1411. function Matrix3() {
  1412. Object.defineProperty(this, 'isMatrix3', {
  1413. value: true
  1414. });
  1415. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  1416. if (arguments.length > 0) {
  1417. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  1418. }
  1419. }
  1420. var _proto = Matrix3.prototype;
  1421. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  1422. var te = this.elements;
  1423. te[0] = n11;
  1424. te[1] = n21;
  1425. te[2] = n31;
  1426. te[3] = n12;
  1427. te[4] = n22;
  1428. te[5] = n32;
  1429. te[6] = n13;
  1430. te[7] = n23;
  1431. te[8] = n33;
  1432. return this;
  1433. };
  1434. _proto.identity = function identity() {
  1435. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  1436. return this;
  1437. };
  1438. _proto.clone = function clone() {
  1439. return new this.constructor().fromArray(this.elements);
  1440. };
  1441. _proto.copy = function copy(m) {
  1442. var te = this.elements;
  1443. var me = m.elements;
  1444. te[0] = me[0];
  1445. te[1] = me[1];
  1446. te[2] = me[2];
  1447. te[3] = me[3];
  1448. te[4] = me[4];
  1449. te[5] = me[5];
  1450. te[6] = me[6];
  1451. te[7] = me[7];
  1452. te[8] = me[8];
  1453. return this;
  1454. };
  1455. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  1456. xAxis.setFromMatrix3Column(this, 0);
  1457. yAxis.setFromMatrix3Column(this, 1);
  1458. zAxis.setFromMatrix3Column(this, 2);
  1459. return this;
  1460. };
  1461. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  1462. var me = m.elements;
  1463. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  1464. return this;
  1465. };
  1466. _proto.multiply = function multiply(m) {
  1467. return this.multiplyMatrices(this, m);
  1468. };
  1469. _proto.premultiply = function premultiply(m) {
  1470. return this.multiplyMatrices(m, this);
  1471. };
  1472. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  1473. var ae = a.elements;
  1474. var be = b.elements;
  1475. var te = this.elements;
  1476. var a11 = ae[0],
  1477. a12 = ae[3],
  1478. a13 = ae[6];
  1479. var a21 = ae[1],
  1480. a22 = ae[4],
  1481. a23 = ae[7];
  1482. var a31 = ae[2],
  1483. a32 = ae[5],
  1484. a33 = ae[8];
  1485. var b11 = be[0],
  1486. b12 = be[3],
  1487. b13 = be[6];
  1488. var b21 = be[1],
  1489. b22 = be[4],
  1490. b23 = be[7];
  1491. var b31 = be[2],
  1492. b32 = be[5],
  1493. b33 = be[8];
  1494. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  1495. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  1496. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  1497. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  1498. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  1499. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  1500. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  1501. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  1502. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  1503. return this;
  1504. };
  1505. _proto.multiplyScalar = function multiplyScalar(s) {
  1506. var te = this.elements;
  1507. te[0] *= s;
  1508. te[3] *= s;
  1509. te[6] *= s;
  1510. te[1] *= s;
  1511. te[4] *= s;
  1512. te[7] *= s;
  1513. te[2] *= s;
  1514. te[5] *= s;
  1515. te[8] *= s;
  1516. return this;
  1517. };
  1518. _proto.determinant = function determinant() {
  1519. var te = this.elements;
  1520. var a = te[0],
  1521. b = te[1],
  1522. c = te[2],
  1523. d = te[3],
  1524. e = te[4],
  1525. f = te[5],
  1526. g = te[6],
  1527. h = te[7],
  1528. i = te[8];
  1529. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1530. };
  1531. _proto.invert = function invert() {
  1532. var te = this.elements,
  1533. n11 = te[0],
  1534. n21 = te[1],
  1535. n31 = te[2],
  1536. n12 = te[3],
  1537. n22 = te[4],
  1538. n32 = te[5],
  1539. n13 = te[6],
  1540. n23 = te[7],
  1541. n33 = te[8],
  1542. t11 = n33 * n22 - n32 * n23,
  1543. t12 = n32 * n13 - n33 * n12,
  1544. t13 = n23 * n12 - n22 * n13,
  1545. det = n11 * t11 + n21 * t12 + n31 * t13;
  1546. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  1547. var detInv = 1 / det;
  1548. te[0] = t11 * detInv;
  1549. te[1] = (n31 * n23 - n33 * n21) * detInv;
  1550. te[2] = (n32 * n21 - n31 * n22) * detInv;
  1551. te[3] = t12 * detInv;
  1552. te[4] = (n33 * n11 - n31 * n13) * detInv;
  1553. te[5] = (n31 * n12 - n32 * n11) * detInv;
  1554. te[6] = t13 * detInv;
  1555. te[7] = (n21 * n13 - n23 * n11) * detInv;
  1556. te[8] = (n22 * n11 - n21 * n12) * detInv;
  1557. return this;
  1558. };
  1559. _proto.transpose = function transpose() {
  1560. var tmp;
  1561. var m = this.elements;
  1562. tmp = m[1];
  1563. m[1] = m[3];
  1564. m[3] = tmp;
  1565. tmp = m[2];
  1566. m[2] = m[6];
  1567. m[6] = tmp;
  1568. tmp = m[5];
  1569. m[5] = m[7];
  1570. m[7] = tmp;
  1571. return this;
  1572. };
  1573. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  1574. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  1575. };
  1576. _proto.transposeIntoArray = function transposeIntoArray(r) {
  1577. var m = this.elements;
  1578. r[0] = m[0];
  1579. r[1] = m[3];
  1580. r[2] = m[6];
  1581. r[3] = m[1];
  1582. r[4] = m[4];
  1583. r[5] = m[7];
  1584. r[6] = m[2];
  1585. r[7] = m[5];
  1586. r[8] = m[8];
  1587. return this;
  1588. };
  1589. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  1590. var c = Math.cos(rotation);
  1591. var s = Math.sin(rotation);
  1592. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  1593. return this;
  1594. };
  1595. _proto.scale = function scale(sx, sy) {
  1596. var te = this.elements;
  1597. te[0] *= sx;
  1598. te[3] *= sx;
  1599. te[6] *= sx;
  1600. te[1] *= sy;
  1601. te[4] *= sy;
  1602. te[7] *= sy;
  1603. return this;
  1604. };
  1605. _proto.rotate = function rotate(theta) {
  1606. var c = Math.cos(theta);
  1607. var s = Math.sin(theta);
  1608. var te = this.elements;
  1609. var a11 = te[0],
  1610. a12 = te[3],
  1611. a13 = te[6];
  1612. var a21 = te[1],
  1613. a22 = te[4],
  1614. a23 = te[7];
  1615. te[0] = c * a11 + s * a21;
  1616. te[3] = c * a12 + s * a22;
  1617. te[6] = c * a13 + s * a23;
  1618. te[1] = -s * a11 + c * a21;
  1619. te[4] = -s * a12 + c * a22;
  1620. te[7] = -s * a13 + c * a23;
  1621. return this;
  1622. };
  1623. _proto.translate = function translate(tx, ty) {
  1624. var te = this.elements;
  1625. te[0] += tx * te[2];
  1626. te[3] += tx * te[5];
  1627. te[6] += tx * te[8];
  1628. te[1] += ty * te[2];
  1629. te[4] += ty * te[5];
  1630. te[7] += ty * te[8];
  1631. return this;
  1632. };
  1633. _proto.equals = function equals(matrix) {
  1634. var te = this.elements;
  1635. var me = matrix.elements;
  1636. for (var i = 0; i < 9; i++) {
  1637. if (te[i] !== me[i]) return false;
  1638. }
  1639. return true;
  1640. };
  1641. _proto.fromArray = function fromArray(array, offset) {
  1642. if (offset === void 0) {
  1643. offset = 0;
  1644. }
  1645. for (var i = 0; i < 9; i++) {
  1646. this.elements[i] = array[i + offset];
  1647. }
  1648. return this;
  1649. };
  1650. _proto.toArray = function toArray(array, offset) {
  1651. if (array === void 0) {
  1652. array = [];
  1653. }
  1654. if (offset === void 0) {
  1655. offset = 0;
  1656. }
  1657. var te = this.elements;
  1658. array[offset] = te[0];
  1659. array[offset + 1] = te[1];
  1660. array[offset + 2] = te[2];
  1661. array[offset + 3] = te[3];
  1662. array[offset + 4] = te[4];
  1663. array[offset + 5] = te[5];
  1664. array[offset + 6] = te[6];
  1665. array[offset + 7] = te[7];
  1666. array[offset + 8] = te[8];
  1667. return array;
  1668. };
  1669. return Matrix3;
  1670. }();
  1671. var _canvas;
  1672. var ImageUtils = {
  1673. getDataURL: function getDataURL(image) {
  1674. if (/^data:/i.test(image.src)) {
  1675. return image.src;
  1676. }
  1677. if (typeof HTMLCanvasElement == 'undefined') {
  1678. return image.src;
  1679. }
  1680. var canvas;
  1681. if (image instanceof HTMLCanvasElement) {
  1682. canvas = image;
  1683. } else {
  1684. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1685. _canvas.width = image.width;
  1686. _canvas.height = image.height;
  1687. var context = _canvas.getContext('2d');
  1688. if (image instanceof ImageData) {
  1689. context.putImageData(image, 0, 0);
  1690. } else {
  1691. context.drawImage(image, 0, 0, image.width, image.height);
  1692. }
  1693. canvas = _canvas;
  1694. }
  1695. if (canvas.width > 2048 || canvas.height > 2048) {
  1696. return canvas.toDataURL('image/jpeg', 0.6);
  1697. } else {
  1698. return canvas.toDataURL('image/png');
  1699. }
  1700. }
  1701. };
  1702. var textureId = 0;
  1703. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1704. if (image === void 0) {
  1705. image = Texture.DEFAULT_IMAGE;
  1706. }
  1707. if (mapping === void 0) {
  1708. mapping = Texture.DEFAULT_MAPPING;
  1709. }
  1710. if (wrapS === void 0) {
  1711. wrapS = ClampToEdgeWrapping;
  1712. }
  1713. if (wrapT === void 0) {
  1714. wrapT = ClampToEdgeWrapping;
  1715. }
  1716. if (magFilter === void 0) {
  1717. magFilter = LinearFilter;
  1718. }
  1719. if (minFilter === void 0) {
  1720. minFilter = LinearMipmapLinearFilter;
  1721. }
  1722. if (format === void 0) {
  1723. format = RGBAFormat;
  1724. }
  1725. if (type === void 0) {
  1726. type = UnsignedByteType;
  1727. }
  1728. if (anisotropy === void 0) {
  1729. anisotropy = 1;
  1730. }
  1731. if (encoding === void 0) {
  1732. encoding = LinearEncoding;
  1733. }
  1734. Object.defineProperty(this, 'id', {
  1735. value: textureId++
  1736. });
  1737. this.uuid = MathUtils.generateUUID();
  1738. this.name = '';
  1739. this.image = image;
  1740. this.mipmaps = [];
  1741. this.mapping = mapping;
  1742. this.wrapS = wrapS;
  1743. this.wrapT = wrapT;
  1744. this.magFilter = magFilter;
  1745. this.minFilter = minFilter;
  1746. this.anisotropy = anisotropy;
  1747. this.format = format;
  1748. this.internalFormat = null;
  1749. this.type = type;
  1750. this.offset = new Vector2(0, 0);
  1751. this.repeat = new Vector2(1, 1);
  1752. this.center = new Vector2(0, 0);
  1753. this.rotation = 0;
  1754. this.matrixAutoUpdate = true;
  1755. this.matrix = new Matrix3();
  1756. this.generateMipmaps = true;
  1757. this.premultiplyAlpha = false;
  1758. this.flipY = true;
  1759. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1760. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1761. //
  1762. // Also changing the encoding after already used by a Material will not automatically make the Material
  1763. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1764. this.encoding = encoding;
  1765. this.version = 0;
  1766. this.onUpdate = null;
  1767. }
  1768. Texture.DEFAULT_IMAGE = undefined;
  1769. Texture.DEFAULT_MAPPING = UVMapping;
  1770. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1771. constructor: Texture,
  1772. isTexture: true,
  1773. updateMatrix: function updateMatrix() {
  1774. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1775. },
  1776. clone: function clone() {
  1777. return new this.constructor().copy(this);
  1778. },
  1779. copy: function copy(source) {
  1780. this.name = source.name;
  1781. this.image = source.image;
  1782. this.mipmaps = source.mipmaps.slice(0);
  1783. this.mapping = source.mapping;
  1784. this.wrapS = source.wrapS;
  1785. this.wrapT = source.wrapT;
  1786. this.magFilter = source.magFilter;
  1787. this.minFilter = source.minFilter;
  1788. this.anisotropy = source.anisotropy;
  1789. this.format = source.format;
  1790. this.internalFormat = source.internalFormat;
  1791. this.type = source.type;
  1792. this.offset.copy(source.offset);
  1793. this.repeat.copy(source.repeat);
  1794. this.center.copy(source.center);
  1795. this.rotation = source.rotation;
  1796. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1797. this.matrix.copy(source.matrix);
  1798. this.generateMipmaps = source.generateMipmaps;
  1799. this.premultiplyAlpha = source.premultiplyAlpha;
  1800. this.flipY = source.flipY;
  1801. this.unpackAlignment = source.unpackAlignment;
  1802. this.encoding = source.encoding;
  1803. return this;
  1804. },
  1805. toJSON: function toJSON(meta) {
  1806. var isRootObject = meta === undefined || typeof meta === 'string';
  1807. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1808. return meta.textures[this.uuid];
  1809. }
  1810. var output = {
  1811. metadata: {
  1812. version: 4.5,
  1813. type: 'Texture',
  1814. generator: 'Texture.toJSON'
  1815. },
  1816. uuid: this.uuid,
  1817. name: this.name,
  1818. mapping: this.mapping,
  1819. repeat: [this.repeat.x, this.repeat.y],
  1820. offset: [this.offset.x, this.offset.y],
  1821. center: [this.center.x, this.center.y],
  1822. rotation: this.rotation,
  1823. wrap: [this.wrapS, this.wrapT],
  1824. format: this.format,
  1825. type: this.type,
  1826. encoding: this.encoding,
  1827. minFilter: this.minFilter,
  1828. magFilter: this.magFilter,
  1829. anisotropy: this.anisotropy,
  1830. flipY: this.flipY,
  1831. premultiplyAlpha: this.premultiplyAlpha,
  1832. unpackAlignment: this.unpackAlignment
  1833. };
  1834. if (this.image !== undefined) {
  1835. // TODO: Move to THREE.Image
  1836. var image = this.image;
  1837. if (image.uuid === undefined) {
  1838. image.uuid = MathUtils.generateUUID(); // UGH
  1839. }
  1840. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1841. var url;
  1842. if (Array.isArray(image)) {
  1843. // process array of images e.g. CubeTexture
  1844. url = [];
  1845. for (var i = 0, l = image.length; i < l; i++) {
  1846. // check cube texture with data textures
  1847. if (image[i].isDataTexture) {
  1848. url.push(serializeImage(image[i].image));
  1849. } else {
  1850. url.push(serializeImage(image[i]));
  1851. }
  1852. }
  1853. } else {
  1854. // process single image
  1855. url = serializeImage(image);
  1856. }
  1857. meta.images[image.uuid] = {
  1858. uuid: image.uuid,
  1859. url: url
  1860. };
  1861. }
  1862. output.image = image.uuid;
  1863. }
  1864. if (!isRootObject) {
  1865. meta.textures[this.uuid] = output;
  1866. }
  1867. return output;
  1868. },
  1869. dispose: function dispose() {
  1870. this.dispatchEvent({
  1871. type: 'dispose'
  1872. });
  1873. },
  1874. transformUv: function transformUv(uv) {
  1875. if (this.mapping !== UVMapping) return uv;
  1876. uv.applyMatrix3(this.matrix);
  1877. if (uv.x < 0 || uv.x > 1) {
  1878. switch (this.wrapS) {
  1879. case RepeatWrapping:
  1880. uv.x = uv.x - Math.floor(uv.x);
  1881. break;
  1882. case ClampToEdgeWrapping:
  1883. uv.x = uv.x < 0 ? 0 : 1;
  1884. break;
  1885. case MirroredRepeatWrapping:
  1886. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1887. uv.x = Math.ceil(uv.x) - uv.x;
  1888. } else {
  1889. uv.x = uv.x - Math.floor(uv.x);
  1890. }
  1891. break;
  1892. }
  1893. }
  1894. if (uv.y < 0 || uv.y > 1) {
  1895. switch (this.wrapT) {
  1896. case RepeatWrapping:
  1897. uv.y = uv.y - Math.floor(uv.y);
  1898. break;
  1899. case ClampToEdgeWrapping:
  1900. uv.y = uv.y < 0 ? 0 : 1;
  1901. break;
  1902. case MirroredRepeatWrapping:
  1903. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1904. uv.y = Math.ceil(uv.y) - uv.y;
  1905. } else {
  1906. uv.y = uv.y - Math.floor(uv.y);
  1907. }
  1908. break;
  1909. }
  1910. }
  1911. if (this.flipY) {
  1912. uv.y = 1 - uv.y;
  1913. }
  1914. return uv;
  1915. }
  1916. });
  1917. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1918. set: function set(value) {
  1919. if (value === true) this.version++;
  1920. }
  1921. });
  1922. function serializeImage(image) {
  1923. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1924. // default images
  1925. return ImageUtils.getDataURL(image);
  1926. } else {
  1927. if (image.data) {
  1928. // images of DataTexture
  1929. return {
  1930. data: Array.prototype.slice.call(image.data),
  1931. width: image.width,
  1932. height: image.height,
  1933. type: image.data.constructor.name
  1934. };
  1935. } else {
  1936. console.warn('THREE.Texture: Unable to serialize Texture.');
  1937. return {};
  1938. }
  1939. }
  1940. }
  1941. var Vector4 = /*#__PURE__*/function () {
  1942. function Vector4(x, y, z, w) {
  1943. if (x === void 0) {
  1944. x = 0;
  1945. }
  1946. if (y === void 0) {
  1947. y = 0;
  1948. }
  1949. if (z === void 0) {
  1950. z = 0;
  1951. }
  1952. if (w === void 0) {
  1953. w = 1;
  1954. }
  1955. Object.defineProperty(this, 'isVector4', {
  1956. value: true
  1957. });
  1958. this.x = x;
  1959. this.y = y;
  1960. this.z = z;
  1961. this.w = w;
  1962. }
  1963. var _proto = Vector4.prototype;
  1964. _proto.set = function set(x, y, z, w) {
  1965. this.x = x;
  1966. this.y = y;
  1967. this.z = z;
  1968. this.w = w;
  1969. return this;
  1970. };
  1971. _proto.setScalar = function setScalar(scalar) {
  1972. this.x = scalar;
  1973. this.y = scalar;
  1974. this.z = scalar;
  1975. this.w = scalar;
  1976. return this;
  1977. };
  1978. _proto.setX = function setX(x) {
  1979. this.x = x;
  1980. return this;
  1981. };
  1982. _proto.setY = function setY(y) {
  1983. this.y = y;
  1984. return this;
  1985. };
  1986. _proto.setZ = function setZ(z) {
  1987. this.z = z;
  1988. return this;
  1989. };
  1990. _proto.setW = function setW(w) {
  1991. this.w = w;
  1992. return this;
  1993. };
  1994. _proto.setComponent = function setComponent(index, value) {
  1995. switch (index) {
  1996. case 0:
  1997. this.x = value;
  1998. break;
  1999. case 1:
  2000. this.y = value;
  2001. break;
  2002. case 2:
  2003. this.z = value;
  2004. break;
  2005. case 3:
  2006. this.w = value;
  2007. break;
  2008. default:
  2009. throw new Error('index is out of range: ' + index);
  2010. }
  2011. return this;
  2012. };
  2013. _proto.getComponent = function getComponent(index) {
  2014. switch (index) {
  2015. case 0:
  2016. return this.x;
  2017. case 1:
  2018. return this.y;
  2019. case 2:
  2020. return this.z;
  2021. case 3:
  2022. return this.w;
  2023. default:
  2024. throw new Error('index is out of range: ' + index);
  2025. }
  2026. };
  2027. _proto.clone = function clone() {
  2028. return new this.constructor(this.x, this.y, this.z, this.w);
  2029. };
  2030. _proto.copy = function copy(v) {
  2031. this.x = v.x;
  2032. this.y = v.y;
  2033. this.z = v.z;
  2034. this.w = v.w !== undefined ? v.w : 1;
  2035. return this;
  2036. };
  2037. _proto.add = function add(v, w) {
  2038. if (w !== undefined) {
  2039. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2040. return this.addVectors(v, w);
  2041. }
  2042. this.x += v.x;
  2043. this.y += v.y;
  2044. this.z += v.z;
  2045. this.w += v.w;
  2046. return this;
  2047. };
  2048. _proto.addScalar = function addScalar(s) {
  2049. this.x += s;
  2050. this.y += s;
  2051. this.z += s;
  2052. this.w += s;
  2053. return this;
  2054. };
  2055. _proto.addVectors = function addVectors(a, b) {
  2056. this.x = a.x + b.x;
  2057. this.y = a.y + b.y;
  2058. this.z = a.z + b.z;
  2059. this.w = a.w + b.w;
  2060. return this;
  2061. };
  2062. _proto.addScaledVector = function addScaledVector(v, s) {
  2063. this.x += v.x * s;
  2064. this.y += v.y * s;
  2065. this.z += v.z * s;
  2066. this.w += v.w * s;
  2067. return this;
  2068. };
  2069. _proto.sub = function sub(v, w) {
  2070. if (w !== undefined) {
  2071. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2072. return this.subVectors(v, w);
  2073. }
  2074. this.x -= v.x;
  2075. this.y -= v.y;
  2076. this.z -= v.z;
  2077. this.w -= v.w;
  2078. return this;
  2079. };
  2080. _proto.subScalar = function subScalar(s) {
  2081. this.x -= s;
  2082. this.y -= s;
  2083. this.z -= s;
  2084. this.w -= s;
  2085. return this;
  2086. };
  2087. _proto.subVectors = function subVectors(a, b) {
  2088. this.x = a.x - b.x;
  2089. this.y = a.y - b.y;
  2090. this.z = a.z - b.z;
  2091. this.w = a.w - b.w;
  2092. return this;
  2093. };
  2094. _proto.multiply = function multiply(v) {
  2095. this.x *= v.x;
  2096. this.y *= v.y;
  2097. this.z *= v.z;
  2098. this.w *= v.w;
  2099. return this;
  2100. };
  2101. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2102. this.x *= scalar;
  2103. this.y *= scalar;
  2104. this.z *= scalar;
  2105. this.w *= scalar;
  2106. return this;
  2107. };
  2108. _proto.applyMatrix4 = function applyMatrix4(m) {
  2109. var x = this.x,
  2110. y = this.y,
  2111. z = this.z,
  2112. w = this.w;
  2113. var e = m.elements;
  2114. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  2115. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  2116. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  2117. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  2118. return this;
  2119. };
  2120. _proto.divideScalar = function divideScalar(scalar) {
  2121. return this.multiplyScalar(1 / scalar);
  2122. };
  2123. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  2124. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2125. // q is assumed to be normalized
  2126. this.w = 2 * Math.acos(q.w);
  2127. var s = Math.sqrt(1 - q.w * q.w);
  2128. if (s < 0.0001) {
  2129. this.x = 1;
  2130. this.y = 0;
  2131. this.z = 0;
  2132. } else {
  2133. this.x = q.x / s;
  2134. this.y = q.y / s;
  2135. this.z = q.z / s;
  2136. }
  2137. return this;
  2138. };
  2139. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  2140. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2141. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2142. var angle, x, y, z; // variables for result
  2143. var epsilon = 0.01,
  2144. // margin to allow for rounding errors
  2145. epsilon2 = 0.1,
  2146. // margin to distinguish between 0 and 180 degrees
  2147. te = m.elements,
  2148. m11 = te[0],
  2149. m12 = te[4],
  2150. m13 = te[8],
  2151. m21 = te[1],
  2152. m22 = te[5],
  2153. m23 = te[9],
  2154. m31 = te[2],
  2155. m32 = te[6],
  2156. m33 = te[10];
  2157. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  2158. // singularity found
  2159. // first check for identity matrix which must have +1 for all terms
  2160. // in leading diagonal and zero in other terms
  2161. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  2162. // this singularity is identity matrix so angle = 0
  2163. this.set(1, 0, 0, 0);
  2164. return this; // zero angle, arbitrary axis
  2165. } // otherwise this singularity is angle = 180
  2166. angle = Math.PI;
  2167. var xx = (m11 + 1) / 2;
  2168. var yy = (m22 + 1) / 2;
  2169. var zz = (m33 + 1) / 2;
  2170. var xy = (m12 + m21) / 4;
  2171. var xz = (m13 + m31) / 4;
  2172. var yz = (m23 + m32) / 4;
  2173. if (xx > yy && xx > zz) {
  2174. // m11 is the largest diagonal term
  2175. if (xx < epsilon) {
  2176. x = 0;
  2177. y = 0.707106781;
  2178. z = 0.707106781;
  2179. } else {
  2180. x = Math.sqrt(xx);
  2181. y = xy / x;
  2182. z = xz / x;
  2183. }
  2184. } else if (yy > zz) {
  2185. // m22 is the largest diagonal term
  2186. if (yy < epsilon) {
  2187. x = 0.707106781;
  2188. y = 0;
  2189. z = 0.707106781;
  2190. } else {
  2191. y = Math.sqrt(yy);
  2192. x = xy / y;
  2193. z = yz / y;
  2194. }
  2195. } else {
  2196. // m33 is the largest diagonal term so base result on this
  2197. if (zz < epsilon) {
  2198. x = 0.707106781;
  2199. y = 0.707106781;
  2200. z = 0;
  2201. } else {
  2202. z = Math.sqrt(zz);
  2203. x = xz / z;
  2204. y = yz / z;
  2205. }
  2206. }
  2207. this.set(x, y, z, angle);
  2208. return this; // return 180 deg rotation
  2209. } // as we have reached here there are no singularities so we can handle normally
  2210. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  2211. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2212. // caught by singularity test above, but I've left it in just in case
  2213. this.x = (m32 - m23) / s;
  2214. this.y = (m13 - m31) / s;
  2215. this.z = (m21 - m12) / s;
  2216. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  2217. return this;
  2218. };
  2219. _proto.min = function min(v) {
  2220. this.x = Math.min(this.x, v.x);
  2221. this.y = Math.min(this.y, v.y);
  2222. this.z = Math.min(this.z, v.z);
  2223. this.w = Math.min(this.w, v.w);
  2224. return this;
  2225. };
  2226. _proto.max = function max(v) {
  2227. this.x = Math.max(this.x, v.x);
  2228. this.y = Math.max(this.y, v.y);
  2229. this.z = Math.max(this.z, v.z);
  2230. this.w = Math.max(this.w, v.w);
  2231. return this;
  2232. };
  2233. _proto.clamp = function clamp(min, max) {
  2234. // assumes min < max, componentwise
  2235. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2236. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2237. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2238. this.w = Math.max(min.w, Math.min(max.w, this.w));
  2239. return this;
  2240. };
  2241. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2242. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2243. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2244. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2245. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  2246. return this;
  2247. };
  2248. _proto.clampLength = function clampLength(min, max) {
  2249. var length = this.length();
  2250. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2251. };
  2252. _proto.floor = function floor() {
  2253. this.x = Math.floor(this.x);
  2254. this.y = Math.floor(this.y);
  2255. this.z = Math.floor(this.z);
  2256. this.w = Math.floor(this.w);
  2257. return this;
  2258. };
  2259. _proto.ceil = function ceil() {
  2260. this.x = Math.ceil(this.x);
  2261. this.y = Math.ceil(this.y);
  2262. this.z = Math.ceil(this.z);
  2263. this.w = Math.ceil(this.w);
  2264. return this;
  2265. };
  2266. _proto.round = function round() {
  2267. this.x = Math.round(this.x);
  2268. this.y = Math.round(this.y);
  2269. this.z = Math.round(this.z);
  2270. this.w = Math.round(this.w);
  2271. return this;
  2272. };
  2273. _proto.roundToZero = function roundToZero() {
  2274. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2275. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2276. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2277. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  2278. return this;
  2279. };
  2280. _proto.negate = function negate() {
  2281. this.x = -this.x;
  2282. this.y = -this.y;
  2283. this.z = -this.z;
  2284. this.w = -this.w;
  2285. return this;
  2286. };
  2287. _proto.dot = function dot(v) {
  2288. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2289. };
  2290. _proto.lengthSq = function lengthSq() {
  2291. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2292. };
  2293. _proto.length = function length() {
  2294. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  2295. };
  2296. _proto.manhattanLength = function manhattanLength() {
  2297. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  2298. };
  2299. _proto.normalize = function normalize() {
  2300. return this.divideScalar(this.length() || 1);
  2301. };
  2302. _proto.setLength = function setLength(length) {
  2303. return this.normalize().multiplyScalar(length);
  2304. };
  2305. _proto.lerp = function lerp(v, alpha) {
  2306. this.x += (v.x - this.x) * alpha;
  2307. this.y += (v.y - this.y) * alpha;
  2308. this.z += (v.z - this.z) * alpha;
  2309. this.w += (v.w - this.w) * alpha;
  2310. return this;
  2311. };
  2312. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2313. this.x = v1.x + (v2.x - v1.x) * alpha;
  2314. this.y = v1.y + (v2.y - v1.y) * alpha;
  2315. this.z = v1.z + (v2.z - v1.z) * alpha;
  2316. this.w = v1.w + (v2.w - v1.w) * alpha;
  2317. return this;
  2318. };
  2319. _proto.equals = function equals(v) {
  2320. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  2321. };
  2322. _proto.fromArray = function fromArray(array, offset) {
  2323. if (offset === void 0) {
  2324. offset = 0;
  2325. }
  2326. this.x = array[offset];
  2327. this.y = array[offset + 1];
  2328. this.z = array[offset + 2];
  2329. this.w = array[offset + 3];
  2330. return this;
  2331. };
  2332. _proto.toArray = function toArray(array, offset) {
  2333. if (array === void 0) {
  2334. array = [];
  2335. }
  2336. if (offset === void 0) {
  2337. offset = 0;
  2338. }
  2339. array[offset] = this.x;
  2340. array[offset + 1] = this.y;
  2341. array[offset + 2] = this.z;
  2342. array[offset + 3] = this.w;
  2343. return array;
  2344. };
  2345. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2346. if (offset !== undefined) {
  2347. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  2348. }
  2349. this.x = attribute.getX(index);
  2350. this.y = attribute.getY(index);
  2351. this.z = attribute.getZ(index);
  2352. this.w = attribute.getW(index);
  2353. return this;
  2354. };
  2355. _proto.random = function random() {
  2356. this.x = Math.random();
  2357. this.y = Math.random();
  2358. this.z = Math.random();
  2359. this.w = Math.random();
  2360. return this;
  2361. };
  2362. _createClass(Vector4, [{
  2363. key: "width",
  2364. get: function get() {
  2365. return this.z;
  2366. },
  2367. set: function set(value) {
  2368. this.z = value;
  2369. }
  2370. }, {
  2371. key: "height",
  2372. get: function get() {
  2373. return this.w;
  2374. },
  2375. set: function set(value) {
  2376. this.w = value;
  2377. }
  2378. }]);
  2379. return Vector4;
  2380. }();
  2381. /*
  2382. In options, we can specify:
  2383. * Texture parameters for an auto-generated target texture
  2384. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2385. */
  2386. var WebGLRenderTarget = /*#__PURE__*/function (_EventDispatcher) {
  2387. _inheritsLoose(WebGLRenderTarget, _EventDispatcher);
  2388. function WebGLRenderTarget(width, height, options) {
  2389. var _this;
  2390. _this = _EventDispatcher.call(this) || this;
  2391. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLRenderTarget', {
  2392. value: true
  2393. });
  2394. _this.width = width;
  2395. _this.height = height;
  2396. _this.depth = 1;
  2397. _this.scissor = new Vector4(0, 0, width, height);
  2398. _this.scissorTest = false;
  2399. _this.viewport = new Vector4(0, 0, width, height);
  2400. options = options || {};
  2401. _this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  2402. _this.texture.image = {};
  2403. _this.texture.image.width = width;
  2404. _this.texture.image.height = height;
  2405. _this.texture.image.depth = 1;
  2406. _this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2407. _this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2408. _this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2409. _this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  2410. _this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2411. return _this;
  2412. }
  2413. var _proto = WebGLRenderTarget.prototype;
  2414. _proto.setTexture = function setTexture(texture) {
  2415. texture.image = {
  2416. width: this.width,
  2417. height: this.height,
  2418. depth: this.depth
  2419. };
  2420. this.texture = texture;
  2421. };
  2422. _proto.setSize = function setSize(width, height, depth) {
  2423. if (depth === void 0) {
  2424. depth = 1;
  2425. }
  2426. if (this.width !== width || this.height !== height || this.depth !== depth) {
  2427. this.width = width;
  2428. this.height = height;
  2429. this.depth = depth;
  2430. this.texture.image.width = width;
  2431. this.texture.image.height = height;
  2432. this.texture.image.depth = depth;
  2433. this.dispose();
  2434. }
  2435. this.viewport.set(0, 0, width, height);
  2436. this.scissor.set(0, 0, width, height);
  2437. };
  2438. _proto.clone = function clone() {
  2439. return new this.constructor().copy(this);
  2440. };
  2441. _proto.copy = function copy(source) {
  2442. this.width = source.width;
  2443. this.height = source.height;
  2444. this.depth = source.depth;
  2445. this.viewport.copy(source.viewport);
  2446. this.texture = source.texture.clone();
  2447. this.depthBuffer = source.depthBuffer;
  2448. this.stencilBuffer = source.stencilBuffer;
  2449. this.depthTexture = source.depthTexture;
  2450. return this;
  2451. };
  2452. _proto.dispose = function dispose() {
  2453. this.dispatchEvent({
  2454. type: 'dispose'
  2455. });
  2456. };
  2457. return WebGLRenderTarget;
  2458. }(EventDispatcher);
  2459. var WebGLMultisampleRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  2460. _inheritsLoose(WebGLMultisampleRenderTarget, _WebGLRenderTarget);
  2461. function WebGLMultisampleRenderTarget(width, height, options) {
  2462. var _this;
  2463. _this = _WebGLRenderTarget.call(this, width, height, options) || this;
  2464. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLMultisampleRenderTarget', {
  2465. value: true
  2466. });
  2467. _this.samples = 4;
  2468. return _this;
  2469. }
  2470. var _proto = WebGLMultisampleRenderTarget.prototype;
  2471. _proto.copy = function copy(source) {
  2472. _WebGLRenderTarget.prototype.copy.call(this, source);
  2473. this.samples = source.samples;
  2474. return this;
  2475. };
  2476. return WebGLMultisampleRenderTarget;
  2477. }(WebGLRenderTarget);
  2478. var Quaternion = /*#__PURE__*/function () {
  2479. function Quaternion(x, y, z, w) {
  2480. if (x === void 0) {
  2481. x = 0;
  2482. }
  2483. if (y === void 0) {
  2484. y = 0;
  2485. }
  2486. if (z === void 0) {
  2487. z = 0;
  2488. }
  2489. if (w === void 0) {
  2490. w = 1;
  2491. }
  2492. Object.defineProperty(this, 'isQuaternion', {
  2493. value: true
  2494. });
  2495. this._x = x;
  2496. this._y = y;
  2497. this._z = z;
  2498. this._w = w;
  2499. }
  2500. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  2501. return qm.copy(qa).slerp(qb, t);
  2502. };
  2503. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  2504. // fuzz-free, array-based Quaternion SLERP operation
  2505. var x0 = src0[srcOffset0 + 0],
  2506. y0 = src0[srcOffset0 + 1],
  2507. z0 = src0[srcOffset0 + 2],
  2508. w0 = src0[srcOffset0 + 3];
  2509. var x1 = src1[srcOffset1 + 0],
  2510. y1 = src1[srcOffset1 + 1],
  2511. z1 = src1[srcOffset1 + 2],
  2512. w1 = src1[srcOffset1 + 3];
  2513. if (t === 0) {
  2514. dst[dstOffset + 0] = x0;
  2515. dst[dstOffset + 1] = y0;
  2516. dst[dstOffset + 2] = z0;
  2517. dst[dstOffset + 3] = w0;
  2518. return;
  2519. }
  2520. if (t === 1) {
  2521. dst[dstOffset + 0] = x1;
  2522. dst[dstOffset + 1] = y1;
  2523. dst[dstOffset + 2] = z1;
  2524. dst[dstOffset + 3] = w1;
  2525. return;
  2526. }
  2527. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  2528. var s = 1 - t;
  2529. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2530. dir = cos >= 0 ? 1 : -1,
  2531. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  2532. if (sqrSin > Number.EPSILON) {
  2533. var sin = Math.sqrt(sqrSin),
  2534. len = Math.atan2(sin, cos * dir);
  2535. s = Math.sin(s * len) / sin;
  2536. t = Math.sin(t * len) / sin;
  2537. }
  2538. var tDir = t * dir;
  2539. x0 = x0 * s + x1 * tDir;
  2540. y0 = y0 * s + y1 * tDir;
  2541. z0 = z0 * s + z1 * tDir;
  2542. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  2543. if (s === 1 - t) {
  2544. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  2545. x0 *= f;
  2546. y0 *= f;
  2547. z0 *= f;
  2548. w0 *= f;
  2549. }
  2550. }
  2551. dst[dstOffset] = x0;
  2552. dst[dstOffset + 1] = y0;
  2553. dst[dstOffset + 2] = z0;
  2554. dst[dstOffset + 3] = w0;
  2555. };
  2556. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  2557. var x0 = src0[srcOffset0];
  2558. var y0 = src0[srcOffset0 + 1];
  2559. var z0 = src0[srcOffset0 + 2];
  2560. var w0 = src0[srcOffset0 + 3];
  2561. var x1 = src1[srcOffset1];
  2562. var y1 = src1[srcOffset1 + 1];
  2563. var z1 = src1[srcOffset1 + 2];
  2564. var w1 = src1[srcOffset1 + 3];
  2565. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2566. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2567. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2568. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2569. return dst;
  2570. };
  2571. var _proto = Quaternion.prototype;
  2572. _proto.set = function set(x, y, z, w) {
  2573. this._x = x;
  2574. this._y = y;
  2575. this._z = z;
  2576. this._w = w;
  2577. this._onChangeCallback();
  2578. return this;
  2579. };
  2580. _proto.clone = function clone() {
  2581. return new this.constructor(this._x, this._y, this._z, this._w);
  2582. };
  2583. _proto.copy = function copy(quaternion) {
  2584. this._x = quaternion.x;
  2585. this._y = quaternion.y;
  2586. this._z = quaternion.z;
  2587. this._w = quaternion.w;
  2588. this._onChangeCallback();
  2589. return this;
  2590. };
  2591. _proto.setFromEuler = function setFromEuler(euler, update) {
  2592. if (!(euler && euler.isEuler)) {
  2593. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2594. }
  2595. var x = euler._x,
  2596. y = euler._y,
  2597. z = euler._z,
  2598. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  2599. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2600. // content/SpinCalc.m
  2601. var cos = Math.cos;
  2602. var sin = Math.sin;
  2603. var c1 = cos(x / 2);
  2604. var c2 = cos(y / 2);
  2605. var c3 = cos(z / 2);
  2606. var s1 = sin(x / 2);
  2607. var s2 = sin(y / 2);
  2608. var s3 = sin(z / 2);
  2609. switch (order) {
  2610. case 'XYZ':
  2611. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2612. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2613. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2614. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2615. break;
  2616. case 'YXZ':
  2617. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2618. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2619. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2620. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2621. break;
  2622. case 'ZXY':
  2623. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2624. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2625. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2626. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2627. break;
  2628. case 'ZYX':
  2629. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2630. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2631. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2632. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2633. break;
  2634. case 'YZX':
  2635. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2636. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2637. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2638. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2639. break;
  2640. case 'XZY':
  2641. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2642. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2643. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2644. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2645. break;
  2646. default:
  2647. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  2648. }
  2649. if (update !== false) this._onChangeCallback();
  2650. return this;
  2651. };
  2652. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  2653. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2654. // assumes axis is normalized
  2655. var halfAngle = angle / 2,
  2656. s = Math.sin(halfAngle);
  2657. this._x = axis.x * s;
  2658. this._y = axis.y * s;
  2659. this._z = axis.z * s;
  2660. this._w = Math.cos(halfAngle);
  2661. this._onChangeCallback();
  2662. return this;
  2663. };
  2664. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  2665. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2666. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2667. var te = m.elements,
  2668. m11 = te[0],
  2669. m12 = te[4],
  2670. m13 = te[8],
  2671. m21 = te[1],
  2672. m22 = te[5],
  2673. m23 = te[9],
  2674. m31 = te[2],
  2675. m32 = te[6],
  2676. m33 = te[10],
  2677. trace = m11 + m22 + m33;
  2678. if (trace > 0) {
  2679. var s = 0.5 / Math.sqrt(trace + 1.0);
  2680. this._w = 0.25 / s;
  2681. this._x = (m32 - m23) * s;
  2682. this._y = (m13 - m31) * s;
  2683. this._z = (m21 - m12) * s;
  2684. } else if (m11 > m22 && m11 > m33) {
  2685. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  2686. this._w = (m32 - m23) / _s;
  2687. this._x = 0.25 * _s;
  2688. this._y = (m12 + m21) / _s;
  2689. this._z = (m13 + m31) / _s;
  2690. } else if (m22 > m33) {
  2691. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  2692. this._w = (m13 - m31) / _s2;
  2693. this._x = (m12 + m21) / _s2;
  2694. this._y = 0.25 * _s2;
  2695. this._z = (m23 + m32) / _s2;
  2696. } else {
  2697. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  2698. this._w = (m21 - m12) / _s3;
  2699. this._x = (m13 + m31) / _s3;
  2700. this._y = (m23 + m32) / _s3;
  2701. this._z = 0.25 * _s3;
  2702. }
  2703. this._onChangeCallback();
  2704. return this;
  2705. };
  2706. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  2707. // assumes direction vectors vFrom and vTo are normalized
  2708. var EPS = 0.000001;
  2709. var r = vFrom.dot(vTo) + 1;
  2710. if (r < EPS) {
  2711. r = 0;
  2712. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  2713. this._x = -vFrom.y;
  2714. this._y = vFrom.x;
  2715. this._z = 0;
  2716. this._w = r;
  2717. } else {
  2718. this._x = 0;
  2719. this._y = -vFrom.z;
  2720. this._z = vFrom.y;
  2721. this._w = r;
  2722. }
  2723. } else {
  2724. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2725. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2726. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2727. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2728. this._w = r;
  2729. }
  2730. return this.normalize();
  2731. };
  2732. _proto.angleTo = function angleTo(q) {
  2733. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2734. };
  2735. _proto.rotateTowards = function rotateTowards(q, step) {
  2736. var angle = this.angleTo(q);
  2737. if (angle === 0) return this;
  2738. var t = Math.min(1, step / angle);
  2739. this.slerp(q, t);
  2740. return this;
  2741. };
  2742. _proto.identity = function identity() {
  2743. return this.set(0, 0, 0, 1);
  2744. };
  2745. _proto.invert = function invert() {
  2746. // quaternion is assumed to have unit length
  2747. return this.conjugate();
  2748. };
  2749. _proto.conjugate = function conjugate() {
  2750. this._x *= -1;
  2751. this._y *= -1;
  2752. this._z *= -1;
  2753. this._onChangeCallback();
  2754. return this;
  2755. };
  2756. _proto.dot = function dot(v) {
  2757. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2758. };
  2759. _proto.lengthSq = function lengthSq() {
  2760. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2761. };
  2762. _proto.length = function length() {
  2763. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2764. };
  2765. _proto.normalize = function normalize() {
  2766. var l = this.length();
  2767. if (l === 0) {
  2768. this._x = 0;
  2769. this._y = 0;
  2770. this._z = 0;
  2771. this._w = 1;
  2772. } else {
  2773. l = 1 / l;
  2774. this._x = this._x * l;
  2775. this._y = this._y * l;
  2776. this._z = this._z * l;
  2777. this._w = this._w * l;
  2778. }
  2779. this._onChangeCallback();
  2780. return this;
  2781. };
  2782. _proto.multiply = function multiply(q, p) {
  2783. if (p !== undefined) {
  2784. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2785. return this.multiplyQuaternions(q, p);
  2786. }
  2787. return this.multiplyQuaternions(this, q);
  2788. };
  2789. _proto.premultiply = function premultiply(q) {
  2790. return this.multiplyQuaternions(q, this);
  2791. };
  2792. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2793. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2794. var qax = a._x,
  2795. qay = a._y,
  2796. qaz = a._z,
  2797. qaw = a._w;
  2798. var qbx = b._x,
  2799. qby = b._y,
  2800. qbz = b._z,
  2801. qbw = b._w;
  2802. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2803. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2804. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2805. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2806. this._onChangeCallback();
  2807. return this;
  2808. };
  2809. _proto.slerp = function slerp(qb, t) {
  2810. if (t === 0) return this;
  2811. if (t === 1) return this.copy(qb);
  2812. var x = this._x,
  2813. y = this._y,
  2814. z = this._z,
  2815. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2816. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2817. if (cosHalfTheta < 0) {
  2818. this._w = -qb._w;
  2819. this._x = -qb._x;
  2820. this._y = -qb._y;
  2821. this._z = -qb._z;
  2822. cosHalfTheta = -cosHalfTheta;
  2823. } else {
  2824. this.copy(qb);
  2825. }
  2826. if (cosHalfTheta >= 1.0) {
  2827. this._w = w;
  2828. this._x = x;
  2829. this._y = y;
  2830. this._z = z;
  2831. return this;
  2832. }
  2833. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2834. if (sqrSinHalfTheta <= Number.EPSILON) {
  2835. var s = 1 - t;
  2836. this._w = s * w + t * this._w;
  2837. this._x = s * x + t * this._x;
  2838. this._y = s * y + t * this._y;
  2839. this._z = s * z + t * this._z;
  2840. this.normalize();
  2841. this._onChangeCallback();
  2842. return this;
  2843. }
  2844. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2845. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2846. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2847. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2848. this._w = w * ratioA + this._w * ratioB;
  2849. this._x = x * ratioA + this._x * ratioB;
  2850. this._y = y * ratioA + this._y * ratioB;
  2851. this._z = z * ratioA + this._z * ratioB;
  2852. this._onChangeCallback();
  2853. return this;
  2854. };
  2855. _proto.equals = function equals(quaternion) {
  2856. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2857. };
  2858. _proto.fromArray = function fromArray(array, offset) {
  2859. if (offset === void 0) {
  2860. offset = 0;
  2861. }
  2862. this._x = array[offset];
  2863. this._y = array[offset + 1];
  2864. this._z = array[offset + 2];
  2865. this._w = array[offset + 3];
  2866. this._onChangeCallback();
  2867. return this;
  2868. };
  2869. _proto.toArray = function toArray(array, offset) {
  2870. if (array === void 0) {
  2871. array = [];
  2872. }
  2873. if (offset === void 0) {
  2874. offset = 0;
  2875. }
  2876. array[offset] = this._x;
  2877. array[offset + 1] = this._y;
  2878. array[offset + 2] = this._z;
  2879. array[offset + 3] = this._w;
  2880. return array;
  2881. };
  2882. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2883. this._x = attribute.getX(index);
  2884. this._y = attribute.getY(index);
  2885. this._z = attribute.getZ(index);
  2886. this._w = attribute.getW(index);
  2887. return this;
  2888. };
  2889. _proto._onChange = function _onChange(callback) {
  2890. this._onChangeCallback = callback;
  2891. return this;
  2892. };
  2893. _proto._onChangeCallback = function _onChangeCallback() {};
  2894. _createClass(Quaternion, [{
  2895. key: "x",
  2896. get: function get() {
  2897. return this._x;
  2898. },
  2899. set: function set(value) {
  2900. this._x = value;
  2901. this._onChangeCallback();
  2902. }
  2903. }, {
  2904. key: "y",
  2905. get: function get() {
  2906. return this._y;
  2907. },
  2908. set: function set(value) {
  2909. this._y = value;
  2910. this._onChangeCallback();
  2911. }
  2912. }, {
  2913. key: "z",
  2914. get: function get() {
  2915. return this._z;
  2916. },
  2917. set: function set(value) {
  2918. this._z = value;
  2919. this._onChangeCallback();
  2920. }
  2921. }, {
  2922. key: "w",
  2923. get: function get() {
  2924. return this._w;
  2925. },
  2926. set: function set(value) {
  2927. this._w = value;
  2928. this._onChangeCallback();
  2929. }
  2930. }]);
  2931. return Quaternion;
  2932. }();
  2933. var Vector3 = /*#__PURE__*/function () {
  2934. function Vector3(x, y, z) {
  2935. if (x === void 0) {
  2936. x = 0;
  2937. }
  2938. if (y === void 0) {
  2939. y = 0;
  2940. }
  2941. if (z === void 0) {
  2942. z = 0;
  2943. }
  2944. Object.defineProperty(this, 'isVector3', {
  2945. value: true
  2946. });
  2947. this.x = x;
  2948. this.y = y;
  2949. this.z = z;
  2950. }
  2951. var _proto = Vector3.prototype;
  2952. _proto.set = function set(x, y, z) {
  2953. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2954. this.x = x;
  2955. this.y = y;
  2956. this.z = z;
  2957. return this;
  2958. };
  2959. _proto.setScalar = function setScalar(scalar) {
  2960. this.x = scalar;
  2961. this.y = scalar;
  2962. this.z = scalar;
  2963. return this;
  2964. };
  2965. _proto.setX = function setX(x) {
  2966. this.x = x;
  2967. return this;
  2968. };
  2969. _proto.setY = function setY(y) {
  2970. this.y = y;
  2971. return this;
  2972. };
  2973. _proto.setZ = function setZ(z) {
  2974. this.z = z;
  2975. return this;
  2976. };
  2977. _proto.setComponent = function setComponent(index, value) {
  2978. switch (index) {
  2979. case 0:
  2980. this.x = value;
  2981. break;
  2982. case 1:
  2983. this.y = value;
  2984. break;
  2985. case 2:
  2986. this.z = value;
  2987. break;
  2988. default:
  2989. throw new Error('index is out of range: ' + index);
  2990. }
  2991. return this;
  2992. };
  2993. _proto.getComponent = function getComponent(index) {
  2994. switch (index) {
  2995. case 0:
  2996. return this.x;
  2997. case 1:
  2998. return this.y;
  2999. case 2:
  3000. return this.z;
  3001. default:
  3002. throw new Error('index is out of range: ' + index);
  3003. }
  3004. };
  3005. _proto.clone = function clone() {
  3006. return new this.constructor(this.x, this.y, this.z);
  3007. };
  3008. _proto.copy = function copy(v) {
  3009. this.x = v.x;
  3010. this.y = v.y;
  3011. this.z = v.z;
  3012. return this;
  3013. };
  3014. _proto.add = function add(v, w) {
  3015. if (w !== undefined) {
  3016. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  3017. return this.addVectors(v, w);
  3018. }
  3019. this.x += v.x;
  3020. this.y += v.y;
  3021. this.z += v.z;
  3022. return this;
  3023. };
  3024. _proto.addScalar = function addScalar(s) {
  3025. this.x += s;
  3026. this.y += s;
  3027. this.z += s;
  3028. return this;
  3029. };
  3030. _proto.addVectors = function addVectors(a, b) {
  3031. this.x = a.x + b.x;
  3032. this.y = a.y + b.y;
  3033. this.z = a.z + b.z;
  3034. return this;
  3035. };
  3036. _proto.addScaledVector = function addScaledVector(v, s) {
  3037. this.x += v.x * s;
  3038. this.y += v.y * s;
  3039. this.z += v.z * s;
  3040. return this;
  3041. };
  3042. _proto.sub = function sub(v, w) {
  3043. if (w !== undefined) {
  3044. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  3045. return this.subVectors(v, w);
  3046. }
  3047. this.x -= v.x;
  3048. this.y -= v.y;
  3049. this.z -= v.z;
  3050. return this;
  3051. };
  3052. _proto.subScalar = function subScalar(s) {
  3053. this.x -= s;
  3054. this.y -= s;
  3055. this.z -= s;
  3056. return this;
  3057. };
  3058. _proto.subVectors = function subVectors(a, b) {
  3059. this.x = a.x - b.x;
  3060. this.y = a.y - b.y;
  3061. this.z = a.z - b.z;
  3062. return this;
  3063. };
  3064. _proto.multiply = function multiply(v, w) {
  3065. if (w !== undefined) {
  3066. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  3067. return this.multiplyVectors(v, w);
  3068. }
  3069. this.x *= v.x;
  3070. this.y *= v.y;
  3071. this.z *= v.z;
  3072. return this;
  3073. };
  3074. _proto.multiplyScalar = function multiplyScalar(scalar) {
  3075. this.x *= scalar;
  3076. this.y *= scalar;
  3077. this.z *= scalar;
  3078. return this;
  3079. };
  3080. _proto.multiplyVectors = function multiplyVectors(a, b) {
  3081. this.x = a.x * b.x;
  3082. this.y = a.y * b.y;
  3083. this.z = a.z * b.z;
  3084. return this;
  3085. };
  3086. _proto.applyEuler = function applyEuler(euler) {
  3087. if (!(euler && euler.isEuler)) {
  3088. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  3089. }
  3090. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  3091. };
  3092. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  3093. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  3094. };
  3095. _proto.applyMatrix3 = function applyMatrix3(m) {
  3096. var x = this.x,
  3097. y = this.y,
  3098. z = this.z;
  3099. var e = m.elements;
  3100. this.x = e[0] * x + e[3] * y + e[6] * z;
  3101. this.y = e[1] * x + e[4] * y + e[7] * z;
  3102. this.z = e[2] * x + e[5] * y + e[8] * z;
  3103. return this;
  3104. };
  3105. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  3106. return this.applyMatrix3(m).normalize();
  3107. };
  3108. _proto.applyMatrix4 = function applyMatrix4(m) {
  3109. var x = this.x,
  3110. y = this.y,
  3111. z = this.z;
  3112. var e = m.elements;
  3113. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  3114. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  3115. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  3116. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  3117. return this;
  3118. };
  3119. _proto.applyQuaternion = function applyQuaternion(q) {
  3120. var x = this.x,
  3121. y = this.y,
  3122. z = this.z;
  3123. var qx = q.x,
  3124. qy = q.y,
  3125. qz = q.z,
  3126. qw = q.w; // calculate quat * vector
  3127. var ix = qw * x + qy * z - qz * y;
  3128. var iy = qw * y + qz * x - qx * z;
  3129. var iz = qw * z + qx * y - qy * x;
  3130. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  3131. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3132. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3133. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3134. return this;
  3135. };
  3136. _proto.project = function project(camera) {
  3137. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  3138. };
  3139. _proto.unproject = function unproject(camera) {
  3140. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  3141. };
  3142. _proto.transformDirection = function transformDirection(m) {
  3143. // input: THREE.Matrix4 affine matrix
  3144. // vector interpreted as a direction
  3145. var x = this.x,
  3146. y = this.y,
  3147. z = this.z;
  3148. var e = m.elements;
  3149. this.x = e[0] * x + e[4] * y + e[8] * z;
  3150. this.y = e[1] * x + e[5] * y + e[9] * z;
  3151. this.z = e[2] * x + e[6] * y + e[10] * z;
  3152. return this.normalize();
  3153. };
  3154. _proto.divide = function divide(v) {
  3155. this.x /= v.x;
  3156. this.y /= v.y;
  3157. this.z /= v.z;
  3158. return this;
  3159. };
  3160. _proto.divideScalar = function divideScalar(scalar) {
  3161. return this.multiplyScalar(1 / scalar);
  3162. };
  3163. _proto.min = function min(v) {
  3164. this.x = Math.min(this.x, v.x);
  3165. this.y = Math.min(this.y, v.y);
  3166. this.z = Math.min(this.z, v.z);
  3167. return this;
  3168. };
  3169. _proto.max = function max(v) {
  3170. this.x = Math.max(this.x, v.x);
  3171. this.y = Math.max(this.y, v.y);
  3172. this.z = Math.max(this.z, v.z);
  3173. return this;
  3174. };
  3175. _proto.clamp = function clamp(min, max) {
  3176. // assumes min < max, componentwise
  3177. this.x = Math.max(min.x, Math.min(max.x, this.x));
  3178. this.y = Math.max(min.y, Math.min(max.y, this.y));
  3179. this.z = Math.max(min.z, Math.min(max.z, this.z));
  3180. return this;
  3181. };
  3182. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  3183. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  3184. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  3185. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  3186. return this;
  3187. };
  3188. _proto.clampLength = function clampLength(min, max) {
  3189. var length = this.length();
  3190. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  3191. };
  3192. _proto.floor = function floor() {
  3193. this.x = Math.floor(this.x);
  3194. this.y = Math.floor(this.y);
  3195. this.z = Math.floor(this.z);
  3196. return this;
  3197. };
  3198. _proto.ceil = function ceil() {
  3199. this.x = Math.ceil(this.x);
  3200. this.y = Math.ceil(this.y);
  3201. this.z = Math.ceil(this.z);
  3202. return this;
  3203. };
  3204. _proto.round = function round() {
  3205. this.x = Math.round(this.x);
  3206. this.y = Math.round(this.y);
  3207. this.z = Math.round(this.z);
  3208. return this;
  3209. };
  3210. _proto.roundToZero = function roundToZero() {
  3211. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  3212. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  3213. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  3214. return this;
  3215. };
  3216. _proto.negate = function negate() {
  3217. this.x = -this.x;
  3218. this.y = -this.y;
  3219. this.z = -this.z;
  3220. return this;
  3221. };
  3222. _proto.dot = function dot(v) {
  3223. return this.x * v.x + this.y * v.y + this.z * v.z;
  3224. } // TODO lengthSquared?
  3225. ;
  3226. _proto.lengthSq = function lengthSq() {
  3227. return this.x * this.x + this.y * this.y + this.z * this.z;
  3228. };
  3229. _proto.length = function length() {
  3230. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3231. };
  3232. _proto.manhattanLength = function manhattanLength() {
  3233. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  3234. };
  3235. _proto.normalize = function normalize() {
  3236. return this.divideScalar(this.length() || 1);
  3237. };
  3238. _proto.setLength = function setLength(length) {
  3239. return this.normalize().multiplyScalar(length);
  3240. };
  3241. _proto.lerp = function lerp(v, alpha) {
  3242. this.x += (v.x - this.x) * alpha;
  3243. this.y += (v.y - this.y) * alpha;
  3244. this.z += (v.z - this.z) * alpha;
  3245. return this;
  3246. };
  3247. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  3248. this.x = v1.x + (v2.x - v1.x) * alpha;
  3249. this.y = v1.y + (v2.y - v1.y) * alpha;
  3250. this.z = v1.z + (v2.z - v1.z) * alpha;
  3251. return this;
  3252. };
  3253. _proto.cross = function cross(v, w) {
  3254. if (w !== undefined) {
  3255. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  3256. return this.crossVectors(v, w);
  3257. }
  3258. return this.crossVectors(this, v);
  3259. };
  3260. _proto.crossVectors = function crossVectors(a, b) {
  3261. var ax = a.x,
  3262. ay = a.y,
  3263. az = a.z;
  3264. var bx = b.x,
  3265. by = b.y,
  3266. bz = b.z;
  3267. this.x = ay * bz - az * by;
  3268. this.y = az * bx - ax * bz;
  3269. this.z = ax * by - ay * bx;
  3270. return this;
  3271. };
  3272. _proto.projectOnVector = function projectOnVector(v) {
  3273. var denominator = v.lengthSq();
  3274. if (denominator === 0) return this.set(0, 0, 0);
  3275. var scalar = v.dot(this) / denominator;
  3276. return this.copy(v).multiplyScalar(scalar);
  3277. };
  3278. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  3279. _vector.copy(this).projectOnVector(planeNormal);
  3280. return this.sub(_vector);
  3281. };
  3282. _proto.reflect = function reflect(normal) {
  3283. // reflect incident vector off plane orthogonal to normal
  3284. // normal is assumed to have unit length
  3285. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  3286. };
  3287. _proto.angleTo = function angleTo(v) {
  3288. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  3289. if (denominator === 0) return Math.PI / 2;
  3290. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  3291. return Math.acos(MathUtils.clamp(theta, -1, 1));
  3292. };
  3293. _proto.distanceTo = function distanceTo(v) {
  3294. return Math.sqrt(this.distanceToSquared(v));
  3295. };
  3296. _proto.distanceToSquared = function distanceToSquared(v) {
  3297. var dx = this.x - v.x,
  3298. dy = this.y - v.y,
  3299. dz = this.z - v.z;
  3300. return dx * dx + dy * dy + dz * dz;
  3301. };
  3302. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  3303. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  3304. };
  3305. _proto.setFromSpherical = function setFromSpherical(s) {
  3306. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  3307. };
  3308. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  3309. var sinPhiRadius = Math.sin(phi) * radius;
  3310. this.x = sinPhiRadius * Math.sin(theta);
  3311. this.y = Math.cos(phi) * radius;
  3312. this.z = sinPhiRadius * Math.cos(theta);
  3313. return this;
  3314. };
  3315. _proto.setFromCylindrical = function setFromCylindrical(c) {
  3316. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  3317. };
  3318. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  3319. this.x = radius * Math.sin(theta);
  3320. this.y = y;
  3321. this.z = radius * Math.cos(theta);
  3322. return this;
  3323. };
  3324. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  3325. var e = m.elements;
  3326. this.x = e[12];
  3327. this.y = e[13];
  3328. this.z = e[14];
  3329. return this;
  3330. };
  3331. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  3332. var sx = this.setFromMatrixColumn(m, 0).length();
  3333. var sy = this.setFromMatrixColumn(m, 1).length();
  3334. var sz = this.setFromMatrixColumn(m, 2).length();
  3335. this.x = sx;
  3336. this.y = sy;
  3337. this.z = sz;
  3338. return this;
  3339. };
  3340. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  3341. return this.fromArray(m.elements, index * 4);
  3342. };
  3343. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  3344. return this.fromArray(m.elements, index * 3);
  3345. };
  3346. _proto.equals = function equals(v) {
  3347. return v.x === this.x && v.y === this.y && v.z === this.z;
  3348. };
  3349. _proto.fromArray = function fromArray(array, offset) {
  3350. if (offset === void 0) {
  3351. offset = 0;
  3352. }
  3353. this.x = array[offset];
  3354. this.y = array[offset + 1];
  3355. this.z = array[offset + 2];
  3356. return this;
  3357. };
  3358. _proto.toArray = function toArray(array, offset) {
  3359. if (array === void 0) {
  3360. array = [];
  3361. }
  3362. if (offset === void 0) {
  3363. offset = 0;
  3364. }
  3365. array[offset] = this.x;
  3366. array[offset + 1] = this.y;
  3367. array[offset + 2] = this.z;
  3368. return array;
  3369. };
  3370. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  3371. if (offset !== undefined) {
  3372. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  3373. }
  3374. this.x = attribute.getX(index);
  3375. this.y = attribute.getY(index);
  3376. this.z = attribute.getZ(index);
  3377. return this;
  3378. };
  3379. _proto.random = function random() {
  3380. this.x = Math.random();
  3381. this.y = Math.random();
  3382. this.z = Math.random();
  3383. return this;
  3384. };
  3385. return Vector3;
  3386. }();
  3387. var _vector = /*@__PURE__*/new Vector3();
  3388. var _quaternion = /*@__PURE__*/new Quaternion();
  3389. var Box3 = /*#__PURE__*/function () {
  3390. function Box3(min, max) {
  3391. Object.defineProperty(this, 'isBox3', {
  3392. value: true
  3393. });
  3394. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  3395. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  3396. }
  3397. var _proto = Box3.prototype;
  3398. _proto.set = function set(min, max) {
  3399. this.min.copy(min);
  3400. this.max.copy(max);
  3401. return this;
  3402. };
  3403. _proto.setFromArray = function setFromArray(array) {
  3404. var minX = +Infinity;
  3405. var minY = +Infinity;
  3406. var minZ = +Infinity;
  3407. var maxX = -Infinity;
  3408. var maxY = -Infinity;
  3409. var maxZ = -Infinity;
  3410. for (var i = 0, l = array.length; i < l; i += 3) {
  3411. var x = array[i];
  3412. var y = array[i + 1];
  3413. var z = array[i + 2];
  3414. if (x < minX) minX = x;
  3415. if (y < minY) minY = y;
  3416. if (z < minZ) minZ = z;
  3417. if (x > maxX) maxX = x;
  3418. if (y > maxY) maxY = y;
  3419. if (z > maxZ) maxZ = z;
  3420. }
  3421. this.min.set(minX, minY, minZ);
  3422. this.max.set(maxX, maxY, maxZ);
  3423. return this;
  3424. };
  3425. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  3426. var minX = +Infinity;
  3427. var minY = +Infinity;
  3428. var minZ = +Infinity;
  3429. var maxX = -Infinity;
  3430. var maxY = -Infinity;
  3431. var maxZ = -Infinity;
  3432. for (var i = 0, l = attribute.count; i < l; i++) {
  3433. var x = attribute.getX(i);
  3434. var y = attribute.getY(i);
  3435. var z = attribute.getZ(i);
  3436. if (x < minX) minX = x;
  3437. if (y < minY) minY = y;
  3438. if (z < minZ) minZ = z;
  3439. if (x > maxX) maxX = x;
  3440. if (y > maxY) maxY = y;
  3441. if (z > maxZ) maxZ = z;
  3442. }
  3443. this.min.set(minX, minY, minZ);
  3444. this.max.set(maxX, maxY, maxZ);
  3445. return this;
  3446. };
  3447. _proto.setFromPoints = function setFromPoints(points) {
  3448. this.makeEmpty();
  3449. for (var i = 0, il = points.length; i < il; i++) {
  3450. this.expandByPoint(points[i]);
  3451. }
  3452. return this;
  3453. };
  3454. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  3455. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  3456. this.min.copy(center).sub(halfSize);
  3457. this.max.copy(center).add(halfSize);
  3458. return this;
  3459. };
  3460. _proto.setFromObject = function setFromObject(object) {
  3461. this.makeEmpty();
  3462. return this.expandByObject(object);
  3463. };
  3464. _proto.clone = function clone() {
  3465. return new this.constructor().copy(this);
  3466. };
  3467. _proto.copy = function copy(box) {
  3468. this.min.copy(box.min);
  3469. this.max.copy(box.max);
  3470. return this;
  3471. };
  3472. _proto.makeEmpty = function makeEmpty() {
  3473. this.min.x = this.min.y = this.min.z = +Infinity;
  3474. this.max.x = this.max.y = this.max.z = -Infinity;
  3475. return this;
  3476. };
  3477. _proto.isEmpty = function isEmpty() {
  3478. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3479. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  3480. };
  3481. _proto.getCenter = function getCenter(target) {
  3482. if (target === undefined) {
  3483. console.warn('THREE.Box3: .getCenter() target is now required');
  3484. target = new Vector3();
  3485. }
  3486. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  3487. };
  3488. _proto.getSize = function getSize(target) {
  3489. if (target === undefined) {
  3490. console.warn('THREE.Box3: .getSize() target is now required');
  3491. target = new Vector3();
  3492. }
  3493. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  3494. };
  3495. _proto.expandByPoint = function expandByPoint(point) {
  3496. this.min.min(point);
  3497. this.max.max(point);
  3498. return this;
  3499. };
  3500. _proto.expandByVector = function expandByVector(vector) {
  3501. this.min.sub(vector);
  3502. this.max.add(vector);
  3503. return this;
  3504. };
  3505. _proto.expandByScalar = function expandByScalar(scalar) {
  3506. this.min.addScalar(-scalar);
  3507. this.max.addScalar(scalar);
  3508. return this;
  3509. };
  3510. _proto.expandByObject = function expandByObject(object) {
  3511. // Computes the world-axis-aligned bounding box of an object (including its children),
  3512. // accounting for both the object's, and children's, world transforms
  3513. object.updateWorldMatrix(false, false);
  3514. var geometry = object.geometry;
  3515. if (geometry !== undefined) {
  3516. if (geometry.boundingBox === null) {
  3517. geometry.computeBoundingBox();
  3518. }
  3519. _box.copy(geometry.boundingBox);
  3520. _box.applyMatrix4(object.matrixWorld);
  3521. this.union(_box);
  3522. }
  3523. var children = object.children;
  3524. for (var i = 0, l = children.length; i < l; i++) {
  3525. this.expandByObject(children[i]);
  3526. }
  3527. return this;
  3528. };
  3529. _proto.containsPoint = function containsPoint(point) {
  3530. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true;
  3531. };
  3532. _proto.containsBox = function containsBox(box) {
  3533. return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z;
  3534. };
  3535. _proto.getParameter = function getParameter(point, target) {
  3536. // This can potentially have a divide by zero if the box
  3537. // has a size dimension of 0.
  3538. if (target === undefined) {
  3539. console.warn('THREE.Box3: .getParameter() target is now required');
  3540. target = new Vector3();
  3541. }
  3542. return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
  3543. };
  3544. _proto.intersectsBox = function intersectsBox(box) {
  3545. // using 6 splitting planes to rule out intersections.
  3546. return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3547. };
  3548. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3549. // Find the point on the AABB closest to the sphere center.
  3550. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  3551. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  3552. };
  3553. _proto.intersectsPlane = function intersectsPlane(plane) {
  3554. // We compute the minimum and maximum dot product values. If those values
  3555. // are on the same side (back or front) of the plane, then there is no intersection.
  3556. var min, max;
  3557. if (plane.normal.x > 0) {
  3558. min = plane.normal.x * this.min.x;
  3559. max = plane.normal.x * this.max.x;
  3560. } else {
  3561. min = plane.normal.x * this.max.x;
  3562. max = plane.normal.x * this.min.x;
  3563. }
  3564. if (plane.normal.y > 0) {
  3565. min += plane.normal.y * this.min.y;
  3566. max += plane.normal.y * this.max.y;
  3567. } else {
  3568. min += plane.normal.y * this.max.y;
  3569. max += plane.normal.y * this.min.y;
  3570. }
  3571. if (plane.normal.z > 0) {
  3572. min += plane.normal.z * this.min.z;
  3573. max += plane.normal.z * this.max.z;
  3574. } else {
  3575. min += plane.normal.z * this.max.z;
  3576. max += plane.normal.z * this.min.z;
  3577. }
  3578. return min <= -plane.constant && max >= -plane.constant;
  3579. };
  3580. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  3581. if (this.isEmpty()) {
  3582. return false;
  3583. } // compute box center and extents
  3584. this.getCenter(_center);
  3585. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  3586. _v0.subVectors(triangle.a, _center);
  3587. _v1.subVectors(triangle.b, _center);
  3588. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  3589. _f0.subVectors(_v1, _v0);
  3590. _f1.subVectors(_v2, _v1);
  3591. _f2.subVectors(_v0, _v2); // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3592. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  3593. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3594. var axes = [0, -_f0.z, _f0.y, 0, -_f1.z, _f1.y, 0, -_f2.z, _f2.y, _f0.z, 0, -_f0.x, _f1.z, 0, -_f1.x, _f2.z, 0, -_f2.x, -_f0.y, _f0.x, 0, -_f1.y, _f1.x, 0, -_f2.y, _f2.x, 0];
  3595. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3596. return false;
  3597. } // test 3 face normals from the aabb
  3598. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  3599. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3600. return false;
  3601. } // finally testing the face normal of the triangle
  3602. // use already existing triangle edge vectors here
  3603. _triangleNormal.crossVectors(_f0, _f1);
  3604. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  3605. return satForAxes(axes, _v0, _v1, _v2, _extents);
  3606. };
  3607. _proto.clampPoint = function clampPoint(point, target) {
  3608. if (target === undefined) {
  3609. console.warn('THREE.Box3: .clampPoint() target is now required');
  3610. target = new Vector3();
  3611. }
  3612. return target.copy(point).clamp(this.min, this.max);
  3613. };
  3614. _proto.distanceToPoint = function distanceToPoint(point) {
  3615. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  3616. return clampedPoint.sub(point).length();
  3617. };
  3618. _proto.getBoundingSphere = function getBoundingSphere(target) {
  3619. if (target === undefined) {
  3620. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  3621. }
  3622. this.getCenter(target.center);
  3623. target.radius = this.getSize(_vector$1).length() * 0.5;
  3624. return target;
  3625. };
  3626. _proto.intersect = function intersect(box) {
  3627. this.min.max(box.min);
  3628. this.max.min(box.max); // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  3629. if (this.isEmpty()) this.makeEmpty();
  3630. return this;
  3631. };
  3632. _proto.union = function union(box) {
  3633. this.min.min(box.min);
  3634. this.max.max(box.max);
  3635. return this;
  3636. };
  3637. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3638. // transform of empty box is an empty box.
  3639. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3640. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  3641. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  3642. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  3643. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  3644. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  3645. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  3646. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  3647. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  3648. this.setFromPoints(_points);
  3649. return this;
  3650. };
  3651. _proto.translate = function translate(offset) {
  3652. this.min.add(offset);
  3653. this.max.add(offset);
  3654. return this;
  3655. };
  3656. _proto.equals = function equals(box) {
  3657. return box.min.equals(this.min) && box.max.equals(this.max);
  3658. };
  3659. return Box3;
  3660. }();
  3661. function satForAxes(axes, v0, v1, v2, extents) {
  3662. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  3663. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  3664. var r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z); // project all 3 vertices of the triangle onto the seperating axis
  3665. var p0 = v0.dot(_testAxis);
  3666. var p1 = v1.dot(_testAxis);
  3667. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  3668. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  3669. // points of the projected triangle are outside the projected half-length of the aabb
  3670. // the axis is seperating and we can exit
  3671. return false;
  3672. }
  3673. }
  3674. return true;
  3675. }
  3676. var _points = [/*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3()];
  3677. var _vector$1 = /*@__PURE__*/new Vector3();
  3678. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  3679. var _v0 = /*@__PURE__*/new Vector3();
  3680. var _v1 = /*@__PURE__*/new Vector3();
  3681. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  3682. var _f0 = /*@__PURE__*/new Vector3();
  3683. var _f1 = /*@__PURE__*/new Vector3();
  3684. var _f2 = /*@__PURE__*/new Vector3();
  3685. var _center = /*@__PURE__*/new Vector3();
  3686. var _extents = /*@__PURE__*/new Vector3();
  3687. var _triangleNormal = /*@__PURE__*/new Vector3();
  3688. var _testAxis = /*@__PURE__*/new Vector3();
  3689. var _box$1 = /*@__PURE__*/new Box3();
  3690. var Sphere = /*#__PURE__*/function () {
  3691. function Sphere(center, radius) {
  3692. this.center = center !== undefined ? center : new Vector3();
  3693. this.radius = radius !== undefined ? radius : -1;
  3694. }
  3695. var _proto = Sphere.prototype;
  3696. _proto.set = function set(center, radius) {
  3697. this.center.copy(center);
  3698. this.radius = radius;
  3699. return this;
  3700. };
  3701. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  3702. var center = this.center;
  3703. if (optionalCenter !== undefined) {
  3704. center.copy(optionalCenter);
  3705. } else {
  3706. _box$1.setFromPoints(points).getCenter(center);
  3707. }
  3708. var maxRadiusSq = 0;
  3709. for (var i = 0, il = points.length; i < il; i++) {
  3710. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  3711. }
  3712. this.radius = Math.sqrt(maxRadiusSq);
  3713. return this;
  3714. };
  3715. _proto.clone = function clone() {
  3716. return new this.constructor().copy(this);
  3717. };
  3718. _proto.copy = function copy(sphere) {
  3719. this.center.copy(sphere.center);
  3720. this.radius = sphere.radius;
  3721. return this;
  3722. };
  3723. _proto.isEmpty = function isEmpty() {
  3724. return this.radius < 0;
  3725. };
  3726. _proto.makeEmpty = function makeEmpty() {
  3727. this.center.set(0, 0, 0);
  3728. this.radius = -1;
  3729. return this;
  3730. };
  3731. _proto.containsPoint = function containsPoint(point) {
  3732. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3733. };
  3734. _proto.distanceToPoint = function distanceToPoint(point) {
  3735. return point.distanceTo(this.center) - this.radius;
  3736. };
  3737. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3738. var radiusSum = this.radius + sphere.radius;
  3739. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3740. };
  3741. _proto.intersectsBox = function intersectsBox(box) {
  3742. return box.intersectsSphere(this);
  3743. };
  3744. _proto.intersectsPlane = function intersectsPlane(plane) {
  3745. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3746. };
  3747. _proto.clampPoint = function clampPoint(point, target) {
  3748. var deltaLengthSq = this.center.distanceToSquared(point);
  3749. if (target === undefined) {
  3750. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3751. target = new Vector3();
  3752. }
  3753. target.copy(point);
  3754. if (deltaLengthSq > this.radius * this.radius) {
  3755. target.sub(this.center).normalize();
  3756. target.multiplyScalar(this.radius).add(this.center);
  3757. }
  3758. return target;
  3759. };
  3760. _proto.getBoundingBox = function getBoundingBox(target) {
  3761. if (target === undefined) {
  3762. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3763. target = new Box3();
  3764. }
  3765. if (this.isEmpty()) {
  3766. // Empty sphere produces empty bounding box
  3767. target.makeEmpty();
  3768. return target;
  3769. }
  3770. target.set(this.center, this.center);
  3771. target.expandByScalar(this.radius);
  3772. return target;
  3773. };
  3774. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3775. this.center.applyMatrix4(matrix);
  3776. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3777. return this;
  3778. };
  3779. _proto.translate = function translate(offset) {
  3780. this.center.add(offset);
  3781. return this;
  3782. };
  3783. _proto.equals = function equals(sphere) {
  3784. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3785. };
  3786. return Sphere;
  3787. }();
  3788. var _vector$2 = /*@__PURE__*/new Vector3();
  3789. var _segCenter = /*@__PURE__*/new Vector3();
  3790. var _segDir = /*@__PURE__*/new Vector3();
  3791. var _diff = /*@__PURE__*/new Vector3();
  3792. var _edge1 = /*@__PURE__*/new Vector3();
  3793. var _edge2 = /*@__PURE__*/new Vector3();
  3794. var _normal = /*@__PURE__*/new Vector3();
  3795. var Ray = /*#__PURE__*/function () {
  3796. function Ray(origin, direction) {
  3797. this.origin = origin !== undefined ? origin : new Vector3();
  3798. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3799. }
  3800. var _proto = Ray.prototype;
  3801. _proto.set = function set(origin, direction) {
  3802. this.origin.copy(origin);
  3803. this.direction.copy(direction);
  3804. return this;
  3805. };
  3806. _proto.clone = function clone() {
  3807. return new this.constructor().copy(this);
  3808. };
  3809. _proto.copy = function copy(ray) {
  3810. this.origin.copy(ray.origin);
  3811. this.direction.copy(ray.direction);
  3812. return this;
  3813. };
  3814. _proto.at = function at(t, target) {
  3815. if (target === undefined) {
  3816. console.warn('THREE.Ray: .at() target is now required');
  3817. target = new Vector3();
  3818. }
  3819. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3820. };
  3821. _proto.lookAt = function lookAt(v) {
  3822. this.direction.copy(v).sub(this.origin).normalize();
  3823. return this;
  3824. };
  3825. _proto.recast = function recast(t) {
  3826. this.origin.copy(this.at(t, _vector$2));
  3827. return this;
  3828. };
  3829. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3830. if (target === undefined) {
  3831. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3832. target = new Vector3();
  3833. }
  3834. target.subVectors(point, this.origin);
  3835. var directionDistance = target.dot(this.direction);
  3836. if (directionDistance < 0) {
  3837. return target.copy(this.origin);
  3838. }
  3839. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3840. };
  3841. _proto.distanceToPoint = function distanceToPoint(point) {
  3842. return Math.sqrt(this.distanceSqToPoint(point));
  3843. };
  3844. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3845. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3846. if (directionDistance < 0) {
  3847. return this.origin.distanceToSquared(point);
  3848. }
  3849. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3850. return _vector$2.distanceToSquared(point);
  3851. };
  3852. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3853. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3854. // It returns the min distance between the ray and the segment
  3855. // defined by v0 and v1
  3856. // It can also set two optional targets :
  3857. // - The closest point on the ray
  3858. // - The closest point on the segment
  3859. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3860. _segDir.copy(v1).sub(v0).normalize();
  3861. _diff.copy(this.origin).sub(_segCenter);
  3862. var segExtent = v0.distanceTo(v1) * 0.5;
  3863. var a01 = -this.direction.dot(_segDir);
  3864. var b0 = _diff.dot(this.direction);
  3865. var b1 = -_diff.dot(_segDir);
  3866. var c = _diff.lengthSq();
  3867. var det = Math.abs(1 - a01 * a01);
  3868. var s0, s1, sqrDist, extDet;
  3869. if (det > 0) {
  3870. // The ray and segment are not parallel.
  3871. s0 = a01 * b1 - b0;
  3872. s1 = a01 * b0 - b1;
  3873. extDet = segExtent * det;
  3874. if (s0 >= 0) {
  3875. if (s1 >= -extDet) {
  3876. if (s1 <= extDet) {
  3877. // region 0
  3878. // Minimum at interior points of ray and segment.
  3879. var invDet = 1 / det;
  3880. s0 *= invDet;
  3881. s1 *= invDet;
  3882. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3883. } else {
  3884. // region 1
  3885. s1 = segExtent;
  3886. s0 = Math.max(0, -(a01 * s1 + b0));
  3887. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3888. }
  3889. } else {
  3890. // region 5
  3891. s1 = -segExtent;
  3892. s0 = Math.max(0, -(a01 * s1 + b0));
  3893. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3894. }
  3895. } else {
  3896. if (s1 <= -extDet) {
  3897. // region 4
  3898. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3899. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3900. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3901. } else if (s1 <= extDet) {
  3902. // region 3
  3903. s0 = 0;
  3904. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3905. sqrDist = s1 * (s1 + 2 * b1) + c;
  3906. } else {
  3907. // region 2
  3908. s0 = Math.max(0, -(a01 * segExtent + b0));
  3909. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3910. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3911. }
  3912. }
  3913. } else {
  3914. // Ray and segment are parallel.
  3915. s1 = a01 > 0 ? -segExtent : segExtent;
  3916. s0 = Math.max(0, -(a01 * s1 + b0));
  3917. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3918. }
  3919. if (optionalPointOnRay) {
  3920. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3921. }
  3922. if (optionalPointOnSegment) {
  3923. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3924. }
  3925. return sqrDist;
  3926. };
  3927. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3928. _vector$2.subVectors(sphere.center, this.origin);
  3929. var tca = _vector$2.dot(this.direction);
  3930. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3931. var radius2 = sphere.radius * sphere.radius;
  3932. if (d2 > radius2) return null;
  3933. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3934. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3935. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3936. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3937. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3938. // in order to always return an intersect point that is in front of the ray.
  3939. if (t0 < 0) return this.at(t1, target); // else t0 is in front of the ray, so return the first collision point scaled by t0
  3940. return this.at(t0, target);
  3941. };
  3942. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3943. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3944. };
  3945. _proto.distanceToPlane = function distanceToPlane(plane) {
  3946. var denominator = plane.normal.dot(this.direction);
  3947. if (denominator === 0) {
  3948. // line is coplanar, return origin
  3949. if (plane.distanceToPoint(this.origin) === 0) {
  3950. return 0;
  3951. } // Null is preferable to undefined since undefined means.... it is undefined
  3952. return null;
  3953. }
  3954. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3955. return t >= 0 ? t : null;
  3956. };
  3957. _proto.intersectPlane = function intersectPlane(plane, target) {
  3958. var t = this.distanceToPlane(plane);
  3959. if (t === null) {
  3960. return null;
  3961. }
  3962. return this.at(t, target);
  3963. };
  3964. _proto.intersectsPlane = function intersectsPlane(plane) {
  3965. // check if the ray lies on the plane first
  3966. var distToPoint = plane.distanceToPoint(this.origin);
  3967. if (distToPoint === 0) {
  3968. return true;
  3969. }
  3970. var denominator = plane.normal.dot(this.direction);
  3971. if (denominator * distToPoint < 0) {
  3972. return true;
  3973. } // ray origin is behind the plane (and is pointing behind it)
  3974. return false;
  3975. };
  3976. _proto.intersectBox = function intersectBox(box, target) {
  3977. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3978. var invdirx = 1 / this.direction.x,
  3979. invdiry = 1 / this.direction.y,
  3980. invdirz = 1 / this.direction.z;
  3981. var origin = this.origin;
  3982. if (invdirx >= 0) {
  3983. tmin = (box.min.x - origin.x) * invdirx;
  3984. tmax = (box.max.x - origin.x) * invdirx;
  3985. } else {
  3986. tmin = (box.max.x - origin.x) * invdirx;
  3987. tmax = (box.min.x - origin.x) * invdirx;
  3988. }
  3989. if (invdiry >= 0) {
  3990. tymin = (box.min.y - origin.y) * invdiry;
  3991. tymax = (box.max.y - origin.y) * invdiry;
  3992. } else {
  3993. tymin = (box.max.y - origin.y) * invdiry;
  3994. tymax = (box.min.y - origin.y) * invdiry;
  3995. }
  3996. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3997. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3998. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3999. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  4000. if (invdirz >= 0) {
  4001. tzmin = (box.min.z - origin.z) * invdirz;
  4002. tzmax = (box.max.z - origin.z) * invdirz;
  4003. } else {
  4004. tzmin = (box.max.z - origin.z) * invdirz;
  4005. tzmax = (box.min.z - origin.z) * invdirz;
  4006. }
  4007. if (tmin > tzmax || tzmin > tmax) return null;
  4008. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  4009. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  4010. if (tmax < 0) return null;
  4011. return this.at(tmin >= 0 ? tmin : tmax, target);
  4012. };
  4013. _proto.intersectsBox = function intersectsBox(box) {
  4014. return this.intersectBox(box, _vector$2) !== null;
  4015. };
  4016. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  4017. // Compute the offset origin, edges, and normal.
  4018. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4019. _edge1.subVectors(b, a);
  4020. _edge2.subVectors(c, a);
  4021. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4022. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4023. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4024. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4025. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4026. var DdN = this.direction.dot(_normal);
  4027. var sign;
  4028. if (DdN > 0) {
  4029. if (backfaceCulling) return null;
  4030. sign = 1;
  4031. } else if (DdN < 0) {
  4032. sign = -1;
  4033. DdN = -DdN;
  4034. } else {
  4035. return null;
  4036. }
  4037. _diff.subVectors(this.origin, a);
  4038. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  4039. if (DdQxE2 < 0) {
  4040. return null;
  4041. }
  4042. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  4043. if (DdE1xQ < 0) {
  4044. return null;
  4045. } // b1+b2 > 1, no intersection
  4046. if (DdQxE2 + DdE1xQ > DdN) {
  4047. return null;
  4048. } // Line intersects triangle, check if ray does.
  4049. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  4050. if (QdN < 0) {
  4051. return null;
  4052. } // Ray intersects triangle.
  4053. return this.at(QdN / DdN, target);
  4054. };
  4055. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  4056. this.origin.applyMatrix4(matrix4);
  4057. this.direction.transformDirection(matrix4);
  4058. return this;
  4059. };
  4060. _proto.equals = function equals(ray) {
  4061. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  4062. };
  4063. return Ray;
  4064. }();
  4065. var Matrix4 = /*#__PURE__*/function () {
  4066. function Matrix4() {
  4067. Object.defineProperty(this, 'isMatrix4', {
  4068. value: true
  4069. });
  4070. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  4071. if (arguments.length > 0) {
  4072. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  4073. }
  4074. }
  4075. var _proto = Matrix4.prototype;
  4076. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  4077. var te = this.elements;
  4078. te[0] = n11;
  4079. te[4] = n12;
  4080. te[8] = n13;
  4081. te[12] = n14;
  4082. te[1] = n21;
  4083. te[5] = n22;
  4084. te[9] = n23;
  4085. te[13] = n24;
  4086. te[2] = n31;
  4087. te[6] = n32;
  4088. te[10] = n33;
  4089. te[14] = n34;
  4090. te[3] = n41;
  4091. te[7] = n42;
  4092. te[11] = n43;
  4093. te[15] = n44;
  4094. return this;
  4095. };
  4096. _proto.identity = function identity() {
  4097. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4098. return this;
  4099. };
  4100. _proto.clone = function clone() {
  4101. return new Matrix4().fromArray(this.elements);
  4102. };
  4103. _proto.copy = function copy(m) {
  4104. var te = this.elements;
  4105. var me = m.elements;
  4106. te[0] = me[0];
  4107. te[1] = me[1];
  4108. te[2] = me[2];
  4109. te[3] = me[3];
  4110. te[4] = me[4];
  4111. te[5] = me[5];
  4112. te[6] = me[6];
  4113. te[7] = me[7];
  4114. te[8] = me[8];
  4115. te[9] = me[9];
  4116. te[10] = me[10];
  4117. te[11] = me[11];
  4118. te[12] = me[12];
  4119. te[13] = me[13];
  4120. te[14] = me[14];
  4121. te[15] = me[15];
  4122. return this;
  4123. };
  4124. _proto.copyPosition = function copyPosition(m) {
  4125. var te = this.elements,
  4126. me = m.elements;
  4127. te[12] = me[12];
  4128. te[13] = me[13];
  4129. te[14] = me[14];
  4130. return this;
  4131. };
  4132. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  4133. var me = m.elements;
  4134. this.set(me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1);
  4135. return this;
  4136. };
  4137. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  4138. xAxis.setFromMatrixColumn(this, 0);
  4139. yAxis.setFromMatrixColumn(this, 1);
  4140. zAxis.setFromMatrixColumn(this, 2);
  4141. return this;
  4142. };
  4143. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  4144. this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
  4145. return this;
  4146. };
  4147. _proto.extractRotation = function extractRotation(m) {
  4148. // this method does not support reflection matrices
  4149. var te = this.elements;
  4150. var me = m.elements;
  4151. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  4152. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  4153. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  4154. te[0] = me[0] * scaleX;
  4155. te[1] = me[1] * scaleX;
  4156. te[2] = me[2] * scaleX;
  4157. te[3] = 0;
  4158. te[4] = me[4] * scaleY;
  4159. te[5] = me[5] * scaleY;
  4160. te[6] = me[6] * scaleY;
  4161. te[7] = 0;
  4162. te[8] = me[8] * scaleZ;
  4163. te[9] = me[9] * scaleZ;
  4164. te[10] = me[10] * scaleZ;
  4165. te[11] = 0;
  4166. te[12] = 0;
  4167. te[13] = 0;
  4168. te[14] = 0;
  4169. te[15] = 1;
  4170. return this;
  4171. };
  4172. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  4173. if (!(euler && euler.isEuler)) {
  4174. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  4175. }
  4176. var te = this.elements;
  4177. var x = euler.x,
  4178. y = euler.y,
  4179. z = euler.z;
  4180. var a = Math.cos(x),
  4181. b = Math.sin(x);
  4182. var c = Math.cos(y),
  4183. d = Math.sin(y);
  4184. var e = Math.cos(z),
  4185. f = Math.sin(z);
  4186. if (euler.order === 'XYZ') {
  4187. var ae = a * e,
  4188. af = a * f,
  4189. be = b * e,
  4190. bf = b * f;
  4191. te[0] = c * e;
  4192. te[4] = -c * f;
  4193. te[8] = d;
  4194. te[1] = af + be * d;
  4195. te[5] = ae - bf * d;
  4196. te[9] = -b * c;
  4197. te[2] = bf - ae * d;
  4198. te[6] = be + af * d;
  4199. te[10] = a * c;
  4200. } else if (euler.order === 'YXZ') {
  4201. var ce = c * e,
  4202. cf = c * f,
  4203. de = d * e,
  4204. df = d * f;
  4205. te[0] = ce + df * b;
  4206. te[4] = de * b - cf;
  4207. te[8] = a * d;
  4208. te[1] = a * f;
  4209. te[5] = a * e;
  4210. te[9] = -b;
  4211. te[2] = cf * b - de;
  4212. te[6] = df + ce * b;
  4213. te[10] = a * c;
  4214. } else if (euler.order === 'ZXY') {
  4215. var _ce = c * e,
  4216. _cf = c * f,
  4217. _de = d * e,
  4218. _df = d * f;
  4219. te[0] = _ce - _df * b;
  4220. te[4] = -a * f;
  4221. te[8] = _de + _cf * b;
  4222. te[1] = _cf + _de * b;
  4223. te[5] = a * e;
  4224. te[9] = _df - _ce * b;
  4225. te[2] = -a * d;
  4226. te[6] = b;
  4227. te[10] = a * c;
  4228. } else if (euler.order === 'ZYX') {
  4229. var _ae = a * e,
  4230. _af = a * f,
  4231. _be = b * e,
  4232. _bf = b * f;
  4233. te[0] = c * e;
  4234. te[4] = _be * d - _af;
  4235. te[8] = _ae * d + _bf;
  4236. te[1] = c * f;
  4237. te[5] = _bf * d + _ae;
  4238. te[9] = _af * d - _be;
  4239. te[2] = -d;
  4240. te[6] = b * c;
  4241. te[10] = a * c;
  4242. } else if (euler.order === 'YZX') {
  4243. var ac = a * c,
  4244. ad = a * d,
  4245. bc = b * c,
  4246. bd = b * d;
  4247. te[0] = c * e;
  4248. te[4] = bd - ac * f;
  4249. te[8] = bc * f + ad;
  4250. te[1] = f;
  4251. te[5] = a * e;
  4252. te[9] = -b * e;
  4253. te[2] = -d * e;
  4254. te[6] = ad * f + bc;
  4255. te[10] = ac - bd * f;
  4256. } else if (euler.order === 'XZY') {
  4257. var _ac = a * c,
  4258. _ad = a * d,
  4259. _bc = b * c,
  4260. _bd = b * d;
  4261. te[0] = c * e;
  4262. te[4] = -f;
  4263. te[8] = d * e;
  4264. te[1] = _ac * f + _bd;
  4265. te[5] = a * e;
  4266. te[9] = _ad * f - _bc;
  4267. te[2] = _bc * f - _ad;
  4268. te[6] = b * e;
  4269. te[10] = _bd * f + _ac;
  4270. } // bottom row
  4271. te[3] = 0;
  4272. te[7] = 0;
  4273. te[11] = 0; // last column
  4274. te[12] = 0;
  4275. te[13] = 0;
  4276. te[14] = 0;
  4277. te[15] = 1;
  4278. return this;
  4279. };
  4280. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  4281. return this.compose(_zero, q, _one);
  4282. };
  4283. _proto.lookAt = function lookAt(eye, target, up) {
  4284. var te = this.elements;
  4285. _z.subVectors(eye, target);
  4286. if (_z.lengthSq() === 0) {
  4287. // eye and target are in the same position
  4288. _z.z = 1;
  4289. }
  4290. _z.normalize();
  4291. _x.crossVectors(up, _z);
  4292. if (_x.lengthSq() === 0) {
  4293. // up and z are parallel
  4294. if (Math.abs(up.z) === 1) {
  4295. _z.x += 0.0001;
  4296. } else {
  4297. _z.z += 0.0001;
  4298. }
  4299. _z.normalize();
  4300. _x.crossVectors(up, _z);
  4301. }
  4302. _x.normalize();
  4303. _y.crossVectors(_z, _x);
  4304. te[0] = _x.x;
  4305. te[4] = _y.x;
  4306. te[8] = _z.x;
  4307. te[1] = _x.y;
  4308. te[5] = _y.y;
  4309. te[9] = _z.y;
  4310. te[2] = _x.z;
  4311. te[6] = _y.z;
  4312. te[10] = _z.z;
  4313. return this;
  4314. };
  4315. _proto.multiply = function multiply(m, n) {
  4316. if (n !== undefined) {
  4317. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  4318. return this.multiplyMatrices(m, n);
  4319. }
  4320. return this.multiplyMatrices(this, m);
  4321. };
  4322. _proto.premultiply = function premultiply(m) {
  4323. return this.multiplyMatrices(m, this);
  4324. };
  4325. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  4326. var ae = a.elements;
  4327. var be = b.elements;
  4328. var te = this.elements;
  4329. var a11 = ae[0],
  4330. a12 = ae[4],
  4331. a13 = ae[8],
  4332. a14 = ae[12];
  4333. var a21 = ae[1],
  4334. a22 = ae[5],
  4335. a23 = ae[9],
  4336. a24 = ae[13];
  4337. var a31 = ae[2],
  4338. a32 = ae[6],
  4339. a33 = ae[10],
  4340. a34 = ae[14];
  4341. var a41 = ae[3],
  4342. a42 = ae[7],
  4343. a43 = ae[11],
  4344. a44 = ae[15];
  4345. var b11 = be[0],
  4346. b12 = be[4],
  4347. b13 = be[8],
  4348. b14 = be[12];
  4349. var b21 = be[1],
  4350. b22 = be[5],
  4351. b23 = be[9],
  4352. b24 = be[13];
  4353. var b31 = be[2],
  4354. b32 = be[6],
  4355. b33 = be[10],
  4356. b34 = be[14];
  4357. var b41 = be[3],
  4358. b42 = be[7],
  4359. b43 = be[11],
  4360. b44 = be[15];
  4361. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  4362. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  4363. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  4364. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  4365. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  4366. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  4367. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  4368. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  4369. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  4370. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  4371. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  4372. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  4373. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  4374. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  4375. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  4376. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  4377. return this;
  4378. };
  4379. _proto.multiplyScalar = function multiplyScalar(s) {
  4380. var te = this.elements;
  4381. te[0] *= s;
  4382. te[4] *= s;
  4383. te[8] *= s;
  4384. te[12] *= s;
  4385. te[1] *= s;
  4386. te[5] *= s;
  4387. te[9] *= s;
  4388. te[13] *= s;
  4389. te[2] *= s;
  4390. te[6] *= s;
  4391. te[10] *= s;
  4392. te[14] *= s;
  4393. te[3] *= s;
  4394. te[7] *= s;
  4395. te[11] *= s;
  4396. te[15] *= s;
  4397. return this;
  4398. };
  4399. _proto.determinant = function determinant() {
  4400. var te = this.elements;
  4401. var n11 = te[0],
  4402. n12 = te[4],
  4403. n13 = te[8],
  4404. n14 = te[12];
  4405. var n21 = te[1],
  4406. n22 = te[5],
  4407. n23 = te[9],
  4408. n24 = te[13];
  4409. var n31 = te[2],
  4410. n32 = te[6],
  4411. n33 = te[10],
  4412. n34 = te[14];
  4413. var n41 = te[3],
  4414. n42 = te[7],
  4415. n43 = te[11],
  4416. n44 = te[15]; //TODO: make this more efficient
  4417. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  4418. return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31);
  4419. };
  4420. _proto.transpose = function transpose() {
  4421. var te = this.elements;
  4422. var tmp;
  4423. tmp = te[1];
  4424. te[1] = te[4];
  4425. te[4] = tmp;
  4426. tmp = te[2];
  4427. te[2] = te[8];
  4428. te[8] = tmp;
  4429. tmp = te[6];
  4430. te[6] = te[9];
  4431. te[9] = tmp;
  4432. tmp = te[3];
  4433. te[3] = te[12];
  4434. te[12] = tmp;
  4435. tmp = te[7];
  4436. te[7] = te[13];
  4437. te[13] = tmp;
  4438. tmp = te[11];
  4439. te[11] = te[14];
  4440. te[14] = tmp;
  4441. return this;
  4442. };
  4443. _proto.setPosition = function setPosition(x, y, z) {
  4444. var te = this.elements;
  4445. if (x.isVector3) {
  4446. te[12] = x.x;
  4447. te[13] = x.y;
  4448. te[14] = x.z;
  4449. } else {
  4450. te[12] = x;
  4451. te[13] = y;
  4452. te[14] = z;
  4453. }
  4454. return this;
  4455. };
  4456. _proto.invert = function invert() {
  4457. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  4458. var te = this.elements,
  4459. n11 = te[0],
  4460. n21 = te[1],
  4461. n31 = te[2],
  4462. n41 = te[3],
  4463. n12 = te[4],
  4464. n22 = te[5],
  4465. n32 = te[6],
  4466. n42 = te[7],
  4467. n13 = te[8],
  4468. n23 = te[9],
  4469. n33 = te[10],
  4470. n43 = te[11],
  4471. n14 = te[12],
  4472. n24 = te[13],
  4473. n34 = te[14],
  4474. n44 = te[15],
  4475. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  4476. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  4477. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  4478. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  4479. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  4480. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  4481. var detInv = 1 / det;
  4482. te[0] = t11 * detInv;
  4483. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  4484. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  4485. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  4486. te[4] = t12 * detInv;
  4487. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  4488. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  4489. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  4490. te[8] = t13 * detInv;
  4491. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  4492. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  4493. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  4494. te[12] = t14 * detInv;
  4495. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  4496. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  4497. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  4498. return this;
  4499. };
  4500. _proto.scale = function scale(v) {
  4501. var te = this.elements;
  4502. var x = v.x,
  4503. y = v.y,
  4504. z = v.z;
  4505. te[0] *= x;
  4506. te[4] *= y;
  4507. te[8] *= z;
  4508. te[1] *= x;
  4509. te[5] *= y;
  4510. te[9] *= z;
  4511. te[2] *= x;
  4512. te[6] *= y;
  4513. te[10] *= z;
  4514. te[3] *= x;
  4515. te[7] *= y;
  4516. te[11] *= z;
  4517. return this;
  4518. };
  4519. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  4520. var te = this.elements;
  4521. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  4522. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  4523. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  4524. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  4525. };
  4526. _proto.makeTranslation = function makeTranslation(x, y, z) {
  4527. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  4528. return this;
  4529. };
  4530. _proto.makeRotationX = function makeRotationX(theta) {
  4531. var c = Math.cos(theta),
  4532. s = Math.sin(theta);
  4533. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  4534. return this;
  4535. };
  4536. _proto.makeRotationY = function makeRotationY(theta) {
  4537. var c = Math.cos(theta),
  4538. s = Math.sin(theta);
  4539. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  4540. return this;
  4541. };
  4542. _proto.makeRotationZ = function makeRotationZ(theta) {
  4543. var c = Math.cos(theta),
  4544. s = Math.sin(theta);
  4545. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4546. return this;
  4547. };
  4548. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  4549. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4550. var c = Math.cos(angle);
  4551. var s = Math.sin(angle);
  4552. var t = 1 - c;
  4553. var x = axis.x,
  4554. y = axis.y,
  4555. z = axis.z;
  4556. var tx = t * x,
  4557. ty = t * y;
  4558. this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
  4559. return this;
  4560. };
  4561. _proto.makeScale = function makeScale(x, y, z) {
  4562. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  4563. return this;
  4564. };
  4565. _proto.makeShear = function makeShear(x, y, z) {
  4566. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  4567. return this;
  4568. };
  4569. _proto.compose = function compose(position, quaternion, scale) {
  4570. var te = this.elements;
  4571. var x = quaternion._x,
  4572. y = quaternion._y,
  4573. z = quaternion._z,
  4574. w = quaternion._w;
  4575. var x2 = x + x,
  4576. y2 = y + y,
  4577. z2 = z + z;
  4578. var xx = x * x2,
  4579. xy = x * y2,
  4580. xz = x * z2;
  4581. var yy = y * y2,
  4582. yz = y * z2,
  4583. zz = z * z2;
  4584. var wx = w * x2,
  4585. wy = w * y2,
  4586. wz = w * z2;
  4587. var sx = scale.x,
  4588. sy = scale.y,
  4589. sz = scale.z;
  4590. te[0] = (1 - (yy + zz)) * sx;
  4591. te[1] = (xy + wz) * sx;
  4592. te[2] = (xz - wy) * sx;
  4593. te[3] = 0;
  4594. te[4] = (xy - wz) * sy;
  4595. te[5] = (1 - (xx + zz)) * sy;
  4596. te[6] = (yz + wx) * sy;
  4597. te[7] = 0;
  4598. te[8] = (xz + wy) * sz;
  4599. te[9] = (yz - wx) * sz;
  4600. te[10] = (1 - (xx + yy)) * sz;
  4601. te[11] = 0;
  4602. te[12] = position.x;
  4603. te[13] = position.y;
  4604. te[14] = position.z;
  4605. te[15] = 1;
  4606. return this;
  4607. };
  4608. _proto.decompose = function decompose(position, quaternion, scale) {
  4609. var te = this.elements;
  4610. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  4611. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  4612. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  4613. var det = this.determinant();
  4614. if (det < 0) sx = -sx;
  4615. position.x = te[12];
  4616. position.y = te[13];
  4617. position.z = te[14]; // scale the rotation part
  4618. _m1.copy(this);
  4619. var invSX = 1 / sx;
  4620. var invSY = 1 / sy;
  4621. var invSZ = 1 / sz;
  4622. _m1.elements[0] *= invSX;
  4623. _m1.elements[1] *= invSX;
  4624. _m1.elements[2] *= invSX;
  4625. _m1.elements[4] *= invSY;
  4626. _m1.elements[5] *= invSY;
  4627. _m1.elements[6] *= invSY;
  4628. _m1.elements[8] *= invSZ;
  4629. _m1.elements[9] *= invSZ;
  4630. _m1.elements[10] *= invSZ;
  4631. quaternion.setFromRotationMatrix(_m1);
  4632. scale.x = sx;
  4633. scale.y = sy;
  4634. scale.z = sz;
  4635. return this;
  4636. };
  4637. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  4638. if (far === undefined) {
  4639. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  4640. }
  4641. var te = this.elements;
  4642. var x = 2 * near / (right - left);
  4643. var y = 2 * near / (top - bottom);
  4644. var a = (right + left) / (right - left);
  4645. var b = (top + bottom) / (top - bottom);
  4646. var c = -(far + near) / (far - near);
  4647. var d = -2 * far * near / (far - near);
  4648. te[0] = x;
  4649. te[4] = 0;
  4650. te[8] = a;
  4651. te[12] = 0;
  4652. te[1] = 0;
  4653. te[5] = y;
  4654. te[9] = b;
  4655. te[13] = 0;
  4656. te[2] = 0;
  4657. te[6] = 0;
  4658. te[10] = c;
  4659. te[14] = d;
  4660. te[3] = 0;
  4661. te[7] = 0;
  4662. te[11] = -1;
  4663. te[15] = 0;
  4664. return this;
  4665. };
  4666. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  4667. var te = this.elements;
  4668. var w = 1.0 / (right - left);
  4669. var h = 1.0 / (top - bottom);
  4670. var p = 1.0 / (far - near);
  4671. var x = (right + left) * w;
  4672. var y = (top + bottom) * h;
  4673. var z = (far + near) * p;
  4674. te[0] = 2 * w;
  4675. te[4] = 0;
  4676. te[8] = 0;
  4677. te[12] = -x;
  4678. te[1] = 0;
  4679. te[5] = 2 * h;
  4680. te[9] = 0;
  4681. te[13] = -y;
  4682. te[2] = 0;
  4683. te[6] = 0;
  4684. te[10] = -2 * p;
  4685. te[14] = -z;
  4686. te[3] = 0;
  4687. te[7] = 0;
  4688. te[11] = 0;
  4689. te[15] = 1;
  4690. return this;
  4691. };
  4692. _proto.equals = function equals(matrix) {
  4693. var te = this.elements;
  4694. var me = matrix.elements;
  4695. for (var i = 0; i < 16; i++) {
  4696. if (te[i] !== me[i]) return false;
  4697. }
  4698. return true;
  4699. };
  4700. _proto.fromArray = function fromArray(array, offset) {
  4701. if (offset === void 0) {
  4702. offset = 0;
  4703. }
  4704. for (var i = 0; i < 16; i++) {
  4705. this.elements[i] = array[i + offset];
  4706. }
  4707. return this;
  4708. };
  4709. _proto.toArray = function toArray(array, offset) {
  4710. if (array === void 0) {
  4711. array = [];
  4712. }
  4713. if (offset === void 0) {
  4714. offset = 0;
  4715. }
  4716. var te = this.elements;
  4717. array[offset] = te[0];
  4718. array[offset + 1] = te[1];
  4719. array[offset + 2] = te[2];
  4720. array[offset + 3] = te[3];
  4721. array[offset + 4] = te[4];
  4722. array[offset + 5] = te[5];
  4723. array[offset + 6] = te[6];
  4724. array[offset + 7] = te[7];
  4725. array[offset + 8] = te[8];
  4726. array[offset + 9] = te[9];
  4727. array[offset + 10] = te[10];
  4728. array[offset + 11] = te[11];
  4729. array[offset + 12] = te[12];
  4730. array[offset + 13] = te[13];
  4731. array[offset + 14] = te[14];
  4732. array[offset + 15] = te[15];
  4733. return array;
  4734. };
  4735. return Matrix4;
  4736. }();
  4737. var _v1$1 = /*@__PURE__*/new Vector3();
  4738. var _m1 = /*@__PURE__*/new Matrix4();
  4739. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4740. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4741. var _x = /*@__PURE__*/new Vector3();
  4742. var _y = /*@__PURE__*/new Vector3();
  4743. var _z = /*@__PURE__*/new Vector3();
  4744. var Euler = /*#__PURE__*/function () {
  4745. function Euler(x, y, z, order) {
  4746. if (x === void 0) {
  4747. x = 0;
  4748. }
  4749. if (y === void 0) {
  4750. y = 0;
  4751. }
  4752. if (z === void 0) {
  4753. z = 0;
  4754. }
  4755. if (order === void 0) {
  4756. order = Euler.DefaultOrder;
  4757. }
  4758. Object.defineProperty(this, 'isEuler', {
  4759. value: true
  4760. });
  4761. this._x = x;
  4762. this._y = y;
  4763. this._z = z;
  4764. this._order = order;
  4765. }
  4766. var _proto = Euler.prototype;
  4767. _proto.set = function set(x, y, z, order) {
  4768. this._x = x;
  4769. this._y = y;
  4770. this._z = z;
  4771. this._order = order || this._order;
  4772. this._onChangeCallback();
  4773. return this;
  4774. };
  4775. _proto.clone = function clone() {
  4776. return new this.constructor(this._x, this._y, this._z, this._order);
  4777. };
  4778. _proto.copy = function copy(euler) {
  4779. this._x = euler._x;
  4780. this._y = euler._y;
  4781. this._z = euler._z;
  4782. this._order = euler._order;
  4783. this._onChangeCallback();
  4784. return this;
  4785. };
  4786. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4787. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4788. var te = m.elements;
  4789. var m11 = te[0],
  4790. m12 = te[4],
  4791. m13 = te[8];
  4792. var m21 = te[1],
  4793. m22 = te[5],
  4794. m23 = te[9];
  4795. var m31 = te[2],
  4796. m32 = te[6],
  4797. m33 = te[10];
  4798. order = order || this._order;
  4799. switch (order) {
  4800. case 'XYZ':
  4801. this._y = Math.asin(clamp(m13, -1, 1));
  4802. if (Math.abs(m13) < 0.9999999) {
  4803. this._x = Math.atan2(-m23, m33);
  4804. this._z = Math.atan2(-m12, m11);
  4805. } else {
  4806. this._x = Math.atan2(m32, m22);
  4807. this._z = 0;
  4808. }
  4809. break;
  4810. case 'YXZ':
  4811. this._x = Math.asin(-clamp(m23, -1, 1));
  4812. if (Math.abs(m23) < 0.9999999) {
  4813. this._y = Math.atan2(m13, m33);
  4814. this._z = Math.atan2(m21, m22);
  4815. } else {
  4816. this._y = Math.atan2(-m31, m11);
  4817. this._z = 0;
  4818. }
  4819. break;
  4820. case 'ZXY':
  4821. this._x = Math.asin(clamp(m32, -1, 1));
  4822. if (Math.abs(m32) < 0.9999999) {
  4823. this._y = Math.atan2(-m31, m33);
  4824. this._z = Math.atan2(-m12, m22);
  4825. } else {
  4826. this._y = 0;
  4827. this._z = Math.atan2(m21, m11);
  4828. }
  4829. break;
  4830. case 'ZYX':
  4831. this._y = Math.asin(-clamp(m31, -1, 1));
  4832. if (Math.abs(m31) < 0.9999999) {
  4833. this._x = Math.atan2(m32, m33);
  4834. this._z = Math.atan2(m21, m11);
  4835. } else {
  4836. this._x = 0;
  4837. this._z = Math.atan2(-m12, m22);
  4838. }
  4839. break;
  4840. case 'YZX':
  4841. this._z = Math.asin(clamp(m21, -1, 1));
  4842. if (Math.abs(m21) < 0.9999999) {
  4843. this._x = Math.atan2(-m23, m22);
  4844. this._y = Math.atan2(-m31, m11);
  4845. } else {
  4846. this._x = 0;
  4847. this._y = Math.atan2(m13, m33);
  4848. }
  4849. break;
  4850. case 'XZY':
  4851. this._z = Math.asin(-clamp(m12, -1, 1));
  4852. if (Math.abs(m12) < 0.9999999) {
  4853. this._x = Math.atan2(m32, m22);
  4854. this._y = Math.atan2(m13, m11);
  4855. } else {
  4856. this._x = Math.atan2(-m23, m33);
  4857. this._y = 0;
  4858. }
  4859. break;
  4860. default:
  4861. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4862. }
  4863. this._order = order;
  4864. if (update !== false) this._onChangeCallback();
  4865. return this;
  4866. };
  4867. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4868. _matrix.makeRotationFromQuaternion(q);
  4869. return this.setFromRotationMatrix(_matrix, order, update);
  4870. };
  4871. _proto.setFromVector3 = function setFromVector3(v, order) {
  4872. return this.set(v.x, v.y, v.z, order || this._order);
  4873. };
  4874. _proto.reorder = function reorder(newOrder) {
  4875. // WARNING: this discards revolution information -bhouston
  4876. _quaternion$1.setFromEuler(this);
  4877. return this.setFromQuaternion(_quaternion$1, newOrder);
  4878. };
  4879. _proto.equals = function equals(euler) {
  4880. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4881. };
  4882. _proto.fromArray = function fromArray(array) {
  4883. this._x = array[0];
  4884. this._y = array[1];
  4885. this._z = array[2];
  4886. if (array[3] !== undefined) this._order = array[3];
  4887. this._onChangeCallback();
  4888. return this;
  4889. };
  4890. _proto.toArray = function toArray(array, offset) {
  4891. if (array === void 0) {
  4892. array = [];
  4893. }
  4894. if (offset === void 0) {
  4895. offset = 0;
  4896. }
  4897. array[offset] = this._x;
  4898. array[offset + 1] = this._y;
  4899. array[offset + 2] = this._z;
  4900. array[offset + 3] = this._order;
  4901. return array;
  4902. };
  4903. _proto.toVector3 = function toVector3(optionalResult) {
  4904. if (optionalResult) {
  4905. return optionalResult.set(this._x, this._y, this._z);
  4906. } else {
  4907. return new Vector3(this._x, this._y, this._z);
  4908. }
  4909. };
  4910. _proto._onChange = function _onChange(callback) {
  4911. this._onChangeCallback = callback;
  4912. return this;
  4913. };
  4914. _proto._onChangeCallback = function _onChangeCallback() {};
  4915. _createClass(Euler, [{
  4916. key: "x",
  4917. get: function get() {
  4918. return this._x;
  4919. },
  4920. set: function set(value) {
  4921. this._x = value;
  4922. this._onChangeCallback();
  4923. }
  4924. }, {
  4925. key: "y",
  4926. get: function get() {
  4927. return this._y;
  4928. },
  4929. set: function set(value) {
  4930. this._y = value;
  4931. this._onChangeCallback();
  4932. }
  4933. }, {
  4934. key: "z",
  4935. get: function get() {
  4936. return this._z;
  4937. },
  4938. set: function set(value) {
  4939. this._z = value;
  4940. this._onChangeCallback();
  4941. }
  4942. }, {
  4943. key: "order",
  4944. get: function get() {
  4945. return this._order;
  4946. },
  4947. set: function set(value) {
  4948. this._order = value;
  4949. this._onChangeCallback();
  4950. }
  4951. }]);
  4952. return Euler;
  4953. }();
  4954. Euler.DefaultOrder = 'XYZ';
  4955. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4956. var _matrix = /*@__PURE__*/new Matrix4();
  4957. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4958. var Layers = /*#__PURE__*/function () {
  4959. function Layers() {
  4960. this.mask = 1 | 0;
  4961. }
  4962. var _proto = Layers.prototype;
  4963. _proto.set = function set(channel) {
  4964. this.mask = 1 << channel | 0;
  4965. };
  4966. _proto.enable = function enable(channel) {
  4967. this.mask |= 1 << channel | 0;
  4968. };
  4969. _proto.enableAll = function enableAll() {
  4970. this.mask = 0xffffffff | 0;
  4971. };
  4972. _proto.toggle = function toggle(channel) {
  4973. this.mask ^= 1 << channel | 0;
  4974. };
  4975. _proto.disable = function disable(channel) {
  4976. this.mask &= ~(1 << channel | 0);
  4977. };
  4978. _proto.disableAll = function disableAll() {
  4979. this.mask = 0;
  4980. };
  4981. _proto.test = function test(layers) {
  4982. return (this.mask & layers.mask) !== 0;
  4983. };
  4984. return Layers;
  4985. }();
  4986. var _object3DId = 0;
  4987. var _v1$2 = new Vector3();
  4988. var _q1 = new Quaternion();
  4989. var _m1$1 = new Matrix4();
  4990. var _target = new Vector3();
  4991. var _position = new Vector3();
  4992. var _scale = new Vector3();
  4993. var _quaternion$2 = new Quaternion();
  4994. var _xAxis = new Vector3(1, 0, 0);
  4995. var _yAxis = new Vector3(0, 1, 0);
  4996. var _zAxis = new Vector3(0, 0, 1);
  4997. var _addedEvent = {
  4998. type: 'added'
  4999. };
  5000. var _removedEvent = {
  5001. type: 'removed'
  5002. };
  5003. function Object3D() {
  5004. Object.defineProperty(this, 'id', {
  5005. value: _object3DId++
  5006. });
  5007. this.uuid = MathUtils.generateUUID();
  5008. this.name = '';
  5009. this.type = 'Object3D';
  5010. this.parent = null;
  5011. this.children = [];
  5012. this.up = Object3D.DefaultUp.clone();
  5013. var position = new Vector3();
  5014. var rotation = new Euler();
  5015. var quaternion = new Quaternion();
  5016. var scale = new Vector3(1, 1, 1);
  5017. function onRotationChange() {
  5018. quaternion.setFromEuler(rotation, false);
  5019. }
  5020. function onQuaternionChange() {
  5021. rotation.setFromQuaternion(quaternion, undefined, false);
  5022. }
  5023. rotation._onChange(onRotationChange);
  5024. quaternion._onChange(onQuaternionChange);
  5025. Object.defineProperties(this, {
  5026. position: {
  5027. configurable: true,
  5028. enumerable: true,
  5029. value: position
  5030. },
  5031. rotation: {
  5032. configurable: true,
  5033. enumerable: true,
  5034. value: rotation
  5035. },
  5036. quaternion: {
  5037. configurable: true,
  5038. enumerable: true,
  5039. value: quaternion
  5040. },
  5041. scale: {
  5042. configurable: true,
  5043. enumerable: true,
  5044. value: scale
  5045. },
  5046. modelViewMatrix: {
  5047. value: new Matrix4()
  5048. },
  5049. normalMatrix: {
  5050. value: new Matrix3()
  5051. }
  5052. });
  5053. this.matrix = new Matrix4();
  5054. this.matrixWorld = new Matrix4();
  5055. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5056. this.matrixWorldNeedsUpdate = false;
  5057. this.layers = new Layers();
  5058. this.visible = true;
  5059. this.castShadow = false;
  5060. this.receiveShadow = false;
  5061. this.frustumCulled = true;
  5062. this.renderOrder = 0;
  5063. this.animations = [];
  5064. this.userData = {};
  5065. }
  5066. Object3D.DefaultUp = new Vector3(0, 1, 0);
  5067. Object3D.DefaultMatrixAutoUpdate = true;
  5068. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5069. constructor: Object3D,
  5070. isObject3D: true,
  5071. onBeforeRender: function onBeforeRender() {},
  5072. onAfterRender: function onAfterRender() {},
  5073. applyMatrix4: function applyMatrix4(matrix) {
  5074. if (this.matrixAutoUpdate) this.updateMatrix();
  5075. this.matrix.premultiply(matrix);
  5076. this.matrix.decompose(this.position, this.quaternion, this.scale);
  5077. },
  5078. applyQuaternion: function applyQuaternion(q) {
  5079. this.quaternion.premultiply(q);
  5080. return this;
  5081. },
  5082. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  5083. // assumes axis is normalized
  5084. this.quaternion.setFromAxisAngle(axis, angle);
  5085. },
  5086. setRotationFromEuler: function setRotationFromEuler(euler) {
  5087. this.quaternion.setFromEuler(euler, true);
  5088. },
  5089. setRotationFromMatrix: function setRotationFromMatrix(m) {
  5090. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5091. this.quaternion.setFromRotationMatrix(m);
  5092. },
  5093. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  5094. // assumes q is normalized
  5095. this.quaternion.copy(q);
  5096. },
  5097. rotateOnAxis: function rotateOnAxis(axis, angle) {
  5098. // rotate object on axis in object space
  5099. // axis is assumed to be normalized
  5100. _q1.setFromAxisAngle(axis, angle);
  5101. this.quaternion.multiply(_q1);
  5102. return this;
  5103. },
  5104. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  5105. // rotate object on axis in world space
  5106. // axis is assumed to be normalized
  5107. // method assumes no rotated parent
  5108. _q1.setFromAxisAngle(axis, angle);
  5109. this.quaternion.premultiply(_q1);
  5110. return this;
  5111. },
  5112. rotateX: function rotateX(angle) {
  5113. return this.rotateOnAxis(_xAxis, angle);
  5114. },
  5115. rotateY: function rotateY(angle) {
  5116. return this.rotateOnAxis(_yAxis, angle);
  5117. },
  5118. rotateZ: function rotateZ(angle) {
  5119. return this.rotateOnAxis(_zAxis, angle);
  5120. },
  5121. translateOnAxis: function translateOnAxis(axis, distance) {
  5122. // translate object by distance along axis in object space
  5123. // axis is assumed to be normalized
  5124. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  5125. this.position.add(_v1$2.multiplyScalar(distance));
  5126. return this;
  5127. },
  5128. translateX: function translateX(distance) {
  5129. return this.translateOnAxis(_xAxis, distance);
  5130. },
  5131. translateY: function translateY(distance) {
  5132. return this.translateOnAxis(_yAxis, distance);
  5133. },
  5134. translateZ: function translateZ(distance) {
  5135. return this.translateOnAxis(_zAxis, distance);
  5136. },
  5137. localToWorld: function localToWorld(vector) {
  5138. return vector.applyMatrix4(this.matrixWorld);
  5139. },
  5140. worldToLocal: function worldToLocal(vector) {
  5141. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  5142. },
  5143. lookAt: function lookAt(x, y, z) {
  5144. // This method does not support objects having non-uniformly-scaled parent(s)
  5145. if (x.isVector3) {
  5146. _target.copy(x);
  5147. } else {
  5148. _target.set(x, y, z);
  5149. }
  5150. var parent = this.parent;
  5151. this.updateWorldMatrix(true, false);
  5152. _position.setFromMatrixPosition(this.matrixWorld);
  5153. if (this.isCamera || this.isLight) {
  5154. _m1$1.lookAt(_position, _target, this.up);
  5155. } else {
  5156. _m1$1.lookAt(_target, _position, this.up);
  5157. }
  5158. this.quaternion.setFromRotationMatrix(_m1$1);
  5159. if (parent) {
  5160. _m1$1.extractRotation(parent.matrixWorld);
  5161. _q1.setFromRotationMatrix(_m1$1);
  5162. this.quaternion.premultiply(_q1.invert());
  5163. }
  5164. },
  5165. add: function add(object) {
  5166. if (arguments.length > 1) {
  5167. for (var i = 0; i < arguments.length; i++) {
  5168. this.add(arguments[i]);
  5169. }
  5170. return this;
  5171. }
  5172. if (object === this) {
  5173. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  5174. return this;
  5175. }
  5176. if (object && object.isObject3D) {
  5177. if (object.parent !== null) {
  5178. object.parent.remove(object);
  5179. }
  5180. object.parent = this;
  5181. this.children.push(object);
  5182. object.dispatchEvent(_addedEvent);
  5183. } else {
  5184. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  5185. }
  5186. return this;
  5187. },
  5188. remove: function remove(object) {
  5189. if (arguments.length > 1) {
  5190. for (var i = 0; i < arguments.length; i++) {
  5191. this.remove(arguments[i]);
  5192. }
  5193. return this;
  5194. }
  5195. var index = this.children.indexOf(object);
  5196. if (index !== -1) {
  5197. object.parent = null;
  5198. this.children.splice(index, 1);
  5199. object.dispatchEvent(_removedEvent);
  5200. }
  5201. return this;
  5202. },
  5203. clear: function clear() {
  5204. for (var i = 0; i < this.children.length; i++) {
  5205. var object = this.children[i];
  5206. object.parent = null;
  5207. object.dispatchEvent(_removedEvent);
  5208. }
  5209. this.children.length = 0;
  5210. return this;
  5211. },
  5212. attach: function attach(object) {
  5213. // adds object as a child of this, while maintaining the object's world transform
  5214. this.updateWorldMatrix(true, false);
  5215. _m1$1.copy(this.matrixWorld).invert();
  5216. if (object.parent !== null) {
  5217. object.parent.updateWorldMatrix(true, false);
  5218. _m1$1.multiply(object.parent.matrixWorld);
  5219. }
  5220. object.applyMatrix4(_m1$1);
  5221. this.add(object);
  5222. object.updateWorldMatrix(false, true);
  5223. return this;
  5224. },
  5225. getObjectById: function getObjectById(id) {
  5226. return this.getObjectByProperty('id', id);
  5227. },
  5228. getObjectByName: function getObjectByName(name) {
  5229. return this.getObjectByProperty('name', name);
  5230. },
  5231. getObjectByProperty: function getObjectByProperty(name, value) {
  5232. if (this[name] === value) return this;
  5233. for (var i = 0, l = this.children.length; i < l; i++) {
  5234. var child = this.children[i];
  5235. var object = child.getObjectByProperty(name, value);
  5236. if (object !== undefined) {
  5237. return object;
  5238. }
  5239. }
  5240. return undefined;
  5241. },
  5242. getWorldPosition: function getWorldPosition(target) {
  5243. if (target === undefined) {
  5244. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  5245. target = new Vector3();
  5246. }
  5247. this.updateWorldMatrix(true, false);
  5248. return target.setFromMatrixPosition(this.matrixWorld);
  5249. },
  5250. getWorldQuaternion: function getWorldQuaternion(target) {
  5251. if (target === undefined) {
  5252. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  5253. target = new Quaternion();
  5254. }
  5255. this.updateWorldMatrix(true, false);
  5256. this.matrixWorld.decompose(_position, target, _scale);
  5257. return target;
  5258. },
  5259. getWorldScale: function getWorldScale(target) {
  5260. if (target === undefined) {
  5261. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  5262. target = new Vector3();
  5263. }
  5264. this.updateWorldMatrix(true, false);
  5265. this.matrixWorld.decompose(_position, _quaternion$2, target);
  5266. return target;
  5267. },
  5268. getWorldDirection: function getWorldDirection(target) {
  5269. if (target === undefined) {
  5270. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  5271. target = new Vector3();
  5272. }
  5273. this.updateWorldMatrix(true, false);
  5274. var e = this.matrixWorld.elements;
  5275. return target.set(e[8], e[9], e[10]).normalize();
  5276. },
  5277. raycast: function raycast() {},
  5278. traverse: function traverse(callback) {
  5279. callback(this);
  5280. var children = this.children;
  5281. for (var i = 0, l = children.length; i < l; i++) {
  5282. children[i].traverse(callback);
  5283. }
  5284. },
  5285. traverseVisible: function traverseVisible(callback) {
  5286. if (this.visible === false) return;
  5287. callback(this);
  5288. var children = this.children;
  5289. for (var i = 0, l = children.length; i < l; i++) {
  5290. children[i].traverseVisible(callback);
  5291. }
  5292. },
  5293. traverseAncestors: function traverseAncestors(callback) {
  5294. var parent = this.parent;
  5295. if (parent !== null) {
  5296. callback(parent);
  5297. parent.traverseAncestors(callback);
  5298. }
  5299. },
  5300. updateMatrix: function updateMatrix() {
  5301. this.matrix.compose(this.position, this.quaternion, this.scale);
  5302. this.matrixWorldNeedsUpdate = true;
  5303. },
  5304. updateMatrixWorld: function updateMatrixWorld(force) {
  5305. if (this.matrixAutoUpdate) this.updateMatrix();
  5306. if (this.matrixWorldNeedsUpdate || force) {
  5307. if (this.parent === null) {
  5308. this.matrixWorld.copy(this.matrix);
  5309. } else {
  5310. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5311. }
  5312. this.matrixWorldNeedsUpdate = false;
  5313. force = true;
  5314. } // update children
  5315. var children = this.children;
  5316. for (var i = 0, l = children.length; i < l; i++) {
  5317. children[i].updateMatrixWorld(force);
  5318. }
  5319. },
  5320. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  5321. var parent = this.parent;
  5322. if (updateParents === true && parent !== null) {
  5323. parent.updateWorldMatrix(true, false);
  5324. }
  5325. if (this.matrixAutoUpdate) this.updateMatrix();
  5326. if (this.parent === null) {
  5327. this.matrixWorld.copy(this.matrix);
  5328. } else {
  5329. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5330. } // update children
  5331. if (updateChildren === true) {
  5332. var children = this.children;
  5333. for (var i = 0, l = children.length; i < l; i++) {
  5334. children[i].updateWorldMatrix(false, true);
  5335. }
  5336. }
  5337. },
  5338. toJSON: function toJSON(meta) {
  5339. // meta is a string when called from JSON.stringify
  5340. var isRootObject = meta === undefined || typeof meta === 'string';
  5341. var output = {}; // meta is a hash used to collect geometries, materials.
  5342. // not providing it implies that this is the root object
  5343. // being serialized.
  5344. if (isRootObject) {
  5345. // initialize meta obj
  5346. meta = {
  5347. geometries: {},
  5348. materials: {},
  5349. textures: {},
  5350. images: {},
  5351. shapes: {},
  5352. skeletons: {},
  5353. animations: {}
  5354. };
  5355. output.metadata = {
  5356. version: 4.5,
  5357. type: 'Object',
  5358. generator: 'Object3D.toJSON'
  5359. };
  5360. } // standard Object3D serialization
  5361. var object = {};
  5362. object.uuid = this.uuid;
  5363. object.type = this.type;
  5364. if (this.name !== '') object.name = this.name;
  5365. if (this.castShadow === true) object.castShadow = true;
  5366. if (this.receiveShadow === true) object.receiveShadow = true;
  5367. if (this.visible === false) object.visible = false;
  5368. if (this.frustumCulled === false) object.frustumCulled = false;
  5369. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  5370. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  5371. object.layers = this.layers.mask;
  5372. object.matrix = this.matrix.toArray();
  5373. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  5374. if (this.isInstancedMesh) {
  5375. object.type = 'InstancedMesh';
  5376. object.count = this.count;
  5377. object.instanceMatrix = this.instanceMatrix.toJSON();
  5378. } //
  5379. function serialize(library, element) {
  5380. if (library[element.uuid] === undefined) {
  5381. library[element.uuid] = element.toJSON(meta);
  5382. }
  5383. return element.uuid;
  5384. }
  5385. if (this.isMesh || this.isLine || this.isPoints) {
  5386. object.geometry = serialize(meta.geometries, this.geometry);
  5387. var parameters = this.geometry.parameters;
  5388. if (parameters !== undefined && parameters.shapes !== undefined) {
  5389. var shapes = parameters.shapes;
  5390. if (Array.isArray(shapes)) {
  5391. for (var i = 0, l = shapes.length; i < l; i++) {
  5392. var shape = shapes[i];
  5393. serialize(meta.shapes, shape);
  5394. }
  5395. } else {
  5396. serialize(meta.shapes, shapes);
  5397. }
  5398. }
  5399. }
  5400. if (this.isSkinnedMesh) {
  5401. object.bindMode = this.bindMode;
  5402. object.bindMatrix = this.bindMatrix.toArray();
  5403. if (this.skeleton !== undefined) {
  5404. serialize(meta.skeletons, this.skeleton);
  5405. object.skeleton = this.skeleton.uuid;
  5406. }
  5407. }
  5408. if (this.material !== undefined) {
  5409. if (Array.isArray(this.material)) {
  5410. var uuids = [];
  5411. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  5412. uuids.push(serialize(meta.materials, this.material[_i]));
  5413. }
  5414. object.material = uuids;
  5415. } else {
  5416. object.material = serialize(meta.materials, this.material);
  5417. }
  5418. } //
  5419. if (this.children.length > 0) {
  5420. object.children = [];
  5421. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  5422. object.children.push(this.children[_i2].toJSON(meta).object);
  5423. }
  5424. } //
  5425. if (this.animations.length > 0) {
  5426. object.animations = [];
  5427. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  5428. var animation = this.animations[_i3];
  5429. object.animations.push(serialize(meta.animations, animation));
  5430. }
  5431. }
  5432. if (isRootObject) {
  5433. var geometries = extractFromCache(meta.geometries);
  5434. var materials = extractFromCache(meta.materials);
  5435. var textures = extractFromCache(meta.textures);
  5436. var images = extractFromCache(meta.images);
  5437. var _shapes = extractFromCache(meta.shapes);
  5438. var skeletons = extractFromCache(meta.skeletons);
  5439. var animations = extractFromCache(meta.animations);
  5440. if (geometries.length > 0) output.geometries = geometries;
  5441. if (materials.length > 0) output.materials = materials;
  5442. if (textures.length > 0) output.textures = textures;
  5443. if (images.length > 0) output.images = images;
  5444. if (_shapes.length > 0) output.shapes = _shapes;
  5445. if (skeletons.length > 0) output.skeletons = skeletons;
  5446. if (animations.length > 0) output.animations = animations;
  5447. }
  5448. output.object = object;
  5449. return output; // extract data from the cache hash
  5450. // remove metadata on each item
  5451. // and return as array
  5452. function extractFromCache(cache) {
  5453. var values = [];
  5454. for (var key in cache) {
  5455. var data = cache[key];
  5456. delete data.metadata;
  5457. values.push(data);
  5458. }
  5459. return values;
  5460. }
  5461. },
  5462. clone: function clone(recursive) {
  5463. return new this.constructor().copy(this, recursive);
  5464. },
  5465. copy: function copy(source, recursive) {
  5466. if (recursive === void 0) {
  5467. recursive = true;
  5468. }
  5469. this.name = source.name;
  5470. this.up.copy(source.up);
  5471. this.position.copy(source.position);
  5472. this.rotation.order = source.rotation.order;
  5473. this.quaternion.copy(source.quaternion);
  5474. this.scale.copy(source.scale);
  5475. this.matrix.copy(source.matrix);
  5476. this.matrixWorld.copy(source.matrixWorld);
  5477. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5478. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5479. this.layers.mask = source.layers.mask;
  5480. this.visible = source.visible;
  5481. this.castShadow = source.castShadow;
  5482. this.receiveShadow = source.receiveShadow;
  5483. this.frustumCulled = source.frustumCulled;
  5484. this.renderOrder = source.renderOrder;
  5485. this.userData = JSON.parse(JSON.stringify(source.userData));
  5486. if (recursive === true) {
  5487. for (var i = 0; i < source.children.length; i++) {
  5488. var child = source.children[i];
  5489. this.add(child.clone());
  5490. }
  5491. }
  5492. return this;
  5493. }
  5494. });
  5495. var _vector1 = /*@__PURE__*/new Vector3();
  5496. var _vector2 = /*@__PURE__*/new Vector3();
  5497. var _normalMatrix = /*@__PURE__*/new Matrix3();
  5498. var Plane = /*#__PURE__*/function () {
  5499. function Plane(normal, constant) {
  5500. Object.defineProperty(this, 'isPlane', {
  5501. value: true
  5502. }); // normal is assumed to be normalized
  5503. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  5504. this.constant = constant !== undefined ? constant : 0;
  5505. }
  5506. var _proto = Plane.prototype;
  5507. _proto.set = function set(normal, constant) {
  5508. this.normal.copy(normal);
  5509. this.constant = constant;
  5510. return this;
  5511. };
  5512. _proto.setComponents = function setComponents(x, y, z, w) {
  5513. this.normal.set(x, y, z);
  5514. this.constant = w;
  5515. return this;
  5516. };
  5517. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  5518. this.normal.copy(normal);
  5519. this.constant = -point.dot(this.normal);
  5520. return this;
  5521. };
  5522. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  5523. var normal = _vector1.subVectors(c, b).cross(_vector2.subVectors(a, b)).normalize(); // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  5524. this.setFromNormalAndCoplanarPoint(normal, a);
  5525. return this;
  5526. };
  5527. _proto.clone = function clone() {
  5528. return new this.constructor().copy(this);
  5529. };
  5530. _proto.copy = function copy(plane) {
  5531. this.normal.copy(plane.normal);
  5532. this.constant = plane.constant;
  5533. return this;
  5534. };
  5535. _proto.normalize = function normalize() {
  5536. // Note: will lead to a divide by zero if the plane is invalid.
  5537. var inverseNormalLength = 1.0 / this.normal.length();
  5538. this.normal.multiplyScalar(inverseNormalLength);
  5539. this.constant *= inverseNormalLength;
  5540. return this;
  5541. };
  5542. _proto.negate = function negate() {
  5543. this.constant *= -1;
  5544. this.normal.negate();
  5545. return this;
  5546. };
  5547. _proto.distanceToPoint = function distanceToPoint(point) {
  5548. return this.normal.dot(point) + this.constant;
  5549. };
  5550. _proto.distanceToSphere = function distanceToSphere(sphere) {
  5551. return this.distanceToPoint(sphere.center) - sphere.radius;
  5552. };
  5553. _proto.projectPoint = function projectPoint(point, target) {
  5554. if (target === undefined) {
  5555. console.warn('THREE.Plane: .projectPoint() target is now required');
  5556. target = new Vector3();
  5557. }
  5558. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  5559. };
  5560. _proto.intersectLine = function intersectLine(line, target) {
  5561. if (target === undefined) {
  5562. console.warn('THREE.Plane: .intersectLine() target is now required');
  5563. target = new Vector3();
  5564. }
  5565. var direction = line.delta(_vector1);
  5566. var denominator = this.normal.dot(direction);
  5567. if (denominator === 0) {
  5568. // line is coplanar, return origin
  5569. if (this.distanceToPoint(line.start) === 0) {
  5570. return target.copy(line.start);
  5571. } // Unsure if this is the correct method to handle this case.
  5572. return undefined;
  5573. }
  5574. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  5575. if (t < 0 || t > 1) {
  5576. return undefined;
  5577. }
  5578. return target.copy(direction).multiplyScalar(t).add(line.start);
  5579. };
  5580. _proto.intersectsLine = function intersectsLine(line) {
  5581. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5582. var startSign = this.distanceToPoint(line.start);
  5583. var endSign = this.distanceToPoint(line.end);
  5584. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  5585. };
  5586. _proto.intersectsBox = function intersectsBox(box) {
  5587. return box.intersectsPlane(this);
  5588. };
  5589. _proto.intersectsSphere = function intersectsSphere(sphere) {
  5590. return sphere.intersectsPlane(this);
  5591. };
  5592. _proto.coplanarPoint = function coplanarPoint(target) {
  5593. if (target === undefined) {
  5594. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  5595. target = new Vector3();
  5596. }
  5597. return target.copy(this.normal).multiplyScalar(-this.constant);
  5598. };
  5599. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  5600. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  5601. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  5602. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  5603. this.constant = -referencePoint.dot(normal);
  5604. return this;
  5605. };
  5606. _proto.translate = function translate(offset) {
  5607. this.constant -= offset.dot(this.normal);
  5608. return this;
  5609. };
  5610. _proto.equals = function equals(plane) {
  5611. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  5612. };
  5613. return Plane;
  5614. }();
  5615. var _v0$1 = /*@__PURE__*/new Vector3();
  5616. var _v1$3 = /*@__PURE__*/new Vector3();
  5617. var _v2$1 = /*@__PURE__*/new Vector3();
  5618. var _v3 = /*@__PURE__*/new Vector3();
  5619. var _vab = /*@__PURE__*/new Vector3();
  5620. var _vac = /*@__PURE__*/new Vector3();
  5621. var _vbc = /*@__PURE__*/new Vector3();
  5622. var _vap = /*@__PURE__*/new Vector3();
  5623. var _vbp = /*@__PURE__*/new Vector3();
  5624. var _vcp = /*@__PURE__*/new Vector3();
  5625. var Triangle = /*#__PURE__*/function () {
  5626. function Triangle(a, b, c) {
  5627. this.a = a !== undefined ? a : new Vector3();
  5628. this.b = b !== undefined ? b : new Vector3();
  5629. this.c = c !== undefined ? c : new Vector3();
  5630. }
  5631. Triangle.getNormal = function getNormal(a, b, c, target) {
  5632. if (target === undefined) {
  5633. console.warn('THREE.Triangle: .getNormal() target is now required');
  5634. target = new Vector3();
  5635. }
  5636. target.subVectors(c, b);
  5637. _v0$1.subVectors(a, b);
  5638. target.cross(_v0$1);
  5639. var targetLengthSq = target.lengthSq();
  5640. if (targetLengthSq > 0) {
  5641. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  5642. }
  5643. return target.set(0, 0, 0);
  5644. } // static/instance method to calculate barycentric coordinates
  5645. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  5646. ;
  5647. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  5648. _v0$1.subVectors(c, a);
  5649. _v1$3.subVectors(b, a);
  5650. _v2$1.subVectors(point, a);
  5651. var dot00 = _v0$1.dot(_v0$1);
  5652. var dot01 = _v0$1.dot(_v1$3);
  5653. var dot02 = _v0$1.dot(_v2$1);
  5654. var dot11 = _v1$3.dot(_v1$3);
  5655. var dot12 = _v1$3.dot(_v2$1);
  5656. var denom = dot00 * dot11 - dot01 * dot01;
  5657. if (target === undefined) {
  5658. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  5659. target = new Vector3();
  5660. } // collinear or singular triangle
  5661. if (denom === 0) {
  5662. // arbitrary location outside of triangle?
  5663. // not sure if this is the best idea, maybe should be returning undefined
  5664. return target.set(-2, -1, -1);
  5665. }
  5666. var invDenom = 1 / denom;
  5667. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  5668. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  5669. return target.set(1 - u - v, v, u);
  5670. };
  5671. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  5672. this.getBarycoord(point, a, b, c, _v3);
  5673. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  5674. };
  5675. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  5676. this.getBarycoord(point, p1, p2, p3, _v3);
  5677. target.set(0, 0);
  5678. target.addScaledVector(uv1, _v3.x);
  5679. target.addScaledVector(uv2, _v3.y);
  5680. target.addScaledVector(uv3, _v3.z);
  5681. return target;
  5682. };
  5683. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  5684. _v0$1.subVectors(c, b);
  5685. _v1$3.subVectors(a, b); // strictly front facing
  5686. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  5687. };
  5688. var _proto = Triangle.prototype;
  5689. _proto.set = function set(a, b, c) {
  5690. this.a.copy(a);
  5691. this.b.copy(b);
  5692. this.c.copy(c);
  5693. return this;
  5694. };
  5695. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  5696. this.a.copy(points[i0]);
  5697. this.b.copy(points[i1]);
  5698. this.c.copy(points[i2]);
  5699. return this;
  5700. };
  5701. _proto.clone = function clone() {
  5702. return new this.constructor().copy(this);
  5703. };
  5704. _proto.copy = function copy(triangle) {
  5705. this.a.copy(triangle.a);
  5706. this.b.copy(triangle.b);
  5707. this.c.copy(triangle.c);
  5708. return this;
  5709. };
  5710. _proto.getArea = function getArea() {
  5711. _v0$1.subVectors(this.c, this.b);
  5712. _v1$3.subVectors(this.a, this.b);
  5713. return _v0$1.cross(_v1$3).length() * 0.5;
  5714. };
  5715. _proto.getMidpoint = function getMidpoint(target) {
  5716. if (target === undefined) {
  5717. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  5718. target = new Vector3();
  5719. }
  5720. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5721. };
  5722. _proto.getNormal = function getNormal(target) {
  5723. return Triangle.getNormal(this.a, this.b, this.c, target);
  5724. };
  5725. _proto.getPlane = function getPlane(target) {
  5726. if (target === undefined) {
  5727. console.warn('THREE.Triangle: .getPlane() target is now required');
  5728. target = new Plane();
  5729. }
  5730. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5731. };
  5732. _proto.getBarycoord = function getBarycoord(point, target) {
  5733. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5734. };
  5735. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5736. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5737. };
  5738. _proto.containsPoint = function containsPoint(point) {
  5739. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5740. };
  5741. _proto.isFrontFacing = function isFrontFacing(direction) {
  5742. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5743. };
  5744. _proto.intersectsBox = function intersectsBox(box) {
  5745. return box.intersectsTriangle(this);
  5746. };
  5747. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5748. if (target === undefined) {
  5749. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5750. target = new Vector3();
  5751. }
  5752. var a = this.a,
  5753. b = this.b,
  5754. c = this.c;
  5755. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5756. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5757. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5758. // basically, we're distinguishing which of the voronoi regions of the triangle
  5759. // the point lies in with the minimum amount of redundant computation.
  5760. _vab.subVectors(b, a);
  5761. _vac.subVectors(c, a);
  5762. _vap.subVectors(p, a);
  5763. var d1 = _vab.dot(_vap);
  5764. var d2 = _vac.dot(_vap);
  5765. if (d1 <= 0 && d2 <= 0) {
  5766. // vertex region of A; barycentric coords (1, 0, 0)
  5767. return target.copy(a);
  5768. }
  5769. _vbp.subVectors(p, b);
  5770. var d3 = _vab.dot(_vbp);
  5771. var d4 = _vac.dot(_vbp);
  5772. if (d3 >= 0 && d4 <= d3) {
  5773. // vertex region of B; barycentric coords (0, 1, 0)
  5774. return target.copy(b);
  5775. }
  5776. var vc = d1 * d4 - d3 * d2;
  5777. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5778. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5779. return target.copy(a).addScaledVector(_vab, v);
  5780. }
  5781. _vcp.subVectors(p, c);
  5782. var d5 = _vab.dot(_vcp);
  5783. var d6 = _vac.dot(_vcp);
  5784. if (d6 >= 0 && d5 <= d6) {
  5785. // vertex region of C; barycentric coords (0, 0, 1)
  5786. return target.copy(c);
  5787. }
  5788. var vb = d5 * d2 - d1 * d6;
  5789. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5790. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5791. return target.copy(a).addScaledVector(_vac, w);
  5792. }
  5793. var va = d3 * d6 - d5 * d4;
  5794. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5795. _vbc.subVectors(c, b);
  5796. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5797. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5798. } // face region
  5799. var denom = 1 / (va + vb + vc); // u = va * denom
  5800. v = vb * denom;
  5801. w = vc * denom;
  5802. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5803. };
  5804. _proto.equals = function equals(triangle) {
  5805. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5806. };
  5807. return Triangle;
  5808. }();
  5809. var materialId = 0;
  5810. function Material() {
  5811. Object.defineProperty(this, 'id', {
  5812. value: materialId++
  5813. });
  5814. this.uuid = MathUtils.generateUUID();
  5815. this.name = '';
  5816. this.type = 'Material';
  5817. this.fog = true;
  5818. this.blending = NormalBlending;
  5819. this.side = FrontSide;
  5820. this.vertexColors = false;
  5821. this.opacity = 1;
  5822. this.transparent = false;
  5823. this.blendSrc = SrcAlphaFactor;
  5824. this.blendDst = OneMinusSrcAlphaFactor;
  5825. this.blendEquation = AddEquation;
  5826. this.blendSrcAlpha = null;
  5827. this.blendDstAlpha = null;
  5828. this.blendEquationAlpha = null;
  5829. this.depthFunc = LessEqualDepth;
  5830. this.depthTest = true;
  5831. this.depthWrite = true;
  5832. this.stencilWriteMask = 0xff;
  5833. this.stencilFunc = AlwaysStencilFunc;
  5834. this.stencilRef = 0;
  5835. this.stencilFuncMask = 0xff;
  5836. this.stencilFail = KeepStencilOp;
  5837. this.stencilZFail = KeepStencilOp;
  5838. this.stencilZPass = KeepStencilOp;
  5839. this.stencilWrite = false;
  5840. this.clippingPlanes = null;
  5841. this.clipIntersection = false;
  5842. this.clipShadows = false;
  5843. this.shadowSide = null;
  5844. this.colorWrite = true;
  5845. this.precision = null; // override the renderer's default precision for this material
  5846. this.polygonOffset = false;
  5847. this.polygonOffsetFactor = 0;
  5848. this.polygonOffsetUnits = 0;
  5849. this.dithering = false;
  5850. this.alphaTest = 0;
  5851. this.premultipliedAlpha = false;
  5852. this.visible = true;
  5853. this.toneMapped = true;
  5854. this.userData = {};
  5855. this.version = 0;
  5856. }
  5857. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5858. constructor: Material,
  5859. isMaterial: true,
  5860. onBeforeCompile: function onBeforeCompile()
  5861. /* shaderobject, renderer */
  5862. {},
  5863. customProgramCacheKey: function customProgramCacheKey() {
  5864. return this.onBeforeCompile.toString();
  5865. },
  5866. setValues: function setValues(values) {
  5867. if (values === undefined) return;
  5868. for (var key in values) {
  5869. var newValue = values[key];
  5870. if (newValue === undefined) {
  5871. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  5872. continue;
  5873. } // for backward compatability if shading is set in the constructor
  5874. if (key === 'shading') {
  5875. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5876. this.flatShading = newValue === FlatShading ? true : false;
  5877. continue;
  5878. }
  5879. var currentValue = this[key];
  5880. if (currentValue === undefined) {
  5881. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  5882. continue;
  5883. }
  5884. if (currentValue && currentValue.isColor) {
  5885. currentValue.set(newValue);
  5886. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5887. currentValue.copy(newValue);
  5888. } else {
  5889. this[key] = newValue;
  5890. }
  5891. }
  5892. },
  5893. toJSON: function toJSON(meta) {
  5894. var isRoot = meta === undefined || typeof meta === 'string';
  5895. if (isRoot) {
  5896. meta = {
  5897. textures: {},
  5898. images: {}
  5899. };
  5900. }
  5901. var data = {
  5902. metadata: {
  5903. version: 4.5,
  5904. type: 'Material',
  5905. generator: 'Material.toJSON'
  5906. }
  5907. }; // standard Material serialization
  5908. data.uuid = this.uuid;
  5909. data.type = this.type;
  5910. if (this.name !== '') data.name = this.name;
  5911. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5912. if (this.roughness !== undefined) data.roughness = this.roughness;
  5913. if (this.metalness !== undefined) data.metalness = this.metalness;
  5914. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5915. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5916. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5917. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5918. if (this.shininess !== undefined) data.shininess = this.shininess;
  5919. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5920. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5921. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5922. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5923. }
  5924. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5925. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5926. }
  5927. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5928. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5929. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5930. }
  5931. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5932. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5933. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5934. if (this.lightMap && this.lightMap.isTexture) {
  5935. data.lightMap = this.lightMap.toJSON(meta).uuid;
  5936. data.lightMapIntensity = this.lightMapIntensity;
  5937. }
  5938. if (this.aoMap && this.aoMap.isTexture) {
  5939. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5940. data.aoMapIntensity = this.aoMapIntensity;
  5941. }
  5942. if (this.bumpMap && this.bumpMap.isTexture) {
  5943. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5944. data.bumpScale = this.bumpScale;
  5945. }
  5946. if (this.normalMap && this.normalMap.isTexture) {
  5947. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5948. data.normalMapType = this.normalMapType;
  5949. data.normalScale = this.normalScale.toArray();
  5950. }
  5951. if (this.displacementMap && this.displacementMap.isTexture) {
  5952. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5953. data.displacementScale = this.displacementScale;
  5954. data.displacementBias = this.displacementBias;
  5955. }
  5956. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5957. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5958. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5959. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5960. if (this.envMap && this.envMap.isTexture) {
  5961. data.envMap = this.envMap.toJSON(meta).uuid;
  5962. data.reflectivity = this.reflectivity; // Scale behind envMap
  5963. data.refractionRatio = this.refractionRatio;
  5964. if (this.combine !== undefined) data.combine = this.combine;
  5965. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5966. }
  5967. if (this.gradientMap && this.gradientMap.isTexture) {
  5968. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5969. }
  5970. if (this.size !== undefined) data.size = this.size;
  5971. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5972. if (this.blending !== NormalBlending) data.blending = this.blending;
  5973. if (this.side !== FrontSide) data.side = this.side;
  5974. if (this.vertexColors) data.vertexColors = true;
  5975. if (this.opacity < 1) data.opacity = this.opacity;
  5976. if (this.transparent === true) data.transparent = this.transparent;
  5977. data.depthFunc = this.depthFunc;
  5978. data.depthTest = this.depthTest;
  5979. data.depthWrite = this.depthWrite;
  5980. data.stencilWrite = this.stencilWrite;
  5981. data.stencilWriteMask = this.stencilWriteMask;
  5982. data.stencilFunc = this.stencilFunc;
  5983. data.stencilRef = this.stencilRef;
  5984. data.stencilFuncMask = this.stencilFuncMask;
  5985. data.stencilFail = this.stencilFail;
  5986. data.stencilZFail = this.stencilZFail;
  5987. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5988. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5989. if (this.polygonOffset === true) data.polygonOffset = true;
  5990. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5991. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5992. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5993. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5994. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5995. if (this.scale !== undefined) data.scale = this.scale;
  5996. if (this.dithering === true) data.dithering = true;
  5997. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5998. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5999. if (this.wireframe === true) data.wireframe = this.wireframe;
  6000. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  6001. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  6002. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  6003. if (this.morphTargets === true) data.morphTargets = true;
  6004. if (this.morphNormals === true) data.morphNormals = true;
  6005. if (this.skinning === true) data.skinning = true;
  6006. if (this.flatShading === true) data.flatShading = this.flatShading;
  6007. if (this.visible === false) data.visible = false;
  6008. if (this.toneMapped === false) data.toneMapped = false;
  6009. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  6010. function extractFromCache(cache) {
  6011. var values = [];
  6012. for (var key in cache) {
  6013. var _data = cache[key];
  6014. delete _data.metadata;
  6015. values.push(_data);
  6016. }
  6017. return values;
  6018. }
  6019. if (isRoot) {
  6020. var textures = extractFromCache(meta.textures);
  6021. var images = extractFromCache(meta.images);
  6022. if (textures.length > 0) data.textures = textures;
  6023. if (images.length > 0) data.images = images;
  6024. }
  6025. return data;
  6026. },
  6027. clone: function clone() {
  6028. return new this.constructor().copy(this);
  6029. },
  6030. copy: function copy(source) {
  6031. this.name = source.name;
  6032. this.fog = source.fog;
  6033. this.blending = source.blending;
  6034. this.side = source.side;
  6035. this.vertexColors = source.vertexColors;
  6036. this.opacity = source.opacity;
  6037. this.transparent = source.transparent;
  6038. this.blendSrc = source.blendSrc;
  6039. this.blendDst = source.blendDst;
  6040. this.blendEquation = source.blendEquation;
  6041. this.blendSrcAlpha = source.blendSrcAlpha;
  6042. this.blendDstAlpha = source.blendDstAlpha;
  6043. this.blendEquationAlpha = source.blendEquationAlpha;
  6044. this.depthFunc = source.depthFunc;
  6045. this.depthTest = source.depthTest;
  6046. this.depthWrite = source.depthWrite;
  6047. this.stencilWriteMask = source.stencilWriteMask;
  6048. this.stencilFunc = source.stencilFunc;
  6049. this.stencilRef = source.stencilRef;
  6050. this.stencilFuncMask = source.stencilFuncMask;
  6051. this.stencilFail = source.stencilFail;
  6052. this.stencilZFail = source.stencilZFail;
  6053. this.stencilZPass = source.stencilZPass;
  6054. this.stencilWrite = source.stencilWrite;
  6055. var srcPlanes = source.clippingPlanes;
  6056. var dstPlanes = null;
  6057. if (srcPlanes !== null) {
  6058. var n = srcPlanes.length;
  6059. dstPlanes = new Array(n);
  6060. for (var i = 0; i !== n; ++i) {
  6061. dstPlanes[i] = srcPlanes[i].clone();
  6062. }
  6063. }
  6064. this.clippingPlanes = dstPlanes;
  6065. this.clipIntersection = source.clipIntersection;
  6066. this.clipShadows = source.clipShadows;
  6067. this.shadowSide = source.shadowSide;
  6068. this.colorWrite = source.colorWrite;
  6069. this.precision = source.precision;
  6070. this.polygonOffset = source.polygonOffset;
  6071. this.polygonOffsetFactor = source.polygonOffsetFactor;
  6072. this.polygonOffsetUnits = source.polygonOffsetUnits;
  6073. this.dithering = source.dithering;
  6074. this.alphaTest = source.alphaTest;
  6075. this.premultipliedAlpha = source.premultipliedAlpha;
  6076. this.visible = source.visible;
  6077. this.toneMapped = source.toneMapped;
  6078. this.userData = JSON.parse(JSON.stringify(source.userData));
  6079. return this;
  6080. },
  6081. dispose: function dispose() {
  6082. this.dispatchEvent({
  6083. type: 'dispose'
  6084. });
  6085. }
  6086. });
  6087. Object.defineProperty(Material.prototype, 'needsUpdate', {
  6088. set: function set(value) {
  6089. if (value === true) this.version++;
  6090. }
  6091. });
  6092. var _colorKeywords = {
  6093. 'aliceblue': 0xF0F8FF,
  6094. 'antiquewhite': 0xFAEBD7,
  6095. 'aqua': 0x00FFFF,
  6096. 'aquamarine': 0x7FFFD4,
  6097. 'azure': 0xF0FFFF,
  6098. 'beige': 0xF5F5DC,
  6099. 'bisque': 0xFFE4C4,
  6100. 'black': 0x000000,
  6101. 'blanchedalmond': 0xFFEBCD,
  6102. 'blue': 0x0000FF,
  6103. 'blueviolet': 0x8A2BE2,
  6104. 'brown': 0xA52A2A,
  6105. 'burlywood': 0xDEB887,
  6106. 'cadetblue': 0x5F9EA0,
  6107. 'chartreuse': 0x7FFF00,
  6108. 'chocolate': 0xD2691E,
  6109. 'coral': 0xFF7F50,
  6110. 'cornflowerblue': 0x6495ED,
  6111. 'cornsilk': 0xFFF8DC,
  6112. 'crimson': 0xDC143C,
  6113. 'cyan': 0x00FFFF,
  6114. 'darkblue': 0x00008B,
  6115. 'darkcyan': 0x008B8B,
  6116. 'darkgoldenrod': 0xB8860B,
  6117. 'darkgray': 0xA9A9A9,
  6118. 'darkgreen': 0x006400,
  6119. 'darkgrey': 0xA9A9A9,
  6120. 'darkkhaki': 0xBDB76B,
  6121. 'darkmagenta': 0x8B008B,
  6122. 'darkolivegreen': 0x556B2F,
  6123. 'darkorange': 0xFF8C00,
  6124. 'darkorchid': 0x9932CC,
  6125. 'darkred': 0x8B0000,
  6126. 'darksalmon': 0xE9967A,
  6127. 'darkseagreen': 0x8FBC8F,
  6128. 'darkslateblue': 0x483D8B,
  6129. 'darkslategray': 0x2F4F4F,
  6130. 'darkslategrey': 0x2F4F4F,
  6131. 'darkturquoise': 0x00CED1,
  6132. 'darkviolet': 0x9400D3,
  6133. 'deeppink': 0xFF1493,
  6134. 'deepskyblue': 0x00BFFF,
  6135. 'dimgray': 0x696969,
  6136. 'dimgrey': 0x696969,
  6137. 'dodgerblue': 0x1E90FF,
  6138. 'firebrick': 0xB22222,
  6139. 'floralwhite': 0xFFFAF0,
  6140. 'forestgreen': 0x228B22,
  6141. 'fuchsia': 0xFF00FF,
  6142. 'gainsboro': 0xDCDCDC,
  6143. 'ghostwhite': 0xF8F8FF,
  6144. 'gold': 0xFFD700,
  6145. 'goldenrod': 0xDAA520,
  6146. 'gray': 0x808080,
  6147. 'green': 0x008000,
  6148. 'greenyellow': 0xADFF2F,
  6149. 'grey': 0x808080,
  6150. 'honeydew': 0xF0FFF0,
  6151. 'hotpink': 0xFF69B4,
  6152. 'indianred': 0xCD5C5C,
  6153. 'indigo': 0x4B0082,
  6154. 'ivory': 0xFFFFF0,
  6155. 'khaki': 0xF0E68C,
  6156. 'lavender': 0xE6E6FA,
  6157. 'lavenderblush': 0xFFF0F5,
  6158. 'lawngreen': 0x7CFC00,
  6159. 'lemonchiffon': 0xFFFACD,
  6160. 'lightblue': 0xADD8E6,
  6161. 'lightcoral': 0xF08080,
  6162. 'lightcyan': 0xE0FFFF,
  6163. 'lightgoldenrodyellow': 0xFAFAD2,
  6164. 'lightgray': 0xD3D3D3,
  6165. 'lightgreen': 0x90EE90,
  6166. 'lightgrey': 0xD3D3D3,
  6167. 'lightpink': 0xFFB6C1,
  6168. 'lightsalmon': 0xFFA07A,
  6169. 'lightseagreen': 0x20B2AA,
  6170. 'lightskyblue': 0x87CEFA,
  6171. 'lightslategray': 0x778899,
  6172. 'lightslategrey': 0x778899,
  6173. 'lightsteelblue': 0xB0C4DE,
  6174. 'lightyellow': 0xFFFFE0,
  6175. 'lime': 0x00FF00,
  6176. 'limegreen': 0x32CD32,
  6177. 'linen': 0xFAF0E6,
  6178. 'magenta': 0xFF00FF,
  6179. 'maroon': 0x800000,
  6180. 'mediumaquamarine': 0x66CDAA,
  6181. 'mediumblue': 0x0000CD,
  6182. 'mediumorchid': 0xBA55D3,
  6183. 'mediumpurple': 0x9370DB,
  6184. 'mediumseagreen': 0x3CB371,
  6185. 'mediumslateblue': 0x7B68EE,
  6186. 'mediumspringgreen': 0x00FA9A,
  6187. 'mediumturquoise': 0x48D1CC,
  6188. 'mediumvioletred': 0xC71585,
  6189. 'midnightblue': 0x191970,
  6190. 'mintcream': 0xF5FFFA,
  6191. 'mistyrose': 0xFFE4E1,
  6192. 'moccasin': 0xFFE4B5,
  6193. 'navajowhite': 0xFFDEAD,
  6194. 'navy': 0x000080,
  6195. 'oldlace': 0xFDF5E6,
  6196. 'olive': 0x808000,
  6197. 'olivedrab': 0x6B8E23,
  6198. 'orange': 0xFFA500,
  6199. 'orangered': 0xFF4500,
  6200. 'orchid': 0xDA70D6,
  6201. 'palegoldenrod': 0xEEE8AA,
  6202. 'palegreen': 0x98FB98,
  6203. 'paleturquoise': 0xAFEEEE,
  6204. 'palevioletred': 0xDB7093,
  6205. 'papayawhip': 0xFFEFD5,
  6206. 'peachpuff': 0xFFDAB9,
  6207. 'peru': 0xCD853F,
  6208. 'pink': 0xFFC0CB,
  6209. 'plum': 0xDDA0DD,
  6210. 'powderblue': 0xB0E0E6,
  6211. 'purple': 0x800080,
  6212. 'rebeccapurple': 0x663399,
  6213. 'red': 0xFF0000,
  6214. 'rosybrown': 0xBC8F8F,
  6215. 'royalblue': 0x4169E1,
  6216. 'saddlebrown': 0x8B4513,
  6217. 'salmon': 0xFA8072,
  6218. 'sandybrown': 0xF4A460,
  6219. 'seagreen': 0x2E8B57,
  6220. 'seashell': 0xFFF5EE,
  6221. 'sienna': 0xA0522D,
  6222. 'silver': 0xC0C0C0,
  6223. 'skyblue': 0x87CEEB,
  6224. 'slateblue': 0x6A5ACD,
  6225. 'slategray': 0x708090,
  6226. 'slategrey': 0x708090,
  6227. 'snow': 0xFFFAFA,
  6228. 'springgreen': 0x00FF7F,
  6229. 'steelblue': 0x4682B4,
  6230. 'tan': 0xD2B48C,
  6231. 'teal': 0x008080,
  6232. 'thistle': 0xD8BFD8,
  6233. 'tomato': 0xFF6347,
  6234. 'turquoise': 0x40E0D0,
  6235. 'violet': 0xEE82EE,
  6236. 'wheat': 0xF5DEB3,
  6237. 'white': 0xFFFFFF,
  6238. 'whitesmoke': 0xF5F5F5,
  6239. 'yellow': 0xFFFF00,
  6240. 'yellowgreen': 0x9ACD32
  6241. };
  6242. var _hslA = {
  6243. h: 0,
  6244. s: 0,
  6245. l: 0
  6246. };
  6247. var _hslB = {
  6248. h: 0,
  6249. s: 0,
  6250. l: 0
  6251. };
  6252. function hue2rgb(p, q, t) {
  6253. if (t < 0) t += 1;
  6254. if (t > 1) t -= 1;
  6255. if (t < 1 / 6) return p + (q - p) * 6 * t;
  6256. if (t < 1 / 2) return q;
  6257. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  6258. return p;
  6259. }
  6260. function SRGBToLinear(c) {
  6261. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  6262. }
  6263. function LinearToSRGB(c) {
  6264. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  6265. }
  6266. var Color = /*#__PURE__*/function () {
  6267. function Color(r, g, b) {
  6268. Object.defineProperty(this, 'isColor', {
  6269. value: true
  6270. });
  6271. if (g === undefined && b === undefined) {
  6272. // r is THREE.Color, hex or string
  6273. return this.set(r);
  6274. }
  6275. return this.setRGB(r, g, b);
  6276. }
  6277. var _proto = Color.prototype;
  6278. _proto.set = function set(value) {
  6279. if (value && value.isColor) {
  6280. this.copy(value);
  6281. } else if (typeof value === 'number') {
  6282. this.setHex(value);
  6283. } else if (typeof value === 'string') {
  6284. this.setStyle(value);
  6285. }
  6286. return this;
  6287. };
  6288. _proto.setScalar = function setScalar(scalar) {
  6289. this.r = scalar;
  6290. this.g = scalar;
  6291. this.b = scalar;
  6292. return this;
  6293. };
  6294. _proto.setHex = function setHex(hex) {
  6295. hex = Math.floor(hex);
  6296. this.r = (hex >> 16 & 255) / 255;
  6297. this.g = (hex >> 8 & 255) / 255;
  6298. this.b = (hex & 255) / 255;
  6299. return this;
  6300. };
  6301. _proto.setRGB = function setRGB(r, g, b) {
  6302. this.r = r;
  6303. this.g = g;
  6304. this.b = b;
  6305. return this;
  6306. };
  6307. _proto.setHSL = function setHSL(h, s, l) {
  6308. // h,s,l ranges are in 0.0 - 1.0
  6309. h = MathUtils.euclideanModulo(h, 1);
  6310. s = MathUtils.clamp(s, 0, 1);
  6311. l = MathUtils.clamp(l, 0, 1);
  6312. if (s === 0) {
  6313. this.r = this.g = this.b = l;
  6314. } else {
  6315. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  6316. var q = 2 * l - p;
  6317. this.r = hue2rgb(q, p, h + 1 / 3);
  6318. this.g = hue2rgb(q, p, h);
  6319. this.b = hue2rgb(q, p, h - 1 / 3);
  6320. }
  6321. return this;
  6322. };
  6323. _proto.setStyle = function setStyle(style) {
  6324. function handleAlpha(string) {
  6325. if (string === undefined) return;
  6326. if (parseFloat(string) < 1) {
  6327. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  6328. }
  6329. }
  6330. var m;
  6331. if (m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style)) {
  6332. // rgb / hsl
  6333. var color;
  6334. var name = m[1];
  6335. var components = m[2];
  6336. switch (name) {
  6337. case 'rgb':
  6338. case 'rgba':
  6339. if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6340. // rgb(255,0,0) rgba(255,0,0,0.5)
  6341. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  6342. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  6343. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  6344. handleAlpha(color[4]);
  6345. return this;
  6346. }
  6347. if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6348. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6349. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  6350. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  6351. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  6352. handleAlpha(color[4]);
  6353. return this;
  6354. }
  6355. break;
  6356. case 'hsl':
  6357. case 'hsla':
  6358. if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6359. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6360. var h = parseFloat(color[1]) / 360;
  6361. var s = parseInt(color[2], 10) / 100;
  6362. var l = parseInt(color[3], 10) / 100;
  6363. handleAlpha(color[4]);
  6364. return this.setHSL(h, s, l);
  6365. }
  6366. break;
  6367. }
  6368. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  6369. // hex color
  6370. var hex = m[1];
  6371. var size = hex.length;
  6372. if (size === 3) {
  6373. // #ff0
  6374. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  6375. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  6376. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  6377. return this;
  6378. } else if (size === 6) {
  6379. // #ff0000
  6380. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  6381. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  6382. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  6383. return this;
  6384. }
  6385. }
  6386. if (style && style.length > 0) {
  6387. return this.setColorName(style);
  6388. }
  6389. return this;
  6390. };
  6391. _proto.setColorName = function setColorName(style) {
  6392. // color keywords
  6393. var hex = _colorKeywords[style];
  6394. if (hex !== undefined) {
  6395. // red
  6396. this.setHex(hex);
  6397. } else {
  6398. // unknown color
  6399. console.warn('THREE.Color: Unknown color ' + style);
  6400. }
  6401. return this;
  6402. };
  6403. _proto.clone = function clone() {
  6404. return new this.constructor(this.r, this.g, this.b);
  6405. };
  6406. _proto.copy = function copy(color) {
  6407. this.r = color.r;
  6408. this.g = color.g;
  6409. this.b = color.b;
  6410. return this;
  6411. };
  6412. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  6413. if (gammaFactor === void 0) {
  6414. gammaFactor = 2.0;
  6415. }
  6416. this.r = Math.pow(color.r, gammaFactor);
  6417. this.g = Math.pow(color.g, gammaFactor);
  6418. this.b = Math.pow(color.b, gammaFactor);
  6419. return this;
  6420. };
  6421. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  6422. if (gammaFactor === void 0) {
  6423. gammaFactor = 2.0;
  6424. }
  6425. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  6426. this.r = Math.pow(color.r, safeInverse);
  6427. this.g = Math.pow(color.g, safeInverse);
  6428. this.b = Math.pow(color.b, safeInverse);
  6429. return this;
  6430. };
  6431. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  6432. this.copyGammaToLinear(this, gammaFactor);
  6433. return this;
  6434. };
  6435. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  6436. this.copyLinearToGamma(this, gammaFactor);
  6437. return this;
  6438. };
  6439. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  6440. this.r = SRGBToLinear(color.r);
  6441. this.g = SRGBToLinear(color.g);
  6442. this.b = SRGBToLinear(color.b);
  6443. return this;
  6444. };
  6445. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  6446. this.r = LinearToSRGB(color.r);
  6447. this.g = LinearToSRGB(color.g);
  6448. this.b = LinearToSRGB(color.b);
  6449. return this;
  6450. };
  6451. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  6452. this.copySRGBToLinear(this);
  6453. return this;
  6454. };
  6455. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  6456. this.copyLinearToSRGB(this);
  6457. return this;
  6458. };
  6459. _proto.getHex = function getHex() {
  6460. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  6461. };
  6462. _proto.getHexString = function getHexString() {
  6463. return ('000000' + this.getHex().toString(16)).slice(-6);
  6464. };
  6465. _proto.getHSL = function getHSL(target) {
  6466. // h,s,l ranges are in 0.0 - 1.0
  6467. if (target === undefined) {
  6468. console.warn('THREE.Color: .getHSL() target is now required');
  6469. target = {
  6470. h: 0,
  6471. s: 0,
  6472. l: 0
  6473. };
  6474. }
  6475. var r = this.r,
  6476. g = this.g,
  6477. b = this.b;
  6478. var max = Math.max(r, g, b);
  6479. var min = Math.min(r, g, b);
  6480. var hue, saturation;
  6481. var lightness = (min + max) / 2.0;
  6482. if (min === max) {
  6483. hue = 0;
  6484. saturation = 0;
  6485. } else {
  6486. var delta = max - min;
  6487. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  6488. switch (max) {
  6489. case r:
  6490. hue = (g - b) / delta + (g < b ? 6 : 0);
  6491. break;
  6492. case g:
  6493. hue = (b - r) / delta + 2;
  6494. break;
  6495. case b:
  6496. hue = (r - g) / delta + 4;
  6497. break;
  6498. }
  6499. hue /= 6;
  6500. }
  6501. target.h = hue;
  6502. target.s = saturation;
  6503. target.l = lightness;
  6504. return target;
  6505. };
  6506. _proto.getStyle = function getStyle() {
  6507. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  6508. };
  6509. _proto.offsetHSL = function offsetHSL(h, s, l) {
  6510. this.getHSL(_hslA);
  6511. _hslA.h += h;
  6512. _hslA.s += s;
  6513. _hslA.l += l;
  6514. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  6515. return this;
  6516. };
  6517. _proto.add = function add(color) {
  6518. this.r += color.r;
  6519. this.g += color.g;
  6520. this.b += color.b;
  6521. return this;
  6522. };
  6523. _proto.addColors = function addColors(color1, color2) {
  6524. this.r = color1.r + color2.r;
  6525. this.g = color1.g + color2.g;
  6526. this.b = color1.b + color2.b;
  6527. return this;
  6528. };
  6529. _proto.addScalar = function addScalar(s) {
  6530. this.r += s;
  6531. this.g += s;
  6532. this.b += s;
  6533. return this;
  6534. };
  6535. _proto.sub = function sub(color) {
  6536. this.r = Math.max(0, this.r - color.r);
  6537. this.g = Math.max(0, this.g - color.g);
  6538. this.b = Math.max(0, this.b - color.b);
  6539. return this;
  6540. };
  6541. _proto.multiply = function multiply(color) {
  6542. this.r *= color.r;
  6543. this.g *= color.g;
  6544. this.b *= color.b;
  6545. return this;
  6546. };
  6547. _proto.multiplyScalar = function multiplyScalar(s) {
  6548. this.r *= s;
  6549. this.g *= s;
  6550. this.b *= s;
  6551. return this;
  6552. };
  6553. _proto.lerp = function lerp(color, alpha) {
  6554. this.r += (color.r - this.r) * alpha;
  6555. this.g += (color.g - this.g) * alpha;
  6556. this.b += (color.b - this.b) * alpha;
  6557. return this;
  6558. };
  6559. _proto.lerpColors = function lerpColors(color1, color2, alpha) {
  6560. this.r = color1.r + (color2.r - color1.r) * alpha;
  6561. this.g = color1.g + (color2.g - color1.g) * alpha;
  6562. this.b = color1.b + (color2.b - color1.b) * alpha;
  6563. return this;
  6564. };
  6565. _proto.lerpHSL = function lerpHSL(color, alpha) {
  6566. this.getHSL(_hslA);
  6567. color.getHSL(_hslB);
  6568. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  6569. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  6570. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  6571. this.setHSL(h, s, l);
  6572. return this;
  6573. };
  6574. _proto.equals = function equals(c) {
  6575. return c.r === this.r && c.g === this.g && c.b === this.b;
  6576. };
  6577. _proto.fromArray = function fromArray(array, offset) {
  6578. if (offset === void 0) {
  6579. offset = 0;
  6580. }
  6581. this.r = array[offset];
  6582. this.g = array[offset + 1];
  6583. this.b = array[offset + 2];
  6584. return this;
  6585. };
  6586. _proto.toArray = function toArray(array, offset) {
  6587. if (array === void 0) {
  6588. array = [];
  6589. }
  6590. if (offset === void 0) {
  6591. offset = 0;
  6592. }
  6593. array[offset] = this.r;
  6594. array[offset + 1] = this.g;
  6595. array[offset + 2] = this.b;
  6596. return array;
  6597. };
  6598. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  6599. this.r = attribute.getX(index);
  6600. this.g = attribute.getY(index);
  6601. this.b = attribute.getZ(index);
  6602. if (attribute.normalized === true) {
  6603. // assuming Uint8Array
  6604. this.r /= 255;
  6605. this.g /= 255;
  6606. this.b /= 255;
  6607. }
  6608. return this;
  6609. };
  6610. _proto.toJSON = function toJSON() {
  6611. return this.getHex();
  6612. };
  6613. return Color;
  6614. }();
  6615. Color.NAMES = _colorKeywords;
  6616. Color.prototype.r = 1;
  6617. Color.prototype.g = 1;
  6618. Color.prototype.b = 1;
  6619. /**
  6620. * parameters = {
  6621. * color: <hex>,
  6622. * opacity: <float>,
  6623. * map: new THREE.Texture( <Image> ),
  6624. *
  6625. * lightMap: new THREE.Texture( <Image> ),
  6626. * lightMapIntensity: <float>
  6627. *
  6628. * aoMap: new THREE.Texture( <Image> ),
  6629. * aoMapIntensity: <float>
  6630. *
  6631. * specularMap: new THREE.Texture( <Image> ),
  6632. *
  6633. * alphaMap: new THREE.Texture( <Image> ),
  6634. *
  6635. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  6636. * combine: THREE.Multiply,
  6637. * reflectivity: <float>,
  6638. * refractionRatio: <float>,
  6639. *
  6640. * depthTest: <bool>,
  6641. * depthWrite: <bool>,
  6642. *
  6643. * wireframe: <boolean>,
  6644. * wireframeLinewidth: <float>,
  6645. *
  6646. * skinning: <bool>,
  6647. * morphTargets: <bool>
  6648. * }
  6649. */
  6650. function MeshBasicMaterial(parameters) {
  6651. Material.call(this);
  6652. this.type = 'MeshBasicMaterial';
  6653. this.color = new Color(0xffffff); // emissive
  6654. this.map = null;
  6655. this.lightMap = null;
  6656. this.lightMapIntensity = 1.0;
  6657. this.aoMap = null;
  6658. this.aoMapIntensity = 1.0;
  6659. this.specularMap = null;
  6660. this.alphaMap = null;
  6661. this.envMap = null;
  6662. this.combine = MultiplyOperation;
  6663. this.reflectivity = 1;
  6664. this.refractionRatio = 0.98;
  6665. this.wireframe = false;
  6666. this.wireframeLinewidth = 1;
  6667. this.wireframeLinecap = 'round';
  6668. this.wireframeLinejoin = 'round';
  6669. this.skinning = false;
  6670. this.morphTargets = false;
  6671. this.setValues(parameters);
  6672. }
  6673. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  6674. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  6675. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  6676. MeshBasicMaterial.prototype.copy = function (source) {
  6677. Material.prototype.copy.call(this, source);
  6678. this.color.copy(source.color);
  6679. this.map = source.map;
  6680. this.lightMap = source.lightMap;
  6681. this.lightMapIntensity = source.lightMapIntensity;
  6682. this.aoMap = source.aoMap;
  6683. this.aoMapIntensity = source.aoMapIntensity;
  6684. this.specularMap = source.specularMap;
  6685. this.alphaMap = source.alphaMap;
  6686. this.envMap = source.envMap;
  6687. this.combine = source.combine;
  6688. this.reflectivity = source.reflectivity;
  6689. this.refractionRatio = source.refractionRatio;
  6690. this.wireframe = source.wireframe;
  6691. this.wireframeLinewidth = source.wireframeLinewidth;
  6692. this.wireframeLinecap = source.wireframeLinecap;
  6693. this.wireframeLinejoin = source.wireframeLinejoin;
  6694. this.skinning = source.skinning;
  6695. this.morphTargets = source.morphTargets;
  6696. return this;
  6697. };
  6698. var _vector$3 = new Vector3();
  6699. var _vector2$1 = new Vector2();
  6700. function BufferAttribute(array, itemSize, normalized) {
  6701. if (Array.isArray(array)) {
  6702. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6703. }
  6704. this.name = '';
  6705. this.array = array;
  6706. this.itemSize = itemSize;
  6707. this.count = array !== undefined ? array.length / itemSize : 0;
  6708. this.normalized = normalized === true;
  6709. this.usage = StaticDrawUsage;
  6710. this.updateRange = {
  6711. offset: 0,
  6712. count: -1
  6713. };
  6714. this.version = 0;
  6715. }
  6716. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6717. set: function set(value) {
  6718. if (value === true) this.version++;
  6719. }
  6720. });
  6721. Object.assign(BufferAttribute.prototype, {
  6722. isBufferAttribute: true,
  6723. onUploadCallback: function onUploadCallback() {},
  6724. setUsage: function setUsage(value) {
  6725. this.usage = value;
  6726. return this;
  6727. },
  6728. copy: function copy(source) {
  6729. this.name = source.name;
  6730. this.array = new source.array.constructor(source.array);
  6731. this.itemSize = source.itemSize;
  6732. this.count = source.count;
  6733. this.normalized = source.normalized;
  6734. this.usage = source.usage;
  6735. return this;
  6736. },
  6737. copyAt: function copyAt(index1, attribute, index2) {
  6738. index1 *= this.itemSize;
  6739. index2 *= attribute.itemSize;
  6740. for (var i = 0, l = this.itemSize; i < l; i++) {
  6741. this.array[index1 + i] = attribute.array[index2 + i];
  6742. }
  6743. return this;
  6744. },
  6745. copyArray: function copyArray(array) {
  6746. this.array.set(array);
  6747. return this;
  6748. },
  6749. copyColorsArray: function copyColorsArray(colors) {
  6750. var array = this.array;
  6751. var offset = 0;
  6752. for (var i = 0, l = colors.length; i < l; i++) {
  6753. var color = colors[i];
  6754. if (color === undefined) {
  6755. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6756. color = new Color();
  6757. }
  6758. array[offset++] = color.r;
  6759. array[offset++] = color.g;
  6760. array[offset++] = color.b;
  6761. }
  6762. return this;
  6763. },
  6764. copyVector2sArray: function copyVector2sArray(vectors) {
  6765. var array = this.array;
  6766. var offset = 0;
  6767. for (var i = 0, l = vectors.length; i < l; i++) {
  6768. var vector = vectors[i];
  6769. if (vector === undefined) {
  6770. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6771. vector = new Vector2();
  6772. }
  6773. array[offset++] = vector.x;
  6774. array[offset++] = vector.y;
  6775. }
  6776. return this;
  6777. },
  6778. copyVector3sArray: function copyVector3sArray(vectors) {
  6779. var array = this.array;
  6780. var offset = 0;
  6781. for (var i = 0, l = vectors.length; i < l; i++) {
  6782. var vector = vectors[i];
  6783. if (vector === undefined) {
  6784. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6785. vector = new Vector3();
  6786. }
  6787. array[offset++] = vector.x;
  6788. array[offset++] = vector.y;
  6789. array[offset++] = vector.z;
  6790. }
  6791. return this;
  6792. },
  6793. copyVector4sArray: function copyVector4sArray(vectors) {
  6794. var array = this.array;
  6795. var offset = 0;
  6796. for (var i = 0, l = vectors.length; i < l; i++) {
  6797. var vector = vectors[i];
  6798. if (vector === undefined) {
  6799. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6800. vector = new Vector4();
  6801. }
  6802. array[offset++] = vector.x;
  6803. array[offset++] = vector.y;
  6804. array[offset++] = vector.z;
  6805. array[offset++] = vector.w;
  6806. }
  6807. return this;
  6808. },
  6809. applyMatrix3: function applyMatrix3(m) {
  6810. if (this.itemSize === 2) {
  6811. for (var i = 0, l = this.count; i < l; i++) {
  6812. _vector2$1.fromBufferAttribute(this, i);
  6813. _vector2$1.applyMatrix3(m);
  6814. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6815. }
  6816. } else if (this.itemSize === 3) {
  6817. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6818. _vector$3.fromBufferAttribute(this, _i);
  6819. _vector$3.applyMatrix3(m);
  6820. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6821. }
  6822. }
  6823. return this;
  6824. },
  6825. applyMatrix4: function applyMatrix4(m) {
  6826. for (var i = 0, l = this.count; i < l; i++) {
  6827. _vector$3.x = this.getX(i);
  6828. _vector$3.y = this.getY(i);
  6829. _vector$3.z = this.getZ(i);
  6830. _vector$3.applyMatrix4(m);
  6831. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6832. }
  6833. return this;
  6834. },
  6835. applyNormalMatrix: function applyNormalMatrix(m) {
  6836. for (var i = 0, l = this.count; i < l; i++) {
  6837. _vector$3.x = this.getX(i);
  6838. _vector$3.y = this.getY(i);
  6839. _vector$3.z = this.getZ(i);
  6840. _vector$3.applyNormalMatrix(m);
  6841. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6842. }
  6843. return this;
  6844. },
  6845. transformDirection: function transformDirection(m) {
  6846. for (var i = 0, l = this.count; i < l; i++) {
  6847. _vector$3.x = this.getX(i);
  6848. _vector$3.y = this.getY(i);
  6849. _vector$3.z = this.getZ(i);
  6850. _vector$3.transformDirection(m);
  6851. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6852. }
  6853. return this;
  6854. },
  6855. set: function set(value, offset) {
  6856. if (offset === void 0) {
  6857. offset = 0;
  6858. }
  6859. this.array.set(value, offset);
  6860. return this;
  6861. },
  6862. getX: function getX(index) {
  6863. return this.array[index * this.itemSize];
  6864. },
  6865. setX: function setX(index, x) {
  6866. this.array[index * this.itemSize] = x;
  6867. return this;
  6868. },
  6869. getY: function getY(index) {
  6870. return this.array[index * this.itemSize + 1];
  6871. },
  6872. setY: function setY(index, y) {
  6873. this.array[index * this.itemSize + 1] = y;
  6874. return this;
  6875. },
  6876. getZ: function getZ(index) {
  6877. return this.array[index * this.itemSize + 2];
  6878. },
  6879. setZ: function setZ(index, z) {
  6880. this.array[index * this.itemSize + 2] = z;
  6881. return this;
  6882. },
  6883. getW: function getW(index) {
  6884. return this.array[index * this.itemSize + 3];
  6885. },
  6886. setW: function setW(index, w) {
  6887. this.array[index * this.itemSize + 3] = w;
  6888. return this;
  6889. },
  6890. setXY: function setXY(index, x, y) {
  6891. index *= this.itemSize;
  6892. this.array[index + 0] = x;
  6893. this.array[index + 1] = y;
  6894. return this;
  6895. },
  6896. setXYZ: function setXYZ(index, x, y, z) {
  6897. index *= this.itemSize;
  6898. this.array[index + 0] = x;
  6899. this.array[index + 1] = y;
  6900. this.array[index + 2] = z;
  6901. return this;
  6902. },
  6903. setXYZW: function setXYZW(index, x, y, z, w) {
  6904. index *= this.itemSize;
  6905. this.array[index + 0] = x;
  6906. this.array[index + 1] = y;
  6907. this.array[index + 2] = z;
  6908. this.array[index + 3] = w;
  6909. return this;
  6910. },
  6911. onUpload: function onUpload(callback) {
  6912. this.onUploadCallback = callback;
  6913. return this;
  6914. },
  6915. clone: function clone() {
  6916. return new this.constructor(this.array, this.itemSize).copy(this);
  6917. },
  6918. toJSON: function toJSON() {
  6919. return {
  6920. itemSize: this.itemSize,
  6921. type: this.array.constructor.name,
  6922. array: Array.prototype.slice.call(this.array),
  6923. normalized: this.normalized
  6924. };
  6925. }
  6926. }); //
  6927. function Int8BufferAttribute(array, itemSize, normalized) {
  6928. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6929. }
  6930. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6931. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6932. function Uint8BufferAttribute(array, itemSize, normalized) {
  6933. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6934. }
  6935. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6936. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6937. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6938. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6939. }
  6940. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6941. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6942. function Int16BufferAttribute(array, itemSize, normalized) {
  6943. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6944. }
  6945. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6946. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6947. function Uint16BufferAttribute(array, itemSize, normalized) {
  6948. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6949. }
  6950. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6951. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6952. function Int32BufferAttribute(array, itemSize, normalized) {
  6953. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6954. }
  6955. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6956. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6957. function Uint32BufferAttribute(array, itemSize, normalized) {
  6958. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6959. }
  6960. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6961. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6962. function Float16BufferAttribute(array, itemSize, normalized) {
  6963. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6964. }
  6965. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6966. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6967. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6968. function Float32BufferAttribute(array, itemSize, normalized) {
  6969. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6970. }
  6971. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6972. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6973. function Float64BufferAttribute(array, itemSize, normalized) {
  6974. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6975. }
  6976. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6977. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6978. function arrayMax(array) {
  6979. if (array.length === 0) return -Infinity;
  6980. var max = array[0];
  6981. for (var i = 1, l = array.length; i < l; ++i) {
  6982. if (array[i] > max) max = array[i];
  6983. }
  6984. return max;
  6985. }
  6986. var TYPED_ARRAYS = {
  6987. Int8Array: Int8Array,
  6988. Uint8Array: Uint8Array,
  6989. // Workaround for IE11 pre KB2929437. See #11440
  6990. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6991. Int16Array: Int16Array,
  6992. Uint16Array: Uint16Array,
  6993. Int32Array: Int32Array,
  6994. Uint32Array: Uint32Array,
  6995. Float32Array: Float32Array,
  6996. Float64Array: Float64Array
  6997. };
  6998. function getTypedArray(type, buffer) {
  6999. return new TYPED_ARRAYS[type](buffer);
  7000. }
  7001. var _id = 0;
  7002. var _m1$2 = new Matrix4();
  7003. var _obj = new Object3D();
  7004. var _offset = new Vector3();
  7005. var _box$2 = new Box3();
  7006. var _boxMorphTargets = new Box3();
  7007. var _vector$4 = new Vector3();
  7008. function BufferGeometry() {
  7009. Object.defineProperty(this, 'id', {
  7010. value: _id++
  7011. });
  7012. this.uuid = MathUtils.generateUUID();
  7013. this.name = '';
  7014. this.type = 'BufferGeometry';
  7015. this.index = null;
  7016. this.attributes = {};
  7017. this.morphAttributes = {};
  7018. this.morphTargetsRelative = false;
  7019. this.groups = [];
  7020. this.boundingBox = null;
  7021. this.boundingSphere = null;
  7022. this.drawRange = {
  7023. start: 0,
  7024. count: Infinity
  7025. };
  7026. this.userData = {};
  7027. }
  7028. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  7029. constructor: BufferGeometry,
  7030. isBufferGeometry: true,
  7031. getIndex: function getIndex() {
  7032. return this.index;
  7033. },
  7034. setIndex: function setIndex(index) {
  7035. if (Array.isArray(index)) {
  7036. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  7037. } else {
  7038. this.index = index;
  7039. }
  7040. return this;
  7041. },
  7042. getAttribute: function getAttribute(name) {
  7043. return this.attributes[name];
  7044. },
  7045. setAttribute: function setAttribute(name, attribute) {
  7046. this.attributes[name] = attribute;
  7047. return this;
  7048. },
  7049. deleteAttribute: function deleteAttribute(name) {
  7050. delete this.attributes[name];
  7051. return this;
  7052. },
  7053. hasAttribute: function hasAttribute(name) {
  7054. return this.attributes[name] !== undefined;
  7055. },
  7056. addGroup: function addGroup(start, count, materialIndex) {
  7057. if (materialIndex === void 0) {
  7058. materialIndex = 0;
  7059. }
  7060. this.groups.push({
  7061. start: start,
  7062. count: count,
  7063. materialIndex: materialIndex
  7064. });
  7065. },
  7066. clearGroups: function clearGroups() {
  7067. this.groups = [];
  7068. },
  7069. setDrawRange: function setDrawRange(start, count) {
  7070. this.drawRange.start = start;
  7071. this.drawRange.count = count;
  7072. },
  7073. applyMatrix4: function applyMatrix4(matrix) {
  7074. var position = this.attributes.position;
  7075. if (position !== undefined) {
  7076. position.applyMatrix4(matrix);
  7077. position.needsUpdate = true;
  7078. }
  7079. var normal = this.attributes.normal;
  7080. if (normal !== undefined) {
  7081. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  7082. normal.applyNormalMatrix(normalMatrix);
  7083. normal.needsUpdate = true;
  7084. }
  7085. var tangent = this.attributes.tangent;
  7086. if (tangent !== undefined) {
  7087. tangent.transformDirection(matrix);
  7088. tangent.needsUpdate = true;
  7089. }
  7090. if (this.boundingBox !== null) {
  7091. this.computeBoundingBox();
  7092. }
  7093. if (this.boundingSphere !== null) {
  7094. this.computeBoundingSphere();
  7095. }
  7096. return this;
  7097. },
  7098. rotateX: function rotateX(angle) {
  7099. // rotate geometry around world x-axis
  7100. _m1$2.makeRotationX(angle);
  7101. this.applyMatrix4(_m1$2);
  7102. return this;
  7103. },
  7104. rotateY: function rotateY(angle) {
  7105. // rotate geometry around world y-axis
  7106. _m1$2.makeRotationY(angle);
  7107. this.applyMatrix4(_m1$2);
  7108. return this;
  7109. },
  7110. rotateZ: function rotateZ(angle) {
  7111. // rotate geometry around world z-axis
  7112. _m1$2.makeRotationZ(angle);
  7113. this.applyMatrix4(_m1$2);
  7114. return this;
  7115. },
  7116. translate: function translate(x, y, z) {
  7117. // translate geometry
  7118. _m1$2.makeTranslation(x, y, z);
  7119. this.applyMatrix4(_m1$2);
  7120. return this;
  7121. },
  7122. scale: function scale(x, y, z) {
  7123. // scale geometry
  7124. _m1$2.makeScale(x, y, z);
  7125. this.applyMatrix4(_m1$2);
  7126. return this;
  7127. },
  7128. lookAt: function lookAt(vector) {
  7129. _obj.lookAt(vector);
  7130. _obj.updateMatrix();
  7131. this.applyMatrix4(_obj.matrix);
  7132. return this;
  7133. },
  7134. center: function center() {
  7135. this.computeBoundingBox();
  7136. this.boundingBox.getCenter(_offset).negate();
  7137. this.translate(_offset.x, _offset.y, _offset.z);
  7138. return this;
  7139. },
  7140. setFromPoints: function setFromPoints(points) {
  7141. var position = [];
  7142. for (var i = 0, l = points.length; i < l; i++) {
  7143. var point = points[i];
  7144. position.push(point.x, point.y, point.z || 0);
  7145. }
  7146. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  7147. return this;
  7148. },
  7149. computeBoundingBox: function computeBoundingBox() {
  7150. if (this.boundingBox === null) {
  7151. this.boundingBox = new Box3();
  7152. }
  7153. var position = this.attributes.position;
  7154. var morphAttributesPosition = this.morphAttributes.position;
  7155. if (position && position.isGLBufferAttribute) {
  7156. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  7157. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  7158. return;
  7159. }
  7160. if (position !== undefined) {
  7161. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  7162. if (morphAttributesPosition) {
  7163. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7164. var morphAttribute = morphAttributesPosition[i];
  7165. _box$2.setFromBufferAttribute(morphAttribute);
  7166. if (this.morphTargetsRelative) {
  7167. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  7168. this.boundingBox.expandByPoint(_vector$4);
  7169. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  7170. this.boundingBox.expandByPoint(_vector$4);
  7171. } else {
  7172. this.boundingBox.expandByPoint(_box$2.min);
  7173. this.boundingBox.expandByPoint(_box$2.max);
  7174. }
  7175. }
  7176. }
  7177. } else {
  7178. this.boundingBox.makeEmpty();
  7179. }
  7180. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  7181. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  7182. }
  7183. },
  7184. computeBoundingSphere: function computeBoundingSphere() {
  7185. if (this.boundingSphere === null) {
  7186. this.boundingSphere = new Sphere();
  7187. }
  7188. var position = this.attributes.position;
  7189. var morphAttributesPosition = this.morphAttributes.position;
  7190. if (position && position.isGLBufferAttribute) {
  7191. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  7192. this.boundingSphere.set(new Vector3(), Infinity);
  7193. return;
  7194. }
  7195. if (position) {
  7196. // first, find the center of the bounding sphere
  7197. var center = this.boundingSphere.center;
  7198. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  7199. if (morphAttributesPosition) {
  7200. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7201. var morphAttribute = morphAttributesPosition[i];
  7202. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  7203. if (this.morphTargetsRelative) {
  7204. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  7205. _box$2.expandByPoint(_vector$4);
  7206. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  7207. _box$2.expandByPoint(_vector$4);
  7208. } else {
  7209. _box$2.expandByPoint(_boxMorphTargets.min);
  7210. _box$2.expandByPoint(_boxMorphTargets.max);
  7211. }
  7212. }
  7213. }
  7214. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  7215. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7216. var maxRadiusSq = 0;
  7217. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  7218. _vector$4.fromBufferAttribute(position, _i);
  7219. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7220. } // process morph attributes if present
  7221. if (morphAttributesPosition) {
  7222. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  7223. var _morphAttribute = morphAttributesPosition[_i2];
  7224. var morphTargetsRelative = this.morphTargetsRelative;
  7225. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  7226. _vector$4.fromBufferAttribute(_morphAttribute, j);
  7227. if (morphTargetsRelative) {
  7228. _offset.fromBufferAttribute(position, j);
  7229. _vector$4.add(_offset);
  7230. }
  7231. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7232. }
  7233. }
  7234. }
  7235. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  7236. if (isNaN(this.boundingSphere.radius)) {
  7237. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  7238. }
  7239. }
  7240. },
  7241. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  7242. },
  7243. computeTangents: function computeTangents() {
  7244. var index = this.index;
  7245. var attributes = this.attributes; // based on http://www.terathon.com/code/tangent.html
  7246. // (per vertex tangents)
  7247. if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
  7248. console.error('THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)');
  7249. return;
  7250. }
  7251. var indices = index.array;
  7252. var positions = attributes.position.array;
  7253. var normals = attributes.normal.array;
  7254. var uvs = attributes.uv.array;
  7255. var nVertices = positions.length / 3;
  7256. if (attributes.tangent === undefined) {
  7257. this.setAttribute('tangent', new BufferAttribute(new Float32Array(4 * nVertices), 4));
  7258. }
  7259. var tangents = attributes.tangent.array;
  7260. var tan1 = [],
  7261. tan2 = [];
  7262. for (var i = 0; i < nVertices; i++) {
  7263. tan1[i] = new Vector3();
  7264. tan2[i] = new Vector3();
  7265. }
  7266. var vA = new Vector3(),
  7267. vB = new Vector3(),
  7268. vC = new Vector3(),
  7269. uvA = new Vector2(),
  7270. uvB = new Vector2(),
  7271. uvC = new Vector2(),
  7272. sdir = new Vector3(),
  7273. tdir = new Vector3();
  7274. function handleTriangle(a, b, c) {
  7275. vA.fromArray(positions, a * 3);
  7276. vB.fromArray(positions, b * 3);
  7277. vC.fromArray(positions, c * 3);
  7278. uvA.fromArray(uvs, a * 2);
  7279. uvB.fromArray(uvs, b * 2);
  7280. uvC.fromArray(uvs, c * 2);
  7281. vB.sub(vA);
  7282. vC.sub(vA);
  7283. uvB.sub(uvA);
  7284. uvC.sub(uvA);
  7285. var r = 1.0 / (uvB.x * uvC.y - uvC.x * uvB.y); // silently ignore degenerate uv triangles having coincident or colinear vertices
  7286. if (!isFinite(r)) return;
  7287. sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
  7288. tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
  7289. tan1[a].add(sdir);
  7290. tan1[b].add(sdir);
  7291. tan1[c].add(sdir);
  7292. tan2[a].add(tdir);
  7293. tan2[b].add(tdir);
  7294. tan2[c].add(tdir);
  7295. }
  7296. var groups = this.groups;
  7297. if (groups.length === 0) {
  7298. groups = [{
  7299. start: 0,
  7300. count: indices.length
  7301. }];
  7302. }
  7303. for (var _i3 = 0, il = groups.length; _i3 < il; ++_i3) {
  7304. var group = groups[_i3];
  7305. var start = group.start;
  7306. var count = group.count;
  7307. for (var j = start, jl = start + count; j < jl; j += 3) {
  7308. handleTriangle(indices[j + 0], indices[j + 1], indices[j + 2]);
  7309. }
  7310. }
  7311. var tmp = new Vector3(),
  7312. tmp2 = new Vector3();
  7313. var n = new Vector3(),
  7314. n2 = new Vector3();
  7315. function handleVertex(v) {
  7316. n.fromArray(normals, v * 3);
  7317. n2.copy(n);
  7318. var t = tan1[v]; // Gram-Schmidt orthogonalize
  7319. tmp.copy(t);
  7320. tmp.sub(n.multiplyScalar(n.dot(t))).normalize(); // Calculate handedness
  7321. tmp2.crossVectors(n2, t);
  7322. var test = tmp2.dot(tan2[v]);
  7323. var w = test < 0.0 ? -1.0 : 1.0;
  7324. tangents[v * 4] = tmp.x;
  7325. tangents[v * 4 + 1] = tmp.y;
  7326. tangents[v * 4 + 2] = tmp.z;
  7327. tangents[v * 4 + 3] = w;
  7328. }
  7329. for (var _i4 = 0, _il3 = groups.length; _i4 < _il3; ++_i4) {
  7330. var _group = groups[_i4];
  7331. var _start = _group.start;
  7332. var _count = _group.count;
  7333. for (var _j = _start, _jl = _start + _count; _j < _jl; _j += 3) {
  7334. handleVertex(indices[_j + 0]);
  7335. handleVertex(indices[_j + 1]);
  7336. handleVertex(indices[_j + 2]);
  7337. }
  7338. }
  7339. },
  7340. computeVertexNormals: function computeVertexNormals() {
  7341. var index = this.index;
  7342. var positionAttribute = this.getAttribute('position');
  7343. if (positionAttribute !== undefined) {
  7344. var normalAttribute = this.getAttribute('normal');
  7345. if (normalAttribute === undefined) {
  7346. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  7347. this.setAttribute('normal', normalAttribute);
  7348. } else {
  7349. // reset existing normals to zero
  7350. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  7351. normalAttribute.setXYZ(i, 0, 0, 0);
  7352. }
  7353. }
  7354. var pA = new Vector3(),
  7355. pB = new Vector3(),
  7356. pC = new Vector3();
  7357. var nA = new Vector3(),
  7358. nB = new Vector3(),
  7359. nC = new Vector3();
  7360. var cb = new Vector3(),
  7361. ab = new Vector3(); // indexed elements
  7362. if (index) {
  7363. for (var _i5 = 0, _il4 = index.count; _i5 < _il4; _i5 += 3) {
  7364. var vA = index.getX(_i5 + 0);
  7365. var vB = index.getX(_i5 + 1);
  7366. var vC = index.getX(_i5 + 2);
  7367. pA.fromBufferAttribute(positionAttribute, vA);
  7368. pB.fromBufferAttribute(positionAttribute, vB);
  7369. pC.fromBufferAttribute(positionAttribute, vC);
  7370. cb.subVectors(pC, pB);
  7371. ab.subVectors(pA, pB);
  7372. cb.cross(ab);
  7373. nA.fromBufferAttribute(normalAttribute, vA);
  7374. nB.fromBufferAttribute(normalAttribute, vB);
  7375. nC.fromBufferAttribute(normalAttribute, vC);
  7376. nA.add(cb);
  7377. nB.add(cb);
  7378. nC.add(cb);
  7379. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  7380. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  7381. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  7382. }
  7383. } else {
  7384. // non-indexed elements (unconnected triangle soup)
  7385. for (var _i6 = 0, _il5 = positionAttribute.count; _i6 < _il5; _i6 += 3) {
  7386. pA.fromBufferAttribute(positionAttribute, _i6 + 0);
  7387. pB.fromBufferAttribute(positionAttribute, _i6 + 1);
  7388. pC.fromBufferAttribute(positionAttribute, _i6 + 2);
  7389. cb.subVectors(pC, pB);
  7390. ab.subVectors(pA, pB);
  7391. cb.cross(ab);
  7392. normalAttribute.setXYZ(_i6 + 0, cb.x, cb.y, cb.z);
  7393. normalAttribute.setXYZ(_i6 + 1, cb.x, cb.y, cb.z);
  7394. normalAttribute.setXYZ(_i6 + 2, cb.x, cb.y, cb.z);
  7395. }
  7396. }
  7397. this.normalizeNormals();
  7398. normalAttribute.needsUpdate = true;
  7399. }
  7400. },
  7401. merge: function merge(geometry, offset) {
  7402. if (!(geometry && geometry.isBufferGeometry)) {
  7403. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  7404. return;
  7405. }
  7406. if (offset === undefined) {
  7407. offset = 0;
  7408. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  7409. }
  7410. var attributes = this.attributes;
  7411. for (var key in attributes) {
  7412. if (geometry.attributes[key] === undefined) continue;
  7413. var attribute1 = attributes[key];
  7414. var attributeArray1 = attribute1.array;
  7415. var attribute2 = geometry.attributes[key];
  7416. var attributeArray2 = attribute2.array;
  7417. var attributeOffset = attribute2.itemSize * offset;
  7418. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  7419. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  7420. attributeArray1[j] = attributeArray2[i];
  7421. }
  7422. }
  7423. return this;
  7424. },
  7425. normalizeNormals: function normalizeNormals() {
  7426. var normals = this.attributes.normal;
  7427. for (var i = 0, il = normals.count; i < il; i++) {
  7428. _vector$4.fromBufferAttribute(normals, i);
  7429. _vector$4.normalize();
  7430. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  7431. }
  7432. },
  7433. toNonIndexed: function toNonIndexed() {
  7434. function convertBufferAttribute(attribute, indices) {
  7435. var array = attribute.array;
  7436. var itemSize = attribute.itemSize;
  7437. var normalized = attribute.normalized;
  7438. var array2 = new array.constructor(indices.length * itemSize);
  7439. var index = 0,
  7440. index2 = 0;
  7441. for (var i = 0, l = indices.length; i < l; i++) {
  7442. index = indices[i] * itemSize;
  7443. for (var j = 0; j < itemSize; j++) {
  7444. array2[index2++] = array[index++];
  7445. }
  7446. }
  7447. return new BufferAttribute(array2, itemSize, normalized);
  7448. } //
  7449. if (this.index === null) {
  7450. console.warn('THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.');
  7451. return this;
  7452. }
  7453. var geometry2 = new BufferGeometry();
  7454. var indices = this.index.array;
  7455. var attributes = this.attributes; // attributes
  7456. for (var name in attributes) {
  7457. var attribute = attributes[name];
  7458. var newAttribute = convertBufferAttribute(attribute, indices);
  7459. geometry2.setAttribute(name, newAttribute);
  7460. } // morph attributes
  7461. var morphAttributes = this.morphAttributes;
  7462. for (var _name in morphAttributes) {
  7463. var morphArray = [];
  7464. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  7465. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  7466. var _attribute = morphAttribute[i];
  7467. var _newAttribute = convertBufferAttribute(_attribute, indices);
  7468. morphArray.push(_newAttribute);
  7469. }
  7470. geometry2.morphAttributes[_name] = morphArray;
  7471. }
  7472. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  7473. var groups = this.groups;
  7474. for (var _i7 = 0, l = groups.length; _i7 < l; _i7++) {
  7475. var group = groups[_i7];
  7476. geometry2.addGroup(group.start, group.count, group.materialIndex);
  7477. }
  7478. return geometry2;
  7479. },
  7480. toJSON: function toJSON() {
  7481. var data = {
  7482. metadata: {
  7483. version: 4.5,
  7484. type: 'BufferGeometry',
  7485. generator: 'BufferGeometry.toJSON'
  7486. }
  7487. }; // standard BufferGeometry serialization
  7488. data.uuid = this.uuid;
  7489. data.type = this.type;
  7490. if (this.name !== '') data.name = this.name;
  7491. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  7492. if (this.parameters !== undefined) {
  7493. var parameters = this.parameters;
  7494. for (var key in parameters) {
  7495. if (parameters[key] !== undefined) data[key] = parameters[key];
  7496. }
  7497. return data;
  7498. }
  7499. data.data = {
  7500. attributes: {}
  7501. };
  7502. var index = this.index;
  7503. if (index !== null) {
  7504. data.data.index = {
  7505. type: index.array.constructor.name,
  7506. array: Array.prototype.slice.call(index.array)
  7507. };
  7508. }
  7509. var attributes = this.attributes;
  7510. for (var _key in attributes) {
  7511. var attribute = attributes[_key];
  7512. var attributeData = attribute.toJSON(data.data);
  7513. if (attribute.name !== '') attributeData.name = attribute.name;
  7514. data.data.attributes[_key] = attributeData;
  7515. }
  7516. var morphAttributes = {};
  7517. var hasMorphAttributes = false;
  7518. for (var _key2 in this.morphAttributes) {
  7519. var attributeArray = this.morphAttributes[_key2];
  7520. var array = [];
  7521. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7522. var _attribute2 = attributeArray[i];
  7523. var _attributeData = _attribute2.toJSON(data.data);
  7524. if (_attribute2.name !== '') _attributeData.name = _attribute2.name;
  7525. array.push(_attributeData);
  7526. }
  7527. if (array.length > 0) {
  7528. morphAttributes[_key2] = array;
  7529. hasMorphAttributes = true;
  7530. }
  7531. }
  7532. if (hasMorphAttributes) {
  7533. data.data.morphAttributes = morphAttributes;
  7534. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7535. }
  7536. var groups = this.groups;
  7537. if (groups.length > 0) {
  7538. data.data.groups = JSON.parse(JSON.stringify(groups));
  7539. }
  7540. var boundingSphere = this.boundingSphere;
  7541. if (boundingSphere !== null) {
  7542. data.data.boundingSphere = {
  7543. center: boundingSphere.center.toArray(),
  7544. radius: boundingSphere.radius
  7545. };
  7546. }
  7547. return data;
  7548. },
  7549. clone: function clone() {
  7550. /*
  7551. // Handle primitives
  7552. const parameters = this.parameters;
  7553. if ( parameters !== undefined ) {
  7554. const values = [];
  7555. for ( const key in parameters ) {
  7556. values.push( parameters[ key ] );
  7557. }
  7558. const geometry = Object.create( this.constructor.prototype );
  7559. this.constructor.apply( geometry, values );
  7560. return geometry;
  7561. }
  7562. return new this.constructor().copy( this );
  7563. */
  7564. return new BufferGeometry().copy(this);
  7565. },
  7566. copy: function copy(source) {
  7567. // reset
  7568. this.index = null;
  7569. this.attributes = {};
  7570. this.morphAttributes = {};
  7571. this.groups = [];
  7572. this.boundingBox = null;
  7573. this.boundingSphere = null; // used for storing cloned, shared data
  7574. var data = {}; // name
  7575. this.name = source.name; // index
  7576. var index = source.index;
  7577. if (index !== null) {
  7578. this.setIndex(index.clone(data));
  7579. } // attributes
  7580. var attributes = source.attributes;
  7581. for (var name in attributes) {
  7582. var attribute = attributes[name];
  7583. this.setAttribute(name, attribute.clone(data));
  7584. } // morph attributes
  7585. var morphAttributes = source.morphAttributes;
  7586. for (var _name2 in morphAttributes) {
  7587. var array = [];
  7588. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7589. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7590. array.push(morphAttribute[i].clone(data));
  7591. }
  7592. this.morphAttributes[_name2] = array;
  7593. }
  7594. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7595. var groups = source.groups;
  7596. for (var _i8 = 0, _l = groups.length; _i8 < _l; _i8++) {
  7597. var group = groups[_i8];
  7598. this.addGroup(group.start, group.count, group.materialIndex);
  7599. } // bounding box
  7600. var boundingBox = source.boundingBox;
  7601. if (boundingBox !== null) {
  7602. this.boundingBox = boundingBox.clone();
  7603. } // bounding sphere
  7604. var boundingSphere = source.boundingSphere;
  7605. if (boundingSphere !== null) {
  7606. this.boundingSphere = boundingSphere.clone();
  7607. } // draw range
  7608. this.drawRange.start = source.drawRange.start;
  7609. this.drawRange.count = source.drawRange.count; // user data
  7610. this.userData = source.userData;
  7611. return this;
  7612. },
  7613. dispose: function dispose() {
  7614. this.dispatchEvent({
  7615. type: 'dispose'
  7616. });
  7617. }
  7618. });
  7619. var _inverseMatrix = new Matrix4();
  7620. var _ray = new Ray();
  7621. var _sphere = new Sphere();
  7622. var _vA = new Vector3();
  7623. var _vB = new Vector3();
  7624. var _vC = new Vector3();
  7625. var _tempA = new Vector3();
  7626. var _tempB = new Vector3();
  7627. var _tempC = new Vector3();
  7628. var _morphA = new Vector3();
  7629. var _morphB = new Vector3();
  7630. var _morphC = new Vector3();
  7631. var _uvA = new Vector2();
  7632. var _uvB = new Vector2();
  7633. var _uvC = new Vector2();
  7634. var _intersectionPoint = new Vector3();
  7635. var _intersectionPointWorld = new Vector3();
  7636. function Mesh(geometry, material) {
  7637. if (geometry === void 0) {
  7638. geometry = new BufferGeometry();
  7639. }
  7640. if (material === void 0) {
  7641. material = new MeshBasicMaterial();
  7642. }
  7643. Object3D.call(this);
  7644. this.type = 'Mesh';
  7645. this.geometry = geometry;
  7646. this.material = material;
  7647. this.updateMorphTargets();
  7648. }
  7649. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7650. constructor: Mesh,
  7651. isMesh: true,
  7652. copy: function copy(source) {
  7653. Object3D.prototype.copy.call(this, source);
  7654. if (source.morphTargetInfluences !== undefined) {
  7655. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7656. }
  7657. if (source.morphTargetDictionary !== undefined) {
  7658. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7659. }
  7660. this.material = source.material;
  7661. this.geometry = source.geometry;
  7662. return this;
  7663. },
  7664. updateMorphTargets: function updateMorphTargets() {
  7665. var geometry = this.geometry;
  7666. if (geometry.isBufferGeometry) {
  7667. var morphAttributes = geometry.morphAttributes;
  7668. var keys = Object.keys(morphAttributes);
  7669. if (keys.length > 0) {
  7670. var morphAttribute = morphAttributes[keys[0]];
  7671. if (morphAttribute !== undefined) {
  7672. this.morphTargetInfluences = [];
  7673. this.morphTargetDictionary = {};
  7674. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7675. var name = morphAttribute[m].name || String(m);
  7676. this.morphTargetInfluences.push(0);
  7677. this.morphTargetDictionary[name] = m;
  7678. }
  7679. }
  7680. }
  7681. } else {
  7682. var morphTargets = geometry.morphTargets;
  7683. if (morphTargets !== undefined && morphTargets.length > 0) {
  7684. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7685. }
  7686. }
  7687. },
  7688. raycast: function raycast(raycaster, intersects) {
  7689. var geometry = this.geometry;
  7690. var material = this.material;
  7691. var matrixWorld = this.matrixWorld;
  7692. if (material === undefined) return; // Checking boundingSphere distance to ray
  7693. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7694. _sphere.copy(geometry.boundingSphere);
  7695. _sphere.applyMatrix4(matrixWorld);
  7696. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7697. _inverseMatrix.copy(matrixWorld).invert();
  7698. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7699. if (geometry.boundingBox !== null) {
  7700. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7701. }
  7702. var intersection;
  7703. if (geometry.isBufferGeometry) {
  7704. var index = geometry.index;
  7705. var position = geometry.attributes.position;
  7706. var morphPosition = geometry.morphAttributes.position;
  7707. var morphTargetsRelative = geometry.morphTargetsRelative;
  7708. var uv = geometry.attributes.uv;
  7709. var uv2 = geometry.attributes.uv2;
  7710. var groups = geometry.groups;
  7711. var drawRange = geometry.drawRange;
  7712. if (index !== null) {
  7713. // indexed buffer geometry
  7714. if (Array.isArray(material)) {
  7715. for (var i = 0, il = groups.length; i < il; i++) {
  7716. var group = groups[i];
  7717. var groupMaterial = material[group.materialIndex];
  7718. var start = Math.max(group.start, drawRange.start);
  7719. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7720. for (var j = start, jl = end; j < jl; j += 3) {
  7721. var a = index.getX(j);
  7722. var b = index.getX(j + 1);
  7723. var c = index.getX(j + 2);
  7724. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7725. if (intersection) {
  7726. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7727. intersection.face.materialIndex = group.materialIndex;
  7728. intersects.push(intersection);
  7729. }
  7730. }
  7731. }
  7732. } else {
  7733. var _start = Math.max(0, drawRange.start);
  7734. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7735. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7736. var _a = index.getX(_i);
  7737. var _b = index.getX(_i + 1);
  7738. var _c = index.getX(_i + 2);
  7739. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7740. if (intersection) {
  7741. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7742. intersects.push(intersection);
  7743. }
  7744. }
  7745. }
  7746. } else if (position !== undefined) {
  7747. // non-indexed buffer geometry
  7748. if (Array.isArray(material)) {
  7749. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7750. var _group = groups[_i2];
  7751. var _groupMaterial = material[_group.materialIndex];
  7752. var _start2 = Math.max(_group.start, drawRange.start);
  7753. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7754. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7755. var _a2 = _j;
  7756. var _b2 = _j + 1;
  7757. var _c2 = _j + 2;
  7758. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7759. if (intersection) {
  7760. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7761. intersection.face.materialIndex = _group.materialIndex;
  7762. intersects.push(intersection);
  7763. }
  7764. }
  7765. }
  7766. } else {
  7767. var _start3 = Math.max(0, drawRange.start);
  7768. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7769. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7770. var _a3 = _i3;
  7771. var _b3 = _i3 + 1;
  7772. var _c3 = _i3 + 2;
  7773. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7774. if (intersection) {
  7775. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7776. intersects.push(intersection);
  7777. }
  7778. }
  7779. }
  7780. }
  7781. } else if (geometry.isGeometry) {
  7782. console.error('THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7783. }
  7784. }
  7785. });
  7786. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7787. var intersect;
  7788. if (material.side === BackSide) {
  7789. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7790. } else {
  7791. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7792. }
  7793. if (intersect === null) return null;
  7794. _intersectionPointWorld.copy(point);
  7795. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7796. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7797. if (distance < raycaster.near || distance > raycaster.far) return null;
  7798. return {
  7799. distance: distance,
  7800. point: _intersectionPointWorld.clone(),
  7801. object: object
  7802. };
  7803. }
  7804. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7805. _vA.fromBufferAttribute(position, a);
  7806. _vB.fromBufferAttribute(position, b);
  7807. _vC.fromBufferAttribute(position, c);
  7808. var morphInfluences = object.morphTargetInfluences;
  7809. if (material.morphTargets && morphPosition && morphInfluences) {
  7810. _morphA.set(0, 0, 0);
  7811. _morphB.set(0, 0, 0);
  7812. _morphC.set(0, 0, 0);
  7813. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7814. var influence = morphInfluences[i];
  7815. var morphAttribute = morphPosition[i];
  7816. if (influence === 0) continue;
  7817. _tempA.fromBufferAttribute(morphAttribute, a);
  7818. _tempB.fromBufferAttribute(morphAttribute, b);
  7819. _tempC.fromBufferAttribute(morphAttribute, c);
  7820. if (morphTargetsRelative) {
  7821. _morphA.addScaledVector(_tempA, influence);
  7822. _morphB.addScaledVector(_tempB, influence);
  7823. _morphC.addScaledVector(_tempC, influence);
  7824. } else {
  7825. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7826. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7827. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7828. }
  7829. }
  7830. _vA.add(_morphA);
  7831. _vB.add(_morphB);
  7832. _vC.add(_morphC);
  7833. }
  7834. if (object.isSkinnedMesh && material.skinning) {
  7835. object.boneTransform(a, _vA);
  7836. object.boneTransform(b, _vB);
  7837. object.boneTransform(c, _vC);
  7838. }
  7839. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7840. if (intersection) {
  7841. if (uv) {
  7842. _uvA.fromBufferAttribute(uv, a);
  7843. _uvB.fromBufferAttribute(uv, b);
  7844. _uvC.fromBufferAttribute(uv, c);
  7845. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7846. }
  7847. if (uv2) {
  7848. _uvA.fromBufferAttribute(uv2, a);
  7849. _uvB.fromBufferAttribute(uv2, b);
  7850. _uvC.fromBufferAttribute(uv2, c);
  7851. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7852. }
  7853. var face = {
  7854. a: a,
  7855. b: a,
  7856. c: c,
  7857. normal: new Vector3(),
  7858. materialIndex: 0
  7859. };
  7860. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7861. intersection.face = face;
  7862. }
  7863. return intersection;
  7864. }
  7865. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7866. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7867. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7868. var _this;
  7869. if (width === void 0) {
  7870. width = 1;
  7871. }
  7872. if (height === void 0) {
  7873. height = 1;
  7874. }
  7875. if (depth === void 0) {
  7876. depth = 1;
  7877. }
  7878. if (widthSegments === void 0) {
  7879. widthSegments = 1;
  7880. }
  7881. if (heightSegments === void 0) {
  7882. heightSegments = 1;
  7883. }
  7884. if (depthSegments === void 0) {
  7885. depthSegments = 1;
  7886. }
  7887. _this = _BufferGeometry.call(this) || this;
  7888. _this.type = 'BoxGeometry';
  7889. _this.parameters = {
  7890. width: width,
  7891. height: height,
  7892. depth: depth,
  7893. widthSegments: widthSegments,
  7894. heightSegments: heightSegments,
  7895. depthSegments: depthSegments
  7896. };
  7897. var scope = _assertThisInitialized(_this); // segments
  7898. widthSegments = Math.floor(widthSegments);
  7899. heightSegments = Math.floor(heightSegments);
  7900. depthSegments = Math.floor(depthSegments); // buffers
  7901. var indices = [];
  7902. var vertices = [];
  7903. var normals = [];
  7904. var uvs = []; // helper variables
  7905. var numberOfVertices = 0;
  7906. var groupStart = 0; // build each side of the box geometry
  7907. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7908. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7909. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7910. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7911. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7912. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7913. // build geometry
  7914. _this.setIndex(indices);
  7915. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7916. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7917. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7918. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7919. var segmentWidth = width / gridX;
  7920. var segmentHeight = height / gridY;
  7921. var widthHalf = width / 2;
  7922. var heightHalf = height / 2;
  7923. var depthHalf = depth / 2;
  7924. var gridX1 = gridX + 1;
  7925. var gridY1 = gridY + 1;
  7926. var vertexCounter = 0;
  7927. var groupCount = 0;
  7928. var vector = new Vector3(); // generate vertices, normals and uvs
  7929. for (var iy = 0; iy < gridY1; iy++) {
  7930. var y = iy * segmentHeight - heightHalf;
  7931. for (var ix = 0; ix < gridX1; ix++) {
  7932. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7933. vector[u] = x * udir;
  7934. vector[v] = y * vdir;
  7935. vector[w] = depthHalf; // now apply vector to vertex buffer
  7936. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7937. vector[u] = 0;
  7938. vector[v] = 0;
  7939. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7940. normals.push(vector.x, vector.y, vector.z); // uvs
  7941. uvs.push(ix / gridX);
  7942. uvs.push(1 - iy / gridY); // counters
  7943. vertexCounter += 1;
  7944. }
  7945. } // indices
  7946. // 1. you need three indices to draw a single face
  7947. // 2. a single segment consists of two faces
  7948. // 3. so we need to generate six (2*3) indices per segment
  7949. for (var _iy = 0; _iy < gridY; _iy++) {
  7950. for (var _ix = 0; _ix < gridX; _ix++) {
  7951. var a = numberOfVertices + _ix + gridX1 * _iy;
  7952. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7953. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7954. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7955. indices.push(a, b, d);
  7956. indices.push(b, c, d); // increase counter
  7957. groupCount += 6;
  7958. }
  7959. } // add a group to the geometry. this will ensure multi material support
  7960. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7961. groupStart += groupCount; // update total number of vertices
  7962. numberOfVertices += vertexCounter;
  7963. }
  7964. return _this;
  7965. }
  7966. return BoxGeometry;
  7967. }(BufferGeometry);
  7968. /**
  7969. * Uniform Utilities
  7970. */
  7971. function cloneUniforms(src) {
  7972. var dst = {};
  7973. for (var u in src) {
  7974. dst[u] = {};
  7975. for (var p in src[u]) {
  7976. var property = src[u][p];
  7977. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture || property.isQuaternion)) {
  7978. dst[u][p] = property.clone();
  7979. } else if (Array.isArray(property)) {
  7980. dst[u][p] = property.slice();
  7981. } else {
  7982. dst[u][p] = property;
  7983. }
  7984. }
  7985. }
  7986. return dst;
  7987. }
  7988. function mergeUniforms(uniforms) {
  7989. var merged = {};
  7990. for (var u = 0; u < uniforms.length; u++) {
  7991. var tmp = cloneUniforms(uniforms[u]);
  7992. for (var p in tmp) {
  7993. merged[p] = tmp[p];
  7994. }
  7995. }
  7996. return merged;
  7997. } // Legacy
  7998. var UniformsUtils = {
  7999. clone: cloneUniforms,
  8000. merge: mergeUniforms
  8001. };
  8002. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  8003. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  8004. /**
  8005. * parameters = {
  8006. * defines: { "label" : "value" },
  8007. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  8008. *
  8009. * fragmentShader: <string>,
  8010. * vertexShader: <string>,
  8011. *
  8012. * wireframe: <boolean>,
  8013. * wireframeLinewidth: <float>,
  8014. *
  8015. * lights: <bool>,
  8016. *
  8017. * skinning: <bool>,
  8018. * morphTargets: <bool>,
  8019. * morphNormals: <bool>
  8020. * }
  8021. */
  8022. function ShaderMaterial(parameters) {
  8023. Material.call(this);
  8024. this.type = 'ShaderMaterial';
  8025. this.defines = {};
  8026. this.uniforms = {};
  8027. this.vertexShader = default_vertex;
  8028. this.fragmentShader = default_fragment;
  8029. this.linewidth = 1;
  8030. this.wireframe = false;
  8031. this.wireframeLinewidth = 1;
  8032. this.fog = false; // set to use scene fog
  8033. this.lights = false; // set to use scene lights
  8034. this.clipping = false; // set to use user-defined clipping planes
  8035. this.skinning = false; // set to use skinning attribute streams
  8036. this.morphTargets = false; // set to use morph targets
  8037. this.morphNormals = false; // set to use morph normals
  8038. this.extensions = {
  8039. derivatives: false,
  8040. // set to use derivatives
  8041. fragDepth: false,
  8042. // set to use fragment depth values
  8043. drawBuffers: false,
  8044. // set to use draw buffers
  8045. shaderTextureLOD: false // set to use shader texture LOD
  8046. }; // When rendered geometry doesn't include these attributes but the material does,
  8047. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8048. this.defaultAttributeValues = {
  8049. 'color': [1, 1, 1],
  8050. 'uv': [0, 0],
  8051. 'uv2': [0, 0]
  8052. };
  8053. this.index0AttributeName = undefined;
  8054. this.uniformsNeedUpdate = false;
  8055. this.glslVersion = null;
  8056. if (parameters !== undefined) {
  8057. if (parameters.attributes !== undefined) {
  8058. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  8059. }
  8060. this.setValues(parameters);
  8061. }
  8062. }
  8063. ShaderMaterial.prototype = Object.create(Material.prototype);
  8064. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8065. ShaderMaterial.prototype.isShaderMaterial = true;
  8066. ShaderMaterial.prototype.copy = function (source) {
  8067. Material.prototype.copy.call(this, source);
  8068. this.fragmentShader = source.fragmentShader;
  8069. this.vertexShader = source.vertexShader;
  8070. this.uniforms = cloneUniforms(source.uniforms);
  8071. this.defines = Object.assign({}, source.defines);
  8072. this.wireframe = source.wireframe;
  8073. this.wireframeLinewidth = source.wireframeLinewidth;
  8074. this.lights = source.lights;
  8075. this.clipping = source.clipping;
  8076. this.skinning = source.skinning;
  8077. this.morphTargets = source.morphTargets;
  8078. this.morphNormals = source.morphNormals;
  8079. this.extensions = Object.assign({}, source.extensions);
  8080. this.glslVersion = source.glslVersion;
  8081. return this;
  8082. };
  8083. ShaderMaterial.prototype.toJSON = function (meta) {
  8084. var data = Material.prototype.toJSON.call(this, meta);
  8085. data.glslVersion = this.glslVersion;
  8086. data.uniforms = {};
  8087. for (var name in this.uniforms) {
  8088. var uniform = this.uniforms[name];
  8089. var value = uniform.value;
  8090. if (value && value.isTexture) {
  8091. data.uniforms[name] = {
  8092. type: 't',
  8093. value: value.toJSON(meta).uuid
  8094. };
  8095. } else if (value && value.isColor) {
  8096. data.uniforms[name] = {
  8097. type: 'c',
  8098. value: value.getHex()
  8099. };
  8100. } else if (value && value.isVector2) {
  8101. data.uniforms[name] = {
  8102. type: 'v2',
  8103. value: value.toArray()
  8104. };
  8105. } else if (value && value.isVector3) {
  8106. data.uniforms[name] = {
  8107. type: 'v3',
  8108. value: value.toArray()
  8109. };
  8110. } else if (value && value.isVector4) {
  8111. data.uniforms[name] = {
  8112. type: 'v4',
  8113. value: value.toArray()
  8114. };
  8115. } else if (value && value.isMatrix3) {
  8116. data.uniforms[name] = {
  8117. type: 'm3',
  8118. value: value.toArray()
  8119. };
  8120. } else if (value && value.isMatrix4) {
  8121. data.uniforms[name] = {
  8122. type: 'm4',
  8123. value: value.toArray()
  8124. };
  8125. } else {
  8126. data.uniforms[name] = {
  8127. value: value
  8128. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8129. }
  8130. }
  8131. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  8132. data.vertexShader = this.vertexShader;
  8133. data.fragmentShader = this.fragmentShader;
  8134. var extensions = {};
  8135. for (var key in this.extensions) {
  8136. if (this.extensions[key] === true) extensions[key] = true;
  8137. }
  8138. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  8139. return data;
  8140. };
  8141. function Camera() {
  8142. Object3D.call(this);
  8143. this.type = 'Camera';
  8144. this.matrixWorldInverse = new Matrix4();
  8145. this.projectionMatrix = new Matrix4();
  8146. this.projectionMatrixInverse = new Matrix4();
  8147. }
  8148. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  8149. constructor: Camera,
  8150. isCamera: true,
  8151. copy: function copy(source, recursive) {
  8152. Object3D.prototype.copy.call(this, source, recursive);
  8153. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  8154. this.projectionMatrix.copy(source.projectionMatrix);
  8155. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  8156. return this;
  8157. },
  8158. getWorldDirection: function getWorldDirection(target) {
  8159. if (target === undefined) {
  8160. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  8161. target = new Vector3();
  8162. }
  8163. this.updateWorldMatrix(true, false);
  8164. var e = this.matrixWorld.elements;
  8165. return target.set(-e[8], -e[9], -e[10]).normalize();
  8166. },
  8167. updateMatrixWorld: function updateMatrixWorld(force) {
  8168. Object3D.prototype.updateMatrixWorld.call(this, force);
  8169. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8170. },
  8171. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  8172. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  8173. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8174. },
  8175. clone: function clone() {
  8176. return new this.constructor().copy(this);
  8177. }
  8178. });
  8179. function PerspectiveCamera(fov, aspect, near, far) {
  8180. if (fov === void 0) {
  8181. fov = 50;
  8182. }
  8183. if (aspect === void 0) {
  8184. aspect = 1;
  8185. }
  8186. if (near === void 0) {
  8187. near = 0.1;
  8188. }
  8189. if (far === void 0) {
  8190. far = 2000;
  8191. }
  8192. Camera.call(this);
  8193. this.type = 'PerspectiveCamera';
  8194. this.fov = fov;
  8195. this.zoom = 1;
  8196. this.near = near;
  8197. this.far = far;
  8198. this.focus = 10;
  8199. this.aspect = aspect;
  8200. this.view = null;
  8201. this.filmGauge = 35; // width of the film (default in millimeters)
  8202. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8203. this.updateProjectionMatrix();
  8204. }
  8205. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  8206. constructor: PerspectiveCamera,
  8207. isPerspectiveCamera: true,
  8208. copy: function copy(source, recursive) {
  8209. Camera.prototype.copy.call(this, source, recursive);
  8210. this.fov = source.fov;
  8211. this.zoom = source.zoom;
  8212. this.near = source.near;
  8213. this.far = source.far;
  8214. this.focus = source.focus;
  8215. this.aspect = source.aspect;
  8216. this.view = source.view === null ? null : Object.assign({}, source.view);
  8217. this.filmGauge = source.filmGauge;
  8218. this.filmOffset = source.filmOffset;
  8219. return this;
  8220. },
  8221. /**
  8222. * Sets the FOV by focal length in respect to the current .filmGauge.
  8223. *
  8224. * The default film gauge is 35, so that the focal length can be specified for
  8225. * a 35mm (full frame) camera.
  8226. *
  8227. * Values for focal length and film gauge must have the same unit.
  8228. */
  8229. setFocalLength: function setFocalLength(focalLength) {
  8230. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  8231. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8232. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  8233. this.updateProjectionMatrix();
  8234. },
  8235. /**
  8236. * Calculates the focal length from the current .fov and .filmGauge.
  8237. */
  8238. getFocalLength: function getFocalLength() {
  8239. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  8240. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8241. },
  8242. getEffectiveFOV: function getEffectiveFOV() {
  8243. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  8244. },
  8245. getFilmWidth: function getFilmWidth() {
  8246. // film not completely covered in portrait format (aspect < 1)
  8247. return this.filmGauge * Math.min(this.aspect, 1);
  8248. },
  8249. getFilmHeight: function getFilmHeight() {
  8250. // film not completely covered in landscape format (aspect > 1)
  8251. return this.filmGauge / Math.max(this.aspect, 1);
  8252. },
  8253. /**
  8254. * Sets an offset in a larger frustum. This is useful for multi-window or
  8255. * multi-monitor/multi-machine setups.
  8256. *
  8257. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8258. * the monitors are in grid like this
  8259. *
  8260. * +---+---+---+
  8261. * | A | B | C |
  8262. * +---+---+---+
  8263. * | D | E | F |
  8264. * +---+---+---+
  8265. *
  8266. * then for each monitor you would call it like this
  8267. *
  8268. * const w = 1920;
  8269. * const h = 1080;
  8270. * const fullWidth = w * 3;
  8271. * const fullHeight = h * 2;
  8272. *
  8273. * --A--
  8274. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8275. * --B--
  8276. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8277. * --C--
  8278. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8279. * --D--
  8280. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8281. * --E--
  8282. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8283. * --F--
  8284. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8285. *
  8286. * Note there is no reason monitors have to be the same size or in a grid.
  8287. */
  8288. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  8289. this.aspect = fullWidth / fullHeight;
  8290. if (this.view === null) {
  8291. this.view = {
  8292. enabled: true,
  8293. fullWidth: 1,
  8294. fullHeight: 1,
  8295. offsetX: 0,
  8296. offsetY: 0,
  8297. width: 1,
  8298. height: 1
  8299. };
  8300. }
  8301. this.view.enabled = true;
  8302. this.view.fullWidth = fullWidth;
  8303. this.view.fullHeight = fullHeight;
  8304. this.view.offsetX = x;
  8305. this.view.offsetY = y;
  8306. this.view.width = width;
  8307. this.view.height = height;
  8308. this.updateProjectionMatrix();
  8309. },
  8310. clearViewOffset: function clearViewOffset() {
  8311. if (this.view !== null) {
  8312. this.view.enabled = false;
  8313. }
  8314. this.updateProjectionMatrix();
  8315. },
  8316. updateProjectionMatrix: function updateProjectionMatrix() {
  8317. var near = this.near;
  8318. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  8319. var height = 2 * top;
  8320. var width = this.aspect * height;
  8321. var left = -0.5 * width;
  8322. var view = this.view;
  8323. if (this.view !== null && this.view.enabled) {
  8324. var fullWidth = view.fullWidth,
  8325. fullHeight = view.fullHeight;
  8326. left += view.offsetX * width / fullWidth;
  8327. top -= view.offsetY * height / fullHeight;
  8328. width *= view.width / fullWidth;
  8329. height *= view.height / fullHeight;
  8330. }
  8331. var skew = this.filmOffset;
  8332. if (skew !== 0) left += near * skew / this.getFilmWidth();
  8333. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  8334. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  8335. },
  8336. toJSON: function toJSON(meta) {
  8337. var data = Object3D.prototype.toJSON.call(this, meta);
  8338. data.object.fov = this.fov;
  8339. data.object.zoom = this.zoom;
  8340. data.object.near = this.near;
  8341. data.object.far = this.far;
  8342. data.object.focus = this.focus;
  8343. data.object.aspect = this.aspect;
  8344. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  8345. data.object.filmGauge = this.filmGauge;
  8346. data.object.filmOffset = this.filmOffset;
  8347. return data;
  8348. }
  8349. });
  8350. var fov = 90,
  8351. aspect = 1;
  8352. function CubeCamera(near, far, renderTarget) {
  8353. Object3D.call(this);
  8354. this.type = 'CubeCamera';
  8355. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  8356. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  8357. return;
  8358. }
  8359. this.renderTarget = renderTarget;
  8360. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  8361. cameraPX.layers = this.layers;
  8362. cameraPX.up.set(0, -1, 0);
  8363. cameraPX.lookAt(new Vector3(1, 0, 0));
  8364. this.add(cameraPX);
  8365. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  8366. cameraNX.layers = this.layers;
  8367. cameraNX.up.set(0, -1, 0);
  8368. cameraNX.lookAt(new Vector3(-1, 0, 0));
  8369. this.add(cameraNX);
  8370. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  8371. cameraPY.layers = this.layers;
  8372. cameraPY.up.set(0, 0, 1);
  8373. cameraPY.lookAt(new Vector3(0, 1, 0));
  8374. this.add(cameraPY);
  8375. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  8376. cameraNY.layers = this.layers;
  8377. cameraNY.up.set(0, 0, -1);
  8378. cameraNY.lookAt(new Vector3(0, -1, 0));
  8379. this.add(cameraNY);
  8380. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  8381. cameraPZ.layers = this.layers;
  8382. cameraPZ.up.set(0, -1, 0);
  8383. cameraPZ.lookAt(new Vector3(0, 0, 1));
  8384. this.add(cameraPZ);
  8385. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  8386. cameraNZ.layers = this.layers;
  8387. cameraNZ.up.set(0, -1, 0);
  8388. cameraNZ.lookAt(new Vector3(0, 0, -1));
  8389. this.add(cameraNZ);
  8390. this.update = function (renderer, scene) {
  8391. if (this.parent === null) this.updateMatrixWorld();
  8392. var currentXrEnabled = renderer.xr.enabled;
  8393. var currentRenderTarget = renderer.getRenderTarget();
  8394. renderer.xr.enabled = false;
  8395. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8396. renderTarget.texture.generateMipmaps = false;
  8397. renderer.setRenderTarget(renderTarget, 0);
  8398. renderer.render(scene, cameraPX);
  8399. renderer.setRenderTarget(renderTarget, 1);
  8400. renderer.render(scene, cameraNX);
  8401. renderer.setRenderTarget(renderTarget, 2);
  8402. renderer.render(scene, cameraPY);
  8403. renderer.setRenderTarget(renderTarget, 3);
  8404. renderer.render(scene, cameraNY);
  8405. renderer.setRenderTarget(renderTarget, 4);
  8406. renderer.render(scene, cameraPZ);
  8407. renderTarget.texture.generateMipmaps = generateMipmaps;
  8408. renderer.setRenderTarget(renderTarget, 5);
  8409. renderer.render(scene, cameraNZ);
  8410. renderer.setRenderTarget(currentRenderTarget);
  8411. renderer.xr.enabled = currentXrEnabled;
  8412. };
  8413. }
  8414. CubeCamera.prototype = Object.create(Object3D.prototype);
  8415. CubeCamera.prototype.constructor = CubeCamera;
  8416. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  8417. images = images !== undefined ? images : [];
  8418. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  8419. format = format !== undefined ? format : RGBFormat;
  8420. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8421. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  8422. //
  8423. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  8424. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  8425. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  8426. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  8427. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  8428. // when using WebGLCubeRenderTarget.texture as a cube texture.
  8429. this._needsFlipEnvMap = true;
  8430. }
  8431. CubeTexture.prototype = Object.create(Texture.prototype);
  8432. CubeTexture.prototype.constructor = CubeTexture;
  8433. CubeTexture.prototype.isCubeTexture = true;
  8434. Object.defineProperty(CubeTexture.prototype, 'images', {
  8435. get: function get() {
  8436. return this.image;
  8437. },
  8438. set: function set(value) {
  8439. this.image = value;
  8440. }
  8441. });
  8442. var WebGLCubeRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  8443. _inheritsLoose(WebGLCubeRenderTarget, _WebGLRenderTarget);
  8444. function WebGLCubeRenderTarget(size, options, dummy) {
  8445. var _this;
  8446. if (Number.isInteger(options)) {
  8447. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  8448. options = dummy;
  8449. }
  8450. _this = _WebGLRenderTarget.call(this, size, size, options) || this;
  8451. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLCubeRenderTarget', {
  8452. value: true
  8453. });
  8454. options = options || {};
  8455. _this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  8456. _this.texture._needsFlipEnvMap = false;
  8457. return _this;
  8458. }
  8459. var _proto = WebGLCubeRenderTarget.prototype;
  8460. _proto.fromEquirectangularTexture = function fromEquirectangularTexture(renderer, texture) {
  8461. this.texture.type = texture.type;
  8462. this.texture.format = RGBAFormat; // see #18859
  8463. this.texture.encoding = texture.encoding;
  8464. this.texture.generateMipmaps = texture.generateMipmaps;
  8465. this.texture.minFilter = texture.minFilter;
  8466. this.texture.magFilter = texture.magFilter;
  8467. var shader = {
  8468. uniforms: {
  8469. tEquirect: {
  8470. value: null
  8471. }
  8472. },
  8473. vertexShader:
  8474. /* glsl */
  8475. "\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\n\n\t\t\t\t}\n\t\t\t",
  8476. fragmentShader:
  8477. /* glsl */
  8478. "\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include <common>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"
  8479. };
  8480. var geometry = new BoxGeometry(5, 5, 5);
  8481. var material = new ShaderMaterial({
  8482. name: 'CubemapFromEquirect',
  8483. uniforms: cloneUniforms(shader.uniforms),
  8484. vertexShader: shader.vertexShader,
  8485. fragmentShader: shader.fragmentShader,
  8486. side: BackSide,
  8487. blending: NoBlending
  8488. });
  8489. material.uniforms.tEquirect.value = texture;
  8490. var mesh = new Mesh(geometry, material);
  8491. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8492. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8493. var camera = new CubeCamera(1, 10, this);
  8494. camera.update(renderer, mesh);
  8495. texture.minFilter = currentMinFilter;
  8496. mesh.geometry.dispose();
  8497. mesh.material.dispose();
  8498. return this;
  8499. };
  8500. _proto.clear = function clear(renderer, color, depth, stencil) {
  8501. var currentRenderTarget = renderer.getRenderTarget();
  8502. for (var i = 0; i < 6; i++) {
  8503. renderer.setRenderTarget(this, i);
  8504. renderer.clear(color, depth, stencil);
  8505. }
  8506. renderer.setRenderTarget(currentRenderTarget);
  8507. };
  8508. return WebGLCubeRenderTarget;
  8509. }(WebGLRenderTarget);
  8510. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8511. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8512. this.image = {
  8513. data: data || null,
  8514. width: width || 1,
  8515. height: height || 1
  8516. };
  8517. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8518. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8519. this.generateMipmaps = false;
  8520. this.flipY = false;
  8521. this.unpackAlignment = 1;
  8522. this.needsUpdate = true;
  8523. }
  8524. DataTexture.prototype = Object.create(Texture.prototype);
  8525. DataTexture.prototype.constructor = DataTexture;
  8526. DataTexture.prototype.isDataTexture = true;
  8527. var _sphere$1 = /*@__PURE__*/new Sphere();
  8528. var _vector$5 = /*@__PURE__*/new Vector3();
  8529. var Frustum = /*#__PURE__*/function () {
  8530. function Frustum(p0, p1, p2, p3, p4, p5) {
  8531. this.planes = [p0 !== undefined ? p0 : new Plane(), p1 !== undefined ? p1 : new Plane(), p2 !== undefined ? p2 : new Plane(), p3 !== undefined ? p3 : new Plane(), p4 !== undefined ? p4 : new Plane(), p5 !== undefined ? p5 : new Plane()];
  8532. }
  8533. var _proto = Frustum.prototype;
  8534. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8535. var planes = this.planes;
  8536. planes[0].copy(p0);
  8537. planes[1].copy(p1);
  8538. planes[2].copy(p2);
  8539. planes[3].copy(p3);
  8540. planes[4].copy(p4);
  8541. planes[5].copy(p5);
  8542. return this;
  8543. };
  8544. _proto.clone = function clone() {
  8545. return new this.constructor().copy(this);
  8546. };
  8547. _proto.copy = function copy(frustum) {
  8548. var planes = this.planes;
  8549. for (var i = 0; i < 6; i++) {
  8550. planes[i].copy(frustum.planes[i]);
  8551. }
  8552. return this;
  8553. };
  8554. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8555. var planes = this.planes;
  8556. var me = m.elements;
  8557. var me0 = me[0],
  8558. me1 = me[1],
  8559. me2 = me[2],
  8560. me3 = me[3];
  8561. var me4 = me[4],
  8562. me5 = me[5],
  8563. me6 = me[6],
  8564. me7 = me[7];
  8565. var me8 = me[8],
  8566. me9 = me[9],
  8567. me10 = me[10],
  8568. me11 = me[11];
  8569. var me12 = me[12],
  8570. me13 = me[13],
  8571. me14 = me[14],
  8572. me15 = me[15];
  8573. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8574. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8575. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8576. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8577. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8578. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8579. return this;
  8580. };
  8581. _proto.intersectsObject = function intersectsObject(object) {
  8582. var geometry = object.geometry;
  8583. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8584. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8585. return this.intersectsSphere(_sphere$1);
  8586. };
  8587. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8588. _sphere$1.center.set(0, 0, 0);
  8589. _sphere$1.radius = 0.7071067811865476;
  8590. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8591. return this.intersectsSphere(_sphere$1);
  8592. };
  8593. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8594. var planes = this.planes;
  8595. var center = sphere.center;
  8596. var negRadius = -sphere.radius;
  8597. for (var i = 0; i < 6; i++) {
  8598. var distance = planes[i].distanceToPoint(center);
  8599. if (distance < negRadius) {
  8600. return false;
  8601. }
  8602. }
  8603. return true;
  8604. };
  8605. _proto.intersectsBox = function intersectsBox(box) {
  8606. var planes = this.planes;
  8607. for (var i = 0; i < 6; i++) {
  8608. var plane = planes[i]; // corner at max distance
  8609. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8610. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8611. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8612. if (plane.distanceToPoint(_vector$5) < 0) {
  8613. return false;
  8614. }
  8615. }
  8616. return true;
  8617. };
  8618. _proto.containsPoint = function containsPoint(point) {
  8619. var planes = this.planes;
  8620. for (var i = 0; i < 6; i++) {
  8621. if (planes[i].distanceToPoint(point) < 0) {
  8622. return false;
  8623. }
  8624. }
  8625. return true;
  8626. };
  8627. return Frustum;
  8628. }();
  8629. function WebGLAnimation() {
  8630. var context = null;
  8631. var isAnimating = false;
  8632. var animationLoop = null;
  8633. var requestId = null;
  8634. function onAnimationFrame(time, frame) {
  8635. animationLoop(time, frame);
  8636. requestId = context.requestAnimationFrame(onAnimationFrame);
  8637. }
  8638. return {
  8639. start: function start() {
  8640. if (isAnimating === true) return;
  8641. if (animationLoop === null) return;
  8642. requestId = context.requestAnimationFrame(onAnimationFrame);
  8643. isAnimating = true;
  8644. },
  8645. stop: function stop() {
  8646. context.cancelAnimationFrame(requestId);
  8647. isAnimating = false;
  8648. },
  8649. setAnimationLoop: function setAnimationLoop(callback) {
  8650. animationLoop = callback;
  8651. },
  8652. setContext: function setContext(value) {
  8653. context = value;
  8654. }
  8655. };
  8656. }
  8657. function WebGLAttributes(gl, capabilities) {
  8658. var isWebGL2 = capabilities.isWebGL2;
  8659. var buffers = new WeakMap();
  8660. function createBuffer(attribute, bufferType) {
  8661. var array = attribute.array;
  8662. var usage = attribute.usage;
  8663. var buffer = gl.createBuffer();
  8664. gl.bindBuffer(bufferType, buffer);
  8665. gl.bufferData(bufferType, array, usage);
  8666. attribute.onUploadCallback();
  8667. var type = 5126;
  8668. if (array instanceof Float32Array) {
  8669. type = 5126;
  8670. } else if (array instanceof Float64Array) {
  8671. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8672. } else if (array instanceof Uint16Array) {
  8673. if (attribute.isFloat16BufferAttribute) {
  8674. if (isWebGL2) {
  8675. type = 5131;
  8676. } else {
  8677. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8678. }
  8679. } else {
  8680. type = 5123;
  8681. }
  8682. } else if (array instanceof Int16Array) {
  8683. type = 5122;
  8684. } else if (array instanceof Uint32Array) {
  8685. type = 5125;
  8686. } else if (array instanceof Int32Array) {
  8687. type = 5124;
  8688. } else if (array instanceof Int8Array) {
  8689. type = 5120;
  8690. } else if (array instanceof Uint8Array) {
  8691. type = 5121;
  8692. }
  8693. return {
  8694. buffer: buffer,
  8695. type: type,
  8696. bytesPerElement: array.BYTES_PER_ELEMENT,
  8697. version: attribute.version
  8698. };
  8699. }
  8700. function updateBuffer(buffer, attribute, bufferType) {
  8701. var array = attribute.array;
  8702. var updateRange = attribute.updateRange;
  8703. gl.bindBuffer(bufferType, buffer);
  8704. if (updateRange.count === -1) {
  8705. // Not using update ranges
  8706. gl.bufferSubData(bufferType, 0, array);
  8707. } else {
  8708. if (isWebGL2) {
  8709. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8710. } else {
  8711. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8712. }
  8713. updateRange.count = -1; // reset range
  8714. }
  8715. } //
  8716. function get(attribute) {
  8717. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8718. return buffers.get(attribute);
  8719. }
  8720. function remove(attribute) {
  8721. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8722. var data = buffers.get(attribute);
  8723. if (data) {
  8724. gl.deleteBuffer(data.buffer);
  8725. buffers.delete(attribute);
  8726. }
  8727. }
  8728. function update(attribute, bufferType) {
  8729. if (attribute.isGLBufferAttribute) {
  8730. var cached = buffers.get(attribute);
  8731. if (!cached || cached.version < attribute.version) {
  8732. buffers.set(attribute, {
  8733. buffer: attribute.buffer,
  8734. type: attribute.type,
  8735. bytesPerElement: attribute.elementSize,
  8736. version: attribute.version
  8737. });
  8738. }
  8739. return;
  8740. }
  8741. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8742. var data = buffers.get(attribute);
  8743. if (data === undefined) {
  8744. buffers.set(attribute, createBuffer(attribute, bufferType));
  8745. } else if (data.version < attribute.version) {
  8746. updateBuffer(data.buffer, attribute, bufferType);
  8747. data.version = attribute.version;
  8748. }
  8749. }
  8750. return {
  8751. get: get,
  8752. remove: remove,
  8753. update: update
  8754. };
  8755. }
  8756. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8757. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8758. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8759. var _this;
  8760. if (width === void 0) {
  8761. width = 1;
  8762. }
  8763. if (height === void 0) {
  8764. height = 1;
  8765. }
  8766. if (widthSegments === void 0) {
  8767. widthSegments = 1;
  8768. }
  8769. if (heightSegments === void 0) {
  8770. heightSegments = 1;
  8771. }
  8772. _this = _BufferGeometry.call(this) || this;
  8773. _this.type = 'PlaneGeometry';
  8774. _this.parameters = {
  8775. width: width,
  8776. height: height,
  8777. widthSegments: widthSegments,
  8778. heightSegments: heightSegments
  8779. };
  8780. var width_half = width / 2;
  8781. var height_half = height / 2;
  8782. var gridX = Math.floor(widthSegments);
  8783. var gridY = Math.floor(heightSegments);
  8784. var gridX1 = gridX + 1;
  8785. var gridY1 = gridY + 1;
  8786. var segment_width = width / gridX;
  8787. var segment_height = height / gridY; //
  8788. var indices = [];
  8789. var vertices = [];
  8790. var normals = [];
  8791. var uvs = [];
  8792. for (var iy = 0; iy < gridY1; iy++) {
  8793. var y = iy * segment_height - height_half;
  8794. for (var ix = 0; ix < gridX1; ix++) {
  8795. var x = ix * segment_width - width_half;
  8796. vertices.push(x, -y, 0);
  8797. normals.push(0, 0, 1);
  8798. uvs.push(ix / gridX);
  8799. uvs.push(1 - iy / gridY);
  8800. }
  8801. }
  8802. for (var _iy = 0; _iy < gridY; _iy++) {
  8803. for (var _ix = 0; _ix < gridX; _ix++) {
  8804. var a = _ix + gridX1 * _iy;
  8805. var b = _ix + gridX1 * (_iy + 1);
  8806. var c = _ix + 1 + gridX1 * (_iy + 1);
  8807. var d = _ix + 1 + gridX1 * _iy;
  8808. indices.push(a, b, d);
  8809. indices.push(b, c, d);
  8810. }
  8811. }
  8812. _this.setIndex(indices);
  8813. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8814. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8815. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8816. return _this;
  8817. }
  8818. return PlaneGeometry;
  8819. }(BufferGeometry);
  8820. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8821. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8822. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8823. var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif";
  8824. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8825. var begin_vertex = "vec3 transformed = vec3( position );";
  8826. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8827. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie(float roughness, float NoH) {\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125);\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\nfloat V_Neubelt(float NoV, float NoL) {\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif";
  8828. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  8829. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";
  8830. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8831. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8832. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8833. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8834. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8835. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8836. var color_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor.xyz *= color.xyz;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif";
  8837. var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}";
  8838. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_maxMipLevel 8.0\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_maxTileSize 256.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\tfloat texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );\n\t\tvec2 uv = getUV( direction, face ) * ( faceSize - 1.0 );\n\t\tvec2 f = fract( uv );\n\t\tuv += 0.5 - f;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tif ( mipInt < cubeUV_maxMipLevel ) {\n\t\t\tuv.y += 2.0 * cubeUV_maxTileSize;\n\t\t}\n\t\tuv.y += filterInt * 2.0 * cubeUV_minTileSize;\n\t\tuv.x += 3.0 * max( 0.0, cubeUV_maxTileSize - 2.0 * faceSize );\n\t\tuv *= texelSize;\n\t\tvec3 tl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x += texelSize;\n\t\tvec3 tr = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.y += texelSize;\n\t\tvec3 br = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x -= texelSize;\n\t\tvec3 bl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tvec3 tm = mix( tl, tr, f.x );\n\t\tvec3 bm = mix( bl, br, f.x );\n\t\treturn mix( tm, bm, f.y );\n\t}\n\t#define r0 1.0\n\t#define v0 0.339\n\t#define m0 - 2.0\n\t#define r1 0.8\n\t#define v1 0.276\n\t#define m1 - 1.0\n\t#define r4 0.4\n\t#define v4 0.046\n\t#define m4 2.0\n\t#define r5 0.305\n\t#define v5 0.016\n\t#define m5 3.0\n\t#define r6 0.21\n\t#define v6 0.0038\n\t#define m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= r1 ) {\n\t\t\tmip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;\n\t\t} else if ( roughness >= r4 ) {\n\t\t\tmip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;\n\t\t} else if ( roughness >= r5 ) {\n\t\t\tmip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;\n\t\t} else if ( roughness >= r6 ) {\n\t\t\tmip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), m0, cubeUV_maxMipLevel );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif";
  8839. var defaultnormal_vertex = "vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";
  8840. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8841. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8842. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8843. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8844. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8845. var encodings_pars_fragment = "\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = clamp( floor( D ) / 255.0, 0.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = cLogLuvM * value.rgb;\n\tXp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract( Le );\n\tvResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";
  8846. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
  8847. var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif";
  8848. var envmap_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
  8849. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";
  8850. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif";
  8851. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8852. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8853. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";
  8854. var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif";
  8855. var gradientmap_pars_fragment = "#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn texture2D( gradientMap, coord ).rgb;\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}";
  8856. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8857. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8858. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif";
  8859. var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {\n\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";
  8860. var envmap_physical_pars_fragment = "#if defined( USE_ENVMAP )\n\t#ifdef ENVMAP_MODE_REFRACTION\n\t\tuniform float refractionRatio;\n\t#endif\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat sigma = PI * roughness * roughness / ( 1.0 + roughness );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + log2( sigma );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -viewDir, normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";
  8861. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8862. var lights_toon_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD( material )\t(0)";
  8863. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8864. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)";
  8865. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.specularRoughness = max( roughnessFactor, 0.0525 );material.specularRoughness += geometryRoughness;\nmaterial.specularRoughness = min( material.specularRoughness, 1.0 );\n#ifdef REFLECTIVITY\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#endif\n#ifdef CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheen;\n#endif";
  8866. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat specularRoughness;\n\tvec3 specularColor;\n#ifdef CLEARCOAT\n\tfloat clearcoat;\n\tfloat clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tvec3 sheenColor;\n#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearcoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNL = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = ccDotNL * directLight.color;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tccIrradiance *= PI;\n\t\t#endif\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t\treflectedLight.directSpecular += ccIrradiance * material.clearcoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_Sheen(\n\t\t\tmaterial.specularRoughness,\n\t\t\tdirectLight.direction,\n\t\t\tgeometry,\n\t\t\tmaterial.sheenColor\n\t\t);\n\t#else\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness);\n\t#endif\n\treflectedLight.directDiffuse += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNV = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular += clearcoatRadiance * material.clearcoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t\tfloat ccDotNL = ccDotNV;\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\tfloat clearcoatInv = 1.0 - clearcoatDHR;\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += clearcoatInv * radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
  8867. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";
  8868. var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );\n\t#ifdef CLEARCOAT\n\t\tclearcoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness, maxMipLevel );\n\t#endif\n#endif";
  8869. var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif";
  8870. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  8871. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif";
  8872. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";
  8873. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif";
  8874. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8875. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8876. var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";
  8877. var map_particle_pars_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8878. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8879. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8880. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n#endif";
  8881. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifndef USE_MORPHNORMALS\n\t\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\t\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  8882. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
  8883. var normal_fragment_begin = "float faceDirection = float( gl_FrontFacing ) * 2.0 - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * faceDirection;\n\t\t\tbitangent = bitangent * faceDirection;\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  8884. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN, faceDirection );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif";
  8885. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= faceDirection;\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8886. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8887. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );\n\t#endif\n#endif";
  8888. var clearcoat_pars_fragment = "#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif";
  8889. var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}";
  8890. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8891. var project_vertex = "vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;";
  8892. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8893. var dithering_pars_fragment = "#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";
  8894. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8895. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8896. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";
  8897. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";
  8898. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\tvec4 shadowWorldPosition;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif";
  8899. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";
  8900. var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
  8901. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
  8902. var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";
  8903. var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";
  8904. var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";
  8905. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8906. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8907. var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }";
  8908. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8909. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8910. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8911. var uv_pars_vertex = "#ifdef USE_UV\n\t#ifdef UVS_VERTEX_ONLY\n\t\tvec2 vUv;\n\t#else\n\t\tvarying vec2 vUv;\n\t#endif\n\tuniform mat3 uvTransform;\n#endif";
  8912. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8913. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8914. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif";
  8915. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8916. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif";
  8917. var background_frag = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8918. var background_vert = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";
  8919. var cube_frag = "#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8920. var cube_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
  8921. var depth_frag = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#endif\n}";
  8922. var depth_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}";
  8923. var distanceRGBA_frag = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";
  8924. var distanceRGBA_vert = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";
  8925. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8926. var equirect_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
  8927. var linedashed_frag = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  8928. var linedashed_vert = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  8929. var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8930. var meshbasic_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";
  8931. var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8932. var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8933. var meshmatcap_frag = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8934. var meshmatcap_vert = "#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
  8935. var meshtoon_frag = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8936. var meshtoon_vert = "#define TOON\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8937. var meshphong_frag = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8938. var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8939. var meshphysical_frag = "#define STANDARD\n#ifdef PHYSICAL\n\t#define REFLECTIVITY\n\t#define CLEARCOAT\n\t#define TRANSMISSION\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef TRANSMISSION\n\tuniform float transmission;\n#endif\n#ifdef REFLECTIVITY\n\tuniform float reflectivity;\n#endif\n#ifdef CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheen;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <transmissionmap_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#ifdef TRANSMISSION\n\t\tfloat totalTransmission = transmission;\n\t#endif\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <transmissionmap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSMISSION\n\t\tdiffuseColor.a *= mix( saturate( 1. - totalTransmission + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) ), 1.0, metalness );\n\t#endif\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8940. var meshphysical_vert = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8941. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
  8942. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  8943. var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  8944. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";
  8945. var shadow_frag = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8946. var shadow_vert = "#include <common>\n#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8947. var sprite_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8948. var sprite_vert = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  8949. var ShaderChunk = {
  8950. alphamap_fragment: alphamap_fragment,
  8951. alphamap_pars_fragment: alphamap_pars_fragment,
  8952. alphatest_fragment: alphatest_fragment,
  8953. aomap_fragment: aomap_fragment,
  8954. aomap_pars_fragment: aomap_pars_fragment,
  8955. begin_vertex: begin_vertex,
  8956. beginnormal_vertex: beginnormal_vertex,
  8957. bsdfs: bsdfs,
  8958. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8959. clipping_planes_fragment: clipping_planes_fragment,
  8960. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8961. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8962. clipping_planes_vertex: clipping_planes_vertex,
  8963. color_fragment: color_fragment,
  8964. color_pars_fragment: color_pars_fragment,
  8965. color_pars_vertex: color_pars_vertex,
  8966. color_vertex: color_vertex,
  8967. common: common,
  8968. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8969. defaultnormal_vertex: defaultnormal_vertex,
  8970. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8971. displacementmap_vertex: displacementmap_vertex,
  8972. emissivemap_fragment: emissivemap_fragment,
  8973. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8974. encodings_fragment: encodings_fragment,
  8975. encodings_pars_fragment: encodings_pars_fragment,
  8976. envmap_fragment: envmap_fragment,
  8977. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8978. envmap_pars_fragment: envmap_pars_fragment,
  8979. envmap_pars_vertex: envmap_pars_vertex,
  8980. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8981. envmap_vertex: envmap_vertex,
  8982. fog_vertex: fog_vertex,
  8983. fog_pars_vertex: fog_pars_vertex,
  8984. fog_fragment: fog_fragment,
  8985. fog_pars_fragment: fog_pars_fragment,
  8986. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8987. lightmap_fragment: lightmap_fragment,
  8988. lightmap_pars_fragment: lightmap_pars_fragment,
  8989. lights_lambert_vertex: lights_lambert_vertex,
  8990. lights_pars_begin: lights_pars_begin,
  8991. lights_toon_fragment: lights_toon_fragment,
  8992. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8993. lights_phong_fragment: lights_phong_fragment,
  8994. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8995. lights_physical_fragment: lights_physical_fragment,
  8996. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8997. lights_fragment_begin: lights_fragment_begin,
  8998. lights_fragment_maps: lights_fragment_maps,
  8999. lights_fragment_end: lights_fragment_end,
  9000. logdepthbuf_fragment: logdepthbuf_fragment,
  9001. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9002. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9003. logdepthbuf_vertex: logdepthbuf_vertex,
  9004. map_fragment: map_fragment,
  9005. map_pars_fragment: map_pars_fragment,
  9006. map_particle_fragment: map_particle_fragment,
  9007. map_particle_pars_fragment: map_particle_pars_fragment,
  9008. metalnessmap_fragment: metalnessmap_fragment,
  9009. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9010. morphnormal_vertex: morphnormal_vertex,
  9011. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9012. morphtarget_vertex: morphtarget_vertex,
  9013. normal_fragment_begin: normal_fragment_begin,
  9014. normal_fragment_maps: normal_fragment_maps,
  9015. normalmap_pars_fragment: normalmap_pars_fragment,
  9016. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9017. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9018. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9019. packing: packing,
  9020. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9021. project_vertex: project_vertex,
  9022. dithering_fragment: dithering_fragment,
  9023. dithering_pars_fragment: dithering_pars_fragment,
  9024. roughnessmap_fragment: roughnessmap_fragment,
  9025. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9026. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9027. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9028. shadowmap_vertex: shadowmap_vertex,
  9029. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9030. skinbase_vertex: skinbase_vertex,
  9031. skinning_pars_vertex: skinning_pars_vertex,
  9032. skinning_vertex: skinning_vertex,
  9033. skinnormal_vertex: skinnormal_vertex,
  9034. specularmap_fragment: specularmap_fragment,
  9035. specularmap_pars_fragment: specularmap_pars_fragment,
  9036. tonemapping_fragment: tonemapping_fragment,
  9037. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9038. transmissionmap_fragment: transmissionmap_fragment,
  9039. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  9040. uv_pars_fragment: uv_pars_fragment,
  9041. uv_pars_vertex: uv_pars_vertex,
  9042. uv_vertex: uv_vertex,
  9043. uv2_pars_fragment: uv2_pars_fragment,
  9044. uv2_pars_vertex: uv2_pars_vertex,
  9045. uv2_vertex: uv2_vertex,
  9046. worldpos_vertex: worldpos_vertex,
  9047. background_frag: background_frag,
  9048. background_vert: background_vert,
  9049. cube_frag: cube_frag,
  9050. cube_vert: cube_vert,
  9051. depth_frag: depth_frag,
  9052. depth_vert: depth_vert,
  9053. distanceRGBA_frag: distanceRGBA_frag,
  9054. distanceRGBA_vert: distanceRGBA_vert,
  9055. equirect_frag: equirect_frag,
  9056. equirect_vert: equirect_vert,
  9057. linedashed_frag: linedashed_frag,
  9058. linedashed_vert: linedashed_vert,
  9059. meshbasic_frag: meshbasic_frag,
  9060. meshbasic_vert: meshbasic_vert,
  9061. meshlambert_frag: meshlambert_frag,
  9062. meshlambert_vert: meshlambert_vert,
  9063. meshmatcap_frag: meshmatcap_frag,
  9064. meshmatcap_vert: meshmatcap_vert,
  9065. meshtoon_frag: meshtoon_frag,
  9066. meshtoon_vert: meshtoon_vert,
  9067. meshphong_frag: meshphong_frag,
  9068. meshphong_vert: meshphong_vert,
  9069. meshphysical_frag: meshphysical_frag,
  9070. meshphysical_vert: meshphysical_vert,
  9071. normal_frag: normal_frag,
  9072. normal_vert: normal_vert,
  9073. points_frag: points_frag,
  9074. points_vert: points_vert,
  9075. shadow_frag: shadow_frag,
  9076. shadow_vert: shadow_vert,
  9077. sprite_frag: sprite_frag,
  9078. sprite_vert: sprite_vert
  9079. };
  9080. /**
  9081. * Uniforms library for shared webgl shaders
  9082. */
  9083. var UniformsLib = {
  9084. common: {
  9085. diffuse: {
  9086. value: new Color(0xeeeeee)
  9087. },
  9088. opacity: {
  9089. value: 1.0
  9090. },
  9091. map: {
  9092. value: null
  9093. },
  9094. uvTransform: {
  9095. value: new Matrix3()
  9096. },
  9097. uv2Transform: {
  9098. value: new Matrix3()
  9099. },
  9100. alphaMap: {
  9101. value: null
  9102. }
  9103. },
  9104. specularmap: {
  9105. specularMap: {
  9106. value: null
  9107. }
  9108. },
  9109. envmap: {
  9110. envMap: {
  9111. value: null
  9112. },
  9113. flipEnvMap: {
  9114. value: -1
  9115. },
  9116. reflectivity: {
  9117. value: 1.0
  9118. },
  9119. refractionRatio: {
  9120. value: 0.98
  9121. },
  9122. maxMipLevel: {
  9123. value: 0
  9124. }
  9125. },
  9126. aomap: {
  9127. aoMap: {
  9128. value: null
  9129. },
  9130. aoMapIntensity: {
  9131. value: 1
  9132. }
  9133. },
  9134. lightmap: {
  9135. lightMap: {
  9136. value: null
  9137. },
  9138. lightMapIntensity: {
  9139. value: 1
  9140. }
  9141. },
  9142. emissivemap: {
  9143. emissiveMap: {
  9144. value: null
  9145. }
  9146. },
  9147. bumpmap: {
  9148. bumpMap: {
  9149. value: null
  9150. },
  9151. bumpScale: {
  9152. value: 1
  9153. }
  9154. },
  9155. normalmap: {
  9156. normalMap: {
  9157. value: null
  9158. },
  9159. normalScale: {
  9160. value: new Vector2(1, 1)
  9161. }
  9162. },
  9163. displacementmap: {
  9164. displacementMap: {
  9165. value: null
  9166. },
  9167. displacementScale: {
  9168. value: 1
  9169. },
  9170. displacementBias: {
  9171. value: 0
  9172. }
  9173. },
  9174. roughnessmap: {
  9175. roughnessMap: {
  9176. value: null
  9177. }
  9178. },
  9179. metalnessmap: {
  9180. metalnessMap: {
  9181. value: null
  9182. }
  9183. },
  9184. gradientmap: {
  9185. gradientMap: {
  9186. value: null
  9187. }
  9188. },
  9189. fog: {
  9190. fogDensity: {
  9191. value: 0.00025
  9192. },
  9193. fogNear: {
  9194. value: 1
  9195. },
  9196. fogFar: {
  9197. value: 2000
  9198. },
  9199. fogColor: {
  9200. value: new Color(0xffffff)
  9201. }
  9202. },
  9203. lights: {
  9204. ambientLightColor: {
  9205. value: []
  9206. },
  9207. lightProbe: {
  9208. value: []
  9209. },
  9210. directionalLights: {
  9211. value: [],
  9212. properties: {
  9213. direction: {},
  9214. color: {}
  9215. }
  9216. },
  9217. directionalLightShadows: {
  9218. value: [],
  9219. properties: {
  9220. shadowBias: {},
  9221. shadowNormalBias: {},
  9222. shadowRadius: {},
  9223. shadowMapSize: {}
  9224. }
  9225. },
  9226. directionalShadowMap: {
  9227. value: []
  9228. },
  9229. directionalShadowMatrix: {
  9230. value: []
  9231. },
  9232. spotLights: {
  9233. value: [],
  9234. properties: {
  9235. color: {},
  9236. position: {},
  9237. direction: {},
  9238. distance: {},
  9239. coneCos: {},
  9240. penumbraCos: {},
  9241. decay: {}
  9242. }
  9243. },
  9244. spotLightShadows: {
  9245. value: [],
  9246. properties: {
  9247. shadowBias: {},
  9248. shadowNormalBias: {},
  9249. shadowRadius: {},
  9250. shadowMapSize: {}
  9251. }
  9252. },
  9253. spotShadowMap: {
  9254. value: []
  9255. },
  9256. spotShadowMatrix: {
  9257. value: []
  9258. },
  9259. pointLights: {
  9260. value: [],
  9261. properties: {
  9262. color: {},
  9263. position: {},
  9264. decay: {},
  9265. distance: {}
  9266. }
  9267. },
  9268. pointLightShadows: {
  9269. value: [],
  9270. properties: {
  9271. shadowBias: {},
  9272. shadowNormalBias: {},
  9273. shadowRadius: {},
  9274. shadowMapSize: {},
  9275. shadowCameraNear: {},
  9276. shadowCameraFar: {}
  9277. }
  9278. },
  9279. pointShadowMap: {
  9280. value: []
  9281. },
  9282. pointShadowMatrix: {
  9283. value: []
  9284. },
  9285. hemisphereLights: {
  9286. value: [],
  9287. properties: {
  9288. direction: {},
  9289. skyColor: {},
  9290. groundColor: {}
  9291. }
  9292. },
  9293. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9294. rectAreaLights: {
  9295. value: [],
  9296. properties: {
  9297. color: {},
  9298. position: {},
  9299. width: {},
  9300. height: {}
  9301. }
  9302. },
  9303. ltc_1: {
  9304. value: null
  9305. },
  9306. ltc_2: {
  9307. value: null
  9308. }
  9309. },
  9310. points: {
  9311. diffuse: {
  9312. value: new Color(0xeeeeee)
  9313. },
  9314. opacity: {
  9315. value: 1.0
  9316. },
  9317. size: {
  9318. value: 1.0
  9319. },
  9320. scale: {
  9321. value: 1.0
  9322. },
  9323. map: {
  9324. value: null
  9325. },
  9326. alphaMap: {
  9327. value: null
  9328. },
  9329. uvTransform: {
  9330. value: new Matrix3()
  9331. }
  9332. },
  9333. sprite: {
  9334. diffuse: {
  9335. value: new Color(0xeeeeee)
  9336. },
  9337. opacity: {
  9338. value: 1.0
  9339. },
  9340. center: {
  9341. value: new Vector2(0.5, 0.5)
  9342. },
  9343. rotation: {
  9344. value: 0.0
  9345. },
  9346. map: {
  9347. value: null
  9348. },
  9349. alphaMap: {
  9350. value: null
  9351. },
  9352. uvTransform: {
  9353. value: new Matrix3()
  9354. }
  9355. }
  9356. };
  9357. var ShaderLib = {
  9358. basic: {
  9359. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  9360. vertexShader: ShaderChunk.meshbasic_vert,
  9361. fragmentShader: ShaderChunk.meshbasic_frag
  9362. },
  9363. lambert: {
  9364. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  9365. emissive: {
  9366. value: new Color(0x000000)
  9367. }
  9368. }]),
  9369. vertexShader: ShaderChunk.meshlambert_vert,
  9370. fragmentShader: ShaderChunk.meshlambert_frag
  9371. },
  9372. phong: {
  9373. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  9374. emissive: {
  9375. value: new Color(0x000000)
  9376. },
  9377. specular: {
  9378. value: new Color(0x111111)
  9379. },
  9380. shininess: {
  9381. value: 30
  9382. }
  9383. }]),
  9384. vertexShader: ShaderChunk.meshphong_vert,
  9385. fragmentShader: ShaderChunk.meshphong_frag
  9386. },
  9387. standard: {
  9388. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.roughnessmap, UniformsLib.metalnessmap, UniformsLib.fog, UniformsLib.lights, {
  9389. emissive: {
  9390. value: new Color(0x000000)
  9391. },
  9392. roughness: {
  9393. value: 1.0
  9394. },
  9395. metalness: {
  9396. value: 0.0
  9397. },
  9398. envMapIntensity: {
  9399. value: 1
  9400. } // temporary
  9401. }]),
  9402. vertexShader: ShaderChunk.meshphysical_vert,
  9403. fragmentShader: ShaderChunk.meshphysical_frag
  9404. },
  9405. toon: {
  9406. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  9407. emissive: {
  9408. value: new Color(0x000000)
  9409. }
  9410. }]),
  9411. vertexShader: ShaderChunk.meshtoon_vert,
  9412. fragmentShader: ShaderChunk.meshtoon_frag
  9413. },
  9414. matcap: {
  9415. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  9416. matcap: {
  9417. value: null
  9418. }
  9419. }]),
  9420. vertexShader: ShaderChunk.meshmatcap_vert,
  9421. fragmentShader: ShaderChunk.meshmatcap_frag
  9422. },
  9423. points: {
  9424. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  9425. vertexShader: ShaderChunk.points_vert,
  9426. fragmentShader: ShaderChunk.points_frag
  9427. },
  9428. dashed: {
  9429. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  9430. scale: {
  9431. value: 1
  9432. },
  9433. dashSize: {
  9434. value: 1
  9435. },
  9436. totalSize: {
  9437. value: 2
  9438. }
  9439. }]),
  9440. vertexShader: ShaderChunk.linedashed_vert,
  9441. fragmentShader: ShaderChunk.linedashed_frag
  9442. },
  9443. depth: {
  9444. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  9445. vertexShader: ShaderChunk.depth_vert,
  9446. fragmentShader: ShaderChunk.depth_frag
  9447. },
  9448. normal: {
  9449. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  9450. opacity: {
  9451. value: 1.0
  9452. }
  9453. }]),
  9454. vertexShader: ShaderChunk.normal_vert,
  9455. fragmentShader: ShaderChunk.normal_frag
  9456. },
  9457. sprite: {
  9458. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  9459. vertexShader: ShaderChunk.sprite_vert,
  9460. fragmentShader: ShaderChunk.sprite_frag
  9461. },
  9462. background: {
  9463. uniforms: {
  9464. uvTransform: {
  9465. value: new Matrix3()
  9466. },
  9467. t2D: {
  9468. value: null
  9469. }
  9470. },
  9471. vertexShader: ShaderChunk.background_vert,
  9472. fragmentShader: ShaderChunk.background_frag
  9473. },
  9474. /* -------------------------------------------------------------------------
  9475. // Cube map shader
  9476. ------------------------------------------------------------------------- */
  9477. cube: {
  9478. uniforms: mergeUniforms([UniformsLib.envmap, {
  9479. opacity: {
  9480. value: 1.0
  9481. }
  9482. }]),
  9483. vertexShader: ShaderChunk.cube_vert,
  9484. fragmentShader: ShaderChunk.cube_frag
  9485. },
  9486. equirect: {
  9487. uniforms: {
  9488. tEquirect: {
  9489. value: null
  9490. }
  9491. },
  9492. vertexShader: ShaderChunk.equirect_vert,
  9493. fragmentShader: ShaderChunk.equirect_frag
  9494. },
  9495. distanceRGBA: {
  9496. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9497. referencePosition: {
  9498. value: new Vector3()
  9499. },
  9500. nearDistance: {
  9501. value: 1
  9502. },
  9503. farDistance: {
  9504. value: 1000
  9505. }
  9506. }]),
  9507. vertexShader: ShaderChunk.distanceRGBA_vert,
  9508. fragmentShader: ShaderChunk.distanceRGBA_frag
  9509. },
  9510. shadow: {
  9511. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9512. color: {
  9513. value: new Color(0x00000)
  9514. },
  9515. opacity: {
  9516. value: 1.0
  9517. }
  9518. }]),
  9519. vertexShader: ShaderChunk.shadow_vert,
  9520. fragmentShader: ShaderChunk.shadow_frag
  9521. }
  9522. };
  9523. ShaderLib.physical = {
  9524. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9525. clearcoat: {
  9526. value: 0
  9527. },
  9528. clearcoatMap: {
  9529. value: null
  9530. },
  9531. clearcoatRoughness: {
  9532. value: 0
  9533. },
  9534. clearcoatRoughnessMap: {
  9535. value: null
  9536. },
  9537. clearcoatNormalScale: {
  9538. value: new Vector2(1, 1)
  9539. },
  9540. clearcoatNormalMap: {
  9541. value: null
  9542. },
  9543. sheen: {
  9544. value: new Color(0x000000)
  9545. },
  9546. transmission: {
  9547. value: 0
  9548. },
  9549. transmissionMap: {
  9550. value: null
  9551. }
  9552. }]),
  9553. vertexShader: ShaderChunk.meshphysical_vert,
  9554. fragmentShader: ShaderChunk.meshphysical_frag
  9555. };
  9556. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9557. var clearColor = new Color(0x000000);
  9558. var clearAlpha = 0;
  9559. var planeMesh;
  9560. var boxMesh;
  9561. var currentBackground = null;
  9562. var currentBackgroundVersion = 0;
  9563. var currentTonemapping = null;
  9564. function render(renderList, scene, camera, forceClear) {
  9565. var background = scene.isScene === true ? scene.background : null;
  9566. if (background && background.isTexture) {
  9567. background = cubemaps.get(background);
  9568. } // Ignore background in AR
  9569. // TODO: Reconsider this.
  9570. var xr = renderer.xr;
  9571. var session = xr.getSession && xr.getSession();
  9572. if (session && session.environmentBlendMode === 'additive') {
  9573. background = null;
  9574. }
  9575. if (background === null) {
  9576. setClear(clearColor, clearAlpha);
  9577. } else if (background && background.isColor) {
  9578. setClear(background, 1);
  9579. forceClear = true;
  9580. }
  9581. if (renderer.autoClear || forceClear) {
  9582. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9583. }
  9584. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9585. if (boxMesh === undefined) {
  9586. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9587. name: 'BackgroundCubeMaterial',
  9588. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9589. vertexShader: ShaderLib.cube.vertexShader,
  9590. fragmentShader: ShaderLib.cube.fragmentShader,
  9591. side: BackSide,
  9592. depthTest: false,
  9593. depthWrite: false,
  9594. fog: false
  9595. }));
  9596. boxMesh.geometry.deleteAttribute('normal');
  9597. boxMesh.geometry.deleteAttribute('uv');
  9598. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9599. this.matrixWorld.copyPosition(camera.matrixWorld);
  9600. }; // enable code injection for non-built-in material
  9601. Object.defineProperty(boxMesh.material, 'envMap', {
  9602. get: function get() {
  9603. return this.uniforms.envMap.value;
  9604. }
  9605. });
  9606. objects.update(boxMesh);
  9607. }
  9608. if (background.isWebGLCubeRenderTarget) {
  9609. // TODO Deprecate
  9610. background = background.texture;
  9611. }
  9612. boxMesh.material.uniforms.envMap.value = background;
  9613. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9614. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9615. boxMesh.material.needsUpdate = true;
  9616. currentBackground = background;
  9617. currentBackgroundVersion = background.version;
  9618. currentTonemapping = renderer.toneMapping;
  9619. } // push to the pre-sorted opaque render list
  9620. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9621. } else if (background && background.isTexture) {
  9622. if (planeMesh === undefined) {
  9623. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9624. name: 'BackgroundMaterial',
  9625. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9626. vertexShader: ShaderLib.background.vertexShader,
  9627. fragmentShader: ShaderLib.background.fragmentShader,
  9628. side: FrontSide,
  9629. depthTest: false,
  9630. depthWrite: false,
  9631. fog: false
  9632. }));
  9633. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9634. Object.defineProperty(planeMesh.material, 'map', {
  9635. get: function get() {
  9636. return this.uniforms.t2D.value;
  9637. }
  9638. });
  9639. objects.update(planeMesh);
  9640. }
  9641. planeMesh.material.uniforms.t2D.value = background;
  9642. if (background.matrixAutoUpdate === true) {
  9643. background.updateMatrix();
  9644. }
  9645. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9646. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9647. planeMesh.material.needsUpdate = true;
  9648. currentBackground = background;
  9649. currentBackgroundVersion = background.version;
  9650. currentTonemapping = renderer.toneMapping;
  9651. } // push to the pre-sorted opaque render list
  9652. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9653. }
  9654. }
  9655. function setClear(color, alpha) {
  9656. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9657. }
  9658. return {
  9659. getClearColor: function getClearColor() {
  9660. return clearColor;
  9661. },
  9662. setClearColor: function setClearColor(color, alpha) {
  9663. if (alpha === void 0) {
  9664. alpha = 1;
  9665. }
  9666. clearColor.set(color);
  9667. clearAlpha = alpha;
  9668. setClear(clearColor, clearAlpha);
  9669. },
  9670. getClearAlpha: function getClearAlpha() {
  9671. return clearAlpha;
  9672. },
  9673. setClearAlpha: function setClearAlpha(alpha) {
  9674. clearAlpha = alpha;
  9675. setClear(clearColor, clearAlpha);
  9676. },
  9677. render: render
  9678. };
  9679. }
  9680. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9681. var maxVertexAttributes = gl.getParameter(34921);
  9682. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9683. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9684. var bindingStates = {};
  9685. var defaultState = createBindingState(null);
  9686. var currentState = defaultState;
  9687. function setup(object, material, program, geometry, index) {
  9688. var updateBuffers = false;
  9689. if (vaoAvailable) {
  9690. var state = getBindingState(geometry, program, material);
  9691. if (currentState !== state) {
  9692. currentState = state;
  9693. bindVertexArrayObject(currentState.object);
  9694. }
  9695. updateBuffers = needsUpdate(geometry, index);
  9696. if (updateBuffers) saveCache(geometry, index);
  9697. } else {
  9698. var wireframe = material.wireframe === true;
  9699. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9700. currentState.geometry = geometry.id;
  9701. currentState.program = program.id;
  9702. currentState.wireframe = wireframe;
  9703. updateBuffers = true;
  9704. }
  9705. }
  9706. if (object.isInstancedMesh === true) {
  9707. updateBuffers = true;
  9708. }
  9709. if (index !== null) {
  9710. attributes.update(index, 34963);
  9711. }
  9712. if (updateBuffers) {
  9713. setupVertexAttributes(object, material, program, geometry);
  9714. if (index !== null) {
  9715. gl.bindBuffer(34963, attributes.get(index).buffer);
  9716. }
  9717. }
  9718. }
  9719. function createVertexArrayObject() {
  9720. if (capabilities.isWebGL2) return gl.createVertexArray();
  9721. return extension.createVertexArrayOES();
  9722. }
  9723. function bindVertexArrayObject(vao) {
  9724. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9725. return extension.bindVertexArrayOES(vao);
  9726. }
  9727. function deleteVertexArrayObject(vao) {
  9728. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9729. return extension.deleteVertexArrayOES(vao);
  9730. }
  9731. function getBindingState(geometry, program, material) {
  9732. var wireframe = material.wireframe === true;
  9733. var programMap = bindingStates[geometry.id];
  9734. if (programMap === undefined) {
  9735. programMap = {};
  9736. bindingStates[geometry.id] = programMap;
  9737. }
  9738. var stateMap = programMap[program.id];
  9739. if (stateMap === undefined) {
  9740. stateMap = {};
  9741. programMap[program.id] = stateMap;
  9742. }
  9743. var state = stateMap[wireframe];
  9744. if (state === undefined) {
  9745. state = createBindingState(createVertexArrayObject());
  9746. stateMap[wireframe] = state;
  9747. }
  9748. return state;
  9749. }
  9750. function createBindingState(vao) {
  9751. var newAttributes = [];
  9752. var enabledAttributes = [];
  9753. var attributeDivisors = [];
  9754. for (var i = 0; i < maxVertexAttributes; i++) {
  9755. newAttributes[i] = 0;
  9756. enabledAttributes[i] = 0;
  9757. attributeDivisors[i] = 0;
  9758. }
  9759. return {
  9760. // for backward compatibility on non-VAO support browser
  9761. geometry: null,
  9762. program: null,
  9763. wireframe: false,
  9764. newAttributes: newAttributes,
  9765. enabledAttributes: enabledAttributes,
  9766. attributeDivisors: attributeDivisors,
  9767. object: vao,
  9768. attributes: {},
  9769. index: null
  9770. };
  9771. }
  9772. function needsUpdate(geometry, index) {
  9773. var cachedAttributes = currentState.attributes;
  9774. var geometryAttributes = geometry.attributes;
  9775. var attributesNum = 0;
  9776. for (var key in geometryAttributes) {
  9777. var cachedAttribute = cachedAttributes[key];
  9778. var geometryAttribute = geometryAttributes[key];
  9779. if (cachedAttribute === undefined) return true;
  9780. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9781. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9782. attributesNum++;
  9783. }
  9784. if (currentState.attributesNum !== attributesNum) return true;
  9785. if (currentState.index !== index) return true;
  9786. return false;
  9787. }
  9788. function saveCache(geometry, index) {
  9789. var cache = {};
  9790. var attributes = geometry.attributes;
  9791. var attributesNum = 0;
  9792. for (var key in attributes) {
  9793. var attribute = attributes[key];
  9794. var data = {};
  9795. data.attribute = attribute;
  9796. if (attribute.data) {
  9797. data.data = attribute.data;
  9798. }
  9799. cache[key] = data;
  9800. attributesNum++;
  9801. }
  9802. currentState.attributes = cache;
  9803. currentState.attributesNum = attributesNum;
  9804. currentState.index = index;
  9805. }
  9806. function initAttributes() {
  9807. var newAttributes = currentState.newAttributes;
  9808. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9809. newAttributes[i] = 0;
  9810. }
  9811. }
  9812. function enableAttribute(attribute) {
  9813. enableAttributeAndDivisor(attribute, 0);
  9814. }
  9815. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9816. var newAttributes = currentState.newAttributes;
  9817. var enabledAttributes = currentState.enabledAttributes;
  9818. var attributeDivisors = currentState.attributeDivisors;
  9819. newAttributes[attribute] = 1;
  9820. if (enabledAttributes[attribute] === 0) {
  9821. gl.enableVertexAttribArray(attribute);
  9822. enabledAttributes[attribute] = 1;
  9823. }
  9824. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9825. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9826. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9827. attributeDivisors[attribute] = meshPerAttribute;
  9828. }
  9829. }
  9830. function disableUnusedAttributes() {
  9831. var newAttributes = currentState.newAttributes;
  9832. var enabledAttributes = currentState.enabledAttributes;
  9833. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9834. if (enabledAttributes[i] !== newAttributes[i]) {
  9835. gl.disableVertexAttribArray(i);
  9836. enabledAttributes[i] = 0;
  9837. }
  9838. }
  9839. }
  9840. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9841. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9842. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9843. } else {
  9844. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9845. }
  9846. }
  9847. function setupVertexAttributes(object, material, program, geometry) {
  9848. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9849. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9850. }
  9851. initAttributes();
  9852. var geometryAttributes = geometry.attributes;
  9853. var programAttributes = program.getAttributes();
  9854. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9855. for (var name in programAttributes) {
  9856. var programAttribute = programAttributes[name];
  9857. if (programAttribute >= 0) {
  9858. var geometryAttribute = geometryAttributes[name];
  9859. if (geometryAttribute !== undefined) {
  9860. var normalized = geometryAttribute.normalized;
  9861. var size = geometryAttribute.itemSize;
  9862. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9863. if (attribute === undefined) continue;
  9864. var buffer = attribute.buffer;
  9865. var type = attribute.type;
  9866. var bytesPerElement = attribute.bytesPerElement;
  9867. if (geometryAttribute.isInterleavedBufferAttribute) {
  9868. var data = geometryAttribute.data;
  9869. var stride = data.stride;
  9870. var offset = geometryAttribute.offset;
  9871. if (data && data.isInstancedInterleavedBuffer) {
  9872. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9873. if (geometry._maxInstanceCount === undefined) {
  9874. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9875. }
  9876. } else {
  9877. enableAttribute(programAttribute);
  9878. }
  9879. gl.bindBuffer(34962, buffer);
  9880. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9881. } else {
  9882. if (geometryAttribute.isInstancedBufferAttribute) {
  9883. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9884. if (geometry._maxInstanceCount === undefined) {
  9885. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9886. }
  9887. } else {
  9888. enableAttribute(programAttribute);
  9889. }
  9890. gl.bindBuffer(34962, buffer);
  9891. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9892. }
  9893. } else if (name === 'instanceMatrix') {
  9894. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9895. if (_attribute === undefined) continue;
  9896. var _buffer = _attribute.buffer;
  9897. var _type = _attribute.type;
  9898. enableAttributeAndDivisor(programAttribute + 0, 1);
  9899. enableAttributeAndDivisor(programAttribute + 1, 1);
  9900. enableAttributeAndDivisor(programAttribute + 2, 1);
  9901. enableAttributeAndDivisor(programAttribute + 3, 1);
  9902. gl.bindBuffer(34962, _buffer);
  9903. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9904. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9905. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9906. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9907. } else if (name === 'instanceColor') {
  9908. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9909. if (_attribute2 === undefined) continue;
  9910. var _buffer2 = _attribute2.buffer;
  9911. var _type2 = _attribute2.type;
  9912. enableAttributeAndDivisor(programAttribute, 1);
  9913. gl.bindBuffer(34962, _buffer2);
  9914. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9915. } else if (materialDefaultAttributeValues !== undefined) {
  9916. var value = materialDefaultAttributeValues[name];
  9917. if (value !== undefined) {
  9918. switch (value.length) {
  9919. case 2:
  9920. gl.vertexAttrib2fv(programAttribute, value);
  9921. break;
  9922. case 3:
  9923. gl.vertexAttrib3fv(programAttribute, value);
  9924. break;
  9925. case 4:
  9926. gl.vertexAttrib4fv(programAttribute, value);
  9927. break;
  9928. default:
  9929. gl.vertexAttrib1fv(programAttribute, value);
  9930. }
  9931. }
  9932. }
  9933. }
  9934. }
  9935. disableUnusedAttributes();
  9936. }
  9937. function dispose() {
  9938. reset();
  9939. for (var geometryId in bindingStates) {
  9940. var programMap = bindingStates[geometryId];
  9941. for (var programId in programMap) {
  9942. var stateMap = programMap[programId];
  9943. for (var wireframe in stateMap) {
  9944. deleteVertexArrayObject(stateMap[wireframe].object);
  9945. delete stateMap[wireframe];
  9946. }
  9947. delete programMap[programId];
  9948. }
  9949. delete bindingStates[geometryId];
  9950. }
  9951. }
  9952. function releaseStatesOfGeometry(geometry) {
  9953. if (bindingStates[geometry.id] === undefined) return;
  9954. var programMap = bindingStates[geometry.id];
  9955. for (var programId in programMap) {
  9956. var stateMap = programMap[programId];
  9957. for (var wireframe in stateMap) {
  9958. deleteVertexArrayObject(stateMap[wireframe].object);
  9959. delete stateMap[wireframe];
  9960. }
  9961. delete programMap[programId];
  9962. }
  9963. delete bindingStates[geometry.id];
  9964. }
  9965. function releaseStatesOfProgram(program) {
  9966. for (var geometryId in bindingStates) {
  9967. var programMap = bindingStates[geometryId];
  9968. if (programMap[program.id] === undefined) continue;
  9969. var stateMap = programMap[program.id];
  9970. for (var wireframe in stateMap) {
  9971. deleteVertexArrayObject(stateMap[wireframe].object);
  9972. delete stateMap[wireframe];
  9973. }
  9974. delete programMap[program.id];
  9975. }
  9976. }
  9977. function reset() {
  9978. resetDefaultState();
  9979. if (currentState === defaultState) return;
  9980. currentState = defaultState;
  9981. bindVertexArrayObject(currentState.object);
  9982. } // for backward-compatilibity
  9983. function resetDefaultState() {
  9984. defaultState.geometry = null;
  9985. defaultState.program = null;
  9986. defaultState.wireframe = false;
  9987. }
  9988. return {
  9989. setup: setup,
  9990. reset: reset,
  9991. resetDefaultState: resetDefaultState,
  9992. dispose: dispose,
  9993. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9994. releaseStatesOfProgram: releaseStatesOfProgram,
  9995. initAttributes: initAttributes,
  9996. enableAttribute: enableAttribute,
  9997. disableUnusedAttributes: disableUnusedAttributes
  9998. };
  9999. }
  10000. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  10001. var isWebGL2 = capabilities.isWebGL2;
  10002. var mode;
  10003. function setMode(value) {
  10004. mode = value;
  10005. }
  10006. function render(start, count) {
  10007. gl.drawArrays(mode, start, count);
  10008. info.update(count, mode, 1);
  10009. }
  10010. function renderInstances(start, count, primcount) {
  10011. if (primcount === 0) return;
  10012. var extension, methodName;
  10013. if (isWebGL2) {
  10014. extension = gl;
  10015. methodName = 'drawArraysInstanced';
  10016. } else {
  10017. extension = extensions.get('ANGLE_instanced_arrays');
  10018. methodName = 'drawArraysInstancedANGLE';
  10019. if (extension === null) {
  10020. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10021. return;
  10022. }
  10023. }
  10024. extension[methodName](mode, start, count, primcount);
  10025. info.update(count, mode, primcount);
  10026. } //
  10027. this.setMode = setMode;
  10028. this.render = render;
  10029. this.renderInstances = renderInstances;
  10030. }
  10031. function WebGLCapabilities(gl, extensions, parameters) {
  10032. var maxAnisotropy;
  10033. function getMaxAnisotropy() {
  10034. if (maxAnisotropy !== undefined) return maxAnisotropy;
  10035. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  10036. var extension = extensions.get('EXT_texture_filter_anisotropic');
  10037. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  10038. } else {
  10039. maxAnisotropy = 0;
  10040. }
  10041. return maxAnisotropy;
  10042. }
  10043. function getMaxPrecision(precision) {
  10044. if (precision === 'highp') {
  10045. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  10046. return 'highp';
  10047. }
  10048. precision = 'mediump';
  10049. }
  10050. if (precision === 'mediump') {
  10051. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  10052. return 'mediump';
  10053. }
  10054. }
  10055. return 'lowp';
  10056. }
  10057. /* eslint-disable no-undef */
  10058. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  10059. /* eslint-enable no-undef */
  10060. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10061. var maxPrecision = getMaxPrecision(precision);
  10062. if (maxPrecision !== precision) {
  10063. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  10064. precision = maxPrecision;
  10065. }
  10066. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10067. var maxTextures = gl.getParameter(34930);
  10068. var maxVertexTextures = gl.getParameter(35660);
  10069. var maxTextureSize = gl.getParameter(3379);
  10070. var maxCubemapSize = gl.getParameter(34076);
  10071. var maxAttributes = gl.getParameter(34921);
  10072. var maxVertexUniforms = gl.getParameter(36347);
  10073. var maxVaryings = gl.getParameter(36348);
  10074. var maxFragmentUniforms = gl.getParameter(36349);
  10075. var vertexTextures = maxVertexTextures > 0;
  10076. var floatFragmentTextures = isWebGL2 || extensions.has('OES_texture_float');
  10077. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10078. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  10079. return {
  10080. isWebGL2: isWebGL2,
  10081. getMaxAnisotropy: getMaxAnisotropy,
  10082. getMaxPrecision: getMaxPrecision,
  10083. precision: precision,
  10084. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10085. maxTextures: maxTextures,
  10086. maxVertexTextures: maxVertexTextures,
  10087. maxTextureSize: maxTextureSize,
  10088. maxCubemapSize: maxCubemapSize,
  10089. maxAttributes: maxAttributes,
  10090. maxVertexUniforms: maxVertexUniforms,
  10091. maxVaryings: maxVaryings,
  10092. maxFragmentUniforms: maxFragmentUniforms,
  10093. vertexTextures: vertexTextures,
  10094. floatFragmentTextures: floatFragmentTextures,
  10095. floatVertexTextures: floatVertexTextures,
  10096. maxSamples: maxSamples
  10097. };
  10098. }
  10099. function WebGLClipping(properties) {
  10100. var scope = this;
  10101. var globalState = null,
  10102. numGlobalPlanes = 0,
  10103. localClippingEnabled = false,
  10104. renderingShadows = false;
  10105. var plane = new Plane(),
  10106. viewNormalMatrix = new Matrix3(),
  10107. uniform = {
  10108. value: null,
  10109. needsUpdate: false
  10110. };
  10111. this.uniform = uniform;
  10112. this.numPlanes = 0;
  10113. this.numIntersection = 0;
  10114. this.init = function (planes, enableLocalClipping, camera) {
  10115. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  10116. // run another frame in order to reset the state:
  10117. numGlobalPlanes !== 0 || localClippingEnabled;
  10118. localClippingEnabled = enableLocalClipping;
  10119. globalState = projectPlanes(planes, camera, 0);
  10120. numGlobalPlanes = planes.length;
  10121. return enabled;
  10122. };
  10123. this.beginShadows = function () {
  10124. renderingShadows = true;
  10125. projectPlanes(null);
  10126. };
  10127. this.endShadows = function () {
  10128. renderingShadows = false;
  10129. resetGlobalState();
  10130. };
  10131. this.setState = function (material, camera, useCache) {
  10132. var planes = material.clippingPlanes,
  10133. clipIntersection = material.clipIntersection,
  10134. clipShadows = material.clipShadows;
  10135. var materialProperties = properties.get(material);
  10136. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  10137. // there's no local clipping
  10138. if (renderingShadows) {
  10139. // there's no global clipping
  10140. projectPlanes(null);
  10141. } else {
  10142. resetGlobalState();
  10143. }
  10144. } else {
  10145. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10146. lGlobal = nGlobal * 4;
  10147. var dstArray = materialProperties.clippingState || null;
  10148. uniform.value = dstArray; // ensure unique state
  10149. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  10150. for (var i = 0; i !== lGlobal; ++i) {
  10151. dstArray[i] = globalState[i];
  10152. }
  10153. materialProperties.clippingState = dstArray;
  10154. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10155. this.numPlanes += nGlobal;
  10156. }
  10157. };
  10158. function resetGlobalState() {
  10159. if (uniform.value !== globalState) {
  10160. uniform.value = globalState;
  10161. uniform.needsUpdate = numGlobalPlanes > 0;
  10162. }
  10163. scope.numPlanes = numGlobalPlanes;
  10164. scope.numIntersection = 0;
  10165. }
  10166. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  10167. var nPlanes = planes !== null ? planes.length : 0;
  10168. var dstArray = null;
  10169. if (nPlanes !== 0) {
  10170. dstArray = uniform.value;
  10171. if (skipTransform !== true || dstArray === null) {
  10172. var flatSize = dstOffset + nPlanes * 4,
  10173. viewMatrix = camera.matrixWorldInverse;
  10174. viewNormalMatrix.getNormalMatrix(viewMatrix);
  10175. if (dstArray === null || dstArray.length < flatSize) {
  10176. dstArray = new Float32Array(flatSize);
  10177. }
  10178. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  10179. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  10180. plane.normal.toArray(dstArray, i4);
  10181. dstArray[i4 + 3] = plane.constant;
  10182. }
  10183. }
  10184. uniform.value = dstArray;
  10185. uniform.needsUpdate = true;
  10186. }
  10187. scope.numPlanes = nPlanes;
  10188. scope.numIntersection = 0;
  10189. return dstArray;
  10190. }
  10191. }
  10192. function WebGLCubeMaps(renderer) {
  10193. var cubemaps = new WeakMap();
  10194. function mapTextureMapping(texture, mapping) {
  10195. if (mapping === EquirectangularReflectionMapping) {
  10196. texture.mapping = CubeReflectionMapping;
  10197. } else if (mapping === EquirectangularRefractionMapping) {
  10198. texture.mapping = CubeRefractionMapping;
  10199. }
  10200. return texture;
  10201. }
  10202. function get(texture) {
  10203. if (texture && texture.isTexture) {
  10204. var mapping = texture.mapping;
  10205. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  10206. if (cubemaps.has(texture)) {
  10207. var cubemap = cubemaps.get(texture).texture;
  10208. return mapTextureMapping(cubemap, texture.mapping);
  10209. } else {
  10210. var image = texture.image;
  10211. if (image && image.height > 0) {
  10212. var currentRenderTarget = renderer.getRenderTarget();
  10213. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  10214. renderTarget.fromEquirectangularTexture(renderer, texture);
  10215. cubemaps.set(texture, renderTarget);
  10216. renderer.setRenderTarget(currentRenderTarget);
  10217. texture.addEventListener('dispose', onTextureDispose);
  10218. return mapTextureMapping(renderTarget.texture, texture.mapping);
  10219. } else {
  10220. // image not yet ready. try the conversion next frame
  10221. return null;
  10222. }
  10223. }
  10224. }
  10225. }
  10226. return texture;
  10227. }
  10228. function onTextureDispose(event) {
  10229. var texture = event.target;
  10230. texture.removeEventListener('dispose', onTextureDispose);
  10231. var cubemap = cubemaps.get(texture);
  10232. if (cubemap !== undefined) {
  10233. cubemaps.delete(texture);
  10234. cubemap.dispose();
  10235. }
  10236. }
  10237. function dispose() {
  10238. cubemaps = new WeakMap();
  10239. }
  10240. return {
  10241. get: get,
  10242. dispose: dispose
  10243. };
  10244. }
  10245. function WebGLExtensions(gl) {
  10246. var extensions = {};
  10247. function getExtension(name) {
  10248. if (extensions[name] !== undefined) {
  10249. return extensions[name];
  10250. }
  10251. var extension;
  10252. switch (name) {
  10253. case 'WEBGL_depth_texture':
  10254. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  10255. break;
  10256. case 'EXT_texture_filter_anisotropic':
  10257. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  10258. break;
  10259. case 'WEBGL_compressed_texture_s3tc':
  10260. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  10261. break;
  10262. case 'WEBGL_compressed_texture_pvrtc':
  10263. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  10264. break;
  10265. default:
  10266. extension = gl.getExtension(name);
  10267. }
  10268. extensions[name] = extension;
  10269. return extension;
  10270. }
  10271. return {
  10272. has: function has(name) {
  10273. return getExtension(name) !== null;
  10274. },
  10275. init: function init(capabilities) {
  10276. if (capabilities.isWebGL2) {
  10277. getExtension('EXT_color_buffer_float');
  10278. } else {
  10279. getExtension('WEBGL_depth_texture');
  10280. getExtension('OES_texture_float');
  10281. getExtension('OES_texture_half_float');
  10282. getExtension('OES_texture_half_float_linear');
  10283. getExtension('OES_standard_derivatives');
  10284. getExtension('OES_element_index_uint');
  10285. getExtension('OES_vertex_array_object');
  10286. getExtension('ANGLE_instanced_arrays');
  10287. }
  10288. getExtension('OES_texture_float_linear');
  10289. getExtension('EXT_color_buffer_half_float');
  10290. },
  10291. get: function get(name) {
  10292. var extension = getExtension(name);
  10293. if (extension === null) {
  10294. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  10295. }
  10296. return extension;
  10297. }
  10298. };
  10299. }
  10300. function WebGLGeometries(gl, attributes, info, bindingStates) {
  10301. var geometries = {};
  10302. var wireframeAttributes = new WeakMap();
  10303. function onGeometryDispose(event) {
  10304. var geometry = event.target;
  10305. if (geometry.index !== null) {
  10306. attributes.remove(geometry.index);
  10307. }
  10308. for (var name in geometry.attributes) {
  10309. attributes.remove(geometry.attributes[name]);
  10310. }
  10311. geometry.removeEventListener('dispose', onGeometryDispose);
  10312. delete geometries[geometry.id];
  10313. var attribute = wireframeAttributes.get(geometry);
  10314. if (attribute) {
  10315. attributes.remove(attribute);
  10316. wireframeAttributes.delete(geometry);
  10317. }
  10318. bindingStates.releaseStatesOfGeometry(geometry);
  10319. if (geometry.isInstancedBufferGeometry === true) {
  10320. delete geometry._maxInstanceCount;
  10321. } //
  10322. info.memory.geometries--;
  10323. }
  10324. function get(object, geometry) {
  10325. if (geometries[geometry.id] === true) return geometry;
  10326. geometry.addEventListener('dispose', onGeometryDispose);
  10327. geometries[geometry.id] = true;
  10328. info.memory.geometries++;
  10329. return geometry;
  10330. }
  10331. function update(geometry) {
  10332. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  10333. for (var name in geometryAttributes) {
  10334. attributes.update(geometryAttributes[name], 34962);
  10335. } // morph targets
  10336. var morphAttributes = geometry.morphAttributes;
  10337. for (var _name in morphAttributes) {
  10338. var array = morphAttributes[_name];
  10339. for (var i = 0, l = array.length; i < l; i++) {
  10340. attributes.update(array[i], 34962);
  10341. }
  10342. }
  10343. }
  10344. function updateWireframeAttribute(geometry) {
  10345. var indices = [];
  10346. var geometryIndex = geometry.index;
  10347. var geometryPosition = geometry.attributes.position;
  10348. var version = 0;
  10349. if (geometryIndex !== null) {
  10350. var array = geometryIndex.array;
  10351. version = geometryIndex.version;
  10352. for (var i = 0, l = array.length; i < l; i += 3) {
  10353. var a = array[i + 0];
  10354. var b = array[i + 1];
  10355. var c = array[i + 2];
  10356. indices.push(a, b, b, c, c, a);
  10357. }
  10358. } else {
  10359. var _array = geometryPosition.array;
  10360. version = geometryPosition.version;
  10361. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  10362. var _a = _i + 0;
  10363. var _b = _i + 1;
  10364. var _c = _i + 2;
  10365. indices.push(_a, _b, _b, _c, _c, _a);
  10366. }
  10367. }
  10368. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  10369. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  10370. //
  10371. var previousAttribute = wireframeAttributes.get(geometry);
  10372. if (previousAttribute) attributes.remove(previousAttribute); //
  10373. wireframeAttributes.set(geometry, attribute);
  10374. }
  10375. function getWireframeAttribute(geometry) {
  10376. var currentAttribute = wireframeAttributes.get(geometry);
  10377. if (currentAttribute) {
  10378. var geometryIndex = geometry.index;
  10379. if (geometryIndex !== null) {
  10380. // if the attribute is obsolete, create a new one
  10381. if (currentAttribute.version < geometryIndex.version) {
  10382. updateWireframeAttribute(geometry);
  10383. }
  10384. }
  10385. } else {
  10386. updateWireframeAttribute(geometry);
  10387. }
  10388. return wireframeAttributes.get(geometry);
  10389. }
  10390. return {
  10391. get: get,
  10392. update: update,
  10393. getWireframeAttribute: getWireframeAttribute
  10394. };
  10395. }
  10396. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  10397. var isWebGL2 = capabilities.isWebGL2;
  10398. var mode;
  10399. function setMode(value) {
  10400. mode = value;
  10401. }
  10402. var type, bytesPerElement;
  10403. function setIndex(value) {
  10404. type = value.type;
  10405. bytesPerElement = value.bytesPerElement;
  10406. }
  10407. function render(start, count) {
  10408. gl.drawElements(mode, count, type, start * bytesPerElement);
  10409. info.update(count, mode, 1);
  10410. }
  10411. function renderInstances(start, count, primcount) {
  10412. if (primcount === 0) return;
  10413. var extension, methodName;
  10414. if (isWebGL2) {
  10415. extension = gl;
  10416. methodName = 'drawElementsInstanced';
  10417. } else {
  10418. extension = extensions.get('ANGLE_instanced_arrays');
  10419. methodName = 'drawElementsInstancedANGLE';
  10420. if (extension === null) {
  10421. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10422. return;
  10423. }
  10424. }
  10425. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  10426. info.update(count, mode, primcount);
  10427. } //
  10428. this.setMode = setMode;
  10429. this.setIndex = setIndex;
  10430. this.render = render;
  10431. this.renderInstances = renderInstances;
  10432. }
  10433. function WebGLInfo(gl) {
  10434. var memory = {
  10435. geometries: 0,
  10436. textures: 0
  10437. };
  10438. var render = {
  10439. frame: 0,
  10440. calls: 0,
  10441. triangles: 0,
  10442. points: 0,
  10443. lines: 0
  10444. };
  10445. function update(count, mode, instanceCount) {
  10446. render.calls++;
  10447. switch (mode) {
  10448. case 4:
  10449. render.triangles += instanceCount * (count / 3);
  10450. break;
  10451. case 1:
  10452. render.lines += instanceCount * (count / 2);
  10453. break;
  10454. case 3:
  10455. render.lines += instanceCount * (count - 1);
  10456. break;
  10457. case 2:
  10458. render.lines += instanceCount * count;
  10459. break;
  10460. case 0:
  10461. render.points += instanceCount * count;
  10462. break;
  10463. default:
  10464. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  10465. break;
  10466. }
  10467. }
  10468. function reset() {
  10469. render.frame++;
  10470. render.calls = 0;
  10471. render.triangles = 0;
  10472. render.points = 0;
  10473. render.lines = 0;
  10474. }
  10475. return {
  10476. memory: memory,
  10477. render: render,
  10478. programs: null,
  10479. autoReset: true,
  10480. reset: reset,
  10481. update: update
  10482. };
  10483. }
  10484. function numericalSort(a, b) {
  10485. return a[0] - b[0];
  10486. }
  10487. function absNumericalSort(a, b) {
  10488. return Math.abs(b[1]) - Math.abs(a[1]);
  10489. }
  10490. function WebGLMorphtargets(gl) {
  10491. var influencesList = {};
  10492. var morphInfluences = new Float32Array(8);
  10493. var workInfluences = [];
  10494. for (var i = 0; i < 8; i++) {
  10495. workInfluences[i] = [i, 0];
  10496. }
  10497. function update(object, geometry, material, program) {
  10498. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10499. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10500. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10501. var influences = influencesList[geometry.id];
  10502. if (influences === undefined) {
  10503. // initialise list
  10504. influences = [];
  10505. for (var _i = 0; _i < length; _i++) {
  10506. influences[_i] = [_i, 0];
  10507. }
  10508. influencesList[geometry.id] = influences;
  10509. } // Collect influences
  10510. for (var _i2 = 0; _i2 < length; _i2++) {
  10511. var influence = influences[_i2];
  10512. influence[0] = _i2;
  10513. influence[1] = objectInfluences[_i2];
  10514. }
  10515. influences.sort(absNumericalSort);
  10516. for (var _i3 = 0; _i3 < 8; _i3++) {
  10517. if (_i3 < length && influences[_i3][1]) {
  10518. workInfluences[_i3][0] = influences[_i3][0];
  10519. workInfluences[_i3][1] = influences[_i3][1];
  10520. } else {
  10521. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10522. workInfluences[_i3][1] = 0;
  10523. }
  10524. }
  10525. workInfluences.sort(numericalSort);
  10526. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10527. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10528. var morphInfluencesSum = 0;
  10529. for (var _i4 = 0; _i4 < 8; _i4++) {
  10530. var _influence = workInfluences[_i4];
  10531. var index = _influence[0];
  10532. var value = _influence[1];
  10533. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10534. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10535. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10536. }
  10537. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10538. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10539. }
  10540. morphInfluences[_i4] = value;
  10541. morphInfluencesSum += value;
  10542. } else {
  10543. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10544. geometry.deleteAttribute('morphTarget' + _i4);
  10545. }
  10546. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10547. geometry.deleteAttribute('morphNormal' + _i4);
  10548. }
  10549. morphInfluences[_i4] = 0;
  10550. }
  10551. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10552. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10553. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10554. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10555. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10556. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10557. }
  10558. return {
  10559. update: update
  10560. };
  10561. }
  10562. function WebGLObjects(gl, geometries, attributes, info) {
  10563. var updateMap = new WeakMap();
  10564. function update(object) {
  10565. var frame = info.render.frame;
  10566. var geometry = object.geometry;
  10567. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10568. if (updateMap.get(buffergeometry) !== frame) {
  10569. geometries.update(buffergeometry);
  10570. updateMap.set(buffergeometry, frame);
  10571. }
  10572. if (object.isInstancedMesh) {
  10573. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10574. object.addEventListener('dispose', onInstancedMeshDispose);
  10575. }
  10576. attributes.update(object.instanceMatrix, 34962);
  10577. if (object.instanceColor !== null) {
  10578. attributes.update(object.instanceColor, 34962);
  10579. }
  10580. }
  10581. return buffergeometry;
  10582. }
  10583. function dispose() {
  10584. updateMap = new WeakMap();
  10585. }
  10586. function onInstancedMeshDispose(event) {
  10587. var instancedMesh = event.target;
  10588. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10589. attributes.remove(instancedMesh.instanceMatrix);
  10590. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10591. }
  10592. return {
  10593. update: update,
  10594. dispose: dispose
  10595. };
  10596. }
  10597. function DataTexture2DArray(data, width, height, depth) {
  10598. if (data === void 0) {
  10599. data = null;
  10600. }
  10601. if (width === void 0) {
  10602. width = 1;
  10603. }
  10604. if (height === void 0) {
  10605. height = 1;
  10606. }
  10607. if (depth === void 0) {
  10608. depth = 1;
  10609. }
  10610. Texture.call(this, null);
  10611. this.image = {
  10612. data: data,
  10613. width: width,
  10614. height: height,
  10615. depth: depth
  10616. };
  10617. this.magFilter = NearestFilter;
  10618. this.minFilter = NearestFilter;
  10619. this.wrapR = ClampToEdgeWrapping;
  10620. this.generateMipmaps = false;
  10621. this.flipY = false;
  10622. this.needsUpdate = true;
  10623. }
  10624. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10625. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10626. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10627. function DataTexture3D(data, width, height, depth) {
  10628. if (data === void 0) {
  10629. data = null;
  10630. }
  10631. if (width === void 0) {
  10632. width = 1;
  10633. }
  10634. if (height === void 0) {
  10635. height = 1;
  10636. }
  10637. if (depth === void 0) {
  10638. depth = 1;
  10639. }
  10640. // We're going to add .setXXX() methods for setting properties later.
  10641. // Users can still set in DataTexture3D directly.
  10642. //
  10643. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10644. // texture.anisotropy = 16;
  10645. //
  10646. // See #14839
  10647. Texture.call(this, null);
  10648. this.image = {
  10649. data: data,
  10650. width: width,
  10651. height: height,
  10652. depth: depth
  10653. };
  10654. this.magFilter = NearestFilter;
  10655. this.minFilter = NearestFilter;
  10656. this.wrapR = ClampToEdgeWrapping;
  10657. this.generateMipmaps = false;
  10658. this.flipY = false;
  10659. this.needsUpdate = true;
  10660. }
  10661. DataTexture3D.prototype = Object.create(Texture.prototype);
  10662. DataTexture3D.prototype.constructor = DataTexture3D;
  10663. DataTexture3D.prototype.isDataTexture3D = true;
  10664. /**
  10665. * Uniforms of a program.
  10666. * Those form a tree structure with a special top-level container for the root,
  10667. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10668. *
  10669. *
  10670. * Properties of inner nodes including the top-level container:
  10671. *
  10672. * .seq - array of nested uniforms
  10673. * .map - nested uniforms by name
  10674. *
  10675. *
  10676. * Methods of all nodes except the top-level container:
  10677. *
  10678. * .setValue( gl, value, [textures] )
  10679. *
  10680. * uploads a uniform value(s)
  10681. * the 'textures' parameter is needed for sampler uniforms
  10682. *
  10683. *
  10684. * Static methods of the top-level container (textures factorizations):
  10685. *
  10686. * .upload( gl, seq, values, textures )
  10687. *
  10688. * sets uniforms in 'seq' to 'values[id].value'
  10689. *
  10690. * .seqWithValue( seq, values ) : filteredSeq
  10691. *
  10692. * filters 'seq' entries with corresponding entry in values
  10693. *
  10694. *
  10695. * Methods of the top-level container (textures factorizations):
  10696. *
  10697. * .setValue( gl, name, value, textures )
  10698. *
  10699. * sets uniform with name 'name' to 'value'
  10700. *
  10701. * .setOptional( gl, obj, prop )
  10702. *
  10703. * like .set for an optional property of the object
  10704. *
  10705. */
  10706. var emptyTexture = new Texture();
  10707. var emptyTexture2dArray = new DataTexture2DArray();
  10708. var emptyTexture3d = new DataTexture3D();
  10709. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10710. // Array Caches (provide typed arrays for temporary by size)
  10711. var arrayCacheF32 = [];
  10712. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10713. var mat4array = new Float32Array(16);
  10714. var mat3array = new Float32Array(9);
  10715. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10716. function flatten(array, nBlocks, blockSize) {
  10717. var firstElem = array[0];
  10718. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10719. // see http://jacksondunstan.com/articles/983
  10720. var n = nBlocks * blockSize;
  10721. var r = arrayCacheF32[n];
  10722. if (r === undefined) {
  10723. r = new Float32Array(n);
  10724. arrayCacheF32[n] = r;
  10725. }
  10726. if (nBlocks !== 0) {
  10727. firstElem.toArray(r, 0);
  10728. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10729. offset += blockSize;
  10730. array[i].toArray(r, offset);
  10731. }
  10732. }
  10733. return r;
  10734. }
  10735. function arraysEqual(a, b) {
  10736. if (a.length !== b.length) return false;
  10737. for (var i = 0, l = a.length; i < l; i++) {
  10738. if (a[i] !== b[i]) return false;
  10739. }
  10740. return true;
  10741. }
  10742. function copyArray(a, b) {
  10743. for (var i = 0, l = b.length; i < l; i++) {
  10744. a[i] = b[i];
  10745. }
  10746. } // Texture unit allocation
  10747. function allocTexUnits(textures, n) {
  10748. var r = arrayCacheI32[n];
  10749. if (r === undefined) {
  10750. r = new Int32Array(n);
  10751. arrayCacheI32[n] = r;
  10752. }
  10753. for (var i = 0; i !== n; ++i) {
  10754. r[i] = textures.allocateTextureUnit();
  10755. }
  10756. return r;
  10757. } // --- Setters ---
  10758. // Note: Defining these methods externally, because they come in a bunch
  10759. // and this way their names minify.
  10760. // Single scalar
  10761. function setValueV1f(gl, v) {
  10762. var cache = this.cache;
  10763. if (cache[0] === v) return;
  10764. gl.uniform1f(this.addr, v);
  10765. cache[0] = v;
  10766. } // Single float vector (from flat array or THREE.VectorN)
  10767. function setValueV2f(gl, v) {
  10768. var cache = this.cache;
  10769. if (v.x !== undefined) {
  10770. if (cache[0] !== v.x || cache[1] !== v.y) {
  10771. gl.uniform2f(this.addr, v.x, v.y);
  10772. cache[0] = v.x;
  10773. cache[1] = v.y;
  10774. }
  10775. } else {
  10776. if (arraysEqual(cache, v)) return;
  10777. gl.uniform2fv(this.addr, v);
  10778. copyArray(cache, v);
  10779. }
  10780. }
  10781. function setValueV3f(gl, v) {
  10782. var cache = this.cache;
  10783. if (v.x !== undefined) {
  10784. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10785. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10786. cache[0] = v.x;
  10787. cache[1] = v.y;
  10788. cache[2] = v.z;
  10789. }
  10790. } else if (v.r !== undefined) {
  10791. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10792. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10793. cache[0] = v.r;
  10794. cache[1] = v.g;
  10795. cache[2] = v.b;
  10796. }
  10797. } else {
  10798. if (arraysEqual(cache, v)) return;
  10799. gl.uniform3fv(this.addr, v);
  10800. copyArray(cache, v);
  10801. }
  10802. }
  10803. function setValueV4f(gl, v) {
  10804. var cache = this.cache;
  10805. if (v.x !== undefined) {
  10806. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10807. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10808. cache[0] = v.x;
  10809. cache[1] = v.y;
  10810. cache[2] = v.z;
  10811. cache[3] = v.w;
  10812. }
  10813. } else {
  10814. if (arraysEqual(cache, v)) return;
  10815. gl.uniform4fv(this.addr, v);
  10816. copyArray(cache, v);
  10817. }
  10818. } // Single matrix (from flat array or MatrixN)
  10819. function setValueM2(gl, v) {
  10820. var cache = this.cache;
  10821. var elements = v.elements;
  10822. if (elements === undefined) {
  10823. if (arraysEqual(cache, v)) return;
  10824. gl.uniformMatrix2fv(this.addr, false, v);
  10825. copyArray(cache, v);
  10826. } else {
  10827. if (arraysEqual(cache, elements)) return;
  10828. mat2array.set(elements);
  10829. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10830. copyArray(cache, elements);
  10831. }
  10832. }
  10833. function setValueM3(gl, v) {
  10834. var cache = this.cache;
  10835. var elements = v.elements;
  10836. if (elements === undefined) {
  10837. if (arraysEqual(cache, v)) return;
  10838. gl.uniformMatrix3fv(this.addr, false, v);
  10839. copyArray(cache, v);
  10840. } else {
  10841. if (arraysEqual(cache, elements)) return;
  10842. mat3array.set(elements);
  10843. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10844. copyArray(cache, elements);
  10845. }
  10846. }
  10847. function setValueM4(gl, v) {
  10848. var cache = this.cache;
  10849. var elements = v.elements;
  10850. if (elements === undefined) {
  10851. if (arraysEqual(cache, v)) return;
  10852. gl.uniformMatrix4fv(this.addr, false, v);
  10853. copyArray(cache, v);
  10854. } else {
  10855. if (arraysEqual(cache, elements)) return;
  10856. mat4array.set(elements);
  10857. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10858. copyArray(cache, elements);
  10859. }
  10860. } // Single texture (2D / Cube)
  10861. function setValueT1(gl, v, textures) {
  10862. var cache = this.cache;
  10863. var unit = textures.allocateTextureUnit();
  10864. if (cache[0] !== unit) {
  10865. gl.uniform1i(this.addr, unit);
  10866. cache[0] = unit;
  10867. }
  10868. textures.safeSetTexture2D(v || emptyTexture, unit);
  10869. }
  10870. function setValueT2DArray1(gl, v, textures) {
  10871. var cache = this.cache;
  10872. var unit = textures.allocateTextureUnit();
  10873. if (cache[0] !== unit) {
  10874. gl.uniform1i(this.addr, unit);
  10875. cache[0] = unit;
  10876. }
  10877. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10878. }
  10879. function setValueT3D1(gl, v, textures) {
  10880. var cache = this.cache;
  10881. var unit = textures.allocateTextureUnit();
  10882. if (cache[0] !== unit) {
  10883. gl.uniform1i(this.addr, unit);
  10884. cache[0] = unit;
  10885. }
  10886. textures.setTexture3D(v || emptyTexture3d, unit);
  10887. }
  10888. function setValueT6(gl, v, textures) {
  10889. var cache = this.cache;
  10890. var unit = textures.allocateTextureUnit();
  10891. if (cache[0] !== unit) {
  10892. gl.uniform1i(this.addr, unit);
  10893. cache[0] = unit;
  10894. }
  10895. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10896. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10897. function setValueV1i(gl, v) {
  10898. var cache = this.cache;
  10899. if (cache[0] === v) return;
  10900. gl.uniform1i(this.addr, v);
  10901. cache[0] = v;
  10902. }
  10903. function setValueV2i(gl, v) {
  10904. var cache = this.cache;
  10905. if (arraysEqual(cache, v)) return;
  10906. gl.uniform2iv(this.addr, v);
  10907. copyArray(cache, v);
  10908. }
  10909. function setValueV3i(gl, v) {
  10910. var cache = this.cache;
  10911. if (arraysEqual(cache, v)) return;
  10912. gl.uniform3iv(this.addr, v);
  10913. copyArray(cache, v);
  10914. }
  10915. function setValueV4i(gl, v) {
  10916. var cache = this.cache;
  10917. if (arraysEqual(cache, v)) return;
  10918. gl.uniform4iv(this.addr, v);
  10919. copyArray(cache, v);
  10920. } // uint
  10921. function setValueV1ui(gl, v) {
  10922. var cache = this.cache;
  10923. if (cache[0] === v) return;
  10924. gl.uniform1ui(this.addr, v);
  10925. cache[0] = v;
  10926. } // Helper to pick the right setter for the singular case
  10927. function getSingularSetter(type) {
  10928. switch (type) {
  10929. case 0x1406:
  10930. return setValueV1f;
  10931. // FLOAT
  10932. case 0x8b50:
  10933. return setValueV2f;
  10934. // _VEC2
  10935. case 0x8b51:
  10936. return setValueV3f;
  10937. // _VEC3
  10938. case 0x8b52:
  10939. return setValueV4f;
  10940. // _VEC4
  10941. case 0x8b5a:
  10942. return setValueM2;
  10943. // _MAT2
  10944. case 0x8b5b:
  10945. return setValueM3;
  10946. // _MAT3
  10947. case 0x8b5c:
  10948. return setValueM4;
  10949. // _MAT4
  10950. case 0x1404:
  10951. case 0x8b56:
  10952. return setValueV1i;
  10953. // INT, BOOL
  10954. case 0x8b53:
  10955. case 0x8b57:
  10956. return setValueV2i;
  10957. // _VEC2
  10958. case 0x8b54:
  10959. case 0x8b58:
  10960. return setValueV3i;
  10961. // _VEC3
  10962. case 0x8b55:
  10963. case 0x8b59:
  10964. return setValueV4i;
  10965. // _VEC4
  10966. case 0x1405:
  10967. return setValueV1ui;
  10968. // UINT
  10969. case 0x8b5e: // SAMPLER_2D
  10970. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10971. case 0x8dca: // INT_SAMPLER_2D
  10972. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10973. case 0x8b62:
  10974. // SAMPLER_2D_SHADOW
  10975. return setValueT1;
  10976. case 0x8b5f: // SAMPLER_3D
  10977. case 0x8dcb: // INT_SAMPLER_3D
  10978. case 0x8dd3:
  10979. // UNSIGNED_INT_SAMPLER_3D
  10980. return setValueT3D1;
  10981. case 0x8b60: // SAMPLER_CUBE
  10982. case 0x8dcc: // INT_SAMPLER_CUBE
  10983. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10984. case 0x8dc5:
  10985. // SAMPLER_CUBE_SHADOW
  10986. return setValueT6;
  10987. case 0x8dc1: // SAMPLER_2D_ARRAY
  10988. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10989. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10990. case 0x8dc4:
  10991. // SAMPLER_2D_ARRAY_SHADOW
  10992. return setValueT2DArray1;
  10993. }
  10994. } // Array of scalars
  10995. function setValueV1fArray(gl, v) {
  10996. gl.uniform1fv(this.addr, v);
  10997. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10998. function setValueV1iArray(gl, v) {
  10999. gl.uniform1iv(this.addr, v);
  11000. }
  11001. function setValueV2iArray(gl, v) {
  11002. gl.uniform2iv(this.addr, v);
  11003. }
  11004. function setValueV3iArray(gl, v) {
  11005. gl.uniform3iv(this.addr, v);
  11006. }
  11007. function setValueV4iArray(gl, v) {
  11008. gl.uniform4iv(this.addr, v);
  11009. } // Array of vectors (flat or from THREE classes)
  11010. function setValueV2fArray(gl, v) {
  11011. var data = flatten(v, this.size, 2);
  11012. gl.uniform2fv(this.addr, data);
  11013. }
  11014. function setValueV3fArray(gl, v) {
  11015. var data = flatten(v, this.size, 3);
  11016. gl.uniform3fv(this.addr, data);
  11017. }
  11018. function setValueV4fArray(gl, v) {
  11019. var data = flatten(v, this.size, 4);
  11020. gl.uniform4fv(this.addr, data);
  11021. } // Array of matrices (flat or from THREE clases)
  11022. function setValueM2Array(gl, v) {
  11023. var data = flatten(v, this.size, 4);
  11024. gl.uniformMatrix2fv(this.addr, false, data);
  11025. }
  11026. function setValueM3Array(gl, v) {
  11027. var data = flatten(v, this.size, 9);
  11028. gl.uniformMatrix3fv(this.addr, false, data);
  11029. }
  11030. function setValueM4Array(gl, v) {
  11031. var data = flatten(v, this.size, 16);
  11032. gl.uniformMatrix4fv(this.addr, false, data);
  11033. } // Array of textures (2D / Cube)
  11034. function setValueT1Array(gl, v, textures) {
  11035. var n = v.length;
  11036. var units = allocTexUnits(textures, n);
  11037. gl.uniform1iv(this.addr, units);
  11038. for (var i = 0; i !== n; ++i) {
  11039. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  11040. }
  11041. }
  11042. function setValueT6Array(gl, v, textures) {
  11043. var n = v.length;
  11044. var units = allocTexUnits(textures, n);
  11045. gl.uniform1iv(this.addr, units);
  11046. for (var i = 0; i !== n; ++i) {
  11047. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  11048. }
  11049. } // Helper to pick the right setter for a pure (bottom-level) array
  11050. function getPureArraySetter(type) {
  11051. switch (type) {
  11052. case 0x1406:
  11053. return setValueV1fArray;
  11054. // FLOAT
  11055. case 0x8b50:
  11056. return setValueV2fArray;
  11057. // _VEC2
  11058. case 0x8b51:
  11059. return setValueV3fArray;
  11060. // _VEC3
  11061. case 0x8b52:
  11062. return setValueV4fArray;
  11063. // _VEC4
  11064. case 0x8b5a:
  11065. return setValueM2Array;
  11066. // _MAT2
  11067. case 0x8b5b:
  11068. return setValueM3Array;
  11069. // _MAT3
  11070. case 0x8b5c:
  11071. return setValueM4Array;
  11072. // _MAT4
  11073. case 0x1404:
  11074. case 0x8b56:
  11075. return setValueV1iArray;
  11076. // INT, BOOL
  11077. case 0x8b53:
  11078. case 0x8b57:
  11079. return setValueV2iArray;
  11080. // _VEC2
  11081. case 0x8b54:
  11082. case 0x8b58:
  11083. return setValueV3iArray;
  11084. // _VEC3
  11085. case 0x8b55:
  11086. case 0x8b59:
  11087. return setValueV4iArray;
  11088. // _VEC4
  11089. case 0x8b5e: // SAMPLER_2D
  11090. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11091. case 0x8dca: // INT_SAMPLER_2D
  11092. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11093. case 0x8b62:
  11094. // SAMPLER_2D_SHADOW
  11095. return setValueT1Array;
  11096. case 0x8b60: // SAMPLER_CUBE
  11097. case 0x8dcc: // INT_SAMPLER_CUBE
  11098. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11099. case 0x8dc5:
  11100. // SAMPLER_CUBE_SHADOW
  11101. return setValueT6Array;
  11102. }
  11103. } // --- Uniform Classes ---
  11104. function SingleUniform(id, activeInfo, addr) {
  11105. this.id = id;
  11106. this.addr = addr;
  11107. this.cache = [];
  11108. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11109. }
  11110. function PureArrayUniform(id, activeInfo, addr) {
  11111. this.id = id;
  11112. this.addr = addr;
  11113. this.cache = [];
  11114. this.size = activeInfo.size;
  11115. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11116. }
  11117. PureArrayUniform.prototype.updateCache = function (data) {
  11118. var cache = this.cache;
  11119. if (data instanceof Float32Array && cache.length !== data.length) {
  11120. this.cache = new Float32Array(data.length);
  11121. }
  11122. copyArray(cache, data);
  11123. };
  11124. function StructuredUniform(id) {
  11125. this.id = id;
  11126. this.seq = [];
  11127. this.map = {};
  11128. }
  11129. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  11130. var seq = this.seq;
  11131. for (var i = 0, n = seq.length; i !== n; ++i) {
  11132. var u = seq[i];
  11133. u.setValue(gl, value[u.id], textures);
  11134. }
  11135. }; // --- Top-level ---
  11136. // Parser - builds up the property tree from the path strings
  11137. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  11138. // - the identifier (member name or array index)
  11139. // - followed by an optional right bracket (found when array index)
  11140. // - followed by an optional left bracket or dot (type of subscript)
  11141. //
  11142. // Note: These portions can be read in a non-overlapping fashion and
  11143. // allow straightforward parsing of the hierarchy that WebGL encodes
  11144. // in the uniform names.
  11145. function addUniform(container, uniformObject) {
  11146. container.seq.push(uniformObject);
  11147. container.map[uniformObject.id] = uniformObject;
  11148. }
  11149. function parseUniform(activeInfo, addr, container) {
  11150. var path = activeInfo.name,
  11151. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  11152. RePathPart.lastIndex = 0;
  11153. while (true) {
  11154. var match = RePathPart.exec(path),
  11155. matchEnd = RePathPart.lastIndex;
  11156. var id = match[1];
  11157. var idIsIndex = match[2] === ']',
  11158. subscript = match[3];
  11159. if (idIsIndex) id = id | 0; // convert to integer
  11160. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  11161. // bare name or "pure" bottom-level array "[0]" suffix
  11162. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  11163. break;
  11164. } else {
  11165. // step into inner node / create it in case it doesn't exist
  11166. var map = container.map;
  11167. var next = map[id];
  11168. if (next === undefined) {
  11169. next = new StructuredUniform(id);
  11170. addUniform(container, next);
  11171. }
  11172. container = next;
  11173. }
  11174. }
  11175. } // Root Container
  11176. function WebGLUniforms(gl, program) {
  11177. this.seq = [];
  11178. this.map = {};
  11179. var n = gl.getProgramParameter(program, 35718);
  11180. for (var i = 0; i < n; ++i) {
  11181. var info = gl.getActiveUniform(program, i),
  11182. addr = gl.getUniformLocation(program, info.name);
  11183. parseUniform(info, addr, this);
  11184. }
  11185. }
  11186. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  11187. var u = this.map[name];
  11188. if (u !== undefined) u.setValue(gl, value, textures);
  11189. };
  11190. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  11191. var v = object[name];
  11192. if (v !== undefined) this.setValue(gl, name, v);
  11193. }; // Static interface
  11194. WebGLUniforms.upload = function (gl, seq, values, textures) {
  11195. for (var i = 0, n = seq.length; i !== n; ++i) {
  11196. var u = seq[i],
  11197. v = values[u.id];
  11198. if (v.needsUpdate !== false) {
  11199. // note: always updating when .needsUpdate is undefined
  11200. u.setValue(gl, v.value, textures);
  11201. }
  11202. }
  11203. };
  11204. WebGLUniforms.seqWithValue = function (seq, values) {
  11205. var r = [];
  11206. for (var i = 0, n = seq.length; i !== n; ++i) {
  11207. var u = seq[i];
  11208. if (u.id in values) r.push(u);
  11209. }
  11210. return r;
  11211. };
  11212. function WebGLShader(gl, type, string) {
  11213. var shader = gl.createShader(type);
  11214. gl.shaderSource(shader, string);
  11215. gl.compileShader(shader);
  11216. return shader;
  11217. }
  11218. var programIdCount = 0;
  11219. function addLineNumbers(string) {
  11220. var lines = string.split('\n');
  11221. for (var i = 0; i < lines.length; i++) {
  11222. lines[i] = i + 1 + ': ' + lines[i];
  11223. }
  11224. return lines.join('\n');
  11225. }
  11226. function getEncodingComponents(encoding) {
  11227. switch (encoding) {
  11228. case LinearEncoding:
  11229. return ['Linear', '( value )'];
  11230. case sRGBEncoding:
  11231. return ['sRGB', '( value )'];
  11232. case RGBEEncoding:
  11233. return ['RGBE', '( value )'];
  11234. case RGBM7Encoding:
  11235. return ['RGBM', '( value, 7.0 )'];
  11236. case RGBM16Encoding:
  11237. return ['RGBM', '( value, 16.0 )'];
  11238. case RGBDEncoding:
  11239. return ['RGBD', '( value, 256.0 )'];
  11240. case GammaEncoding:
  11241. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  11242. case LogLuvEncoding:
  11243. return ['LogLuv', '( value )'];
  11244. default:
  11245. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  11246. return ['Linear', '( value )'];
  11247. }
  11248. }
  11249. function getShaderErrors(gl, shader, type) {
  11250. var status = gl.getShaderParameter(shader, 35713);
  11251. var log = gl.getShaderInfoLog(shader).trim();
  11252. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  11253. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11254. var source = gl.getShaderSource(shader);
  11255. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  11256. }
  11257. function getTexelDecodingFunction(functionName, encoding) {
  11258. var components = getEncodingComponents(encoding);
  11259. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  11260. }
  11261. function getTexelEncodingFunction(functionName, encoding) {
  11262. var components = getEncodingComponents(encoding);
  11263. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  11264. }
  11265. function getToneMappingFunction(functionName, toneMapping) {
  11266. var toneMappingName;
  11267. switch (toneMapping) {
  11268. case LinearToneMapping:
  11269. toneMappingName = 'Linear';
  11270. break;
  11271. case ReinhardToneMapping:
  11272. toneMappingName = 'Reinhard';
  11273. break;
  11274. case CineonToneMapping:
  11275. toneMappingName = 'OptimizedCineon';
  11276. break;
  11277. case ACESFilmicToneMapping:
  11278. toneMappingName = 'ACESFilmic';
  11279. break;
  11280. case CustomToneMapping:
  11281. toneMappingName = 'Custom';
  11282. break;
  11283. default:
  11284. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  11285. toneMappingName = 'Linear';
  11286. }
  11287. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11288. }
  11289. function generateExtensions(parameters) {
  11290. 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' : ''];
  11291. return chunks.filter(filterEmptyLine).join('\n');
  11292. }
  11293. function generateDefines(defines) {
  11294. var chunks = [];
  11295. for (var name in defines) {
  11296. var value = defines[name];
  11297. if (value === false) continue;
  11298. chunks.push('#define ' + name + ' ' + value);
  11299. }
  11300. return chunks.join('\n');
  11301. }
  11302. function fetchAttributeLocations(gl, program) {
  11303. var attributes = {};
  11304. var n = gl.getProgramParameter(program, 35721);
  11305. for (var i = 0; i < n; i++) {
  11306. var info = gl.getActiveAttrib(program, i);
  11307. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11308. attributes[name] = gl.getAttribLocation(program, name);
  11309. }
  11310. return attributes;
  11311. }
  11312. function filterEmptyLine(string) {
  11313. return string !== '';
  11314. }
  11315. function replaceLightNums(string, parameters) {
  11316. 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);
  11317. }
  11318. function replaceClippingPlaneNums(string, parameters) {
  11319. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  11320. } // Resolve Includes
  11321. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11322. function resolveIncludes(string) {
  11323. return string.replace(includePattern, includeReplacer);
  11324. }
  11325. function includeReplacer(match, include) {
  11326. var string = ShaderChunk[include];
  11327. if (string === undefined) {
  11328. throw new Error('Can not resolve #include <' + include + '>');
  11329. }
  11330. return resolveIncludes(string);
  11331. } // Unroll Loops
  11332. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11333. 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;
  11334. function unrollLoops(string) {
  11335. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  11336. }
  11337. function deprecatedLoopReplacer(match, start, end, snippet) {
  11338. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  11339. return loopReplacer(match, start, end, snippet);
  11340. }
  11341. function loopReplacer(match, start, end, snippet) {
  11342. var string = '';
  11343. for (var i = parseInt(start); i < parseInt(end); i++) {
  11344. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  11345. }
  11346. return string;
  11347. } //
  11348. function generatePrecision(parameters) {
  11349. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  11350. if (parameters.precision === 'highp') {
  11351. precisionstring += '\n#define HIGH_PRECISION';
  11352. } else if (parameters.precision === 'mediump') {
  11353. precisionstring += '\n#define MEDIUM_PRECISION';
  11354. } else if (parameters.precision === 'lowp') {
  11355. precisionstring += '\n#define LOW_PRECISION';
  11356. }
  11357. return precisionstring;
  11358. }
  11359. function generateShadowMapTypeDefine(parameters) {
  11360. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11361. if (parameters.shadowMapType === PCFShadowMap) {
  11362. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11363. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  11364. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11365. } else if (parameters.shadowMapType === VSMShadowMap) {
  11366. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11367. }
  11368. return shadowMapTypeDefine;
  11369. }
  11370. function generateEnvMapTypeDefine(parameters) {
  11371. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11372. if (parameters.envMap) {
  11373. switch (parameters.envMapMode) {
  11374. case CubeReflectionMapping:
  11375. case CubeRefractionMapping:
  11376. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11377. break;
  11378. case CubeUVReflectionMapping:
  11379. case CubeUVRefractionMapping:
  11380. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11381. break;
  11382. }
  11383. }
  11384. return envMapTypeDefine;
  11385. }
  11386. function generateEnvMapModeDefine(parameters) {
  11387. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11388. if (parameters.envMap) {
  11389. switch (parameters.envMapMode) {
  11390. case CubeRefractionMapping:
  11391. case CubeUVRefractionMapping:
  11392. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11393. break;
  11394. }
  11395. }
  11396. return envMapModeDefine;
  11397. }
  11398. function generateEnvMapBlendingDefine(parameters) {
  11399. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11400. if (parameters.envMap) {
  11401. switch (parameters.combine) {
  11402. case MultiplyOperation:
  11403. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11404. break;
  11405. case MixOperation:
  11406. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11407. break;
  11408. case AddOperation:
  11409. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11410. break;
  11411. }
  11412. }
  11413. return envMapBlendingDefine;
  11414. }
  11415. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  11416. var gl = renderer.getContext();
  11417. var defines = parameters.defines;
  11418. var vertexShader = parameters.vertexShader;
  11419. var fragmentShader = parameters.fragmentShader;
  11420. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  11421. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  11422. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  11423. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  11424. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  11425. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  11426. var customDefines = generateDefines(defines);
  11427. var program = gl.createProgram();
  11428. var prefixVertex, prefixFragment;
  11429. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11430. if (parameters.isRawShaderMaterial) {
  11431. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  11432. if (prefixVertex.length > 0) {
  11433. prefixVertex += '\n';
  11434. }
  11435. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  11436. if (prefixFragment.length > 0) {
  11437. prefixFragment += '\n';
  11438. }
  11439. } else {
  11440. 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');
  11441. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  11442. '#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
  11443. 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
  11444. 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');
  11445. }
  11446. vertexShader = resolveIncludes(vertexShader);
  11447. vertexShader = replaceLightNums(vertexShader, parameters);
  11448. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  11449. fragmentShader = resolveIncludes(fragmentShader);
  11450. fragmentShader = replaceLightNums(fragmentShader, parameters);
  11451. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  11452. vertexShader = unrollLoops(vertexShader);
  11453. fragmentShader = unrollLoops(fragmentShader);
  11454. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  11455. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11456. versionString = '#version 300 es\n';
  11457. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  11458. 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;
  11459. }
  11460. var vertexGlsl = versionString + prefixVertex + vertexShader;
  11461. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  11462. // console.log( '*FRAGMENT*', fragmentGlsl );
  11463. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  11464. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  11465. gl.attachShader(program, glVertexShader);
  11466. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  11467. if (parameters.index0AttributeName !== undefined) {
  11468. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  11469. } else if (parameters.morphTargets === true) {
  11470. // programs with morphTargets displace position out of attribute 0
  11471. gl.bindAttribLocation(program, 0, 'position');
  11472. }
  11473. gl.linkProgram(program); // check for link errors
  11474. if (renderer.debug.checkShaderErrors) {
  11475. var programLog = gl.getProgramInfoLog(program).trim();
  11476. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  11477. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  11478. var runnable = true;
  11479. var haveDiagnostics = true;
  11480. if (gl.getProgramParameter(program, 35714) === false) {
  11481. runnable = false;
  11482. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  11483. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  11484. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11485. } else if (programLog !== '') {
  11486. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11487. } else if (vertexLog === '' || fragmentLog === '') {
  11488. haveDiagnostics = false;
  11489. }
  11490. if (haveDiagnostics) {
  11491. this.diagnostics = {
  11492. runnable: runnable,
  11493. programLog: programLog,
  11494. vertexShader: {
  11495. log: vertexLog,
  11496. prefix: prefixVertex
  11497. },
  11498. fragmentShader: {
  11499. log: fragmentLog,
  11500. prefix: prefixFragment
  11501. }
  11502. };
  11503. }
  11504. } // Clean up
  11505. // Crashes in iOS9 and iOS10. #18402
  11506. // gl.detachShader( program, glVertexShader );
  11507. // gl.detachShader( program, glFragmentShader );
  11508. gl.deleteShader(glVertexShader);
  11509. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11510. var cachedUniforms;
  11511. this.getUniforms = function () {
  11512. if (cachedUniforms === undefined) {
  11513. cachedUniforms = new WebGLUniforms(gl, program);
  11514. }
  11515. return cachedUniforms;
  11516. }; // set up caching for attribute locations
  11517. var cachedAttributes;
  11518. this.getAttributes = function () {
  11519. if (cachedAttributes === undefined) {
  11520. cachedAttributes = fetchAttributeLocations(gl, program);
  11521. }
  11522. return cachedAttributes;
  11523. }; // free resource
  11524. this.destroy = function () {
  11525. bindingStates.releaseStatesOfProgram(this);
  11526. gl.deleteProgram(program);
  11527. this.program = undefined;
  11528. }; //
  11529. this.name = parameters.shaderName;
  11530. this.id = programIdCount++;
  11531. this.cacheKey = cacheKey;
  11532. this.usedTimes = 1;
  11533. this.program = program;
  11534. this.vertexShader = glVertexShader;
  11535. this.fragmentShader = glFragmentShader;
  11536. return this;
  11537. }
  11538. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11539. var programs = [];
  11540. var isWebGL2 = capabilities.isWebGL2;
  11541. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11542. var floatVertexTextures = capabilities.floatVertexTextures;
  11543. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11544. var vertexTextures = capabilities.vertexTextures;
  11545. var precision = capabilities.precision;
  11546. var shaderIDs = {
  11547. MeshDepthMaterial: 'depth',
  11548. MeshDistanceMaterial: 'distanceRGBA',
  11549. MeshNormalMaterial: 'normal',
  11550. MeshBasicMaterial: 'basic',
  11551. MeshLambertMaterial: 'lambert',
  11552. MeshPhongMaterial: 'phong',
  11553. MeshToonMaterial: 'toon',
  11554. MeshStandardMaterial: 'physical',
  11555. MeshPhysicalMaterial: 'physical',
  11556. MeshMatcapMaterial: 'matcap',
  11557. LineBasicMaterial: 'basic',
  11558. LineDashedMaterial: 'dashed',
  11559. PointsMaterial: 'points',
  11560. ShadowMaterial: 'shadow',
  11561. SpriteMaterial: 'sprite'
  11562. };
  11563. 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'];
  11564. function getMaxBones(object) {
  11565. var skeleton = object.skeleton;
  11566. var bones = skeleton.bones;
  11567. if (floatVertexTextures) {
  11568. return 1024;
  11569. } else {
  11570. // default for when object is not specified
  11571. // ( for example when prebuilding shader to be used with multiple objects )
  11572. //
  11573. // - leave some extra space for other uniforms
  11574. // - limit here is ANGLE's 254 max uniform vectors
  11575. // (up to 54 should be safe)
  11576. var nVertexUniforms = maxVertexUniforms;
  11577. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11578. var maxBones = Math.min(nVertexMatrices, bones.length);
  11579. if (maxBones < bones.length) {
  11580. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11581. return 0;
  11582. }
  11583. return maxBones;
  11584. }
  11585. }
  11586. function getTextureEncodingFromMap(map) {
  11587. var encoding;
  11588. if (map && map.isTexture) {
  11589. encoding = map.encoding;
  11590. } else if (map && map.isWebGLRenderTarget) {
  11591. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11592. encoding = map.texture.encoding;
  11593. } else {
  11594. encoding = LinearEncoding;
  11595. }
  11596. return encoding;
  11597. }
  11598. function getParameters(material, lights, shadows, scene, object) {
  11599. var fog = scene.fog;
  11600. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11601. var envMap = cubemaps.get(material.envMap || environment);
  11602. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11603. // (not to blow over maxLights budget)
  11604. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11605. if (material.precision !== null) {
  11606. precision = capabilities.getMaxPrecision(material.precision);
  11607. if (precision !== material.precision) {
  11608. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11609. }
  11610. }
  11611. var vertexShader, fragmentShader;
  11612. if (shaderID) {
  11613. var shader = ShaderLib[shaderID];
  11614. vertexShader = shader.vertexShader;
  11615. fragmentShader = shader.fragmentShader;
  11616. } else {
  11617. vertexShader = material.vertexShader;
  11618. fragmentShader = material.fragmentShader;
  11619. }
  11620. var currentRenderTarget = renderer.getRenderTarget();
  11621. var parameters = {
  11622. isWebGL2: isWebGL2,
  11623. shaderID: shaderID,
  11624. shaderName: material.type,
  11625. vertexShader: vertexShader,
  11626. fragmentShader: fragmentShader,
  11627. defines: material.defines,
  11628. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11629. glslVersion: material.glslVersion,
  11630. precision: precision,
  11631. instancing: object.isInstancedMesh === true,
  11632. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11633. supportsVertexTextures: vertexTextures,
  11634. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11635. map: !!material.map,
  11636. mapEncoding: getTextureEncodingFromMap(material.map),
  11637. matcap: !!material.matcap,
  11638. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11639. envMap: !!envMap,
  11640. envMapMode: envMap && envMap.mapping,
  11641. envMapEncoding: getTextureEncodingFromMap(envMap),
  11642. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11643. lightMap: !!material.lightMap,
  11644. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11645. aoMap: !!material.aoMap,
  11646. emissiveMap: !!material.emissiveMap,
  11647. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11648. bumpMap: !!material.bumpMap,
  11649. normalMap: !!material.normalMap,
  11650. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11651. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11652. clearcoatMap: !!material.clearcoatMap,
  11653. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11654. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11655. displacementMap: !!material.displacementMap,
  11656. roughnessMap: !!material.roughnessMap,
  11657. metalnessMap: !!material.metalnessMap,
  11658. specularMap: !!material.specularMap,
  11659. alphaMap: !!material.alphaMap,
  11660. gradientMap: !!material.gradientMap,
  11661. sheen: !!material.sheen,
  11662. transmissionMap: !!material.transmissionMap,
  11663. combine: material.combine,
  11664. vertexTangents: material.normalMap && material.vertexTangents,
  11665. vertexColors: material.vertexColors,
  11666. 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,
  11667. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11668. fog: !!fog,
  11669. useFog: material.fog,
  11670. fogExp2: fog && fog.isFogExp2,
  11671. flatShading: !!material.flatShading,
  11672. sizeAttenuation: material.sizeAttenuation,
  11673. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11674. skinning: material.skinning && maxBones > 0,
  11675. maxBones: maxBones,
  11676. useVertexTexture: floatVertexTextures,
  11677. morphTargets: material.morphTargets,
  11678. morphNormals: material.morphNormals,
  11679. maxMorphTargets: renderer.maxMorphTargets,
  11680. maxMorphNormals: renderer.maxMorphNormals,
  11681. numDirLights: lights.directional.length,
  11682. numPointLights: lights.point.length,
  11683. numSpotLights: lights.spot.length,
  11684. numRectAreaLights: lights.rectArea.length,
  11685. numHemiLights: lights.hemi.length,
  11686. numDirLightShadows: lights.directionalShadowMap.length,
  11687. numPointLightShadows: lights.pointShadowMap.length,
  11688. numSpotLightShadows: lights.spotShadowMap.length,
  11689. numClippingPlanes: clipping.numPlanes,
  11690. numClipIntersection: clipping.numIntersection,
  11691. dithering: material.dithering,
  11692. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11693. shadowMapType: renderer.shadowMap.type,
  11694. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11695. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11696. premultipliedAlpha: material.premultipliedAlpha,
  11697. alphaTest: material.alphaTest,
  11698. doubleSided: material.side === DoubleSide,
  11699. flipSided: material.side === BackSide,
  11700. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11701. index0AttributeName: material.index0AttributeName,
  11702. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11703. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11704. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11705. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11706. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11707. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11708. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11709. customProgramCacheKey: material.customProgramCacheKey()
  11710. };
  11711. return parameters;
  11712. }
  11713. function getProgramCacheKey(parameters) {
  11714. var array = [];
  11715. if (parameters.shaderID) {
  11716. array.push(parameters.shaderID);
  11717. } else {
  11718. array.push(parameters.fragmentShader);
  11719. array.push(parameters.vertexShader);
  11720. }
  11721. if (parameters.defines !== undefined) {
  11722. for (var name in parameters.defines) {
  11723. array.push(name);
  11724. array.push(parameters.defines[name]);
  11725. }
  11726. }
  11727. if (parameters.isRawShaderMaterial === false) {
  11728. for (var i = 0; i < parameterNames.length; i++) {
  11729. array.push(parameters[parameterNames[i]]);
  11730. }
  11731. array.push(renderer.outputEncoding);
  11732. array.push(renderer.gammaFactor);
  11733. }
  11734. array.push(parameters.customProgramCacheKey);
  11735. return array.join();
  11736. }
  11737. function getUniforms(material) {
  11738. var shaderID = shaderIDs[material.type];
  11739. var uniforms;
  11740. if (shaderID) {
  11741. var shader = ShaderLib[shaderID];
  11742. uniforms = UniformsUtils.clone(shader.uniforms);
  11743. } else {
  11744. uniforms = material.uniforms;
  11745. }
  11746. return uniforms;
  11747. }
  11748. function acquireProgram(parameters, cacheKey) {
  11749. var program; // Check if code has been already compiled
  11750. for (var p = 0, pl = programs.length; p < pl; p++) {
  11751. var preexistingProgram = programs[p];
  11752. if (preexistingProgram.cacheKey === cacheKey) {
  11753. program = preexistingProgram;
  11754. ++program.usedTimes;
  11755. break;
  11756. }
  11757. }
  11758. if (program === undefined) {
  11759. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11760. programs.push(program);
  11761. }
  11762. return program;
  11763. }
  11764. function releaseProgram(program) {
  11765. if (--program.usedTimes === 0) {
  11766. // Remove from unordered set
  11767. var i = programs.indexOf(program);
  11768. programs[i] = programs[programs.length - 1];
  11769. programs.pop(); // Free WebGL resources
  11770. program.destroy();
  11771. }
  11772. }
  11773. return {
  11774. getParameters: getParameters,
  11775. getProgramCacheKey: getProgramCacheKey,
  11776. getUniforms: getUniforms,
  11777. acquireProgram: acquireProgram,
  11778. releaseProgram: releaseProgram,
  11779. // Exposed for resource monitoring & error feedback via renderer.info:
  11780. programs: programs
  11781. };
  11782. }
  11783. function WebGLProperties() {
  11784. var properties = new WeakMap();
  11785. function get(object) {
  11786. var map = properties.get(object);
  11787. if (map === undefined) {
  11788. map = {};
  11789. properties.set(object, map);
  11790. }
  11791. return map;
  11792. }
  11793. function remove(object) {
  11794. properties.delete(object);
  11795. }
  11796. function update(object, key, value) {
  11797. properties.get(object)[key] = value;
  11798. }
  11799. function dispose() {
  11800. properties = new WeakMap();
  11801. }
  11802. return {
  11803. get: get,
  11804. remove: remove,
  11805. update: update,
  11806. dispose: dispose
  11807. };
  11808. }
  11809. function painterSortStable(a, b) {
  11810. if (a.groupOrder !== b.groupOrder) {
  11811. return a.groupOrder - b.groupOrder;
  11812. } else if (a.renderOrder !== b.renderOrder) {
  11813. return a.renderOrder - b.renderOrder;
  11814. } else if (a.program !== b.program) {
  11815. return a.program.id - b.program.id;
  11816. } else if (a.material.id !== b.material.id) {
  11817. return a.material.id - b.material.id;
  11818. } else if (a.z !== b.z) {
  11819. return a.z - b.z;
  11820. } else {
  11821. return a.id - b.id;
  11822. }
  11823. }
  11824. function reversePainterSortStable(a, b) {
  11825. if (a.groupOrder !== b.groupOrder) {
  11826. return a.groupOrder - b.groupOrder;
  11827. } else if (a.renderOrder !== b.renderOrder) {
  11828. return a.renderOrder - b.renderOrder;
  11829. } else if (a.z !== b.z) {
  11830. return b.z - a.z;
  11831. } else {
  11832. return a.id - b.id;
  11833. }
  11834. }
  11835. function WebGLRenderList(properties) {
  11836. var renderItems = [];
  11837. var renderItemsIndex = 0;
  11838. var opaque = [];
  11839. var transparent = [];
  11840. var defaultProgram = {
  11841. id: -1
  11842. };
  11843. function init() {
  11844. renderItemsIndex = 0;
  11845. opaque.length = 0;
  11846. transparent.length = 0;
  11847. }
  11848. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11849. var renderItem = renderItems[renderItemsIndex];
  11850. var materialProperties = properties.get(material);
  11851. if (renderItem === undefined) {
  11852. renderItem = {
  11853. id: object.id,
  11854. object: object,
  11855. geometry: geometry,
  11856. material: material,
  11857. program: materialProperties.program || defaultProgram,
  11858. groupOrder: groupOrder,
  11859. renderOrder: object.renderOrder,
  11860. z: z,
  11861. group: group
  11862. };
  11863. renderItems[renderItemsIndex] = renderItem;
  11864. } else {
  11865. renderItem.id = object.id;
  11866. renderItem.object = object;
  11867. renderItem.geometry = geometry;
  11868. renderItem.material = material;
  11869. renderItem.program = materialProperties.program || defaultProgram;
  11870. renderItem.groupOrder = groupOrder;
  11871. renderItem.renderOrder = object.renderOrder;
  11872. renderItem.z = z;
  11873. renderItem.group = group;
  11874. }
  11875. renderItemsIndex++;
  11876. return renderItem;
  11877. }
  11878. function push(object, geometry, material, groupOrder, z, group) {
  11879. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11880. (material.transparent === true ? transparent : opaque).push(renderItem);
  11881. }
  11882. function unshift(object, geometry, material, groupOrder, z, group) {
  11883. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11884. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11885. }
  11886. function sort(customOpaqueSort, customTransparentSort) {
  11887. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11888. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11889. }
  11890. function finish() {
  11891. // Clear references from inactive renderItems in the list
  11892. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11893. var renderItem = renderItems[i];
  11894. if (renderItem.id === null) break;
  11895. renderItem.id = null;
  11896. renderItem.object = null;
  11897. renderItem.geometry = null;
  11898. renderItem.material = null;
  11899. renderItem.program = null;
  11900. renderItem.group = null;
  11901. }
  11902. }
  11903. return {
  11904. opaque: opaque,
  11905. transparent: transparent,
  11906. init: init,
  11907. push: push,
  11908. unshift: unshift,
  11909. finish: finish,
  11910. sort: sort
  11911. };
  11912. }
  11913. function WebGLRenderLists(properties) {
  11914. var lists = new WeakMap();
  11915. function get(scene, renderCallDepth) {
  11916. var list;
  11917. if (lists.has(scene) === false) {
  11918. list = new WebGLRenderList(properties);
  11919. lists.set(scene, [list]);
  11920. } else {
  11921. if (renderCallDepth >= lists.get(scene).length) {
  11922. list = new WebGLRenderList(properties);
  11923. lists.get(scene).push(list);
  11924. } else {
  11925. list = lists.get(scene)[renderCallDepth];
  11926. }
  11927. }
  11928. return list;
  11929. }
  11930. function dispose() {
  11931. lists = new WeakMap();
  11932. }
  11933. return {
  11934. get: get,
  11935. dispose: dispose
  11936. };
  11937. }
  11938. function UniformsCache() {
  11939. var lights = {};
  11940. return {
  11941. get: function get(light) {
  11942. if (lights[light.id] !== undefined) {
  11943. return lights[light.id];
  11944. }
  11945. var uniforms;
  11946. switch (light.type) {
  11947. case 'DirectionalLight':
  11948. uniforms = {
  11949. direction: new Vector3(),
  11950. color: new Color()
  11951. };
  11952. break;
  11953. case 'SpotLight':
  11954. uniforms = {
  11955. position: new Vector3(),
  11956. direction: new Vector3(),
  11957. color: new Color(),
  11958. distance: 0,
  11959. coneCos: 0,
  11960. penumbraCos: 0,
  11961. decay: 0
  11962. };
  11963. break;
  11964. case 'PointLight':
  11965. uniforms = {
  11966. position: new Vector3(),
  11967. color: new Color(),
  11968. distance: 0,
  11969. decay: 0
  11970. };
  11971. break;
  11972. case 'HemisphereLight':
  11973. uniforms = {
  11974. direction: new Vector3(),
  11975. skyColor: new Color(),
  11976. groundColor: new Color()
  11977. };
  11978. break;
  11979. case 'RectAreaLight':
  11980. uniforms = {
  11981. color: new Color(),
  11982. position: new Vector3(),
  11983. halfWidth: new Vector3(),
  11984. halfHeight: new Vector3()
  11985. };
  11986. break;
  11987. }
  11988. lights[light.id] = uniforms;
  11989. return uniforms;
  11990. }
  11991. };
  11992. }
  11993. function ShadowUniformsCache() {
  11994. var lights = {};
  11995. return {
  11996. get: function get(light) {
  11997. if (lights[light.id] !== undefined) {
  11998. return lights[light.id];
  11999. }
  12000. var uniforms;
  12001. switch (light.type) {
  12002. case 'DirectionalLight':
  12003. uniforms = {
  12004. shadowBias: 0,
  12005. shadowNormalBias: 0,
  12006. shadowRadius: 1,
  12007. shadowMapSize: new Vector2()
  12008. };
  12009. break;
  12010. case 'SpotLight':
  12011. uniforms = {
  12012. shadowBias: 0,
  12013. shadowNormalBias: 0,
  12014. shadowRadius: 1,
  12015. shadowMapSize: new Vector2()
  12016. };
  12017. break;
  12018. case 'PointLight':
  12019. uniforms = {
  12020. shadowBias: 0,
  12021. shadowNormalBias: 0,
  12022. shadowRadius: 1,
  12023. shadowMapSize: new Vector2(),
  12024. shadowCameraNear: 1,
  12025. shadowCameraFar: 1000
  12026. };
  12027. break;
  12028. // TODO (abelnation): set RectAreaLight shadow uniforms
  12029. }
  12030. lights[light.id] = uniforms;
  12031. return uniforms;
  12032. }
  12033. };
  12034. }
  12035. var nextVersion = 0;
  12036. function shadowCastingLightsFirst(lightA, lightB) {
  12037. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  12038. }
  12039. function WebGLLights(extensions, capabilities) {
  12040. var cache = new UniformsCache();
  12041. var shadowCache = ShadowUniformsCache();
  12042. var state = {
  12043. version: 0,
  12044. hash: {
  12045. directionalLength: -1,
  12046. pointLength: -1,
  12047. spotLength: -1,
  12048. rectAreaLength: -1,
  12049. hemiLength: -1,
  12050. numDirectionalShadows: -1,
  12051. numPointShadows: -1,
  12052. numSpotShadows: -1
  12053. },
  12054. ambient: [0, 0, 0],
  12055. probe: [],
  12056. directional: [],
  12057. directionalShadow: [],
  12058. directionalShadowMap: [],
  12059. directionalShadowMatrix: [],
  12060. spot: [],
  12061. spotShadow: [],
  12062. spotShadowMap: [],
  12063. spotShadowMatrix: [],
  12064. rectArea: [],
  12065. rectAreaLTC1: null,
  12066. rectAreaLTC2: null,
  12067. point: [],
  12068. pointShadow: [],
  12069. pointShadowMap: [],
  12070. pointShadowMatrix: [],
  12071. hemi: []
  12072. };
  12073. for (var i = 0; i < 9; i++) {
  12074. state.probe.push(new Vector3());
  12075. }
  12076. var vector3 = new Vector3();
  12077. var matrix4 = new Matrix4();
  12078. var matrix42 = new Matrix4();
  12079. function setup(lights) {
  12080. var r = 0,
  12081. g = 0,
  12082. b = 0;
  12083. for (var _i = 0; _i < 9; _i++) {
  12084. state.probe[_i].set(0, 0, 0);
  12085. }
  12086. var directionalLength = 0;
  12087. var pointLength = 0;
  12088. var spotLength = 0;
  12089. var rectAreaLength = 0;
  12090. var hemiLength = 0;
  12091. var numDirectionalShadows = 0;
  12092. var numPointShadows = 0;
  12093. var numSpotShadows = 0;
  12094. lights.sort(shadowCastingLightsFirst);
  12095. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  12096. var light = lights[_i2];
  12097. var color = light.color;
  12098. var intensity = light.intensity;
  12099. var distance = light.distance;
  12100. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  12101. if (light.isAmbientLight) {
  12102. r += color.r * intensity;
  12103. g += color.g * intensity;
  12104. b += color.b * intensity;
  12105. } else if (light.isLightProbe) {
  12106. for (var j = 0; j < 9; j++) {
  12107. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  12108. }
  12109. } else if (light.isDirectionalLight) {
  12110. var uniforms = cache.get(light);
  12111. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  12112. if (light.castShadow) {
  12113. var shadow = light.shadow;
  12114. var shadowUniforms = shadowCache.get(light);
  12115. shadowUniforms.shadowBias = shadow.bias;
  12116. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12117. shadowUniforms.shadowRadius = shadow.radius;
  12118. shadowUniforms.shadowMapSize = shadow.mapSize;
  12119. state.directionalShadow[directionalLength] = shadowUniforms;
  12120. state.directionalShadowMap[directionalLength] = shadowMap;
  12121. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  12122. numDirectionalShadows++;
  12123. }
  12124. state.directional[directionalLength] = uniforms;
  12125. directionalLength++;
  12126. } else if (light.isSpotLight) {
  12127. var _uniforms = cache.get(light);
  12128. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  12129. _uniforms.color.copy(color).multiplyScalar(intensity);
  12130. _uniforms.distance = distance;
  12131. _uniforms.coneCos = Math.cos(light.angle);
  12132. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  12133. _uniforms.decay = light.decay;
  12134. if (light.castShadow) {
  12135. var _shadow = light.shadow;
  12136. var _shadowUniforms = shadowCache.get(light);
  12137. _shadowUniforms.shadowBias = _shadow.bias;
  12138. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  12139. _shadowUniforms.shadowRadius = _shadow.radius;
  12140. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  12141. state.spotShadow[spotLength] = _shadowUniforms;
  12142. state.spotShadowMap[spotLength] = shadowMap;
  12143. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  12144. numSpotShadows++;
  12145. }
  12146. state.spot[spotLength] = _uniforms;
  12147. spotLength++;
  12148. } else if (light.isRectAreaLight) {
  12149. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  12150. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12151. // (b) intensity is the brightness of the light
  12152. _uniforms2.color.copy(color).multiplyScalar(intensity);
  12153. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12154. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12155. state.rectArea[rectAreaLength] = _uniforms2;
  12156. rectAreaLength++;
  12157. } else if (light.isPointLight) {
  12158. var _uniforms3 = cache.get(light);
  12159. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  12160. _uniforms3.distance = light.distance;
  12161. _uniforms3.decay = light.decay;
  12162. if (light.castShadow) {
  12163. var _shadow2 = light.shadow;
  12164. var _shadowUniforms2 = shadowCache.get(light);
  12165. _shadowUniforms2.shadowBias = _shadow2.bias;
  12166. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  12167. _shadowUniforms2.shadowRadius = _shadow2.radius;
  12168. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  12169. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  12170. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  12171. state.pointShadow[pointLength] = _shadowUniforms2;
  12172. state.pointShadowMap[pointLength] = shadowMap;
  12173. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  12174. numPointShadows++;
  12175. }
  12176. state.point[pointLength] = _uniforms3;
  12177. pointLength++;
  12178. } else if (light.isHemisphereLight) {
  12179. var _uniforms4 = cache.get(light);
  12180. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  12181. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  12182. state.hemi[hemiLength] = _uniforms4;
  12183. hemiLength++;
  12184. }
  12185. }
  12186. if (rectAreaLength > 0) {
  12187. if (capabilities.isWebGL2) {
  12188. // WebGL 2
  12189. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12190. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12191. } else {
  12192. // WebGL 1
  12193. if (extensions.has('OES_texture_float_linear') === true) {
  12194. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12195. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12196. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  12197. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12198. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12199. } else {
  12200. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  12201. }
  12202. }
  12203. }
  12204. state.ambient[0] = r;
  12205. state.ambient[1] = g;
  12206. state.ambient[2] = b;
  12207. var hash = state.hash;
  12208. 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) {
  12209. state.directional.length = directionalLength;
  12210. state.spot.length = spotLength;
  12211. state.rectArea.length = rectAreaLength;
  12212. state.point.length = pointLength;
  12213. state.hemi.length = hemiLength;
  12214. state.directionalShadow.length = numDirectionalShadows;
  12215. state.directionalShadowMap.length = numDirectionalShadows;
  12216. state.pointShadow.length = numPointShadows;
  12217. state.pointShadowMap.length = numPointShadows;
  12218. state.spotShadow.length = numSpotShadows;
  12219. state.spotShadowMap.length = numSpotShadows;
  12220. state.directionalShadowMatrix.length = numDirectionalShadows;
  12221. state.pointShadowMatrix.length = numPointShadows;
  12222. state.spotShadowMatrix.length = numSpotShadows;
  12223. hash.directionalLength = directionalLength;
  12224. hash.pointLength = pointLength;
  12225. hash.spotLength = spotLength;
  12226. hash.rectAreaLength = rectAreaLength;
  12227. hash.hemiLength = hemiLength;
  12228. hash.numDirectionalShadows = numDirectionalShadows;
  12229. hash.numPointShadows = numPointShadows;
  12230. hash.numSpotShadows = numSpotShadows;
  12231. state.version = nextVersion++;
  12232. }
  12233. }
  12234. function setupView(lights, camera) {
  12235. var directionalLength = 0;
  12236. var pointLength = 0;
  12237. var spotLength = 0;
  12238. var rectAreaLength = 0;
  12239. var hemiLength = 0;
  12240. var viewMatrix = camera.matrixWorldInverse;
  12241. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  12242. var light = lights[_i3];
  12243. if (light.isDirectionalLight) {
  12244. var uniforms = state.directional[directionalLength];
  12245. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  12246. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12247. uniforms.direction.sub(vector3);
  12248. uniforms.direction.transformDirection(viewMatrix);
  12249. directionalLength++;
  12250. } else if (light.isSpotLight) {
  12251. var _uniforms5 = state.spot[spotLength];
  12252. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  12253. _uniforms5.position.applyMatrix4(viewMatrix);
  12254. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  12255. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12256. _uniforms5.direction.sub(vector3);
  12257. _uniforms5.direction.transformDirection(viewMatrix);
  12258. spotLength++;
  12259. } else if (light.isRectAreaLight) {
  12260. var _uniforms6 = state.rectArea[rectAreaLength];
  12261. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  12262. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  12263. matrix42.identity();
  12264. matrix4.copy(light.matrixWorld);
  12265. matrix4.premultiply(viewMatrix);
  12266. matrix42.extractRotation(matrix4);
  12267. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12268. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12269. _uniforms6.halfWidth.applyMatrix4(matrix42);
  12270. _uniforms6.halfHeight.applyMatrix4(matrix42);
  12271. rectAreaLength++;
  12272. } else if (light.isPointLight) {
  12273. var _uniforms7 = state.point[pointLength];
  12274. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  12275. _uniforms7.position.applyMatrix4(viewMatrix);
  12276. pointLength++;
  12277. } else if (light.isHemisphereLight) {
  12278. var _uniforms8 = state.hemi[hemiLength];
  12279. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  12280. _uniforms8.direction.transformDirection(viewMatrix);
  12281. _uniforms8.direction.normalize();
  12282. hemiLength++;
  12283. }
  12284. }
  12285. }
  12286. return {
  12287. setup: setup,
  12288. setupView: setupView,
  12289. state: state
  12290. };
  12291. }
  12292. function WebGLRenderState(extensions, capabilities) {
  12293. var lights = new WebGLLights(extensions, capabilities);
  12294. var lightsArray = [];
  12295. var shadowsArray = [];
  12296. function init() {
  12297. lightsArray.length = 0;
  12298. shadowsArray.length = 0;
  12299. }
  12300. function pushLight(light) {
  12301. lightsArray.push(light);
  12302. }
  12303. function pushShadow(shadowLight) {
  12304. shadowsArray.push(shadowLight);
  12305. }
  12306. function setupLights() {
  12307. lights.setup(lightsArray);
  12308. }
  12309. function setupLightsView(camera) {
  12310. lights.setupView(lightsArray, camera);
  12311. }
  12312. var state = {
  12313. lightsArray: lightsArray,
  12314. shadowsArray: shadowsArray,
  12315. lights: lights
  12316. };
  12317. return {
  12318. init: init,
  12319. state: state,
  12320. setupLights: setupLights,
  12321. setupLightsView: setupLightsView,
  12322. pushLight: pushLight,
  12323. pushShadow: pushShadow
  12324. };
  12325. }
  12326. function WebGLRenderStates(extensions, capabilities) {
  12327. var renderStates = new WeakMap();
  12328. function get(scene, renderCallDepth) {
  12329. if (renderCallDepth === void 0) {
  12330. renderCallDepth = 0;
  12331. }
  12332. var renderState;
  12333. if (renderStates.has(scene) === false) {
  12334. renderState = new WebGLRenderState(extensions, capabilities);
  12335. renderStates.set(scene, [renderState]);
  12336. } else {
  12337. if (renderCallDepth >= renderStates.get(scene).length) {
  12338. renderState = new WebGLRenderState(extensions, capabilities);
  12339. renderStates.get(scene).push(renderState);
  12340. } else {
  12341. renderState = renderStates.get(scene)[renderCallDepth];
  12342. }
  12343. }
  12344. return renderState;
  12345. }
  12346. function dispose() {
  12347. renderStates = new WeakMap();
  12348. }
  12349. return {
  12350. get: get,
  12351. dispose: dispose
  12352. };
  12353. }
  12354. /**
  12355. * parameters = {
  12356. *
  12357. * opacity: <float>,
  12358. *
  12359. * map: new THREE.Texture( <Image> ),
  12360. *
  12361. * alphaMap: new THREE.Texture( <Image> ),
  12362. *
  12363. * displacementMap: new THREE.Texture( <Image> ),
  12364. * displacementScale: <float>,
  12365. * displacementBias: <float>,
  12366. *
  12367. * wireframe: <boolean>,
  12368. * wireframeLinewidth: <float>
  12369. * }
  12370. */
  12371. function MeshDepthMaterial(parameters) {
  12372. Material.call(this);
  12373. this.type = 'MeshDepthMaterial';
  12374. this.depthPacking = BasicDepthPacking;
  12375. this.skinning = false;
  12376. this.morphTargets = false;
  12377. this.map = null;
  12378. this.alphaMap = null;
  12379. this.displacementMap = null;
  12380. this.displacementScale = 1;
  12381. this.displacementBias = 0;
  12382. this.wireframe = false;
  12383. this.wireframeLinewidth = 1;
  12384. this.fog = false;
  12385. this.setValues(parameters);
  12386. }
  12387. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  12388. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12389. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12390. MeshDepthMaterial.prototype.copy = function (source) {
  12391. Material.prototype.copy.call(this, source);
  12392. this.depthPacking = source.depthPacking;
  12393. this.skinning = source.skinning;
  12394. this.morphTargets = source.morphTargets;
  12395. this.map = source.map;
  12396. this.alphaMap = source.alphaMap;
  12397. this.displacementMap = source.displacementMap;
  12398. this.displacementScale = source.displacementScale;
  12399. this.displacementBias = source.displacementBias;
  12400. this.wireframe = source.wireframe;
  12401. this.wireframeLinewidth = source.wireframeLinewidth;
  12402. return this;
  12403. };
  12404. /**
  12405. * parameters = {
  12406. *
  12407. * referencePosition: <float>,
  12408. * nearDistance: <float>,
  12409. * farDistance: <float>,
  12410. *
  12411. * skinning: <bool>,
  12412. * morphTargets: <bool>,
  12413. *
  12414. * map: new THREE.Texture( <Image> ),
  12415. *
  12416. * alphaMap: new THREE.Texture( <Image> ),
  12417. *
  12418. * displacementMap: new THREE.Texture( <Image> ),
  12419. * displacementScale: <float>,
  12420. * displacementBias: <float>
  12421. *
  12422. * }
  12423. */
  12424. function MeshDistanceMaterial(parameters) {
  12425. Material.call(this);
  12426. this.type = 'MeshDistanceMaterial';
  12427. this.referencePosition = new Vector3();
  12428. this.nearDistance = 1;
  12429. this.farDistance = 1000;
  12430. this.skinning = false;
  12431. this.morphTargets = false;
  12432. this.map = null;
  12433. this.alphaMap = null;
  12434. this.displacementMap = null;
  12435. this.displacementScale = 1;
  12436. this.displacementBias = 0;
  12437. this.fog = false;
  12438. this.setValues(parameters);
  12439. }
  12440. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  12441. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12442. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12443. MeshDistanceMaterial.prototype.copy = function (source) {
  12444. Material.prototype.copy.call(this, source);
  12445. this.referencePosition.copy(source.referencePosition);
  12446. this.nearDistance = source.nearDistance;
  12447. this.farDistance = source.farDistance;
  12448. this.skinning = source.skinning;
  12449. this.morphTargets = source.morphTargets;
  12450. this.map = source.map;
  12451. this.alphaMap = source.alphaMap;
  12452. this.displacementMap = source.displacementMap;
  12453. this.displacementScale = source.displacementScale;
  12454. this.displacementBias = source.displacementBias;
  12455. return this;
  12456. };
  12457. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  12458. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12459. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  12460. var _frustum = new Frustum();
  12461. var _shadowMapSize = new Vector2(),
  12462. _viewportSize = new Vector2(),
  12463. _viewport = new Vector4(),
  12464. _depthMaterials = [],
  12465. _distanceMaterials = [],
  12466. _materialCache = {};
  12467. var shadowSide = {
  12468. 0: BackSide,
  12469. 1: FrontSide,
  12470. 2: DoubleSide
  12471. };
  12472. var shadowMaterialVertical = new ShaderMaterial({
  12473. defines: {
  12474. SAMPLE_RATE: 2.0 / 8.0,
  12475. HALF_SAMPLE_RATE: 1.0 / 8.0
  12476. },
  12477. uniforms: {
  12478. shadow_pass: {
  12479. value: null
  12480. },
  12481. resolution: {
  12482. value: new Vector2()
  12483. },
  12484. radius: {
  12485. value: 4.0
  12486. }
  12487. },
  12488. vertexShader: vsm_vert,
  12489. fragmentShader: vsm_frag
  12490. });
  12491. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12492. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12493. var fullScreenTri = new BufferGeometry();
  12494. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12495. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12496. var scope = this;
  12497. this.enabled = false;
  12498. this.autoUpdate = true;
  12499. this.needsUpdate = false;
  12500. this.type = PCFShadowMap;
  12501. this.render = function (lights, scene, camera) {
  12502. if (scope.enabled === false) return;
  12503. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12504. if (lights.length === 0) return;
  12505. var currentRenderTarget = _renderer.getRenderTarget();
  12506. var activeCubeFace = _renderer.getActiveCubeFace();
  12507. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12508. var _state = _renderer.state; // Set GL state for depth map.
  12509. _state.setBlending(NoBlending);
  12510. _state.buffers.color.setClear(1, 1, 1, 1);
  12511. _state.buffers.depth.setTest(true);
  12512. _state.setScissorTest(false); // render depth map
  12513. for (var i = 0, il = lights.length; i < il; i++) {
  12514. var light = lights[i];
  12515. var shadow = light.shadow;
  12516. if (shadow === undefined) {
  12517. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12518. continue;
  12519. }
  12520. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12521. _shadowMapSize.copy(shadow.mapSize);
  12522. var shadowFrameExtents = shadow.getFrameExtents();
  12523. _shadowMapSize.multiply(shadowFrameExtents);
  12524. _viewportSize.copy(shadow.mapSize);
  12525. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12526. if (_shadowMapSize.x > maxTextureSize) {
  12527. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12528. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12529. shadow.mapSize.x = _viewportSize.x;
  12530. }
  12531. if (_shadowMapSize.y > maxTextureSize) {
  12532. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12533. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12534. shadow.mapSize.y = _viewportSize.y;
  12535. }
  12536. }
  12537. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12538. var pars = {
  12539. minFilter: LinearFilter,
  12540. magFilter: LinearFilter,
  12541. format: RGBAFormat
  12542. };
  12543. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12544. shadow.map.texture.name = light.name + '.shadowMap';
  12545. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12546. shadow.camera.updateProjectionMatrix();
  12547. }
  12548. if (shadow.map === null) {
  12549. var _pars = {
  12550. minFilter: NearestFilter,
  12551. magFilter: NearestFilter,
  12552. format: RGBAFormat
  12553. };
  12554. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12555. shadow.map.texture.name = light.name + '.shadowMap';
  12556. shadow.camera.updateProjectionMatrix();
  12557. }
  12558. _renderer.setRenderTarget(shadow.map);
  12559. _renderer.clear();
  12560. var viewportCount = shadow.getViewportCount();
  12561. for (var vp = 0; vp < viewportCount; vp++) {
  12562. var viewport = shadow.getViewport(vp);
  12563. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12564. _state.viewport(_viewport);
  12565. shadow.updateMatrices(light, vp);
  12566. _frustum = shadow.getFrustum();
  12567. renderObject(scene, camera, shadow.camera, light, this.type);
  12568. } // do blur pass for VSM
  12569. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12570. VSMPass(shadow, camera);
  12571. }
  12572. shadow.needsUpdate = false;
  12573. }
  12574. scope.needsUpdate = false;
  12575. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12576. };
  12577. function VSMPass(shadow, camera) {
  12578. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12579. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12580. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12581. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12582. _renderer.setRenderTarget(shadow.mapPass);
  12583. _renderer.clear();
  12584. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12585. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12586. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12587. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12588. _renderer.setRenderTarget(shadow.map);
  12589. _renderer.clear();
  12590. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12591. }
  12592. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12593. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12594. var material = _depthMaterials[index];
  12595. if (material === undefined) {
  12596. material = new MeshDepthMaterial({
  12597. depthPacking: RGBADepthPacking,
  12598. morphTargets: useMorphing,
  12599. skinning: useSkinning
  12600. });
  12601. _depthMaterials[index] = material;
  12602. }
  12603. return material;
  12604. }
  12605. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12606. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12607. var material = _distanceMaterials[index];
  12608. if (material === undefined) {
  12609. material = new MeshDistanceMaterial({
  12610. morphTargets: useMorphing,
  12611. skinning: useSkinning
  12612. });
  12613. _distanceMaterials[index] = material;
  12614. }
  12615. return material;
  12616. }
  12617. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12618. var result = null;
  12619. var getMaterialVariant = getDepthMaterialVariant;
  12620. var customMaterial = object.customDepthMaterial;
  12621. if (light.isPointLight === true) {
  12622. getMaterialVariant = getDistanceMaterialVariant;
  12623. customMaterial = object.customDistanceMaterial;
  12624. }
  12625. if (customMaterial === undefined) {
  12626. var useMorphing = false;
  12627. if (material.morphTargets === true) {
  12628. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12629. }
  12630. var useSkinning = false;
  12631. if (object.isSkinnedMesh === true) {
  12632. if (material.skinning === true) {
  12633. useSkinning = true;
  12634. } else {
  12635. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12636. }
  12637. }
  12638. var useInstancing = object.isInstancedMesh === true;
  12639. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12640. } else {
  12641. result = customMaterial;
  12642. }
  12643. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12644. // in this case we need a unique material instance reflecting the
  12645. // appropriate state
  12646. var keyA = result.uuid,
  12647. keyB = material.uuid;
  12648. var materialsForVariant = _materialCache[keyA];
  12649. if (materialsForVariant === undefined) {
  12650. materialsForVariant = {};
  12651. _materialCache[keyA] = materialsForVariant;
  12652. }
  12653. var cachedMaterial = materialsForVariant[keyB];
  12654. if (cachedMaterial === undefined) {
  12655. cachedMaterial = result.clone();
  12656. materialsForVariant[keyB] = cachedMaterial;
  12657. }
  12658. result = cachedMaterial;
  12659. }
  12660. result.visible = material.visible;
  12661. result.wireframe = material.wireframe;
  12662. if (type === VSMShadowMap) {
  12663. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12664. } else {
  12665. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12666. }
  12667. result.clipShadows = material.clipShadows;
  12668. result.clippingPlanes = material.clippingPlanes;
  12669. result.clipIntersection = material.clipIntersection;
  12670. result.wireframeLinewidth = material.wireframeLinewidth;
  12671. result.linewidth = material.linewidth;
  12672. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12673. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12674. result.nearDistance = shadowCameraNear;
  12675. result.farDistance = shadowCameraFar;
  12676. }
  12677. return result;
  12678. }
  12679. function renderObject(object, camera, shadowCamera, light, type) {
  12680. if (object.visible === false) return;
  12681. var visible = object.layers.test(camera.layers);
  12682. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12683. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12684. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12685. var geometry = _objects.update(object);
  12686. var material = object.material;
  12687. if (Array.isArray(material)) {
  12688. var groups = geometry.groups;
  12689. for (var k = 0, kl = groups.length; k < kl; k++) {
  12690. var group = groups[k];
  12691. var groupMaterial = material[group.materialIndex];
  12692. if (groupMaterial && groupMaterial.visible) {
  12693. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12694. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12695. }
  12696. }
  12697. } else if (material.visible) {
  12698. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12699. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12700. }
  12701. }
  12702. }
  12703. var children = object.children;
  12704. for (var i = 0, l = children.length; i < l; i++) {
  12705. renderObject(children[i], camera, shadowCamera, light, type);
  12706. }
  12707. }
  12708. }
  12709. function WebGLState(gl, extensions, capabilities) {
  12710. var _equationToGL, _factorToGL;
  12711. var isWebGL2 = capabilities.isWebGL2;
  12712. function ColorBuffer() {
  12713. var locked = false;
  12714. var color = new Vector4();
  12715. var currentColorMask = null;
  12716. var currentColorClear = new Vector4(0, 0, 0, 0);
  12717. return {
  12718. setMask: function setMask(colorMask) {
  12719. if (currentColorMask !== colorMask && !locked) {
  12720. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12721. currentColorMask = colorMask;
  12722. }
  12723. },
  12724. setLocked: function setLocked(lock) {
  12725. locked = lock;
  12726. },
  12727. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12728. if (premultipliedAlpha === true) {
  12729. r *= a;
  12730. g *= a;
  12731. b *= a;
  12732. }
  12733. color.set(r, g, b, a);
  12734. if (currentColorClear.equals(color) === false) {
  12735. gl.clearColor(r, g, b, a);
  12736. currentColorClear.copy(color);
  12737. }
  12738. },
  12739. reset: function reset() {
  12740. locked = false;
  12741. currentColorMask = null;
  12742. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12743. }
  12744. };
  12745. }
  12746. function DepthBuffer() {
  12747. var locked = false;
  12748. var currentDepthMask = null;
  12749. var currentDepthFunc = null;
  12750. var currentDepthClear = null;
  12751. return {
  12752. setTest: function setTest(depthTest) {
  12753. if (depthTest) {
  12754. enable(2929);
  12755. } else {
  12756. disable(2929);
  12757. }
  12758. },
  12759. setMask: function setMask(depthMask) {
  12760. if (currentDepthMask !== depthMask && !locked) {
  12761. gl.depthMask(depthMask);
  12762. currentDepthMask = depthMask;
  12763. }
  12764. },
  12765. setFunc: function setFunc(depthFunc) {
  12766. if (currentDepthFunc !== depthFunc) {
  12767. if (depthFunc) {
  12768. switch (depthFunc) {
  12769. case NeverDepth:
  12770. gl.depthFunc(512);
  12771. break;
  12772. case AlwaysDepth:
  12773. gl.depthFunc(519);
  12774. break;
  12775. case LessDepth:
  12776. gl.depthFunc(513);
  12777. break;
  12778. case LessEqualDepth:
  12779. gl.depthFunc(515);
  12780. break;
  12781. case EqualDepth:
  12782. gl.depthFunc(514);
  12783. break;
  12784. case GreaterEqualDepth:
  12785. gl.depthFunc(518);
  12786. break;
  12787. case GreaterDepth:
  12788. gl.depthFunc(516);
  12789. break;
  12790. case NotEqualDepth:
  12791. gl.depthFunc(517);
  12792. break;
  12793. default:
  12794. gl.depthFunc(515);
  12795. }
  12796. } else {
  12797. gl.depthFunc(515);
  12798. }
  12799. currentDepthFunc = depthFunc;
  12800. }
  12801. },
  12802. setLocked: function setLocked(lock) {
  12803. locked = lock;
  12804. },
  12805. setClear: function setClear(depth) {
  12806. if (currentDepthClear !== depth) {
  12807. gl.clearDepth(depth);
  12808. currentDepthClear = depth;
  12809. }
  12810. },
  12811. reset: function reset() {
  12812. locked = false;
  12813. currentDepthMask = null;
  12814. currentDepthFunc = null;
  12815. currentDepthClear = null;
  12816. }
  12817. };
  12818. }
  12819. function StencilBuffer() {
  12820. var locked = false;
  12821. var currentStencilMask = null;
  12822. var currentStencilFunc = null;
  12823. var currentStencilRef = null;
  12824. var currentStencilFuncMask = null;
  12825. var currentStencilFail = null;
  12826. var currentStencilZFail = null;
  12827. var currentStencilZPass = null;
  12828. var currentStencilClear = null;
  12829. return {
  12830. setTest: function setTest(stencilTest) {
  12831. if (!locked) {
  12832. if (stencilTest) {
  12833. enable(2960);
  12834. } else {
  12835. disable(2960);
  12836. }
  12837. }
  12838. },
  12839. setMask: function setMask(stencilMask) {
  12840. if (currentStencilMask !== stencilMask && !locked) {
  12841. gl.stencilMask(stencilMask);
  12842. currentStencilMask = stencilMask;
  12843. }
  12844. },
  12845. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12846. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12847. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12848. currentStencilFunc = stencilFunc;
  12849. currentStencilRef = stencilRef;
  12850. currentStencilFuncMask = stencilMask;
  12851. }
  12852. },
  12853. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12854. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12855. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12856. currentStencilFail = stencilFail;
  12857. currentStencilZFail = stencilZFail;
  12858. currentStencilZPass = stencilZPass;
  12859. }
  12860. },
  12861. setLocked: function setLocked(lock) {
  12862. locked = lock;
  12863. },
  12864. setClear: function setClear(stencil) {
  12865. if (currentStencilClear !== stencil) {
  12866. gl.clearStencil(stencil);
  12867. currentStencilClear = stencil;
  12868. }
  12869. },
  12870. reset: function reset() {
  12871. locked = false;
  12872. currentStencilMask = null;
  12873. currentStencilFunc = null;
  12874. currentStencilRef = null;
  12875. currentStencilFuncMask = null;
  12876. currentStencilFail = null;
  12877. currentStencilZFail = null;
  12878. currentStencilZPass = null;
  12879. currentStencilClear = null;
  12880. }
  12881. };
  12882. } //
  12883. var colorBuffer = new ColorBuffer();
  12884. var depthBuffer = new DepthBuffer();
  12885. var stencilBuffer = new StencilBuffer();
  12886. var enabledCapabilities = {};
  12887. var currentProgram = null;
  12888. var currentBlendingEnabled = false;
  12889. var currentBlending = null;
  12890. var currentBlendEquation = null;
  12891. var currentBlendSrc = null;
  12892. var currentBlendDst = null;
  12893. var currentBlendEquationAlpha = null;
  12894. var currentBlendSrcAlpha = null;
  12895. var currentBlendDstAlpha = null;
  12896. var currentPremultipledAlpha = false;
  12897. var currentFlipSided = null;
  12898. var currentCullFace = null;
  12899. var currentLineWidth = null;
  12900. var currentPolygonOffsetFactor = null;
  12901. var currentPolygonOffsetUnits = null;
  12902. var maxTextures = gl.getParameter(35661);
  12903. var lineWidthAvailable = false;
  12904. var version = 0;
  12905. var glVersion = gl.getParameter(7938);
  12906. if (glVersion.indexOf('WebGL') !== -1) {
  12907. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12908. lineWidthAvailable = version >= 1.0;
  12909. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12910. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12911. lineWidthAvailable = version >= 2.0;
  12912. }
  12913. var currentTextureSlot = null;
  12914. var currentBoundTextures = {};
  12915. var currentScissor = new Vector4();
  12916. var currentViewport = new Vector4();
  12917. function createTexture(type, target, count) {
  12918. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12919. var texture = gl.createTexture();
  12920. gl.bindTexture(type, texture);
  12921. gl.texParameteri(type, 10241, 9728);
  12922. gl.texParameteri(type, 10240, 9728);
  12923. for (var i = 0; i < count; i++) {
  12924. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12925. }
  12926. return texture;
  12927. }
  12928. var emptyTextures = {};
  12929. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12930. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12931. colorBuffer.setClear(0, 0, 0, 1);
  12932. depthBuffer.setClear(1);
  12933. stencilBuffer.setClear(0);
  12934. enable(2929);
  12935. depthBuffer.setFunc(LessEqualDepth);
  12936. setFlipSided(false);
  12937. setCullFace(CullFaceBack);
  12938. enable(2884);
  12939. setBlending(NoBlending); //
  12940. function enable(id) {
  12941. if (enabledCapabilities[id] !== true) {
  12942. gl.enable(id);
  12943. enabledCapabilities[id] = true;
  12944. }
  12945. }
  12946. function disable(id) {
  12947. if (enabledCapabilities[id] !== false) {
  12948. gl.disable(id);
  12949. enabledCapabilities[id] = false;
  12950. }
  12951. }
  12952. function useProgram(program) {
  12953. if (currentProgram !== program) {
  12954. gl.useProgram(program);
  12955. currentProgram = program;
  12956. return true;
  12957. }
  12958. return false;
  12959. }
  12960. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12961. if (isWebGL2) {
  12962. equationToGL[MinEquation] = 32775;
  12963. equationToGL[MaxEquation] = 32776;
  12964. } else {
  12965. var extension = extensions.get('EXT_blend_minmax');
  12966. if (extension !== null) {
  12967. equationToGL[MinEquation] = extension.MIN_EXT;
  12968. equationToGL[MaxEquation] = extension.MAX_EXT;
  12969. }
  12970. }
  12971. 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);
  12972. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12973. if (blending === NoBlending) {
  12974. if (currentBlendingEnabled === true) {
  12975. disable(3042);
  12976. currentBlendingEnabled = false;
  12977. }
  12978. return;
  12979. }
  12980. if (currentBlendingEnabled === false) {
  12981. enable(3042);
  12982. currentBlendingEnabled = true;
  12983. }
  12984. if (blending !== CustomBlending) {
  12985. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12986. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12987. gl.blendEquation(32774);
  12988. currentBlendEquation = AddEquation;
  12989. currentBlendEquationAlpha = AddEquation;
  12990. }
  12991. if (premultipliedAlpha) {
  12992. switch (blending) {
  12993. case NormalBlending:
  12994. gl.blendFuncSeparate(1, 771, 1, 771);
  12995. break;
  12996. case AdditiveBlending:
  12997. gl.blendFunc(1, 1);
  12998. break;
  12999. case SubtractiveBlending:
  13000. gl.blendFuncSeparate(0, 0, 769, 771);
  13001. break;
  13002. case MultiplyBlending:
  13003. gl.blendFuncSeparate(0, 768, 0, 770);
  13004. break;
  13005. default:
  13006. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13007. break;
  13008. }
  13009. } else {
  13010. switch (blending) {
  13011. case NormalBlending:
  13012. gl.blendFuncSeparate(770, 771, 1, 771);
  13013. break;
  13014. case AdditiveBlending:
  13015. gl.blendFunc(770, 1);
  13016. break;
  13017. case SubtractiveBlending:
  13018. gl.blendFunc(0, 769);
  13019. break;
  13020. case MultiplyBlending:
  13021. gl.blendFunc(0, 768);
  13022. break;
  13023. default:
  13024. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13025. break;
  13026. }
  13027. }
  13028. currentBlendSrc = null;
  13029. currentBlendDst = null;
  13030. currentBlendSrcAlpha = null;
  13031. currentBlendDstAlpha = null;
  13032. currentBlending = blending;
  13033. currentPremultipledAlpha = premultipliedAlpha;
  13034. }
  13035. return;
  13036. } // custom blending
  13037. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13038. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13039. blendDstAlpha = blendDstAlpha || blendDst;
  13040. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  13041. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  13042. currentBlendEquation = blendEquation;
  13043. currentBlendEquationAlpha = blendEquationAlpha;
  13044. }
  13045. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  13046. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  13047. currentBlendSrc = blendSrc;
  13048. currentBlendDst = blendDst;
  13049. currentBlendSrcAlpha = blendSrcAlpha;
  13050. currentBlendDstAlpha = blendDstAlpha;
  13051. }
  13052. currentBlending = blending;
  13053. currentPremultipledAlpha = null;
  13054. }
  13055. function setMaterial(material, frontFaceCW) {
  13056. material.side === DoubleSide ? disable(2884) : enable(2884);
  13057. var flipSided = material.side === BackSide;
  13058. if (frontFaceCW) flipSided = !flipSided;
  13059. setFlipSided(flipSided);
  13060. 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);
  13061. depthBuffer.setFunc(material.depthFunc);
  13062. depthBuffer.setTest(material.depthTest);
  13063. depthBuffer.setMask(material.depthWrite);
  13064. colorBuffer.setMask(material.colorWrite);
  13065. var stencilWrite = material.stencilWrite;
  13066. stencilBuffer.setTest(stencilWrite);
  13067. if (stencilWrite) {
  13068. stencilBuffer.setMask(material.stencilWriteMask);
  13069. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  13070. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  13071. }
  13072. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  13073. } //
  13074. function setFlipSided(flipSided) {
  13075. if (currentFlipSided !== flipSided) {
  13076. if (flipSided) {
  13077. gl.frontFace(2304);
  13078. } else {
  13079. gl.frontFace(2305);
  13080. }
  13081. currentFlipSided = flipSided;
  13082. }
  13083. }
  13084. function setCullFace(cullFace) {
  13085. if (cullFace !== CullFaceNone) {
  13086. enable(2884);
  13087. if (cullFace !== currentCullFace) {
  13088. if (cullFace === CullFaceBack) {
  13089. gl.cullFace(1029);
  13090. } else if (cullFace === CullFaceFront) {
  13091. gl.cullFace(1028);
  13092. } else {
  13093. gl.cullFace(1032);
  13094. }
  13095. }
  13096. } else {
  13097. disable(2884);
  13098. }
  13099. currentCullFace = cullFace;
  13100. }
  13101. function setLineWidth(width) {
  13102. if (width !== currentLineWidth) {
  13103. if (lineWidthAvailable) gl.lineWidth(width);
  13104. currentLineWidth = width;
  13105. }
  13106. }
  13107. function setPolygonOffset(polygonOffset, factor, units) {
  13108. if (polygonOffset) {
  13109. enable(32823);
  13110. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  13111. gl.polygonOffset(factor, units);
  13112. currentPolygonOffsetFactor = factor;
  13113. currentPolygonOffsetUnits = units;
  13114. }
  13115. } else {
  13116. disable(32823);
  13117. }
  13118. }
  13119. function setScissorTest(scissorTest) {
  13120. if (scissorTest) {
  13121. enable(3089);
  13122. } else {
  13123. disable(3089);
  13124. }
  13125. } // texture
  13126. function activeTexture(webglSlot) {
  13127. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  13128. if (currentTextureSlot !== webglSlot) {
  13129. gl.activeTexture(webglSlot);
  13130. currentTextureSlot = webglSlot;
  13131. }
  13132. }
  13133. function bindTexture(webglType, webglTexture) {
  13134. if (currentTextureSlot === null) {
  13135. activeTexture();
  13136. }
  13137. var boundTexture = currentBoundTextures[currentTextureSlot];
  13138. if (boundTexture === undefined) {
  13139. boundTexture = {
  13140. type: undefined,
  13141. texture: undefined
  13142. };
  13143. currentBoundTextures[currentTextureSlot] = boundTexture;
  13144. }
  13145. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  13146. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  13147. boundTexture.type = webglType;
  13148. boundTexture.texture = webglTexture;
  13149. }
  13150. }
  13151. function unbindTexture() {
  13152. var boundTexture = currentBoundTextures[currentTextureSlot];
  13153. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  13154. gl.bindTexture(boundTexture.type, null);
  13155. boundTexture.type = undefined;
  13156. boundTexture.texture = undefined;
  13157. }
  13158. }
  13159. function compressedTexImage2D() {
  13160. try {
  13161. gl.compressedTexImage2D.apply(gl, arguments);
  13162. } catch (error) {
  13163. console.error('THREE.WebGLState:', error);
  13164. }
  13165. }
  13166. function texImage2D() {
  13167. try {
  13168. gl.texImage2D.apply(gl, arguments);
  13169. } catch (error) {
  13170. console.error('THREE.WebGLState:', error);
  13171. }
  13172. }
  13173. function texImage3D() {
  13174. try {
  13175. gl.texImage3D.apply(gl, arguments);
  13176. } catch (error) {
  13177. console.error('THREE.WebGLState:', error);
  13178. }
  13179. } //
  13180. function scissor(scissor) {
  13181. if (currentScissor.equals(scissor) === false) {
  13182. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  13183. currentScissor.copy(scissor);
  13184. }
  13185. }
  13186. function viewport(viewport) {
  13187. if (currentViewport.equals(viewport) === false) {
  13188. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  13189. currentViewport.copy(viewport);
  13190. }
  13191. } //
  13192. function reset() {
  13193. // reset state
  13194. gl.disable(3042);
  13195. gl.disable(2884);
  13196. gl.disable(2929);
  13197. gl.disable(32823);
  13198. gl.disable(3089);
  13199. gl.disable(2960);
  13200. gl.blendEquation(32774);
  13201. gl.blendFunc(1, 0);
  13202. gl.blendFuncSeparate(1, 0, 1, 0);
  13203. gl.colorMask(true, true, true, true);
  13204. gl.clearColor(0, 0, 0, 0);
  13205. gl.depthMask(true);
  13206. gl.depthFunc(513);
  13207. gl.clearDepth(1);
  13208. gl.stencilMask(0xffffffff);
  13209. gl.stencilFunc(519, 0, 1);
  13210. gl.stencilOp(7680, 7680, 7680);
  13211. gl.clearStencil(0);
  13212. gl.cullFace(1029);
  13213. gl.frontFace(2305);
  13214. gl.polygonOffset(0, 0); // reset internals
  13215. enabledCapabilities = {};
  13216. currentTextureSlot = null;
  13217. currentBoundTextures = {};
  13218. currentProgram = null;
  13219. currentBlendingEnabled = false;
  13220. currentBlending = null;
  13221. currentBlendEquation = null;
  13222. currentBlendSrc = null;
  13223. currentBlendDst = null;
  13224. currentBlendEquationAlpha = null;
  13225. currentBlendSrcAlpha = null;
  13226. currentBlendDstAlpha = null;
  13227. currentPremultipledAlpha = false;
  13228. currentFlipSided = null;
  13229. currentCullFace = null;
  13230. currentLineWidth = null;
  13231. currentPolygonOffsetFactor = null;
  13232. currentPolygonOffsetUnits = null;
  13233. colorBuffer.reset();
  13234. depthBuffer.reset();
  13235. stencilBuffer.reset();
  13236. }
  13237. return {
  13238. buffers: {
  13239. color: colorBuffer,
  13240. depth: depthBuffer,
  13241. stencil: stencilBuffer
  13242. },
  13243. enable: enable,
  13244. disable: disable,
  13245. useProgram: useProgram,
  13246. setBlending: setBlending,
  13247. setMaterial: setMaterial,
  13248. setFlipSided: setFlipSided,
  13249. setCullFace: setCullFace,
  13250. setLineWidth: setLineWidth,
  13251. setPolygonOffset: setPolygonOffset,
  13252. setScissorTest: setScissorTest,
  13253. activeTexture: activeTexture,
  13254. bindTexture: bindTexture,
  13255. unbindTexture: unbindTexture,
  13256. compressedTexImage2D: compressedTexImage2D,
  13257. texImage2D: texImage2D,
  13258. texImage3D: texImage3D,
  13259. scissor: scissor,
  13260. viewport: viewport,
  13261. reset: reset
  13262. };
  13263. }
  13264. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  13265. var _wrappingToGL, _filterToGL;
  13266. var isWebGL2 = capabilities.isWebGL2;
  13267. var maxTextures = capabilities.maxTextures;
  13268. var maxCubemapSize = capabilities.maxCubemapSize;
  13269. var maxTextureSize = capabilities.maxTextureSize;
  13270. var maxSamples = capabilities.maxSamples;
  13271. var _videoTextures = new WeakMap();
  13272. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13273. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13274. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13275. var useOffscreenCanvas = false;
  13276. try {
  13277. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  13278. } catch (err) {// Ignore any errors
  13279. }
  13280. function createCanvas(width, height) {
  13281. // Use OffscreenCanvas when available. Specially needed in web workers
  13282. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  13283. }
  13284. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  13285. var scale = 1; // handle case if texture exceeds max size
  13286. if (image.width > maxSize || image.height > maxSize) {
  13287. scale = maxSize / Math.max(image.width, image.height);
  13288. } // only perform resize if necessary
  13289. if (scale < 1 || needsPowerOfTwo === true) {
  13290. // only perform resize for certain image types
  13291. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  13292. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13293. var width = floor(scale * image.width);
  13294. var height = floor(scale * image.height);
  13295. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  13296. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  13297. canvas.width = width;
  13298. canvas.height = height;
  13299. var context = canvas.getContext('2d');
  13300. context.drawImage(image, 0, 0, width, height);
  13301. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  13302. return canvas;
  13303. } else {
  13304. if ('data' in image) {
  13305. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  13306. }
  13307. return image;
  13308. }
  13309. }
  13310. return image;
  13311. }
  13312. function isPowerOfTwo(image) {
  13313. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  13314. }
  13315. function textureNeedsPowerOfTwo(texture) {
  13316. if (isWebGL2) return false;
  13317. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13318. }
  13319. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  13320. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13321. }
  13322. function generateMipmap(target, texture, width, height) {
  13323. _gl.generateMipmap(target);
  13324. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13325. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  13326. }
  13327. function getInternalFormat(internalFormatName, glFormat, glType) {
  13328. if (isWebGL2 === false) return glFormat;
  13329. if (internalFormatName !== null) {
  13330. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  13331. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  13332. }
  13333. var internalFormat = glFormat;
  13334. if (glFormat === 6403) {
  13335. if (glType === 5126) internalFormat = 33326;
  13336. if (glType === 5131) internalFormat = 33325;
  13337. if (glType === 5121) internalFormat = 33321;
  13338. }
  13339. if (glFormat === 6407) {
  13340. if (glType === 5126) internalFormat = 34837;
  13341. if (glType === 5131) internalFormat = 34843;
  13342. if (glType === 5121) internalFormat = 32849;
  13343. }
  13344. if (glFormat === 6408) {
  13345. if (glType === 5126) internalFormat = 34836;
  13346. if (glType === 5131) internalFormat = 34842;
  13347. if (glType === 5121) internalFormat = 32856;
  13348. }
  13349. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  13350. extensions.get('EXT_color_buffer_float');
  13351. }
  13352. return internalFormat;
  13353. } // Fallback filters for non-power-of-2 textures
  13354. function filterFallback(f) {
  13355. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  13356. return 9728;
  13357. }
  13358. return 9729;
  13359. } //
  13360. function onTextureDispose(event) {
  13361. var texture = event.target;
  13362. texture.removeEventListener('dispose', onTextureDispose);
  13363. deallocateTexture(texture);
  13364. if (texture.isVideoTexture) {
  13365. _videoTextures.delete(texture);
  13366. }
  13367. info.memory.textures--;
  13368. }
  13369. function onRenderTargetDispose(event) {
  13370. var renderTarget = event.target;
  13371. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  13372. deallocateRenderTarget(renderTarget);
  13373. info.memory.textures--;
  13374. } //
  13375. function deallocateTexture(texture) {
  13376. var textureProperties = properties.get(texture);
  13377. if (textureProperties.__webglInit === undefined) return;
  13378. _gl.deleteTexture(textureProperties.__webglTexture);
  13379. properties.remove(texture);
  13380. }
  13381. function deallocateRenderTarget(renderTarget) {
  13382. var texture = renderTarget.texture;
  13383. var renderTargetProperties = properties.get(renderTarget);
  13384. var textureProperties = properties.get(texture);
  13385. if (!renderTarget) return;
  13386. if (textureProperties.__webglTexture !== undefined) {
  13387. _gl.deleteTexture(textureProperties.__webglTexture);
  13388. }
  13389. if (renderTarget.depthTexture) {
  13390. renderTarget.depthTexture.dispose();
  13391. }
  13392. if (renderTarget.isWebGLCubeRenderTarget) {
  13393. for (var i = 0; i < 6; i++) {
  13394. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  13395. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  13396. }
  13397. } else {
  13398. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  13399. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  13400. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  13401. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  13402. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  13403. }
  13404. properties.remove(texture);
  13405. properties.remove(renderTarget);
  13406. } //
  13407. var textureUnits = 0;
  13408. function resetTextureUnits() {
  13409. textureUnits = 0;
  13410. }
  13411. function allocateTextureUnit() {
  13412. var textureUnit = textureUnits;
  13413. if (textureUnit >= maxTextures) {
  13414. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  13415. }
  13416. textureUnits += 1;
  13417. return textureUnit;
  13418. } //
  13419. function setTexture2D(texture, slot) {
  13420. var textureProperties = properties.get(texture);
  13421. if (texture.isVideoTexture) updateVideoTexture(texture);
  13422. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13423. var image = texture.image;
  13424. if (image === undefined) {
  13425. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  13426. } else if (image.complete === false) {
  13427. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  13428. } else {
  13429. uploadTexture(textureProperties, texture, slot);
  13430. return;
  13431. }
  13432. }
  13433. state.activeTexture(33984 + slot);
  13434. state.bindTexture(3553, textureProperties.__webglTexture);
  13435. }
  13436. function setTexture2DArray(texture, slot) {
  13437. var textureProperties = properties.get(texture);
  13438. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13439. uploadTexture(textureProperties, texture, slot);
  13440. return;
  13441. }
  13442. state.activeTexture(33984 + slot);
  13443. state.bindTexture(35866, textureProperties.__webglTexture);
  13444. }
  13445. function setTexture3D(texture, slot) {
  13446. var textureProperties = properties.get(texture);
  13447. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13448. uploadTexture(textureProperties, texture, slot);
  13449. return;
  13450. }
  13451. state.activeTexture(33984 + slot);
  13452. state.bindTexture(32879, textureProperties.__webglTexture);
  13453. }
  13454. function setTextureCube(texture, slot) {
  13455. var textureProperties = properties.get(texture);
  13456. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13457. uploadCubeTexture(textureProperties, texture, slot);
  13458. return;
  13459. }
  13460. state.activeTexture(33984 + slot);
  13461. state.bindTexture(34067, textureProperties.__webglTexture);
  13462. }
  13463. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  13464. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  13465. function setTextureParameters(textureType, texture, supportsMips) {
  13466. if (supportsMips) {
  13467. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  13468. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  13469. if (textureType === 32879 || textureType === 35866) {
  13470. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  13471. }
  13472. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  13473. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  13474. } else {
  13475. _gl.texParameteri(textureType, 10242, 33071);
  13476. _gl.texParameteri(textureType, 10243, 33071);
  13477. if (textureType === 32879 || textureType === 35866) {
  13478. _gl.texParameteri(textureType, 32882, 33071);
  13479. }
  13480. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  13481. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  13482. }
  13483. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  13484. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  13485. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  13486. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  13487. }
  13488. }
  13489. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  13490. var extension = extensions.get('EXT_texture_filter_anisotropic');
  13491. if (texture.type === FloatType && extensions.has('OES_texture_float_linear') === false) return; // verify extension for WebGL 1 and WebGL 2
  13492. if (isWebGL2 === false && texture.type === HalfFloatType && extensions.has('OES_texture_half_float_linear') === false) return; // verify extension for WebGL 1 only
  13493. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  13494. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  13495. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  13496. }
  13497. }
  13498. }
  13499. function initTexture(textureProperties, texture) {
  13500. if (textureProperties.__webglInit === undefined) {
  13501. textureProperties.__webglInit = true;
  13502. texture.addEventListener('dispose', onTextureDispose);
  13503. textureProperties.__webglTexture = _gl.createTexture();
  13504. info.memory.textures++;
  13505. }
  13506. }
  13507. function uploadTexture(textureProperties, texture, slot) {
  13508. var textureType = 3553;
  13509. if (texture.isDataTexture2DArray) textureType = 35866;
  13510. if (texture.isDataTexture3D) textureType = 32879;
  13511. initTexture(textureProperties, texture);
  13512. state.activeTexture(33984 + slot);
  13513. state.bindTexture(textureType, textureProperties.__webglTexture);
  13514. _gl.pixelStorei(37440, texture.flipY);
  13515. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13516. _gl.pixelStorei(3317, texture.unpackAlignment);
  13517. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13518. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13519. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13520. glFormat = utils.convert(texture.format);
  13521. var glType = utils.convert(texture.type),
  13522. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13523. setTextureParameters(textureType, texture, supportsMips);
  13524. var mipmap;
  13525. var mipmaps = texture.mipmaps;
  13526. if (texture.isDepthTexture) {
  13527. // populate depth texture with dummy data
  13528. glInternalFormat = 6402;
  13529. if (isWebGL2) {
  13530. if (texture.type === FloatType) {
  13531. glInternalFormat = 36012;
  13532. } else if (texture.type === UnsignedIntType) {
  13533. glInternalFormat = 33190;
  13534. } else if (texture.type === UnsignedInt248Type) {
  13535. glInternalFormat = 35056;
  13536. } else {
  13537. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13538. }
  13539. } else {
  13540. if (texture.type === FloatType) {
  13541. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13542. }
  13543. } // validation checks for WebGL 1
  13544. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13545. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13546. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13547. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13548. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13549. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13550. texture.type = UnsignedShortType;
  13551. glType = utils.convert(texture.type);
  13552. }
  13553. }
  13554. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13555. // Depth stencil textures need the DEPTH_STENCIL internal format
  13556. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13557. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13558. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13559. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13560. if (texture.type !== UnsignedInt248Type) {
  13561. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13562. texture.type = UnsignedInt248Type;
  13563. glType = utils.convert(texture.type);
  13564. }
  13565. } //
  13566. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13567. } else if (texture.isDataTexture) {
  13568. // use manually created mipmaps if available
  13569. // if there are no manual mipmaps
  13570. // set 0 level mipmap and then use GL to generate other mipmap levels
  13571. if (mipmaps.length > 0 && supportsMips) {
  13572. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13573. mipmap = mipmaps[i];
  13574. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13575. }
  13576. texture.generateMipmaps = false;
  13577. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13578. } else {
  13579. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13580. textureProperties.__maxMipLevel = 0;
  13581. }
  13582. } else if (texture.isCompressedTexture) {
  13583. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13584. mipmap = mipmaps[_i];
  13585. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13586. if (glFormat !== null) {
  13587. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13588. } else {
  13589. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13590. }
  13591. } else {
  13592. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13593. }
  13594. }
  13595. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13596. } else if (texture.isDataTexture2DArray) {
  13597. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13598. textureProperties.__maxMipLevel = 0;
  13599. } else if (texture.isDataTexture3D) {
  13600. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13601. textureProperties.__maxMipLevel = 0;
  13602. } else {
  13603. // regular Texture (image, video, canvas)
  13604. // use manually created mipmaps if available
  13605. // if there are no manual mipmaps
  13606. // set 0 level mipmap and then use GL to generate other mipmap levels
  13607. if (mipmaps.length > 0 && supportsMips) {
  13608. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13609. mipmap = mipmaps[_i2];
  13610. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13611. }
  13612. texture.generateMipmaps = false;
  13613. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13614. } else {
  13615. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13616. textureProperties.__maxMipLevel = 0;
  13617. }
  13618. }
  13619. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13620. generateMipmap(textureType, texture, image.width, image.height);
  13621. }
  13622. textureProperties.__version = texture.version;
  13623. if (texture.onUpdate) texture.onUpdate(texture);
  13624. }
  13625. function uploadCubeTexture(textureProperties, texture, slot) {
  13626. if (texture.image.length !== 6) return;
  13627. initTexture(textureProperties, texture);
  13628. state.activeTexture(33984 + slot);
  13629. state.bindTexture(34067, textureProperties.__webglTexture);
  13630. _gl.pixelStorei(37440, texture.flipY);
  13631. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13632. _gl.pixelStorei(3317, texture.unpackAlignment);
  13633. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13634. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13635. var cubeImage = [];
  13636. for (var i = 0; i < 6; i++) {
  13637. if (!isCompressed && !isDataTexture) {
  13638. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13639. } else {
  13640. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13641. }
  13642. }
  13643. var image = cubeImage[0],
  13644. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13645. glFormat = utils.convert(texture.format),
  13646. glType = utils.convert(texture.type),
  13647. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13648. setTextureParameters(34067, texture, supportsMips);
  13649. var mipmaps;
  13650. if (isCompressed) {
  13651. for (var _i3 = 0; _i3 < 6; _i3++) {
  13652. mipmaps = cubeImage[_i3].mipmaps;
  13653. for (var j = 0; j < mipmaps.length; j++) {
  13654. var mipmap = mipmaps[j];
  13655. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13656. if (glFormat !== null) {
  13657. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13658. } else {
  13659. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13660. }
  13661. } else {
  13662. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13663. }
  13664. }
  13665. }
  13666. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13667. } else {
  13668. mipmaps = texture.mipmaps;
  13669. for (var _i4 = 0; _i4 < 6; _i4++) {
  13670. if (isDataTexture) {
  13671. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13672. for (var _j = 0; _j < mipmaps.length; _j++) {
  13673. var _mipmap = mipmaps[_j];
  13674. var mipmapImage = _mipmap.image[_i4].image;
  13675. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13676. }
  13677. } else {
  13678. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13679. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13680. var _mipmap2 = mipmaps[_j2];
  13681. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13682. }
  13683. }
  13684. }
  13685. textureProperties.__maxMipLevel = mipmaps.length;
  13686. }
  13687. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13688. // We assume images for cube map have the same size.
  13689. generateMipmap(34067, texture, image.width, image.height);
  13690. }
  13691. textureProperties.__version = texture.version;
  13692. if (texture.onUpdate) texture.onUpdate(texture);
  13693. } // Render targets
  13694. // Setup storage for target texture and bind it to correct framebuffer
  13695. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13696. var texture = renderTarget.texture;
  13697. var glFormat = utils.convert(texture.format);
  13698. var glType = utils.convert(texture.type);
  13699. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13700. if (textureTarget === 32879 || textureTarget === 35866) {
  13701. state.texImage3D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null);
  13702. } else {
  13703. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13704. }
  13705. _gl.bindFramebuffer(36160, framebuffer);
  13706. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(texture).__webglTexture, 0);
  13707. _gl.bindFramebuffer(36160, null);
  13708. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13709. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13710. _gl.bindRenderbuffer(36161, renderbuffer);
  13711. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13712. var glInternalFormat = 33189;
  13713. if (isMultisample) {
  13714. var depthTexture = renderTarget.depthTexture;
  13715. if (depthTexture && depthTexture.isDepthTexture) {
  13716. if (depthTexture.type === FloatType) {
  13717. glInternalFormat = 36012;
  13718. } else if (depthTexture.type === UnsignedIntType) {
  13719. glInternalFormat = 33190;
  13720. }
  13721. }
  13722. var samples = getRenderTargetSamples(renderTarget);
  13723. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13724. } else {
  13725. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13726. }
  13727. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13728. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13729. if (isMultisample) {
  13730. var _samples = getRenderTargetSamples(renderTarget);
  13731. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13732. } else {
  13733. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13734. }
  13735. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13736. } else {
  13737. var texture = renderTarget.texture;
  13738. var glFormat = utils.convert(texture.format);
  13739. var glType = utils.convert(texture.type);
  13740. var _glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13741. if (isMultisample) {
  13742. var _samples2 = getRenderTargetSamples(renderTarget);
  13743. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13744. } else {
  13745. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13746. }
  13747. }
  13748. _gl.bindRenderbuffer(36161, null);
  13749. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13750. function setupDepthTexture(framebuffer, renderTarget) {
  13751. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13752. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13753. _gl.bindFramebuffer(36160, framebuffer);
  13754. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13755. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13756. } // upload an empty depth texture with framebuffer size
  13757. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13758. renderTarget.depthTexture.image.width = renderTarget.width;
  13759. renderTarget.depthTexture.image.height = renderTarget.height;
  13760. renderTarget.depthTexture.needsUpdate = true;
  13761. }
  13762. setTexture2D(renderTarget.depthTexture, 0);
  13763. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13764. if (renderTarget.depthTexture.format === DepthFormat) {
  13765. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13766. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13767. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13768. } else {
  13769. throw new Error('Unknown depthTexture format');
  13770. }
  13771. } // Setup GL resources for a non-texture depth buffer
  13772. function setupDepthRenderbuffer(renderTarget) {
  13773. var renderTargetProperties = properties.get(renderTarget);
  13774. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13775. if (renderTarget.depthTexture) {
  13776. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13777. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13778. } else {
  13779. if (isCube) {
  13780. renderTargetProperties.__webglDepthbuffer = [];
  13781. for (var i = 0; i < 6; i++) {
  13782. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13783. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13784. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13785. }
  13786. } else {
  13787. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13788. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13789. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13790. }
  13791. }
  13792. _gl.bindFramebuffer(36160, null);
  13793. } // Set up GL resources for the render target
  13794. function setupRenderTarget(renderTarget) {
  13795. var texture = renderTarget.texture;
  13796. var renderTargetProperties = properties.get(renderTarget);
  13797. var textureProperties = properties.get(texture);
  13798. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13799. textureProperties.__webglTexture = _gl.createTexture();
  13800. info.memory.textures++;
  13801. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13802. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13803. var isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
  13804. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13805. if (isWebGL2 && texture.format === RGBFormat && (texture.type === FloatType || texture.type === HalfFloatType)) {
  13806. texture.format = RGBAFormat;
  13807. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13808. } // Setup framebuffer
  13809. if (isCube) {
  13810. renderTargetProperties.__webglFramebuffer = [];
  13811. for (var i = 0; i < 6; i++) {
  13812. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13813. }
  13814. } else {
  13815. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13816. if (isMultisample) {
  13817. if (isWebGL2) {
  13818. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13819. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13820. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13821. var glFormat = utils.convert(texture.format);
  13822. var glType = utils.convert(texture.type);
  13823. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13824. var samples = getRenderTargetSamples(renderTarget);
  13825. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13826. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13827. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13828. _gl.bindRenderbuffer(36161, null);
  13829. if (renderTarget.depthBuffer) {
  13830. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13831. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13832. }
  13833. _gl.bindFramebuffer(36160, null);
  13834. } else {
  13835. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13836. }
  13837. }
  13838. } // Setup color buffer
  13839. if (isCube) {
  13840. state.bindTexture(34067, textureProperties.__webglTexture);
  13841. setTextureParameters(34067, texture, supportsMips);
  13842. for (var _i5 = 0; _i5 < 6; _i5++) {
  13843. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13844. }
  13845. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13846. generateMipmap(34067, texture, renderTarget.width, renderTarget.height);
  13847. }
  13848. state.bindTexture(34067, null);
  13849. } else {
  13850. var glTextureType = 3553;
  13851. if (isRenderTarget3D) {
  13852. // Render targets containing layers, i.e: Texture 3D and 2d arrays
  13853. if (isWebGL2) {
  13854. var isTexture3D = texture.isDataTexture3D;
  13855. glTextureType = isTexture3D ? 32879 : 35866;
  13856. } else {
  13857. console.warn('THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.');
  13858. }
  13859. }
  13860. state.bindTexture(glTextureType, textureProperties.__webglTexture);
  13861. setTextureParameters(glTextureType, texture, supportsMips);
  13862. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, glTextureType);
  13863. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13864. generateMipmap(3553, texture, renderTarget.width, renderTarget.height);
  13865. }
  13866. state.bindTexture(3553, null);
  13867. } // Setup depth and stencil buffers
  13868. if (renderTarget.depthBuffer) {
  13869. setupDepthRenderbuffer(renderTarget);
  13870. }
  13871. }
  13872. function updateRenderTargetMipmap(renderTarget) {
  13873. var texture = renderTarget.texture;
  13874. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13875. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13876. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13877. var webglTexture = properties.get(texture).__webglTexture;
  13878. state.bindTexture(target, webglTexture);
  13879. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13880. state.bindTexture(target, null);
  13881. }
  13882. }
  13883. function updateMultisampleRenderTarget(renderTarget) {
  13884. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13885. if (isWebGL2) {
  13886. var renderTargetProperties = properties.get(renderTarget);
  13887. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13888. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13889. var width = renderTarget.width;
  13890. var height = renderTarget.height;
  13891. var mask = 16384;
  13892. if (renderTarget.depthBuffer) mask |= 256;
  13893. if (renderTarget.stencilBuffer) mask |= 1024;
  13894. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13895. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13896. } else {
  13897. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13898. }
  13899. }
  13900. }
  13901. function getRenderTargetSamples(renderTarget) {
  13902. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13903. }
  13904. function updateVideoTexture(texture) {
  13905. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13906. if (_videoTextures.get(texture) !== frame) {
  13907. _videoTextures.set(texture, frame);
  13908. texture.update();
  13909. }
  13910. } // backwards compatibility
  13911. var warnedTexture2D = false;
  13912. var warnedTextureCube = false;
  13913. function safeSetTexture2D(texture, slot) {
  13914. if (texture && texture.isWebGLRenderTarget) {
  13915. if (warnedTexture2D === false) {
  13916. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13917. warnedTexture2D = true;
  13918. }
  13919. texture = texture.texture;
  13920. }
  13921. setTexture2D(texture, slot);
  13922. }
  13923. function safeSetTextureCube(texture, slot) {
  13924. if (texture && texture.isWebGLCubeRenderTarget) {
  13925. if (warnedTextureCube === false) {
  13926. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13927. warnedTextureCube = true;
  13928. }
  13929. texture = texture.texture;
  13930. }
  13931. setTextureCube(texture, slot);
  13932. } //
  13933. this.allocateTextureUnit = allocateTextureUnit;
  13934. this.resetTextureUnits = resetTextureUnits;
  13935. this.setTexture2D = setTexture2D;
  13936. this.setTexture2DArray = setTexture2DArray;
  13937. this.setTexture3D = setTexture3D;
  13938. this.setTextureCube = setTextureCube;
  13939. this.setupRenderTarget = setupRenderTarget;
  13940. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13941. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13942. this.safeSetTexture2D = safeSetTexture2D;
  13943. this.safeSetTextureCube = safeSetTextureCube;
  13944. }
  13945. function WebGLUtils(gl, extensions, capabilities) {
  13946. var isWebGL2 = capabilities.isWebGL2;
  13947. function convert(p) {
  13948. var extension;
  13949. if (p === UnsignedByteType) return 5121;
  13950. if (p === UnsignedShort4444Type) return 32819;
  13951. if (p === UnsignedShort5551Type) return 32820;
  13952. if (p === UnsignedShort565Type) return 33635;
  13953. if (p === ByteType) return 5120;
  13954. if (p === ShortType) return 5122;
  13955. if (p === UnsignedShortType) return 5123;
  13956. if (p === IntType) return 5124;
  13957. if (p === UnsignedIntType) return 5125;
  13958. if (p === FloatType) return 5126;
  13959. if (p === HalfFloatType) {
  13960. if (isWebGL2) return 5131;
  13961. extension = extensions.get('OES_texture_half_float');
  13962. if (extension !== null) {
  13963. return extension.HALF_FLOAT_OES;
  13964. } else {
  13965. return null;
  13966. }
  13967. }
  13968. if (p === AlphaFormat) return 6406;
  13969. if (p === RGBFormat) return 6407;
  13970. if (p === RGBAFormat) return 6408;
  13971. if (p === LuminanceFormat) return 6409;
  13972. if (p === LuminanceAlphaFormat) return 6410;
  13973. if (p === DepthFormat) return 6402;
  13974. if (p === DepthStencilFormat) return 34041;
  13975. if (p === RedFormat) return 6403; // WebGL2 formats.
  13976. if (p === RedIntegerFormat) return 36244;
  13977. if (p === RGFormat) return 33319;
  13978. if (p === RGIntegerFormat) return 33320;
  13979. if (p === RGBIntegerFormat) return 36248;
  13980. if (p === RGBAIntegerFormat) return 36249;
  13981. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13982. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13983. if (extension !== null) {
  13984. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13985. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13986. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13987. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13988. } else {
  13989. return null;
  13990. }
  13991. }
  13992. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13993. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13994. if (extension !== null) {
  13995. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13996. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13997. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13998. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13999. } else {
  14000. return null;
  14001. }
  14002. }
  14003. if (p === RGB_ETC1_Format) {
  14004. extension = extensions.get('WEBGL_compressed_texture_etc1');
  14005. if (extension !== null) {
  14006. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  14007. } else {
  14008. return null;
  14009. }
  14010. }
  14011. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  14012. extension = extensions.get('WEBGL_compressed_texture_etc');
  14013. if (extension !== null) {
  14014. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  14015. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  14016. }
  14017. }
  14018. 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) {
  14019. extension = extensions.get('WEBGL_compressed_texture_astc');
  14020. if (extension !== null) {
  14021. // TODO Complete?
  14022. return p;
  14023. } else {
  14024. return null;
  14025. }
  14026. }
  14027. if (p === RGBA_BPTC_Format) {
  14028. extension = extensions.get('EXT_texture_compression_bptc');
  14029. if (extension !== null) {
  14030. // TODO Complete?
  14031. return p;
  14032. } else {
  14033. return null;
  14034. }
  14035. }
  14036. if (p === UnsignedInt248Type) {
  14037. if (isWebGL2) return 34042;
  14038. extension = extensions.get('WEBGL_depth_texture');
  14039. if (extension !== null) {
  14040. return extension.UNSIGNED_INT_24_8_WEBGL;
  14041. } else {
  14042. return null;
  14043. }
  14044. }
  14045. }
  14046. return {
  14047. convert: convert
  14048. };
  14049. }
  14050. function ArrayCamera(array) {
  14051. if (array === void 0) {
  14052. array = [];
  14053. }
  14054. PerspectiveCamera.call(this);
  14055. this.cameras = array;
  14056. }
  14057. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  14058. constructor: ArrayCamera,
  14059. isArrayCamera: true
  14060. });
  14061. var Group = /*#__PURE__*/function (_Object3D) {
  14062. _inheritsLoose(Group, _Object3D);
  14063. function Group() {
  14064. var _this;
  14065. _this = _Object3D.call(this) || this;
  14066. _this.type = 'Group';
  14067. Object.defineProperty(_assertThisInitialized(_this), 'isGroup', {
  14068. value: true
  14069. });
  14070. return _this;
  14071. }
  14072. return Group;
  14073. }(Object3D);
  14074. function WebXRController() {
  14075. this._targetRay = null;
  14076. this._grip = null;
  14077. this._hand = null;
  14078. }
  14079. Object.assign(WebXRController.prototype, {
  14080. constructor: WebXRController,
  14081. getHandSpace: function getHandSpace() {
  14082. if (this._hand === null) {
  14083. this._hand = new Group();
  14084. this._hand.matrixAutoUpdate = false;
  14085. this._hand.visible = false;
  14086. this._hand.joints = {};
  14087. this._hand.inputState = {
  14088. pinching: false
  14089. };
  14090. }
  14091. return this._hand;
  14092. },
  14093. getTargetRaySpace: function getTargetRaySpace() {
  14094. if (this._targetRay === null) {
  14095. this._targetRay = new Group();
  14096. this._targetRay.matrixAutoUpdate = false;
  14097. this._targetRay.visible = false;
  14098. }
  14099. return this._targetRay;
  14100. },
  14101. getGripSpace: function getGripSpace() {
  14102. if (this._grip === null) {
  14103. this._grip = new Group();
  14104. this._grip.matrixAutoUpdate = false;
  14105. this._grip.visible = false;
  14106. }
  14107. return this._grip;
  14108. },
  14109. dispatchEvent: function dispatchEvent(event) {
  14110. if (this._targetRay !== null) {
  14111. this._targetRay.dispatchEvent(event);
  14112. }
  14113. if (this._grip !== null) {
  14114. this._grip.dispatchEvent(event);
  14115. }
  14116. if (this._hand !== null) {
  14117. this._hand.dispatchEvent(event);
  14118. }
  14119. return this;
  14120. },
  14121. disconnect: function disconnect(inputSource) {
  14122. this.dispatchEvent({
  14123. type: 'disconnected',
  14124. data: inputSource
  14125. });
  14126. if (this._targetRay !== null) {
  14127. this._targetRay.visible = false;
  14128. }
  14129. if (this._grip !== null) {
  14130. this._grip.visible = false;
  14131. }
  14132. if (this._hand !== null) {
  14133. this._hand.visible = false;
  14134. }
  14135. return this;
  14136. },
  14137. update: function update(inputSource, frame, referenceSpace) {
  14138. var inputPose = null;
  14139. var gripPose = null;
  14140. var handPose = null;
  14141. var targetRay = this._targetRay;
  14142. var grip = this._grip;
  14143. var hand = this._hand;
  14144. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  14145. if (hand && inputSource.hand) {
  14146. handPose = true;
  14147. for (var _iterator = _createForOfIteratorHelperLoose(inputSource.hand.values()), _step; !(_step = _iterator()).done;) {
  14148. var inputjoint = _step.value;
  14149. // Update the joints groups with the XRJoint poses
  14150. var jointPose = frame.getJointPose(inputjoint, referenceSpace);
  14151. if (hand.joints[inputjoint.jointName] === undefined) {
  14152. // The transform of this joint will be updated with the joint pose on each frame
  14153. var _joint = new Group();
  14154. _joint.matrixAutoUpdate = false;
  14155. _joint.visible = false;
  14156. hand.joints[inputjoint.jointName] = _joint; // ??
  14157. hand.add(_joint);
  14158. }
  14159. var joint = hand.joints[inputjoint.jointName];
  14160. if (jointPose !== null) {
  14161. joint.matrix.fromArray(jointPose.transform.matrix);
  14162. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  14163. joint.jointRadius = jointPose.radius;
  14164. }
  14165. joint.visible = jointPose !== null;
  14166. } // Custom events
  14167. // Check pinchz
  14168. var indexTip = hand.joints['index-finger-tip'];
  14169. var thumbTip = hand.joints['thumb-tip'];
  14170. var distance = indexTip.position.distanceTo(thumbTip.position);
  14171. var distanceToPinch = 0.02;
  14172. var threshold = 0.005;
  14173. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  14174. hand.inputState.pinching = false;
  14175. this.dispatchEvent({
  14176. type: 'pinchend',
  14177. handedness: inputSource.handedness,
  14178. target: this
  14179. });
  14180. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  14181. hand.inputState.pinching = true;
  14182. this.dispatchEvent({
  14183. type: 'pinchstart',
  14184. handedness: inputSource.handedness,
  14185. target: this
  14186. });
  14187. }
  14188. } else {
  14189. if (targetRay !== null) {
  14190. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  14191. if (inputPose !== null) {
  14192. targetRay.matrix.fromArray(inputPose.transform.matrix);
  14193. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  14194. }
  14195. }
  14196. if (grip !== null && inputSource.gripSpace) {
  14197. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  14198. if (gripPose !== null) {
  14199. grip.matrix.fromArray(gripPose.transform.matrix);
  14200. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  14201. }
  14202. }
  14203. }
  14204. }
  14205. if (targetRay !== null) {
  14206. targetRay.visible = inputPose !== null;
  14207. }
  14208. if (grip !== null) {
  14209. grip.visible = gripPose !== null;
  14210. }
  14211. if (hand !== null) {
  14212. hand.visible = handPose !== null;
  14213. }
  14214. return this;
  14215. }
  14216. });
  14217. function WebXRManager(renderer, gl) {
  14218. var scope = this;
  14219. var session = null;
  14220. var framebufferScaleFactor = 1.0;
  14221. var referenceSpace = null;
  14222. var referenceSpaceType = 'local-floor';
  14223. var pose = null;
  14224. var controllers = [];
  14225. var inputSourcesMap = new Map(); //
  14226. var cameraL = new PerspectiveCamera();
  14227. cameraL.layers.enable(1);
  14228. cameraL.viewport = new Vector4();
  14229. var cameraR = new PerspectiveCamera();
  14230. cameraR.layers.enable(2);
  14231. cameraR.viewport = new Vector4();
  14232. var cameras = [cameraL, cameraR];
  14233. var cameraVR = new ArrayCamera();
  14234. cameraVR.layers.enable(1);
  14235. cameraVR.layers.enable(2);
  14236. var _currentDepthNear = null;
  14237. var _currentDepthFar = null; //
  14238. this.enabled = false;
  14239. this.isPresenting = false;
  14240. this.getController = function (index) {
  14241. var controller = controllers[index];
  14242. if (controller === undefined) {
  14243. controller = new WebXRController();
  14244. controllers[index] = controller;
  14245. }
  14246. return controller.getTargetRaySpace();
  14247. };
  14248. this.getControllerGrip = function (index) {
  14249. var controller = controllers[index];
  14250. if (controller === undefined) {
  14251. controller = new WebXRController();
  14252. controllers[index] = controller;
  14253. }
  14254. return controller.getGripSpace();
  14255. };
  14256. this.getHand = function (index) {
  14257. var controller = controllers[index];
  14258. if (controller === undefined) {
  14259. controller = new WebXRController();
  14260. controllers[index] = controller;
  14261. }
  14262. return controller.getHandSpace();
  14263. }; //
  14264. function onSessionEvent(event) {
  14265. var controller = inputSourcesMap.get(event.inputSource);
  14266. if (controller) {
  14267. controller.dispatchEvent({
  14268. type: event.type,
  14269. data: event.inputSource
  14270. });
  14271. }
  14272. }
  14273. function onSessionEnd() {
  14274. inputSourcesMap.forEach(function (controller, inputSource) {
  14275. controller.disconnect(inputSource);
  14276. });
  14277. inputSourcesMap.clear();
  14278. _currentDepthNear = null;
  14279. _currentDepthFar = null; //
  14280. renderer.setFramebuffer(null);
  14281. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  14282. animation.stop();
  14283. scope.isPresenting = false;
  14284. scope.dispatchEvent({
  14285. type: 'sessionend'
  14286. });
  14287. }
  14288. this.setFramebufferScaleFactor = function (value) {
  14289. framebufferScaleFactor = value;
  14290. if (scope.isPresenting === true) {
  14291. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  14292. }
  14293. };
  14294. this.setReferenceSpaceType = function (value) {
  14295. referenceSpaceType = value;
  14296. if (scope.isPresenting === true) {
  14297. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  14298. }
  14299. };
  14300. this.getReferenceSpace = function () {
  14301. return referenceSpace;
  14302. };
  14303. this.getSession = function () {
  14304. return session;
  14305. };
  14306. this.setSession = /*#__PURE__*/function () {
  14307. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
  14308. var attributes, layerInit, baseLayer;
  14309. return regeneratorRuntime.wrap(function _callee$(_context) {
  14310. while (1) {
  14311. switch (_context.prev = _context.next) {
  14312. case 0:
  14313. session = value;
  14314. if (!(session !== null)) {
  14315. _context.next = 24;
  14316. break;
  14317. }
  14318. session.addEventListener('select', onSessionEvent);
  14319. session.addEventListener('selectstart', onSessionEvent);
  14320. session.addEventListener('selectend', onSessionEvent);
  14321. session.addEventListener('squeeze', onSessionEvent);
  14322. session.addEventListener('squeezestart', onSessionEvent);
  14323. session.addEventListener('squeezeend', onSessionEvent);
  14324. session.addEventListener('end', onSessionEnd);
  14325. session.addEventListener('inputsourceschange', onInputSourcesChange);
  14326. attributes = gl.getContextAttributes();
  14327. if (!(attributes.xrCompatible !== true)) {
  14328. _context.next = 14;
  14329. break;
  14330. }
  14331. _context.next = 14;
  14332. return gl.makeXRCompatible();
  14333. case 14:
  14334. layerInit = {
  14335. antialias: attributes.antialias,
  14336. alpha: attributes.alpha,
  14337. depth: attributes.depth,
  14338. stencil: attributes.stencil,
  14339. framebufferScaleFactor: framebufferScaleFactor
  14340. }; // eslint-disable-next-line no-undef
  14341. baseLayer = new XRWebGLLayer(session, gl, layerInit);
  14342. session.updateRenderState({
  14343. baseLayer: baseLayer
  14344. });
  14345. _context.next = 19;
  14346. return session.requestReferenceSpace(referenceSpaceType);
  14347. case 19:
  14348. referenceSpace = _context.sent;
  14349. animation.setContext(session);
  14350. animation.start();
  14351. scope.isPresenting = true;
  14352. scope.dispatchEvent({
  14353. type: 'sessionstart'
  14354. });
  14355. case 24:
  14356. case "end":
  14357. return _context.stop();
  14358. }
  14359. }
  14360. }, _callee);
  14361. }));
  14362. return function (_x) {
  14363. return _ref.apply(this, arguments);
  14364. };
  14365. }();
  14366. function onInputSourcesChange(event) {
  14367. var inputSources = session.inputSources; // Assign inputSources to available controllers
  14368. for (var i = 0; i < controllers.length; i++) {
  14369. inputSourcesMap.set(inputSources[i], controllers[i]);
  14370. } // Notify disconnected
  14371. for (var _i = 0; _i < event.removed.length; _i++) {
  14372. var inputSource = event.removed[_i];
  14373. var controller = inputSourcesMap.get(inputSource);
  14374. if (controller) {
  14375. controller.dispatchEvent({
  14376. type: 'disconnected',
  14377. data: inputSource
  14378. });
  14379. inputSourcesMap.delete(inputSource);
  14380. }
  14381. } // Notify connected
  14382. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  14383. var _inputSource = event.added[_i2];
  14384. var _controller = inputSourcesMap.get(_inputSource);
  14385. if (_controller) {
  14386. _controller.dispatchEvent({
  14387. type: 'connected',
  14388. data: _inputSource
  14389. });
  14390. }
  14391. }
  14392. } //
  14393. var cameraLPos = new Vector3();
  14394. var cameraRPos = new Vector3();
  14395. /**
  14396. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14397. * the cameras' projection and world matrices have already been set.
  14398. * And that near and far planes are identical for both cameras.
  14399. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14400. */
  14401. function setProjectionFromUnion(camera, cameraL, cameraR) {
  14402. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  14403. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  14404. var ipd = cameraLPos.distanceTo(cameraRPos);
  14405. var projL = cameraL.projectionMatrix.elements;
  14406. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  14407. // most likely identical top and bottom frustum extents.
  14408. // Use the left camera for these values.
  14409. var near = projL[14] / (projL[10] - 1);
  14410. var far = projL[14] / (projL[10] + 1);
  14411. var topFov = (projL[9] + 1) / projL[5];
  14412. var bottomFov = (projL[9] - 1) / projL[5];
  14413. var leftFov = (projL[8] - 1) / projL[0];
  14414. var rightFov = (projR[8] + 1) / projR[0];
  14415. var left = near * leftFov;
  14416. var right = near * rightFov; // Calculate the new camera's position offset from the
  14417. // left camera. xOffset should be roughly half `ipd`.
  14418. var zOffset = ipd / (-leftFov + rightFov);
  14419. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  14420. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  14421. camera.translateX(xOffset);
  14422. camera.translateZ(zOffset);
  14423. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  14424. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  14425. // the values so that the near plane's position does not change in world space,
  14426. // although must now be relative to the new union camera.
  14427. var near2 = near + zOffset;
  14428. var far2 = far + zOffset;
  14429. var left2 = left - xOffset;
  14430. var right2 = right + (ipd - xOffset);
  14431. var top2 = topFov * far / far2 * near2;
  14432. var bottom2 = bottomFov * far / far2 * near2;
  14433. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  14434. }
  14435. function updateCamera(camera, parent) {
  14436. if (parent === null) {
  14437. camera.matrixWorld.copy(camera.matrix);
  14438. } else {
  14439. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  14440. }
  14441. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  14442. }
  14443. this.getCamera = function (camera) {
  14444. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14445. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14446. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  14447. // Note that the new renderState won't apply until the next frame. See #18320
  14448. session.updateRenderState({
  14449. depthNear: cameraVR.near,
  14450. depthFar: cameraVR.far
  14451. });
  14452. _currentDepthNear = cameraVR.near;
  14453. _currentDepthFar = cameraVR.far;
  14454. }
  14455. var parent = camera.parent;
  14456. var cameras = cameraVR.cameras;
  14457. updateCamera(cameraVR, parent);
  14458. for (var i = 0; i < cameras.length; i++) {
  14459. updateCamera(cameras[i], parent);
  14460. } // update camera and its children
  14461. camera.matrixWorld.copy(cameraVR.matrixWorld);
  14462. camera.matrix.copy(cameraVR.matrix);
  14463. camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
  14464. var children = camera.children;
  14465. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  14466. children[_i3].updateMatrixWorld(true);
  14467. } // update projection matrix for proper view frustum culling
  14468. if (cameras.length === 2) {
  14469. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  14470. } else {
  14471. // assume single camera setup (AR)
  14472. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  14473. }
  14474. return cameraVR;
  14475. }; // Animation Loop
  14476. var onAnimationFrameCallback = null;
  14477. function onAnimationFrame(time, frame) {
  14478. pose = frame.getViewerPose(referenceSpace);
  14479. if (pose !== null) {
  14480. var views = pose.views;
  14481. var baseLayer = session.renderState.baseLayer;
  14482. renderer.setFramebuffer(baseLayer.framebuffer);
  14483. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  14484. if (views.length !== cameraVR.cameras.length) {
  14485. cameraVR.cameras.length = 0;
  14486. cameraVRNeedsUpdate = true;
  14487. }
  14488. for (var i = 0; i < views.length; i++) {
  14489. var view = views[i];
  14490. var viewport = baseLayer.getViewport(view);
  14491. var camera = cameras[i];
  14492. camera.matrix.fromArray(view.transform.matrix);
  14493. camera.projectionMatrix.fromArray(view.projectionMatrix);
  14494. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  14495. if (i === 0) {
  14496. cameraVR.matrix.copy(camera.matrix);
  14497. }
  14498. if (cameraVRNeedsUpdate === true) {
  14499. cameraVR.cameras.push(camera);
  14500. }
  14501. }
  14502. } //
  14503. var inputSources = session.inputSources;
  14504. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  14505. var controller = controllers[_i4];
  14506. var inputSource = inputSources[_i4];
  14507. controller.update(inputSource, frame, referenceSpace);
  14508. }
  14509. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  14510. }
  14511. var animation = new WebGLAnimation();
  14512. animation.setAnimationLoop(onAnimationFrame);
  14513. this.setAnimationLoop = function (callback) {
  14514. onAnimationFrameCallback = callback;
  14515. };
  14516. this.dispose = function () {};
  14517. }
  14518. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  14519. function WebGLMaterials(properties) {
  14520. function refreshFogUniforms(uniforms, fog) {
  14521. uniforms.fogColor.value.copy(fog.color);
  14522. if (fog.isFog) {
  14523. uniforms.fogNear.value = fog.near;
  14524. uniforms.fogFar.value = fog.far;
  14525. } else if (fog.isFogExp2) {
  14526. uniforms.fogDensity.value = fog.density;
  14527. }
  14528. }
  14529. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  14530. if (material.isMeshBasicMaterial) {
  14531. refreshUniformsCommon(uniforms, material);
  14532. } else if (material.isMeshLambertMaterial) {
  14533. refreshUniformsCommon(uniforms, material);
  14534. refreshUniformsLambert(uniforms, material);
  14535. } else if (material.isMeshToonMaterial) {
  14536. refreshUniformsCommon(uniforms, material);
  14537. refreshUniformsToon(uniforms, material);
  14538. } else if (material.isMeshPhongMaterial) {
  14539. refreshUniformsCommon(uniforms, material);
  14540. refreshUniformsPhong(uniforms, material);
  14541. } else if (material.isMeshStandardMaterial) {
  14542. refreshUniformsCommon(uniforms, material);
  14543. if (material.isMeshPhysicalMaterial) {
  14544. refreshUniformsPhysical(uniforms, material);
  14545. } else {
  14546. refreshUniformsStandard(uniforms, material);
  14547. }
  14548. } else if (material.isMeshMatcapMaterial) {
  14549. refreshUniformsCommon(uniforms, material);
  14550. refreshUniformsMatcap(uniforms, material);
  14551. } else if (material.isMeshDepthMaterial) {
  14552. refreshUniformsCommon(uniforms, material);
  14553. refreshUniformsDepth(uniforms, material);
  14554. } else if (material.isMeshDistanceMaterial) {
  14555. refreshUniformsCommon(uniforms, material);
  14556. refreshUniformsDistance(uniforms, material);
  14557. } else if (material.isMeshNormalMaterial) {
  14558. refreshUniformsCommon(uniforms, material);
  14559. refreshUniformsNormal(uniforms, material);
  14560. } else if (material.isLineBasicMaterial) {
  14561. refreshUniformsLine(uniforms, material);
  14562. if (material.isLineDashedMaterial) {
  14563. refreshUniformsDash(uniforms, material);
  14564. }
  14565. } else if (material.isPointsMaterial) {
  14566. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14567. } else if (material.isSpriteMaterial) {
  14568. refreshUniformsSprites(uniforms, material);
  14569. } else if (material.isShadowMaterial) {
  14570. uniforms.color.value.copy(material.color);
  14571. uniforms.opacity.value = material.opacity;
  14572. } else if (material.isShaderMaterial) {
  14573. material.uniformsNeedUpdate = false; // #15581
  14574. }
  14575. }
  14576. function refreshUniformsCommon(uniforms, material) {
  14577. uniforms.opacity.value = material.opacity;
  14578. if (material.color) {
  14579. uniforms.diffuse.value.copy(material.color);
  14580. }
  14581. if (material.emissive) {
  14582. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14583. }
  14584. if (material.map) {
  14585. uniforms.map.value = material.map;
  14586. }
  14587. if (material.alphaMap) {
  14588. uniforms.alphaMap.value = material.alphaMap;
  14589. }
  14590. if (material.specularMap) {
  14591. uniforms.specularMap.value = material.specularMap;
  14592. }
  14593. var envMap = properties.get(material).envMap;
  14594. if (envMap) {
  14595. uniforms.envMap.value = envMap;
  14596. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14597. uniforms.reflectivity.value = material.reflectivity;
  14598. uniforms.refractionRatio.value = material.refractionRatio;
  14599. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14600. if (maxMipLevel !== undefined) {
  14601. uniforms.maxMipLevel.value = maxMipLevel;
  14602. }
  14603. }
  14604. if (material.lightMap) {
  14605. uniforms.lightMap.value = material.lightMap;
  14606. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14607. }
  14608. if (material.aoMap) {
  14609. uniforms.aoMap.value = material.aoMap;
  14610. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14611. } // uv repeat and offset setting priorities
  14612. // 1. color map
  14613. // 2. specular map
  14614. // 3. displacementMap map
  14615. // 4. normal map
  14616. // 5. bump map
  14617. // 6. roughnessMap map
  14618. // 7. metalnessMap map
  14619. // 8. alphaMap map
  14620. // 9. emissiveMap map
  14621. // 10. clearcoat map
  14622. // 11. clearcoat normal map
  14623. // 12. clearcoat roughnessMap map
  14624. var uvScaleMap;
  14625. if (material.map) {
  14626. uvScaleMap = material.map;
  14627. } else if (material.specularMap) {
  14628. uvScaleMap = material.specularMap;
  14629. } else if (material.displacementMap) {
  14630. uvScaleMap = material.displacementMap;
  14631. } else if (material.normalMap) {
  14632. uvScaleMap = material.normalMap;
  14633. } else if (material.bumpMap) {
  14634. uvScaleMap = material.bumpMap;
  14635. } else if (material.roughnessMap) {
  14636. uvScaleMap = material.roughnessMap;
  14637. } else if (material.metalnessMap) {
  14638. uvScaleMap = material.metalnessMap;
  14639. } else if (material.alphaMap) {
  14640. uvScaleMap = material.alphaMap;
  14641. } else if (material.emissiveMap) {
  14642. uvScaleMap = material.emissiveMap;
  14643. } else if (material.clearcoatMap) {
  14644. uvScaleMap = material.clearcoatMap;
  14645. } else if (material.clearcoatNormalMap) {
  14646. uvScaleMap = material.clearcoatNormalMap;
  14647. } else if (material.clearcoatRoughnessMap) {
  14648. uvScaleMap = material.clearcoatRoughnessMap;
  14649. }
  14650. if (uvScaleMap !== undefined) {
  14651. // backwards compatibility
  14652. if (uvScaleMap.isWebGLRenderTarget) {
  14653. uvScaleMap = uvScaleMap.texture;
  14654. }
  14655. if (uvScaleMap.matrixAutoUpdate === true) {
  14656. uvScaleMap.updateMatrix();
  14657. }
  14658. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14659. } // uv repeat and offset setting priorities for uv2
  14660. // 1. ao map
  14661. // 2. light map
  14662. var uv2ScaleMap;
  14663. if (material.aoMap) {
  14664. uv2ScaleMap = material.aoMap;
  14665. } else if (material.lightMap) {
  14666. uv2ScaleMap = material.lightMap;
  14667. }
  14668. if (uv2ScaleMap !== undefined) {
  14669. // backwards compatibility
  14670. if (uv2ScaleMap.isWebGLRenderTarget) {
  14671. uv2ScaleMap = uv2ScaleMap.texture;
  14672. }
  14673. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14674. uv2ScaleMap.updateMatrix();
  14675. }
  14676. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14677. }
  14678. }
  14679. function refreshUniformsLine(uniforms, material) {
  14680. uniforms.diffuse.value.copy(material.color);
  14681. uniforms.opacity.value = material.opacity;
  14682. }
  14683. function refreshUniformsDash(uniforms, material) {
  14684. uniforms.dashSize.value = material.dashSize;
  14685. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14686. uniforms.scale.value = material.scale;
  14687. }
  14688. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14689. uniforms.diffuse.value.copy(material.color);
  14690. uniforms.opacity.value = material.opacity;
  14691. uniforms.size.value = material.size * pixelRatio;
  14692. uniforms.scale.value = height * 0.5;
  14693. if (material.map) {
  14694. uniforms.map.value = material.map;
  14695. }
  14696. if (material.alphaMap) {
  14697. uniforms.alphaMap.value = material.alphaMap;
  14698. } // uv repeat and offset setting priorities
  14699. // 1. color map
  14700. // 2. alpha map
  14701. var uvScaleMap;
  14702. if (material.map) {
  14703. uvScaleMap = material.map;
  14704. } else if (material.alphaMap) {
  14705. uvScaleMap = material.alphaMap;
  14706. }
  14707. if (uvScaleMap !== undefined) {
  14708. if (uvScaleMap.matrixAutoUpdate === true) {
  14709. uvScaleMap.updateMatrix();
  14710. }
  14711. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14712. }
  14713. }
  14714. function refreshUniformsSprites(uniforms, material) {
  14715. uniforms.diffuse.value.copy(material.color);
  14716. uniforms.opacity.value = material.opacity;
  14717. uniforms.rotation.value = material.rotation;
  14718. if (material.map) {
  14719. uniforms.map.value = material.map;
  14720. }
  14721. if (material.alphaMap) {
  14722. uniforms.alphaMap.value = material.alphaMap;
  14723. } // uv repeat and offset setting priorities
  14724. // 1. color map
  14725. // 2. alpha map
  14726. var uvScaleMap;
  14727. if (material.map) {
  14728. uvScaleMap = material.map;
  14729. } else if (material.alphaMap) {
  14730. uvScaleMap = material.alphaMap;
  14731. }
  14732. if (uvScaleMap !== undefined) {
  14733. if (uvScaleMap.matrixAutoUpdate === true) {
  14734. uvScaleMap.updateMatrix();
  14735. }
  14736. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14737. }
  14738. }
  14739. function refreshUniformsLambert(uniforms, material) {
  14740. if (material.emissiveMap) {
  14741. uniforms.emissiveMap.value = material.emissiveMap;
  14742. }
  14743. }
  14744. function refreshUniformsPhong(uniforms, material) {
  14745. uniforms.specular.value.copy(material.specular);
  14746. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14747. if (material.emissiveMap) {
  14748. uniforms.emissiveMap.value = material.emissiveMap;
  14749. }
  14750. if (material.bumpMap) {
  14751. uniforms.bumpMap.value = material.bumpMap;
  14752. uniforms.bumpScale.value = material.bumpScale;
  14753. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14754. }
  14755. if (material.normalMap) {
  14756. uniforms.normalMap.value = material.normalMap;
  14757. uniforms.normalScale.value.copy(material.normalScale);
  14758. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14759. }
  14760. if (material.displacementMap) {
  14761. uniforms.displacementMap.value = material.displacementMap;
  14762. uniforms.displacementScale.value = material.displacementScale;
  14763. uniforms.displacementBias.value = material.displacementBias;
  14764. }
  14765. }
  14766. function refreshUniformsToon(uniforms, material) {
  14767. if (material.gradientMap) {
  14768. uniforms.gradientMap.value = material.gradientMap;
  14769. }
  14770. if (material.emissiveMap) {
  14771. uniforms.emissiveMap.value = material.emissiveMap;
  14772. }
  14773. if (material.bumpMap) {
  14774. uniforms.bumpMap.value = material.bumpMap;
  14775. uniforms.bumpScale.value = material.bumpScale;
  14776. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14777. }
  14778. if (material.normalMap) {
  14779. uniforms.normalMap.value = material.normalMap;
  14780. uniforms.normalScale.value.copy(material.normalScale);
  14781. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14782. }
  14783. if (material.displacementMap) {
  14784. uniforms.displacementMap.value = material.displacementMap;
  14785. uniforms.displacementScale.value = material.displacementScale;
  14786. uniforms.displacementBias.value = material.displacementBias;
  14787. }
  14788. }
  14789. function refreshUniformsStandard(uniforms, material) {
  14790. uniforms.roughness.value = material.roughness;
  14791. uniforms.metalness.value = material.metalness;
  14792. if (material.roughnessMap) {
  14793. uniforms.roughnessMap.value = material.roughnessMap;
  14794. }
  14795. if (material.metalnessMap) {
  14796. uniforms.metalnessMap.value = material.metalnessMap;
  14797. }
  14798. if (material.emissiveMap) {
  14799. uniforms.emissiveMap.value = material.emissiveMap;
  14800. }
  14801. if (material.bumpMap) {
  14802. uniforms.bumpMap.value = material.bumpMap;
  14803. uniforms.bumpScale.value = material.bumpScale;
  14804. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14805. }
  14806. if (material.normalMap) {
  14807. uniforms.normalMap.value = material.normalMap;
  14808. uniforms.normalScale.value.copy(material.normalScale);
  14809. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14810. }
  14811. if (material.displacementMap) {
  14812. uniforms.displacementMap.value = material.displacementMap;
  14813. uniforms.displacementScale.value = material.displacementScale;
  14814. uniforms.displacementBias.value = material.displacementBias;
  14815. }
  14816. var envMap = properties.get(material).envMap;
  14817. if (envMap) {
  14818. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14819. uniforms.envMapIntensity.value = material.envMapIntensity;
  14820. }
  14821. }
  14822. function refreshUniformsPhysical(uniforms, material) {
  14823. refreshUniformsStandard(uniforms, material);
  14824. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14825. uniforms.clearcoat.value = material.clearcoat;
  14826. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14827. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14828. if (material.clearcoatMap) {
  14829. uniforms.clearcoatMap.value = material.clearcoatMap;
  14830. }
  14831. if (material.clearcoatRoughnessMap) {
  14832. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14833. }
  14834. if (material.clearcoatNormalMap) {
  14835. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14836. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14837. if (material.side === BackSide) {
  14838. uniforms.clearcoatNormalScale.value.negate();
  14839. }
  14840. }
  14841. uniforms.transmission.value = material.transmission;
  14842. if (material.transmissionMap) {
  14843. uniforms.transmissionMap.value = material.transmissionMap;
  14844. }
  14845. }
  14846. function refreshUniformsMatcap(uniforms, material) {
  14847. if (material.matcap) {
  14848. uniforms.matcap.value = material.matcap;
  14849. }
  14850. if (material.bumpMap) {
  14851. uniforms.bumpMap.value = material.bumpMap;
  14852. uniforms.bumpScale.value = material.bumpScale;
  14853. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14854. }
  14855. if (material.normalMap) {
  14856. uniforms.normalMap.value = material.normalMap;
  14857. uniforms.normalScale.value.copy(material.normalScale);
  14858. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14859. }
  14860. if (material.displacementMap) {
  14861. uniforms.displacementMap.value = material.displacementMap;
  14862. uniforms.displacementScale.value = material.displacementScale;
  14863. uniforms.displacementBias.value = material.displacementBias;
  14864. }
  14865. }
  14866. function refreshUniformsDepth(uniforms, material) {
  14867. if (material.displacementMap) {
  14868. uniforms.displacementMap.value = material.displacementMap;
  14869. uniforms.displacementScale.value = material.displacementScale;
  14870. uniforms.displacementBias.value = material.displacementBias;
  14871. }
  14872. }
  14873. function refreshUniformsDistance(uniforms, material) {
  14874. if (material.displacementMap) {
  14875. uniforms.displacementMap.value = material.displacementMap;
  14876. uniforms.displacementScale.value = material.displacementScale;
  14877. uniforms.displacementBias.value = material.displacementBias;
  14878. }
  14879. uniforms.referencePosition.value.copy(material.referencePosition);
  14880. uniforms.nearDistance.value = material.nearDistance;
  14881. uniforms.farDistance.value = material.farDistance;
  14882. }
  14883. function refreshUniformsNormal(uniforms, material) {
  14884. if (material.bumpMap) {
  14885. uniforms.bumpMap.value = material.bumpMap;
  14886. uniforms.bumpScale.value = material.bumpScale;
  14887. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14888. }
  14889. if (material.normalMap) {
  14890. uniforms.normalMap.value = material.normalMap;
  14891. uniforms.normalScale.value.copy(material.normalScale);
  14892. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14893. }
  14894. if (material.displacementMap) {
  14895. uniforms.displacementMap.value = material.displacementMap;
  14896. uniforms.displacementScale.value = material.displacementScale;
  14897. uniforms.displacementBias.value = material.displacementBias;
  14898. }
  14899. }
  14900. return {
  14901. refreshFogUniforms: refreshFogUniforms,
  14902. refreshMaterialUniforms: refreshMaterialUniforms
  14903. };
  14904. }
  14905. function createCanvasElement() {
  14906. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14907. canvas.style.display = 'block';
  14908. return canvas;
  14909. }
  14910. function WebGLRenderer(parameters) {
  14911. parameters = parameters || {};
  14912. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14913. _context = parameters.context !== undefined ? parameters.context : null,
  14914. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14915. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14916. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14917. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14918. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14919. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14920. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14921. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14922. var currentRenderList = null;
  14923. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14924. // We track this so that the nested render call gets its list and state isolated from the parent render call.
  14925. var renderListStack = [];
  14926. var renderStateStack = []; // public properties
  14927. this.domElement = _canvas; // Debug configuration container
  14928. this.debug = {
  14929. /**
  14930. * Enables error checking and reporting when shader programs are being compiled
  14931. * @type {boolean}
  14932. */
  14933. checkShaderErrors: true
  14934. }; // clearing
  14935. this.autoClear = true;
  14936. this.autoClearColor = true;
  14937. this.autoClearDepth = true;
  14938. this.autoClearStencil = true; // scene graph
  14939. this.sortObjects = true; // user-defined clipping
  14940. this.clippingPlanes = [];
  14941. this.localClippingEnabled = false; // physically based shading
  14942. this.gammaFactor = 2.0; // for backwards compatibility
  14943. this.outputEncoding = LinearEncoding; // physical lights
  14944. this.physicallyCorrectLights = false; // tone mapping
  14945. this.toneMapping = NoToneMapping;
  14946. this.toneMappingExposure = 1.0; // morphs
  14947. this.maxMorphTargets = 8;
  14948. this.maxMorphNormals = 4; // internal properties
  14949. var _this = this;
  14950. var _isContextLost = false; // internal state cache
  14951. var _framebuffer = null;
  14952. var _currentActiveCubeFace = 0;
  14953. var _currentActiveMipmapLevel = 0;
  14954. var _currentRenderTarget = null;
  14955. var _currentFramebuffer = null;
  14956. var _currentMaterialId = -1;
  14957. var _currentCamera = null;
  14958. var _currentViewport = new Vector4();
  14959. var _currentScissor = new Vector4();
  14960. var _currentScissorTest = null; //
  14961. var _width = _canvas.width;
  14962. var _height = _canvas.height;
  14963. var _pixelRatio = 1;
  14964. var _opaqueSort = null;
  14965. var _transparentSort = null;
  14966. var _viewport = new Vector4(0, 0, _width, _height);
  14967. var _scissor = new Vector4(0, 0, _width, _height);
  14968. var _scissorTest = false; // frustum
  14969. var _frustum = new Frustum(); // clipping
  14970. var _clippingEnabled = false;
  14971. var _localClippingEnabled = false; // camera matrices cache
  14972. var _projScreenMatrix = new Matrix4();
  14973. var _vector3 = new Vector3();
  14974. var _emptyScene = {
  14975. background: null,
  14976. fog: null,
  14977. environment: null,
  14978. overrideMaterial: null,
  14979. isScene: true
  14980. };
  14981. function getTargetPixelRatio() {
  14982. return _currentRenderTarget === null ? _pixelRatio : 1;
  14983. } // initialize
  14984. var _gl = _context;
  14985. function getContext(contextNames, contextAttributes) {
  14986. for (var i = 0; i < contextNames.length; i++) {
  14987. var contextName = contextNames[i];
  14988. var context = _canvas.getContext(contextName, contextAttributes);
  14989. if (context !== null) return context;
  14990. }
  14991. return null;
  14992. }
  14993. try {
  14994. var contextAttributes = {
  14995. alpha: _alpha,
  14996. depth: _depth,
  14997. stencil: _stencil,
  14998. antialias: _antialias,
  14999. premultipliedAlpha: _premultipliedAlpha,
  15000. preserveDrawingBuffer: _preserveDrawingBuffer,
  15001. powerPreference: _powerPreference,
  15002. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  15003. }; // event listeners must be registered before WebGL context is created, see #12753
  15004. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  15005. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  15006. if (_gl === null) {
  15007. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  15008. if (_this.isWebGL1Renderer === true) {
  15009. contextNames.shift();
  15010. }
  15011. _gl = getContext(contextNames, contextAttributes);
  15012. if (_gl === null) {
  15013. if (getContext(contextNames)) {
  15014. throw new Error('Error creating WebGL context with your selected attributes.');
  15015. } else {
  15016. throw new Error('Error creating WebGL context.');
  15017. }
  15018. }
  15019. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  15020. if (_gl.getShaderPrecisionFormat === undefined) {
  15021. _gl.getShaderPrecisionFormat = function () {
  15022. return {
  15023. 'rangeMin': 1,
  15024. 'rangeMax': 1,
  15025. 'precision': 1
  15026. };
  15027. };
  15028. }
  15029. } catch (error) {
  15030. console.error('THREE.WebGLRenderer: ' + error.message);
  15031. throw error;
  15032. }
  15033. var extensions, capabilities, state, info;
  15034. var properties, textures, cubemaps, attributes, geometries, objects;
  15035. var programCache, materials, renderLists, renderStates, clipping;
  15036. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  15037. var utils, bindingStates;
  15038. function initGLContext() {
  15039. extensions = new WebGLExtensions(_gl);
  15040. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  15041. extensions.init(capabilities);
  15042. utils = new WebGLUtils(_gl, extensions, capabilities);
  15043. state = new WebGLState(_gl, extensions, capabilities);
  15044. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15045. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15046. info = new WebGLInfo(_gl);
  15047. properties = new WebGLProperties();
  15048. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  15049. cubemaps = new WebGLCubeMaps(_this);
  15050. attributes = new WebGLAttributes(_gl, capabilities);
  15051. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  15052. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  15053. objects = new WebGLObjects(_gl, geometries, attributes, info);
  15054. morphtargets = new WebGLMorphtargets(_gl);
  15055. clipping = new WebGLClipping(properties);
  15056. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  15057. materials = new WebGLMaterials(properties);
  15058. renderLists = new WebGLRenderLists(properties);
  15059. renderStates = new WebGLRenderStates(extensions, capabilities);
  15060. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  15061. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  15062. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  15063. info.programs = programCache.programs;
  15064. _this.capabilities = capabilities;
  15065. _this.extensions = extensions;
  15066. _this.properties = properties;
  15067. _this.renderLists = renderLists;
  15068. _this.state = state;
  15069. _this.info = info;
  15070. }
  15071. initGLContext(); // xr
  15072. var xr = new WebXRManager(_this, _gl);
  15073. this.xr = xr; // shadow map
  15074. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  15075. this.shadowMap = shadowMap; // API
  15076. this.getContext = function () {
  15077. return _gl;
  15078. };
  15079. this.getContextAttributes = function () {
  15080. return _gl.getContextAttributes();
  15081. };
  15082. this.forceContextLoss = function () {
  15083. var extension = extensions.get('WEBGL_lose_context');
  15084. if (extension) extension.loseContext();
  15085. };
  15086. this.forceContextRestore = function () {
  15087. var extension = extensions.get('WEBGL_lose_context');
  15088. if (extension) extension.restoreContext();
  15089. };
  15090. this.getPixelRatio = function () {
  15091. return _pixelRatio;
  15092. };
  15093. this.setPixelRatio = function (value) {
  15094. if (value === undefined) return;
  15095. _pixelRatio = value;
  15096. this.setSize(_width, _height, false);
  15097. };
  15098. this.getSize = function (target) {
  15099. if (target === undefined) {
  15100. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  15101. target = new Vector2();
  15102. }
  15103. return target.set(_width, _height);
  15104. };
  15105. this.setSize = function (width, height, updateStyle) {
  15106. if (xr.isPresenting) {
  15107. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  15108. return;
  15109. }
  15110. _width = width;
  15111. _height = height;
  15112. _canvas.width = Math.floor(width * _pixelRatio);
  15113. _canvas.height = Math.floor(height * _pixelRatio);
  15114. if (updateStyle !== false) {
  15115. _canvas.style.width = width + 'px';
  15116. _canvas.style.height = height + 'px';
  15117. }
  15118. this.setViewport(0, 0, width, height);
  15119. };
  15120. this.getDrawingBufferSize = function (target) {
  15121. if (target === undefined) {
  15122. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  15123. target = new Vector2();
  15124. }
  15125. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  15126. };
  15127. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  15128. _width = width;
  15129. _height = height;
  15130. _pixelRatio = pixelRatio;
  15131. _canvas.width = Math.floor(width * pixelRatio);
  15132. _canvas.height = Math.floor(height * pixelRatio);
  15133. this.setViewport(0, 0, width, height);
  15134. };
  15135. this.getCurrentViewport = function (target) {
  15136. if (target === undefined) {
  15137. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  15138. target = new Vector4();
  15139. }
  15140. return target.copy(_currentViewport);
  15141. };
  15142. this.getViewport = function (target) {
  15143. return target.copy(_viewport);
  15144. };
  15145. this.setViewport = function (x, y, width, height) {
  15146. if (x.isVector4) {
  15147. _viewport.set(x.x, x.y, x.z, x.w);
  15148. } else {
  15149. _viewport.set(x, y, width, height);
  15150. }
  15151. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15152. };
  15153. this.getScissor = function (target) {
  15154. return target.copy(_scissor);
  15155. };
  15156. this.setScissor = function (x, y, width, height) {
  15157. if (x.isVector4) {
  15158. _scissor.set(x.x, x.y, x.z, x.w);
  15159. } else {
  15160. _scissor.set(x, y, width, height);
  15161. }
  15162. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15163. };
  15164. this.getScissorTest = function () {
  15165. return _scissorTest;
  15166. };
  15167. this.setScissorTest = function (boolean) {
  15168. state.setScissorTest(_scissorTest = boolean);
  15169. };
  15170. this.setOpaqueSort = function (method) {
  15171. _opaqueSort = method;
  15172. };
  15173. this.setTransparentSort = function (method) {
  15174. _transparentSort = method;
  15175. }; // Clearing
  15176. this.getClearColor = function (target) {
  15177. if (target === undefined) {
  15178. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  15179. target = new Color();
  15180. }
  15181. return target.copy(background.getClearColor());
  15182. };
  15183. this.setClearColor = function () {
  15184. background.setClearColor.apply(background, arguments);
  15185. };
  15186. this.getClearAlpha = function () {
  15187. return background.getClearAlpha();
  15188. };
  15189. this.setClearAlpha = function () {
  15190. background.setClearAlpha.apply(background, arguments);
  15191. };
  15192. this.clear = function (color, depth, stencil) {
  15193. var bits = 0;
  15194. if (color === undefined || color) bits |= 16384;
  15195. if (depth === undefined || depth) bits |= 256;
  15196. if (stencil === undefined || stencil) bits |= 1024;
  15197. _gl.clear(bits);
  15198. };
  15199. this.clearColor = function () {
  15200. this.clear(true, false, false);
  15201. };
  15202. this.clearDepth = function () {
  15203. this.clear(false, true, false);
  15204. };
  15205. this.clearStencil = function () {
  15206. this.clear(false, false, true);
  15207. }; //
  15208. this.dispose = function () {
  15209. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  15210. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  15211. renderLists.dispose();
  15212. renderStates.dispose();
  15213. properties.dispose();
  15214. cubemaps.dispose();
  15215. objects.dispose();
  15216. bindingStates.dispose();
  15217. xr.dispose();
  15218. animation.stop();
  15219. }; // Events
  15220. function onContextLost(event) {
  15221. event.preventDefault();
  15222. console.log('THREE.WebGLRenderer: Context Lost.');
  15223. _isContextLost = true;
  15224. }
  15225. function onContextRestore()
  15226. /* event */
  15227. {
  15228. console.log('THREE.WebGLRenderer: Context Restored.');
  15229. _isContextLost = false;
  15230. initGLContext();
  15231. }
  15232. function onMaterialDispose(event) {
  15233. var material = event.target;
  15234. material.removeEventListener('dispose', onMaterialDispose);
  15235. deallocateMaterial(material);
  15236. } // Buffer deallocation
  15237. function deallocateMaterial(material) {
  15238. releaseMaterialProgramReference(material);
  15239. properties.remove(material);
  15240. }
  15241. function releaseMaterialProgramReference(material) {
  15242. var programInfo = properties.get(material).program;
  15243. if (programInfo !== undefined) {
  15244. programCache.releaseProgram(programInfo);
  15245. }
  15246. } // Buffer rendering
  15247. function renderObjectImmediate(object, program) {
  15248. object.render(function (object) {
  15249. _this.renderBufferImmediate(object, program);
  15250. });
  15251. }
  15252. this.renderBufferImmediate = function (object, program) {
  15253. bindingStates.initAttributes();
  15254. var buffers = properties.get(object);
  15255. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  15256. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  15257. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  15258. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  15259. var programAttributes = program.getAttributes();
  15260. if (object.hasPositions) {
  15261. _gl.bindBuffer(34962, buffers.position);
  15262. _gl.bufferData(34962, object.positionArray, 35048);
  15263. bindingStates.enableAttribute(programAttributes.position);
  15264. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  15265. }
  15266. if (object.hasNormals) {
  15267. _gl.bindBuffer(34962, buffers.normal);
  15268. _gl.bufferData(34962, object.normalArray, 35048);
  15269. bindingStates.enableAttribute(programAttributes.normal);
  15270. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  15271. }
  15272. if (object.hasUvs) {
  15273. _gl.bindBuffer(34962, buffers.uv);
  15274. _gl.bufferData(34962, object.uvArray, 35048);
  15275. bindingStates.enableAttribute(programAttributes.uv);
  15276. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  15277. }
  15278. if (object.hasColors) {
  15279. _gl.bindBuffer(34962, buffers.color);
  15280. _gl.bufferData(34962, object.colorArray, 35048);
  15281. bindingStates.enableAttribute(programAttributes.color);
  15282. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  15283. }
  15284. bindingStates.disableUnusedAttributes();
  15285. _gl.drawArrays(4, 0, object.count);
  15286. object.count = 0;
  15287. };
  15288. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  15289. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15290. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  15291. var program = setProgram(camera, scene, material, object);
  15292. state.setMaterial(material, frontFaceCW); //
  15293. var index = geometry.index;
  15294. var position = geometry.attributes.position; //
  15295. if (index === null) {
  15296. if (position === undefined || position.count === 0) return;
  15297. } else if (index.count === 0) {
  15298. return;
  15299. } //
  15300. var rangeFactor = 1;
  15301. if (material.wireframe === true) {
  15302. index = geometries.getWireframeAttribute(geometry);
  15303. rangeFactor = 2;
  15304. }
  15305. if (material.morphTargets || material.morphNormals) {
  15306. morphtargets.update(object, geometry, material, program);
  15307. }
  15308. bindingStates.setup(object, material, program, geometry, index);
  15309. var attribute;
  15310. var renderer = bufferRenderer;
  15311. if (index !== null) {
  15312. attribute = attributes.get(index);
  15313. renderer = indexedBufferRenderer;
  15314. renderer.setIndex(attribute);
  15315. } //
  15316. var dataCount = index !== null ? index.count : position.count;
  15317. var rangeStart = geometry.drawRange.start * rangeFactor;
  15318. var rangeCount = geometry.drawRange.count * rangeFactor;
  15319. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15320. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15321. var drawStart = Math.max(rangeStart, groupStart);
  15322. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  15323. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  15324. if (drawCount === 0) return; //
  15325. if (object.isMesh) {
  15326. if (material.wireframe === true) {
  15327. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  15328. renderer.setMode(1);
  15329. } else {
  15330. renderer.setMode(4);
  15331. }
  15332. } else if (object.isLine) {
  15333. var lineWidth = material.linewidth;
  15334. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  15335. state.setLineWidth(lineWidth * getTargetPixelRatio());
  15336. if (object.isLineSegments) {
  15337. renderer.setMode(1);
  15338. } else if (object.isLineLoop) {
  15339. renderer.setMode(2);
  15340. } else {
  15341. renderer.setMode(3);
  15342. }
  15343. } else if (object.isPoints) {
  15344. renderer.setMode(0);
  15345. } else if (object.isSprite) {
  15346. renderer.setMode(4);
  15347. }
  15348. if (object.isInstancedMesh) {
  15349. renderer.renderInstances(drawStart, drawCount, object.count);
  15350. } else if (geometry.isInstancedBufferGeometry) {
  15351. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  15352. renderer.renderInstances(drawStart, drawCount, instanceCount);
  15353. } else {
  15354. renderer.render(drawStart, drawCount);
  15355. }
  15356. }; // Compile
  15357. this.compile = function (scene, camera) {
  15358. currentRenderState = renderStates.get(scene);
  15359. currentRenderState.init();
  15360. scene.traverseVisible(function (object) {
  15361. if (object.isLight && object.layers.test(camera.layers)) {
  15362. currentRenderState.pushLight(object);
  15363. if (object.castShadow) {
  15364. currentRenderState.pushShadow(object);
  15365. }
  15366. }
  15367. });
  15368. currentRenderState.setupLights();
  15369. var compiled = new WeakMap();
  15370. scene.traverse(function (object) {
  15371. var material = object.material;
  15372. if (material) {
  15373. if (Array.isArray(material)) {
  15374. for (var i = 0; i < material.length; i++) {
  15375. var material2 = material[i];
  15376. if (compiled.has(material2) === false) {
  15377. initMaterial(material2, scene, object);
  15378. compiled.set(material2);
  15379. }
  15380. }
  15381. } else if (compiled.has(material) === false) {
  15382. initMaterial(material, scene, object);
  15383. compiled.set(material);
  15384. }
  15385. }
  15386. });
  15387. }; // Animation Loop
  15388. var onAnimationFrameCallback = null;
  15389. function onAnimationFrame(time) {
  15390. if (xr.isPresenting) return;
  15391. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  15392. }
  15393. var animation = new WebGLAnimation();
  15394. animation.setAnimationLoop(onAnimationFrame);
  15395. if (typeof window !== 'undefined') animation.setContext(window);
  15396. this.setAnimationLoop = function (callback) {
  15397. onAnimationFrameCallback = callback;
  15398. xr.setAnimationLoop(callback);
  15399. callback === null ? animation.stop() : animation.start();
  15400. }; // Rendering
  15401. this.render = function (scene, camera) {
  15402. var renderTarget, forceClear;
  15403. if (arguments[2] !== undefined) {
  15404. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  15405. renderTarget = arguments[2];
  15406. }
  15407. if (arguments[3] !== undefined) {
  15408. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  15409. forceClear = arguments[3];
  15410. }
  15411. if (camera !== undefined && camera.isCamera !== true) {
  15412. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  15413. return;
  15414. }
  15415. if (_isContextLost === true) return; // reset caching for this frame
  15416. bindingStates.resetDefaultState();
  15417. _currentMaterialId = -1;
  15418. _currentCamera = null; // update scene graph
  15419. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  15420. if (camera.parent === null) camera.updateMatrixWorld();
  15421. if (xr.enabled === true && xr.isPresenting === true) {
  15422. camera = xr.getCamera(camera);
  15423. } //
  15424. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  15425. currentRenderState = renderStates.get(scene, renderStateStack.length);
  15426. currentRenderState.init();
  15427. renderStateStack.push(currentRenderState);
  15428. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  15429. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  15430. _localClippingEnabled = this.localClippingEnabled;
  15431. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  15432. currentRenderList = renderLists.get(scene, renderListStack.length);
  15433. currentRenderList.init();
  15434. renderListStack.push(currentRenderList);
  15435. projectObject(scene, camera, 0, _this.sortObjects);
  15436. currentRenderList.finish();
  15437. if (_this.sortObjects === true) {
  15438. currentRenderList.sort(_opaqueSort, _transparentSort);
  15439. } //
  15440. if (_clippingEnabled === true) clipping.beginShadows();
  15441. var shadowsArray = currentRenderState.state.shadowsArray;
  15442. shadowMap.render(shadowsArray, scene, camera);
  15443. currentRenderState.setupLights();
  15444. currentRenderState.setupLightsView(camera);
  15445. if (_clippingEnabled === true) clipping.endShadows(); //
  15446. if (this.info.autoReset === true) this.info.reset();
  15447. if (renderTarget !== undefined) {
  15448. this.setRenderTarget(renderTarget);
  15449. } //
  15450. background.render(currentRenderList, scene, camera, forceClear); // render scene
  15451. var opaqueObjects = currentRenderList.opaque;
  15452. var transparentObjects = currentRenderList.transparent;
  15453. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  15454. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  15455. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  15456. if (_currentRenderTarget !== null) {
  15457. // Generate mipmap if we're using any kind of mipmap filtering
  15458. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  15459. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  15460. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  15461. state.buffers.depth.setTest(true);
  15462. state.buffers.depth.setMask(true);
  15463. state.buffers.color.setMask(true);
  15464. state.setPolygonOffset(false); // _gl.finish();
  15465. renderStateStack.pop();
  15466. if (renderStateStack.length > 0) {
  15467. currentRenderState = renderStateStack[renderStateStack.length - 1];
  15468. } else {
  15469. currentRenderState = null;
  15470. }
  15471. renderListStack.pop();
  15472. if (renderListStack.length > 0) {
  15473. currentRenderList = renderListStack[renderListStack.length - 1];
  15474. } else {
  15475. currentRenderList = null;
  15476. }
  15477. };
  15478. function projectObject(object, camera, groupOrder, sortObjects) {
  15479. if (object.visible === false) return;
  15480. var visible = object.layers.test(camera.layers);
  15481. if (visible) {
  15482. if (object.isGroup) {
  15483. groupOrder = object.renderOrder;
  15484. } else if (object.isLOD) {
  15485. if (object.autoUpdate === true) object.update(camera);
  15486. } else if (object.isLight) {
  15487. currentRenderState.pushLight(object);
  15488. if (object.castShadow) {
  15489. currentRenderState.pushShadow(object);
  15490. }
  15491. } else if (object.isSprite) {
  15492. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  15493. if (sortObjects) {
  15494. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15495. }
  15496. var geometry = objects.update(object);
  15497. var material = object.material;
  15498. if (material.visible) {
  15499. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  15500. }
  15501. }
  15502. } else if (object.isImmediateRenderObject) {
  15503. if (sortObjects) {
  15504. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15505. }
  15506. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  15507. } else if (object.isMesh || object.isLine || object.isPoints) {
  15508. if (object.isSkinnedMesh) {
  15509. // update skeleton only once in a frame
  15510. if (object.skeleton.frame !== info.render.frame) {
  15511. object.skeleton.update();
  15512. object.skeleton.frame = info.render.frame;
  15513. }
  15514. }
  15515. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  15516. if (sortObjects) {
  15517. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15518. }
  15519. var _geometry = objects.update(object);
  15520. var _material = object.material;
  15521. if (Array.isArray(_material)) {
  15522. var groups = _geometry.groups;
  15523. for (var i = 0, l = groups.length; i < l; i++) {
  15524. var group = groups[i];
  15525. var groupMaterial = _material[group.materialIndex];
  15526. if (groupMaterial && groupMaterial.visible) {
  15527. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  15528. }
  15529. }
  15530. } else if (_material.visible) {
  15531. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  15532. }
  15533. }
  15534. }
  15535. }
  15536. var children = object.children;
  15537. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  15538. projectObject(children[_i], camera, groupOrder, sortObjects);
  15539. }
  15540. }
  15541. function renderObjects(renderList, scene, camera) {
  15542. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15543. for (var i = 0, l = renderList.length; i < l; i++) {
  15544. var renderItem = renderList[i];
  15545. var object = renderItem.object;
  15546. var geometry = renderItem.geometry;
  15547. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15548. var group = renderItem.group;
  15549. if (camera.isArrayCamera) {
  15550. var cameras = camera.cameras;
  15551. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15552. var camera2 = cameras[j];
  15553. if (object.layers.test(camera2.layers)) {
  15554. state.viewport(_currentViewport.copy(camera2.viewport));
  15555. currentRenderState.setupLightsView(camera2);
  15556. renderObject(object, scene, camera2, geometry, material, group);
  15557. }
  15558. }
  15559. } else {
  15560. renderObject(object, scene, camera, geometry, material, group);
  15561. }
  15562. }
  15563. }
  15564. function renderObject(object, scene, camera, geometry, material, group) {
  15565. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15566. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15567. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15568. if (object.isImmediateRenderObject) {
  15569. var program = setProgram(camera, scene, material, object);
  15570. state.setMaterial(material);
  15571. bindingStates.reset();
  15572. renderObjectImmediate(object, program);
  15573. } else {
  15574. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15575. }
  15576. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15577. }
  15578. function initMaterial(material, scene, object) {
  15579. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15580. var materialProperties = properties.get(material);
  15581. var lights = currentRenderState.state.lights;
  15582. var shadowsArray = currentRenderState.state.shadowsArray;
  15583. var lightsStateVersion = lights.state.version;
  15584. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15585. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15586. var program = materialProperties.program;
  15587. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15588. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15589. materialProperties.fog = scene.fog;
  15590. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15591. if (program === undefined) {
  15592. // new material
  15593. material.addEventListener('dispose', onMaterialDispose);
  15594. } else if (program.cacheKey !== programCacheKey) {
  15595. // changed glsl or parameters
  15596. releaseMaterialProgramReference(material);
  15597. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15598. programChange = false;
  15599. } else if (parameters.shaderID !== undefined) {
  15600. // same glsl and uniform list
  15601. return;
  15602. } else {
  15603. // only rebuild uniform list
  15604. programChange = false;
  15605. }
  15606. if (programChange) {
  15607. parameters.uniforms = programCache.getUniforms(material);
  15608. material.onBeforeCompile(parameters, _this);
  15609. program = programCache.acquireProgram(parameters, programCacheKey);
  15610. materialProperties.program = program;
  15611. materialProperties.uniforms = parameters.uniforms;
  15612. materialProperties.outputEncoding = parameters.outputEncoding;
  15613. }
  15614. var uniforms = materialProperties.uniforms;
  15615. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15616. materialProperties.numClippingPlanes = clipping.numPlanes;
  15617. materialProperties.numIntersection = clipping.numIntersection;
  15618. uniforms.clippingPlanes = clipping.uniform;
  15619. } // store the light setup it was created for
  15620. materialProperties.needsLights = materialNeedsLights(material);
  15621. materialProperties.lightsStateVersion = lightsStateVersion;
  15622. if (materialProperties.needsLights) {
  15623. // wire up the material to this renderer's lighting state
  15624. uniforms.ambientLightColor.value = lights.state.ambient;
  15625. uniforms.lightProbe.value = lights.state.probe;
  15626. uniforms.directionalLights.value = lights.state.directional;
  15627. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15628. uniforms.spotLights.value = lights.state.spot;
  15629. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15630. uniforms.rectAreaLights.value = lights.state.rectArea;
  15631. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15632. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15633. uniforms.pointLights.value = lights.state.point;
  15634. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15635. uniforms.hemisphereLights.value = lights.state.hemi;
  15636. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15637. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15638. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15639. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15640. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15641. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15642. }
  15643. var progUniforms = materialProperties.program.getUniforms();
  15644. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15645. materialProperties.uniformsList = uniformsList;
  15646. }
  15647. function setProgram(camera, scene, material, object) {
  15648. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15649. textures.resetTextureUnits();
  15650. var fog = scene.fog;
  15651. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15652. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15653. var envMap = cubemaps.get(material.envMap || environment);
  15654. var materialProperties = properties.get(material);
  15655. var lights = currentRenderState.state.lights;
  15656. if (_clippingEnabled === true) {
  15657. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15658. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15659. // object instead of the material, once it becomes feasible
  15660. // (#8465, #8379)
  15661. clipping.setState(material, camera, useCache);
  15662. }
  15663. }
  15664. if (material.version === materialProperties.__version) {
  15665. if (material.fog && materialProperties.fog !== fog) {
  15666. initMaterial(material, scene, object);
  15667. } else if (materialProperties.environment !== environment) {
  15668. initMaterial(material, scene, object);
  15669. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15670. initMaterial(material, scene, object);
  15671. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15672. initMaterial(material, scene, object);
  15673. } else if (materialProperties.outputEncoding !== encoding) {
  15674. initMaterial(material, scene, object);
  15675. } else if (materialProperties.envMap !== envMap) {
  15676. initMaterial(material, scene, object);
  15677. }
  15678. } else {
  15679. initMaterial(material, scene, object);
  15680. materialProperties.__version = material.version;
  15681. }
  15682. var refreshProgram = false;
  15683. var refreshMaterial = false;
  15684. var refreshLights = false;
  15685. var program = materialProperties.program,
  15686. p_uniforms = program.getUniforms(),
  15687. m_uniforms = materialProperties.uniforms;
  15688. if (state.useProgram(program.program)) {
  15689. refreshProgram = true;
  15690. refreshMaterial = true;
  15691. refreshLights = true;
  15692. }
  15693. if (material.id !== _currentMaterialId) {
  15694. _currentMaterialId = material.id;
  15695. refreshMaterial = true;
  15696. }
  15697. if (refreshProgram || _currentCamera !== camera) {
  15698. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15699. if (capabilities.logarithmicDepthBuffer) {
  15700. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15701. }
  15702. if (_currentCamera !== camera) {
  15703. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15704. // now, in case this material supports lights - or later, when
  15705. // the next material that does gets activated:
  15706. refreshMaterial = true; // set to true on material change
  15707. refreshLights = true; // remains set until update done
  15708. } // load material specific uniforms
  15709. // (shader material also gets them for the sake of genericity)
  15710. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15711. var uCamPos = p_uniforms.map.cameraPosition;
  15712. if (uCamPos !== undefined) {
  15713. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15714. }
  15715. }
  15716. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15717. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15718. }
  15719. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15720. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15721. }
  15722. } // skinning uniforms must be set even if material didn't change
  15723. // auto-setting of texture unit for bone texture must go before other textures
  15724. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15725. if (material.skinning) {
  15726. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15727. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15728. var skeleton = object.skeleton;
  15729. if (skeleton) {
  15730. var bones = skeleton.bones;
  15731. if (capabilities.floatVertexTextures) {
  15732. if (skeleton.boneTexture === null) {
  15733. // layout (1 matrix = 4 pixels)
  15734. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15735. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15736. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15737. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15738. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15739. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15740. size = MathUtils.ceilPowerOfTwo(size);
  15741. size = Math.max(size, 4);
  15742. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15743. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15744. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15745. skeleton.boneMatrices = boneMatrices;
  15746. skeleton.boneTexture = boneTexture;
  15747. skeleton.boneTextureSize = size;
  15748. }
  15749. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15750. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15751. } else {
  15752. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15753. }
  15754. }
  15755. }
  15756. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15757. materialProperties.receiveShadow = object.receiveShadow;
  15758. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15759. }
  15760. if (refreshMaterial) {
  15761. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15762. if (materialProperties.needsLights) {
  15763. // the current material requires lighting info
  15764. // note: all lighting uniforms are always set correctly
  15765. // they simply reference the renderer's state for their
  15766. // values
  15767. //
  15768. // use the current material's .needsUpdate flags to set
  15769. // the GL state when required
  15770. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15771. } // refresh uniforms common to several materials
  15772. if (fog && material.fog) {
  15773. materials.refreshFogUniforms(m_uniforms, fog);
  15774. }
  15775. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15776. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15777. }
  15778. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15779. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15780. material.uniformsNeedUpdate = false;
  15781. }
  15782. if (material.isSpriteMaterial) {
  15783. p_uniforms.setValue(_gl, 'center', object.center);
  15784. } // common matrices
  15785. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15786. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15787. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15788. return program;
  15789. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15790. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15791. uniforms.ambientLightColor.needsUpdate = value;
  15792. uniforms.lightProbe.needsUpdate = value;
  15793. uniforms.directionalLights.needsUpdate = value;
  15794. uniforms.directionalLightShadows.needsUpdate = value;
  15795. uniforms.pointLights.needsUpdate = value;
  15796. uniforms.pointLightShadows.needsUpdate = value;
  15797. uniforms.spotLights.needsUpdate = value;
  15798. uniforms.spotLightShadows.needsUpdate = value;
  15799. uniforms.rectAreaLights.needsUpdate = value;
  15800. uniforms.hemisphereLights.needsUpdate = value;
  15801. }
  15802. function materialNeedsLights(material) {
  15803. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15804. } //
  15805. this.setFramebuffer = function (value) {
  15806. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15807. _framebuffer = value;
  15808. };
  15809. this.getActiveCubeFace = function () {
  15810. return _currentActiveCubeFace;
  15811. };
  15812. this.getActiveMipmapLevel = function () {
  15813. return _currentActiveMipmapLevel;
  15814. };
  15815. this.getRenderTarget = function () {
  15816. return _currentRenderTarget;
  15817. };
  15818. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15819. if (activeCubeFace === void 0) {
  15820. activeCubeFace = 0;
  15821. }
  15822. if (activeMipmapLevel === void 0) {
  15823. activeMipmapLevel = 0;
  15824. }
  15825. _currentRenderTarget = renderTarget;
  15826. _currentActiveCubeFace = activeCubeFace;
  15827. _currentActiveMipmapLevel = activeMipmapLevel;
  15828. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15829. textures.setupRenderTarget(renderTarget);
  15830. }
  15831. var framebuffer = _framebuffer;
  15832. var isCube = false;
  15833. var isRenderTarget3D = false;
  15834. if (renderTarget) {
  15835. var texture = renderTarget.texture;
  15836. if (texture.isDataTexture3D || texture.isDataTexture2DArray) {
  15837. isRenderTarget3D = true;
  15838. }
  15839. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15840. if (renderTarget.isWebGLCubeRenderTarget) {
  15841. framebuffer = __webglFramebuffer[activeCubeFace];
  15842. isCube = true;
  15843. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15844. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15845. } else {
  15846. framebuffer = __webglFramebuffer;
  15847. }
  15848. _currentViewport.copy(renderTarget.viewport);
  15849. _currentScissor.copy(renderTarget.scissor);
  15850. _currentScissorTest = renderTarget.scissorTest;
  15851. } else {
  15852. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15853. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15854. _currentScissorTest = _scissorTest;
  15855. }
  15856. if (_currentFramebuffer !== framebuffer) {
  15857. _gl.bindFramebuffer(36160, framebuffer);
  15858. _currentFramebuffer = framebuffer;
  15859. }
  15860. state.viewport(_currentViewport);
  15861. state.scissor(_currentScissor);
  15862. state.setScissorTest(_currentScissorTest);
  15863. if (isCube) {
  15864. var textureProperties = properties.get(renderTarget.texture);
  15865. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15866. } else if (isRenderTarget3D) {
  15867. var _textureProperties = properties.get(renderTarget.texture);
  15868. var layer = activeCubeFace || 0;
  15869. _gl.framebufferTextureLayer(36160, 36064, _textureProperties.__webglTexture, activeMipmapLevel || 0, layer);
  15870. }
  15871. };
  15872. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15873. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15874. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15875. return;
  15876. }
  15877. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15878. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15879. framebuffer = framebuffer[activeCubeFaceIndex];
  15880. }
  15881. if (framebuffer) {
  15882. var restore = false;
  15883. if (framebuffer !== _currentFramebuffer) {
  15884. _gl.bindFramebuffer(36160, framebuffer);
  15885. restore = true;
  15886. }
  15887. try {
  15888. var texture = renderTarget.texture;
  15889. var textureFormat = texture.format;
  15890. var textureType = texture.type;
  15891. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15892. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15893. return;
  15894. }
  15895. var halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has('EXT_color_buffer_half_float') || capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float'));
  15896. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15897. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has('OES_texture_float') || extensions.has('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15898. !halfFloatSupportedByExt) {
  15899. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15900. return;
  15901. }
  15902. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15903. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15904. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15905. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15906. }
  15907. } else {
  15908. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15909. }
  15910. } finally {
  15911. if (restore) {
  15912. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15913. }
  15914. }
  15915. }
  15916. };
  15917. this.copyFramebufferToTexture = function (position, texture, level) {
  15918. if (level === void 0) {
  15919. level = 0;
  15920. }
  15921. var levelScale = Math.pow(2, -level);
  15922. var width = Math.floor(texture.image.width * levelScale);
  15923. var height = Math.floor(texture.image.height * levelScale);
  15924. var glFormat = utils.convert(texture.format);
  15925. textures.setTexture2D(texture, 0);
  15926. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15927. state.unbindTexture();
  15928. };
  15929. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15930. if (level === void 0) {
  15931. level = 0;
  15932. }
  15933. var width = srcTexture.image.width;
  15934. var height = srcTexture.image.height;
  15935. var glFormat = utils.convert(dstTexture.format);
  15936. var glType = utils.convert(dstTexture.type);
  15937. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15938. // parameters, make sure they are correct for the dstTexture
  15939. _gl.pixelStorei(37440, dstTexture.flipY);
  15940. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15941. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15942. if (srcTexture.isDataTexture) {
  15943. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15944. } else {
  15945. if (srcTexture.isCompressedTexture) {
  15946. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15947. } else {
  15948. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15949. }
  15950. } // Generate mipmaps only when copying level 0
  15951. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15952. state.unbindTexture();
  15953. };
  15954. this.initTexture = function (texture) {
  15955. textures.setTexture2D(texture, 0);
  15956. state.unbindTexture();
  15957. };
  15958. this.resetState = function () {
  15959. state.reset();
  15960. bindingStates.reset();
  15961. };
  15962. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15963. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15964. detail: this
  15965. })); // eslint-disable-line no-undef
  15966. }
  15967. }
  15968. function WebGL1Renderer(parameters) {
  15969. WebGLRenderer.call(this, parameters);
  15970. }
  15971. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15972. constructor: WebGL1Renderer,
  15973. isWebGL1Renderer: true
  15974. });
  15975. var FogExp2 = /*#__PURE__*/function () {
  15976. function FogExp2(color, density) {
  15977. Object.defineProperty(this, 'isFogExp2', {
  15978. value: true
  15979. });
  15980. this.name = '';
  15981. this.color = new Color(color);
  15982. this.density = density !== undefined ? density : 0.00025;
  15983. }
  15984. var _proto = FogExp2.prototype;
  15985. _proto.clone = function clone() {
  15986. return new FogExp2(this.color, this.density);
  15987. };
  15988. _proto.toJSON = function toJSON()
  15989. /* meta */
  15990. {
  15991. return {
  15992. type: 'FogExp2',
  15993. color: this.color.getHex(),
  15994. density: this.density
  15995. };
  15996. };
  15997. return FogExp2;
  15998. }();
  15999. var Fog = /*#__PURE__*/function () {
  16000. function Fog(color, near, far) {
  16001. Object.defineProperty(this, 'isFog', {
  16002. value: true
  16003. });
  16004. this.name = '';
  16005. this.color = new Color(color);
  16006. this.near = near !== undefined ? near : 1;
  16007. this.far = far !== undefined ? far : 1000;
  16008. }
  16009. var _proto = Fog.prototype;
  16010. _proto.clone = function clone() {
  16011. return new Fog(this.color, this.near, this.far);
  16012. };
  16013. _proto.toJSON = function toJSON()
  16014. /* meta */
  16015. {
  16016. return {
  16017. type: 'Fog',
  16018. color: this.color.getHex(),
  16019. near: this.near,
  16020. far: this.far
  16021. };
  16022. };
  16023. return Fog;
  16024. }();
  16025. var Scene = /*#__PURE__*/function (_Object3D) {
  16026. _inheritsLoose(Scene, _Object3D);
  16027. function Scene() {
  16028. var _this;
  16029. _this = _Object3D.call(this) || this;
  16030. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  16031. value: true
  16032. });
  16033. _this.type = 'Scene';
  16034. _this.background = null;
  16035. _this.environment = null;
  16036. _this.fog = null;
  16037. _this.overrideMaterial = null;
  16038. _this.autoUpdate = true; // checked by the renderer
  16039. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  16040. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  16041. detail: _assertThisInitialized(_this)
  16042. })); // eslint-disable-line no-undef
  16043. }
  16044. return _this;
  16045. }
  16046. var _proto = Scene.prototype;
  16047. _proto.copy = function copy(source, recursive) {
  16048. _Object3D.prototype.copy.call(this, source, recursive);
  16049. if (source.background !== null) this.background = source.background.clone();
  16050. if (source.environment !== null) this.environment = source.environment.clone();
  16051. if (source.fog !== null) this.fog = source.fog.clone();
  16052. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  16053. this.autoUpdate = source.autoUpdate;
  16054. this.matrixAutoUpdate = source.matrixAutoUpdate;
  16055. return this;
  16056. };
  16057. _proto.toJSON = function toJSON(meta) {
  16058. var data = _Object3D.prototype.toJSON.call(this, meta);
  16059. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  16060. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  16061. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  16062. return data;
  16063. };
  16064. return Scene;
  16065. }(Object3D);
  16066. function InterleavedBuffer(array, stride) {
  16067. this.array = array;
  16068. this.stride = stride;
  16069. this.count = array !== undefined ? array.length / stride : 0;
  16070. this.usage = StaticDrawUsage;
  16071. this.updateRange = {
  16072. offset: 0,
  16073. count: -1
  16074. };
  16075. this.version = 0;
  16076. this.uuid = MathUtils.generateUUID();
  16077. }
  16078. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  16079. set: function set(value) {
  16080. if (value === true) this.version++;
  16081. }
  16082. });
  16083. Object.assign(InterleavedBuffer.prototype, {
  16084. isInterleavedBuffer: true,
  16085. onUploadCallback: function onUploadCallback() {},
  16086. setUsage: function setUsage(value) {
  16087. this.usage = value;
  16088. return this;
  16089. },
  16090. copy: function copy(source) {
  16091. this.array = new source.array.constructor(source.array);
  16092. this.count = source.count;
  16093. this.stride = source.stride;
  16094. this.usage = source.usage;
  16095. return this;
  16096. },
  16097. copyAt: function copyAt(index1, attribute, index2) {
  16098. index1 *= this.stride;
  16099. index2 *= attribute.stride;
  16100. for (var i = 0, l = this.stride; i < l; i++) {
  16101. this.array[index1 + i] = attribute.array[index2 + i];
  16102. }
  16103. return this;
  16104. },
  16105. set: function set(value, offset) {
  16106. if (offset === void 0) {
  16107. offset = 0;
  16108. }
  16109. this.array.set(value, offset);
  16110. return this;
  16111. },
  16112. clone: function clone(data) {
  16113. if (data.arrayBuffers === undefined) {
  16114. data.arrayBuffers = {};
  16115. }
  16116. if (this.array.buffer._uuid === undefined) {
  16117. this.array.buffer._uuid = MathUtils.generateUUID();
  16118. }
  16119. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16120. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  16121. }
  16122. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  16123. var ib = new InterleavedBuffer(array, this.stride);
  16124. ib.setUsage(this.usage);
  16125. return ib;
  16126. },
  16127. onUpload: function onUpload(callback) {
  16128. this.onUploadCallback = callback;
  16129. return this;
  16130. },
  16131. toJSON: function toJSON(data) {
  16132. if (data.arrayBuffers === undefined) {
  16133. data.arrayBuffers = {};
  16134. } // generate UUID for array buffer if necessary
  16135. if (this.array.buffer._uuid === undefined) {
  16136. this.array.buffer._uuid = MathUtils.generateUUID();
  16137. }
  16138. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16139. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  16140. } //
  16141. return {
  16142. uuid: this.uuid,
  16143. buffer: this.array.buffer._uuid,
  16144. type: this.array.constructor.name,
  16145. stride: this.stride
  16146. };
  16147. }
  16148. });
  16149. var _vector$6 = new Vector3();
  16150. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  16151. this.name = '';
  16152. this.data = interleavedBuffer;
  16153. this.itemSize = itemSize;
  16154. this.offset = offset;
  16155. this.normalized = normalized === true;
  16156. }
  16157. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  16158. count: {
  16159. get: function get() {
  16160. return this.data.count;
  16161. }
  16162. },
  16163. array: {
  16164. get: function get() {
  16165. return this.data.array;
  16166. }
  16167. },
  16168. needsUpdate: {
  16169. set: function set(value) {
  16170. this.data.needsUpdate = value;
  16171. }
  16172. }
  16173. });
  16174. Object.assign(InterleavedBufferAttribute.prototype, {
  16175. isInterleavedBufferAttribute: true,
  16176. applyMatrix4: function applyMatrix4(m) {
  16177. for (var i = 0, l = this.data.count; i < l; i++) {
  16178. _vector$6.x = this.getX(i);
  16179. _vector$6.y = this.getY(i);
  16180. _vector$6.z = this.getZ(i);
  16181. _vector$6.applyMatrix4(m);
  16182. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  16183. }
  16184. return this;
  16185. },
  16186. setX: function setX(index, x) {
  16187. this.data.array[index * this.data.stride + this.offset] = x;
  16188. return this;
  16189. },
  16190. setY: function setY(index, y) {
  16191. this.data.array[index * this.data.stride + this.offset + 1] = y;
  16192. return this;
  16193. },
  16194. setZ: function setZ(index, z) {
  16195. this.data.array[index * this.data.stride + this.offset + 2] = z;
  16196. return this;
  16197. },
  16198. setW: function setW(index, w) {
  16199. this.data.array[index * this.data.stride + this.offset + 3] = w;
  16200. return this;
  16201. },
  16202. getX: function getX(index) {
  16203. return this.data.array[index * this.data.stride + this.offset];
  16204. },
  16205. getY: function getY(index) {
  16206. return this.data.array[index * this.data.stride + this.offset + 1];
  16207. },
  16208. getZ: function getZ(index) {
  16209. return this.data.array[index * this.data.stride + this.offset + 2];
  16210. },
  16211. getW: function getW(index) {
  16212. return this.data.array[index * this.data.stride + this.offset + 3];
  16213. },
  16214. setXY: function setXY(index, x, y) {
  16215. index = index * this.data.stride + this.offset;
  16216. this.data.array[index + 0] = x;
  16217. this.data.array[index + 1] = y;
  16218. return this;
  16219. },
  16220. setXYZ: function setXYZ(index, x, y, z) {
  16221. index = index * this.data.stride + this.offset;
  16222. this.data.array[index + 0] = x;
  16223. this.data.array[index + 1] = y;
  16224. this.data.array[index + 2] = z;
  16225. return this;
  16226. },
  16227. setXYZW: function setXYZW(index, x, y, z, w) {
  16228. index = index * this.data.stride + this.offset;
  16229. this.data.array[index + 0] = x;
  16230. this.data.array[index + 1] = y;
  16231. this.data.array[index + 2] = z;
  16232. this.data.array[index + 3] = w;
  16233. return this;
  16234. },
  16235. clone: function clone(data) {
  16236. if (data === undefined) {
  16237. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  16238. var array = [];
  16239. for (var i = 0; i < this.count; i++) {
  16240. var index = i * this.data.stride + this.offset;
  16241. for (var j = 0; j < this.itemSize; j++) {
  16242. array.push(this.data.array[index + j]);
  16243. }
  16244. }
  16245. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  16246. } else {
  16247. if (data.interleavedBuffers === undefined) {
  16248. data.interleavedBuffers = {};
  16249. }
  16250. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16251. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  16252. }
  16253. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  16254. }
  16255. },
  16256. toJSON: function toJSON(data) {
  16257. if (data === undefined) {
  16258. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  16259. var array = [];
  16260. for (var i = 0; i < this.count; i++) {
  16261. var index = i * this.data.stride + this.offset;
  16262. for (var j = 0; j < this.itemSize; j++) {
  16263. array.push(this.data.array[index + j]);
  16264. }
  16265. } // deinterleave data and save it as an ordinary buffer attribute for now
  16266. return {
  16267. itemSize: this.itemSize,
  16268. type: this.array.constructor.name,
  16269. array: array,
  16270. normalized: this.normalized
  16271. };
  16272. } else {
  16273. // save as true interlaved attribtue
  16274. if (data.interleavedBuffers === undefined) {
  16275. data.interleavedBuffers = {};
  16276. }
  16277. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16278. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  16279. }
  16280. return {
  16281. isInterleavedBufferAttribute: true,
  16282. itemSize: this.itemSize,
  16283. data: this.data.uuid,
  16284. offset: this.offset,
  16285. normalized: this.normalized
  16286. };
  16287. }
  16288. }
  16289. });
  16290. /**
  16291. * parameters = {
  16292. * color: <hex>,
  16293. * map: new THREE.Texture( <Image> ),
  16294. * alphaMap: new THREE.Texture( <Image> ),
  16295. * rotation: <float>,
  16296. * sizeAttenuation: <bool>
  16297. * }
  16298. */
  16299. function SpriteMaterial(parameters) {
  16300. Material.call(this);
  16301. this.type = 'SpriteMaterial';
  16302. this.color = new Color(0xffffff);
  16303. this.map = null;
  16304. this.alphaMap = null;
  16305. this.rotation = 0;
  16306. this.sizeAttenuation = true;
  16307. this.transparent = true;
  16308. this.setValues(parameters);
  16309. }
  16310. SpriteMaterial.prototype = Object.create(Material.prototype);
  16311. SpriteMaterial.prototype.constructor = SpriteMaterial;
  16312. SpriteMaterial.prototype.isSpriteMaterial = true;
  16313. SpriteMaterial.prototype.copy = function (source) {
  16314. Material.prototype.copy.call(this, source);
  16315. this.color.copy(source.color);
  16316. this.map = source.map;
  16317. this.alphaMap = source.alphaMap;
  16318. this.rotation = source.rotation;
  16319. this.sizeAttenuation = source.sizeAttenuation;
  16320. return this;
  16321. };
  16322. var _geometry;
  16323. var _intersectPoint = /*@__PURE__*/new Vector3();
  16324. var _worldScale = /*@__PURE__*/new Vector3();
  16325. var _mvPosition = /*@__PURE__*/new Vector3();
  16326. var _alignedPosition = /*@__PURE__*/new Vector2();
  16327. var _rotatedPosition = /*@__PURE__*/new Vector2();
  16328. var _viewWorldMatrix = /*@__PURE__*/new Matrix4();
  16329. var _vA$1 = /*@__PURE__*/new Vector3();
  16330. var _vB$1 = /*@__PURE__*/new Vector3();
  16331. var _vC$1 = /*@__PURE__*/new Vector3();
  16332. var _uvA$1 = /*@__PURE__*/new Vector2();
  16333. var _uvB$1 = /*@__PURE__*/new Vector2();
  16334. var _uvC$1 = /*@__PURE__*/new Vector2();
  16335. var Sprite = /*#__PURE__*/function (_Object3D) {
  16336. _inheritsLoose(Sprite, _Object3D);
  16337. function Sprite(material) {
  16338. var _this;
  16339. _this = _Object3D.call(this) || this;
  16340. _this.type = 'Sprite';
  16341. if (_geometry === undefined) {
  16342. _geometry = new BufferGeometry();
  16343. 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]);
  16344. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  16345. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  16346. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  16347. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  16348. }
  16349. _this.geometry = _geometry;
  16350. _this.material = material !== undefined ? material : new SpriteMaterial();
  16351. _this.center = new Vector2(0.5, 0.5);
  16352. Object.defineProperty(_assertThisInitialized(_this), 'isSprite', {
  16353. value: true
  16354. });
  16355. return _this;
  16356. }
  16357. var _proto = Sprite.prototype;
  16358. _proto.raycast = function raycast(raycaster, intersects) {
  16359. if (raycaster.camera === null) {
  16360. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  16361. }
  16362. _worldScale.setFromMatrixScale(this.matrixWorld);
  16363. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  16364. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  16365. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  16366. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  16367. _worldScale.multiplyScalar(-_mvPosition.z);
  16368. }
  16369. var rotation = this.material.rotation;
  16370. var sin, cos;
  16371. if (rotation !== 0) {
  16372. cos = Math.cos(rotation);
  16373. sin = Math.sin(rotation);
  16374. }
  16375. var center = this.center;
  16376. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16377. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16378. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16379. _uvA$1.set(0, 0);
  16380. _uvB$1.set(1, 0);
  16381. _uvC$1.set(1, 1); // check first triangle
  16382. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  16383. if (intersect === null) {
  16384. // check second triangle
  16385. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16386. _uvB$1.set(0, 1);
  16387. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  16388. if (intersect === null) {
  16389. return;
  16390. }
  16391. }
  16392. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  16393. if (distance < raycaster.near || distance > raycaster.far) return;
  16394. intersects.push({
  16395. distance: distance,
  16396. point: _intersectPoint.clone(),
  16397. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  16398. face: null,
  16399. object: this
  16400. });
  16401. };
  16402. _proto.copy = function copy(source) {
  16403. Object3D.prototype.copy.call(this, source);
  16404. if (source.center !== undefined) this.center.copy(source.center);
  16405. this.material = source.material;
  16406. return this;
  16407. };
  16408. return Sprite;
  16409. }(Object3D);
  16410. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  16411. // compute position in camera space
  16412. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  16413. if (sin !== undefined) {
  16414. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  16415. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  16416. } else {
  16417. _rotatedPosition.copy(_alignedPosition);
  16418. }
  16419. vertexPosition.copy(mvPosition);
  16420. vertexPosition.x += _rotatedPosition.x;
  16421. vertexPosition.y += _rotatedPosition.y; // transform to world space
  16422. vertexPosition.applyMatrix4(_viewWorldMatrix);
  16423. }
  16424. var _v1$4 = /*@__PURE__*/new Vector3();
  16425. var _v2$2 = /*@__PURE__*/new Vector3();
  16426. var LOD = /*#__PURE__*/function (_Object3D) {
  16427. _inheritsLoose(LOD, _Object3D);
  16428. function LOD() {
  16429. var _this;
  16430. _this = _Object3D.call(this) || this;
  16431. _this._currentLevel = 0;
  16432. _this.type = 'LOD';
  16433. Object.defineProperties(_assertThisInitialized(_this), {
  16434. levels: {
  16435. enumerable: true,
  16436. value: []
  16437. },
  16438. isLOD: {
  16439. value: true
  16440. }
  16441. });
  16442. _this.autoUpdate = true;
  16443. return _this;
  16444. }
  16445. var _proto = LOD.prototype;
  16446. _proto.copy = function copy(source) {
  16447. _Object3D.prototype.copy.call(this, source, false);
  16448. var levels = source.levels;
  16449. for (var i = 0, l = levels.length; i < l; i++) {
  16450. var level = levels[i];
  16451. this.addLevel(level.object.clone(), level.distance);
  16452. }
  16453. this.autoUpdate = source.autoUpdate;
  16454. return this;
  16455. };
  16456. _proto.addLevel = function addLevel(object, distance) {
  16457. if (distance === void 0) {
  16458. distance = 0;
  16459. }
  16460. distance = Math.abs(distance);
  16461. var levels = this.levels;
  16462. var l;
  16463. for (l = 0; l < levels.length; l++) {
  16464. if (distance < levels[l].distance) {
  16465. break;
  16466. }
  16467. }
  16468. levels.splice(l, 0, {
  16469. distance: distance,
  16470. object: object
  16471. });
  16472. this.add(object);
  16473. return this;
  16474. };
  16475. _proto.getCurrentLevel = function getCurrentLevel() {
  16476. return this._currentLevel;
  16477. };
  16478. _proto.getObjectForDistance = function getObjectForDistance(distance) {
  16479. var levels = this.levels;
  16480. if (levels.length > 0) {
  16481. var i, l;
  16482. for (i = 1, l = levels.length; i < l; i++) {
  16483. if (distance < levels[i].distance) {
  16484. break;
  16485. }
  16486. }
  16487. return levels[i - 1].object;
  16488. }
  16489. return null;
  16490. };
  16491. _proto.raycast = function raycast(raycaster, intersects) {
  16492. var levels = this.levels;
  16493. if (levels.length > 0) {
  16494. _v1$4.setFromMatrixPosition(this.matrixWorld);
  16495. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  16496. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  16497. }
  16498. };
  16499. _proto.update = function update(camera) {
  16500. var levels = this.levels;
  16501. if (levels.length > 1) {
  16502. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  16503. _v2$2.setFromMatrixPosition(this.matrixWorld);
  16504. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  16505. levels[0].object.visible = true;
  16506. var i, l;
  16507. for (i = 1, l = levels.length; i < l; i++) {
  16508. if (distance >= levels[i].distance) {
  16509. levels[i - 1].object.visible = false;
  16510. levels[i].object.visible = true;
  16511. } else {
  16512. break;
  16513. }
  16514. }
  16515. this._currentLevel = i - 1;
  16516. for (; i < l; i++) {
  16517. levels[i].object.visible = false;
  16518. }
  16519. }
  16520. };
  16521. _proto.toJSON = function toJSON(meta) {
  16522. var data = _Object3D.prototype.toJSON.call(this, meta);
  16523. if (this.autoUpdate === false) data.object.autoUpdate = false;
  16524. data.object.levels = [];
  16525. var levels = this.levels;
  16526. for (var i = 0, l = levels.length; i < l; i++) {
  16527. var level = levels[i];
  16528. data.object.levels.push({
  16529. object: level.object.uuid,
  16530. distance: level.distance
  16531. });
  16532. }
  16533. return data;
  16534. };
  16535. return LOD;
  16536. }(Object3D);
  16537. var _basePosition = new Vector3();
  16538. var _skinIndex = new Vector4();
  16539. var _skinWeight = new Vector4();
  16540. var _vector$7 = new Vector3();
  16541. var _matrix$1 = new Matrix4();
  16542. function SkinnedMesh(geometry, material) {
  16543. Mesh.call(this, geometry, material);
  16544. this.type = 'SkinnedMesh';
  16545. this.bindMode = 'attached';
  16546. this.bindMatrix = new Matrix4();
  16547. this.bindMatrixInverse = new Matrix4();
  16548. }
  16549. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16550. constructor: SkinnedMesh,
  16551. isSkinnedMesh: true,
  16552. copy: function copy(source) {
  16553. Mesh.prototype.copy.call(this, source);
  16554. this.bindMode = source.bindMode;
  16555. this.bindMatrix.copy(source.bindMatrix);
  16556. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  16557. this.skeleton = source.skeleton;
  16558. return this;
  16559. },
  16560. bind: function bind(skeleton, bindMatrix) {
  16561. this.skeleton = skeleton;
  16562. if (bindMatrix === undefined) {
  16563. this.updateMatrixWorld(true);
  16564. this.skeleton.calculateInverses();
  16565. bindMatrix = this.matrixWorld;
  16566. }
  16567. this.bindMatrix.copy(bindMatrix);
  16568. this.bindMatrixInverse.copy(bindMatrix).invert();
  16569. },
  16570. pose: function pose() {
  16571. this.skeleton.pose();
  16572. },
  16573. normalizeSkinWeights: function normalizeSkinWeights() {
  16574. var vector = new Vector4();
  16575. var skinWeight = this.geometry.attributes.skinWeight;
  16576. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16577. vector.x = skinWeight.getX(i);
  16578. vector.y = skinWeight.getY(i);
  16579. vector.z = skinWeight.getZ(i);
  16580. vector.w = skinWeight.getW(i);
  16581. var scale = 1.0 / vector.manhattanLength();
  16582. if (scale !== Infinity) {
  16583. vector.multiplyScalar(scale);
  16584. } else {
  16585. vector.set(1, 0, 0, 0); // do something reasonable
  16586. }
  16587. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16588. }
  16589. },
  16590. updateMatrixWorld: function updateMatrixWorld(force) {
  16591. Mesh.prototype.updateMatrixWorld.call(this, force);
  16592. if (this.bindMode === 'attached') {
  16593. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16594. } else if (this.bindMode === 'detached') {
  16595. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16596. } else {
  16597. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16598. }
  16599. },
  16600. boneTransform: function boneTransform(index, target) {
  16601. var skeleton = this.skeleton;
  16602. var geometry = this.geometry;
  16603. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16604. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16605. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16606. target.set(0, 0, 0);
  16607. for (var i = 0; i < 4; i++) {
  16608. var weight = _skinWeight.getComponent(i);
  16609. if (weight !== 0) {
  16610. var boneIndex = _skinIndex.getComponent(i);
  16611. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16612. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16613. }
  16614. }
  16615. return target.applyMatrix4(this.bindMatrixInverse);
  16616. }
  16617. });
  16618. function Bone() {
  16619. Object3D.call(this);
  16620. this.type = 'Bone';
  16621. }
  16622. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16623. constructor: Bone,
  16624. isBone: true
  16625. });
  16626. var _offsetMatrix = /*@__PURE__*/new Matrix4();
  16627. var _identityMatrix = /*@__PURE__*/new Matrix4();
  16628. var Skeleton = /*#__PURE__*/function () {
  16629. function Skeleton(bones, boneInverses) {
  16630. if (bones === void 0) {
  16631. bones = [];
  16632. }
  16633. if (boneInverses === void 0) {
  16634. boneInverses = [];
  16635. }
  16636. this.uuid = MathUtils.generateUUID();
  16637. this.bones = bones.slice(0);
  16638. this.boneInverses = boneInverses;
  16639. this.boneMatrices = null;
  16640. this.boneTexture = null;
  16641. this.boneTextureSize = 0;
  16642. this.frame = -1;
  16643. this.init();
  16644. }
  16645. var _proto = Skeleton.prototype;
  16646. _proto.init = function init() {
  16647. var bones = this.bones;
  16648. var boneInverses = this.boneInverses;
  16649. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16650. if (boneInverses.length === 0) {
  16651. this.calculateInverses();
  16652. } else {
  16653. // handle special case
  16654. if (bones.length !== boneInverses.length) {
  16655. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16656. this.boneInverses = [];
  16657. for (var i = 0, il = this.bones.length; i < il; i++) {
  16658. this.boneInverses.push(new Matrix4());
  16659. }
  16660. }
  16661. }
  16662. };
  16663. _proto.calculateInverses = function calculateInverses() {
  16664. this.boneInverses.length = 0;
  16665. for (var i = 0, il = this.bones.length; i < il; i++) {
  16666. var inverse = new Matrix4();
  16667. if (this.bones[i]) {
  16668. inverse.copy(this.bones[i].matrixWorld).invert();
  16669. }
  16670. this.boneInverses.push(inverse);
  16671. }
  16672. };
  16673. _proto.pose = function pose() {
  16674. // recover the bind-time world matrices
  16675. for (var i = 0, il = this.bones.length; i < il; i++) {
  16676. var bone = this.bones[i];
  16677. if (bone) {
  16678. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16679. }
  16680. } // compute the local matrices, positions, rotations and scales
  16681. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16682. var _bone = this.bones[_i];
  16683. if (_bone) {
  16684. if (_bone.parent && _bone.parent.isBone) {
  16685. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16686. _bone.matrix.multiply(_bone.matrixWorld);
  16687. } else {
  16688. _bone.matrix.copy(_bone.matrixWorld);
  16689. }
  16690. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16691. }
  16692. }
  16693. };
  16694. _proto.update = function update() {
  16695. var bones = this.bones;
  16696. var boneInverses = this.boneInverses;
  16697. var boneMatrices = this.boneMatrices;
  16698. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16699. for (var i = 0, il = bones.length; i < il; i++) {
  16700. // compute the offset between the current and the original transform
  16701. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16702. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16703. _offsetMatrix.toArray(boneMatrices, i * 16);
  16704. }
  16705. if (boneTexture !== null) {
  16706. boneTexture.needsUpdate = true;
  16707. }
  16708. };
  16709. _proto.clone = function clone() {
  16710. return new Skeleton(this.bones, this.boneInverses);
  16711. };
  16712. _proto.getBoneByName = function getBoneByName(name) {
  16713. for (var i = 0, il = this.bones.length; i < il; i++) {
  16714. var bone = this.bones[i];
  16715. if (bone.name === name) {
  16716. return bone;
  16717. }
  16718. }
  16719. return undefined;
  16720. };
  16721. _proto.dispose = function dispose() {
  16722. if (this.boneTexture !== null) {
  16723. this.boneTexture.dispose();
  16724. this.boneTexture = null;
  16725. }
  16726. };
  16727. _proto.fromJSON = function fromJSON(json, bones) {
  16728. this.uuid = json.uuid;
  16729. for (var i = 0, l = json.bones.length; i < l; i++) {
  16730. var uuid = json.bones[i];
  16731. var bone = bones[uuid];
  16732. if (bone === undefined) {
  16733. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16734. bone = new Bone();
  16735. }
  16736. this.bones.push(bone);
  16737. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16738. }
  16739. this.init();
  16740. return this;
  16741. };
  16742. _proto.toJSON = function toJSON() {
  16743. var data = {
  16744. metadata: {
  16745. version: 4.5,
  16746. type: 'Skeleton',
  16747. generator: 'Skeleton.toJSON'
  16748. },
  16749. bones: [],
  16750. boneInverses: []
  16751. };
  16752. data.uuid = this.uuid;
  16753. var bones = this.bones;
  16754. var boneInverses = this.boneInverses;
  16755. for (var i = 0, l = bones.length; i < l; i++) {
  16756. var bone = bones[i];
  16757. data.bones.push(bone.uuid);
  16758. var boneInverse = boneInverses[i];
  16759. data.boneInverses.push(boneInverse.toArray());
  16760. }
  16761. return data;
  16762. };
  16763. return Skeleton;
  16764. }();
  16765. var _instanceLocalMatrix = new Matrix4();
  16766. var _instanceWorldMatrix = new Matrix4();
  16767. var _instanceIntersects = [];
  16768. var _mesh = new Mesh();
  16769. function InstancedMesh(geometry, material, count) {
  16770. Mesh.call(this, geometry, material);
  16771. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16772. this.instanceColor = null;
  16773. this.count = count;
  16774. this.frustumCulled = false;
  16775. }
  16776. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16777. constructor: InstancedMesh,
  16778. isInstancedMesh: true,
  16779. copy: function copy(source) {
  16780. Mesh.prototype.copy.call(this, source);
  16781. this.instanceMatrix.copy(source.instanceMatrix);
  16782. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16783. this.count = source.count;
  16784. return this;
  16785. },
  16786. getColorAt: function getColorAt(index, color) {
  16787. color.fromArray(this.instanceColor.array, index * 3);
  16788. },
  16789. getMatrixAt: function getMatrixAt(index, matrix) {
  16790. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16791. },
  16792. raycast: function raycast(raycaster, intersects) {
  16793. var matrixWorld = this.matrixWorld;
  16794. var raycastTimes = this.count;
  16795. _mesh.geometry = this.geometry;
  16796. _mesh.material = this.material;
  16797. if (_mesh.material === undefined) return;
  16798. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16799. // calculate the world matrix for each instance
  16800. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16801. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16802. _mesh.matrixWorld = _instanceWorldMatrix;
  16803. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16804. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16805. var intersect = _instanceIntersects[i];
  16806. intersect.instanceId = instanceId;
  16807. intersect.object = this;
  16808. intersects.push(intersect);
  16809. }
  16810. _instanceIntersects.length = 0;
  16811. }
  16812. },
  16813. setColorAt: function setColorAt(index, color) {
  16814. if (this.instanceColor === null) {
  16815. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16816. }
  16817. color.toArray(this.instanceColor.array, index * 3);
  16818. },
  16819. setMatrixAt: function setMatrixAt(index, matrix) {
  16820. matrix.toArray(this.instanceMatrix.array, index * 16);
  16821. },
  16822. updateMorphTargets: function updateMorphTargets() {},
  16823. dispose: function dispose() {
  16824. this.dispatchEvent({
  16825. type: 'dispose'
  16826. });
  16827. }
  16828. });
  16829. /**
  16830. * parameters = {
  16831. * color: <hex>,
  16832. * opacity: <float>,
  16833. *
  16834. * linewidth: <float>,
  16835. * linecap: "round",
  16836. * linejoin: "round"
  16837. * }
  16838. */
  16839. function LineBasicMaterial(parameters) {
  16840. Material.call(this);
  16841. this.type = 'LineBasicMaterial';
  16842. this.color = new Color(0xffffff);
  16843. this.linewidth = 1;
  16844. this.linecap = 'round';
  16845. this.linejoin = 'round';
  16846. this.morphTargets = false;
  16847. this.setValues(parameters);
  16848. }
  16849. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16850. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16851. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16852. LineBasicMaterial.prototype.copy = function (source) {
  16853. Material.prototype.copy.call(this, source);
  16854. this.color.copy(source.color);
  16855. this.linewidth = source.linewidth;
  16856. this.linecap = source.linecap;
  16857. this.linejoin = source.linejoin;
  16858. this.morphTargets = source.morphTargets;
  16859. return this;
  16860. };
  16861. var _start = new Vector3();
  16862. var _end = new Vector3();
  16863. var _inverseMatrix$1 = new Matrix4();
  16864. var _ray$1 = new Ray();
  16865. var _sphere$2 = new Sphere();
  16866. function Line(geometry, material) {
  16867. if (geometry === void 0) {
  16868. geometry = new BufferGeometry();
  16869. }
  16870. if (material === void 0) {
  16871. material = new LineBasicMaterial();
  16872. }
  16873. Object3D.call(this);
  16874. this.type = 'Line';
  16875. this.geometry = geometry;
  16876. this.material = material;
  16877. this.updateMorphTargets();
  16878. }
  16879. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16880. constructor: Line,
  16881. isLine: true,
  16882. copy: function copy(source) {
  16883. Object3D.prototype.copy.call(this, source);
  16884. this.material = source.material;
  16885. this.geometry = source.geometry;
  16886. return this;
  16887. },
  16888. computeLineDistances: function computeLineDistances() {
  16889. var geometry = this.geometry;
  16890. if (geometry.isBufferGeometry) {
  16891. // we assume non-indexed geometry
  16892. if (geometry.index === null) {
  16893. var positionAttribute = geometry.attributes.position;
  16894. var lineDistances = [0];
  16895. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16896. _start.fromBufferAttribute(positionAttribute, i - 1);
  16897. _end.fromBufferAttribute(positionAttribute, i);
  16898. lineDistances[i] = lineDistances[i - 1];
  16899. lineDistances[i] += _start.distanceTo(_end);
  16900. }
  16901. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16902. } else {
  16903. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16904. }
  16905. } else if (geometry.isGeometry) {
  16906. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16907. }
  16908. return this;
  16909. },
  16910. raycast: function raycast(raycaster, intersects) {
  16911. var geometry = this.geometry;
  16912. var matrixWorld = this.matrixWorld;
  16913. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16914. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16915. _sphere$2.copy(geometry.boundingSphere);
  16916. _sphere$2.applyMatrix4(matrixWorld);
  16917. _sphere$2.radius += threshold;
  16918. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16919. _inverseMatrix$1.copy(matrixWorld).invert();
  16920. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16921. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16922. var localThresholdSq = localThreshold * localThreshold;
  16923. var vStart = new Vector3();
  16924. var vEnd = new Vector3();
  16925. var interSegment = new Vector3();
  16926. var interRay = new Vector3();
  16927. var step = this.isLineSegments ? 2 : 1;
  16928. if (geometry.isBufferGeometry) {
  16929. var index = geometry.index;
  16930. var attributes = geometry.attributes;
  16931. var positionAttribute = attributes.position;
  16932. if (index !== null) {
  16933. var indices = index.array;
  16934. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16935. var a = indices[i];
  16936. var b = indices[i + 1];
  16937. vStart.fromBufferAttribute(positionAttribute, a);
  16938. vEnd.fromBufferAttribute(positionAttribute, b);
  16939. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16940. if (distSq > localThresholdSq) continue;
  16941. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16942. var distance = raycaster.ray.origin.distanceTo(interRay);
  16943. if (distance < raycaster.near || distance > raycaster.far) continue;
  16944. intersects.push({
  16945. distance: distance,
  16946. // What do we want? intersection point on the ray or on the segment??
  16947. // point: raycaster.ray.at( distance ),
  16948. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16949. index: i,
  16950. face: null,
  16951. faceIndex: null,
  16952. object: this
  16953. });
  16954. }
  16955. } else {
  16956. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  16957. vStart.fromBufferAttribute(positionAttribute, _i);
  16958. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  16959. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16960. if (_distSq > localThresholdSq) continue;
  16961. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16962. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16963. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16964. intersects.push({
  16965. distance: _distance,
  16966. // What do we want? intersection point on the ray or on the segment??
  16967. // point: raycaster.ray.at( distance ),
  16968. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16969. index: _i,
  16970. face: null,
  16971. faceIndex: null,
  16972. object: this
  16973. });
  16974. }
  16975. }
  16976. } else if (geometry.isGeometry) {
  16977. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16978. }
  16979. },
  16980. updateMorphTargets: function updateMorphTargets() {
  16981. var geometry = this.geometry;
  16982. if (geometry.isBufferGeometry) {
  16983. var morphAttributes = geometry.morphAttributes;
  16984. var keys = Object.keys(morphAttributes);
  16985. if (keys.length > 0) {
  16986. var morphAttribute = morphAttributes[keys[0]];
  16987. if (morphAttribute !== undefined) {
  16988. this.morphTargetInfluences = [];
  16989. this.morphTargetDictionary = {};
  16990. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16991. var name = morphAttribute[m].name || String(m);
  16992. this.morphTargetInfluences.push(0);
  16993. this.morphTargetDictionary[name] = m;
  16994. }
  16995. }
  16996. }
  16997. } else {
  16998. var morphTargets = geometry.morphTargets;
  16999. if (morphTargets !== undefined && morphTargets.length > 0) {
  17000. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17001. }
  17002. }
  17003. }
  17004. });
  17005. var _start$1 = new Vector3();
  17006. var _end$1 = new Vector3();
  17007. function LineSegments(geometry, material) {
  17008. Line.call(this, geometry, material);
  17009. this.type = 'LineSegments';
  17010. }
  17011. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  17012. constructor: LineSegments,
  17013. isLineSegments: true,
  17014. computeLineDistances: function computeLineDistances() {
  17015. var geometry = this.geometry;
  17016. if (geometry.isBufferGeometry) {
  17017. // we assume non-indexed geometry
  17018. if (geometry.index === null) {
  17019. var positionAttribute = geometry.attributes.position;
  17020. var lineDistances = [];
  17021. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  17022. _start$1.fromBufferAttribute(positionAttribute, i);
  17023. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  17024. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  17025. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  17026. }
  17027. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  17028. } else {
  17029. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  17030. }
  17031. } else if (geometry.isGeometry) {
  17032. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17033. }
  17034. return this;
  17035. }
  17036. });
  17037. var LineLoop = /*#__PURE__*/function (_Line) {
  17038. _inheritsLoose(LineLoop, _Line);
  17039. function LineLoop(geometry, material) {
  17040. var _this;
  17041. _this = _Line.call(this, geometry, material) || this;
  17042. _this.type = 'LineLoop';
  17043. Object.defineProperty(_assertThisInitialized(_this), 'isLineLoop', {
  17044. value: true
  17045. });
  17046. return _this;
  17047. }
  17048. return LineLoop;
  17049. }(Line);
  17050. /**
  17051. * parameters = {
  17052. * color: <hex>,
  17053. * opacity: <float>,
  17054. * map: new THREE.Texture( <Image> ),
  17055. * alphaMap: new THREE.Texture( <Image> ),
  17056. *
  17057. * size: <float>,
  17058. * sizeAttenuation: <bool>
  17059. *
  17060. * morphTargets: <bool>
  17061. * }
  17062. */
  17063. function PointsMaterial(parameters) {
  17064. Material.call(this);
  17065. this.type = 'PointsMaterial';
  17066. this.color = new Color(0xffffff);
  17067. this.map = null;
  17068. this.alphaMap = null;
  17069. this.size = 1;
  17070. this.sizeAttenuation = true;
  17071. this.morphTargets = false;
  17072. this.setValues(parameters);
  17073. }
  17074. PointsMaterial.prototype = Object.create(Material.prototype);
  17075. PointsMaterial.prototype.constructor = PointsMaterial;
  17076. PointsMaterial.prototype.isPointsMaterial = true;
  17077. PointsMaterial.prototype.copy = function (source) {
  17078. Material.prototype.copy.call(this, source);
  17079. this.color.copy(source.color);
  17080. this.map = source.map;
  17081. this.alphaMap = source.alphaMap;
  17082. this.size = source.size;
  17083. this.sizeAttenuation = source.sizeAttenuation;
  17084. this.morphTargets = source.morphTargets;
  17085. return this;
  17086. };
  17087. var _inverseMatrix$2 = new Matrix4();
  17088. var _ray$2 = new Ray();
  17089. var _sphere$3 = new Sphere();
  17090. var _position$1 = new Vector3();
  17091. function Points(geometry, material) {
  17092. if (geometry === void 0) {
  17093. geometry = new BufferGeometry();
  17094. }
  17095. if (material === void 0) {
  17096. material = new PointsMaterial();
  17097. }
  17098. Object3D.call(this);
  17099. this.type = 'Points';
  17100. this.geometry = geometry;
  17101. this.material = material;
  17102. this.updateMorphTargets();
  17103. }
  17104. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  17105. constructor: Points,
  17106. isPoints: true,
  17107. copy: function copy(source) {
  17108. Object3D.prototype.copy.call(this, source);
  17109. this.material = source.material;
  17110. this.geometry = source.geometry;
  17111. return this;
  17112. },
  17113. raycast: function raycast(raycaster, intersects) {
  17114. var geometry = this.geometry;
  17115. var matrixWorld = this.matrixWorld;
  17116. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  17117. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17118. _sphere$3.copy(geometry.boundingSphere);
  17119. _sphere$3.applyMatrix4(matrixWorld);
  17120. _sphere$3.radius += threshold;
  17121. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  17122. _inverseMatrix$2.copy(matrixWorld).invert();
  17123. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  17124. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17125. var localThresholdSq = localThreshold * localThreshold;
  17126. if (geometry.isBufferGeometry) {
  17127. var index = geometry.index;
  17128. var attributes = geometry.attributes;
  17129. var positionAttribute = attributes.position;
  17130. if (index !== null) {
  17131. var indices = index.array;
  17132. for (var i = 0, il = indices.length; i < il; i++) {
  17133. var a = indices[i];
  17134. _position$1.fromBufferAttribute(positionAttribute, a);
  17135. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17136. }
  17137. } else {
  17138. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  17139. _position$1.fromBufferAttribute(positionAttribute, _i);
  17140. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17141. }
  17142. }
  17143. } else {
  17144. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17145. }
  17146. },
  17147. updateMorphTargets: function updateMorphTargets() {
  17148. var geometry = this.geometry;
  17149. if (geometry.isBufferGeometry) {
  17150. var morphAttributes = geometry.morphAttributes;
  17151. var keys = Object.keys(morphAttributes);
  17152. if (keys.length > 0) {
  17153. var morphAttribute = morphAttributes[keys[0]];
  17154. if (morphAttribute !== undefined) {
  17155. this.morphTargetInfluences = [];
  17156. this.morphTargetDictionary = {};
  17157. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17158. var name = morphAttribute[m].name || String(m);
  17159. this.morphTargetInfluences.push(0);
  17160. this.morphTargetDictionary[name] = m;
  17161. }
  17162. }
  17163. }
  17164. } else {
  17165. var morphTargets = geometry.morphTargets;
  17166. if (morphTargets !== undefined && morphTargets.length > 0) {
  17167. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17168. }
  17169. }
  17170. }
  17171. });
  17172. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  17173. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  17174. if (rayPointDistanceSq < localThresholdSq) {
  17175. var intersectPoint = new Vector3();
  17176. _ray$2.closestPointToPoint(point, intersectPoint);
  17177. intersectPoint.applyMatrix4(matrixWorld);
  17178. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  17179. if (distance < raycaster.near || distance > raycaster.far) return;
  17180. intersects.push({
  17181. distance: distance,
  17182. distanceToRay: Math.sqrt(rayPointDistanceSq),
  17183. point: intersectPoint,
  17184. index: index,
  17185. face: null,
  17186. object: object
  17187. });
  17188. }
  17189. }
  17190. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17191. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17192. this.format = format !== undefined ? format : RGBFormat;
  17193. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17194. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17195. this.generateMipmaps = false;
  17196. var scope = this;
  17197. function updateVideo() {
  17198. scope.needsUpdate = true;
  17199. video.requestVideoFrameCallback(updateVideo);
  17200. }
  17201. if ('requestVideoFrameCallback' in video) {
  17202. video.requestVideoFrameCallback(updateVideo);
  17203. }
  17204. }
  17205. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  17206. constructor: VideoTexture,
  17207. clone: function clone() {
  17208. return new this.constructor(this.image).copy(this);
  17209. },
  17210. isVideoTexture: true,
  17211. update: function update() {
  17212. var video = this.image;
  17213. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  17214. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  17215. this.needsUpdate = true;
  17216. }
  17217. }
  17218. });
  17219. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  17220. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  17221. this.image = {
  17222. width: width,
  17223. height: height
  17224. };
  17225. this.mipmaps = mipmaps; // no flipping for cube textures
  17226. // (also flipping doesn't work for compressed textures )
  17227. this.flipY = false; // can't generate mipmaps for compressed textures
  17228. // mips must be embedded in DDS files
  17229. this.generateMipmaps = false;
  17230. }
  17231. CompressedTexture.prototype = Object.create(Texture.prototype);
  17232. CompressedTexture.prototype.constructor = CompressedTexture;
  17233. CompressedTexture.prototype.isCompressedTexture = true;
  17234. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17235. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17236. this.needsUpdate = true;
  17237. }
  17238. CanvasTexture.prototype = Object.create(Texture.prototype);
  17239. CanvasTexture.prototype.constructor = CanvasTexture;
  17240. CanvasTexture.prototype.isCanvasTexture = true;
  17241. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  17242. format = format !== undefined ? format : DepthFormat;
  17243. if (format !== DepthFormat && format !== DepthStencilFormat) {
  17244. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  17245. }
  17246. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  17247. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  17248. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17249. this.image = {
  17250. width: width,
  17251. height: height
  17252. };
  17253. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17254. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17255. this.flipY = false;
  17256. this.generateMipmaps = false;
  17257. }
  17258. DepthTexture.prototype = Object.create(Texture.prototype);
  17259. DepthTexture.prototype.constructor = DepthTexture;
  17260. DepthTexture.prototype.isDepthTexture = true;
  17261. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17262. _inheritsLoose(CircleGeometry, _BufferGeometry);
  17263. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17264. var _this;
  17265. if (radius === void 0) {
  17266. radius = 1;
  17267. }
  17268. if (segments === void 0) {
  17269. segments = 8;
  17270. }
  17271. if (thetaStart === void 0) {
  17272. thetaStart = 0;
  17273. }
  17274. if (thetaLength === void 0) {
  17275. thetaLength = Math.PI * 2;
  17276. }
  17277. _this = _BufferGeometry.call(this) || this;
  17278. _this.type = 'CircleGeometry';
  17279. _this.parameters = {
  17280. radius: radius,
  17281. segments: segments,
  17282. thetaStart: thetaStart,
  17283. thetaLength: thetaLength
  17284. };
  17285. segments = Math.max(3, segments); // buffers
  17286. var indices = [];
  17287. var vertices = [];
  17288. var normals = [];
  17289. var uvs = []; // helper variables
  17290. var vertex = new Vector3();
  17291. var uv = new Vector2(); // center point
  17292. vertices.push(0, 0, 0);
  17293. normals.push(0, 0, 1);
  17294. uvs.push(0.5, 0.5);
  17295. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17296. var segment = thetaStart + s / segments * thetaLength; // vertex
  17297. vertex.x = radius * Math.cos(segment);
  17298. vertex.y = radius * Math.sin(segment);
  17299. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17300. normals.push(0, 0, 1); // uvs
  17301. uv.x = (vertices[i] / radius + 1) / 2;
  17302. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17303. uvs.push(uv.x, uv.y);
  17304. } // indices
  17305. for (var _i = 1; _i <= segments; _i++) {
  17306. indices.push(_i, _i + 1, 0);
  17307. } // build geometry
  17308. _this.setIndex(indices);
  17309. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17310. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17311. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17312. return _this;
  17313. }
  17314. return CircleGeometry;
  17315. }(BufferGeometry);
  17316. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17317. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  17318. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17319. var _this;
  17320. if (radiusTop === void 0) {
  17321. radiusTop = 1;
  17322. }
  17323. if (radiusBottom === void 0) {
  17324. radiusBottom = 1;
  17325. }
  17326. if (height === void 0) {
  17327. height = 1;
  17328. }
  17329. if (radialSegments === void 0) {
  17330. radialSegments = 8;
  17331. }
  17332. if (heightSegments === void 0) {
  17333. heightSegments = 1;
  17334. }
  17335. if (openEnded === void 0) {
  17336. openEnded = false;
  17337. }
  17338. if (thetaStart === void 0) {
  17339. thetaStart = 0;
  17340. }
  17341. if (thetaLength === void 0) {
  17342. thetaLength = Math.PI * 2;
  17343. }
  17344. _this = _BufferGeometry.call(this) || this;
  17345. _this.type = 'CylinderGeometry';
  17346. _this.parameters = {
  17347. radiusTop: radiusTop,
  17348. radiusBottom: radiusBottom,
  17349. height: height,
  17350. radialSegments: radialSegments,
  17351. heightSegments: heightSegments,
  17352. openEnded: openEnded,
  17353. thetaStart: thetaStart,
  17354. thetaLength: thetaLength
  17355. };
  17356. var scope = _assertThisInitialized(_this);
  17357. radialSegments = Math.floor(radialSegments);
  17358. heightSegments = Math.floor(heightSegments); // buffers
  17359. var indices = [];
  17360. var vertices = [];
  17361. var normals = [];
  17362. var uvs = []; // helper variables
  17363. var index = 0;
  17364. var indexArray = [];
  17365. var halfHeight = height / 2;
  17366. var groupStart = 0; // generate geometry
  17367. generateTorso();
  17368. if (openEnded === false) {
  17369. if (radiusTop > 0) generateCap(true);
  17370. if (radiusBottom > 0) generateCap(false);
  17371. } // build geometry
  17372. _this.setIndex(indices);
  17373. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17374. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17375. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17376. function generateTorso() {
  17377. var normal = new Vector3();
  17378. var vertex = new Vector3();
  17379. var groupCount = 0; // this will be used to calculate the normal
  17380. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17381. for (var y = 0; y <= heightSegments; y++) {
  17382. var indexRow = [];
  17383. var v = y / heightSegments; // calculate the radius of the current row
  17384. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17385. for (var x = 0; x <= radialSegments; x++) {
  17386. var u = x / radialSegments;
  17387. var theta = u * thetaLength + thetaStart;
  17388. var sinTheta = Math.sin(theta);
  17389. var cosTheta = Math.cos(theta); // vertex
  17390. vertex.x = radius * sinTheta;
  17391. vertex.y = -v * height + halfHeight;
  17392. vertex.z = radius * cosTheta;
  17393. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17394. normal.set(sinTheta, slope, cosTheta).normalize();
  17395. normals.push(normal.x, normal.y, normal.z); // uv
  17396. uvs.push(u, 1 - v); // save index of vertex in respective row
  17397. indexRow.push(index++);
  17398. } // now save vertices of the row in our index array
  17399. indexArray.push(indexRow);
  17400. } // generate indices
  17401. for (var _x = 0; _x < radialSegments; _x++) {
  17402. for (var _y = 0; _y < heightSegments; _y++) {
  17403. // we use the index array to access the correct indices
  17404. var a = indexArray[_y][_x];
  17405. var b = indexArray[_y + 1][_x];
  17406. var c = indexArray[_y + 1][_x + 1];
  17407. var d = indexArray[_y][_x + 1]; // faces
  17408. indices.push(a, b, d);
  17409. indices.push(b, c, d); // update group counter
  17410. groupCount += 6;
  17411. }
  17412. } // add a group to the geometry. this will ensure multi material support
  17413. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17414. groupStart += groupCount;
  17415. }
  17416. function generateCap(top) {
  17417. // save the index of the first center vertex
  17418. var centerIndexStart = index;
  17419. var uv = new Vector2();
  17420. var vertex = new Vector3();
  17421. var groupCount = 0;
  17422. var radius = top === true ? radiusTop : radiusBottom;
  17423. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17424. // because the geometry needs one set of uvs per face,
  17425. // we must generate a center vertex per face/segment
  17426. for (var x = 1; x <= radialSegments; x++) {
  17427. // vertex
  17428. vertices.push(0, halfHeight * sign, 0); // normal
  17429. normals.push(0, sign, 0); // uv
  17430. uvs.push(0.5, 0.5); // increase index
  17431. index++;
  17432. } // save the index of the last center vertex
  17433. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17434. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17435. var u = _x2 / radialSegments;
  17436. var theta = u * thetaLength + thetaStart;
  17437. var cosTheta = Math.cos(theta);
  17438. var sinTheta = Math.sin(theta); // vertex
  17439. vertex.x = radius * sinTheta;
  17440. vertex.y = halfHeight * sign;
  17441. vertex.z = radius * cosTheta;
  17442. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17443. normals.push(0, sign, 0); // uv
  17444. uv.x = cosTheta * 0.5 + 0.5;
  17445. uv.y = sinTheta * 0.5 * sign + 0.5;
  17446. uvs.push(uv.x, uv.y); // increase index
  17447. index++;
  17448. } // generate indices
  17449. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17450. var c = centerIndexStart + _x3;
  17451. var i = centerIndexEnd + _x3;
  17452. if (top === true) {
  17453. // face top
  17454. indices.push(i, i + 1, c);
  17455. } else {
  17456. // face bottom
  17457. indices.push(i + 1, i, c);
  17458. }
  17459. groupCount += 3;
  17460. } // add a group to the geometry. this will ensure multi material support
  17461. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17462. groupStart += groupCount;
  17463. }
  17464. return _this;
  17465. }
  17466. return CylinderGeometry;
  17467. }(BufferGeometry);
  17468. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17469. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17470. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17471. var _this;
  17472. if (radius === void 0) {
  17473. radius = 1;
  17474. }
  17475. if (height === void 0) {
  17476. height = 1;
  17477. }
  17478. if (radialSegments === void 0) {
  17479. radialSegments = 8;
  17480. }
  17481. if (heightSegments === void 0) {
  17482. heightSegments = 1;
  17483. }
  17484. if (openEnded === void 0) {
  17485. openEnded = false;
  17486. }
  17487. if (thetaStart === void 0) {
  17488. thetaStart = 0;
  17489. }
  17490. if (thetaLength === void 0) {
  17491. thetaLength = Math.PI * 2;
  17492. }
  17493. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17494. _this.type = 'ConeGeometry';
  17495. _this.parameters = {
  17496. radius: radius,
  17497. height: height,
  17498. radialSegments: radialSegments,
  17499. heightSegments: heightSegments,
  17500. openEnded: openEnded,
  17501. thetaStart: thetaStart,
  17502. thetaLength: thetaLength
  17503. };
  17504. return _this;
  17505. }
  17506. return ConeGeometry;
  17507. }(CylinderGeometry);
  17508. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17509. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  17510. function PolyhedronGeometry(vertices, indices, radius, detail) {
  17511. var _this;
  17512. if (radius === void 0) {
  17513. radius = 1;
  17514. }
  17515. if (detail === void 0) {
  17516. detail = 0;
  17517. }
  17518. _this = _BufferGeometry.call(this) || this;
  17519. _this.type = 'PolyhedronGeometry';
  17520. _this.parameters = {
  17521. vertices: vertices,
  17522. indices: indices,
  17523. radius: radius,
  17524. detail: detail
  17525. }; // default buffer data
  17526. var vertexBuffer = [];
  17527. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17528. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17529. applyRadius(radius); // finally, create the uv data
  17530. generateUVs(); // build non-indexed geometry
  17531. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17532. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17533. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17534. if (detail === 0) {
  17535. _this.computeVertexNormals(); // flat normals
  17536. } else {
  17537. _this.normalizeNormals(); // smooth normals
  17538. } // helper functions
  17539. function subdivide(detail) {
  17540. var a = new Vector3();
  17541. var b = new Vector3();
  17542. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17543. for (var i = 0; i < indices.length; i += 3) {
  17544. // get the vertices of the face
  17545. getVertexByIndex(indices[i + 0], a);
  17546. getVertexByIndex(indices[i + 1], b);
  17547. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17548. subdivideFace(a, b, c, detail);
  17549. }
  17550. }
  17551. function subdivideFace(a, b, c, detail) {
  17552. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17553. var v = []; // construct all of the vertices for this subdivision
  17554. for (var i = 0; i <= cols; i++) {
  17555. v[i] = [];
  17556. var aj = a.clone().lerp(c, i / cols);
  17557. var bj = b.clone().lerp(c, i / cols);
  17558. var rows = cols - i;
  17559. for (var j = 0; j <= rows; j++) {
  17560. if (j === 0 && i === cols) {
  17561. v[i][j] = aj;
  17562. } else {
  17563. v[i][j] = aj.clone().lerp(bj, j / rows);
  17564. }
  17565. }
  17566. } // construct all of the faces
  17567. for (var _i = 0; _i < cols; _i++) {
  17568. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17569. var k = Math.floor(_j / 2);
  17570. if (_j % 2 === 0) {
  17571. pushVertex(v[_i][k + 1]);
  17572. pushVertex(v[_i + 1][k]);
  17573. pushVertex(v[_i][k]);
  17574. } else {
  17575. pushVertex(v[_i][k + 1]);
  17576. pushVertex(v[_i + 1][k + 1]);
  17577. pushVertex(v[_i + 1][k]);
  17578. }
  17579. }
  17580. }
  17581. }
  17582. function applyRadius(radius) {
  17583. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17584. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17585. vertex.x = vertexBuffer[i + 0];
  17586. vertex.y = vertexBuffer[i + 1];
  17587. vertex.z = vertexBuffer[i + 2];
  17588. vertex.normalize().multiplyScalar(radius);
  17589. vertexBuffer[i + 0] = vertex.x;
  17590. vertexBuffer[i + 1] = vertex.y;
  17591. vertexBuffer[i + 2] = vertex.z;
  17592. }
  17593. }
  17594. function generateUVs() {
  17595. var vertex = new Vector3();
  17596. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17597. vertex.x = vertexBuffer[i + 0];
  17598. vertex.y = vertexBuffer[i + 1];
  17599. vertex.z = vertexBuffer[i + 2];
  17600. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17601. var v = inclination(vertex) / Math.PI + 0.5;
  17602. uvBuffer.push(u, 1 - v);
  17603. }
  17604. correctUVs();
  17605. correctSeam();
  17606. }
  17607. function correctSeam() {
  17608. // handle case when face straddles the seam, see #3269
  17609. for (var i = 0; i < uvBuffer.length; i += 6) {
  17610. // uv data of a single face
  17611. var x0 = uvBuffer[i + 0];
  17612. var x1 = uvBuffer[i + 2];
  17613. var x2 = uvBuffer[i + 4];
  17614. var max = Math.max(x0, x1, x2);
  17615. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17616. if (max > 0.9 && min < 0.1) {
  17617. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17618. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17619. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17620. }
  17621. }
  17622. }
  17623. function pushVertex(vertex) {
  17624. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17625. }
  17626. function getVertexByIndex(index, vertex) {
  17627. var stride = index * 3;
  17628. vertex.x = vertices[stride + 0];
  17629. vertex.y = vertices[stride + 1];
  17630. vertex.z = vertices[stride + 2];
  17631. }
  17632. function correctUVs() {
  17633. var a = new Vector3();
  17634. var b = new Vector3();
  17635. var c = new Vector3();
  17636. var centroid = new Vector3();
  17637. var uvA = new Vector2();
  17638. var uvB = new Vector2();
  17639. var uvC = new Vector2();
  17640. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17641. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17642. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17643. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17644. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17645. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17646. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17647. centroid.copy(a).add(b).add(c).divideScalar(3);
  17648. var azi = azimuth(centroid);
  17649. correctUV(uvA, j + 0, a, azi);
  17650. correctUV(uvB, j + 2, b, azi);
  17651. correctUV(uvC, j + 4, c, azi);
  17652. }
  17653. }
  17654. function correctUV(uv, stride, vector, azimuth) {
  17655. if (azimuth < 0 && uv.x === 1) {
  17656. uvBuffer[stride] = uv.x - 1;
  17657. }
  17658. if (vector.x === 0 && vector.z === 0) {
  17659. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17660. }
  17661. } // Angle around the Y axis, counter-clockwise when looking from above.
  17662. function azimuth(vector) {
  17663. return Math.atan2(vector.z, -vector.x);
  17664. } // Angle above the XZ plane.
  17665. function inclination(vector) {
  17666. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17667. }
  17668. return _this;
  17669. }
  17670. return PolyhedronGeometry;
  17671. }(BufferGeometry);
  17672. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17673. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17674. function DodecahedronGeometry(radius, detail) {
  17675. var _this;
  17676. if (radius === void 0) {
  17677. radius = 1;
  17678. }
  17679. if (detail === void 0) {
  17680. detail = 0;
  17681. }
  17682. var t = (1 + Math.sqrt(5)) / 2;
  17683. var r = 1 / t;
  17684. var vertices = [// (±1, ±1, ±1)
  17685. -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/φ, ±φ)
  17686. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17687. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17688. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17689. 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];
  17690. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17691. _this.type = 'DodecahedronGeometry';
  17692. _this.parameters = {
  17693. radius: radius,
  17694. detail: detail
  17695. };
  17696. return _this;
  17697. }
  17698. return DodecahedronGeometry;
  17699. }(PolyhedronGeometry);
  17700. var _v0$2 = new Vector3();
  17701. var _v1$5 = new Vector3();
  17702. var _normal$1 = new Vector3();
  17703. var _triangle = new Triangle();
  17704. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17705. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17706. function EdgesGeometry(geometry, thresholdAngle) {
  17707. var _this;
  17708. _this = _BufferGeometry.call(this) || this;
  17709. _this.type = 'EdgesGeometry';
  17710. _this.parameters = {
  17711. thresholdAngle: thresholdAngle
  17712. };
  17713. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17714. if (geometry.isGeometry === true) {
  17715. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17716. return _assertThisInitialized(_this);
  17717. }
  17718. var precisionPoints = 4;
  17719. var precision = Math.pow(10, precisionPoints);
  17720. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17721. var indexAttr = geometry.getIndex();
  17722. var positionAttr = geometry.getAttribute('position');
  17723. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17724. var indexArr = [0, 0, 0];
  17725. var vertKeys = ['a', 'b', 'c'];
  17726. var hashes = new Array(3);
  17727. var edgeData = {};
  17728. var vertices = [];
  17729. for (var i = 0; i < indexCount; i += 3) {
  17730. if (indexAttr) {
  17731. indexArr[0] = indexAttr.getX(i);
  17732. indexArr[1] = indexAttr.getX(i + 1);
  17733. indexArr[2] = indexAttr.getX(i + 2);
  17734. } else {
  17735. indexArr[0] = i;
  17736. indexArr[1] = i + 1;
  17737. indexArr[2] = i + 2;
  17738. }
  17739. var a = _triangle.a,
  17740. b = _triangle.b,
  17741. c = _triangle.c;
  17742. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17743. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17744. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17745. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17746. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17747. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17748. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17749. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17750. continue;
  17751. } // iterate over every edge
  17752. for (var j = 0; j < 3; j++) {
  17753. // get the first and next vertex making up the edge
  17754. var jNext = (j + 1) % 3;
  17755. var vecHash0 = hashes[j];
  17756. var vecHash1 = hashes[jNext];
  17757. var v0 = _triangle[vertKeys[j]];
  17758. var v1 = _triangle[vertKeys[jNext]];
  17759. var hash = vecHash0 + "_" + vecHash1;
  17760. var reverseHash = vecHash1 + "_" + vecHash0;
  17761. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17762. // if we found a sibling edge add it into the vertex array if
  17763. // it meets the angle threshold and delete the edge from the map.
  17764. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17765. vertices.push(v0.x, v0.y, v0.z);
  17766. vertices.push(v1.x, v1.y, v1.z);
  17767. }
  17768. edgeData[reverseHash] = null;
  17769. } else if (!(hash in edgeData)) {
  17770. // if we've already got an edge here then skip adding a new one
  17771. edgeData[hash] = {
  17772. index0: indexArr[j],
  17773. index1: indexArr[jNext],
  17774. normal: _normal$1.clone()
  17775. };
  17776. }
  17777. }
  17778. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17779. for (var key in edgeData) {
  17780. if (edgeData[key]) {
  17781. var _edgeData$key = edgeData[key],
  17782. index0 = _edgeData$key.index0,
  17783. index1 = _edgeData$key.index1;
  17784. _v0$2.fromBufferAttribute(positionAttr, index0);
  17785. _v1$5.fromBufferAttribute(positionAttr, index1);
  17786. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17787. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17788. }
  17789. }
  17790. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17791. return _this;
  17792. }
  17793. return EdgesGeometry;
  17794. }(BufferGeometry);
  17795. /**
  17796. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17797. */
  17798. var Earcut = {
  17799. triangulate: function triangulate(data, holeIndices, dim) {
  17800. dim = dim || 2;
  17801. var hasHoles = holeIndices && holeIndices.length;
  17802. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17803. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17804. var triangles = [];
  17805. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17806. var minX, minY, maxX, maxY, x, y, invSize;
  17807. 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
  17808. if (data.length > 80 * dim) {
  17809. minX = maxX = data[0];
  17810. minY = maxY = data[1];
  17811. for (var i = dim; i < outerLen; i += dim) {
  17812. x = data[i];
  17813. y = data[i + 1];
  17814. if (x < minX) minX = x;
  17815. if (y < minY) minY = y;
  17816. if (x > maxX) maxX = x;
  17817. if (y > maxY) maxY = y;
  17818. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17819. invSize = Math.max(maxX - minX, maxY - minY);
  17820. invSize = invSize !== 0 ? 1 / invSize : 0;
  17821. }
  17822. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17823. return triangles;
  17824. }
  17825. }; // create a circular doubly linked list from polygon points in the specified winding order
  17826. function linkedList(data, start, end, dim, clockwise) {
  17827. var i, last;
  17828. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17829. for (i = start; i < end; i += dim) {
  17830. last = insertNode(i, data[i], data[i + 1], last);
  17831. }
  17832. } else {
  17833. for (i = end - dim; i >= start; i -= dim) {
  17834. last = insertNode(i, data[i], data[i + 1], last);
  17835. }
  17836. }
  17837. if (last && equals(last, last.next)) {
  17838. removeNode(last);
  17839. last = last.next;
  17840. }
  17841. return last;
  17842. } // eliminate colinear or duplicate points
  17843. function filterPoints(start, end) {
  17844. if (!start) return start;
  17845. if (!end) end = start;
  17846. var p = start,
  17847. again;
  17848. do {
  17849. again = false;
  17850. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17851. removeNode(p);
  17852. p = end = p.prev;
  17853. if (p === p.next) break;
  17854. again = true;
  17855. } else {
  17856. p = p.next;
  17857. }
  17858. } while (again || p !== end);
  17859. return end;
  17860. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17861. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17862. if (!ear) return; // interlink polygon nodes in z-order
  17863. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17864. var stop = ear,
  17865. prev,
  17866. next; // iterate through ears, slicing them one by one
  17867. while (ear.prev !== ear.next) {
  17868. prev = ear.prev;
  17869. next = ear.next;
  17870. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17871. // cut off the triangle
  17872. triangles.push(prev.i / dim);
  17873. triangles.push(ear.i / dim);
  17874. triangles.push(next.i / dim);
  17875. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17876. ear = next.next;
  17877. stop = next.next;
  17878. continue;
  17879. }
  17880. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17881. if (ear === stop) {
  17882. // try filtering points and slicing again
  17883. if (!pass) {
  17884. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17885. } else if (pass === 1) {
  17886. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17887. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17888. } else if (pass === 2) {
  17889. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17890. }
  17891. break;
  17892. }
  17893. }
  17894. } // check whether a polygon node forms a valid ear with adjacent nodes
  17895. function isEar(ear) {
  17896. var a = ear.prev,
  17897. b = ear,
  17898. c = ear.next;
  17899. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17900. // now make sure we don't have other points inside the potential ear
  17901. var p = ear.next.next;
  17902. while (p !== ear.prev) {
  17903. 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;
  17904. p = p.next;
  17905. }
  17906. return true;
  17907. }
  17908. function isEarHashed(ear, minX, minY, invSize) {
  17909. var a = ear.prev,
  17910. b = ear,
  17911. c = ear.next;
  17912. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17913. // triangle bbox; min & max are calculated like this for speed
  17914. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17915. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17916. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17917. 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;
  17918. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17919. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17920. var p = ear.prevZ,
  17921. n = ear.nextZ; // look for points inside the triangle in both directions
  17922. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17923. 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;
  17924. p = p.prevZ;
  17925. 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;
  17926. n = n.nextZ;
  17927. } // look for remaining points in decreasing z-order
  17928. while (p && p.z >= minZ) {
  17929. 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;
  17930. p = p.prevZ;
  17931. } // look for remaining points in increasing z-order
  17932. while (n && n.z <= maxZ) {
  17933. 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;
  17934. n = n.nextZ;
  17935. }
  17936. return true;
  17937. } // go through all polygon nodes and cure small local self-intersections
  17938. function cureLocalIntersections(start, triangles, dim) {
  17939. var p = start;
  17940. do {
  17941. var a = p.prev,
  17942. b = p.next.next;
  17943. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17944. triangles.push(a.i / dim);
  17945. triangles.push(p.i / dim);
  17946. triangles.push(b.i / dim); // remove two nodes involved
  17947. removeNode(p);
  17948. removeNode(p.next);
  17949. p = start = b;
  17950. }
  17951. p = p.next;
  17952. } while (p !== start);
  17953. return filterPoints(p);
  17954. } // try splitting polygon into two and triangulate them independently
  17955. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17956. // look for a valid diagonal that divides the polygon into two
  17957. var a = start;
  17958. do {
  17959. var b = a.next.next;
  17960. while (b !== a.prev) {
  17961. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17962. // split the polygon in two by the diagonal
  17963. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17964. a = filterPoints(a, a.next);
  17965. c = filterPoints(c, c.next); // run earcut on each half
  17966. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17967. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17968. return;
  17969. }
  17970. b = b.next;
  17971. }
  17972. a = a.next;
  17973. } while (a !== start);
  17974. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17975. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17976. var queue = [];
  17977. var i, len, start, end, list;
  17978. for (i = 0, len = holeIndices.length; i < len; i++) {
  17979. start = holeIndices[i] * dim;
  17980. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17981. list = linkedList(data, start, end, dim, false);
  17982. if (list === list.next) list.steiner = true;
  17983. queue.push(getLeftmost(list));
  17984. }
  17985. queue.sort(compareX); // process holes from left to right
  17986. for (i = 0; i < queue.length; i++) {
  17987. eliminateHole(queue[i], outerNode);
  17988. outerNode = filterPoints(outerNode, outerNode.next);
  17989. }
  17990. return outerNode;
  17991. }
  17992. function compareX(a, b) {
  17993. return a.x - b.x;
  17994. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17995. function eliminateHole(hole, outerNode) {
  17996. outerNode = findHoleBridge(hole, outerNode);
  17997. if (outerNode) {
  17998. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17999. filterPoints(outerNode, outerNode.next);
  18000. filterPoints(b, b.next);
  18001. }
  18002. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18003. function findHoleBridge(hole, outerNode) {
  18004. var p = outerNode;
  18005. var hx = hole.x;
  18006. var hy = hole.y;
  18007. var qx = -Infinity,
  18008. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18009. // segment's endpoint with lesser x will be potential connection point
  18010. do {
  18011. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18012. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18013. if (x <= hx && x > qx) {
  18014. qx = x;
  18015. if (x === hx) {
  18016. if (hy === p.y) return p;
  18017. if (hy === p.next.y) return p.next;
  18018. }
  18019. m = p.x < p.next.x ? p : p.next;
  18020. }
  18021. }
  18022. p = p.next;
  18023. } while (p !== outerNode);
  18024. if (!m) return null;
  18025. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18026. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18027. // if there are no points found, we have a valid connection;
  18028. // otherwise choose the point of the minimum angle with the ray as connection point
  18029. var stop = m,
  18030. mx = m.x,
  18031. my = m.y;
  18032. var tanMin = Infinity,
  18033. tan;
  18034. p = m;
  18035. do {
  18036. 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)) {
  18037. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18038. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18039. m = p;
  18040. tanMin = tan;
  18041. }
  18042. }
  18043. p = p.next;
  18044. } while (p !== stop);
  18045. return m;
  18046. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18047. function sectorContainsSector(m, p) {
  18048. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18049. } // interlink polygon nodes in z-order
  18050. function indexCurve(start, minX, minY, invSize) {
  18051. var p = start;
  18052. do {
  18053. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18054. p.prevZ = p.prev;
  18055. p.nextZ = p.next;
  18056. p = p.next;
  18057. } while (p !== start);
  18058. p.prevZ.nextZ = null;
  18059. p.prevZ = null;
  18060. sortLinked(p);
  18061. } // Simon Tatham's linked list merge sort algorithm
  18062. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18063. function sortLinked(list) {
  18064. var i,
  18065. p,
  18066. q,
  18067. e,
  18068. tail,
  18069. numMerges,
  18070. pSize,
  18071. qSize,
  18072. inSize = 1;
  18073. do {
  18074. p = list;
  18075. list = null;
  18076. tail = null;
  18077. numMerges = 0;
  18078. while (p) {
  18079. numMerges++;
  18080. q = p;
  18081. pSize = 0;
  18082. for (i = 0; i < inSize; i++) {
  18083. pSize++;
  18084. q = q.nextZ;
  18085. if (!q) break;
  18086. }
  18087. qSize = inSize;
  18088. while (pSize > 0 || qSize > 0 && q) {
  18089. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18090. e = p;
  18091. p = p.nextZ;
  18092. pSize--;
  18093. } else {
  18094. e = q;
  18095. q = q.nextZ;
  18096. qSize--;
  18097. }
  18098. if (tail) tail.nextZ = e;else list = e;
  18099. e.prevZ = tail;
  18100. tail = e;
  18101. }
  18102. p = q;
  18103. }
  18104. tail.nextZ = null;
  18105. inSize *= 2;
  18106. } while (numMerges > 1);
  18107. return list;
  18108. } // z-order of a point given coords and inverse of the longer side of data bbox
  18109. function zOrder(x, y, minX, minY, invSize) {
  18110. // coords are transformed into non-negative 15-bit integer range
  18111. x = 32767 * (x - minX) * invSize;
  18112. y = 32767 * (y - minY) * invSize;
  18113. x = (x | x << 8) & 0x00FF00FF;
  18114. x = (x | x << 4) & 0x0F0F0F0F;
  18115. x = (x | x << 2) & 0x33333333;
  18116. x = (x | x << 1) & 0x55555555;
  18117. y = (y | y << 8) & 0x00FF00FF;
  18118. y = (y | y << 4) & 0x0F0F0F0F;
  18119. y = (y | y << 2) & 0x33333333;
  18120. y = (y | y << 1) & 0x55555555;
  18121. return x | y << 1;
  18122. } // find the leftmost node of a polygon ring
  18123. function getLeftmost(start) {
  18124. var p = start,
  18125. leftmost = start;
  18126. do {
  18127. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18128. p = p.next;
  18129. } while (p !== start);
  18130. return leftmost;
  18131. } // check if a point lies within a convex triangle
  18132. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18133. 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;
  18134. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18135. function isValidDiagonal(a, b) {
  18136. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18137. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18138. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18139. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18140. } // signed area of a triangle
  18141. function area(p, q, r) {
  18142. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18143. } // check if two points are equal
  18144. function equals(p1, p2) {
  18145. return p1.x === p2.x && p1.y === p2.y;
  18146. } // check if two segments intersect
  18147. function intersects(p1, q1, p2, q2) {
  18148. var o1 = sign(area(p1, q1, p2));
  18149. var o2 = sign(area(p1, q1, q2));
  18150. var o3 = sign(area(p2, q2, p1));
  18151. var o4 = sign(area(p2, q2, q1));
  18152. if (o1 !== o2 && o3 !== o4) return true; // general case
  18153. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18154. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18155. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18156. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18157. return false;
  18158. } // for collinear points p, q, r, check if point q lies on segment pr
  18159. function onSegment(p, q, r) {
  18160. 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);
  18161. }
  18162. function sign(num) {
  18163. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18164. } // check if a polygon diagonal intersects any polygon segments
  18165. function intersectsPolygon(a, b) {
  18166. var p = a;
  18167. do {
  18168. 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;
  18169. p = p.next;
  18170. } while (p !== a);
  18171. return false;
  18172. } // check if a polygon diagonal is locally inside the polygon
  18173. function locallyInside(a, b) {
  18174. 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;
  18175. } // check if the middle point of a polygon diagonal is inside the polygon
  18176. function middleInside(a, b) {
  18177. var p = a,
  18178. inside = false;
  18179. var px = (a.x + b.x) / 2,
  18180. py = (a.y + b.y) / 2;
  18181. do {
  18182. 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;
  18183. p = p.next;
  18184. } while (p !== a);
  18185. return inside;
  18186. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18187. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18188. function splitPolygon(a, b) {
  18189. var a2 = new Node(a.i, a.x, a.y),
  18190. b2 = new Node(b.i, b.x, b.y),
  18191. an = a.next,
  18192. bp = b.prev;
  18193. a.next = b;
  18194. b.prev = a;
  18195. a2.next = an;
  18196. an.prev = a2;
  18197. b2.next = a2;
  18198. a2.prev = b2;
  18199. bp.next = b2;
  18200. b2.prev = bp;
  18201. return b2;
  18202. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18203. function insertNode(i, x, y, last) {
  18204. var p = new Node(i, x, y);
  18205. if (!last) {
  18206. p.prev = p;
  18207. p.next = p;
  18208. } else {
  18209. p.next = last.next;
  18210. p.prev = last;
  18211. last.next.prev = p;
  18212. last.next = p;
  18213. }
  18214. return p;
  18215. }
  18216. function removeNode(p) {
  18217. p.next.prev = p.prev;
  18218. p.prev.next = p.next;
  18219. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18220. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18221. }
  18222. function Node(i, x, y) {
  18223. // vertex index in coordinates array
  18224. this.i = i; // vertex coordinates
  18225. this.x = x;
  18226. this.y = y; // previous and next vertex nodes in a polygon ring
  18227. this.prev = null;
  18228. this.next = null; // z-order curve value
  18229. this.z = null; // previous and next nodes in z-order
  18230. this.prevZ = null;
  18231. this.nextZ = null; // indicates whether this is a steiner point
  18232. this.steiner = false;
  18233. }
  18234. function signedArea(data, start, end, dim) {
  18235. var sum = 0;
  18236. for (var i = start, j = end - dim; i < end; i += dim) {
  18237. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18238. j = i;
  18239. }
  18240. return sum;
  18241. }
  18242. var ShapeUtils = {
  18243. // calculate area of the contour polygon
  18244. area: function area(contour) {
  18245. var n = contour.length;
  18246. var a = 0.0;
  18247. for (var p = n - 1, q = 0; q < n; p = q++) {
  18248. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18249. }
  18250. return a * 0.5;
  18251. },
  18252. isClockWise: function isClockWise(pts) {
  18253. return ShapeUtils.area(pts) < 0;
  18254. },
  18255. triangulateShape: function triangulateShape(contour, holes) {
  18256. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18257. var holeIndices = []; // array of hole indices
  18258. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18259. removeDupEndPts(contour);
  18260. addContour(vertices, contour); //
  18261. var holeIndex = contour.length;
  18262. holes.forEach(removeDupEndPts);
  18263. for (var i = 0; i < holes.length; i++) {
  18264. holeIndices.push(holeIndex);
  18265. holeIndex += holes[i].length;
  18266. addContour(vertices, holes[i]);
  18267. } //
  18268. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18269. for (var _i = 0; _i < triangles.length; _i += 3) {
  18270. faces.push(triangles.slice(_i, _i + 3));
  18271. }
  18272. return faces;
  18273. }
  18274. };
  18275. function removeDupEndPts(points) {
  18276. var l = points.length;
  18277. if (l > 2 && points[l - 1].equals(points[0])) {
  18278. points.pop();
  18279. }
  18280. }
  18281. function addContour(vertices, contour) {
  18282. for (var i = 0; i < contour.length; i++) {
  18283. vertices.push(contour[i].x);
  18284. vertices.push(contour[i].y);
  18285. }
  18286. }
  18287. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18288. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  18289. function ExtrudeGeometry(shapes, options) {
  18290. var _this;
  18291. _this = _BufferGeometry.call(this) || this;
  18292. _this.type = 'ExtrudeGeometry';
  18293. _this.parameters = {
  18294. shapes: shapes,
  18295. options: options
  18296. };
  18297. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18298. var scope = _assertThisInitialized(_this);
  18299. var verticesArray = [];
  18300. var uvArray = [];
  18301. for (var i = 0, l = shapes.length; i < l; i++) {
  18302. var shape = shapes[i];
  18303. addShape(shape);
  18304. } // build geometry
  18305. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18306. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18307. _this.computeVertexNormals(); // functions
  18308. function addShape(shape) {
  18309. var placeholder = []; // options
  18310. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18311. var steps = options.steps !== undefined ? options.steps : 1;
  18312. var depth = options.depth !== undefined ? options.depth : 100;
  18313. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18314. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18315. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18316. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18317. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18318. var extrudePath = options.extrudePath;
  18319. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18320. if (options.amount !== undefined) {
  18321. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18322. depth = options.amount;
  18323. } //
  18324. var extrudePts,
  18325. extrudeByPath = false;
  18326. var splineTube, binormal, normal, position2;
  18327. if (extrudePath) {
  18328. extrudePts = extrudePath.getSpacedPoints(steps);
  18329. extrudeByPath = true;
  18330. bevelEnabled = false; // bevels not supported for path extrusion
  18331. // SETUP TNB variables
  18332. // TODO1 - have a .isClosed in spline?
  18333. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18334. binormal = new Vector3();
  18335. normal = new Vector3();
  18336. position2 = new Vector3();
  18337. } // Safeguards if bevels are not enabled
  18338. if (!bevelEnabled) {
  18339. bevelSegments = 0;
  18340. bevelThickness = 0;
  18341. bevelSize = 0;
  18342. bevelOffset = 0;
  18343. } // Variables initialization
  18344. var shapePoints = shape.extractPoints(curveSegments);
  18345. var vertices = shapePoints.shape;
  18346. var holes = shapePoints.holes;
  18347. var reverse = !ShapeUtils.isClockWise(vertices);
  18348. if (reverse) {
  18349. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18350. for (var h = 0, hl = holes.length; h < hl; h++) {
  18351. var ahole = holes[h];
  18352. if (ShapeUtils.isClockWise(ahole)) {
  18353. holes[h] = ahole.reverse();
  18354. }
  18355. }
  18356. }
  18357. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18358. /* Vertices */
  18359. var contour = vertices; // vertices has all points but contour has only points of circumference
  18360. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18361. var _ahole = holes[_h];
  18362. vertices = vertices.concat(_ahole);
  18363. }
  18364. function scalePt2(pt, vec, size) {
  18365. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18366. return vec.clone().multiplyScalar(size).add(pt);
  18367. }
  18368. var vlen = vertices.length,
  18369. flen = faces.length; // Find directions for point movement
  18370. function getBevelVec(inPt, inPrev, inNext) {
  18371. // computes for inPt the corresponding point inPt' on a new contour
  18372. // shifted by 1 unit (length of normalized vector) to the left
  18373. // if we walk along contour clockwise, this new contour is outside the old one
  18374. //
  18375. // inPt' is the intersection of the two lines parallel to the two
  18376. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18377. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18378. // good reading for geometry algorithms (here: line-line intersection)
  18379. // http://geomalgorithms.com/a05-_intersect-1.html
  18380. var v_prev_x = inPt.x - inPrev.x,
  18381. v_prev_y = inPt.y - inPrev.y;
  18382. var v_next_x = inNext.x - inPt.x,
  18383. v_next_y = inNext.y - inPt.y;
  18384. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18385. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18386. if (Math.abs(collinear0) > Number.EPSILON) {
  18387. // not collinear
  18388. // length of vectors for normalizing
  18389. var v_prev_len = Math.sqrt(v_prev_lensq);
  18390. 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
  18391. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18392. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18393. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18394. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18395. 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
  18396. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18397. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18398. // but prevent crazy spikes
  18399. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18400. if (v_trans_lensq <= 2) {
  18401. return new Vector2(v_trans_x, v_trans_y);
  18402. } else {
  18403. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18404. }
  18405. } else {
  18406. // handle special case of collinear edges
  18407. var direction_eq = false; // assumes: opposite
  18408. if (v_prev_x > Number.EPSILON) {
  18409. if (v_next_x > Number.EPSILON) {
  18410. direction_eq = true;
  18411. }
  18412. } else {
  18413. if (v_prev_x < -Number.EPSILON) {
  18414. if (v_next_x < -Number.EPSILON) {
  18415. direction_eq = true;
  18416. }
  18417. } else {
  18418. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18419. direction_eq = true;
  18420. }
  18421. }
  18422. }
  18423. if (direction_eq) {
  18424. // console.log("Warning: lines are a straight sequence");
  18425. v_trans_x = -v_prev_y;
  18426. v_trans_y = v_prev_x;
  18427. shrink_by = Math.sqrt(v_prev_lensq);
  18428. } else {
  18429. // console.log("Warning: lines are a straight spike");
  18430. v_trans_x = v_prev_x;
  18431. v_trans_y = v_prev_y;
  18432. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18433. }
  18434. }
  18435. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18436. }
  18437. var contourMovements = [];
  18438. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18439. if (j === il) j = 0;
  18440. if (k === il) k = 0; // (j)---(i)---(k)
  18441. // console.log('i,j,k', i, j , k)
  18442. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18443. }
  18444. var holesMovements = [];
  18445. var oneHoleMovements,
  18446. verticesMovements = contourMovements.concat();
  18447. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18448. var _ahole2 = holes[_h2];
  18449. oneHoleMovements = [];
  18450. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18451. if (_j === _il) _j = 0;
  18452. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18453. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18454. }
  18455. holesMovements.push(oneHoleMovements);
  18456. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18457. } // Loop bevelSegments, 1 for the front, 1 for the back
  18458. for (var b = 0; b < bevelSegments; b++) {
  18459. //for ( b = bevelSegments; b > 0; b -- ) {
  18460. var t = b / bevelSegments;
  18461. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18462. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18463. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18464. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18465. v(vert.x, vert.y, -z);
  18466. } // expand holes
  18467. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18468. var _ahole3 = holes[_h3];
  18469. oneHoleMovements = holesMovements[_h3];
  18470. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18471. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18472. v(_vert.x, _vert.y, -z);
  18473. }
  18474. }
  18475. }
  18476. var bs = bevelSize + bevelOffset; // Back facing vertices
  18477. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18478. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18479. if (!extrudeByPath) {
  18480. v(_vert2.x, _vert2.y, 0);
  18481. } else {
  18482. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18483. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18484. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18485. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18486. v(position2.x, position2.y, position2.z);
  18487. }
  18488. } // Add stepped vertices...
  18489. // Including front facing vertices
  18490. for (var s = 1; s <= steps; s++) {
  18491. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18492. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18493. if (!extrudeByPath) {
  18494. v(_vert3.x, _vert3.y, depth / steps * s);
  18495. } else {
  18496. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18497. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18498. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18499. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18500. v(position2.x, position2.y, position2.z);
  18501. }
  18502. }
  18503. } // Add bevel segments planes
  18504. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18505. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18506. var _t = _b / bevelSegments;
  18507. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18508. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18509. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18510. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18511. v(_vert4.x, _vert4.y, depth + _z);
  18512. } // expand holes
  18513. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18514. var _ahole4 = holes[_h4];
  18515. oneHoleMovements = holesMovements[_h4];
  18516. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18517. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18518. if (!extrudeByPath) {
  18519. v(_vert5.x, _vert5.y, depth + _z);
  18520. } else {
  18521. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18522. }
  18523. }
  18524. }
  18525. }
  18526. /* Faces */
  18527. // Top and bottom faces
  18528. buildLidFaces(); // Sides faces
  18529. buildSideFaces(); ///// Internal functions
  18530. function buildLidFaces() {
  18531. var start = verticesArray.length / 3;
  18532. if (bevelEnabled) {
  18533. var layer = 0; // steps + 1
  18534. var offset = vlen * layer; // Bottom faces
  18535. for (var _i9 = 0; _i9 < flen; _i9++) {
  18536. var face = faces[_i9];
  18537. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18538. }
  18539. layer = steps + bevelSegments * 2;
  18540. offset = vlen * layer; // Top faces
  18541. for (var _i10 = 0; _i10 < flen; _i10++) {
  18542. var _face = faces[_i10];
  18543. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18544. }
  18545. } else {
  18546. // Bottom faces
  18547. for (var _i11 = 0; _i11 < flen; _i11++) {
  18548. var _face2 = faces[_i11];
  18549. f3(_face2[2], _face2[1], _face2[0]);
  18550. } // Top faces
  18551. for (var _i12 = 0; _i12 < flen; _i12++) {
  18552. var _face3 = faces[_i12];
  18553. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18554. }
  18555. }
  18556. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18557. } // Create faces for the z-sides of the shape
  18558. function buildSideFaces() {
  18559. var start = verticesArray.length / 3;
  18560. var layeroffset = 0;
  18561. sidewalls(contour, layeroffset);
  18562. layeroffset += contour.length;
  18563. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18564. var _ahole5 = holes[_h5];
  18565. sidewalls(_ahole5, layeroffset); //, true
  18566. layeroffset += _ahole5.length;
  18567. }
  18568. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18569. }
  18570. function sidewalls(contour, layeroffset) {
  18571. var i = contour.length;
  18572. while (--i >= 0) {
  18573. var _j2 = i;
  18574. var _k2 = i - 1;
  18575. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18576. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18577. var slen1 = vlen * _s;
  18578. var slen2 = vlen * (_s + 1);
  18579. var a = layeroffset + _j2 + slen1,
  18580. _b2 = layeroffset + _k2 + slen1,
  18581. c = layeroffset + _k2 + slen2,
  18582. d = layeroffset + _j2 + slen2;
  18583. f4(a, _b2, c, d);
  18584. }
  18585. }
  18586. }
  18587. function v(x, y, z) {
  18588. placeholder.push(x);
  18589. placeholder.push(y);
  18590. placeholder.push(z);
  18591. }
  18592. function f3(a, b, c) {
  18593. addVertex(a);
  18594. addVertex(b);
  18595. addVertex(c);
  18596. var nextIndex = verticesArray.length / 3;
  18597. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18598. addUV(uvs[0]);
  18599. addUV(uvs[1]);
  18600. addUV(uvs[2]);
  18601. }
  18602. function f4(a, b, c, d) {
  18603. addVertex(a);
  18604. addVertex(b);
  18605. addVertex(d);
  18606. addVertex(b);
  18607. addVertex(c);
  18608. addVertex(d);
  18609. var nextIndex = verticesArray.length / 3;
  18610. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18611. addUV(uvs[0]);
  18612. addUV(uvs[1]);
  18613. addUV(uvs[3]);
  18614. addUV(uvs[1]);
  18615. addUV(uvs[2]);
  18616. addUV(uvs[3]);
  18617. }
  18618. function addVertex(index) {
  18619. verticesArray.push(placeholder[index * 3 + 0]);
  18620. verticesArray.push(placeholder[index * 3 + 1]);
  18621. verticesArray.push(placeholder[index * 3 + 2]);
  18622. }
  18623. function addUV(vector2) {
  18624. uvArray.push(vector2.x);
  18625. uvArray.push(vector2.y);
  18626. }
  18627. }
  18628. return _this;
  18629. }
  18630. var _proto = ExtrudeGeometry.prototype;
  18631. _proto.toJSON = function toJSON() {
  18632. var data = BufferGeometry.prototype.toJSON.call(this);
  18633. var shapes = this.parameters.shapes;
  18634. var options = this.parameters.options;
  18635. return _toJSON(shapes, options, data);
  18636. };
  18637. return ExtrudeGeometry;
  18638. }(BufferGeometry);
  18639. var WorldUVGenerator = {
  18640. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18641. var a_x = vertices[indexA * 3];
  18642. var a_y = vertices[indexA * 3 + 1];
  18643. var b_x = vertices[indexB * 3];
  18644. var b_y = vertices[indexB * 3 + 1];
  18645. var c_x = vertices[indexC * 3];
  18646. var c_y = vertices[indexC * 3 + 1];
  18647. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18648. },
  18649. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18650. var a_x = vertices[indexA * 3];
  18651. var a_y = vertices[indexA * 3 + 1];
  18652. var a_z = vertices[indexA * 3 + 2];
  18653. var b_x = vertices[indexB * 3];
  18654. var b_y = vertices[indexB * 3 + 1];
  18655. var b_z = vertices[indexB * 3 + 2];
  18656. var c_x = vertices[indexC * 3];
  18657. var c_y = vertices[indexC * 3 + 1];
  18658. var c_z = vertices[indexC * 3 + 2];
  18659. var d_x = vertices[indexD * 3];
  18660. var d_y = vertices[indexD * 3 + 1];
  18661. var d_z = vertices[indexD * 3 + 2];
  18662. if (Math.abs(a_y - b_y) < 0.01) {
  18663. 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)];
  18664. } else {
  18665. 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)];
  18666. }
  18667. }
  18668. };
  18669. function _toJSON(shapes, options, data) {
  18670. data.shapes = [];
  18671. if (Array.isArray(shapes)) {
  18672. for (var i = 0, l = shapes.length; i < l; i++) {
  18673. var shape = shapes[i];
  18674. data.shapes.push(shape.uuid);
  18675. }
  18676. } else {
  18677. data.shapes.push(shapes.uuid);
  18678. }
  18679. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18680. return data;
  18681. }
  18682. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18683. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18684. function IcosahedronGeometry(radius, detail) {
  18685. var _this;
  18686. if (radius === void 0) {
  18687. radius = 1;
  18688. }
  18689. if (detail === void 0) {
  18690. detail = 0;
  18691. }
  18692. var t = (1 + Math.sqrt(5)) / 2;
  18693. 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];
  18694. 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];
  18695. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18696. _this.type = 'IcosahedronGeometry';
  18697. _this.parameters = {
  18698. radius: radius,
  18699. detail: detail
  18700. };
  18701. return _this;
  18702. }
  18703. return IcosahedronGeometry;
  18704. }(PolyhedronGeometry);
  18705. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18706. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18707. function LatheGeometry(points, segments, phiStart, phiLength) {
  18708. var _this;
  18709. if (segments === void 0) {
  18710. segments = 12;
  18711. }
  18712. if (phiStart === void 0) {
  18713. phiStart = 0;
  18714. }
  18715. if (phiLength === void 0) {
  18716. phiLength = Math.PI * 2;
  18717. }
  18718. _this = _BufferGeometry.call(this) || this;
  18719. _this.type = 'LatheGeometry';
  18720. _this.parameters = {
  18721. points: points,
  18722. segments: segments,
  18723. phiStart: phiStart,
  18724. phiLength: phiLength
  18725. };
  18726. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18727. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18728. var indices = [];
  18729. var vertices = [];
  18730. var uvs = []; // helper variables
  18731. var inverseSegments = 1.0 / segments;
  18732. var vertex = new Vector3();
  18733. var uv = new Vector2(); // generate vertices and uvs
  18734. for (var i = 0; i <= segments; i++) {
  18735. var phi = phiStart + i * inverseSegments * phiLength;
  18736. var sin = Math.sin(phi);
  18737. var cos = Math.cos(phi);
  18738. for (var j = 0; j <= points.length - 1; j++) {
  18739. // vertex
  18740. vertex.x = points[j].x * sin;
  18741. vertex.y = points[j].y;
  18742. vertex.z = points[j].x * cos;
  18743. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18744. uv.x = i / segments;
  18745. uv.y = j / (points.length - 1);
  18746. uvs.push(uv.x, uv.y);
  18747. }
  18748. } // indices
  18749. for (var _i = 0; _i < segments; _i++) {
  18750. for (var _j = 0; _j < points.length - 1; _j++) {
  18751. var base = _j + _i * points.length;
  18752. var a = base;
  18753. var b = base + points.length;
  18754. var c = base + points.length + 1;
  18755. var d = base + 1; // faces
  18756. indices.push(a, b, d);
  18757. indices.push(b, c, d);
  18758. }
  18759. } // build geometry
  18760. _this.setIndex(indices);
  18761. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18762. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18763. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18764. // because the corresponding vertices are identical (but still have different UVs).
  18765. if (phiLength === Math.PI * 2) {
  18766. var normals = _this.attributes.normal.array;
  18767. var n1 = new Vector3();
  18768. var n2 = new Vector3();
  18769. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18770. var _base = segments * points.length * 3;
  18771. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18772. // select the normal of the vertex in the first line
  18773. n1.x = normals[_j2 + 0];
  18774. n1.y = normals[_j2 + 1];
  18775. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18776. n2.x = normals[_base + _j2 + 0];
  18777. n2.y = normals[_base + _j2 + 1];
  18778. n2.z = normals[_base + _j2 + 2]; // average normals
  18779. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18780. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18781. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18782. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18783. }
  18784. }
  18785. return _this;
  18786. }
  18787. return LatheGeometry;
  18788. }(BufferGeometry);
  18789. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18790. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18791. function OctahedronGeometry(radius, detail) {
  18792. var _this;
  18793. if (radius === void 0) {
  18794. radius = 1;
  18795. }
  18796. if (detail === void 0) {
  18797. detail = 0;
  18798. }
  18799. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18800. 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];
  18801. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18802. _this.type = 'OctahedronGeometry';
  18803. _this.parameters = {
  18804. radius: radius,
  18805. detail: detail
  18806. };
  18807. return _this;
  18808. }
  18809. return OctahedronGeometry;
  18810. }(PolyhedronGeometry);
  18811. /**
  18812. * Parametric Surfaces Geometry
  18813. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18814. */
  18815. function ParametricGeometry(func, slices, stacks) {
  18816. BufferGeometry.call(this);
  18817. this.type = 'ParametricGeometry';
  18818. this.parameters = {
  18819. func: func,
  18820. slices: slices,
  18821. stacks: stacks
  18822. }; // buffers
  18823. var indices = [];
  18824. var vertices = [];
  18825. var normals = [];
  18826. var uvs = [];
  18827. var EPS = 0.00001;
  18828. var normal = new Vector3();
  18829. var p0 = new Vector3(),
  18830. p1 = new Vector3();
  18831. var pu = new Vector3(),
  18832. pv = new Vector3();
  18833. if (func.length < 3) {
  18834. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18835. } // generate vertices, normals and uvs
  18836. var sliceCount = slices + 1;
  18837. for (var i = 0; i <= stacks; i++) {
  18838. var v = i / stacks;
  18839. for (var j = 0; j <= slices; j++) {
  18840. var u = j / slices; // vertex
  18841. func(u, v, p0);
  18842. vertices.push(p0.x, p0.y, p0.z); // normal
  18843. // approximate tangent vectors via finite differences
  18844. if (u - EPS >= 0) {
  18845. func(u - EPS, v, p1);
  18846. pu.subVectors(p0, p1);
  18847. } else {
  18848. func(u + EPS, v, p1);
  18849. pu.subVectors(p1, p0);
  18850. }
  18851. if (v - EPS >= 0) {
  18852. func(u, v - EPS, p1);
  18853. pv.subVectors(p0, p1);
  18854. } else {
  18855. func(u, v + EPS, p1);
  18856. pv.subVectors(p1, p0);
  18857. } // cross product of tangent vectors returns surface normal
  18858. normal.crossVectors(pu, pv).normalize();
  18859. normals.push(normal.x, normal.y, normal.z); // uv
  18860. uvs.push(u, v);
  18861. }
  18862. } // generate indices
  18863. for (var _i = 0; _i < stacks; _i++) {
  18864. for (var _j = 0; _j < slices; _j++) {
  18865. var a = _i * sliceCount + _j;
  18866. var b = _i * sliceCount + _j + 1;
  18867. var c = (_i + 1) * sliceCount + _j + 1;
  18868. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18869. indices.push(a, b, d);
  18870. indices.push(b, c, d);
  18871. }
  18872. } // build geometry
  18873. this.setIndex(indices);
  18874. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18875. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18876. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18877. }
  18878. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18879. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18880. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18881. _inheritsLoose(RingGeometry, _BufferGeometry);
  18882. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18883. var _this;
  18884. if (innerRadius === void 0) {
  18885. innerRadius = 0.5;
  18886. }
  18887. if (outerRadius === void 0) {
  18888. outerRadius = 1;
  18889. }
  18890. if (thetaSegments === void 0) {
  18891. thetaSegments = 8;
  18892. }
  18893. if (phiSegments === void 0) {
  18894. phiSegments = 1;
  18895. }
  18896. if (thetaStart === void 0) {
  18897. thetaStart = 0;
  18898. }
  18899. if (thetaLength === void 0) {
  18900. thetaLength = Math.PI * 2;
  18901. }
  18902. _this = _BufferGeometry.call(this) || this;
  18903. _this.type = 'RingGeometry';
  18904. _this.parameters = {
  18905. innerRadius: innerRadius,
  18906. outerRadius: outerRadius,
  18907. thetaSegments: thetaSegments,
  18908. phiSegments: phiSegments,
  18909. thetaStart: thetaStart,
  18910. thetaLength: thetaLength
  18911. };
  18912. thetaSegments = Math.max(3, thetaSegments);
  18913. phiSegments = Math.max(1, phiSegments); // buffers
  18914. var indices = [];
  18915. var vertices = [];
  18916. var normals = [];
  18917. var uvs = []; // some helper variables
  18918. var radius = innerRadius;
  18919. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18920. var vertex = new Vector3();
  18921. var uv = new Vector2(); // generate vertices, normals and uvs
  18922. for (var j = 0; j <= phiSegments; j++) {
  18923. for (var i = 0; i <= thetaSegments; i++) {
  18924. // values are generate from the inside of the ring to the outside
  18925. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18926. vertex.x = radius * Math.cos(segment);
  18927. vertex.y = radius * Math.sin(segment);
  18928. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18929. normals.push(0, 0, 1); // uv
  18930. uv.x = (vertex.x / outerRadius + 1) / 2;
  18931. uv.y = (vertex.y / outerRadius + 1) / 2;
  18932. uvs.push(uv.x, uv.y);
  18933. } // increase the radius for next row of vertices
  18934. radius += radiusStep;
  18935. } // indices
  18936. for (var _j = 0; _j < phiSegments; _j++) {
  18937. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18938. for (var _i = 0; _i < thetaSegments; _i++) {
  18939. var _segment = _i + thetaSegmentLevel;
  18940. var a = _segment;
  18941. var b = _segment + thetaSegments + 1;
  18942. var c = _segment + thetaSegments + 2;
  18943. var d = _segment + 1; // faces
  18944. indices.push(a, b, d);
  18945. indices.push(b, c, d);
  18946. }
  18947. } // build geometry
  18948. _this.setIndex(indices);
  18949. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18950. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18951. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18952. return _this;
  18953. }
  18954. return RingGeometry;
  18955. }(BufferGeometry);
  18956. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18957. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  18958. function ShapeGeometry(shapes, curveSegments) {
  18959. var _this;
  18960. if (curveSegments === void 0) {
  18961. curveSegments = 12;
  18962. }
  18963. _this = _BufferGeometry.call(this) || this;
  18964. _this.type = 'ShapeGeometry';
  18965. _this.parameters = {
  18966. shapes: shapes,
  18967. curveSegments: curveSegments
  18968. }; // buffers
  18969. var indices = [];
  18970. var vertices = [];
  18971. var normals = [];
  18972. var uvs = []; // helper variables
  18973. var groupStart = 0;
  18974. var groupCount = 0; // allow single and array values for "shapes" parameter
  18975. if (Array.isArray(shapes) === false) {
  18976. addShape(shapes);
  18977. } else {
  18978. for (var i = 0; i < shapes.length; i++) {
  18979. addShape(shapes[i]);
  18980. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18981. groupStart += groupCount;
  18982. groupCount = 0;
  18983. }
  18984. } // build geometry
  18985. _this.setIndex(indices);
  18986. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18987. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18988. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  18989. function addShape(shape) {
  18990. var indexOffset = vertices.length / 3;
  18991. var points = shape.extractPoints(curveSegments);
  18992. var shapeVertices = points.shape;
  18993. var shapeHoles = points.holes; // check direction of vertices
  18994. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  18995. shapeVertices = shapeVertices.reverse();
  18996. }
  18997. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  18998. var shapeHole = shapeHoles[_i];
  18999. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19000. shapeHoles[_i] = shapeHole.reverse();
  19001. }
  19002. }
  19003. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19004. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19005. var _shapeHole = shapeHoles[_i2];
  19006. shapeVertices = shapeVertices.concat(_shapeHole);
  19007. } // vertices, normals, uvs
  19008. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19009. var vertex = shapeVertices[_i3];
  19010. vertices.push(vertex.x, vertex.y, 0);
  19011. normals.push(0, 0, 1);
  19012. uvs.push(vertex.x, vertex.y); // world uvs
  19013. } // incides
  19014. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19015. var face = faces[_i4];
  19016. var a = face[0] + indexOffset;
  19017. var b = face[1] + indexOffset;
  19018. var c = face[2] + indexOffset;
  19019. indices.push(a, b, c);
  19020. groupCount += 3;
  19021. }
  19022. }
  19023. return _this;
  19024. }
  19025. var _proto = ShapeGeometry.prototype;
  19026. _proto.toJSON = function toJSON() {
  19027. var data = BufferGeometry.prototype.toJSON.call(this);
  19028. var shapes = this.parameters.shapes;
  19029. return _toJSON$1(shapes, data);
  19030. };
  19031. return ShapeGeometry;
  19032. }(BufferGeometry);
  19033. function _toJSON$1(shapes, data) {
  19034. data.shapes = [];
  19035. if (Array.isArray(shapes)) {
  19036. for (var i = 0, l = shapes.length; i < l; i++) {
  19037. var shape = shapes[i];
  19038. data.shapes.push(shape.uuid);
  19039. }
  19040. } else {
  19041. data.shapes.push(shapes.uuid);
  19042. }
  19043. return data;
  19044. }
  19045. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19046. _inheritsLoose(SphereGeometry, _BufferGeometry);
  19047. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19048. var _this;
  19049. if (radius === void 0) {
  19050. radius = 1;
  19051. }
  19052. if (widthSegments === void 0) {
  19053. widthSegments = 8;
  19054. }
  19055. if (heightSegments === void 0) {
  19056. heightSegments = 6;
  19057. }
  19058. if (phiStart === void 0) {
  19059. phiStart = 0;
  19060. }
  19061. if (phiLength === void 0) {
  19062. phiLength = Math.PI * 2;
  19063. }
  19064. if (thetaStart === void 0) {
  19065. thetaStart = 0;
  19066. }
  19067. if (thetaLength === void 0) {
  19068. thetaLength = Math.PI;
  19069. }
  19070. _this = _BufferGeometry.call(this) || this;
  19071. _this.type = 'SphereGeometry';
  19072. _this.parameters = {
  19073. radius: radius,
  19074. widthSegments: widthSegments,
  19075. heightSegments: heightSegments,
  19076. phiStart: phiStart,
  19077. phiLength: phiLength,
  19078. thetaStart: thetaStart,
  19079. thetaLength: thetaLength
  19080. };
  19081. widthSegments = Math.max(3, Math.floor(widthSegments));
  19082. heightSegments = Math.max(2, Math.floor(heightSegments));
  19083. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19084. var index = 0;
  19085. var grid = [];
  19086. var vertex = new Vector3();
  19087. var normal = new Vector3(); // buffers
  19088. var indices = [];
  19089. var vertices = [];
  19090. var normals = [];
  19091. var uvs = []; // generate vertices, normals and uvs
  19092. for (var iy = 0; iy <= heightSegments; iy++) {
  19093. var verticesRow = [];
  19094. var v = iy / heightSegments; // special case for the poles
  19095. var uOffset = 0;
  19096. if (iy == 0 && thetaStart == 0) {
  19097. uOffset = 0.5 / widthSegments;
  19098. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19099. uOffset = -0.5 / widthSegments;
  19100. }
  19101. for (var ix = 0; ix <= widthSegments; ix++) {
  19102. var u = ix / widthSegments; // vertex
  19103. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19104. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19105. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19106. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19107. normal.copy(vertex).normalize();
  19108. normals.push(normal.x, normal.y, normal.z); // uv
  19109. uvs.push(u + uOffset, 1 - v);
  19110. verticesRow.push(index++);
  19111. }
  19112. grid.push(verticesRow);
  19113. } // indices
  19114. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19115. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19116. var a = grid[_iy][_ix + 1];
  19117. var b = grid[_iy][_ix];
  19118. var c = grid[_iy + 1][_ix];
  19119. var d = grid[_iy + 1][_ix + 1];
  19120. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19121. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19122. }
  19123. } // build geometry
  19124. _this.setIndex(indices);
  19125. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19126. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19127. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19128. return _this;
  19129. }
  19130. return SphereGeometry;
  19131. }(BufferGeometry);
  19132. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  19133. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  19134. function TetrahedronGeometry(radius, detail) {
  19135. var _this;
  19136. if (radius === void 0) {
  19137. radius = 1;
  19138. }
  19139. if (detail === void 0) {
  19140. detail = 0;
  19141. }
  19142. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19143. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19144. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  19145. _this.type = 'TetrahedronGeometry';
  19146. _this.parameters = {
  19147. radius: radius,
  19148. detail: detail
  19149. };
  19150. return _this;
  19151. }
  19152. return TetrahedronGeometry;
  19153. }(PolyhedronGeometry);
  19154. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  19155. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  19156. function TextGeometry(text, parameters) {
  19157. var _this;
  19158. if (parameters === void 0) {
  19159. parameters = {};
  19160. }
  19161. var font = parameters.font;
  19162. if (!(font && font.isFont)) {
  19163. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19164. return new BufferGeometry() || _assertThisInitialized(_this);
  19165. }
  19166. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19167. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19168. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19169. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19170. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19171. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  19172. _this.type = 'TextGeometry';
  19173. return _this;
  19174. }
  19175. return TextGeometry;
  19176. }(ExtrudeGeometry);
  19177. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19178. _inheritsLoose(TorusGeometry, _BufferGeometry);
  19179. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19180. var _this;
  19181. if (radius === void 0) {
  19182. radius = 1;
  19183. }
  19184. if (tube === void 0) {
  19185. tube = 0.4;
  19186. }
  19187. if (radialSegments === void 0) {
  19188. radialSegments = 8;
  19189. }
  19190. if (tubularSegments === void 0) {
  19191. tubularSegments = 6;
  19192. }
  19193. if (arc === void 0) {
  19194. arc = Math.PI * 2;
  19195. }
  19196. _this = _BufferGeometry.call(this) || this;
  19197. _this.type = 'TorusGeometry';
  19198. _this.parameters = {
  19199. radius: radius,
  19200. tube: tube,
  19201. radialSegments: radialSegments,
  19202. tubularSegments: tubularSegments,
  19203. arc: arc
  19204. };
  19205. radialSegments = Math.floor(radialSegments);
  19206. tubularSegments = Math.floor(tubularSegments); // buffers
  19207. var indices = [];
  19208. var vertices = [];
  19209. var normals = [];
  19210. var uvs = []; // helper variables
  19211. var center = new Vector3();
  19212. var vertex = new Vector3();
  19213. var normal = new Vector3(); // generate vertices, normals and uvs
  19214. for (var j = 0; j <= radialSegments; j++) {
  19215. for (var i = 0; i <= tubularSegments; i++) {
  19216. var u = i / tubularSegments * arc;
  19217. var v = j / radialSegments * Math.PI * 2; // vertex
  19218. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19219. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19220. vertex.z = tube * Math.sin(v);
  19221. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19222. center.x = radius * Math.cos(u);
  19223. center.y = radius * Math.sin(u);
  19224. normal.subVectors(vertex, center).normalize();
  19225. normals.push(normal.x, normal.y, normal.z); // uv
  19226. uvs.push(i / tubularSegments);
  19227. uvs.push(j / radialSegments);
  19228. }
  19229. } // generate indices
  19230. for (var _j = 1; _j <= radialSegments; _j++) {
  19231. for (var _i = 1; _i <= tubularSegments; _i++) {
  19232. // indices
  19233. var a = (tubularSegments + 1) * _j + _i - 1;
  19234. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19235. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19236. var d = (tubularSegments + 1) * _j + _i; // faces
  19237. indices.push(a, b, d);
  19238. indices.push(b, c, d);
  19239. }
  19240. } // build geometry
  19241. _this.setIndex(indices);
  19242. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19243. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19244. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19245. return _this;
  19246. }
  19247. return TorusGeometry;
  19248. }(BufferGeometry);
  19249. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19250. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  19251. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19252. var _this;
  19253. if (radius === void 0) {
  19254. radius = 1;
  19255. }
  19256. if (tube === void 0) {
  19257. tube = 0.4;
  19258. }
  19259. if (tubularSegments === void 0) {
  19260. tubularSegments = 64;
  19261. }
  19262. if (radialSegments === void 0) {
  19263. radialSegments = 8;
  19264. }
  19265. if (p === void 0) {
  19266. p = 2;
  19267. }
  19268. if (q === void 0) {
  19269. q = 3;
  19270. }
  19271. _this = _BufferGeometry.call(this) || this;
  19272. _this.type = 'TorusKnotGeometry';
  19273. _this.parameters = {
  19274. radius: radius,
  19275. tube: tube,
  19276. tubularSegments: tubularSegments,
  19277. radialSegments: radialSegments,
  19278. p: p,
  19279. q: q
  19280. };
  19281. tubularSegments = Math.floor(tubularSegments);
  19282. radialSegments = Math.floor(radialSegments); // buffers
  19283. var indices = [];
  19284. var vertices = [];
  19285. var normals = [];
  19286. var uvs = []; // helper variables
  19287. var vertex = new Vector3();
  19288. var normal = new Vector3();
  19289. var P1 = new Vector3();
  19290. var P2 = new Vector3();
  19291. var B = new Vector3();
  19292. var T = new Vector3();
  19293. var N = new Vector3(); // generate vertices, normals and uvs
  19294. for (var i = 0; i <= tubularSegments; ++i) {
  19295. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19296. 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.
  19297. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19298. calculatePositionOnCurve(u, p, q, radius, P1);
  19299. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19300. T.subVectors(P2, P1);
  19301. N.addVectors(P2, P1);
  19302. B.crossVectors(T, N);
  19303. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19304. B.normalize();
  19305. N.normalize();
  19306. for (var j = 0; j <= radialSegments; ++j) {
  19307. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19308. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19309. var v = j / radialSegments * Math.PI * 2;
  19310. var cx = -tube * Math.cos(v);
  19311. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19312. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19313. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19314. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19315. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19316. 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)
  19317. normal.subVectors(vertex, P1).normalize();
  19318. normals.push(normal.x, normal.y, normal.z); // uv
  19319. uvs.push(i / tubularSegments);
  19320. uvs.push(j / radialSegments);
  19321. }
  19322. } // generate indices
  19323. for (var _j = 1; _j <= tubularSegments; _j++) {
  19324. for (var _i = 1; _i <= radialSegments; _i++) {
  19325. // indices
  19326. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19327. var b = (radialSegments + 1) * _j + (_i - 1);
  19328. var c = (radialSegments + 1) * _j + _i;
  19329. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19330. indices.push(a, b, d);
  19331. indices.push(b, c, d);
  19332. }
  19333. } // build geometry
  19334. _this.setIndex(indices);
  19335. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19336. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19337. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19338. function calculatePositionOnCurve(u, p, q, radius, position) {
  19339. var cu = Math.cos(u);
  19340. var su = Math.sin(u);
  19341. var quOverP = q / p * u;
  19342. var cs = Math.cos(quOverP);
  19343. position.x = radius * (2 + cs) * 0.5 * cu;
  19344. position.y = radius * (2 + cs) * su * 0.5;
  19345. position.z = radius * Math.sin(quOverP) * 0.5;
  19346. }
  19347. return _this;
  19348. }
  19349. return TorusKnotGeometry;
  19350. }(BufferGeometry);
  19351. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19352. _inheritsLoose(TubeGeometry, _BufferGeometry);
  19353. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19354. var _this;
  19355. if (tubularSegments === void 0) {
  19356. tubularSegments = 64;
  19357. }
  19358. if (radius === void 0) {
  19359. radius = 1;
  19360. }
  19361. if (radialSegments === void 0) {
  19362. radialSegments = 8;
  19363. }
  19364. if (closed === void 0) {
  19365. closed = false;
  19366. }
  19367. _this = _BufferGeometry.call(this) || this;
  19368. _this.type = 'TubeGeometry';
  19369. _this.parameters = {
  19370. path: path,
  19371. tubularSegments: tubularSegments,
  19372. radius: radius,
  19373. radialSegments: radialSegments,
  19374. closed: closed
  19375. };
  19376. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19377. _this.tangents = frames.tangents;
  19378. _this.normals = frames.normals;
  19379. _this.binormals = frames.binormals; // helper variables
  19380. var vertex = new Vector3();
  19381. var normal = new Vector3();
  19382. var uv = new Vector2();
  19383. var P = new Vector3(); // buffer
  19384. var vertices = [];
  19385. var normals = [];
  19386. var uvs = [];
  19387. var indices = []; // create buffer data
  19388. generateBufferData(); // build geometry
  19389. _this.setIndex(indices);
  19390. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19391. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19392. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19393. function generateBufferData() {
  19394. for (var i = 0; i < tubularSegments; i++) {
  19395. generateSegment(i);
  19396. } // if the geometry is not closed, generate the last row of vertices and normals
  19397. // at the regular position on the given path
  19398. //
  19399. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19400. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19401. // this makes it easy compute correct values for closed geometries
  19402. generateUVs(); // finally create faces
  19403. generateIndices();
  19404. }
  19405. function generateSegment(i) {
  19406. // we use getPointAt to sample evenly distributed points from the given path
  19407. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19408. var N = frames.normals[i];
  19409. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19410. for (var j = 0; j <= radialSegments; j++) {
  19411. var v = j / radialSegments * Math.PI * 2;
  19412. var sin = Math.sin(v);
  19413. var cos = -Math.cos(v); // normal
  19414. normal.x = cos * N.x + sin * B.x;
  19415. normal.y = cos * N.y + sin * B.y;
  19416. normal.z = cos * N.z + sin * B.z;
  19417. normal.normalize();
  19418. normals.push(normal.x, normal.y, normal.z); // vertex
  19419. vertex.x = P.x + radius * normal.x;
  19420. vertex.y = P.y + radius * normal.y;
  19421. vertex.z = P.z + radius * normal.z;
  19422. vertices.push(vertex.x, vertex.y, vertex.z);
  19423. }
  19424. }
  19425. function generateIndices() {
  19426. for (var j = 1; j <= tubularSegments; j++) {
  19427. for (var i = 1; i <= radialSegments; i++) {
  19428. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19429. var b = (radialSegments + 1) * j + (i - 1);
  19430. var c = (radialSegments + 1) * j + i;
  19431. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19432. indices.push(a, b, d);
  19433. indices.push(b, c, d);
  19434. }
  19435. }
  19436. }
  19437. function generateUVs() {
  19438. for (var i = 0; i <= tubularSegments; i++) {
  19439. for (var j = 0; j <= radialSegments; j++) {
  19440. uv.x = i / tubularSegments;
  19441. uv.y = j / radialSegments;
  19442. uvs.push(uv.x, uv.y);
  19443. }
  19444. }
  19445. }
  19446. return _this;
  19447. }
  19448. var _proto = TubeGeometry.prototype;
  19449. _proto.toJSON = function toJSON() {
  19450. var data = BufferGeometry.prototype.toJSON.call(this);
  19451. data.path = this.parameters.path.toJSON();
  19452. return data;
  19453. };
  19454. return TubeGeometry;
  19455. }(BufferGeometry);
  19456. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19457. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19458. function WireframeGeometry(geometry) {
  19459. var _this;
  19460. _this = _BufferGeometry.call(this) || this;
  19461. _this.type = 'WireframeGeometry';
  19462. if (geometry.isGeometry === true) {
  19463. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  19464. return _assertThisInitialized(_this);
  19465. } // buffer
  19466. var vertices = []; // helper variables
  19467. var edge = [0, 0],
  19468. edges = {};
  19469. var vertex = new Vector3();
  19470. if (geometry.index !== null) {
  19471. // indexed BufferGeometry
  19472. var position = geometry.attributes.position;
  19473. var indices = geometry.index;
  19474. var groups = geometry.groups;
  19475. if (groups.length === 0) {
  19476. groups = [{
  19477. start: 0,
  19478. count: indices.count,
  19479. materialIndex: 0
  19480. }];
  19481. } // create a data structure that contains all eges without duplicates
  19482. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19483. var group = groups[o];
  19484. var start = group.start;
  19485. var count = group.count;
  19486. for (var i = start, l = start + count; i < l; i += 3) {
  19487. for (var j = 0; j < 3; j++) {
  19488. var edge1 = indices.getX(i + j);
  19489. var edge2 = indices.getX(i + (j + 1) % 3);
  19490. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19491. edge[1] = Math.max(edge1, edge2);
  19492. var key = edge[0] + ',' + edge[1];
  19493. if (edges[key] === undefined) {
  19494. edges[key] = {
  19495. index1: edge[0],
  19496. index2: edge[1]
  19497. };
  19498. }
  19499. }
  19500. }
  19501. } // generate vertices
  19502. for (var _key in edges) {
  19503. var e = edges[_key];
  19504. vertex.fromBufferAttribute(position, e.index1);
  19505. vertices.push(vertex.x, vertex.y, vertex.z);
  19506. vertex.fromBufferAttribute(position, e.index2);
  19507. vertices.push(vertex.x, vertex.y, vertex.z);
  19508. }
  19509. } else {
  19510. // non-indexed BufferGeometry
  19511. var _position = geometry.attributes.position;
  19512. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  19513. for (var _j = 0; _j < 3; _j++) {
  19514. // three edges per triangle, an edge is represented as (index1, index2)
  19515. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19516. var index1 = 3 * _i + _j;
  19517. vertex.fromBufferAttribute(_position, index1);
  19518. vertices.push(vertex.x, vertex.y, vertex.z);
  19519. var index2 = 3 * _i + (_j + 1) % 3;
  19520. vertex.fromBufferAttribute(_position, index2);
  19521. vertices.push(vertex.x, vertex.y, vertex.z);
  19522. }
  19523. }
  19524. } // build geometry
  19525. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19526. return _this;
  19527. }
  19528. return WireframeGeometry;
  19529. }(BufferGeometry);
  19530. var Geometries = /*#__PURE__*/Object.freeze({
  19531. __proto__: null,
  19532. BoxGeometry: BoxGeometry,
  19533. BoxBufferGeometry: BoxGeometry,
  19534. CircleGeometry: CircleGeometry,
  19535. CircleBufferGeometry: CircleGeometry,
  19536. ConeGeometry: ConeGeometry,
  19537. ConeBufferGeometry: ConeGeometry,
  19538. CylinderGeometry: CylinderGeometry,
  19539. CylinderBufferGeometry: CylinderGeometry,
  19540. DodecahedronGeometry: DodecahedronGeometry,
  19541. DodecahedronBufferGeometry: DodecahedronGeometry,
  19542. EdgesGeometry: EdgesGeometry,
  19543. ExtrudeGeometry: ExtrudeGeometry,
  19544. ExtrudeBufferGeometry: ExtrudeGeometry,
  19545. IcosahedronGeometry: IcosahedronGeometry,
  19546. IcosahedronBufferGeometry: IcosahedronGeometry,
  19547. LatheGeometry: LatheGeometry,
  19548. LatheBufferGeometry: LatheGeometry,
  19549. OctahedronGeometry: OctahedronGeometry,
  19550. OctahedronBufferGeometry: OctahedronGeometry,
  19551. ParametricGeometry: ParametricGeometry,
  19552. ParametricBufferGeometry: ParametricGeometry,
  19553. PlaneGeometry: PlaneGeometry,
  19554. PlaneBufferGeometry: PlaneGeometry,
  19555. PolyhedronGeometry: PolyhedronGeometry,
  19556. PolyhedronBufferGeometry: PolyhedronGeometry,
  19557. RingGeometry: RingGeometry,
  19558. RingBufferGeometry: RingGeometry,
  19559. ShapeGeometry: ShapeGeometry,
  19560. ShapeBufferGeometry: ShapeGeometry,
  19561. SphereGeometry: SphereGeometry,
  19562. SphereBufferGeometry: SphereGeometry,
  19563. TetrahedronGeometry: TetrahedronGeometry,
  19564. TetrahedronBufferGeometry: TetrahedronGeometry,
  19565. TextGeometry: TextGeometry,
  19566. TextBufferGeometry: TextGeometry,
  19567. TorusGeometry: TorusGeometry,
  19568. TorusBufferGeometry: TorusGeometry,
  19569. TorusKnotGeometry: TorusKnotGeometry,
  19570. TorusKnotBufferGeometry: TorusKnotGeometry,
  19571. TubeGeometry: TubeGeometry,
  19572. TubeBufferGeometry: TubeGeometry,
  19573. WireframeGeometry: WireframeGeometry
  19574. });
  19575. /**
  19576. * parameters = {
  19577. * color: <THREE.Color>
  19578. * }
  19579. */
  19580. function ShadowMaterial(parameters) {
  19581. Material.call(this);
  19582. this.type = 'ShadowMaterial';
  19583. this.color = new Color(0x000000);
  19584. this.transparent = true;
  19585. this.setValues(parameters);
  19586. }
  19587. ShadowMaterial.prototype = Object.create(Material.prototype);
  19588. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19589. ShadowMaterial.prototype.isShadowMaterial = true;
  19590. ShadowMaterial.prototype.copy = function (source) {
  19591. Material.prototype.copy.call(this, source);
  19592. this.color.copy(source.color);
  19593. return this;
  19594. };
  19595. function RawShaderMaterial(parameters) {
  19596. ShaderMaterial.call(this, parameters);
  19597. this.type = 'RawShaderMaterial';
  19598. }
  19599. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19600. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19601. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19602. /**
  19603. * parameters = {
  19604. * color: <hex>,
  19605. * roughness: <float>,
  19606. * metalness: <float>,
  19607. * opacity: <float>,
  19608. *
  19609. * map: new THREE.Texture( <Image> ),
  19610. *
  19611. * lightMap: new THREE.Texture( <Image> ),
  19612. * lightMapIntensity: <float>
  19613. *
  19614. * aoMap: new THREE.Texture( <Image> ),
  19615. * aoMapIntensity: <float>
  19616. *
  19617. * emissive: <hex>,
  19618. * emissiveIntensity: <float>
  19619. * emissiveMap: new THREE.Texture( <Image> ),
  19620. *
  19621. * bumpMap: new THREE.Texture( <Image> ),
  19622. * bumpScale: <float>,
  19623. *
  19624. * normalMap: new THREE.Texture( <Image> ),
  19625. * normalMapType: THREE.TangentSpaceNormalMap,
  19626. * normalScale: <Vector2>,
  19627. *
  19628. * displacementMap: new THREE.Texture( <Image> ),
  19629. * displacementScale: <float>,
  19630. * displacementBias: <float>,
  19631. *
  19632. * roughnessMap: new THREE.Texture( <Image> ),
  19633. *
  19634. * metalnessMap: new THREE.Texture( <Image> ),
  19635. *
  19636. * alphaMap: new THREE.Texture( <Image> ),
  19637. *
  19638. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19639. * envMapIntensity: <float>
  19640. *
  19641. * refractionRatio: <float>,
  19642. *
  19643. * wireframe: <boolean>,
  19644. * wireframeLinewidth: <float>,
  19645. *
  19646. * skinning: <bool>,
  19647. * morphTargets: <bool>,
  19648. * morphNormals: <bool>,
  19649. *
  19650. * flatShading: <bool>
  19651. * }
  19652. */
  19653. function MeshStandardMaterial(parameters) {
  19654. Material.call(this);
  19655. this.defines = {
  19656. 'STANDARD': ''
  19657. };
  19658. this.type = 'MeshStandardMaterial';
  19659. this.color = new Color(0xffffff); // diffuse
  19660. this.roughness = 1.0;
  19661. this.metalness = 0.0;
  19662. this.map = null;
  19663. this.lightMap = null;
  19664. this.lightMapIntensity = 1.0;
  19665. this.aoMap = null;
  19666. this.aoMapIntensity = 1.0;
  19667. this.emissive = new Color(0x000000);
  19668. this.emissiveIntensity = 1.0;
  19669. this.emissiveMap = null;
  19670. this.bumpMap = null;
  19671. this.bumpScale = 1;
  19672. this.normalMap = null;
  19673. this.normalMapType = TangentSpaceNormalMap;
  19674. this.normalScale = new Vector2(1, 1);
  19675. this.displacementMap = null;
  19676. this.displacementScale = 1;
  19677. this.displacementBias = 0;
  19678. this.roughnessMap = null;
  19679. this.metalnessMap = null;
  19680. this.alphaMap = null;
  19681. this.envMap = null;
  19682. this.envMapIntensity = 1.0;
  19683. this.refractionRatio = 0.98;
  19684. this.wireframe = false;
  19685. this.wireframeLinewidth = 1;
  19686. this.wireframeLinecap = 'round';
  19687. this.wireframeLinejoin = 'round';
  19688. this.skinning = false;
  19689. this.morphTargets = false;
  19690. this.morphNormals = false;
  19691. this.flatShading = false;
  19692. this.vertexTangents = false;
  19693. this.setValues(parameters);
  19694. }
  19695. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19696. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19697. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19698. MeshStandardMaterial.prototype.copy = function (source) {
  19699. Material.prototype.copy.call(this, source);
  19700. this.defines = {
  19701. 'STANDARD': ''
  19702. };
  19703. this.color.copy(source.color);
  19704. this.roughness = source.roughness;
  19705. this.metalness = source.metalness;
  19706. this.map = source.map;
  19707. this.lightMap = source.lightMap;
  19708. this.lightMapIntensity = source.lightMapIntensity;
  19709. this.aoMap = source.aoMap;
  19710. this.aoMapIntensity = source.aoMapIntensity;
  19711. this.emissive.copy(source.emissive);
  19712. this.emissiveMap = source.emissiveMap;
  19713. this.emissiveIntensity = source.emissiveIntensity;
  19714. this.bumpMap = source.bumpMap;
  19715. this.bumpScale = source.bumpScale;
  19716. this.normalMap = source.normalMap;
  19717. this.normalMapType = source.normalMapType;
  19718. this.normalScale.copy(source.normalScale);
  19719. this.displacementMap = source.displacementMap;
  19720. this.displacementScale = source.displacementScale;
  19721. this.displacementBias = source.displacementBias;
  19722. this.roughnessMap = source.roughnessMap;
  19723. this.metalnessMap = source.metalnessMap;
  19724. this.alphaMap = source.alphaMap;
  19725. this.envMap = source.envMap;
  19726. this.envMapIntensity = source.envMapIntensity;
  19727. this.refractionRatio = source.refractionRatio;
  19728. this.wireframe = source.wireframe;
  19729. this.wireframeLinewidth = source.wireframeLinewidth;
  19730. this.wireframeLinecap = source.wireframeLinecap;
  19731. this.wireframeLinejoin = source.wireframeLinejoin;
  19732. this.skinning = source.skinning;
  19733. this.morphTargets = source.morphTargets;
  19734. this.morphNormals = source.morphNormals;
  19735. this.flatShading = source.flatShading;
  19736. this.vertexTangents = source.vertexTangents;
  19737. return this;
  19738. };
  19739. /**
  19740. * parameters = {
  19741. * clearcoat: <float>,
  19742. * clearcoatMap: new THREE.Texture( <Image> ),
  19743. * clearcoatRoughness: <float>,
  19744. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19745. * clearcoatNormalScale: <Vector2>,
  19746. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19747. *
  19748. * reflectivity: <float>,
  19749. * ior: <float>,
  19750. *
  19751. * sheen: <Color>,
  19752. *
  19753. * transmission: <float>,
  19754. * transmissionMap: new THREE.Texture( <Image> )
  19755. * }
  19756. */
  19757. function MeshPhysicalMaterial(parameters) {
  19758. MeshStandardMaterial.call(this);
  19759. this.defines = {
  19760. 'STANDARD': '',
  19761. 'PHYSICAL': ''
  19762. };
  19763. this.type = 'MeshPhysicalMaterial';
  19764. this.clearcoat = 0.0;
  19765. this.clearcoatMap = null;
  19766. this.clearcoatRoughness = 0.0;
  19767. this.clearcoatRoughnessMap = null;
  19768. this.clearcoatNormalScale = new Vector2(1, 1);
  19769. this.clearcoatNormalMap = null;
  19770. this.reflectivity = 0.5; // maps to F0 = 0.04
  19771. Object.defineProperty(this, 'ior', {
  19772. get: function get() {
  19773. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19774. },
  19775. set: function set(ior) {
  19776. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19777. }
  19778. });
  19779. this.sheen = null; // null will disable sheen bsdf
  19780. this.transmission = 0.0;
  19781. this.transmissionMap = null;
  19782. this.setValues(parameters);
  19783. }
  19784. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19785. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19786. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19787. MeshPhysicalMaterial.prototype.copy = function (source) {
  19788. MeshStandardMaterial.prototype.copy.call(this, source);
  19789. this.defines = {
  19790. 'STANDARD': '',
  19791. 'PHYSICAL': ''
  19792. };
  19793. this.clearcoat = source.clearcoat;
  19794. this.clearcoatMap = source.clearcoatMap;
  19795. this.clearcoatRoughness = source.clearcoatRoughness;
  19796. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19797. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19798. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19799. this.reflectivity = source.reflectivity;
  19800. if (source.sheen) {
  19801. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19802. } else {
  19803. this.sheen = null;
  19804. }
  19805. this.transmission = source.transmission;
  19806. this.transmissionMap = source.transmissionMap;
  19807. return this;
  19808. };
  19809. /**
  19810. * parameters = {
  19811. * color: <hex>,
  19812. * specular: <hex>,
  19813. * shininess: <float>,
  19814. * opacity: <float>,
  19815. *
  19816. * map: new THREE.Texture( <Image> ),
  19817. *
  19818. * lightMap: new THREE.Texture( <Image> ),
  19819. * lightMapIntensity: <float>
  19820. *
  19821. * aoMap: new THREE.Texture( <Image> ),
  19822. * aoMapIntensity: <float>
  19823. *
  19824. * emissive: <hex>,
  19825. * emissiveIntensity: <float>
  19826. * emissiveMap: new THREE.Texture( <Image> ),
  19827. *
  19828. * bumpMap: new THREE.Texture( <Image> ),
  19829. * bumpScale: <float>,
  19830. *
  19831. * normalMap: new THREE.Texture( <Image> ),
  19832. * normalMapType: THREE.TangentSpaceNormalMap,
  19833. * normalScale: <Vector2>,
  19834. *
  19835. * displacementMap: new THREE.Texture( <Image> ),
  19836. * displacementScale: <float>,
  19837. * displacementBias: <float>,
  19838. *
  19839. * specularMap: new THREE.Texture( <Image> ),
  19840. *
  19841. * alphaMap: new THREE.Texture( <Image> ),
  19842. *
  19843. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19844. * combine: THREE.MultiplyOperation,
  19845. * reflectivity: <float>,
  19846. * refractionRatio: <float>,
  19847. *
  19848. * wireframe: <boolean>,
  19849. * wireframeLinewidth: <float>,
  19850. *
  19851. * skinning: <bool>,
  19852. * morphTargets: <bool>,
  19853. * morphNormals: <bool>,
  19854. *
  19855. * flatShading: <bool>
  19856. * }
  19857. */
  19858. function MeshPhongMaterial(parameters) {
  19859. Material.call(this);
  19860. this.type = 'MeshPhongMaterial';
  19861. this.color = new Color(0xffffff); // diffuse
  19862. this.specular = new Color(0x111111);
  19863. this.shininess = 30;
  19864. this.map = null;
  19865. this.lightMap = null;
  19866. this.lightMapIntensity = 1.0;
  19867. this.aoMap = null;
  19868. this.aoMapIntensity = 1.0;
  19869. this.emissive = new Color(0x000000);
  19870. this.emissiveIntensity = 1.0;
  19871. this.emissiveMap = null;
  19872. this.bumpMap = null;
  19873. this.bumpScale = 1;
  19874. this.normalMap = null;
  19875. this.normalMapType = TangentSpaceNormalMap;
  19876. this.normalScale = new Vector2(1, 1);
  19877. this.displacementMap = null;
  19878. this.displacementScale = 1;
  19879. this.displacementBias = 0;
  19880. this.specularMap = null;
  19881. this.alphaMap = null;
  19882. this.envMap = null;
  19883. this.combine = MultiplyOperation;
  19884. this.reflectivity = 1;
  19885. this.refractionRatio = 0.98;
  19886. this.wireframe = false;
  19887. this.wireframeLinewidth = 1;
  19888. this.wireframeLinecap = 'round';
  19889. this.wireframeLinejoin = 'round';
  19890. this.skinning = false;
  19891. this.morphTargets = false;
  19892. this.morphNormals = false;
  19893. this.flatShading = false;
  19894. this.setValues(parameters);
  19895. }
  19896. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  19897. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19898. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19899. MeshPhongMaterial.prototype.copy = function (source) {
  19900. Material.prototype.copy.call(this, source);
  19901. this.color.copy(source.color);
  19902. this.specular.copy(source.specular);
  19903. this.shininess = source.shininess;
  19904. this.map = source.map;
  19905. this.lightMap = source.lightMap;
  19906. this.lightMapIntensity = source.lightMapIntensity;
  19907. this.aoMap = source.aoMap;
  19908. this.aoMapIntensity = source.aoMapIntensity;
  19909. this.emissive.copy(source.emissive);
  19910. this.emissiveMap = source.emissiveMap;
  19911. this.emissiveIntensity = source.emissiveIntensity;
  19912. this.bumpMap = source.bumpMap;
  19913. this.bumpScale = source.bumpScale;
  19914. this.normalMap = source.normalMap;
  19915. this.normalMapType = source.normalMapType;
  19916. this.normalScale.copy(source.normalScale);
  19917. this.displacementMap = source.displacementMap;
  19918. this.displacementScale = source.displacementScale;
  19919. this.displacementBias = source.displacementBias;
  19920. this.specularMap = source.specularMap;
  19921. this.alphaMap = source.alphaMap;
  19922. this.envMap = source.envMap;
  19923. this.combine = source.combine;
  19924. this.reflectivity = source.reflectivity;
  19925. this.refractionRatio = source.refractionRatio;
  19926. this.wireframe = source.wireframe;
  19927. this.wireframeLinewidth = source.wireframeLinewidth;
  19928. this.wireframeLinecap = source.wireframeLinecap;
  19929. this.wireframeLinejoin = source.wireframeLinejoin;
  19930. this.skinning = source.skinning;
  19931. this.morphTargets = source.morphTargets;
  19932. this.morphNormals = source.morphNormals;
  19933. this.flatShading = source.flatShading;
  19934. return this;
  19935. };
  19936. /**
  19937. * parameters = {
  19938. * color: <hex>,
  19939. *
  19940. * map: new THREE.Texture( <Image> ),
  19941. * gradientMap: new THREE.Texture( <Image> ),
  19942. *
  19943. * lightMap: new THREE.Texture( <Image> ),
  19944. * lightMapIntensity: <float>
  19945. *
  19946. * aoMap: new THREE.Texture( <Image> ),
  19947. * aoMapIntensity: <float>
  19948. *
  19949. * emissive: <hex>,
  19950. * emissiveIntensity: <float>
  19951. * emissiveMap: new THREE.Texture( <Image> ),
  19952. *
  19953. * bumpMap: new THREE.Texture( <Image> ),
  19954. * bumpScale: <float>,
  19955. *
  19956. * normalMap: new THREE.Texture( <Image> ),
  19957. * normalMapType: THREE.TangentSpaceNormalMap,
  19958. * normalScale: <Vector2>,
  19959. *
  19960. * displacementMap: new THREE.Texture( <Image> ),
  19961. * displacementScale: <float>,
  19962. * displacementBias: <float>,
  19963. *
  19964. * alphaMap: new THREE.Texture( <Image> ),
  19965. *
  19966. * wireframe: <boolean>,
  19967. * wireframeLinewidth: <float>,
  19968. *
  19969. * skinning: <bool>,
  19970. * morphTargets: <bool>,
  19971. * morphNormals: <bool>
  19972. * }
  19973. */
  19974. function MeshToonMaterial(parameters) {
  19975. Material.call(this);
  19976. this.defines = {
  19977. 'TOON': ''
  19978. };
  19979. this.type = 'MeshToonMaterial';
  19980. this.color = new Color(0xffffff);
  19981. this.map = null;
  19982. this.gradientMap = null;
  19983. this.lightMap = null;
  19984. this.lightMapIntensity = 1.0;
  19985. this.aoMap = null;
  19986. this.aoMapIntensity = 1.0;
  19987. this.emissive = new Color(0x000000);
  19988. this.emissiveIntensity = 1.0;
  19989. this.emissiveMap = null;
  19990. this.bumpMap = null;
  19991. this.bumpScale = 1;
  19992. this.normalMap = null;
  19993. this.normalMapType = TangentSpaceNormalMap;
  19994. this.normalScale = new Vector2(1, 1);
  19995. this.displacementMap = null;
  19996. this.displacementScale = 1;
  19997. this.displacementBias = 0;
  19998. this.alphaMap = null;
  19999. this.wireframe = false;
  20000. this.wireframeLinewidth = 1;
  20001. this.wireframeLinecap = 'round';
  20002. this.wireframeLinejoin = 'round';
  20003. this.skinning = false;
  20004. this.morphTargets = false;
  20005. this.morphNormals = false;
  20006. this.setValues(parameters);
  20007. }
  20008. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20009. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20010. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20011. MeshToonMaterial.prototype.copy = function (source) {
  20012. Material.prototype.copy.call(this, source);
  20013. this.color.copy(source.color);
  20014. this.map = source.map;
  20015. this.gradientMap = source.gradientMap;
  20016. this.lightMap = source.lightMap;
  20017. this.lightMapIntensity = source.lightMapIntensity;
  20018. this.aoMap = source.aoMap;
  20019. this.aoMapIntensity = source.aoMapIntensity;
  20020. this.emissive.copy(source.emissive);
  20021. this.emissiveMap = source.emissiveMap;
  20022. this.emissiveIntensity = source.emissiveIntensity;
  20023. this.bumpMap = source.bumpMap;
  20024. this.bumpScale = source.bumpScale;
  20025. this.normalMap = source.normalMap;
  20026. this.normalMapType = source.normalMapType;
  20027. this.normalScale.copy(source.normalScale);
  20028. this.displacementMap = source.displacementMap;
  20029. this.displacementScale = source.displacementScale;
  20030. this.displacementBias = source.displacementBias;
  20031. this.alphaMap = source.alphaMap;
  20032. this.wireframe = source.wireframe;
  20033. this.wireframeLinewidth = source.wireframeLinewidth;
  20034. this.wireframeLinecap = source.wireframeLinecap;
  20035. this.wireframeLinejoin = source.wireframeLinejoin;
  20036. this.skinning = source.skinning;
  20037. this.morphTargets = source.morphTargets;
  20038. this.morphNormals = source.morphNormals;
  20039. return this;
  20040. };
  20041. /**
  20042. * parameters = {
  20043. * opacity: <float>,
  20044. *
  20045. * bumpMap: new THREE.Texture( <Image> ),
  20046. * bumpScale: <float>,
  20047. *
  20048. * normalMap: new THREE.Texture( <Image> ),
  20049. * normalMapType: THREE.TangentSpaceNormalMap,
  20050. * normalScale: <Vector2>,
  20051. *
  20052. * displacementMap: new THREE.Texture( <Image> ),
  20053. * displacementScale: <float>,
  20054. * displacementBias: <float>,
  20055. *
  20056. * wireframe: <boolean>,
  20057. * wireframeLinewidth: <float>
  20058. *
  20059. * skinning: <bool>,
  20060. * morphTargets: <bool>,
  20061. * morphNormals: <bool>,
  20062. *
  20063. * flatShading: <bool>
  20064. * }
  20065. */
  20066. function MeshNormalMaterial(parameters) {
  20067. Material.call(this);
  20068. this.type = 'MeshNormalMaterial';
  20069. this.bumpMap = null;
  20070. this.bumpScale = 1;
  20071. this.normalMap = null;
  20072. this.normalMapType = TangentSpaceNormalMap;
  20073. this.normalScale = new Vector2(1, 1);
  20074. this.displacementMap = null;
  20075. this.displacementScale = 1;
  20076. this.displacementBias = 0;
  20077. this.wireframe = false;
  20078. this.wireframeLinewidth = 1;
  20079. this.fog = false;
  20080. this.skinning = false;
  20081. this.morphTargets = false;
  20082. this.morphNormals = false;
  20083. this.flatShading = false;
  20084. this.setValues(parameters);
  20085. }
  20086. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20087. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20088. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20089. MeshNormalMaterial.prototype.copy = function (source) {
  20090. Material.prototype.copy.call(this, source);
  20091. this.bumpMap = source.bumpMap;
  20092. this.bumpScale = source.bumpScale;
  20093. this.normalMap = source.normalMap;
  20094. this.normalMapType = source.normalMapType;
  20095. this.normalScale.copy(source.normalScale);
  20096. this.displacementMap = source.displacementMap;
  20097. this.displacementScale = source.displacementScale;
  20098. this.displacementBias = source.displacementBias;
  20099. this.wireframe = source.wireframe;
  20100. this.wireframeLinewidth = source.wireframeLinewidth;
  20101. this.skinning = source.skinning;
  20102. this.morphTargets = source.morphTargets;
  20103. this.morphNormals = source.morphNormals;
  20104. this.flatShading = source.flatShading;
  20105. return this;
  20106. };
  20107. /**
  20108. * parameters = {
  20109. * color: <hex>,
  20110. * opacity: <float>,
  20111. *
  20112. * map: new THREE.Texture( <Image> ),
  20113. *
  20114. * lightMap: new THREE.Texture( <Image> ),
  20115. * lightMapIntensity: <float>
  20116. *
  20117. * aoMap: new THREE.Texture( <Image> ),
  20118. * aoMapIntensity: <float>
  20119. *
  20120. * emissive: <hex>,
  20121. * emissiveIntensity: <float>
  20122. * emissiveMap: new THREE.Texture( <Image> ),
  20123. *
  20124. * specularMap: new THREE.Texture( <Image> ),
  20125. *
  20126. * alphaMap: new THREE.Texture( <Image> ),
  20127. *
  20128. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20129. * combine: THREE.Multiply,
  20130. * reflectivity: <float>,
  20131. * refractionRatio: <float>,
  20132. *
  20133. * wireframe: <boolean>,
  20134. * wireframeLinewidth: <float>,
  20135. *
  20136. * skinning: <bool>,
  20137. * morphTargets: <bool>,
  20138. * morphNormals: <bool>
  20139. * }
  20140. */
  20141. function MeshLambertMaterial(parameters) {
  20142. Material.call(this);
  20143. this.type = 'MeshLambertMaterial';
  20144. this.color = new Color(0xffffff); // diffuse
  20145. this.map = null;
  20146. this.lightMap = null;
  20147. this.lightMapIntensity = 1.0;
  20148. this.aoMap = null;
  20149. this.aoMapIntensity = 1.0;
  20150. this.emissive = new Color(0x000000);
  20151. this.emissiveIntensity = 1.0;
  20152. this.emissiveMap = null;
  20153. this.specularMap = null;
  20154. this.alphaMap = null;
  20155. this.envMap = null;
  20156. this.combine = MultiplyOperation;
  20157. this.reflectivity = 1;
  20158. this.refractionRatio = 0.98;
  20159. this.wireframe = false;
  20160. this.wireframeLinewidth = 1;
  20161. this.wireframeLinecap = 'round';
  20162. this.wireframeLinejoin = 'round';
  20163. this.skinning = false;
  20164. this.morphTargets = false;
  20165. this.morphNormals = false;
  20166. this.setValues(parameters);
  20167. }
  20168. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20169. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20170. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20171. MeshLambertMaterial.prototype.copy = function (source) {
  20172. Material.prototype.copy.call(this, source);
  20173. this.color.copy(source.color);
  20174. this.map = source.map;
  20175. this.lightMap = source.lightMap;
  20176. this.lightMapIntensity = source.lightMapIntensity;
  20177. this.aoMap = source.aoMap;
  20178. this.aoMapIntensity = source.aoMapIntensity;
  20179. this.emissive.copy(source.emissive);
  20180. this.emissiveMap = source.emissiveMap;
  20181. this.emissiveIntensity = source.emissiveIntensity;
  20182. this.specularMap = source.specularMap;
  20183. this.alphaMap = source.alphaMap;
  20184. this.envMap = source.envMap;
  20185. this.combine = source.combine;
  20186. this.reflectivity = source.reflectivity;
  20187. this.refractionRatio = source.refractionRatio;
  20188. this.wireframe = source.wireframe;
  20189. this.wireframeLinewidth = source.wireframeLinewidth;
  20190. this.wireframeLinecap = source.wireframeLinecap;
  20191. this.wireframeLinejoin = source.wireframeLinejoin;
  20192. this.skinning = source.skinning;
  20193. this.morphTargets = source.morphTargets;
  20194. this.morphNormals = source.morphNormals;
  20195. return this;
  20196. };
  20197. /**
  20198. * parameters = {
  20199. * color: <hex>,
  20200. * opacity: <float>,
  20201. *
  20202. * matcap: new THREE.Texture( <Image> ),
  20203. *
  20204. * map: new THREE.Texture( <Image> ),
  20205. *
  20206. * bumpMap: new THREE.Texture( <Image> ),
  20207. * bumpScale: <float>,
  20208. *
  20209. * normalMap: new THREE.Texture( <Image> ),
  20210. * normalMapType: THREE.TangentSpaceNormalMap,
  20211. * normalScale: <Vector2>,
  20212. *
  20213. * displacementMap: new THREE.Texture( <Image> ),
  20214. * displacementScale: <float>,
  20215. * displacementBias: <float>,
  20216. *
  20217. * alphaMap: new THREE.Texture( <Image> ),
  20218. *
  20219. * skinning: <bool>,
  20220. * morphTargets: <bool>,
  20221. * morphNormals: <bool>
  20222. *
  20223. * flatShading: <bool>
  20224. * }
  20225. */
  20226. function MeshMatcapMaterial(parameters) {
  20227. Material.call(this);
  20228. this.defines = {
  20229. 'MATCAP': ''
  20230. };
  20231. this.type = 'MeshMatcapMaterial';
  20232. this.color = new Color(0xffffff); // diffuse
  20233. this.matcap = null;
  20234. this.map = null;
  20235. this.bumpMap = null;
  20236. this.bumpScale = 1;
  20237. this.normalMap = null;
  20238. this.normalMapType = TangentSpaceNormalMap;
  20239. this.normalScale = new Vector2(1, 1);
  20240. this.displacementMap = null;
  20241. this.displacementScale = 1;
  20242. this.displacementBias = 0;
  20243. this.alphaMap = null;
  20244. this.skinning = false;
  20245. this.morphTargets = false;
  20246. this.morphNormals = false;
  20247. this.flatShading = false;
  20248. this.setValues(parameters);
  20249. }
  20250. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20251. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20252. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20253. MeshMatcapMaterial.prototype.copy = function (source) {
  20254. Material.prototype.copy.call(this, source);
  20255. this.defines = {
  20256. 'MATCAP': ''
  20257. };
  20258. this.color.copy(source.color);
  20259. this.matcap = source.matcap;
  20260. this.map = source.map;
  20261. this.bumpMap = source.bumpMap;
  20262. this.bumpScale = source.bumpScale;
  20263. this.normalMap = source.normalMap;
  20264. this.normalMapType = source.normalMapType;
  20265. this.normalScale.copy(source.normalScale);
  20266. this.displacementMap = source.displacementMap;
  20267. this.displacementScale = source.displacementScale;
  20268. this.displacementBias = source.displacementBias;
  20269. this.alphaMap = source.alphaMap;
  20270. this.skinning = source.skinning;
  20271. this.morphTargets = source.morphTargets;
  20272. this.morphNormals = source.morphNormals;
  20273. this.flatShading = source.flatShading;
  20274. return this;
  20275. };
  20276. /**
  20277. * parameters = {
  20278. * color: <hex>,
  20279. * opacity: <float>,
  20280. *
  20281. * linewidth: <float>,
  20282. *
  20283. * scale: <float>,
  20284. * dashSize: <float>,
  20285. * gapSize: <float>
  20286. * }
  20287. */
  20288. function LineDashedMaterial(parameters) {
  20289. LineBasicMaterial.call(this);
  20290. this.type = 'LineDashedMaterial';
  20291. this.scale = 1;
  20292. this.dashSize = 3;
  20293. this.gapSize = 1;
  20294. this.setValues(parameters);
  20295. }
  20296. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20297. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20298. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20299. LineDashedMaterial.prototype.copy = function (source) {
  20300. LineBasicMaterial.prototype.copy.call(this, source);
  20301. this.scale = source.scale;
  20302. this.dashSize = source.dashSize;
  20303. this.gapSize = source.gapSize;
  20304. return this;
  20305. };
  20306. var Materials = /*#__PURE__*/Object.freeze({
  20307. __proto__: null,
  20308. ShadowMaterial: ShadowMaterial,
  20309. SpriteMaterial: SpriteMaterial,
  20310. RawShaderMaterial: RawShaderMaterial,
  20311. ShaderMaterial: ShaderMaterial,
  20312. PointsMaterial: PointsMaterial,
  20313. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20314. MeshStandardMaterial: MeshStandardMaterial,
  20315. MeshPhongMaterial: MeshPhongMaterial,
  20316. MeshToonMaterial: MeshToonMaterial,
  20317. MeshNormalMaterial: MeshNormalMaterial,
  20318. MeshLambertMaterial: MeshLambertMaterial,
  20319. MeshDepthMaterial: MeshDepthMaterial,
  20320. MeshDistanceMaterial: MeshDistanceMaterial,
  20321. MeshBasicMaterial: MeshBasicMaterial,
  20322. MeshMatcapMaterial: MeshMatcapMaterial,
  20323. LineDashedMaterial: LineDashedMaterial,
  20324. LineBasicMaterial: LineBasicMaterial,
  20325. Material: Material
  20326. });
  20327. var AnimationUtils = {
  20328. // same as Array.prototype.slice, but also works on typed arrays
  20329. arraySlice: function arraySlice(array, from, to) {
  20330. if (AnimationUtils.isTypedArray(array)) {
  20331. // in ios9 array.subarray(from, undefined) will return empty array
  20332. // but array.subarray(from) or array.subarray(from, len) is correct
  20333. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20334. }
  20335. return array.slice(from, to);
  20336. },
  20337. // converts an array to a specific type
  20338. convertArray: function convertArray(array, type, forceClone) {
  20339. if (!array || // let 'undefined' and 'null' pass
  20340. !forceClone && array.constructor === type) return array;
  20341. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20342. return new type(array); // create typed array
  20343. }
  20344. return Array.prototype.slice.call(array); // create Array
  20345. },
  20346. isTypedArray: function isTypedArray(object) {
  20347. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20348. },
  20349. // returns an array by which times and values can be sorted
  20350. getKeyframeOrder: function getKeyframeOrder(times) {
  20351. function compareTime(i, j) {
  20352. return times[i] - times[j];
  20353. }
  20354. var n = times.length;
  20355. var result = new Array(n);
  20356. for (var i = 0; i !== n; ++i) {
  20357. result[i] = i;
  20358. }
  20359. result.sort(compareTime);
  20360. return result;
  20361. },
  20362. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20363. sortedArray: function sortedArray(values, stride, order) {
  20364. var nValues = values.length;
  20365. var result = new values.constructor(nValues);
  20366. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20367. var srcOffset = order[i] * stride;
  20368. for (var j = 0; j !== stride; ++j) {
  20369. result[dstOffset++] = values[srcOffset + j];
  20370. }
  20371. }
  20372. return result;
  20373. },
  20374. // function for parsing AOS keyframe formats
  20375. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20376. var i = 1,
  20377. key = jsonKeys[0];
  20378. while (key !== undefined && key[valuePropertyName] === undefined) {
  20379. key = jsonKeys[i++];
  20380. }
  20381. if (key === undefined) return; // no data
  20382. var value = key[valuePropertyName];
  20383. if (value === undefined) return; // no data
  20384. if (Array.isArray(value)) {
  20385. do {
  20386. value = key[valuePropertyName];
  20387. if (value !== undefined) {
  20388. times.push(key.time);
  20389. values.push.apply(values, value); // push all elements
  20390. }
  20391. key = jsonKeys[i++];
  20392. } while (key !== undefined);
  20393. } else if (value.toArray !== undefined) {
  20394. // ...assume THREE.Math-ish
  20395. do {
  20396. value = key[valuePropertyName];
  20397. if (value !== undefined) {
  20398. times.push(key.time);
  20399. value.toArray(values, values.length);
  20400. }
  20401. key = jsonKeys[i++];
  20402. } while (key !== undefined);
  20403. } else {
  20404. // otherwise push as-is
  20405. do {
  20406. value = key[valuePropertyName];
  20407. if (value !== undefined) {
  20408. times.push(key.time);
  20409. values.push(value);
  20410. }
  20411. key = jsonKeys[i++];
  20412. } while (key !== undefined);
  20413. }
  20414. },
  20415. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20416. if (fps === void 0) {
  20417. fps = 30;
  20418. }
  20419. var clip = sourceClip.clone();
  20420. clip.name = name;
  20421. var tracks = [];
  20422. for (var i = 0; i < clip.tracks.length; ++i) {
  20423. var track = clip.tracks[i];
  20424. var valueSize = track.getValueSize();
  20425. var times = [];
  20426. var values = [];
  20427. for (var j = 0; j < track.times.length; ++j) {
  20428. var frame = track.times[j] * fps;
  20429. if (frame < startFrame || frame >= endFrame) continue;
  20430. times.push(track.times[j]);
  20431. for (var k = 0; k < valueSize; ++k) {
  20432. values.push(track.values[j * valueSize + k]);
  20433. }
  20434. }
  20435. if (times.length === 0) continue;
  20436. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20437. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20438. tracks.push(track);
  20439. }
  20440. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20441. var minStartTime = Infinity;
  20442. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20443. if (minStartTime > clip.tracks[_i].times[0]) {
  20444. minStartTime = clip.tracks[_i].times[0];
  20445. }
  20446. } // shift all tracks such that clip begins at t=0
  20447. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20448. clip.tracks[_i2].shift(-1 * minStartTime);
  20449. }
  20450. clip.resetDuration();
  20451. return clip;
  20452. },
  20453. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20454. if (referenceFrame === void 0) {
  20455. referenceFrame = 0;
  20456. }
  20457. if (referenceClip === void 0) {
  20458. referenceClip = targetClip;
  20459. }
  20460. if (fps === void 0) {
  20461. fps = 30;
  20462. }
  20463. if (fps <= 0) fps = 30;
  20464. var numTracks = referenceClip.tracks.length;
  20465. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20466. var _loop = function _loop(i) {
  20467. var referenceTrack = referenceClip.tracks[i];
  20468. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20469. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20470. var targetTrack = targetClip.tracks.find(function (track) {
  20471. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20472. });
  20473. if (targetTrack === undefined) return "continue";
  20474. var referenceOffset = 0;
  20475. var referenceValueSize = referenceTrack.getValueSize();
  20476. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20477. referenceOffset = referenceValueSize / 3;
  20478. }
  20479. var targetOffset = 0;
  20480. var targetValueSize = targetTrack.getValueSize();
  20481. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20482. targetOffset = targetValueSize / 3;
  20483. }
  20484. var lastIndex = referenceTrack.times.length - 1;
  20485. var referenceValue = void 0; // Find the value to subtract out of the track
  20486. if (referenceTime <= referenceTrack.times[0]) {
  20487. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20488. var startIndex = referenceOffset;
  20489. var endIndex = referenceValueSize - referenceOffset;
  20490. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20491. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20492. // Reference frame is after the last keyframe, so just use the last keyframe
  20493. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20494. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20495. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20496. } else {
  20497. // Interpolate to the reference value
  20498. var interpolant = referenceTrack.createInterpolant();
  20499. var _startIndex2 = referenceOffset;
  20500. var _endIndex2 = referenceValueSize - referenceOffset;
  20501. interpolant.evaluate(referenceTime);
  20502. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20503. } // Conjugate the quaternion
  20504. if (referenceTrackType === 'quaternion') {
  20505. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20506. referenceQuat.toArray(referenceValue);
  20507. } // Subtract the reference value from all of the track values
  20508. var numTimes = targetTrack.times.length;
  20509. for (var j = 0; j < numTimes; ++j) {
  20510. var valueStart = j * targetValueSize + targetOffset;
  20511. if (referenceTrackType === 'quaternion') {
  20512. // Multiply the conjugate for quaternion track types
  20513. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20514. } else {
  20515. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20516. for (var k = 0; k < valueEnd; ++k) {
  20517. targetTrack.values[valueStart + k] -= referenceValue[k];
  20518. }
  20519. }
  20520. }
  20521. };
  20522. for (var i = 0; i < numTracks; ++i) {
  20523. var _ret = _loop(i);
  20524. if (_ret === "continue") continue;
  20525. }
  20526. targetClip.blendMode = AdditiveAnimationBlendMode;
  20527. return targetClip;
  20528. }
  20529. };
  20530. /**
  20531. * Abstract base class of interpolants over parametric samples.
  20532. *
  20533. * The parameter domain is one dimensional, typically the time or a path
  20534. * along a curve defined by the data.
  20535. *
  20536. * The sample values can have any dimensionality and derived classes may
  20537. * apply special interpretations to the data.
  20538. *
  20539. * This class provides the interval seek in a Template Method, deferring
  20540. * the actual interpolation to derived classes.
  20541. *
  20542. * Time complexity is O(1) for linear access crossing at most two points
  20543. * and O(log N) for random access, where N is the number of positions.
  20544. *
  20545. * References:
  20546. *
  20547. * http://www.oodesign.com/template-method-pattern.html
  20548. *
  20549. */
  20550. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20551. this.parameterPositions = parameterPositions;
  20552. this._cachedIndex = 0;
  20553. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20554. this.sampleValues = sampleValues;
  20555. this.valueSize = sampleSize;
  20556. }
  20557. Object.assign(Interpolant.prototype, {
  20558. evaluate: function evaluate(t) {
  20559. var pp = this.parameterPositions;
  20560. var i1 = this._cachedIndex,
  20561. t1 = pp[i1],
  20562. t0 = pp[i1 - 1];
  20563. validate_interval: {
  20564. seek: {
  20565. var right;
  20566. linear_scan: {
  20567. //- See http://jsperf.com/comparison-to-undefined/3
  20568. //- slower code:
  20569. //-
  20570. //- if ( t >= t1 || t1 === undefined ) {
  20571. forward_scan: if (!(t < t1)) {
  20572. for (var giveUpAt = i1 + 2;;) {
  20573. if (t1 === undefined) {
  20574. if (t < t0) break forward_scan; // after end
  20575. i1 = pp.length;
  20576. this._cachedIndex = i1;
  20577. return this.afterEnd_(i1 - 1, t, t0);
  20578. }
  20579. if (i1 === giveUpAt) break; // this loop
  20580. t0 = t1;
  20581. t1 = pp[++i1];
  20582. if (t < t1) {
  20583. // we have arrived at the sought interval
  20584. break seek;
  20585. }
  20586. } // prepare binary search on the right side of the index
  20587. right = pp.length;
  20588. break linear_scan;
  20589. } //- slower code:
  20590. //- if ( t < t0 || t0 === undefined ) {
  20591. if (!(t >= t0)) {
  20592. // looping?
  20593. var t1global = pp[1];
  20594. if (t < t1global) {
  20595. i1 = 2; // + 1, using the scan for the details
  20596. t0 = t1global;
  20597. } // linear reverse scan
  20598. for (var _giveUpAt = i1 - 2;;) {
  20599. if (t0 === undefined) {
  20600. // before start
  20601. this._cachedIndex = 0;
  20602. return this.beforeStart_(0, t, t1);
  20603. }
  20604. if (i1 === _giveUpAt) break; // this loop
  20605. t1 = t0;
  20606. t0 = pp[--i1 - 1];
  20607. if (t >= t0) {
  20608. // we have arrived at the sought interval
  20609. break seek;
  20610. }
  20611. } // prepare binary search on the left side of the index
  20612. right = i1;
  20613. i1 = 0;
  20614. break linear_scan;
  20615. } // the interval is valid
  20616. break validate_interval;
  20617. } // linear scan
  20618. // binary search
  20619. while (i1 < right) {
  20620. var mid = i1 + right >>> 1;
  20621. if (t < pp[mid]) {
  20622. right = mid;
  20623. } else {
  20624. i1 = mid + 1;
  20625. }
  20626. }
  20627. t1 = pp[i1];
  20628. t0 = pp[i1 - 1]; // check boundary cases, again
  20629. if (t0 === undefined) {
  20630. this._cachedIndex = 0;
  20631. return this.beforeStart_(0, t, t1);
  20632. }
  20633. if (t1 === undefined) {
  20634. i1 = pp.length;
  20635. this._cachedIndex = i1;
  20636. return this.afterEnd_(i1 - 1, t0, t);
  20637. }
  20638. } // seek
  20639. this._cachedIndex = i1;
  20640. this.intervalChanged_(i1, t0, t1);
  20641. } // validate_interval
  20642. return this.interpolate_(i1, t0, t, t1);
  20643. },
  20644. settings: null,
  20645. // optional, subclass-specific settings structure
  20646. // Note: The indirection allows central control of many interpolants.
  20647. // --- Protected interface
  20648. DefaultSettings_: {},
  20649. getSettings_: function getSettings_() {
  20650. return this.settings || this.DefaultSettings_;
  20651. },
  20652. copySampleValue_: function copySampleValue_(index) {
  20653. // copies a sample value to the result buffer
  20654. var result = this.resultBuffer,
  20655. values = this.sampleValues,
  20656. stride = this.valueSize,
  20657. offset = index * stride;
  20658. for (var i = 0; i !== stride; ++i) {
  20659. result[i] = values[offset + i];
  20660. }
  20661. return result;
  20662. },
  20663. // Template methods for derived classes:
  20664. interpolate_: function interpolate_()
  20665. /* i1, t0, t, t1 */
  20666. {
  20667. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20668. },
  20669. intervalChanged_: function intervalChanged_()
  20670. /* i1, t0, t1 */
  20671. {// empty
  20672. }
  20673. }); // DECLARE ALIAS AFTER assign prototype
  20674. Object.assign(Interpolant.prototype, {
  20675. //( 0, t, t0 ), returns this.resultBuffer
  20676. beforeStart_: Interpolant.prototype.copySampleValue_,
  20677. //( N-1, tN-1, t ), returns this.resultBuffer
  20678. afterEnd_: Interpolant.prototype.copySampleValue_
  20679. });
  20680. /**
  20681. * Fast and simple cubic spline interpolant.
  20682. *
  20683. * It was derived from a Hermitian construction setting the first derivative
  20684. * at each sample position to the linear slope between neighboring positions
  20685. * over their parameter interval.
  20686. */
  20687. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20688. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20689. this._weightPrev = -0;
  20690. this._offsetPrev = -0;
  20691. this._weightNext = -0;
  20692. this._offsetNext = -0;
  20693. }
  20694. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20695. constructor: CubicInterpolant,
  20696. DefaultSettings_: {
  20697. endingStart: ZeroCurvatureEnding,
  20698. endingEnd: ZeroCurvatureEnding
  20699. },
  20700. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20701. var pp = this.parameterPositions;
  20702. var iPrev = i1 - 2,
  20703. iNext = i1 + 1,
  20704. tPrev = pp[iPrev],
  20705. tNext = pp[iNext];
  20706. if (tPrev === undefined) {
  20707. switch (this.getSettings_().endingStart) {
  20708. case ZeroSlopeEnding:
  20709. // f'(t0) = 0
  20710. iPrev = i1;
  20711. tPrev = 2 * t0 - t1;
  20712. break;
  20713. case WrapAroundEnding:
  20714. // use the other end of the curve
  20715. iPrev = pp.length - 2;
  20716. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20717. break;
  20718. default:
  20719. // ZeroCurvatureEnding
  20720. // f''(t0) = 0 a.k.a. Natural Spline
  20721. iPrev = i1;
  20722. tPrev = t1;
  20723. }
  20724. }
  20725. if (tNext === undefined) {
  20726. switch (this.getSettings_().endingEnd) {
  20727. case ZeroSlopeEnding:
  20728. // f'(tN) = 0
  20729. iNext = i1;
  20730. tNext = 2 * t1 - t0;
  20731. break;
  20732. case WrapAroundEnding:
  20733. // use the other end of the curve
  20734. iNext = 1;
  20735. tNext = t1 + pp[1] - pp[0];
  20736. break;
  20737. default:
  20738. // ZeroCurvatureEnding
  20739. // f''(tN) = 0, a.k.a. Natural Spline
  20740. iNext = i1 - 1;
  20741. tNext = t0;
  20742. }
  20743. }
  20744. var halfDt = (t1 - t0) * 0.5,
  20745. stride = this.valueSize;
  20746. this._weightPrev = halfDt / (t0 - tPrev);
  20747. this._weightNext = halfDt / (tNext - t1);
  20748. this._offsetPrev = iPrev * stride;
  20749. this._offsetNext = iNext * stride;
  20750. },
  20751. interpolate_: function interpolate_(i1, t0, t, t1) {
  20752. var result = this.resultBuffer,
  20753. values = this.sampleValues,
  20754. stride = this.valueSize,
  20755. o1 = i1 * stride,
  20756. o0 = o1 - stride,
  20757. oP = this._offsetPrev,
  20758. oN = this._offsetNext,
  20759. wP = this._weightPrev,
  20760. wN = this._weightNext,
  20761. p = (t - t0) / (t1 - t0),
  20762. pp = p * p,
  20763. ppp = pp * p; // evaluate polynomials
  20764. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20765. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20766. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20767. var sN = wN * ppp - wN * pp; // combine data linearly
  20768. for (var i = 0; i !== stride; ++i) {
  20769. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20770. }
  20771. return result;
  20772. }
  20773. });
  20774. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20775. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20776. }
  20777. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20778. constructor: LinearInterpolant,
  20779. interpolate_: function interpolate_(i1, t0, t, t1) {
  20780. var result = this.resultBuffer,
  20781. values = this.sampleValues,
  20782. stride = this.valueSize,
  20783. offset1 = i1 * stride,
  20784. offset0 = offset1 - stride,
  20785. weight1 = (t - t0) / (t1 - t0),
  20786. weight0 = 1 - weight1;
  20787. for (var i = 0; i !== stride; ++i) {
  20788. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20789. }
  20790. return result;
  20791. }
  20792. });
  20793. /**
  20794. *
  20795. * Interpolant that evaluates to the sample value at the position preceeding
  20796. * the parameter.
  20797. */
  20798. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20799. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20800. }
  20801. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20802. constructor: DiscreteInterpolant,
  20803. interpolate_: function interpolate_(i1
  20804. /*, t0, t, t1 */
  20805. ) {
  20806. return this.copySampleValue_(i1 - 1);
  20807. }
  20808. });
  20809. function KeyframeTrack(name, times, values, interpolation) {
  20810. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20811. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20812. this.name = name;
  20813. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20814. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20815. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20816. } // Static methods
  20817. Object.assign(KeyframeTrack, {
  20818. // Serialization (in static context, because of constructor invocation
  20819. // and automatic invocation of .toJSON):
  20820. toJSON: function toJSON(track) {
  20821. var trackType = track.constructor;
  20822. var json; // derived classes can define a static toJSON method
  20823. if (trackType.toJSON !== undefined) {
  20824. json = trackType.toJSON(track);
  20825. } else {
  20826. // by default, we assume the data can be serialized as-is
  20827. json = {
  20828. 'name': track.name,
  20829. 'times': AnimationUtils.convertArray(track.times, Array),
  20830. 'values': AnimationUtils.convertArray(track.values, Array)
  20831. };
  20832. var interpolation = track.getInterpolation();
  20833. if (interpolation !== track.DefaultInterpolation) {
  20834. json.interpolation = interpolation;
  20835. }
  20836. }
  20837. json.type = track.ValueTypeName; // mandatory
  20838. return json;
  20839. }
  20840. });
  20841. Object.assign(KeyframeTrack.prototype, {
  20842. constructor: KeyframeTrack,
  20843. TimeBufferType: Float32Array,
  20844. ValueBufferType: Float32Array,
  20845. DefaultInterpolation: InterpolateLinear,
  20846. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20847. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20848. },
  20849. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20850. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20851. },
  20852. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20853. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20854. },
  20855. setInterpolation: function setInterpolation(interpolation) {
  20856. var factoryMethod;
  20857. switch (interpolation) {
  20858. case InterpolateDiscrete:
  20859. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20860. break;
  20861. case InterpolateLinear:
  20862. factoryMethod = this.InterpolantFactoryMethodLinear;
  20863. break;
  20864. case InterpolateSmooth:
  20865. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20866. break;
  20867. }
  20868. if (factoryMethod === undefined) {
  20869. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  20870. if (this.createInterpolant === undefined) {
  20871. // fall back to default, unless the default itself is messed up
  20872. if (interpolation !== this.DefaultInterpolation) {
  20873. this.setInterpolation(this.DefaultInterpolation);
  20874. } else {
  20875. throw new Error(message); // fatal, in this case
  20876. }
  20877. }
  20878. console.warn('THREE.KeyframeTrack:', message);
  20879. return this;
  20880. }
  20881. this.createInterpolant = factoryMethod;
  20882. return this;
  20883. },
  20884. getInterpolation: function getInterpolation() {
  20885. switch (this.createInterpolant) {
  20886. case this.InterpolantFactoryMethodDiscrete:
  20887. return InterpolateDiscrete;
  20888. case this.InterpolantFactoryMethodLinear:
  20889. return InterpolateLinear;
  20890. case this.InterpolantFactoryMethodSmooth:
  20891. return InterpolateSmooth;
  20892. }
  20893. },
  20894. getValueSize: function getValueSize() {
  20895. return this.values.length / this.times.length;
  20896. },
  20897. // move all keyframes either forwards or backwards in time
  20898. shift: function shift(timeOffset) {
  20899. if (timeOffset !== 0.0) {
  20900. var times = this.times;
  20901. for (var i = 0, n = times.length; i !== n; ++i) {
  20902. times[i] += timeOffset;
  20903. }
  20904. }
  20905. return this;
  20906. },
  20907. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20908. scale: function scale(timeScale) {
  20909. if (timeScale !== 1.0) {
  20910. var times = this.times;
  20911. for (var i = 0, n = times.length; i !== n; ++i) {
  20912. times[i] *= timeScale;
  20913. }
  20914. }
  20915. return this;
  20916. },
  20917. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20918. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20919. trim: function trim(startTime, endTime) {
  20920. var times = this.times,
  20921. nKeys = times.length;
  20922. var from = 0,
  20923. to = nKeys - 1;
  20924. while (from !== nKeys && times[from] < startTime) {
  20925. ++from;
  20926. }
  20927. while (to !== -1 && times[to] > endTime) {
  20928. --to;
  20929. }
  20930. ++to; // inclusive -> exclusive bound
  20931. if (from !== 0 || to !== nKeys) {
  20932. // empty tracks are forbidden, so keep at least one keyframe
  20933. if (from >= to) {
  20934. to = Math.max(to, 1);
  20935. from = to - 1;
  20936. }
  20937. var stride = this.getValueSize();
  20938. this.times = AnimationUtils.arraySlice(times, from, to);
  20939. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  20940. }
  20941. return this;
  20942. },
  20943. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20944. validate: function validate() {
  20945. var valid = true;
  20946. var valueSize = this.getValueSize();
  20947. if (valueSize - Math.floor(valueSize) !== 0) {
  20948. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  20949. valid = false;
  20950. }
  20951. var times = this.times,
  20952. values = this.values,
  20953. nKeys = times.length;
  20954. if (nKeys === 0) {
  20955. console.error('THREE.KeyframeTrack: Track is empty.', this);
  20956. valid = false;
  20957. }
  20958. var prevTime = null;
  20959. for (var i = 0; i !== nKeys; i++) {
  20960. var currTime = times[i];
  20961. if (typeof currTime === 'number' && isNaN(currTime)) {
  20962. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  20963. valid = false;
  20964. break;
  20965. }
  20966. if (prevTime !== null && prevTime > currTime) {
  20967. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  20968. valid = false;
  20969. break;
  20970. }
  20971. prevTime = currTime;
  20972. }
  20973. if (values !== undefined) {
  20974. if (AnimationUtils.isTypedArray(values)) {
  20975. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  20976. var value = values[_i];
  20977. if (isNaN(value)) {
  20978. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  20979. valid = false;
  20980. break;
  20981. }
  20982. }
  20983. }
  20984. }
  20985. return valid;
  20986. },
  20987. // removes equivalent sequential keys as common in morph target sequences
  20988. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20989. optimize: function optimize() {
  20990. // times or values may be shared with other tracks, so overwriting is unsafe
  20991. var times = AnimationUtils.arraySlice(this.times),
  20992. values = AnimationUtils.arraySlice(this.values),
  20993. stride = this.getValueSize(),
  20994. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20995. lastIndex = times.length - 1;
  20996. var writeIndex = 1;
  20997. for (var i = 1; i < lastIndex; ++i) {
  20998. var keep = false;
  20999. var time = times[i];
  21000. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21001. if (time !== timeNext && (i !== 1 || time !== times[0])) {
  21002. if (!smoothInterpolation) {
  21003. // remove unnecessary keyframes same as their neighbors
  21004. var offset = i * stride,
  21005. offsetP = offset - stride,
  21006. offsetN = offset + stride;
  21007. for (var j = 0; j !== stride; ++j) {
  21008. var value = values[offset + j];
  21009. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21010. keep = true;
  21011. break;
  21012. }
  21013. }
  21014. } else {
  21015. keep = true;
  21016. }
  21017. } // in-place compaction
  21018. if (keep) {
  21019. if (i !== writeIndex) {
  21020. times[writeIndex] = times[i];
  21021. var readOffset = i * stride,
  21022. writeOffset = writeIndex * stride;
  21023. for (var _j = 0; _j !== stride; ++_j) {
  21024. values[writeOffset + _j] = values[readOffset + _j];
  21025. }
  21026. }
  21027. ++writeIndex;
  21028. }
  21029. } // flush last keyframe (compaction looks ahead)
  21030. if (lastIndex > 0) {
  21031. times[writeIndex] = times[lastIndex];
  21032. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21033. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21034. }
  21035. ++writeIndex;
  21036. }
  21037. if (writeIndex !== times.length) {
  21038. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21039. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21040. } else {
  21041. this.times = times;
  21042. this.values = values;
  21043. }
  21044. return this;
  21045. },
  21046. clone: function clone() {
  21047. var times = AnimationUtils.arraySlice(this.times, 0);
  21048. var values = AnimationUtils.arraySlice(this.values, 0);
  21049. var TypedKeyframeTrack = this.constructor;
  21050. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21051. track.createInterpolant = this.createInterpolant;
  21052. return track;
  21053. }
  21054. });
  21055. /**
  21056. * A Track of Boolean keyframe values.
  21057. */
  21058. function BooleanKeyframeTrack(name, times, values) {
  21059. KeyframeTrack.call(this, name, times, values);
  21060. }
  21061. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21062. constructor: BooleanKeyframeTrack,
  21063. ValueTypeName: 'bool',
  21064. ValueBufferType: Array,
  21065. DefaultInterpolation: InterpolateDiscrete,
  21066. InterpolantFactoryMethodLinear: undefined,
  21067. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21068. // representation of a single value and a custom interpolant that
  21069. // computes "firstValue ^ isOdd( index )".
  21070. });
  21071. /**
  21072. * A Track of keyframe values that represent color.
  21073. */
  21074. function ColorKeyframeTrack(name, times, values, interpolation) {
  21075. KeyframeTrack.call(this, name, times, values, interpolation);
  21076. }
  21077. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21078. constructor: ColorKeyframeTrack,
  21079. ValueTypeName: 'color' // ValueBufferType is inherited
  21080. // DefaultInterpolation is inherited
  21081. // Note: Very basic implementation and nothing special yet.
  21082. // However, this is the place for color space parameterization.
  21083. });
  21084. /**
  21085. * A Track of numeric keyframe values.
  21086. */
  21087. function NumberKeyframeTrack(name, times, values, interpolation) {
  21088. KeyframeTrack.call(this, name, times, values, interpolation);
  21089. }
  21090. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21091. constructor: NumberKeyframeTrack,
  21092. ValueTypeName: 'number' // ValueBufferType is inherited
  21093. // DefaultInterpolation is inherited
  21094. });
  21095. /**
  21096. * Spherical linear unit quaternion interpolant.
  21097. */
  21098. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21099. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21100. }
  21101. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21102. constructor: QuaternionLinearInterpolant,
  21103. interpolate_: function interpolate_(i1, t0, t, t1) {
  21104. var result = this.resultBuffer,
  21105. values = this.sampleValues,
  21106. stride = this.valueSize,
  21107. alpha = (t - t0) / (t1 - t0);
  21108. var offset = i1 * stride;
  21109. for (var end = offset + stride; offset !== end; offset += 4) {
  21110. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21111. }
  21112. return result;
  21113. }
  21114. });
  21115. /**
  21116. * A Track of quaternion keyframe values.
  21117. */
  21118. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21119. KeyframeTrack.call(this, name, times, values, interpolation);
  21120. }
  21121. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21122. constructor: QuaternionKeyframeTrack,
  21123. ValueTypeName: 'quaternion',
  21124. // ValueBufferType is inherited
  21125. DefaultInterpolation: InterpolateLinear,
  21126. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21127. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21128. },
  21129. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21130. });
  21131. /**
  21132. * A Track that interpolates Strings
  21133. */
  21134. function StringKeyframeTrack(name, times, values, interpolation) {
  21135. KeyframeTrack.call(this, name, times, values, interpolation);
  21136. }
  21137. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21138. constructor: StringKeyframeTrack,
  21139. ValueTypeName: 'string',
  21140. ValueBufferType: Array,
  21141. DefaultInterpolation: InterpolateDiscrete,
  21142. InterpolantFactoryMethodLinear: undefined,
  21143. InterpolantFactoryMethodSmooth: undefined
  21144. });
  21145. /**
  21146. * A Track of vectored keyframe values.
  21147. */
  21148. function VectorKeyframeTrack(name, times, values, interpolation) {
  21149. KeyframeTrack.call(this, name, times, values, interpolation);
  21150. }
  21151. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21152. constructor: VectorKeyframeTrack,
  21153. ValueTypeName: 'vector' // ValueBufferType is inherited
  21154. // DefaultInterpolation is inherited
  21155. });
  21156. function AnimationClip(name, duration, tracks, blendMode) {
  21157. if (duration === void 0) {
  21158. duration = -1;
  21159. }
  21160. if (blendMode === void 0) {
  21161. blendMode = NormalAnimationBlendMode;
  21162. }
  21163. this.name = name;
  21164. this.tracks = tracks;
  21165. this.duration = duration;
  21166. this.blendMode = blendMode;
  21167. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21168. if (this.duration < 0) {
  21169. this.resetDuration();
  21170. }
  21171. }
  21172. function getTrackTypeForValueTypeName(typeName) {
  21173. switch (typeName.toLowerCase()) {
  21174. case 'scalar':
  21175. case 'double':
  21176. case 'float':
  21177. case 'number':
  21178. case 'integer':
  21179. return NumberKeyframeTrack;
  21180. case 'vector':
  21181. case 'vector2':
  21182. case 'vector3':
  21183. case 'vector4':
  21184. return VectorKeyframeTrack;
  21185. case 'color':
  21186. return ColorKeyframeTrack;
  21187. case 'quaternion':
  21188. return QuaternionKeyframeTrack;
  21189. case 'bool':
  21190. case 'boolean':
  21191. return BooleanKeyframeTrack;
  21192. case 'string':
  21193. return StringKeyframeTrack;
  21194. }
  21195. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21196. }
  21197. function parseKeyframeTrack(json) {
  21198. if (json.type === undefined) {
  21199. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21200. }
  21201. var trackType = getTrackTypeForValueTypeName(json.type);
  21202. if (json.times === undefined) {
  21203. var times = [],
  21204. values = [];
  21205. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21206. json.times = times;
  21207. json.values = values;
  21208. } // derived classes can define a static parse method
  21209. if (trackType.parse !== undefined) {
  21210. return trackType.parse(json);
  21211. } else {
  21212. // by default, we assume a constructor compatible with the base
  21213. return new trackType(json.name, json.times, json.values, json.interpolation);
  21214. }
  21215. }
  21216. Object.assign(AnimationClip, {
  21217. parse: function parse(json) {
  21218. var tracks = [],
  21219. jsonTracks = json.tracks,
  21220. frameTime = 1.0 / (json.fps || 1.0);
  21221. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21222. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21223. }
  21224. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21225. clip.uuid = json.uuid;
  21226. return clip;
  21227. },
  21228. toJSON: function toJSON(clip) {
  21229. var tracks = [],
  21230. clipTracks = clip.tracks;
  21231. var json = {
  21232. 'name': clip.name,
  21233. 'duration': clip.duration,
  21234. 'tracks': tracks,
  21235. 'uuid': clip.uuid,
  21236. 'blendMode': clip.blendMode
  21237. };
  21238. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21239. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21240. }
  21241. return json;
  21242. },
  21243. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21244. var numMorphTargets = morphTargetSequence.length;
  21245. var tracks = [];
  21246. for (var i = 0; i < numMorphTargets; i++) {
  21247. var times = [];
  21248. var values = [];
  21249. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21250. values.push(0, 1, 0);
  21251. var order = AnimationUtils.getKeyframeOrder(times);
  21252. times = AnimationUtils.sortedArray(times, 1, order);
  21253. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21254. // last frame as well for perfect loop.
  21255. if (!noLoop && times[0] === 0) {
  21256. times.push(numMorphTargets);
  21257. values.push(values[0]);
  21258. }
  21259. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21260. }
  21261. return new AnimationClip(name, -1, tracks);
  21262. },
  21263. findByName: function findByName(objectOrClipArray, name) {
  21264. var clipArray = objectOrClipArray;
  21265. if (!Array.isArray(objectOrClipArray)) {
  21266. var o = objectOrClipArray;
  21267. clipArray = o.geometry && o.geometry.animations || o.animations;
  21268. }
  21269. for (var i = 0; i < clipArray.length; i++) {
  21270. if (clipArray[i].name === name) {
  21271. return clipArray[i];
  21272. }
  21273. }
  21274. return null;
  21275. },
  21276. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21277. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21278. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21279. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21280. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21281. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21282. var morphTarget = morphTargets[i];
  21283. var parts = morphTarget.name.match(pattern);
  21284. if (parts && parts.length > 1) {
  21285. var name = parts[1];
  21286. var animationMorphTargets = animationToMorphTargets[name];
  21287. if (!animationMorphTargets) {
  21288. animationToMorphTargets[name] = animationMorphTargets = [];
  21289. }
  21290. animationMorphTargets.push(morphTarget);
  21291. }
  21292. }
  21293. var clips = [];
  21294. for (var _name in animationToMorphTargets) {
  21295. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21296. }
  21297. return clips;
  21298. },
  21299. // parse the animation.hierarchy format
  21300. parseAnimation: function parseAnimation(animation, bones) {
  21301. if (!animation) {
  21302. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21303. return null;
  21304. }
  21305. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21306. // only return track if there are actually keys.
  21307. if (animationKeys.length !== 0) {
  21308. var times = [];
  21309. var values = [];
  21310. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21311. if (times.length !== 0) {
  21312. destTracks.push(new trackType(trackName, times, values));
  21313. }
  21314. }
  21315. };
  21316. var tracks = [];
  21317. var clipName = animation.name || 'default';
  21318. var fps = animation.fps || 30;
  21319. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21320. var duration = animation.length || -1;
  21321. var hierarchyTracks = animation.hierarchy || [];
  21322. for (var h = 0; h < hierarchyTracks.length; h++) {
  21323. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21324. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21325. if (animationKeys[0].morphTargets) {
  21326. // figure out all morph targets used in this track
  21327. var morphTargetNames = {};
  21328. var k = void 0;
  21329. for (k = 0; k < animationKeys.length; k++) {
  21330. if (animationKeys[k].morphTargets) {
  21331. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21332. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21333. }
  21334. }
  21335. } // create a track for each morph target with all zero
  21336. // morphTargetInfluences except for the keys in which
  21337. // the morphTarget is named.
  21338. for (var morphTargetName in morphTargetNames) {
  21339. var times = [];
  21340. var values = [];
  21341. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21342. var animationKey = animationKeys[k];
  21343. times.push(animationKey.time);
  21344. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21345. }
  21346. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21347. }
  21348. duration = morphTargetNames.length * (fps || 1.0);
  21349. } else {
  21350. // ...assume skeletal animation
  21351. var boneName = '.bones[' + bones[h].name + ']';
  21352. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21353. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21354. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21355. }
  21356. }
  21357. if (tracks.length === 0) {
  21358. return null;
  21359. }
  21360. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21361. return clip;
  21362. }
  21363. });
  21364. Object.assign(AnimationClip.prototype, {
  21365. resetDuration: function resetDuration() {
  21366. var tracks = this.tracks;
  21367. var duration = 0;
  21368. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21369. var track = this.tracks[i];
  21370. duration = Math.max(duration, track.times[track.times.length - 1]);
  21371. }
  21372. this.duration = duration;
  21373. return this;
  21374. },
  21375. trim: function trim() {
  21376. for (var i = 0; i < this.tracks.length; i++) {
  21377. this.tracks[i].trim(0, this.duration);
  21378. }
  21379. return this;
  21380. },
  21381. validate: function validate() {
  21382. var valid = true;
  21383. for (var i = 0; i < this.tracks.length; i++) {
  21384. valid = valid && this.tracks[i].validate();
  21385. }
  21386. return valid;
  21387. },
  21388. optimize: function optimize() {
  21389. for (var i = 0; i < this.tracks.length; i++) {
  21390. this.tracks[i].optimize();
  21391. }
  21392. return this;
  21393. },
  21394. clone: function clone() {
  21395. var tracks = [];
  21396. for (var i = 0; i < this.tracks.length; i++) {
  21397. tracks.push(this.tracks[i].clone());
  21398. }
  21399. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21400. },
  21401. toJSON: function toJSON() {
  21402. return AnimationClip.toJSON(this);
  21403. }
  21404. });
  21405. var Cache = {
  21406. enabled: false,
  21407. files: {},
  21408. add: function add(key, file) {
  21409. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21410. this.files[key] = file;
  21411. },
  21412. get: function get(key) {
  21413. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21414. return this.files[key];
  21415. },
  21416. remove: function remove(key) {
  21417. delete this.files[key];
  21418. },
  21419. clear: function clear() {
  21420. this.files = {};
  21421. }
  21422. };
  21423. function LoadingManager(onLoad, onProgress, onError) {
  21424. var scope = this;
  21425. var isLoading = false;
  21426. var itemsLoaded = 0;
  21427. var itemsTotal = 0;
  21428. var urlModifier = undefined;
  21429. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21430. // in the constructor
  21431. this.onStart = undefined;
  21432. this.onLoad = onLoad;
  21433. this.onProgress = onProgress;
  21434. this.onError = onError;
  21435. this.itemStart = function (url) {
  21436. itemsTotal++;
  21437. if (isLoading === false) {
  21438. if (scope.onStart !== undefined) {
  21439. scope.onStart(url, itemsLoaded, itemsTotal);
  21440. }
  21441. }
  21442. isLoading = true;
  21443. };
  21444. this.itemEnd = function (url) {
  21445. itemsLoaded++;
  21446. if (scope.onProgress !== undefined) {
  21447. scope.onProgress(url, itemsLoaded, itemsTotal);
  21448. }
  21449. if (itemsLoaded === itemsTotal) {
  21450. isLoading = false;
  21451. if (scope.onLoad !== undefined) {
  21452. scope.onLoad();
  21453. }
  21454. }
  21455. };
  21456. this.itemError = function (url) {
  21457. if (scope.onError !== undefined) {
  21458. scope.onError(url);
  21459. }
  21460. };
  21461. this.resolveURL = function (url) {
  21462. if (urlModifier) {
  21463. return urlModifier(url);
  21464. }
  21465. return url;
  21466. };
  21467. this.setURLModifier = function (transform) {
  21468. urlModifier = transform;
  21469. return this;
  21470. };
  21471. this.addHandler = function (regex, loader) {
  21472. handlers.push(regex, loader);
  21473. return this;
  21474. };
  21475. this.removeHandler = function (regex) {
  21476. var index = handlers.indexOf(regex);
  21477. if (index !== -1) {
  21478. handlers.splice(index, 2);
  21479. }
  21480. return this;
  21481. };
  21482. this.getHandler = function (file) {
  21483. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21484. var regex = handlers[i];
  21485. var loader = handlers[i + 1];
  21486. if (regex.global) regex.lastIndex = 0; // see #17920
  21487. if (regex.test(file)) {
  21488. return loader;
  21489. }
  21490. }
  21491. return null;
  21492. };
  21493. }
  21494. var DefaultLoadingManager = new LoadingManager();
  21495. function Loader(manager) {
  21496. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21497. this.crossOrigin = 'anonymous';
  21498. this.withCredentials = false;
  21499. this.path = '';
  21500. this.resourcePath = '';
  21501. this.requestHeader = {};
  21502. }
  21503. Object.assign(Loader.prototype, {
  21504. load: function load()
  21505. /* url, onLoad, onProgress, onError */
  21506. {},
  21507. loadAsync: function loadAsync(url, onProgress) {
  21508. var scope = this;
  21509. return new Promise(function (resolve, reject) {
  21510. scope.load(url, resolve, onProgress, reject);
  21511. });
  21512. },
  21513. parse: function parse()
  21514. /* data */
  21515. {},
  21516. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21517. this.crossOrigin = crossOrigin;
  21518. return this;
  21519. },
  21520. setWithCredentials: function setWithCredentials(value) {
  21521. this.withCredentials = value;
  21522. return this;
  21523. },
  21524. setPath: function setPath(path) {
  21525. this.path = path;
  21526. return this;
  21527. },
  21528. setResourcePath: function setResourcePath(resourcePath) {
  21529. this.resourcePath = resourcePath;
  21530. return this;
  21531. },
  21532. setRequestHeader: function setRequestHeader(requestHeader) {
  21533. this.requestHeader = requestHeader;
  21534. return this;
  21535. }
  21536. });
  21537. var loading = {};
  21538. function FileLoader(manager) {
  21539. Loader.call(this, manager);
  21540. }
  21541. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21542. constructor: FileLoader,
  21543. load: function load(url, onLoad, onProgress, onError) {
  21544. if (url === undefined) url = '';
  21545. if (this.path !== undefined) url = this.path + url;
  21546. url = this.manager.resolveURL(url);
  21547. var scope = this;
  21548. var cached = Cache.get(url);
  21549. if (cached !== undefined) {
  21550. scope.manager.itemStart(url);
  21551. setTimeout(function () {
  21552. if (onLoad) onLoad(cached);
  21553. scope.manager.itemEnd(url);
  21554. }, 0);
  21555. return cached;
  21556. } // Check if request is duplicate
  21557. if (loading[url] !== undefined) {
  21558. loading[url].push({
  21559. onLoad: onLoad,
  21560. onProgress: onProgress,
  21561. onError: onError
  21562. });
  21563. return;
  21564. } // Check for data: URI
  21565. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21566. var dataUriRegexResult = url.match(dataUriRegex);
  21567. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21568. if (dataUriRegexResult) {
  21569. var mimeType = dataUriRegexResult[1];
  21570. var isBase64 = !!dataUriRegexResult[2];
  21571. var data = dataUriRegexResult[3];
  21572. data = decodeURIComponent(data);
  21573. if (isBase64) data = atob(data);
  21574. try {
  21575. var response;
  21576. var responseType = (this.responseType || '').toLowerCase();
  21577. switch (responseType) {
  21578. case 'arraybuffer':
  21579. case 'blob':
  21580. var view = new Uint8Array(data.length);
  21581. for (var i = 0; i < data.length; i++) {
  21582. view[i] = data.charCodeAt(i);
  21583. }
  21584. if (responseType === 'blob') {
  21585. response = new Blob([view.buffer], {
  21586. type: mimeType
  21587. });
  21588. } else {
  21589. response = view.buffer;
  21590. }
  21591. break;
  21592. case 'document':
  21593. var parser = new DOMParser();
  21594. response = parser.parseFromString(data, mimeType);
  21595. break;
  21596. case 'json':
  21597. response = JSON.parse(data);
  21598. break;
  21599. default:
  21600. // 'text' or other
  21601. response = data;
  21602. break;
  21603. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21604. setTimeout(function () {
  21605. if (onLoad) onLoad(response);
  21606. scope.manager.itemEnd(url);
  21607. }, 0);
  21608. } catch (error) {
  21609. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21610. setTimeout(function () {
  21611. if (onError) onError(error);
  21612. scope.manager.itemError(url);
  21613. scope.manager.itemEnd(url);
  21614. }, 0);
  21615. }
  21616. } else {
  21617. // Initialise array for duplicate requests
  21618. loading[url] = [];
  21619. loading[url].push({
  21620. onLoad: onLoad,
  21621. onProgress: onProgress,
  21622. onError: onError
  21623. });
  21624. request = new XMLHttpRequest();
  21625. request.open('GET', url, true);
  21626. request.addEventListener('load', function (event) {
  21627. var response = this.response;
  21628. var callbacks = loading[url];
  21629. delete loading[url];
  21630. if (this.status === 200 || this.status === 0) {
  21631. // Some browsers return HTTP Status 0 when using non-http protocol
  21632. // e.g. 'file://' or 'data://'. Handle as success.
  21633. 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
  21634. // error response bodies as proper responses to requests.
  21635. Cache.add(url, response);
  21636. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21637. var callback = callbacks[_i];
  21638. if (callback.onLoad) callback.onLoad(response);
  21639. }
  21640. scope.manager.itemEnd(url);
  21641. } else {
  21642. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21643. var _callback = callbacks[_i2];
  21644. if (_callback.onError) _callback.onError(event);
  21645. }
  21646. scope.manager.itemError(url);
  21647. scope.manager.itemEnd(url);
  21648. }
  21649. }, false);
  21650. request.addEventListener('progress', function (event) {
  21651. var callbacks = loading[url];
  21652. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21653. var callback = callbacks[_i3];
  21654. if (callback.onProgress) callback.onProgress(event);
  21655. }
  21656. }, false);
  21657. request.addEventListener('error', function (event) {
  21658. var callbacks = loading[url];
  21659. delete loading[url];
  21660. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21661. var callback = callbacks[_i4];
  21662. if (callback.onError) callback.onError(event);
  21663. }
  21664. scope.manager.itemError(url);
  21665. scope.manager.itemEnd(url);
  21666. }, false);
  21667. request.addEventListener('abort', function (event) {
  21668. var callbacks = loading[url];
  21669. delete loading[url];
  21670. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21671. var callback = callbacks[_i5];
  21672. if (callback.onError) callback.onError(event);
  21673. }
  21674. scope.manager.itemError(url);
  21675. scope.manager.itemEnd(url);
  21676. }, false);
  21677. if (this.responseType !== undefined) request.responseType = this.responseType;
  21678. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21679. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21680. for (var header in this.requestHeader) {
  21681. request.setRequestHeader(header, this.requestHeader[header]);
  21682. }
  21683. request.send(null);
  21684. }
  21685. scope.manager.itemStart(url);
  21686. return request;
  21687. },
  21688. setResponseType: function setResponseType(value) {
  21689. this.responseType = value;
  21690. return this;
  21691. },
  21692. setMimeType: function setMimeType(value) {
  21693. this.mimeType = value;
  21694. return this;
  21695. }
  21696. });
  21697. var AnimationLoader = /*#__PURE__*/function (_Loader) {
  21698. _inheritsLoose(AnimationLoader, _Loader);
  21699. function AnimationLoader(manager) {
  21700. return _Loader.call(this, manager) || this;
  21701. }
  21702. var _proto = AnimationLoader.prototype;
  21703. _proto.load = function load(url, onLoad, onProgress, onError) {
  21704. var scope = this;
  21705. var loader = new FileLoader(this.manager);
  21706. loader.setPath(this.path);
  21707. loader.setRequestHeader(this.requestHeader);
  21708. loader.setWithCredentials(this.withCredentials);
  21709. loader.load(url, function (text) {
  21710. try {
  21711. onLoad(scope.parse(JSON.parse(text)));
  21712. } catch (e) {
  21713. if (onError) {
  21714. onError(e);
  21715. } else {
  21716. console.error(e);
  21717. }
  21718. scope.manager.itemError(url);
  21719. }
  21720. }, onProgress, onError);
  21721. };
  21722. _proto.parse = function parse(json) {
  21723. var animations = [];
  21724. for (var i = 0; i < json.length; i++) {
  21725. var clip = AnimationClip.parse(json[i]);
  21726. animations.push(clip);
  21727. }
  21728. return animations;
  21729. };
  21730. return AnimationLoader;
  21731. }(Loader);
  21732. /**
  21733. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21734. *
  21735. * Sub classes have to implement the parse() method which will be used in load().
  21736. */
  21737. function CompressedTextureLoader(manager) {
  21738. Loader.call(this, manager);
  21739. }
  21740. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21741. constructor: CompressedTextureLoader,
  21742. load: function load(url, onLoad, onProgress, onError) {
  21743. var scope = this;
  21744. var images = [];
  21745. var texture = new CompressedTexture();
  21746. var loader = new FileLoader(this.manager);
  21747. loader.setPath(this.path);
  21748. loader.setResponseType('arraybuffer');
  21749. loader.setRequestHeader(this.requestHeader);
  21750. loader.setWithCredentials(scope.withCredentials);
  21751. var loaded = 0;
  21752. function loadTexture(i) {
  21753. loader.load(url[i], function (buffer) {
  21754. var texDatas = scope.parse(buffer, true);
  21755. images[i] = {
  21756. width: texDatas.width,
  21757. height: texDatas.height,
  21758. format: texDatas.format,
  21759. mipmaps: texDatas.mipmaps
  21760. };
  21761. loaded += 1;
  21762. if (loaded === 6) {
  21763. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21764. texture.image = images;
  21765. texture.format = texDatas.format;
  21766. texture.needsUpdate = true;
  21767. if (onLoad) onLoad(texture);
  21768. }
  21769. }, onProgress, onError);
  21770. }
  21771. if (Array.isArray(url)) {
  21772. for (var i = 0, il = url.length; i < il; ++i) {
  21773. loadTexture(i);
  21774. }
  21775. } else {
  21776. // compressed cubemap texture stored in a single DDS file
  21777. loader.load(url, function (buffer) {
  21778. var texDatas = scope.parse(buffer, true);
  21779. if (texDatas.isCubemap) {
  21780. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21781. for (var f = 0; f < faces; f++) {
  21782. images[f] = {
  21783. mipmaps: []
  21784. };
  21785. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21786. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21787. images[f].format = texDatas.format;
  21788. images[f].width = texDatas.width;
  21789. images[f].height = texDatas.height;
  21790. }
  21791. }
  21792. texture.image = images;
  21793. } else {
  21794. texture.image.width = texDatas.width;
  21795. texture.image.height = texDatas.height;
  21796. texture.mipmaps = texDatas.mipmaps;
  21797. }
  21798. if (texDatas.mipmapCount === 1) {
  21799. texture.minFilter = LinearFilter;
  21800. }
  21801. texture.format = texDatas.format;
  21802. texture.needsUpdate = true;
  21803. if (onLoad) onLoad(texture);
  21804. }, onProgress, onError);
  21805. }
  21806. return texture;
  21807. }
  21808. });
  21809. var ImageLoader = /*#__PURE__*/function (_Loader) {
  21810. _inheritsLoose(ImageLoader, _Loader);
  21811. function ImageLoader(manager) {
  21812. return _Loader.call(this, manager) || this;
  21813. }
  21814. var _proto = ImageLoader.prototype;
  21815. _proto.load = function load(url, onLoad, onProgress, onError) {
  21816. if (this.path !== undefined) url = this.path + url;
  21817. url = this.manager.resolveURL(url);
  21818. var scope = this;
  21819. var cached = Cache.get(url);
  21820. if (cached !== undefined) {
  21821. scope.manager.itemStart(url);
  21822. setTimeout(function () {
  21823. if (onLoad) onLoad(cached);
  21824. scope.manager.itemEnd(url);
  21825. }, 0);
  21826. return cached;
  21827. }
  21828. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21829. function onImageLoad() {
  21830. image.removeEventListener('load', onImageLoad, false);
  21831. image.removeEventListener('error', onImageError, false);
  21832. Cache.add(url, this);
  21833. if (onLoad) onLoad(this);
  21834. scope.manager.itemEnd(url);
  21835. }
  21836. function onImageError(event) {
  21837. image.removeEventListener('load', onImageLoad, false);
  21838. image.removeEventListener('error', onImageError, false);
  21839. if (onError) onError(event);
  21840. scope.manager.itemError(url);
  21841. scope.manager.itemEnd(url);
  21842. }
  21843. image.addEventListener('load', onImageLoad, false);
  21844. image.addEventListener('error', onImageError, false);
  21845. if (url.substr(0, 5) !== 'data:') {
  21846. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21847. }
  21848. scope.manager.itemStart(url);
  21849. image.src = url;
  21850. return image;
  21851. };
  21852. return ImageLoader;
  21853. }(Loader);
  21854. var CubeTextureLoader = /*#__PURE__*/function (_Loader) {
  21855. _inheritsLoose(CubeTextureLoader, _Loader);
  21856. function CubeTextureLoader(manager) {
  21857. return _Loader.call(this, manager) || this;
  21858. }
  21859. var _proto = CubeTextureLoader.prototype;
  21860. _proto.load = function load(urls, onLoad, onProgress, onError) {
  21861. var texture = new CubeTexture();
  21862. var loader = new ImageLoader(this.manager);
  21863. loader.setCrossOrigin(this.crossOrigin);
  21864. loader.setPath(this.path);
  21865. var loaded = 0;
  21866. function loadTexture(i) {
  21867. loader.load(urls[i], function (image) {
  21868. texture.images[i] = image;
  21869. loaded++;
  21870. if (loaded === 6) {
  21871. texture.needsUpdate = true;
  21872. if (onLoad) onLoad(texture);
  21873. }
  21874. }, undefined, onError);
  21875. }
  21876. for (var i = 0; i < urls.length; ++i) {
  21877. loadTexture(i);
  21878. }
  21879. return texture;
  21880. };
  21881. return CubeTextureLoader;
  21882. }(Loader);
  21883. /**
  21884. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21885. *
  21886. * Sub classes have to implement the parse() method which will be used in load().
  21887. */
  21888. function DataTextureLoader(manager) {
  21889. Loader.call(this, manager);
  21890. }
  21891. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21892. constructor: DataTextureLoader,
  21893. load: function load(url, onLoad, onProgress, onError) {
  21894. var scope = this;
  21895. var texture = new DataTexture();
  21896. var loader = new FileLoader(this.manager);
  21897. loader.setResponseType('arraybuffer');
  21898. loader.setRequestHeader(this.requestHeader);
  21899. loader.setPath(this.path);
  21900. loader.setWithCredentials(scope.withCredentials);
  21901. loader.load(url, function (buffer) {
  21902. var texData = scope.parse(buffer);
  21903. if (!texData) return;
  21904. if (texData.image !== undefined) {
  21905. texture.image = texData.image;
  21906. } else if (texData.data !== undefined) {
  21907. texture.image.width = texData.width;
  21908. texture.image.height = texData.height;
  21909. texture.image.data = texData.data;
  21910. }
  21911. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21912. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21913. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21914. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  21915. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21916. if (texData.encoding !== undefined) {
  21917. texture.encoding = texData.encoding;
  21918. }
  21919. if (texData.flipY !== undefined) {
  21920. texture.flipY = texData.flipY;
  21921. }
  21922. if (texData.format !== undefined) {
  21923. texture.format = texData.format;
  21924. }
  21925. if (texData.type !== undefined) {
  21926. texture.type = texData.type;
  21927. }
  21928. if (texData.mipmaps !== undefined) {
  21929. texture.mipmaps = texData.mipmaps;
  21930. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  21931. }
  21932. if (texData.mipmapCount === 1) {
  21933. texture.minFilter = LinearFilter;
  21934. }
  21935. texture.needsUpdate = true;
  21936. if (onLoad) onLoad(texture, texData);
  21937. }, onProgress, onError);
  21938. return texture;
  21939. }
  21940. });
  21941. function TextureLoader(manager) {
  21942. Loader.call(this, manager);
  21943. }
  21944. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21945. constructor: TextureLoader,
  21946. load: function load(url, onLoad, onProgress, onError) {
  21947. var texture = new Texture();
  21948. var loader = new ImageLoader(this.manager);
  21949. loader.setCrossOrigin(this.crossOrigin);
  21950. loader.setPath(this.path);
  21951. loader.load(url, function (image) {
  21952. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21953. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  21954. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21955. texture.needsUpdate = true;
  21956. if (onLoad !== undefined) {
  21957. onLoad(texture);
  21958. }
  21959. }, onProgress, onError);
  21960. return texture;
  21961. }
  21962. });
  21963. /**
  21964. * Extensible curve object.
  21965. *
  21966. * Some common of curve methods:
  21967. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  21968. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  21969. * .getPoints(), .getSpacedPoints()
  21970. * .getLength()
  21971. * .updateArcLengths()
  21972. *
  21973. * This following curves inherit from THREE.Curve:
  21974. *
  21975. * -- 2D curves --
  21976. * THREE.ArcCurve
  21977. * THREE.CubicBezierCurve
  21978. * THREE.EllipseCurve
  21979. * THREE.LineCurve
  21980. * THREE.QuadraticBezierCurve
  21981. * THREE.SplineCurve
  21982. *
  21983. * -- 3D curves --
  21984. * THREE.CatmullRomCurve3
  21985. * THREE.CubicBezierCurve3
  21986. * THREE.LineCurve3
  21987. * THREE.QuadraticBezierCurve3
  21988. *
  21989. * A series of curves can be represented as a THREE.CurvePath.
  21990. *
  21991. **/
  21992. function Curve() {
  21993. this.type = 'Curve';
  21994. this.arcLengthDivisions = 200;
  21995. }
  21996. Object.assign(Curve.prototype, {
  21997. // Virtual base class method to overwrite and implement in subclasses
  21998. // - t [0 .. 1]
  21999. getPoint: function getPoint()
  22000. /* t, optionalTarget */
  22001. {
  22002. console.warn('THREE.Curve: .getPoint() not implemented.');
  22003. return null;
  22004. },
  22005. // Get point at relative position in curve according to arc length
  22006. // - u [0 .. 1]
  22007. getPointAt: function getPointAt(u, optionalTarget) {
  22008. var t = this.getUtoTmapping(u);
  22009. return this.getPoint(t, optionalTarget);
  22010. },
  22011. // Get sequence of points using getPoint( t )
  22012. getPoints: function getPoints(divisions) {
  22013. if (divisions === void 0) {
  22014. divisions = 5;
  22015. }
  22016. var points = [];
  22017. for (var d = 0; d <= divisions; d++) {
  22018. points.push(this.getPoint(d / divisions));
  22019. }
  22020. return points;
  22021. },
  22022. // Get sequence of points using getPointAt( u )
  22023. getSpacedPoints: function getSpacedPoints(divisions) {
  22024. if (divisions === void 0) {
  22025. divisions = 5;
  22026. }
  22027. var points = [];
  22028. for (var d = 0; d <= divisions; d++) {
  22029. points.push(this.getPointAt(d / divisions));
  22030. }
  22031. return points;
  22032. },
  22033. // Get total curve arc length
  22034. getLength: function getLength() {
  22035. var lengths = this.getLengths();
  22036. return lengths[lengths.length - 1];
  22037. },
  22038. // Get list of cumulative segment lengths
  22039. getLengths: function getLengths(divisions) {
  22040. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22041. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22042. return this.cacheArcLengths;
  22043. }
  22044. this.needsUpdate = false;
  22045. var cache = [];
  22046. var current,
  22047. last = this.getPoint(0);
  22048. var sum = 0;
  22049. cache.push(0);
  22050. for (var p = 1; p <= divisions; p++) {
  22051. current = this.getPoint(p / divisions);
  22052. sum += current.distanceTo(last);
  22053. cache.push(sum);
  22054. last = current;
  22055. }
  22056. this.cacheArcLengths = cache;
  22057. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22058. },
  22059. updateArcLengths: function updateArcLengths() {
  22060. this.needsUpdate = true;
  22061. this.getLengths();
  22062. },
  22063. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22064. getUtoTmapping: function getUtoTmapping(u, distance) {
  22065. var arcLengths = this.getLengths();
  22066. var i = 0;
  22067. var il = arcLengths.length;
  22068. var targetArcLength; // The targeted u distance value to get
  22069. if (distance) {
  22070. targetArcLength = distance;
  22071. } else {
  22072. targetArcLength = u * arcLengths[il - 1];
  22073. } // binary search for the index with largest value smaller than target u distance
  22074. var low = 0,
  22075. high = il - 1,
  22076. comparison;
  22077. while (low <= high) {
  22078. 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
  22079. comparison = arcLengths[i] - targetArcLength;
  22080. if (comparison < 0) {
  22081. low = i + 1;
  22082. } else if (comparison > 0) {
  22083. high = i - 1;
  22084. } else {
  22085. high = i;
  22086. break; // DONE
  22087. }
  22088. }
  22089. i = high;
  22090. if (arcLengths[i] === targetArcLength) {
  22091. return i / (il - 1);
  22092. } // we could get finer grain at lengths, or use simple interpolation between two points
  22093. var lengthBefore = arcLengths[i];
  22094. var lengthAfter = arcLengths[i + 1];
  22095. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22096. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22097. var t = (i + segmentFraction) / (il - 1);
  22098. return t;
  22099. },
  22100. // Returns a unit vector tangent at t
  22101. // In case any sub curve does not implement its tangent derivation,
  22102. // 2 points a small delta apart will be used to find its gradient
  22103. // which seems to give a reasonable approximation
  22104. getTangent: function getTangent(t, optionalTarget) {
  22105. var delta = 0.0001;
  22106. var t1 = t - delta;
  22107. var t2 = t + delta; // Capping in case of danger
  22108. if (t1 < 0) t1 = 0;
  22109. if (t2 > 1) t2 = 1;
  22110. var pt1 = this.getPoint(t1);
  22111. var pt2 = this.getPoint(t2);
  22112. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22113. tangent.copy(pt2).sub(pt1).normalize();
  22114. return tangent;
  22115. },
  22116. getTangentAt: function getTangentAt(u, optionalTarget) {
  22117. var t = this.getUtoTmapping(u);
  22118. return this.getTangent(t, optionalTarget);
  22119. },
  22120. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22121. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22122. var normal = new Vector3();
  22123. var tangents = [];
  22124. var normals = [];
  22125. var binormals = [];
  22126. var vec = new Vector3();
  22127. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22128. for (var i = 0; i <= segments; i++) {
  22129. var u = i / segments;
  22130. tangents[i] = this.getTangentAt(u, new Vector3());
  22131. tangents[i].normalize();
  22132. } // select an initial normal vector perpendicular to the first tangent vector,
  22133. // and in the direction of the minimum tangent xyz component
  22134. normals[0] = new Vector3();
  22135. binormals[0] = new Vector3();
  22136. var min = Number.MAX_VALUE;
  22137. var tx = Math.abs(tangents[0].x);
  22138. var ty = Math.abs(tangents[0].y);
  22139. var tz = Math.abs(tangents[0].z);
  22140. if (tx <= min) {
  22141. min = tx;
  22142. normal.set(1, 0, 0);
  22143. }
  22144. if (ty <= min) {
  22145. min = ty;
  22146. normal.set(0, 1, 0);
  22147. }
  22148. if (tz <= min) {
  22149. normal.set(0, 0, 1);
  22150. }
  22151. vec.crossVectors(tangents[0], normal).normalize();
  22152. normals[0].crossVectors(tangents[0], vec);
  22153. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22154. for (var _i = 1; _i <= segments; _i++) {
  22155. normals[_i] = normals[_i - 1].clone();
  22156. binormals[_i] = binormals[_i - 1].clone();
  22157. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22158. if (vec.length() > Number.EPSILON) {
  22159. vec.normalize();
  22160. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22161. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22162. }
  22163. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22164. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22165. if (closed === true) {
  22166. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22167. _theta /= segments;
  22168. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22169. _theta = -_theta;
  22170. }
  22171. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22172. // twist a little...
  22173. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22174. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22175. }
  22176. }
  22177. return {
  22178. tangents: tangents,
  22179. normals: normals,
  22180. binormals: binormals
  22181. };
  22182. },
  22183. clone: function clone() {
  22184. return new this.constructor().copy(this);
  22185. },
  22186. copy: function copy(source) {
  22187. this.arcLengthDivisions = source.arcLengthDivisions;
  22188. return this;
  22189. },
  22190. toJSON: function toJSON() {
  22191. var data = {
  22192. metadata: {
  22193. version: 4.5,
  22194. type: 'Curve',
  22195. generator: 'Curve.toJSON'
  22196. }
  22197. };
  22198. data.arcLengthDivisions = this.arcLengthDivisions;
  22199. data.type = this.type;
  22200. return data;
  22201. },
  22202. fromJSON: function fromJSON(json) {
  22203. this.arcLengthDivisions = json.arcLengthDivisions;
  22204. return this;
  22205. }
  22206. });
  22207. var EllipseCurve = /*#__PURE__*/function (_Curve) {
  22208. _inheritsLoose(EllipseCurve, _Curve);
  22209. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22210. var _this;
  22211. _this = _Curve.call(this) || this;
  22212. _this.type = 'EllipseCurve';
  22213. Object.defineProperty(_assertThisInitialized(_this), 'isEllipseCurve', {
  22214. value: true
  22215. });
  22216. _this.aX = aX || 0;
  22217. _this.aY = aY || 0;
  22218. _this.xRadius = xRadius || 1;
  22219. _this.yRadius = yRadius || 1;
  22220. _this.aStartAngle = aStartAngle || 0;
  22221. _this.aEndAngle = aEndAngle || 2 * Math.PI;
  22222. _this.aClockwise = aClockwise || false;
  22223. _this.aRotation = aRotation || 0;
  22224. return _this;
  22225. }
  22226. var _proto = EllipseCurve.prototype;
  22227. _proto.getPoint = function getPoint(t, optionalTarget) {
  22228. var point = optionalTarget || new Vector2();
  22229. var twoPi = Math.PI * 2;
  22230. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22231. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22232. while (deltaAngle < 0) {
  22233. deltaAngle += twoPi;
  22234. }
  22235. while (deltaAngle > twoPi) {
  22236. deltaAngle -= twoPi;
  22237. }
  22238. if (deltaAngle < Number.EPSILON) {
  22239. if (samePoints) {
  22240. deltaAngle = 0;
  22241. } else {
  22242. deltaAngle = twoPi;
  22243. }
  22244. }
  22245. if (this.aClockwise === true && !samePoints) {
  22246. if (deltaAngle === twoPi) {
  22247. deltaAngle = -twoPi;
  22248. } else {
  22249. deltaAngle = deltaAngle - twoPi;
  22250. }
  22251. }
  22252. var angle = this.aStartAngle + t * deltaAngle;
  22253. var x = this.aX + this.xRadius * Math.cos(angle);
  22254. var y = this.aY + this.yRadius * Math.sin(angle);
  22255. if (this.aRotation !== 0) {
  22256. var cos = Math.cos(this.aRotation);
  22257. var sin = Math.sin(this.aRotation);
  22258. var tx = x - this.aX;
  22259. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22260. x = tx * cos - ty * sin + this.aX;
  22261. y = tx * sin + ty * cos + this.aY;
  22262. }
  22263. return point.set(x, y);
  22264. };
  22265. _proto.copy = function copy(source) {
  22266. _Curve.prototype.copy.call(this, source);
  22267. this.aX = source.aX;
  22268. this.aY = source.aY;
  22269. this.xRadius = source.xRadius;
  22270. this.yRadius = source.yRadius;
  22271. this.aStartAngle = source.aStartAngle;
  22272. this.aEndAngle = source.aEndAngle;
  22273. this.aClockwise = source.aClockwise;
  22274. this.aRotation = source.aRotation;
  22275. return this;
  22276. };
  22277. _proto.toJSON = function toJSON() {
  22278. var data = _Curve.prototype.toJSON.call(this);
  22279. data.aX = this.aX;
  22280. data.aY = this.aY;
  22281. data.xRadius = this.xRadius;
  22282. data.yRadius = this.yRadius;
  22283. data.aStartAngle = this.aStartAngle;
  22284. data.aEndAngle = this.aEndAngle;
  22285. data.aClockwise = this.aClockwise;
  22286. data.aRotation = this.aRotation;
  22287. return data;
  22288. };
  22289. _proto.fromJSON = function fromJSON(json) {
  22290. _Curve.prototype.fromJSON.call(this, json);
  22291. this.aX = json.aX;
  22292. this.aY = json.aY;
  22293. this.xRadius = json.xRadius;
  22294. this.yRadius = json.yRadius;
  22295. this.aStartAngle = json.aStartAngle;
  22296. this.aEndAngle = json.aEndAngle;
  22297. this.aClockwise = json.aClockwise;
  22298. this.aRotation = json.aRotation;
  22299. return this;
  22300. };
  22301. return EllipseCurve;
  22302. }(Curve);
  22303. var ArcCurve = /*#__PURE__*/function (_EllipseCurve) {
  22304. _inheritsLoose(ArcCurve, _EllipseCurve);
  22305. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22306. var _this;
  22307. _this = _EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise) || this;
  22308. _this.type = 'ArcCurve';
  22309. Object.defineProperty(_assertThisInitialized(_this), 'isArcCurve', {
  22310. value: true
  22311. });
  22312. return _this;
  22313. }
  22314. return ArcCurve;
  22315. }(EllipseCurve);
  22316. /**
  22317. * Centripetal CatmullRom Curve - which is useful for avoiding
  22318. * cusps and self-intersections in non-uniform catmull rom curves.
  22319. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22320. *
  22321. * curve.type accepts centripetal(default), chordal and catmullrom
  22322. * curve.tension is used for catmullrom which defaults to 0.5
  22323. */
  22324. /*
  22325. Based on an optimized c++ solution in
  22326. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22327. - http://ideone.com/NoEbVM
  22328. This CubicPoly class could be used for reusing some variables and calculations,
  22329. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22330. which can be placed in CurveUtils.
  22331. */
  22332. function CubicPoly() {
  22333. var c0 = 0,
  22334. c1 = 0,
  22335. c2 = 0,
  22336. c3 = 0;
  22337. /*
  22338. * Compute coefficients for a cubic polynomial
  22339. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22340. * such that
  22341. * p(0) = x0, p(1) = x1
  22342. * and
  22343. * p'(0) = t0, p'(1) = t1.
  22344. */
  22345. function init(x0, x1, t0, t1) {
  22346. c0 = x0;
  22347. c1 = t0;
  22348. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22349. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22350. }
  22351. return {
  22352. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22353. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22354. },
  22355. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22356. // compute tangents when parameterized in [t1,t2]
  22357. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22358. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22359. t1 *= dt1;
  22360. t2 *= dt1;
  22361. init(x1, x2, t1, t2);
  22362. },
  22363. calc: function calc(t) {
  22364. var t2 = t * t;
  22365. var t3 = t2 * t;
  22366. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22367. }
  22368. };
  22369. } //
  22370. var tmp = new Vector3();
  22371. var px = new CubicPoly(),
  22372. py = new CubicPoly(),
  22373. pz = new CubicPoly();
  22374. var CatmullRomCurve3 = /*#__PURE__*/function (_Curve) {
  22375. _inheritsLoose(CatmullRomCurve3, _Curve);
  22376. function CatmullRomCurve3(points, closed, curveType, tension) {
  22377. var _this;
  22378. if (points === void 0) {
  22379. points = [];
  22380. }
  22381. if (closed === void 0) {
  22382. closed = false;
  22383. }
  22384. if (curveType === void 0) {
  22385. curveType = 'centripetal';
  22386. }
  22387. if (tension === void 0) {
  22388. tension = 0.5;
  22389. }
  22390. _this = _Curve.call(this) || this;
  22391. _this.type = 'CatmullRomCurve3';
  22392. Object.defineProperty(_assertThisInitialized(_this), 'isCatmullRomCurve3', {
  22393. value: true
  22394. });
  22395. _this.points = points;
  22396. _this.closed = closed;
  22397. _this.curveType = curveType;
  22398. _this.tension = tension;
  22399. return _this;
  22400. }
  22401. var _proto = CatmullRomCurve3.prototype;
  22402. _proto.getPoint = function getPoint(t, optionalTarget) {
  22403. if (optionalTarget === void 0) {
  22404. optionalTarget = new Vector3();
  22405. }
  22406. var point = optionalTarget;
  22407. var points = this.points;
  22408. var l = points.length;
  22409. var p = (l - (this.closed ? 0 : 1)) * t;
  22410. var intPoint = Math.floor(p);
  22411. var weight = p - intPoint;
  22412. if (this.closed) {
  22413. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22414. } else if (weight === 0 && intPoint === l - 1) {
  22415. intPoint = l - 2;
  22416. weight = 1;
  22417. }
  22418. var p0, p3; // 4 points (p1 & p2 defined below)
  22419. if (this.closed || intPoint > 0) {
  22420. p0 = points[(intPoint - 1) % l];
  22421. } else {
  22422. // extrapolate first point
  22423. tmp.subVectors(points[0], points[1]).add(points[0]);
  22424. p0 = tmp;
  22425. }
  22426. var p1 = points[intPoint % l];
  22427. var p2 = points[(intPoint + 1) % l];
  22428. if (this.closed || intPoint + 2 < l) {
  22429. p3 = points[(intPoint + 2) % l];
  22430. } else {
  22431. // extrapolate last point
  22432. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22433. p3 = tmp;
  22434. }
  22435. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22436. // init Centripetal / Chordal Catmull-Rom
  22437. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22438. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22439. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22440. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22441. if (dt1 < 1e-4) dt1 = 1.0;
  22442. if (dt0 < 1e-4) dt0 = dt1;
  22443. if (dt2 < 1e-4) dt2 = dt1;
  22444. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22445. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22446. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22447. } else if (this.curveType === 'catmullrom') {
  22448. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22449. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22450. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22451. }
  22452. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22453. return point;
  22454. };
  22455. _proto.copy = function copy(source) {
  22456. _Curve.prototype.copy.call(this, source);
  22457. this.points = [];
  22458. for (var i = 0, l = source.points.length; i < l; i++) {
  22459. var point = source.points[i];
  22460. this.points.push(point.clone());
  22461. }
  22462. this.closed = source.closed;
  22463. this.curveType = source.curveType;
  22464. this.tension = source.tension;
  22465. return this;
  22466. };
  22467. _proto.toJSON = function toJSON() {
  22468. var data = _Curve.prototype.toJSON.call(this);
  22469. data.points = [];
  22470. for (var i = 0, l = this.points.length; i < l; i++) {
  22471. var point = this.points[i];
  22472. data.points.push(point.toArray());
  22473. }
  22474. data.closed = this.closed;
  22475. data.curveType = this.curveType;
  22476. data.tension = this.tension;
  22477. return data;
  22478. };
  22479. _proto.fromJSON = function fromJSON(json) {
  22480. _Curve.prototype.fromJSON.call(this, json);
  22481. this.points = [];
  22482. for (var i = 0, l = json.points.length; i < l; i++) {
  22483. var point = json.points[i];
  22484. this.points.push(new Vector3().fromArray(point));
  22485. }
  22486. this.closed = json.closed;
  22487. this.curveType = json.curveType;
  22488. this.tension = json.tension;
  22489. return this;
  22490. };
  22491. return CatmullRomCurve3;
  22492. }(Curve);
  22493. /**
  22494. * Bezier Curves formulas obtained from
  22495. * http://en.wikipedia.org/wiki/Bézier_curve
  22496. */
  22497. function CatmullRom(t, p0, p1, p2, p3) {
  22498. var v0 = (p2 - p0) * 0.5;
  22499. var v1 = (p3 - p1) * 0.5;
  22500. var t2 = t * t;
  22501. var t3 = t * t2;
  22502. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22503. } //
  22504. function QuadraticBezierP0(t, p) {
  22505. var k = 1 - t;
  22506. return k * k * p;
  22507. }
  22508. function QuadraticBezierP1(t, p) {
  22509. return 2 * (1 - t) * t * p;
  22510. }
  22511. function QuadraticBezierP2(t, p) {
  22512. return t * t * p;
  22513. }
  22514. function QuadraticBezier(t, p0, p1, p2) {
  22515. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22516. } //
  22517. function CubicBezierP0(t, p) {
  22518. var k = 1 - t;
  22519. return k * k * k * p;
  22520. }
  22521. function CubicBezierP1(t, p) {
  22522. var k = 1 - t;
  22523. return 3 * k * k * t * p;
  22524. }
  22525. function CubicBezierP2(t, p) {
  22526. return 3 * (1 - t) * t * t * p;
  22527. }
  22528. function CubicBezierP3(t, p) {
  22529. return t * t * t * p;
  22530. }
  22531. function CubicBezier(t, p0, p1, p2, p3) {
  22532. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22533. }
  22534. var CubicBezierCurve = /*#__PURE__*/function (_Curve) {
  22535. _inheritsLoose(CubicBezierCurve, _Curve);
  22536. function CubicBezierCurve(v0, v1, v2, v3) {
  22537. var _this;
  22538. if (v0 === void 0) {
  22539. v0 = new Vector2();
  22540. }
  22541. if (v1 === void 0) {
  22542. v1 = new Vector2();
  22543. }
  22544. if (v2 === void 0) {
  22545. v2 = new Vector2();
  22546. }
  22547. if (v3 === void 0) {
  22548. v3 = new Vector2();
  22549. }
  22550. _this = _Curve.call(this) || this;
  22551. _this.type = 'CubicBezierCurve';
  22552. Object.defineProperty(_assertThisInitialized(_this), 'isCubicBezierCurve', {
  22553. value: true
  22554. });
  22555. _this.v0 = v0;
  22556. _this.v1 = v1;
  22557. _this.v2 = v2;
  22558. _this.v3 = v3;
  22559. return _this;
  22560. }
  22561. var _proto = CubicBezierCurve.prototype;
  22562. _proto.getPoint = function getPoint(t, optionalTarget) {
  22563. if (optionalTarget === void 0) {
  22564. optionalTarget = new Vector2();
  22565. }
  22566. var point = optionalTarget;
  22567. var v0 = this.v0,
  22568. v1 = this.v1,
  22569. v2 = this.v2,
  22570. v3 = this.v3;
  22571. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22572. return point;
  22573. };
  22574. _proto.copy = function copy(source) {
  22575. _Curve.prototype.copy.call(this, source);
  22576. this.v0.copy(source.v0);
  22577. this.v1.copy(source.v1);
  22578. this.v2.copy(source.v2);
  22579. this.v3.copy(source.v3);
  22580. return this;
  22581. };
  22582. _proto.toJSON = function toJSON() {
  22583. var data = _Curve.prototype.toJSON.call(this);
  22584. data.v0 = this.v0.toArray();
  22585. data.v1 = this.v1.toArray();
  22586. data.v2 = this.v2.toArray();
  22587. data.v3 = this.v3.toArray();
  22588. return data;
  22589. };
  22590. _proto.fromJSON = function fromJSON(json) {
  22591. _Curve.prototype.fromJSON.call(this, json);
  22592. this.v0.fromArray(json.v0);
  22593. this.v1.fromArray(json.v1);
  22594. this.v2.fromArray(json.v2);
  22595. this.v3.fromArray(json.v3);
  22596. return this;
  22597. };
  22598. return CubicBezierCurve;
  22599. }(Curve);
  22600. var CubicBezierCurve3 = /*#__PURE__*/function (_Curve) {
  22601. _inheritsLoose(CubicBezierCurve3, _Curve);
  22602. function CubicBezierCurve3(v0, v1, v2, v3) {
  22603. var _this;
  22604. if (v0 === void 0) {
  22605. v0 = new Vector3();
  22606. }
  22607. if (v1 === void 0) {
  22608. v1 = new Vector3();
  22609. }
  22610. if (v2 === void 0) {
  22611. v2 = new Vector3();
  22612. }
  22613. if (v3 === void 0) {
  22614. v3 = new Vector3();
  22615. }
  22616. _this = _Curve.call(this) || this;
  22617. _this.type = 'CubicBezierCurve3';
  22618. Object.defineProperty(_assertThisInitialized(_this), 'isCubicBezierCurve3', {
  22619. value: true
  22620. });
  22621. _this.v0 = v0;
  22622. _this.v1 = v1;
  22623. _this.v2 = v2;
  22624. _this.v3 = v3;
  22625. return _this;
  22626. }
  22627. var _proto = CubicBezierCurve3.prototype;
  22628. _proto.getPoint = function getPoint(t, optionalTarget) {
  22629. if (optionalTarget === void 0) {
  22630. optionalTarget = new Vector3();
  22631. }
  22632. var point = optionalTarget;
  22633. var v0 = this.v0,
  22634. v1 = this.v1,
  22635. v2 = this.v2,
  22636. v3 = this.v3;
  22637. 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));
  22638. return point;
  22639. };
  22640. _proto.copy = function copy(source) {
  22641. _Curve.prototype.copy.call(this, source);
  22642. this.v0.copy(source.v0);
  22643. this.v1.copy(source.v1);
  22644. this.v2.copy(source.v2);
  22645. this.v3.copy(source.v3);
  22646. return this;
  22647. };
  22648. _proto.toJSON = function toJSON() {
  22649. var data = _Curve.prototype.toJSON.call(this);
  22650. data.v0 = this.v0.toArray();
  22651. data.v1 = this.v1.toArray();
  22652. data.v2 = this.v2.toArray();
  22653. data.v3 = this.v3.toArray();
  22654. return data;
  22655. };
  22656. _proto.fromJSON = function fromJSON(json) {
  22657. _Curve.prototype.fromJSON.call(this, json);
  22658. this.v0.fromArray(json.v0);
  22659. this.v1.fromArray(json.v1);
  22660. this.v2.fromArray(json.v2);
  22661. this.v3.fromArray(json.v3);
  22662. return this;
  22663. };
  22664. return CubicBezierCurve3;
  22665. }(Curve);
  22666. var LineCurve = /*#__PURE__*/function (_Curve) {
  22667. _inheritsLoose(LineCurve, _Curve);
  22668. function LineCurve(v1, v2) {
  22669. var _this;
  22670. if (v1 === void 0) {
  22671. v1 = new Vector2();
  22672. }
  22673. if (v2 === void 0) {
  22674. v2 = new Vector2();
  22675. }
  22676. _this = _Curve.call(this) || this;
  22677. _this.type = 'LineCurve';
  22678. Object.defineProperty(_assertThisInitialized(_this), 'isLineCurve', {
  22679. value: true
  22680. });
  22681. _this.v1 = v1;
  22682. _this.v2 = v2;
  22683. return _this;
  22684. }
  22685. var _proto = LineCurve.prototype;
  22686. _proto.getPoint = function getPoint(t, optionalTarget) {
  22687. if (optionalTarget === void 0) {
  22688. optionalTarget = new Vector2();
  22689. }
  22690. var point = optionalTarget;
  22691. if (t === 1) {
  22692. point.copy(this.v2);
  22693. } else {
  22694. point.copy(this.v2).sub(this.v1);
  22695. point.multiplyScalar(t).add(this.v1);
  22696. }
  22697. return point;
  22698. } // Line curve is linear, so we can overwrite default getPointAt
  22699. ;
  22700. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22701. return this.getPoint(u, optionalTarget);
  22702. };
  22703. _proto.getTangent = function getTangent(t, optionalTarget) {
  22704. var tangent = optionalTarget || new Vector2();
  22705. tangent.copy(this.v2).sub(this.v1).normalize();
  22706. return tangent;
  22707. };
  22708. _proto.copy = function copy(source) {
  22709. _Curve.prototype.copy.call(this, source);
  22710. this.v1.copy(source.v1);
  22711. this.v2.copy(source.v2);
  22712. return this;
  22713. };
  22714. _proto.toJSON = function toJSON() {
  22715. var data = _Curve.prototype.toJSON.call(this);
  22716. data.v1 = this.v1.toArray();
  22717. data.v2 = this.v2.toArray();
  22718. return data;
  22719. };
  22720. _proto.fromJSON = function fromJSON(json) {
  22721. _Curve.prototype.fromJSON.call(this, json);
  22722. this.v1.fromArray(json.v1);
  22723. this.v2.fromArray(json.v2);
  22724. return this;
  22725. };
  22726. return LineCurve;
  22727. }(Curve);
  22728. var LineCurve3 = /*#__PURE__*/function (_Curve) {
  22729. _inheritsLoose(LineCurve3, _Curve);
  22730. function LineCurve3(v1, v2) {
  22731. var _this;
  22732. if (v1 === void 0) {
  22733. v1 = new Vector3();
  22734. }
  22735. if (v2 === void 0) {
  22736. v2 = new Vector3();
  22737. }
  22738. _this = _Curve.call(this) || this;
  22739. _this.type = 'LineCurve3';
  22740. Object.defineProperty(_assertThisInitialized(_this), 'isLineCurve3', {
  22741. value: true
  22742. });
  22743. _this.v1 = v1;
  22744. _this.v2 = v2;
  22745. return _this;
  22746. }
  22747. var _proto = LineCurve3.prototype;
  22748. _proto.getPoint = function getPoint(t, optionalTarget) {
  22749. if (optionalTarget === void 0) {
  22750. optionalTarget = new Vector3();
  22751. }
  22752. var point = optionalTarget;
  22753. if (t === 1) {
  22754. point.copy(this.v2);
  22755. } else {
  22756. point.copy(this.v2).sub(this.v1);
  22757. point.multiplyScalar(t).add(this.v1);
  22758. }
  22759. return point;
  22760. } // Line curve is linear, so we can overwrite default getPointAt
  22761. ;
  22762. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22763. return this.getPoint(u, optionalTarget);
  22764. };
  22765. _proto.copy = function copy(source) {
  22766. _Curve.prototype.copy.call(this, source);
  22767. this.v1.copy(source.v1);
  22768. this.v2.copy(source.v2);
  22769. return this;
  22770. };
  22771. _proto.toJSON = function toJSON() {
  22772. var data = _Curve.prototype.toJSON.call(this);
  22773. data.v1 = this.v1.toArray();
  22774. data.v2 = this.v2.toArray();
  22775. return data;
  22776. };
  22777. _proto.fromJSON = function fromJSON(json) {
  22778. _Curve.prototype.fromJSON.call(this, json);
  22779. this.v1.fromArray(json.v1);
  22780. this.v2.fromArray(json.v2);
  22781. return this;
  22782. };
  22783. return LineCurve3;
  22784. }(Curve);
  22785. var QuadraticBezierCurve = /*#__PURE__*/function (_Curve) {
  22786. _inheritsLoose(QuadraticBezierCurve, _Curve);
  22787. function QuadraticBezierCurve(v0, v1, v2) {
  22788. var _this;
  22789. if (v0 === void 0) {
  22790. v0 = new Vector2();
  22791. }
  22792. if (v1 === void 0) {
  22793. v1 = new Vector2();
  22794. }
  22795. if (v2 === void 0) {
  22796. v2 = new Vector2();
  22797. }
  22798. _this = _Curve.call(this) || this;
  22799. _this.type = 'QuadraticBezierCurve';
  22800. Object.defineProperty(_assertThisInitialized(_this), 'isQuadraticBezierCurve', {
  22801. value: true
  22802. });
  22803. _this.v0 = v0;
  22804. _this.v1 = v1;
  22805. _this.v2 = v2;
  22806. return _this;
  22807. }
  22808. var _proto = QuadraticBezierCurve.prototype;
  22809. _proto.getPoint = function getPoint(t, optionalTarget) {
  22810. if (optionalTarget === void 0) {
  22811. optionalTarget = new Vector2();
  22812. }
  22813. var point = optionalTarget;
  22814. var v0 = this.v0,
  22815. v1 = this.v1,
  22816. v2 = this.v2;
  22817. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22818. return point;
  22819. };
  22820. _proto.copy = function copy(source) {
  22821. _Curve.prototype.copy.call(this, source);
  22822. this.v0.copy(source.v0);
  22823. this.v1.copy(source.v1);
  22824. this.v2.copy(source.v2);
  22825. return this;
  22826. };
  22827. _proto.toJSON = function toJSON() {
  22828. var data = _Curve.prototype.toJSON.call(this);
  22829. data.v0 = this.v0.toArray();
  22830. data.v1 = this.v1.toArray();
  22831. data.v2 = this.v2.toArray();
  22832. return data;
  22833. };
  22834. _proto.fromJSON = function fromJSON(json) {
  22835. _Curve.prototype.fromJSON.call(this, json);
  22836. this.v0.fromArray(json.v0);
  22837. this.v1.fromArray(json.v1);
  22838. this.v2.fromArray(json.v2);
  22839. return this;
  22840. };
  22841. return QuadraticBezierCurve;
  22842. }(Curve);
  22843. var QuadraticBezierCurve3 = /*#__PURE__*/function (_Curve) {
  22844. _inheritsLoose(QuadraticBezierCurve3, _Curve);
  22845. function QuadraticBezierCurve3(v0, v1, v2) {
  22846. var _this;
  22847. if (v0 === void 0) {
  22848. v0 = new Vector3();
  22849. }
  22850. if (v1 === void 0) {
  22851. v1 = new Vector3();
  22852. }
  22853. if (v2 === void 0) {
  22854. v2 = new Vector3();
  22855. }
  22856. _this = _Curve.call(this) || this;
  22857. _this.type = 'QuadraticBezierCurve3';
  22858. Object.defineProperty(_assertThisInitialized(_this), 'isQuadraticBezierCurve3', {
  22859. value: true
  22860. });
  22861. _this.v0 = v0;
  22862. _this.v1 = v1;
  22863. _this.v2 = v2;
  22864. return _this;
  22865. }
  22866. var _proto = QuadraticBezierCurve3.prototype;
  22867. _proto.getPoint = function getPoint(t, optionalTarget) {
  22868. if (optionalTarget === void 0) {
  22869. optionalTarget = new Vector3();
  22870. }
  22871. var point = optionalTarget;
  22872. var v0 = this.v0,
  22873. v1 = this.v1,
  22874. v2 = this.v2;
  22875. 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));
  22876. return point;
  22877. };
  22878. _proto.copy = function copy(source) {
  22879. _Curve.prototype.copy.call(this, source);
  22880. this.v0.copy(source.v0);
  22881. this.v1.copy(source.v1);
  22882. this.v2.copy(source.v2);
  22883. return this;
  22884. };
  22885. _proto.toJSON = function toJSON() {
  22886. var data = _Curve.prototype.toJSON.call(this);
  22887. data.v0 = this.v0.toArray();
  22888. data.v1 = this.v1.toArray();
  22889. data.v2 = this.v2.toArray();
  22890. return data;
  22891. };
  22892. _proto.fromJSON = function fromJSON(json) {
  22893. _Curve.prototype.fromJSON.call(this, json);
  22894. this.v0.fromArray(json.v0);
  22895. this.v1.fromArray(json.v1);
  22896. this.v2.fromArray(json.v2);
  22897. return this;
  22898. };
  22899. return QuadraticBezierCurve3;
  22900. }(Curve);
  22901. var SplineCurve = /*#__PURE__*/function (_Curve) {
  22902. _inheritsLoose(SplineCurve, _Curve);
  22903. function SplineCurve(points) {
  22904. var _this;
  22905. if (points === void 0) {
  22906. points = [];
  22907. }
  22908. _this = _Curve.call(this) || this;
  22909. _this.type = 'SplineCurve';
  22910. Object.defineProperty(_assertThisInitialized(_this), 'isSplineCurve', {
  22911. value: true
  22912. });
  22913. _this.points = points;
  22914. return _this;
  22915. }
  22916. var _proto = SplineCurve.prototype;
  22917. _proto.getPoint = function getPoint(t, optionalTarget) {
  22918. if (optionalTarget === void 0) {
  22919. optionalTarget = new Vector2();
  22920. }
  22921. var point = optionalTarget;
  22922. var points = this.points;
  22923. var p = (points.length - 1) * t;
  22924. var intPoint = Math.floor(p);
  22925. var weight = p - intPoint;
  22926. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22927. var p1 = points[intPoint];
  22928. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22929. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22930. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22931. return point;
  22932. };
  22933. _proto.copy = function copy(source) {
  22934. Curve.prototype.copy.call(this, source);
  22935. this.points = [];
  22936. for (var i = 0, l = source.points.length; i < l; i++) {
  22937. var point = source.points[i];
  22938. this.points.push(point.clone());
  22939. }
  22940. return this;
  22941. };
  22942. _proto.toJSON = function toJSON() {
  22943. var data = Curve.prototype.toJSON.call(this);
  22944. data.points = [];
  22945. for (var i = 0, l = this.points.length; i < l; i++) {
  22946. var point = this.points[i];
  22947. data.points.push(point.toArray());
  22948. }
  22949. return data;
  22950. };
  22951. _proto.fromJSON = function fromJSON(json) {
  22952. Curve.prototype.fromJSON.call(this, json);
  22953. this.points = [];
  22954. for (var i = 0, l = json.points.length; i < l; i++) {
  22955. var point = json.points[i];
  22956. this.points.push(new Vector2().fromArray(point));
  22957. }
  22958. return this;
  22959. };
  22960. return SplineCurve;
  22961. }(Curve);
  22962. var Curves = /*#__PURE__*/Object.freeze({
  22963. __proto__: null,
  22964. ArcCurve: ArcCurve,
  22965. CatmullRomCurve3: CatmullRomCurve3,
  22966. CubicBezierCurve: CubicBezierCurve,
  22967. CubicBezierCurve3: CubicBezierCurve3,
  22968. EllipseCurve: EllipseCurve,
  22969. LineCurve: LineCurve,
  22970. LineCurve3: LineCurve3,
  22971. QuadraticBezierCurve: QuadraticBezierCurve,
  22972. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22973. SplineCurve: SplineCurve
  22974. });
  22975. /**************************************************************
  22976. * Curved Path - a curve path is simply a array of connected
  22977. * curves, but retains the api of a curve
  22978. **************************************************************/
  22979. var CurvePath = /*#__PURE__*/function (_Curve) {
  22980. _inheritsLoose(CurvePath, _Curve);
  22981. function CurvePath() {
  22982. var _this;
  22983. _this = _Curve.call(this) || this;
  22984. _this.type = 'CurvePath';
  22985. _this.curves = [];
  22986. _this.autoClose = false; // Automatically closes the path
  22987. return _this;
  22988. }
  22989. var _proto = CurvePath.prototype;
  22990. _proto.add = function add(curve) {
  22991. this.curves.push(curve);
  22992. };
  22993. _proto.closePath = function closePath() {
  22994. // Add a line curve if start and end of lines are not connected
  22995. var startPoint = this.curves[0].getPoint(0);
  22996. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22997. if (!startPoint.equals(endPoint)) {
  22998. this.curves.push(new LineCurve(endPoint, startPoint));
  22999. }
  23000. } // To get accurate point with reference to
  23001. // entire path distance at time t,
  23002. // following has to be done:
  23003. // 1. Length of each sub path have to be known
  23004. // 2. Locate and identify type of curve
  23005. // 3. Get t for the curve
  23006. // 4. Return curve.getPointAt(t')
  23007. ;
  23008. _proto.getPoint = function getPoint(t) {
  23009. var d = t * this.getLength();
  23010. var curveLengths = this.getCurveLengths();
  23011. var i = 0; // To think about boundaries points.
  23012. while (i < curveLengths.length) {
  23013. if (curveLengths[i] >= d) {
  23014. var diff = curveLengths[i] - d;
  23015. var curve = this.curves[i];
  23016. var segmentLength = curve.getLength();
  23017. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23018. return curve.getPointAt(u);
  23019. }
  23020. i++;
  23021. }
  23022. return null; // loop where sum != 0, sum > d , sum+1 <d
  23023. } // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23024. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23025. // getPoint() depends on getLength
  23026. ;
  23027. _proto.getLength = function getLength() {
  23028. var lens = this.getCurveLengths();
  23029. return lens[lens.length - 1];
  23030. } // cacheLengths must be recalculated.
  23031. ;
  23032. _proto.updateArcLengths = function updateArcLengths() {
  23033. this.needsUpdate = true;
  23034. this.cacheLengths = null;
  23035. this.getCurveLengths();
  23036. } // Compute lengths and cache them
  23037. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23038. ;
  23039. _proto.getCurveLengths = function getCurveLengths() {
  23040. // We use cache values if curves and cache array are same length
  23041. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23042. return this.cacheLengths;
  23043. } // Get length of sub-curve
  23044. // Push sums into cached array
  23045. var lengths = [];
  23046. var sums = 0;
  23047. for (var i = 0, l = this.curves.length; i < l; i++) {
  23048. sums += this.curves[i].getLength();
  23049. lengths.push(sums);
  23050. }
  23051. this.cacheLengths = lengths;
  23052. return lengths;
  23053. };
  23054. _proto.getSpacedPoints = function getSpacedPoints(divisions) {
  23055. if (divisions === void 0) {
  23056. divisions = 40;
  23057. }
  23058. var points = [];
  23059. for (var i = 0; i <= divisions; i++) {
  23060. points.push(this.getPoint(i / divisions));
  23061. }
  23062. if (this.autoClose) {
  23063. points.push(points[0]);
  23064. }
  23065. return points;
  23066. };
  23067. _proto.getPoints = function getPoints(divisions) {
  23068. if (divisions === void 0) {
  23069. divisions = 12;
  23070. }
  23071. var points = [];
  23072. var last;
  23073. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23074. var curve = curves[i];
  23075. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23076. var pts = curve.getPoints(resolution);
  23077. for (var j = 0; j < pts.length; j++) {
  23078. var point = pts[j];
  23079. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23080. points.push(point);
  23081. last = point;
  23082. }
  23083. }
  23084. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23085. points.push(points[0]);
  23086. }
  23087. return points;
  23088. };
  23089. _proto.copy = function copy(source) {
  23090. _Curve.prototype.copy.call(this, source);
  23091. this.curves = [];
  23092. for (var i = 0, l = source.curves.length; i < l; i++) {
  23093. var curve = source.curves[i];
  23094. this.curves.push(curve.clone());
  23095. }
  23096. this.autoClose = source.autoClose;
  23097. return this;
  23098. };
  23099. _proto.toJSON = function toJSON() {
  23100. var data = _Curve.prototype.toJSON.call(this);
  23101. data.autoClose = this.autoClose;
  23102. data.curves = [];
  23103. for (var i = 0, l = this.curves.length; i < l; i++) {
  23104. var curve = this.curves[i];
  23105. data.curves.push(curve.toJSON());
  23106. }
  23107. return data;
  23108. };
  23109. _proto.fromJSON = function fromJSON(json) {
  23110. _Curve.prototype.fromJSON.call(this, json);
  23111. this.autoClose = json.autoClose;
  23112. this.curves = [];
  23113. for (var i = 0, l = json.curves.length; i < l; i++) {
  23114. var curve = json.curves[i];
  23115. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23116. }
  23117. return this;
  23118. };
  23119. return CurvePath;
  23120. }(Curve);
  23121. var Path = /*#__PURE__*/function (_CurvePath) {
  23122. _inheritsLoose(Path, _CurvePath);
  23123. function Path(points) {
  23124. var _this;
  23125. _this = _CurvePath.call(this) || this;
  23126. _this.type = 'Path';
  23127. _this.currentPoint = new Vector2();
  23128. if (points) {
  23129. _this.setFromPoints(points);
  23130. }
  23131. return _this;
  23132. }
  23133. var _proto = Path.prototype;
  23134. _proto.setFromPoints = function setFromPoints(points) {
  23135. this.moveTo(points[0].x, points[0].y);
  23136. for (var i = 1, l = points.length; i < l; i++) {
  23137. this.lineTo(points[i].x, points[i].y);
  23138. }
  23139. return this;
  23140. };
  23141. _proto.moveTo = function moveTo(x, y) {
  23142. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23143. return this;
  23144. };
  23145. _proto.lineTo = function lineTo(x, y) {
  23146. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23147. this.curves.push(curve);
  23148. this.currentPoint.set(x, y);
  23149. return this;
  23150. };
  23151. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23152. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23153. this.curves.push(curve);
  23154. this.currentPoint.set(aX, aY);
  23155. return this;
  23156. };
  23157. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23158. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23159. this.curves.push(curve);
  23160. this.currentPoint.set(aX, aY);
  23161. return this;
  23162. };
  23163. _proto.splineThru = function splineThru(pts
  23164. /*Array of Vector*/
  23165. ) {
  23166. var npts = [this.currentPoint.clone()].concat(pts);
  23167. var curve = new SplineCurve(npts);
  23168. this.curves.push(curve);
  23169. this.currentPoint.copy(pts[pts.length - 1]);
  23170. return this;
  23171. };
  23172. _proto.arc = function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23173. var x0 = this.currentPoint.x;
  23174. var y0 = this.currentPoint.y;
  23175. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23176. return this;
  23177. };
  23178. _proto.absarc = function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23179. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23180. return this;
  23181. };
  23182. _proto.ellipse = function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23183. var x0 = this.currentPoint.x;
  23184. var y0 = this.currentPoint.y;
  23185. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23186. return this;
  23187. };
  23188. _proto.absellipse = function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23189. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23190. if (this.curves.length > 0) {
  23191. // if a previous curve is present, attempt to join
  23192. var firstPoint = curve.getPoint(0);
  23193. if (!firstPoint.equals(this.currentPoint)) {
  23194. this.lineTo(firstPoint.x, firstPoint.y);
  23195. }
  23196. }
  23197. this.curves.push(curve);
  23198. var lastPoint = curve.getPoint(1);
  23199. this.currentPoint.copy(lastPoint);
  23200. return this;
  23201. };
  23202. _proto.copy = function copy(source) {
  23203. _CurvePath.prototype.copy.call(this, source);
  23204. this.currentPoint.copy(source.currentPoint);
  23205. return this;
  23206. };
  23207. _proto.toJSON = function toJSON() {
  23208. var data = _CurvePath.prototype.toJSON.call(this);
  23209. data.currentPoint = this.currentPoint.toArray();
  23210. return data;
  23211. };
  23212. _proto.fromJSON = function fromJSON(json) {
  23213. _CurvePath.prototype.fromJSON.call(this, json);
  23214. this.currentPoint.fromArray(json.currentPoint);
  23215. return this;
  23216. };
  23217. return Path;
  23218. }(CurvePath);
  23219. var Shape = /*#__PURE__*/function (_Path) {
  23220. _inheritsLoose(Shape, _Path);
  23221. function Shape(points) {
  23222. var _this;
  23223. _this = _Path.call(this, points) || this;
  23224. _this.uuid = MathUtils.generateUUID();
  23225. _this.type = 'Shape';
  23226. _this.holes = [];
  23227. return _this;
  23228. }
  23229. var _proto = Shape.prototype;
  23230. _proto.getPointsHoles = function getPointsHoles(divisions) {
  23231. var holesPts = [];
  23232. for (var i = 0, l = this.holes.length; i < l; i++) {
  23233. holesPts[i] = this.holes[i].getPoints(divisions);
  23234. }
  23235. return holesPts;
  23236. } // get points of shape and holes (keypoints based on segments parameter)
  23237. ;
  23238. _proto.extractPoints = function extractPoints(divisions) {
  23239. return {
  23240. shape: this.getPoints(divisions),
  23241. holes: this.getPointsHoles(divisions)
  23242. };
  23243. };
  23244. _proto.copy = function copy(source) {
  23245. _Path.prototype.copy.call(this, source);
  23246. this.holes = [];
  23247. for (var i = 0, l = source.holes.length; i < l; i++) {
  23248. var hole = source.holes[i];
  23249. this.holes.push(hole.clone());
  23250. }
  23251. return this;
  23252. };
  23253. _proto.toJSON = function toJSON() {
  23254. var data = _Path.prototype.toJSON.call(this);
  23255. data.uuid = this.uuid;
  23256. data.holes = [];
  23257. for (var i = 0, l = this.holes.length; i < l; i++) {
  23258. var hole = this.holes[i];
  23259. data.holes.push(hole.toJSON());
  23260. }
  23261. return data;
  23262. };
  23263. _proto.fromJSON = function fromJSON(json) {
  23264. _Path.prototype.fromJSON.call(this, json);
  23265. this.uuid = json.uuid;
  23266. this.holes = [];
  23267. for (var i = 0, l = json.holes.length; i < l; i++) {
  23268. var hole = json.holes[i];
  23269. this.holes.push(new Path().fromJSON(hole));
  23270. }
  23271. return this;
  23272. };
  23273. return Shape;
  23274. }(Path);
  23275. var Light = /*#__PURE__*/function (_Object3D) {
  23276. _inheritsLoose(Light, _Object3D);
  23277. function Light(color, intensity) {
  23278. var _this;
  23279. if (intensity === void 0) {
  23280. intensity = 1;
  23281. }
  23282. _this = _Object3D.call(this) || this;
  23283. Object.defineProperty(_assertThisInitialized(_this), 'isLight', {
  23284. value: true
  23285. });
  23286. _this.type = 'Light';
  23287. _this.color = new Color(color);
  23288. _this.intensity = intensity;
  23289. return _this;
  23290. }
  23291. var _proto = Light.prototype;
  23292. _proto.copy = function copy(source) {
  23293. _Object3D.prototype.copy.call(this, source);
  23294. this.color.copy(source.color);
  23295. this.intensity = source.intensity;
  23296. return this;
  23297. };
  23298. _proto.toJSON = function toJSON(meta) {
  23299. var data = _Object3D.prototype.toJSON.call(this, meta);
  23300. data.object.color = this.color.getHex();
  23301. data.object.intensity = this.intensity;
  23302. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23303. if (this.distance !== undefined) data.object.distance = this.distance;
  23304. if (this.angle !== undefined) data.object.angle = this.angle;
  23305. if (this.decay !== undefined) data.object.decay = this.decay;
  23306. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23307. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23308. return data;
  23309. };
  23310. return Light;
  23311. }(Object3D);
  23312. var HemisphereLight = /*#__PURE__*/function (_Light) {
  23313. _inheritsLoose(HemisphereLight, _Light);
  23314. function HemisphereLight(skyColor, groundColor, intensity) {
  23315. var _this;
  23316. _this = _Light.call(this, skyColor, intensity) || this;
  23317. Object.defineProperty(_assertThisInitialized(_this), 'isHemisphereLight', {
  23318. value: true
  23319. });
  23320. _this.type = 'HemisphereLight';
  23321. _this.position.copy(Object3D.DefaultUp);
  23322. _this.updateMatrix();
  23323. _this.groundColor = new Color(groundColor);
  23324. return _this;
  23325. }
  23326. var _proto = HemisphereLight.prototype;
  23327. _proto.copy = function copy(source) {
  23328. Light.prototype.copy.call(this, source);
  23329. this.groundColor.copy(source.groundColor);
  23330. return this;
  23331. };
  23332. return HemisphereLight;
  23333. }(Light);
  23334. var _projScreenMatrix = /*@__PURE__*/new Matrix4();
  23335. var _lightPositionWorld = /*@__PURE__*/new Vector3();
  23336. var _lookTarget = /*@__PURE__*/new Vector3();
  23337. var LightShadow = /*#__PURE__*/function () {
  23338. function LightShadow(camera) {
  23339. this.camera = camera;
  23340. this.bias = 0;
  23341. this.normalBias = 0;
  23342. this.radius = 1;
  23343. this.mapSize = new Vector2(512, 512);
  23344. this.map = null;
  23345. this.mapPass = null;
  23346. this.matrix = new Matrix4();
  23347. this.autoUpdate = true;
  23348. this.needsUpdate = false;
  23349. this._frustum = new Frustum();
  23350. this._frameExtents = new Vector2(1, 1);
  23351. this._viewportCount = 1;
  23352. this._viewports = [new Vector4(0, 0, 1, 1)];
  23353. }
  23354. var _proto = LightShadow.prototype;
  23355. _proto.getViewportCount = function getViewportCount() {
  23356. return this._viewportCount;
  23357. };
  23358. _proto.getFrustum = function getFrustum() {
  23359. return this._frustum;
  23360. };
  23361. _proto.updateMatrices = function updateMatrices(light) {
  23362. var shadowCamera = this.camera;
  23363. var shadowMatrix = this.matrix;
  23364. _lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23365. shadowCamera.position.copy(_lightPositionWorld);
  23366. _lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23367. shadowCamera.lookAt(_lookTarget);
  23368. shadowCamera.updateMatrixWorld();
  23369. _projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23370. this._frustum.setFromProjectionMatrix(_projScreenMatrix);
  23371. 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);
  23372. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23373. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23374. };
  23375. _proto.getViewport = function getViewport(viewportIndex) {
  23376. return this._viewports[viewportIndex];
  23377. };
  23378. _proto.getFrameExtents = function getFrameExtents() {
  23379. return this._frameExtents;
  23380. };
  23381. _proto.copy = function copy(source) {
  23382. this.camera = source.camera.clone();
  23383. this.bias = source.bias;
  23384. this.radius = source.radius;
  23385. this.mapSize.copy(source.mapSize);
  23386. return this;
  23387. };
  23388. _proto.clone = function clone() {
  23389. return new this.constructor().copy(this);
  23390. };
  23391. _proto.toJSON = function toJSON() {
  23392. var object = {};
  23393. if (this.bias !== 0) object.bias = this.bias;
  23394. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23395. if (this.radius !== 1) object.radius = this.radius;
  23396. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23397. object.camera = this.camera.toJSON(false).object;
  23398. delete object.camera.matrix;
  23399. return object;
  23400. };
  23401. return LightShadow;
  23402. }();
  23403. var SpotLightShadow = /*#__PURE__*/function (_LightShadow) {
  23404. _inheritsLoose(SpotLightShadow, _LightShadow);
  23405. function SpotLightShadow() {
  23406. var _this;
  23407. _this = _LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500)) || this;
  23408. Object.defineProperty(_assertThisInitialized(_this), 'isSpotLightShadow', {
  23409. value: true
  23410. });
  23411. _this.focus = 1;
  23412. return _this;
  23413. }
  23414. var _proto = SpotLightShadow.prototype;
  23415. _proto.updateMatrices = function updateMatrices(light) {
  23416. var camera = this.camera;
  23417. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23418. var aspect = this.mapSize.width / this.mapSize.height;
  23419. var far = light.distance || camera.far;
  23420. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23421. camera.fov = fov;
  23422. camera.aspect = aspect;
  23423. camera.far = far;
  23424. camera.updateProjectionMatrix();
  23425. }
  23426. _LightShadow.prototype.updateMatrices.call(this, light);
  23427. };
  23428. return SpotLightShadow;
  23429. }(LightShadow);
  23430. var SpotLight = /*#__PURE__*/function (_Light) {
  23431. _inheritsLoose(SpotLight, _Light);
  23432. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23433. var _this;
  23434. if (distance === void 0) {
  23435. distance = 0;
  23436. }
  23437. if (angle === void 0) {
  23438. angle = Math.PI / 3;
  23439. }
  23440. if (penumbra === void 0) {
  23441. penumbra = 0;
  23442. }
  23443. if (decay === void 0) {
  23444. decay = 1;
  23445. }
  23446. _this = _Light.call(this, color, intensity) || this;
  23447. Object.defineProperty(_assertThisInitialized(_this), 'isSpotLight', {
  23448. value: true
  23449. });
  23450. _this.type = 'SpotLight';
  23451. _this.position.copy(Object3D.DefaultUp);
  23452. _this.updateMatrix();
  23453. _this.target = new Object3D();
  23454. _this.distance = distance;
  23455. _this.angle = angle;
  23456. _this.penumbra = penumbra;
  23457. _this.decay = decay; // for physically correct lights, should be 2.
  23458. _this.shadow = new SpotLightShadow();
  23459. return _this;
  23460. }
  23461. var _proto = SpotLight.prototype;
  23462. _proto.copy = function copy(source) {
  23463. _Light.prototype.copy.call(this, source);
  23464. this.distance = source.distance;
  23465. this.angle = source.angle;
  23466. this.penumbra = source.penumbra;
  23467. this.decay = source.decay;
  23468. this.target = source.target.clone();
  23469. this.shadow = source.shadow.clone();
  23470. return this;
  23471. };
  23472. _createClass(SpotLight, [{
  23473. key: "power",
  23474. get: function get() {
  23475. // intensity = power per solid angle.
  23476. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23477. return this.intensity * Math.PI;
  23478. },
  23479. set: function set(power) {
  23480. // intensity = power per solid angle.
  23481. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23482. this.intensity = power / Math.PI;
  23483. }
  23484. }]);
  23485. return SpotLight;
  23486. }(Light);
  23487. var _projScreenMatrix$1 = /*@__PURE__*/new Matrix4();
  23488. var _lightPositionWorld$1 = /*@__PURE__*/new Vector3();
  23489. var _lookTarget$1 = /*@__PURE__*/new Vector3();
  23490. var PointLightShadow = /*#__PURE__*/function (_LightShadow) {
  23491. _inheritsLoose(PointLightShadow, _LightShadow);
  23492. function PointLightShadow() {
  23493. var _this;
  23494. _this = _LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500)) || this;
  23495. Object.defineProperty(_assertThisInitialized(_this), 'isPointLightShadow', {
  23496. value: true
  23497. });
  23498. _this._frameExtents = new Vector2(4, 2);
  23499. _this._viewportCount = 6;
  23500. _this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23501. // following orientation:
  23502. //
  23503. // xzXZ
  23504. // y Y
  23505. //
  23506. // X - Positive x direction
  23507. // x - Negative x direction
  23508. // Y - Positive y direction
  23509. // y - Negative y direction
  23510. // Z - Positive z direction
  23511. // z - Negative z direction
  23512. // positive X
  23513. new Vector4(2, 1, 1, 1), // negative X
  23514. new Vector4(0, 1, 1, 1), // positive Z
  23515. new Vector4(3, 1, 1, 1), // negative Z
  23516. new Vector4(1, 1, 1, 1), // positive Y
  23517. new Vector4(3, 0, 1, 1), // negative Y
  23518. new Vector4(1, 0, 1, 1)];
  23519. _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)];
  23520. _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)];
  23521. return _this;
  23522. }
  23523. var _proto = PointLightShadow.prototype;
  23524. _proto.updateMatrices = function updateMatrices(light, viewportIndex) {
  23525. if (viewportIndex === void 0) {
  23526. viewportIndex = 0;
  23527. }
  23528. var camera = this.camera;
  23529. var shadowMatrix = this.matrix;
  23530. _lightPositionWorld$1.setFromMatrixPosition(light.matrixWorld);
  23531. camera.position.copy(_lightPositionWorld$1);
  23532. _lookTarget$1.copy(camera.position);
  23533. _lookTarget$1.add(this._cubeDirections[viewportIndex]);
  23534. camera.up.copy(this._cubeUps[viewportIndex]);
  23535. camera.lookAt(_lookTarget$1);
  23536. camera.updateMatrixWorld();
  23537. shadowMatrix.makeTranslation(-_lightPositionWorld$1.x, -_lightPositionWorld$1.y, -_lightPositionWorld$1.z);
  23538. _projScreenMatrix$1.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23539. this._frustum.setFromProjectionMatrix(_projScreenMatrix$1);
  23540. };
  23541. return PointLightShadow;
  23542. }(LightShadow);
  23543. var PointLight = /*#__PURE__*/function (_Light) {
  23544. _inheritsLoose(PointLight, _Light);
  23545. function PointLight(color, intensity, distance, decay) {
  23546. var _this;
  23547. if (distance === void 0) {
  23548. distance = 0;
  23549. }
  23550. if (decay === void 0) {
  23551. decay = 1;
  23552. }
  23553. _this = _Light.call(this, color, intensity) || this;
  23554. Object.defineProperty(_assertThisInitialized(_this), 'isPointLight', {
  23555. value: true
  23556. });
  23557. _this.type = 'PointLight';
  23558. _this.distance = distance;
  23559. _this.decay = decay; // for physically correct lights, should be 2.
  23560. _this.shadow = new PointLightShadow();
  23561. return _this;
  23562. }
  23563. var _proto = PointLight.prototype;
  23564. _proto.copy = function copy(source) {
  23565. _Light.prototype.copy.call(this, source);
  23566. this.distance = source.distance;
  23567. this.decay = source.decay;
  23568. this.shadow = source.shadow.clone();
  23569. return this;
  23570. };
  23571. _createClass(PointLight, [{
  23572. key: "power",
  23573. get: function get() {
  23574. // intensity = power per solid angle.
  23575. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23576. return this.intensity * 4 * Math.PI;
  23577. },
  23578. set: function set(power) {
  23579. // intensity = power per solid angle.
  23580. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23581. this.intensity = power / (4 * Math.PI);
  23582. }
  23583. }]);
  23584. return PointLight;
  23585. }(Light);
  23586. function OrthographicCamera(left, right, top, bottom, near, far) {
  23587. if (left === void 0) {
  23588. left = -1;
  23589. }
  23590. if (right === void 0) {
  23591. right = 1;
  23592. }
  23593. if (top === void 0) {
  23594. top = 1;
  23595. }
  23596. if (bottom === void 0) {
  23597. bottom = -1;
  23598. }
  23599. if (near === void 0) {
  23600. near = 0.1;
  23601. }
  23602. if (far === void 0) {
  23603. far = 2000;
  23604. }
  23605. Camera.call(this);
  23606. this.type = 'OrthographicCamera';
  23607. this.zoom = 1;
  23608. this.view = null;
  23609. this.left = left;
  23610. this.right = right;
  23611. this.top = top;
  23612. this.bottom = bottom;
  23613. this.near = near;
  23614. this.far = far;
  23615. this.updateProjectionMatrix();
  23616. }
  23617. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23618. constructor: OrthographicCamera,
  23619. isOrthographicCamera: true,
  23620. copy: function copy(source, recursive) {
  23621. Camera.prototype.copy.call(this, source, recursive);
  23622. this.left = source.left;
  23623. this.right = source.right;
  23624. this.top = source.top;
  23625. this.bottom = source.bottom;
  23626. this.near = source.near;
  23627. this.far = source.far;
  23628. this.zoom = source.zoom;
  23629. this.view = source.view === null ? null : Object.assign({}, source.view);
  23630. return this;
  23631. },
  23632. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23633. if (this.view === null) {
  23634. this.view = {
  23635. enabled: true,
  23636. fullWidth: 1,
  23637. fullHeight: 1,
  23638. offsetX: 0,
  23639. offsetY: 0,
  23640. width: 1,
  23641. height: 1
  23642. };
  23643. }
  23644. this.view.enabled = true;
  23645. this.view.fullWidth = fullWidth;
  23646. this.view.fullHeight = fullHeight;
  23647. this.view.offsetX = x;
  23648. this.view.offsetY = y;
  23649. this.view.width = width;
  23650. this.view.height = height;
  23651. this.updateProjectionMatrix();
  23652. },
  23653. clearViewOffset: function clearViewOffset() {
  23654. if (this.view !== null) {
  23655. this.view.enabled = false;
  23656. }
  23657. this.updateProjectionMatrix();
  23658. },
  23659. updateProjectionMatrix: function updateProjectionMatrix() {
  23660. var dx = (this.right - this.left) / (2 * this.zoom);
  23661. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23662. var cx = (this.right + this.left) / 2;
  23663. var cy = (this.top + this.bottom) / 2;
  23664. var left = cx - dx;
  23665. var right = cx + dx;
  23666. var top = cy + dy;
  23667. var bottom = cy - dy;
  23668. if (this.view !== null && this.view.enabled) {
  23669. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23670. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23671. left += scaleW * this.view.offsetX;
  23672. right = left + scaleW * this.view.width;
  23673. top -= scaleH * this.view.offsetY;
  23674. bottom = top - scaleH * this.view.height;
  23675. }
  23676. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23677. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23678. },
  23679. toJSON: function toJSON(meta) {
  23680. var data = Object3D.prototype.toJSON.call(this, meta);
  23681. data.object.zoom = this.zoom;
  23682. data.object.left = this.left;
  23683. data.object.right = this.right;
  23684. data.object.top = this.top;
  23685. data.object.bottom = this.bottom;
  23686. data.object.near = this.near;
  23687. data.object.far = this.far;
  23688. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23689. return data;
  23690. }
  23691. });
  23692. var DirectionalLightShadow = /*#__PURE__*/function (_LightShadow) {
  23693. _inheritsLoose(DirectionalLightShadow, _LightShadow);
  23694. function DirectionalLightShadow() {
  23695. var _this;
  23696. _this = _LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500)) || this;
  23697. Object.defineProperty(_assertThisInitialized(_this), 'isDirectionalLightShadow', {
  23698. value: true
  23699. });
  23700. return _this;
  23701. }
  23702. return DirectionalLightShadow;
  23703. }(LightShadow);
  23704. var DirectionalLight = /*#__PURE__*/function (_Light) {
  23705. _inheritsLoose(DirectionalLight, _Light);
  23706. function DirectionalLight(color, intensity) {
  23707. var _this;
  23708. _this = _Light.call(this, color, intensity) || this;
  23709. Object.defineProperty(_assertThisInitialized(_this), 'isDirectionalLight', {
  23710. value: true
  23711. });
  23712. _this.type = 'DirectionalLight';
  23713. _this.position.copy(Object3D.DefaultUp);
  23714. _this.updateMatrix();
  23715. _this.target = new Object3D();
  23716. _this.shadow = new DirectionalLightShadow();
  23717. return _this;
  23718. }
  23719. var _proto = DirectionalLight.prototype;
  23720. _proto.copy = function copy(source) {
  23721. _Light.prototype.copy.call(this, source);
  23722. this.target = source.target.clone();
  23723. this.shadow = source.shadow.clone();
  23724. return this;
  23725. };
  23726. return DirectionalLight;
  23727. }(Light);
  23728. var AmbientLight = /*#__PURE__*/function (_Light) {
  23729. _inheritsLoose(AmbientLight, _Light);
  23730. function AmbientLight(color, intensity) {
  23731. var _this;
  23732. _this = _Light.call(this, color, intensity) || this;
  23733. _this.type = 'AmbientLight';
  23734. Object.defineProperty(_assertThisInitialized(_this), 'isAmbientLight', {
  23735. value: true
  23736. });
  23737. return _this;
  23738. }
  23739. return AmbientLight;
  23740. }(Light);
  23741. var RectAreaLight = /*#__PURE__*/function (_Light) {
  23742. _inheritsLoose(RectAreaLight, _Light);
  23743. function RectAreaLight(color, intensity, width, height) {
  23744. var _this;
  23745. if (width === void 0) {
  23746. width = 10;
  23747. }
  23748. if (height === void 0) {
  23749. height = 10;
  23750. }
  23751. _this = _Light.call(this, color, intensity) || this;
  23752. Object.defineProperty(_assertThisInitialized(_this), 'isRectAreaLight', {
  23753. value: true
  23754. });
  23755. _this.type = 'RectAreaLight';
  23756. _this.width = width;
  23757. _this.height = height;
  23758. return _this;
  23759. }
  23760. var _proto = RectAreaLight.prototype;
  23761. _proto.copy = function copy(source) {
  23762. _Light.prototype.copy.call(this, source);
  23763. this.width = source.width;
  23764. this.height = source.height;
  23765. return this;
  23766. };
  23767. _proto.toJSON = function toJSON(meta) {
  23768. var data = _Light.prototype.toJSON.call(this, meta);
  23769. data.object.width = this.width;
  23770. data.object.height = this.height;
  23771. return data;
  23772. };
  23773. return RectAreaLight;
  23774. }(Light);
  23775. /**
  23776. * Primary reference:
  23777. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23778. *
  23779. * Secondary reference:
  23780. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23781. */
  23782. // 3-band SH defined by 9 coefficients
  23783. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23784. function SphericalHarmonics3() {
  23785. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23786. value: true
  23787. });
  23788. this.coefficients = [];
  23789. for (var i = 0; i < 9; i++) {
  23790. this.coefficients.push(new Vector3());
  23791. }
  23792. }
  23793. var _proto = SphericalHarmonics3.prototype;
  23794. _proto.set = function set(coefficients) {
  23795. for (var i = 0; i < 9; i++) {
  23796. this.coefficients[i].copy(coefficients[i]);
  23797. }
  23798. return this;
  23799. };
  23800. _proto.zero = function zero() {
  23801. for (var i = 0; i < 9; i++) {
  23802. this.coefficients[i].set(0, 0, 0);
  23803. }
  23804. return this;
  23805. } // get the radiance in the direction of the normal
  23806. // target is a Vector3
  23807. ;
  23808. _proto.getAt = function getAt(normal, target) {
  23809. // normal is assumed to be unit length
  23810. var x = normal.x,
  23811. y = normal.y,
  23812. z = normal.z;
  23813. var coeff = this.coefficients; // band 0
  23814. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23815. target.addScaledVector(coeff[1], 0.488603 * y);
  23816. target.addScaledVector(coeff[2], 0.488603 * z);
  23817. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23818. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23819. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23820. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23821. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23822. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23823. return target;
  23824. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23825. // target is a Vector3
  23826. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23827. ;
  23828. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23829. // normal is assumed to be unit length
  23830. var x = normal.x,
  23831. y = normal.y,
  23832. z = normal.z;
  23833. var coeff = this.coefficients; // band 0
  23834. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23835. // band 1
  23836. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23837. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23838. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23839. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23840. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23841. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23842. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23843. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23844. return target;
  23845. };
  23846. _proto.add = function add(sh) {
  23847. for (var i = 0; i < 9; i++) {
  23848. this.coefficients[i].add(sh.coefficients[i]);
  23849. }
  23850. return this;
  23851. };
  23852. _proto.addScaledSH = function addScaledSH(sh, s) {
  23853. for (var i = 0; i < 9; i++) {
  23854. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23855. }
  23856. return this;
  23857. };
  23858. _proto.scale = function scale(s) {
  23859. for (var i = 0; i < 9; i++) {
  23860. this.coefficients[i].multiplyScalar(s);
  23861. }
  23862. return this;
  23863. };
  23864. _proto.lerp = function lerp(sh, alpha) {
  23865. for (var i = 0; i < 9; i++) {
  23866. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23867. }
  23868. return this;
  23869. };
  23870. _proto.equals = function equals(sh) {
  23871. for (var i = 0; i < 9; i++) {
  23872. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23873. return false;
  23874. }
  23875. }
  23876. return true;
  23877. };
  23878. _proto.copy = function copy(sh) {
  23879. return this.set(sh.coefficients);
  23880. };
  23881. _proto.clone = function clone() {
  23882. return new this.constructor().copy(this);
  23883. };
  23884. _proto.fromArray = function fromArray(array, offset) {
  23885. if (offset === void 0) {
  23886. offset = 0;
  23887. }
  23888. var coefficients = this.coefficients;
  23889. for (var i = 0; i < 9; i++) {
  23890. coefficients[i].fromArray(array, offset + i * 3);
  23891. }
  23892. return this;
  23893. };
  23894. _proto.toArray = function toArray(array, offset) {
  23895. if (array === void 0) {
  23896. array = [];
  23897. }
  23898. if (offset === void 0) {
  23899. offset = 0;
  23900. }
  23901. var coefficients = this.coefficients;
  23902. for (var i = 0; i < 9; i++) {
  23903. coefficients[i].toArray(array, offset + i * 3);
  23904. }
  23905. return array;
  23906. } // evaluate the basis functions
  23907. // shBasis is an Array[ 9 ]
  23908. ;
  23909. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23910. // normal is assumed to be unit length
  23911. var x = normal.x,
  23912. y = normal.y,
  23913. z = normal.z; // band 0
  23914. shBasis[0] = 0.282095; // band 1
  23915. shBasis[1] = 0.488603 * y;
  23916. shBasis[2] = 0.488603 * z;
  23917. shBasis[3] = 0.488603 * x; // band 2
  23918. shBasis[4] = 1.092548 * x * y;
  23919. shBasis[5] = 1.092548 * y * z;
  23920. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23921. shBasis[7] = 1.092548 * x * z;
  23922. shBasis[8] = 0.546274 * (x * x - y * y);
  23923. };
  23924. return SphericalHarmonics3;
  23925. }();
  23926. var LightProbe = /*#__PURE__*/function (_Light) {
  23927. _inheritsLoose(LightProbe, _Light);
  23928. function LightProbe(sh, intensity) {
  23929. var _this;
  23930. if (sh === void 0) {
  23931. sh = new SphericalHarmonics3();
  23932. }
  23933. if (intensity === void 0) {
  23934. intensity = 1;
  23935. }
  23936. _this = _Light.call(this, undefined, intensity) || this;
  23937. Object.defineProperty(_assertThisInitialized(_this), 'isLightProbe', {
  23938. value: true
  23939. });
  23940. _this.sh = sh;
  23941. return _this;
  23942. }
  23943. var _proto = LightProbe.prototype;
  23944. _proto.copy = function copy(source) {
  23945. _Light.prototype.copy.call(this, source);
  23946. this.sh.copy(source.sh);
  23947. return this;
  23948. };
  23949. _proto.fromJSON = function fromJSON(json) {
  23950. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23951. this.sh.fromArray(json.sh);
  23952. return this;
  23953. };
  23954. _proto.toJSON = function toJSON(meta) {
  23955. var data = _Light.prototype.toJSON.call(this, meta);
  23956. data.object.sh = this.sh.toArray();
  23957. return data;
  23958. };
  23959. return LightProbe;
  23960. }(Light);
  23961. var MaterialLoader = /*#__PURE__*/function (_Loader) {
  23962. _inheritsLoose(MaterialLoader, _Loader);
  23963. function MaterialLoader(manager) {
  23964. var _this;
  23965. _this = _Loader.call(this, manager) || this;
  23966. _this.textures = {};
  23967. return _this;
  23968. }
  23969. var _proto = MaterialLoader.prototype;
  23970. _proto.load = function load(url, onLoad, onProgress, onError) {
  23971. var scope = this;
  23972. var loader = new FileLoader(scope.manager);
  23973. loader.setPath(scope.path);
  23974. loader.setRequestHeader(scope.requestHeader);
  23975. loader.setWithCredentials(scope.withCredentials);
  23976. loader.load(url, function (text) {
  23977. try {
  23978. onLoad(scope.parse(JSON.parse(text)));
  23979. } catch (e) {
  23980. if (onError) {
  23981. onError(e);
  23982. } else {
  23983. console.error(e);
  23984. }
  23985. scope.manager.itemError(url);
  23986. }
  23987. }, onProgress, onError);
  23988. };
  23989. _proto.parse = function parse(json) {
  23990. var textures = this.textures;
  23991. function getTexture(name) {
  23992. if (textures[name] === undefined) {
  23993. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23994. }
  23995. return textures[name];
  23996. }
  23997. var material = new Materials[json.type]();
  23998. if (json.uuid !== undefined) material.uuid = json.uuid;
  23999. if (json.name !== undefined) material.name = json.name;
  24000. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  24001. if (json.roughness !== undefined) material.roughness = json.roughness;
  24002. if (json.metalness !== undefined) material.metalness = json.metalness;
  24003. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  24004. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  24005. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  24006. if (json.shininess !== undefined) material.shininess = json.shininess;
  24007. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  24008. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  24009. if (json.fog !== undefined) material.fog = json.fog;
  24010. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  24011. if (json.blending !== undefined) material.blending = json.blending;
  24012. if (json.combine !== undefined) material.combine = json.combine;
  24013. if (json.side !== undefined) material.side = json.side;
  24014. if (json.opacity !== undefined) material.opacity = json.opacity;
  24015. if (json.transparent !== undefined) material.transparent = json.transparent;
  24016. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  24017. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  24018. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  24019. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  24020. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  24021. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  24022. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  24023. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  24024. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  24025. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  24026. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  24027. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  24028. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  24029. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  24030. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  24031. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  24032. if (json.rotation !== undefined) material.rotation = json.rotation;
  24033. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  24034. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  24035. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  24036. if (json.scale !== undefined) material.scale = json.scale;
  24037. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  24038. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24039. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24040. if (json.skinning !== undefined) material.skinning = json.skinning;
  24041. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  24042. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  24043. if (json.dithering !== undefined) material.dithering = json.dithering;
  24044. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  24045. if (json.visible !== undefined) material.visible = json.visible;
  24046. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  24047. if (json.userData !== undefined) material.userData = json.userData;
  24048. if (json.vertexColors !== undefined) {
  24049. if (typeof json.vertexColors === 'number') {
  24050. material.vertexColors = json.vertexColors > 0 ? true : false;
  24051. } else {
  24052. material.vertexColors = json.vertexColors;
  24053. }
  24054. } // Shader Material
  24055. if (json.uniforms !== undefined) {
  24056. for (var name in json.uniforms) {
  24057. var uniform = json.uniforms[name];
  24058. material.uniforms[name] = {};
  24059. switch (uniform.type) {
  24060. case 't':
  24061. material.uniforms[name].value = getTexture(uniform.value);
  24062. break;
  24063. case 'c':
  24064. material.uniforms[name].value = new Color().setHex(uniform.value);
  24065. break;
  24066. case 'v2':
  24067. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  24068. break;
  24069. case 'v3':
  24070. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  24071. break;
  24072. case 'v4':
  24073. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  24074. break;
  24075. case 'm3':
  24076. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  24077. break;
  24078. case 'm4':
  24079. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24080. break;
  24081. default:
  24082. material.uniforms[name].value = uniform.value;
  24083. }
  24084. }
  24085. }
  24086. if (json.defines !== undefined) material.defines = json.defines;
  24087. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24088. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24089. if (json.extensions !== undefined) {
  24090. for (var key in json.extensions) {
  24091. material.extensions[key] = json.extensions[key];
  24092. }
  24093. } // Deprecated
  24094. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24095. // for PointsMaterial
  24096. if (json.size !== undefined) material.size = json.size;
  24097. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24098. if (json.map !== undefined) material.map = getTexture(json.map);
  24099. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24100. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24101. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24102. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24103. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24104. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24105. if (json.normalScale !== undefined) {
  24106. var normalScale = json.normalScale;
  24107. if (Array.isArray(normalScale) === false) {
  24108. // Blender exporter used to export a scalar. See #7459
  24109. normalScale = [normalScale, normalScale];
  24110. }
  24111. material.normalScale = new Vector2().fromArray(normalScale);
  24112. }
  24113. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24114. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24115. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24116. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24117. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24118. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24119. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24120. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24121. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24122. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24123. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24124. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24125. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24126. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24127. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24128. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24129. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24130. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24131. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24132. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24133. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24134. if (json.transmission !== undefined) material.transmission = json.transmission;
  24135. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24136. return material;
  24137. };
  24138. _proto.setTextures = function setTextures(value) {
  24139. this.textures = value;
  24140. return this;
  24141. };
  24142. return MaterialLoader;
  24143. }(Loader);
  24144. var LoaderUtils = {
  24145. decodeText: function decodeText(array) {
  24146. if (typeof TextDecoder !== 'undefined') {
  24147. return new TextDecoder().decode(array);
  24148. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24149. // throws a "maximum call stack size exceeded" error for large arrays.
  24150. var s = '';
  24151. for (var i = 0, il = array.length; i < il; i++) {
  24152. // Implicitly assumes little-endian.
  24153. s += String.fromCharCode(array[i]);
  24154. }
  24155. try {
  24156. // merges multi-byte utf-8 characters.
  24157. return decodeURIComponent(escape(s));
  24158. } catch (e) {
  24159. // see #16358
  24160. return s;
  24161. }
  24162. },
  24163. extractUrlBase: function extractUrlBase(url) {
  24164. var index = url.lastIndexOf('/');
  24165. if (index === -1) return './';
  24166. return url.substr(0, index + 1);
  24167. }
  24168. };
  24169. function InstancedBufferGeometry() {
  24170. BufferGeometry.call(this);
  24171. this.type = 'InstancedBufferGeometry';
  24172. this.instanceCount = Infinity;
  24173. }
  24174. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24175. constructor: InstancedBufferGeometry,
  24176. isInstancedBufferGeometry: true,
  24177. copy: function copy(source) {
  24178. BufferGeometry.prototype.copy.call(this, source);
  24179. this.instanceCount = source.instanceCount;
  24180. return this;
  24181. },
  24182. clone: function clone() {
  24183. return new this.constructor().copy(this);
  24184. },
  24185. toJSON: function toJSON() {
  24186. var data = BufferGeometry.prototype.toJSON.call(this);
  24187. data.instanceCount = this.instanceCount;
  24188. data.isInstancedBufferGeometry = true;
  24189. return data;
  24190. }
  24191. });
  24192. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24193. if (typeof normalized === 'number') {
  24194. meshPerAttribute = normalized;
  24195. normalized = false;
  24196. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24197. }
  24198. BufferAttribute.call(this, array, itemSize, normalized);
  24199. this.meshPerAttribute = meshPerAttribute || 1;
  24200. }
  24201. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24202. constructor: InstancedBufferAttribute,
  24203. isInstancedBufferAttribute: true,
  24204. copy: function copy(source) {
  24205. BufferAttribute.prototype.copy.call(this, source);
  24206. this.meshPerAttribute = source.meshPerAttribute;
  24207. return this;
  24208. },
  24209. toJSON: function toJSON() {
  24210. var data = BufferAttribute.prototype.toJSON.call(this);
  24211. data.meshPerAttribute = this.meshPerAttribute;
  24212. data.isInstancedBufferAttribute = true;
  24213. return data;
  24214. }
  24215. });
  24216. var BufferGeometryLoader = /*#__PURE__*/function (_Loader) {
  24217. _inheritsLoose(BufferGeometryLoader, _Loader);
  24218. function BufferGeometryLoader(manager) {
  24219. return _Loader.call(this, manager) || this;
  24220. }
  24221. var _proto = BufferGeometryLoader.prototype;
  24222. _proto.load = function load(url, onLoad, onProgress, onError) {
  24223. var scope = this;
  24224. var loader = new FileLoader(scope.manager);
  24225. loader.setPath(scope.path);
  24226. loader.setRequestHeader(scope.requestHeader);
  24227. loader.setWithCredentials(scope.withCredentials);
  24228. loader.load(url, function (text) {
  24229. try {
  24230. onLoad(scope.parse(JSON.parse(text)));
  24231. } catch (e) {
  24232. if (onError) {
  24233. onError(e);
  24234. } else {
  24235. console.error(e);
  24236. }
  24237. scope.manager.itemError(url);
  24238. }
  24239. }, onProgress, onError);
  24240. };
  24241. _proto.parse = function parse(json) {
  24242. var interleavedBufferMap = {};
  24243. var arrayBufferMap = {};
  24244. function getInterleavedBuffer(json, uuid) {
  24245. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24246. var interleavedBuffers = json.interleavedBuffers;
  24247. var interleavedBuffer = interleavedBuffers[uuid];
  24248. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24249. var array = getTypedArray(interleavedBuffer.type, buffer);
  24250. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24251. ib.uuid = interleavedBuffer.uuid;
  24252. interleavedBufferMap[uuid] = ib;
  24253. return ib;
  24254. }
  24255. function getArrayBuffer(json, uuid) {
  24256. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24257. var arrayBuffers = json.arrayBuffers;
  24258. var arrayBuffer = arrayBuffers[uuid];
  24259. var ab = new Uint32Array(arrayBuffer).buffer;
  24260. arrayBufferMap[uuid] = ab;
  24261. return ab;
  24262. }
  24263. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24264. var index = json.data.index;
  24265. if (index !== undefined) {
  24266. var typedArray = getTypedArray(index.type, index.array);
  24267. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24268. }
  24269. var attributes = json.data.attributes;
  24270. for (var key in attributes) {
  24271. var attribute = attributes[key];
  24272. var bufferAttribute = void 0;
  24273. if (attribute.isInterleavedBufferAttribute) {
  24274. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24275. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24276. } else {
  24277. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24278. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24279. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24280. }
  24281. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24282. geometry.setAttribute(key, bufferAttribute);
  24283. }
  24284. var morphAttributes = json.data.morphAttributes;
  24285. if (morphAttributes) {
  24286. for (var _key in morphAttributes) {
  24287. var attributeArray = morphAttributes[_key];
  24288. var array = [];
  24289. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24290. var _attribute = attributeArray[i];
  24291. var _bufferAttribute = void 0;
  24292. if (_attribute.isInterleavedBufferAttribute) {
  24293. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24294. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24295. } else {
  24296. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24297. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24298. }
  24299. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24300. array.push(_bufferAttribute);
  24301. }
  24302. geometry.morphAttributes[_key] = array;
  24303. }
  24304. }
  24305. var morphTargetsRelative = json.data.morphTargetsRelative;
  24306. if (morphTargetsRelative) {
  24307. geometry.morphTargetsRelative = true;
  24308. }
  24309. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24310. if (groups !== undefined) {
  24311. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24312. var group = groups[_i];
  24313. geometry.addGroup(group.start, group.count, group.materialIndex);
  24314. }
  24315. }
  24316. var boundingSphere = json.data.boundingSphere;
  24317. if (boundingSphere !== undefined) {
  24318. var center = new Vector3();
  24319. if (boundingSphere.center !== undefined) {
  24320. center.fromArray(boundingSphere.center);
  24321. }
  24322. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24323. }
  24324. if (json.name) geometry.name = json.name;
  24325. if (json.userData) geometry.userData = json.userData;
  24326. return geometry;
  24327. };
  24328. return BufferGeometryLoader;
  24329. }(Loader);
  24330. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24331. _inheritsLoose(ObjectLoader, _Loader);
  24332. function ObjectLoader(manager) {
  24333. return _Loader.call(this, manager) || this;
  24334. }
  24335. var _proto = ObjectLoader.prototype;
  24336. _proto.load = function load(url, onLoad, onProgress, onError) {
  24337. var scope = this;
  24338. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24339. this.resourcePath = this.resourcePath || path;
  24340. var loader = new FileLoader(this.manager);
  24341. loader.setPath(this.path);
  24342. loader.setRequestHeader(this.requestHeader);
  24343. loader.setWithCredentials(this.withCredentials);
  24344. loader.load(url, function (text) {
  24345. var json = null;
  24346. try {
  24347. json = JSON.parse(text);
  24348. } catch (error) {
  24349. if (onError !== undefined) onError(error);
  24350. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24351. return;
  24352. }
  24353. var metadata = json.metadata;
  24354. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24355. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24356. return;
  24357. }
  24358. scope.parse(json, onLoad);
  24359. }, onProgress, onError);
  24360. };
  24361. _proto.parse = function parse(json, onLoad) {
  24362. var animations = this.parseAnimations(json.animations);
  24363. var shapes = this.parseShapes(json.shapes);
  24364. var geometries = this.parseGeometries(json.geometries, shapes);
  24365. var images = this.parseImages(json.images, function () {
  24366. if (onLoad !== undefined) onLoad(object);
  24367. });
  24368. var textures = this.parseTextures(json.textures, images);
  24369. var materials = this.parseMaterials(json.materials, textures);
  24370. var object = this.parseObject(json.object, geometries, materials, animations);
  24371. var skeletons = this.parseSkeletons(json.skeletons, object);
  24372. this.bindSkeletons(object, skeletons); //
  24373. if (onLoad !== undefined) {
  24374. var hasImages = false;
  24375. for (var uuid in images) {
  24376. if (images[uuid] instanceof HTMLImageElement) {
  24377. hasImages = true;
  24378. break;
  24379. }
  24380. }
  24381. if (hasImages === false) onLoad(object);
  24382. }
  24383. return object;
  24384. };
  24385. _proto.parseShapes = function parseShapes(json) {
  24386. var shapes = {};
  24387. if (json !== undefined) {
  24388. for (var i = 0, l = json.length; i < l; i++) {
  24389. var shape = new Shape().fromJSON(json[i]);
  24390. shapes[shape.uuid] = shape;
  24391. }
  24392. }
  24393. return shapes;
  24394. };
  24395. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24396. var skeletons = {};
  24397. var bones = {}; // generate bone lookup table
  24398. object.traverse(function (child) {
  24399. if (child.isBone) bones[child.uuid] = child;
  24400. }); // create skeletons
  24401. if (json !== undefined) {
  24402. for (var i = 0, l = json.length; i < l; i++) {
  24403. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24404. skeletons[skeleton.uuid] = skeleton;
  24405. }
  24406. }
  24407. return skeletons;
  24408. };
  24409. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24410. var geometries = {};
  24411. var geometryShapes;
  24412. if (json !== undefined) {
  24413. var bufferGeometryLoader = new BufferGeometryLoader();
  24414. for (var i = 0, l = json.length; i < l; i++) {
  24415. var geometry = void 0;
  24416. var data = json[i];
  24417. switch (data.type) {
  24418. case 'PlaneGeometry':
  24419. case 'PlaneBufferGeometry':
  24420. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24421. break;
  24422. case 'BoxGeometry':
  24423. case 'BoxBufferGeometry':
  24424. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24425. break;
  24426. case 'CircleGeometry':
  24427. case 'CircleBufferGeometry':
  24428. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24429. break;
  24430. case 'CylinderGeometry':
  24431. case 'CylinderBufferGeometry':
  24432. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24433. break;
  24434. case 'ConeGeometry':
  24435. case 'ConeBufferGeometry':
  24436. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24437. break;
  24438. case 'SphereGeometry':
  24439. case 'SphereBufferGeometry':
  24440. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24441. break;
  24442. case 'DodecahedronGeometry':
  24443. case 'DodecahedronBufferGeometry':
  24444. case 'IcosahedronGeometry':
  24445. case 'IcosahedronBufferGeometry':
  24446. case 'OctahedronGeometry':
  24447. case 'OctahedronBufferGeometry':
  24448. case 'TetrahedronGeometry':
  24449. case 'TetrahedronBufferGeometry':
  24450. geometry = new Geometries[data.type](data.radius, data.detail);
  24451. break;
  24452. case 'RingGeometry':
  24453. case 'RingBufferGeometry':
  24454. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24455. break;
  24456. case 'TorusGeometry':
  24457. case 'TorusBufferGeometry':
  24458. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24459. break;
  24460. case 'TorusKnotGeometry':
  24461. case 'TorusKnotBufferGeometry':
  24462. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24463. break;
  24464. case 'TubeGeometry':
  24465. case 'TubeBufferGeometry':
  24466. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24467. // User defined curves or instances of CurvePath will not be deserialized.
  24468. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24469. break;
  24470. case 'LatheGeometry':
  24471. case 'LatheBufferGeometry':
  24472. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24473. break;
  24474. case 'PolyhedronGeometry':
  24475. case 'PolyhedronBufferGeometry':
  24476. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24477. break;
  24478. case 'ShapeGeometry':
  24479. case 'ShapeBufferGeometry':
  24480. geometryShapes = [];
  24481. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24482. var shape = shapes[data.shapes[j]];
  24483. geometryShapes.push(shape);
  24484. }
  24485. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24486. break;
  24487. case 'ExtrudeGeometry':
  24488. case 'ExtrudeBufferGeometry':
  24489. geometryShapes = [];
  24490. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24491. var _shape = shapes[data.shapes[_j]];
  24492. geometryShapes.push(_shape);
  24493. }
  24494. var extrudePath = data.options.extrudePath;
  24495. if (extrudePath !== undefined) {
  24496. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24497. }
  24498. geometry = new Geometries[data.type](geometryShapes, data.options);
  24499. break;
  24500. case 'BufferGeometry':
  24501. case 'InstancedBufferGeometry':
  24502. geometry = bufferGeometryLoader.parse(data);
  24503. break;
  24504. case 'Geometry':
  24505. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24506. break;
  24507. default:
  24508. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24509. continue;
  24510. }
  24511. geometry.uuid = data.uuid;
  24512. if (data.name !== undefined) geometry.name = data.name;
  24513. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24514. geometries[data.uuid] = geometry;
  24515. }
  24516. }
  24517. return geometries;
  24518. };
  24519. _proto.parseMaterials = function parseMaterials(json, textures) {
  24520. var cache = {}; // MultiMaterial
  24521. var materials = {};
  24522. if (json !== undefined) {
  24523. var loader = new MaterialLoader();
  24524. loader.setTextures(textures);
  24525. for (var i = 0, l = json.length; i < l; i++) {
  24526. var data = json[i];
  24527. if (data.type === 'MultiMaterial') {
  24528. // Deprecated
  24529. var array = [];
  24530. for (var j = 0; j < data.materials.length; j++) {
  24531. var material = data.materials[j];
  24532. if (cache[material.uuid] === undefined) {
  24533. cache[material.uuid] = loader.parse(material);
  24534. }
  24535. array.push(cache[material.uuid]);
  24536. }
  24537. materials[data.uuid] = array;
  24538. } else {
  24539. if (cache[data.uuid] === undefined) {
  24540. cache[data.uuid] = loader.parse(data);
  24541. }
  24542. materials[data.uuid] = cache[data.uuid];
  24543. }
  24544. }
  24545. }
  24546. return materials;
  24547. };
  24548. _proto.parseAnimations = function parseAnimations(json) {
  24549. var animations = {};
  24550. if (json !== undefined) {
  24551. for (var i = 0; i < json.length; i++) {
  24552. var data = json[i];
  24553. var clip = AnimationClip.parse(data);
  24554. animations[clip.uuid] = clip;
  24555. }
  24556. }
  24557. return animations;
  24558. };
  24559. _proto.parseImages = function parseImages(json, onLoad) {
  24560. var scope = this;
  24561. var images = {};
  24562. var loader;
  24563. function loadImage(url) {
  24564. scope.manager.itemStart(url);
  24565. return loader.load(url, function () {
  24566. scope.manager.itemEnd(url);
  24567. }, undefined, function () {
  24568. scope.manager.itemError(url);
  24569. scope.manager.itemEnd(url);
  24570. });
  24571. }
  24572. function deserializeImage(image) {
  24573. if (typeof image === 'string') {
  24574. var url = image;
  24575. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24576. return loadImage(path);
  24577. } else {
  24578. if (image.data) {
  24579. return {
  24580. data: getTypedArray(image.type, image.data),
  24581. width: image.width,
  24582. height: image.height
  24583. };
  24584. } else {
  24585. return null;
  24586. }
  24587. }
  24588. }
  24589. if (json !== undefined && json.length > 0) {
  24590. var manager = new LoadingManager(onLoad);
  24591. loader = new ImageLoader(manager);
  24592. loader.setCrossOrigin(this.crossOrigin);
  24593. for (var i = 0, il = json.length; i < il; i++) {
  24594. var image = json[i];
  24595. var url = image.url;
  24596. if (Array.isArray(url)) {
  24597. // load array of images e.g CubeTexture
  24598. images[image.uuid] = [];
  24599. for (var j = 0, jl = url.length; j < jl; j++) {
  24600. var currentUrl = url[j];
  24601. var deserializedImage = deserializeImage(currentUrl);
  24602. if (deserializedImage !== null) {
  24603. if (deserializedImage instanceof HTMLImageElement) {
  24604. images[image.uuid].push(deserializedImage);
  24605. } else {
  24606. // special case: handle array of data textures for cube textures
  24607. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24608. }
  24609. }
  24610. }
  24611. } else {
  24612. // load single image
  24613. var _deserializedImage = deserializeImage(image.url);
  24614. if (_deserializedImage !== null) {
  24615. images[image.uuid] = _deserializedImage;
  24616. }
  24617. }
  24618. }
  24619. }
  24620. return images;
  24621. };
  24622. _proto.parseTextures = function parseTextures(json, images) {
  24623. function parseConstant(value, type) {
  24624. if (typeof value === 'number') return value;
  24625. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24626. return type[value];
  24627. }
  24628. var textures = {};
  24629. if (json !== undefined) {
  24630. for (var i = 0, l = json.length; i < l; i++) {
  24631. var data = json[i];
  24632. if (data.image === undefined) {
  24633. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24634. }
  24635. if (images[data.image] === undefined) {
  24636. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24637. }
  24638. var texture = void 0;
  24639. var image = images[data.image];
  24640. if (Array.isArray(image)) {
  24641. texture = new CubeTexture(image);
  24642. if (image.length === 6) texture.needsUpdate = true;
  24643. } else {
  24644. if (image && image.data) {
  24645. texture = new DataTexture(image.data, image.width, image.height);
  24646. } else {
  24647. texture = new Texture(image);
  24648. }
  24649. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24650. }
  24651. texture.uuid = data.uuid;
  24652. if (data.name !== undefined) texture.name = data.name;
  24653. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24654. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24655. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24656. if (data.center !== undefined) texture.center.fromArray(data.center);
  24657. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24658. if (data.wrap !== undefined) {
  24659. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24660. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24661. }
  24662. if (data.format !== undefined) texture.format = data.format;
  24663. if (data.type !== undefined) texture.type = data.type;
  24664. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24665. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24666. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24667. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24668. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24669. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24670. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24671. textures[data.uuid] = texture;
  24672. }
  24673. }
  24674. return textures;
  24675. };
  24676. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  24677. var object;
  24678. function getGeometry(name) {
  24679. if (geometries[name] === undefined) {
  24680. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24681. }
  24682. return geometries[name];
  24683. }
  24684. function getMaterial(name) {
  24685. if (name === undefined) return undefined;
  24686. if (Array.isArray(name)) {
  24687. var array = [];
  24688. for (var i = 0, l = name.length; i < l; i++) {
  24689. var uuid = name[i];
  24690. if (materials[uuid] === undefined) {
  24691. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24692. }
  24693. array.push(materials[uuid]);
  24694. }
  24695. return array;
  24696. }
  24697. if (materials[name] === undefined) {
  24698. console.warn('THREE.ObjectLoader: Undefined material', name);
  24699. }
  24700. return materials[name];
  24701. }
  24702. var geometry, material;
  24703. switch (data.type) {
  24704. case 'Scene':
  24705. object = new Scene();
  24706. if (data.background !== undefined) {
  24707. if (Number.isInteger(data.background)) {
  24708. object.background = new Color(data.background);
  24709. }
  24710. }
  24711. if (data.fog !== undefined) {
  24712. if (data.fog.type === 'Fog') {
  24713. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24714. } else if (data.fog.type === 'FogExp2') {
  24715. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24716. }
  24717. }
  24718. break;
  24719. case 'PerspectiveCamera':
  24720. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24721. if (data.focus !== undefined) object.focus = data.focus;
  24722. if (data.zoom !== undefined) object.zoom = data.zoom;
  24723. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24724. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24725. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24726. break;
  24727. case 'OrthographicCamera':
  24728. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24729. if (data.zoom !== undefined) object.zoom = data.zoom;
  24730. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24731. break;
  24732. case 'AmbientLight':
  24733. object = new AmbientLight(data.color, data.intensity);
  24734. break;
  24735. case 'DirectionalLight':
  24736. object = new DirectionalLight(data.color, data.intensity);
  24737. break;
  24738. case 'PointLight':
  24739. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24740. break;
  24741. case 'RectAreaLight':
  24742. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24743. break;
  24744. case 'SpotLight':
  24745. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24746. break;
  24747. case 'HemisphereLight':
  24748. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24749. break;
  24750. case 'LightProbe':
  24751. object = new LightProbe().fromJSON(data);
  24752. break;
  24753. case 'SkinnedMesh':
  24754. geometry = getGeometry(data.geometry);
  24755. material = getMaterial(data.material);
  24756. object = new SkinnedMesh(geometry, material);
  24757. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24758. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24759. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24760. break;
  24761. case 'Mesh':
  24762. geometry = getGeometry(data.geometry);
  24763. material = getMaterial(data.material);
  24764. object = new Mesh(geometry, material);
  24765. break;
  24766. case 'InstancedMesh':
  24767. geometry = getGeometry(data.geometry);
  24768. material = getMaterial(data.material);
  24769. var count = data.count;
  24770. var instanceMatrix = data.instanceMatrix;
  24771. object = new InstancedMesh(geometry, material, count);
  24772. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24773. break;
  24774. case 'LOD':
  24775. object = new LOD();
  24776. break;
  24777. case 'Line':
  24778. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  24779. break;
  24780. case 'LineLoop':
  24781. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24782. break;
  24783. case 'LineSegments':
  24784. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24785. break;
  24786. case 'PointCloud':
  24787. case 'Points':
  24788. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24789. break;
  24790. case 'Sprite':
  24791. object = new Sprite(getMaterial(data.material));
  24792. break;
  24793. case 'Group':
  24794. object = new Group();
  24795. break;
  24796. case 'Bone':
  24797. object = new Bone();
  24798. break;
  24799. default:
  24800. object = new Object3D();
  24801. }
  24802. object.uuid = data.uuid;
  24803. if (data.name !== undefined) object.name = data.name;
  24804. if (data.matrix !== undefined) {
  24805. object.matrix.fromArray(data.matrix);
  24806. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24807. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24808. } else {
  24809. if (data.position !== undefined) object.position.fromArray(data.position);
  24810. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24811. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24812. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24813. }
  24814. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24815. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24816. if (data.shadow) {
  24817. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24818. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24819. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24820. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24821. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24822. }
  24823. if (data.visible !== undefined) object.visible = data.visible;
  24824. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24825. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24826. if (data.userData !== undefined) object.userData = data.userData;
  24827. if (data.layers !== undefined) object.layers.mask = data.layers;
  24828. if (data.children !== undefined) {
  24829. var children = data.children;
  24830. for (var i = 0; i < children.length; i++) {
  24831. object.add(this.parseObject(children[i], geometries, materials, animations));
  24832. }
  24833. }
  24834. if (data.animations !== undefined) {
  24835. var objectAnimations = data.animations;
  24836. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24837. var uuid = objectAnimations[_i];
  24838. object.animations.push(animations[uuid]);
  24839. }
  24840. }
  24841. if (data.type === 'LOD') {
  24842. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24843. var levels = data.levels;
  24844. for (var l = 0; l < levels.length; l++) {
  24845. var level = levels[l];
  24846. var child = object.getObjectByProperty('uuid', level.object);
  24847. if (child !== undefined) {
  24848. object.addLevel(child, level.distance);
  24849. }
  24850. }
  24851. }
  24852. return object;
  24853. };
  24854. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24855. if (Object.keys(skeletons).length === 0) return;
  24856. object.traverse(function (child) {
  24857. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24858. var skeleton = skeletons[child.skeleton];
  24859. if (skeleton === undefined) {
  24860. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24861. } else {
  24862. child.bind(skeleton, child.bindMatrix);
  24863. }
  24864. }
  24865. });
  24866. }
  24867. /* DEPRECATED */
  24868. ;
  24869. _proto.setTexturePath = function setTexturePath(value) {
  24870. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24871. return this.setResourcePath(value);
  24872. };
  24873. return ObjectLoader;
  24874. }(Loader);
  24875. var TEXTURE_MAPPING = {
  24876. UVMapping: UVMapping,
  24877. CubeReflectionMapping: CubeReflectionMapping,
  24878. CubeRefractionMapping: CubeRefractionMapping,
  24879. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24880. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24881. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24882. CubeUVRefractionMapping: CubeUVRefractionMapping
  24883. };
  24884. var TEXTURE_WRAPPING = {
  24885. RepeatWrapping: RepeatWrapping,
  24886. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24887. MirroredRepeatWrapping: MirroredRepeatWrapping
  24888. };
  24889. var TEXTURE_FILTER = {
  24890. NearestFilter: NearestFilter,
  24891. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24892. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24893. LinearFilter: LinearFilter,
  24894. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24895. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24896. };
  24897. function ImageBitmapLoader(manager) {
  24898. if (typeof createImageBitmap === 'undefined') {
  24899. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24900. }
  24901. if (typeof fetch === 'undefined') {
  24902. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24903. }
  24904. Loader.call(this, manager);
  24905. this.options = {
  24906. premultiplyAlpha: 'none'
  24907. };
  24908. }
  24909. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24910. constructor: ImageBitmapLoader,
  24911. isImageBitmapLoader: true,
  24912. setOptions: function setOptions(options) {
  24913. this.options = options;
  24914. return this;
  24915. },
  24916. load: function load(url, onLoad, onProgress, onError) {
  24917. if (url === undefined) url = '';
  24918. if (this.path !== undefined) url = this.path + url;
  24919. url = this.manager.resolveURL(url);
  24920. var scope = this;
  24921. var cached = Cache.get(url);
  24922. if (cached !== undefined) {
  24923. scope.manager.itemStart(url);
  24924. setTimeout(function () {
  24925. if (onLoad) onLoad(cached);
  24926. scope.manager.itemEnd(url);
  24927. }, 0);
  24928. return cached;
  24929. }
  24930. var fetchOptions = {};
  24931. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24932. fetch(url, fetchOptions).then(function (res) {
  24933. return res.blob();
  24934. }).then(function (blob) {
  24935. return createImageBitmap(blob, scope.options);
  24936. }).then(function (imageBitmap) {
  24937. Cache.add(url, imageBitmap);
  24938. if (onLoad) onLoad(imageBitmap);
  24939. scope.manager.itemEnd(url);
  24940. }).catch(function (e) {
  24941. if (onError) onError(e);
  24942. scope.manager.itemError(url);
  24943. scope.manager.itemEnd(url);
  24944. });
  24945. scope.manager.itemStart(url);
  24946. }
  24947. });
  24948. var ShapePath = /*#__PURE__*/function () {
  24949. function ShapePath() {
  24950. this.type = 'ShapePath';
  24951. this.color = new Color();
  24952. this.subPaths = [];
  24953. this.currentPath = null;
  24954. }
  24955. var _proto = ShapePath.prototype;
  24956. _proto.moveTo = function moveTo(x, y) {
  24957. this.currentPath = new Path();
  24958. this.subPaths.push(this.currentPath);
  24959. this.currentPath.moveTo(x, y);
  24960. return this;
  24961. };
  24962. _proto.lineTo = function lineTo(x, y) {
  24963. this.currentPath.lineTo(x, y);
  24964. return this;
  24965. };
  24966. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24967. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24968. return this;
  24969. };
  24970. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24971. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24972. return this;
  24973. };
  24974. _proto.splineThru = function splineThru(pts) {
  24975. this.currentPath.splineThru(pts);
  24976. return this;
  24977. };
  24978. _proto.toShapes = function toShapes(isCCW, noHoles) {
  24979. function toShapesNoHoles(inSubpaths) {
  24980. var shapes = [];
  24981. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24982. var _tmpPath = inSubpaths[i];
  24983. var _tmpShape = new Shape();
  24984. _tmpShape.curves = _tmpPath.curves;
  24985. shapes.push(_tmpShape);
  24986. }
  24987. return shapes;
  24988. }
  24989. function isPointInsidePolygon(inPt, inPolygon) {
  24990. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24991. // toggling of inside/outside at every single! intersection point of an edge
  24992. // with the horizontal line through inPt, left of inPt
  24993. // not counting lowerY endpoints of edges and whole edges on that line
  24994. var inside = false;
  24995. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24996. var edgeLowPt = inPolygon[p];
  24997. var edgeHighPt = inPolygon[q];
  24998. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24999. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25000. if (Math.abs(edgeDy) > Number.EPSILON) {
  25001. // not parallel
  25002. if (edgeDy < 0) {
  25003. edgeLowPt = inPolygon[q];
  25004. edgeDx = -edgeDx;
  25005. edgeHighPt = inPolygon[p];
  25006. edgeDy = -edgeDy;
  25007. }
  25008. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  25009. if (inPt.y === edgeLowPt.y) {
  25010. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  25011. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25012. } else {
  25013. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  25014. if (perpEdge === 0) return true; // inPt is on contour ?
  25015. if (perpEdge < 0) continue;
  25016. inside = !inside; // true intersection left of inPt
  25017. }
  25018. } else {
  25019. // parallel or collinear
  25020. if (inPt.y !== edgeLowPt.y) continue; // parallel
  25021. // edge lies on the same horizontal line as inPt
  25022. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  25023. // continue;
  25024. }
  25025. }
  25026. return inside;
  25027. }
  25028. var isClockWise = ShapeUtils.isClockWise;
  25029. var subPaths = this.subPaths;
  25030. if (subPaths.length === 0) return [];
  25031. if (noHoles === true) return toShapesNoHoles(subPaths);
  25032. var solid, tmpPath, tmpShape;
  25033. var shapes = [];
  25034. if (subPaths.length === 1) {
  25035. tmpPath = subPaths[0];
  25036. tmpShape = new Shape();
  25037. tmpShape.curves = tmpPath.curves;
  25038. shapes.push(tmpShape);
  25039. return shapes;
  25040. }
  25041. var holesFirst = !isClockWise(subPaths[0].getPoints());
  25042. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  25043. var betterShapeHoles = [];
  25044. var newShapes = [];
  25045. var newShapeHoles = [];
  25046. var mainIdx = 0;
  25047. var tmpPoints;
  25048. newShapes[mainIdx] = undefined;
  25049. newShapeHoles[mainIdx] = [];
  25050. for (var i = 0, l = subPaths.length; i < l; i++) {
  25051. tmpPath = subPaths[i];
  25052. tmpPoints = tmpPath.getPoints();
  25053. solid = isClockWise(tmpPoints);
  25054. solid = isCCW ? !solid : solid;
  25055. if (solid) {
  25056. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  25057. newShapes[mainIdx] = {
  25058. s: new Shape(),
  25059. p: tmpPoints
  25060. };
  25061. newShapes[mainIdx].s.curves = tmpPath.curves;
  25062. if (holesFirst) mainIdx++;
  25063. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  25064. } else {
  25065. newShapeHoles[mainIdx].push({
  25066. h: tmpPath,
  25067. p: tmpPoints[0]
  25068. }); //console.log('ccw', i);
  25069. }
  25070. } // only Holes? -> probably all Shapes with wrong orientation
  25071. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  25072. if (newShapes.length > 1) {
  25073. var ambiguous = false;
  25074. var toChange = [];
  25075. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  25076. betterShapeHoles[sIdx] = [];
  25077. }
  25078. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  25079. var sho = newShapeHoles[_sIdx];
  25080. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  25081. var ho = sho[hIdx];
  25082. var hole_unassigned = true;
  25083. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  25084. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  25085. if (_sIdx !== s2Idx) toChange.push({
  25086. froms: _sIdx,
  25087. tos: s2Idx,
  25088. hole: hIdx
  25089. });
  25090. if (hole_unassigned) {
  25091. hole_unassigned = false;
  25092. betterShapeHoles[s2Idx].push(ho);
  25093. } else {
  25094. ambiguous = true;
  25095. }
  25096. }
  25097. }
  25098. if (hole_unassigned) {
  25099. betterShapeHoles[_sIdx].push(ho);
  25100. }
  25101. }
  25102. } // console.log("ambiguous: ", ambiguous);
  25103. if (toChange.length > 0) {
  25104. // console.log("to change: ", toChange);
  25105. if (!ambiguous) newShapeHoles = betterShapeHoles;
  25106. }
  25107. }
  25108. var tmpHoles;
  25109. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  25110. tmpShape = newShapes[_i].s;
  25111. shapes.push(tmpShape);
  25112. tmpHoles = newShapeHoles[_i];
  25113. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  25114. tmpShape.holes.push(tmpHoles[j].h);
  25115. }
  25116. } //console.log("shape", shapes);
  25117. return shapes;
  25118. };
  25119. return ShapePath;
  25120. }();
  25121. var Font = /*#__PURE__*/function () {
  25122. function Font(data) {
  25123. Object.defineProperty(this, 'isFont', {
  25124. value: true
  25125. });
  25126. this.type = 'Font';
  25127. this.data = data;
  25128. }
  25129. var _proto = Font.prototype;
  25130. _proto.generateShapes = function generateShapes(text, size) {
  25131. if (size === void 0) {
  25132. size = 100;
  25133. }
  25134. var shapes = [];
  25135. var paths = createPaths(text, size, this.data);
  25136. for (var p = 0, pl = paths.length; p < pl; p++) {
  25137. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25138. }
  25139. return shapes;
  25140. };
  25141. return Font;
  25142. }();
  25143. function createPaths(text, size, data) {
  25144. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25145. var scale = size / data.resolution;
  25146. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25147. var paths = [];
  25148. var offsetX = 0,
  25149. offsetY = 0;
  25150. for (var i = 0; i < chars.length; i++) {
  25151. var char = chars[i];
  25152. if (char === '\n') {
  25153. offsetX = 0;
  25154. offsetY -= line_height;
  25155. } else {
  25156. var ret = createPath(char, scale, offsetX, offsetY, data);
  25157. offsetX += ret.offsetX;
  25158. paths.push(ret.path);
  25159. }
  25160. }
  25161. return paths;
  25162. }
  25163. function createPath(char, scale, offsetX, offsetY, data) {
  25164. var glyph = data.glyphs[char] || data.glyphs['?'];
  25165. if (!glyph) {
  25166. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25167. return;
  25168. }
  25169. var path = new ShapePath();
  25170. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25171. if (glyph.o) {
  25172. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25173. for (var i = 0, l = outline.length; i < l;) {
  25174. var action = outline[i++];
  25175. switch (action) {
  25176. case 'm':
  25177. // moveTo
  25178. x = outline[i++] * scale + offsetX;
  25179. y = outline[i++] * scale + offsetY;
  25180. path.moveTo(x, y);
  25181. break;
  25182. case 'l':
  25183. // lineTo
  25184. x = outline[i++] * scale + offsetX;
  25185. y = outline[i++] * scale + offsetY;
  25186. path.lineTo(x, y);
  25187. break;
  25188. case 'q':
  25189. // quadraticCurveTo
  25190. cpx = outline[i++] * scale + offsetX;
  25191. cpy = outline[i++] * scale + offsetY;
  25192. cpx1 = outline[i++] * scale + offsetX;
  25193. cpy1 = outline[i++] * scale + offsetY;
  25194. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25195. break;
  25196. case 'b':
  25197. // bezierCurveTo
  25198. cpx = outline[i++] * scale + offsetX;
  25199. cpy = outline[i++] * scale + offsetY;
  25200. cpx1 = outline[i++] * scale + offsetX;
  25201. cpy1 = outline[i++] * scale + offsetY;
  25202. cpx2 = outline[i++] * scale + offsetX;
  25203. cpy2 = outline[i++] * scale + offsetY;
  25204. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25205. break;
  25206. }
  25207. }
  25208. }
  25209. return {
  25210. offsetX: glyph.ha * scale,
  25211. path: path
  25212. };
  25213. }
  25214. var FontLoader = /*#__PURE__*/function (_Loader) {
  25215. _inheritsLoose(FontLoader, _Loader);
  25216. function FontLoader(manager) {
  25217. return _Loader.call(this, manager) || this;
  25218. }
  25219. var _proto = FontLoader.prototype;
  25220. _proto.load = function load(url, onLoad, onProgress, onError) {
  25221. var scope = this;
  25222. var loader = new FileLoader(this.manager);
  25223. loader.setPath(this.path);
  25224. loader.setRequestHeader(this.requestHeader);
  25225. loader.setWithCredentials(scope.withCredentials);
  25226. loader.load(url, function (text) {
  25227. var json;
  25228. try {
  25229. json = JSON.parse(text);
  25230. } catch (e) {
  25231. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25232. json = JSON.parse(text.substring(65, text.length - 2));
  25233. }
  25234. var font = scope.parse(json);
  25235. if (onLoad) onLoad(font);
  25236. }, onProgress, onError);
  25237. };
  25238. _proto.parse = function parse(json) {
  25239. return new Font(json);
  25240. };
  25241. return FontLoader;
  25242. }(Loader);
  25243. var _context;
  25244. var AudioContext = {
  25245. getContext: function getContext() {
  25246. if (_context === undefined) {
  25247. _context = new (window.AudioContext || window.webkitAudioContext)();
  25248. }
  25249. return _context;
  25250. },
  25251. setContext: function setContext(value) {
  25252. _context = value;
  25253. }
  25254. };
  25255. var AudioLoader = /*#__PURE__*/function (_Loader) {
  25256. _inheritsLoose(AudioLoader, _Loader);
  25257. function AudioLoader(manager) {
  25258. return _Loader.call(this, manager) || this;
  25259. }
  25260. var _proto = AudioLoader.prototype;
  25261. _proto.load = function load(url, onLoad, onProgress, onError) {
  25262. var scope = this;
  25263. var loader = new FileLoader(this.manager);
  25264. loader.setResponseType('arraybuffer');
  25265. loader.setPath(this.path);
  25266. loader.setRequestHeader(this.requestHeader);
  25267. loader.setWithCredentials(this.withCredentials);
  25268. loader.load(url, function (buffer) {
  25269. try {
  25270. // Create a copy of the buffer. The `decodeAudioData` method
  25271. // detaches the buffer when complete, preventing reuse.
  25272. var bufferCopy = buffer.slice(0);
  25273. var context = AudioContext.getContext();
  25274. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25275. onLoad(audioBuffer);
  25276. });
  25277. } catch (e) {
  25278. if (onError) {
  25279. onError(e);
  25280. } else {
  25281. console.error(e);
  25282. }
  25283. scope.manager.itemError(url);
  25284. }
  25285. }, onProgress, onError);
  25286. };
  25287. return AudioLoader;
  25288. }(Loader);
  25289. var HemisphereLightProbe = /*#__PURE__*/function (_LightProbe) {
  25290. _inheritsLoose(HemisphereLightProbe, _LightProbe);
  25291. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25292. var _this;
  25293. if (intensity === void 0) {
  25294. intensity = 1;
  25295. }
  25296. _this = _LightProbe.call(this, undefined, intensity) || this;
  25297. Object.defineProperty(_assertThisInitialized(_this), 'isHemisphereLightProbe', {
  25298. value: true
  25299. });
  25300. var color1 = new Color().set(skyColor);
  25301. var color2 = new Color().set(groundColor);
  25302. var sky = new Vector3(color1.r, color1.g, color1.b);
  25303. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25304. var c0 = Math.sqrt(Math.PI);
  25305. var c1 = c0 * Math.sqrt(0.75);
  25306. _this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25307. _this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25308. return _this;
  25309. }
  25310. return HemisphereLightProbe;
  25311. }(LightProbe);
  25312. var AmbientLightProbe = /*#__PURE__*/function (_LightProbe) {
  25313. _inheritsLoose(AmbientLightProbe, _LightProbe);
  25314. function AmbientLightProbe(color, intensity) {
  25315. var _this;
  25316. if (intensity === void 0) {
  25317. intensity = 1;
  25318. }
  25319. _this = _LightProbe.call(this, undefined, intensity) || this;
  25320. Object.defineProperty(_assertThisInitialized(_this), 'isAmbientLightProbe', {
  25321. value: true
  25322. });
  25323. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25324. _this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25325. return _this;
  25326. }
  25327. return AmbientLightProbe;
  25328. }(LightProbe);
  25329. var _eyeRight = new Matrix4();
  25330. var _eyeLeft = new Matrix4();
  25331. function StereoCamera() {
  25332. this.type = 'StereoCamera';
  25333. this.aspect = 1;
  25334. this.eyeSep = 0.064;
  25335. this.cameraL = new PerspectiveCamera();
  25336. this.cameraL.layers.enable(1);
  25337. this.cameraL.matrixAutoUpdate = false;
  25338. this.cameraR = new PerspectiveCamera();
  25339. this.cameraR.layers.enable(2);
  25340. this.cameraR.matrixAutoUpdate = false;
  25341. this._cache = {
  25342. focus: null,
  25343. fov: null,
  25344. aspect: null,
  25345. near: null,
  25346. far: null,
  25347. zoom: null,
  25348. eyeSep: null
  25349. };
  25350. }
  25351. Object.assign(StereoCamera.prototype, {
  25352. update: function update(camera) {
  25353. var cache = this._cache;
  25354. 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;
  25355. if (needsUpdate) {
  25356. cache.focus = camera.focus;
  25357. cache.fov = camera.fov;
  25358. cache.aspect = camera.aspect * this.aspect;
  25359. cache.near = camera.near;
  25360. cache.far = camera.far;
  25361. cache.zoom = camera.zoom;
  25362. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25363. // http://paulbourke.net/stereographics/stereorender/
  25364. var projectionMatrix = camera.projectionMatrix.clone();
  25365. var eyeSepHalf = cache.eyeSep / 2;
  25366. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25367. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25368. var xmin, xmax; // translate xOffset
  25369. _eyeLeft.elements[12] = -eyeSepHalf;
  25370. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25371. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25372. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25373. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25374. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25375. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25376. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25377. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25378. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25379. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25380. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25381. }
  25382. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25383. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25384. }
  25385. });
  25386. var Clock = /*#__PURE__*/function () {
  25387. function Clock(autoStart) {
  25388. this.autoStart = autoStart !== undefined ? autoStart : true;
  25389. this.startTime = 0;
  25390. this.oldTime = 0;
  25391. this.elapsedTime = 0;
  25392. this.running = false;
  25393. }
  25394. var _proto = Clock.prototype;
  25395. _proto.start = function start() {
  25396. this.startTime = now();
  25397. this.oldTime = this.startTime;
  25398. this.elapsedTime = 0;
  25399. this.running = true;
  25400. };
  25401. _proto.stop = function stop() {
  25402. this.getElapsedTime();
  25403. this.running = false;
  25404. this.autoStart = false;
  25405. };
  25406. _proto.getElapsedTime = function getElapsedTime() {
  25407. this.getDelta();
  25408. return this.elapsedTime;
  25409. };
  25410. _proto.getDelta = function getDelta() {
  25411. var diff = 0;
  25412. if (this.autoStart && !this.running) {
  25413. this.start();
  25414. return 0;
  25415. }
  25416. if (this.running) {
  25417. var newTime = now();
  25418. diff = (newTime - this.oldTime) / 1000;
  25419. this.oldTime = newTime;
  25420. this.elapsedTime += diff;
  25421. }
  25422. return diff;
  25423. };
  25424. return Clock;
  25425. }();
  25426. function now() {
  25427. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25428. }
  25429. var _position$2 = /*@__PURE__*/new Vector3();
  25430. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25431. var _scale$1 = /*@__PURE__*/new Vector3();
  25432. var _orientation = /*@__PURE__*/new Vector3();
  25433. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25434. _inheritsLoose(AudioListener, _Object3D);
  25435. function AudioListener() {
  25436. var _this;
  25437. _this = _Object3D.call(this) || this;
  25438. _this.type = 'AudioListener';
  25439. _this.context = AudioContext.getContext();
  25440. _this.gain = _this.context.createGain();
  25441. _this.gain.connect(_this.context.destination);
  25442. _this.filter = null;
  25443. _this.timeDelta = 0; // private
  25444. _this._clock = new Clock();
  25445. return _this;
  25446. }
  25447. var _proto = AudioListener.prototype;
  25448. _proto.getInput = function getInput() {
  25449. return this.gain;
  25450. };
  25451. _proto.removeFilter = function removeFilter() {
  25452. if (this.filter !== null) {
  25453. this.gain.disconnect(this.filter);
  25454. this.filter.disconnect(this.context.destination);
  25455. this.gain.connect(this.context.destination);
  25456. this.filter = null;
  25457. }
  25458. return this;
  25459. };
  25460. _proto.getFilter = function getFilter() {
  25461. return this.filter;
  25462. };
  25463. _proto.setFilter = function setFilter(value) {
  25464. if (this.filter !== null) {
  25465. this.gain.disconnect(this.filter);
  25466. this.filter.disconnect(this.context.destination);
  25467. } else {
  25468. this.gain.disconnect(this.context.destination);
  25469. }
  25470. this.filter = value;
  25471. this.gain.connect(this.filter);
  25472. this.filter.connect(this.context.destination);
  25473. return this;
  25474. };
  25475. _proto.getMasterVolume = function getMasterVolume() {
  25476. return this.gain.gain.value;
  25477. };
  25478. _proto.setMasterVolume = function setMasterVolume(value) {
  25479. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25480. return this;
  25481. };
  25482. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25483. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25484. var listener = this.context.listener;
  25485. var up = this.up;
  25486. this.timeDelta = this._clock.getDelta();
  25487. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25488. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25489. if (listener.positionX) {
  25490. // code path for Chrome (see #14393)
  25491. var endTime = this.context.currentTime + this.timeDelta;
  25492. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25493. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25494. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25495. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25496. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25497. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25498. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25499. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25500. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25501. } else {
  25502. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25503. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25504. }
  25505. };
  25506. return AudioListener;
  25507. }(Object3D);
  25508. var Audio = /*#__PURE__*/function (_Object3D) {
  25509. _inheritsLoose(Audio, _Object3D);
  25510. function Audio(listener) {
  25511. var _this;
  25512. _this = _Object3D.call(this) || this;
  25513. _this.type = 'Audio';
  25514. _this.listener = listener;
  25515. _this.context = listener.context;
  25516. _this.gain = _this.context.createGain();
  25517. _this.gain.connect(listener.getInput());
  25518. _this.autoplay = false;
  25519. _this.buffer = null;
  25520. _this.detune = 0;
  25521. _this.loop = false;
  25522. _this.loopStart = 0;
  25523. _this.loopEnd = 0;
  25524. _this.offset = 0;
  25525. _this.duration = undefined;
  25526. _this.playbackRate = 1;
  25527. _this.isPlaying = false;
  25528. _this.hasPlaybackControl = true;
  25529. _this.source = null;
  25530. _this.sourceType = 'empty';
  25531. _this._startedAt = 0;
  25532. _this._progress = 0;
  25533. _this._connected = false;
  25534. _this.filters = [];
  25535. return _this;
  25536. }
  25537. var _proto = Audio.prototype;
  25538. _proto.getOutput = function getOutput() {
  25539. return this.gain;
  25540. };
  25541. _proto.setNodeSource = function setNodeSource(audioNode) {
  25542. this.hasPlaybackControl = false;
  25543. this.sourceType = 'audioNode';
  25544. this.source = audioNode;
  25545. this.connect();
  25546. return this;
  25547. };
  25548. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25549. this.hasPlaybackControl = false;
  25550. this.sourceType = 'mediaNode';
  25551. this.source = this.context.createMediaElementSource(mediaElement);
  25552. this.connect();
  25553. return this;
  25554. };
  25555. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25556. this.hasPlaybackControl = false;
  25557. this.sourceType = 'mediaStreamNode';
  25558. this.source = this.context.createMediaStreamSource(mediaStream);
  25559. this.connect();
  25560. return this;
  25561. };
  25562. _proto.setBuffer = function setBuffer(audioBuffer) {
  25563. this.buffer = audioBuffer;
  25564. this.sourceType = 'buffer';
  25565. if (this.autoplay) this.play();
  25566. return this;
  25567. };
  25568. _proto.play = function play(delay) {
  25569. if (delay === void 0) {
  25570. delay = 0;
  25571. }
  25572. if (this.isPlaying === true) {
  25573. console.warn('THREE.Audio: Audio is already playing.');
  25574. return;
  25575. }
  25576. if (this.hasPlaybackControl === false) {
  25577. console.warn('THREE.Audio: this Audio has no playback control.');
  25578. return;
  25579. }
  25580. this._startedAt = this.context.currentTime + delay;
  25581. var source = this.context.createBufferSource();
  25582. source.buffer = this.buffer;
  25583. source.loop = this.loop;
  25584. source.loopStart = this.loopStart;
  25585. source.loopEnd = this.loopEnd;
  25586. source.onended = this.onEnded.bind(this);
  25587. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25588. this.isPlaying = true;
  25589. this.source = source;
  25590. this.setDetune(this.detune);
  25591. this.setPlaybackRate(this.playbackRate);
  25592. return this.connect();
  25593. };
  25594. _proto.pause = function pause() {
  25595. if (this.hasPlaybackControl === false) {
  25596. console.warn('THREE.Audio: this Audio has no playback control.');
  25597. return;
  25598. }
  25599. if (this.isPlaying === true) {
  25600. // update current progress
  25601. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25602. if (this.loop === true) {
  25603. // ensure _progress does not exceed duration with looped audios
  25604. this._progress = this._progress % (this.duration || this.buffer.duration);
  25605. }
  25606. this.source.stop();
  25607. this.source.onended = null;
  25608. this.isPlaying = false;
  25609. }
  25610. return this;
  25611. };
  25612. _proto.stop = function stop() {
  25613. if (this.hasPlaybackControl === false) {
  25614. console.warn('THREE.Audio: this Audio has no playback control.');
  25615. return;
  25616. }
  25617. this._progress = 0;
  25618. this.source.stop();
  25619. this.source.onended = null;
  25620. this.isPlaying = false;
  25621. return this;
  25622. };
  25623. _proto.connect = function connect() {
  25624. if (this.filters.length > 0) {
  25625. this.source.connect(this.filters[0]);
  25626. for (var i = 1, l = this.filters.length; i < l; i++) {
  25627. this.filters[i - 1].connect(this.filters[i]);
  25628. }
  25629. this.filters[this.filters.length - 1].connect(this.getOutput());
  25630. } else {
  25631. this.source.connect(this.getOutput());
  25632. }
  25633. this._connected = true;
  25634. return this;
  25635. };
  25636. _proto.disconnect = function disconnect() {
  25637. if (this.filters.length > 0) {
  25638. this.source.disconnect(this.filters[0]);
  25639. for (var i = 1, l = this.filters.length; i < l; i++) {
  25640. this.filters[i - 1].disconnect(this.filters[i]);
  25641. }
  25642. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25643. } else {
  25644. this.source.disconnect(this.getOutput());
  25645. }
  25646. this._connected = false;
  25647. return this;
  25648. };
  25649. _proto.getFilters = function getFilters() {
  25650. return this.filters;
  25651. };
  25652. _proto.setFilters = function setFilters(value) {
  25653. if (!value) value = [];
  25654. if (this._connected === true) {
  25655. this.disconnect();
  25656. this.filters = value.slice();
  25657. this.connect();
  25658. } else {
  25659. this.filters = value.slice();
  25660. }
  25661. return this;
  25662. };
  25663. _proto.setDetune = function setDetune(value) {
  25664. this.detune = value;
  25665. if (this.source.detune === undefined) return; // only set detune when available
  25666. if (this.isPlaying === true) {
  25667. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25668. }
  25669. return this;
  25670. };
  25671. _proto.getDetune = function getDetune() {
  25672. return this.detune;
  25673. };
  25674. _proto.getFilter = function getFilter() {
  25675. return this.getFilters()[0];
  25676. };
  25677. _proto.setFilter = function setFilter(filter) {
  25678. return this.setFilters(filter ? [filter] : []);
  25679. };
  25680. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25681. if (this.hasPlaybackControl === false) {
  25682. console.warn('THREE.Audio: this Audio has no playback control.');
  25683. return;
  25684. }
  25685. this.playbackRate = value;
  25686. if (this.isPlaying === true) {
  25687. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25688. }
  25689. return this;
  25690. };
  25691. _proto.getPlaybackRate = function getPlaybackRate() {
  25692. return this.playbackRate;
  25693. };
  25694. _proto.onEnded = function onEnded() {
  25695. this.isPlaying = false;
  25696. };
  25697. _proto.getLoop = function getLoop() {
  25698. if (this.hasPlaybackControl === false) {
  25699. console.warn('THREE.Audio: this Audio has no playback control.');
  25700. return false;
  25701. }
  25702. return this.loop;
  25703. };
  25704. _proto.setLoop = function setLoop(value) {
  25705. if (this.hasPlaybackControl === false) {
  25706. console.warn('THREE.Audio: this Audio has no playback control.');
  25707. return;
  25708. }
  25709. this.loop = value;
  25710. if (this.isPlaying === true) {
  25711. this.source.loop = this.loop;
  25712. }
  25713. return this;
  25714. };
  25715. _proto.setLoopStart = function setLoopStart(value) {
  25716. this.loopStart = value;
  25717. return this;
  25718. };
  25719. _proto.setLoopEnd = function setLoopEnd(value) {
  25720. this.loopEnd = value;
  25721. return this;
  25722. };
  25723. _proto.getVolume = function getVolume() {
  25724. return this.gain.gain.value;
  25725. };
  25726. _proto.setVolume = function setVolume(value) {
  25727. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25728. return this;
  25729. };
  25730. return Audio;
  25731. }(Object3D);
  25732. var _position$3 = /*@__PURE__*/new Vector3();
  25733. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25734. var _scale$2 = /*@__PURE__*/new Vector3();
  25735. var _orientation$1 = /*@__PURE__*/new Vector3();
  25736. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25737. _inheritsLoose(PositionalAudio, _Audio);
  25738. function PositionalAudio(listener) {
  25739. var _this;
  25740. _this = _Audio.call(this, listener) || this;
  25741. _this.panner = _this.context.createPanner();
  25742. _this.panner.panningModel = 'HRTF';
  25743. _this.panner.connect(_this.gain);
  25744. return _this;
  25745. }
  25746. var _proto = PositionalAudio.prototype;
  25747. _proto.getOutput = function getOutput() {
  25748. return this.panner;
  25749. };
  25750. _proto.getRefDistance = function getRefDistance() {
  25751. return this.panner.refDistance;
  25752. };
  25753. _proto.setRefDistance = function setRefDistance(value) {
  25754. this.panner.refDistance = value;
  25755. return this;
  25756. };
  25757. _proto.getRolloffFactor = function getRolloffFactor() {
  25758. return this.panner.rolloffFactor;
  25759. };
  25760. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25761. this.panner.rolloffFactor = value;
  25762. return this;
  25763. };
  25764. _proto.getDistanceModel = function getDistanceModel() {
  25765. return this.panner.distanceModel;
  25766. };
  25767. _proto.setDistanceModel = function setDistanceModel(value) {
  25768. this.panner.distanceModel = value;
  25769. return this;
  25770. };
  25771. _proto.getMaxDistance = function getMaxDistance() {
  25772. return this.panner.maxDistance;
  25773. };
  25774. _proto.setMaxDistance = function setMaxDistance(value) {
  25775. this.panner.maxDistance = value;
  25776. return this;
  25777. };
  25778. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25779. this.panner.coneInnerAngle = coneInnerAngle;
  25780. this.panner.coneOuterAngle = coneOuterAngle;
  25781. this.panner.coneOuterGain = coneOuterGain;
  25782. return this;
  25783. };
  25784. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25785. _Audio.prototype.updateMatrixWorld.call(this, force);
  25786. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25787. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25788. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25789. var panner = this.panner;
  25790. if (panner.positionX) {
  25791. // code path for Chrome and Firefox (see #14393)
  25792. var endTime = this.context.currentTime + this.listener.timeDelta;
  25793. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25794. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25795. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25796. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25797. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25798. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25799. } else {
  25800. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25801. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25802. }
  25803. };
  25804. return PositionalAudio;
  25805. }(Audio);
  25806. var AudioAnalyser = /*#__PURE__*/function () {
  25807. function AudioAnalyser(audio, fftSize) {
  25808. if (fftSize === void 0) {
  25809. fftSize = 2048;
  25810. }
  25811. this.analyser = audio.context.createAnalyser();
  25812. this.analyser.fftSize = fftSize;
  25813. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25814. audio.getOutput().connect(this.analyser);
  25815. }
  25816. var _proto = AudioAnalyser.prototype;
  25817. _proto.getFrequencyData = function getFrequencyData() {
  25818. this.analyser.getByteFrequencyData(this.data);
  25819. return this.data;
  25820. };
  25821. _proto.getAverageFrequency = function getAverageFrequency() {
  25822. var value = 0;
  25823. var data = this.getFrequencyData();
  25824. for (var i = 0; i < data.length; i++) {
  25825. value += data[i];
  25826. }
  25827. return value / data.length;
  25828. };
  25829. return AudioAnalyser;
  25830. }();
  25831. function PropertyMixer(binding, typeName, valueSize) {
  25832. this.binding = binding;
  25833. this.valueSize = valueSize;
  25834. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25835. //
  25836. // interpolators can use .buffer as their .result
  25837. // the data then goes to 'incoming'
  25838. //
  25839. // 'accu0' and 'accu1' are used frame-interleaved for
  25840. // the cumulative result and are compared to detect
  25841. // changes
  25842. //
  25843. // 'orig' stores the original state of the property
  25844. //
  25845. // 'add' is used for additive cumulative results
  25846. //
  25847. // 'work' is optional and is only present for quaternion types. It is used
  25848. // to store intermediate quaternion multiplication results
  25849. switch (typeName) {
  25850. case 'quaternion':
  25851. mixFunction = this._slerp;
  25852. mixFunctionAdditive = this._slerpAdditive;
  25853. setIdentity = this._setAdditiveIdentityQuaternion;
  25854. this.buffer = new Float64Array(valueSize * 6);
  25855. this._workIndex = 5;
  25856. break;
  25857. case 'string':
  25858. case 'bool':
  25859. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25860. // additive is not relevant for non-numeric types
  25861. mixFunctionAdditive = this._select;
  25862. setIdentity = this._setAdditiveIdentityOther;
  25863. this.buffer = new Array(valueSize * 5);
  25864. break;
  25865. default:
  25866. mixFunction = this._lerp;
  25867. mixFunctionAdditive = this._lerpAdditive;
  25868. setIdentity = this._setAdditiveIdentityNumeric;
  25869. this.buffer = new Float64Array(valueSize * 5);
  25870. }
  25871. this._mixBufferRegion = mixFunction;
  25872. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25873. this._setIdentity = setIdentity;
  25874. this._origIndex = 3;
  25875. this._addIndex = 4;
  25876. this.cumulativeWeight = 0;
  25877. this.cumulativeWeightAdditive = 0;
  25878. this.useCount = 0;
  25879. this.referenceCount = 0;
  25880. }
  25881. Object.assign(PropertyMixer.prototype, {
  25882. // accumulate data in the 'incoming' region into 'accu<i>'
  25883. accumulate: function accumulate(accuIndex, weight) {
  25884. // note: happily accumulating nothing when weight = 0, the caller knows
  25885. // the weight and shouldn't have made the call in the first place
  25886. var buffer = this.buffer,
  25887. stride = this.valueSize,
  25888. offset = accuIndex * stride + stride;
  25889. var currentWeight = this.cumulativeWeight;
  25890. if (currentWeight === 0) {
  25891. // accuN := incoming * weight
  25892. for (var i = 0; i !== stride; ++i) {
  25893. buffer[offset + i] = buffer[i];
  25894. }
  25895. currentWeight = weight;
  25896. } else {
  25897. // accuN := accuN + incoming * weight
  25898. currentWeight += weight;
  25899. var mix = weight / currentWeight;
  25900. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25901. }
  25902. this.cumulativeWeight = currentWeight;
  25903. },
  25904. // accumulate data in the 'incoming' region into 'add'
  25905. accumulateAdditive: function accumulateAdditive(weight) {
  25906. var buffer = this.buffer,
  25907. stride = this.valueSize,
  25908. offset = stride * this._addIndex;
  25909. if (this.cumulativeWeightAdditive === 0) {
  25910. // add = identity
  25911. this._setIdentity();
  25912. } // add := add + incoming * weight
  25913. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25914. this.cumulativeWeightAdditive += weight;
  25915. },
  25916. // apply the state of 'accu<i>' to the binding when accus differ
  25917. apply: function apply(accuIndex) {
  25918. var stride = this.valueSize,
  25919. buffer = this.buffer,
  25920. offset = accuIndex * stride + stride,
  25921. weight = this.cumulativeWeight,
  25922. weightAdditive = this.cumulativeWeightAdditive,
  25923. binding = this.binding;
  25924. this.cumulativeWeight = 0;
  25925. this.cumulativeWeightAdditive = 0;
  25926. if (weight < 1) {
  25927. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25928. var originalValueOffset = stride * this._origIndex;
  25929. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25930. }
  25931. if (weightAdditive > 0) {
  25932. // accuN := accuN + additive accuN
  25933. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25934. }
  25935. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25936. if (buffer[i] !== buffer[i + stride]) {
  25937. // value has changed -> update scene graph
  25938. binding.setValue(buffer, offset);
  25939. break;
  25940. }
  25941. }
  25942. },
  25943. // remember the state of the bound property and copy it to both accus
  25944. saveOriginalState: function saveOriginalState() {
  25945. var binding = this.binding;
  25946. var buffer = this.buffer,
  25947. stride = this.valueSize,
  25948. originalValueOffset = stride * this._origIndex;
  25949. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25950. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25951. buffer[i] = buffer[originalValueOffset + i % stride];
  25952. } // Add to identity for additive
  25953. this._setIdentity();
  25954. this.cumulativeWeight = 0;
  25955. this.cumulativeWeightAdditive = 0;
  25956. },
  25957. // apply the state previously taken via 'saveOriginalState' to the binding
  25958. restoreOriginalState: function restoreOriginalState() {
  25959. var originalValueOffset = this.valueSize * 3;
  25960. this.binding.setValue(this.buffer, originalValueOffset);
  25961. },
  25962. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25963. var startIndex = this._addIndex * this.valueSize;
  25964. var endIndex = startIndex + this.valueSize;
  25965. for (var i = startIndex; i < endIndex; i++) {
  25966. this.buffer[i] = 0;
  25967. }
  25968. },
  25969. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25970. this._setAdditiveIdentityNumeric();
  25971. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25972. },
  25973. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25974. var startIndex = this._origIndex * this.valueSize;
  25975. var targetIndex = this._addIndex * this.valueSize;
  25976. for (var i = 0; i < this.valueSize; i++) {
  25977. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25978. }
  25979. },
  25980. // mix functions
  25981. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25982. if (t >= 0.5) {
  25983. for (var i = 0; i !== stride; ++i) {
  25984. buffer[dstOffset + i] = buffer[srcOffset + i];
  25985. }
  25986. }
  25987. },
  25988. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25989. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25990. },
  25991. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25992. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25993. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25994. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25995. },
  25996. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25997. var s = 1 - t;
  25998. for (var i = 0; i !== stride; ++i) {
  25999. var j = dstOffset + i;
  26000. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  26001. }
  26002. },
  26003. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26004. for (var i = 0; i !== stride; ++i) {
  26005. var j = dstOffset + i;
  26006. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  26007. }
  26008. }
  26009. });
  26010. // Characters [].:/ are reserved for track binding syntax.
  26011. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26012. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26013. // only latin characters, and the unicode \p{L} is not yet supported. So
  26014. // instead, we exclude reserved characters and match everything else.
  26015. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26016. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26017. // be matched to parse the rest of the track name.
  26018. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26019. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  26020. // characters. Accessor may contain any character except closing bracket.
  26021. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  26022. // contain any non-bracket characters.
  26023. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  26024. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  26025. var _supportedObjectNames = ['material', 'materials', 'bones'];
  26026. function Composite(targetGroup, path, optionalParsedPath) {
  26027. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  26028. this._targetGroup = targetGroup;
  26029. this._bindings = targetGroup.subscribe_(path, parsedPath);
  26030. }
  26031. Object.assign(Composite.prototype, {
  26032. getValue: function getValue(array, offset) {
  26033. this.bind(); // bind all binding
  26034. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26035. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  26036. if (binding !== undefined) binding.getValue(array, offset);
  26037. },
  26038. setValue: function setValue(array, offset) {
  26039. var bindings = this._bindings;
  26040. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26041. bindings[i].setValue(array, offset);
  26042. }
  26043. },
  26044. bind: function bind() {
  26045. var bindings = this._bindings;
  26046. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26047. bindings[i].bind();
  26048. }
  26049. },
  26050. unbind: function unbind() {
  26051. var bindings = this._bindings;
  26052. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26053. bindings[i].unbind();
  26054. }
  26055. }
  26056. });
  26057. function PropertyBinding(rootNode, path, parsedPath) {
  26058. this.path = path;
  26059. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  26060. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  26061. this.rootNode = rootNode;
  26062. }
  26063. Object.assign(PropertyBinding, {
  26064. Composite: Composite,
  26065. create: function create(root, path, parsedPath) {
  26066. if (!(root && root.isAnimationObjectGroup)) {
  26067. return new PropertyBinding(root, path, parsedPath);
  26068. } else {
  26069. return new PropertyBinding.Composite(root, path, parsedPath);
  26070. }
  26071. },
  26072. /**
  26073. * Replaces spaces with underscores and removes unsupported characters from
  26074. * node names, to ensure compatibility with parseTrackName().
  26075. *
  26076. * @param {string} name Node name to be sanitized.
  26077. * @return {string}
  26078. */
  26079. sanitizeNodeName: function sanitizeNodeName(name) {
  26080. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  26081. },
  26082. parseTrackName: function parseTrackName(trackName) {
  26083. var matches = _trackRe.exec(trackName);
  26084. if (!matches) {
  26085. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  26086. }
  26087. var results = {
  26088. // directoryName: matches[ 1 ], // (tschw) currently unused
  26089. nodeName: matches[2],
  26090. objectName: matches[3],
  26091. objectIndex: matches[4],
  26092. propertyName: matches[5],
  26093. // required
  26094. propertyIndex: matches[6]
  26095. };
  26096. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  26097. if (lastDot !== undefined && lastDot !== -1) {
  26098. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  26099. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26100. // 'bar' could be the objectName, or part of a nodeName (which can
  26101. // include '.' characters).
  26102. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  26103. results.nodeName = results.nodeName.substring(0, lastDot);
  26104. results.objectName = objectName;
  26105. }
  26106. }
  26107. if (results.propertyName === null || results.propertyName.length === 0) {
  26108. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  26109. }
  26110. return results;
  26111. },
  26112. findNode: function findNode(root, nodeName) {
  26113. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  26114. return root;
  26115. } // search into skeleton bones.
  26116. if (root.skeleton) {
  26117. var bone = root.skeleton.getBoneByName(nodeName);
  26118. if (bone !== undefined) {
  26119. return bone;
  26120. }
  26121. } // search into node subtree.
  26122. if (root.children) {
  26123. var searchNodeSubtree = function searchNodeSubtree(children) {
  26124. for (var i = 0; i < children.length; i++) {
  26125. var childNode = children[i];
  26126. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  26127. return childNode;
  26128. }
  26129. var result = searchNodeSubtree(childNode.children);
  26130. if (result) return result;
  26131. }
  26132. return null;
  26133. };
  26134. var subTreeNode = searchNodeSubtree(root.children);
  26135. if (subTreeNode) {
  26136. return subTreeNode;
  26137. }
  26138. }
  26139. return null;
  26140. }
  26141. });
  26142. Object.assign(PropertyBinding.prototype, {
  26143. // prototype, continued
  26144. // these are used to "bind" a nonexistent property
  26145. _getValue_unavailable: function _getValue_unavailable() {},
  26146. _setValue_unavailable: function _setValue_unavailable() {},
  26147. BindingType: {
  26148. Direct: 0,
  26149. EntireArray: 1,
  26150. ArrayElement: 2,
  26151. HasFromToArray: 3
  26152. },
  26153. Versioning: {
  26154. None: 0,
  26155. NeedsUpdate: 1,
  26156. MatrixWorldNeedsUpdate: 2
  26157. },
  26158. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26159. buffer[offset] = this.node[this.propertyName];
  26160. }, function getValue_array(buffer, offset) {
  26161. var source = this.resolvedProperty;
  26162. for (var i = 0, n = source.length; i !== n; ++i) {
  26163. buffer[offset++] = source[i];
  26164. }
  26165. }, function getValue_arrayElement(buffer, offset) {
  26166. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26167. }, function getValue_toArray(buffer, offset) {
  26168. this.resolvedProperty.toArray(buffer, offset);
  26169. }],
  26170. SetterByBindingTypeAndVersioning: [[// Direct
  26171. function setValue_direct(buffer, offset) {
  26172. this.targetObject[this.propertyName] = buffer[offset];
  26173. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26174. this.targetObject[this.propertyName] = buffer[offset];
  26175. this.targetObject.needsUpdate = true;
  26176. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26177. this.targetObject[this.propertyName] = buffer[offset];
  26178. this.targetObject.matrixWorldNeedsUpdate = true;
  26179. }], [// EntireArray
  26180. function setValue_array(buffer, offset) {
  26181. var dest = this.resolvedProperty;
  26182. for (var i = 0, n = dest.length; i !== n; ++i) {
  26183. dest[i] = buffer[offset++];
  26184. }
  26185. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26186. var dest = this.resolvedProperty;
  26187. for (var i = 0, n = dest.length; i !== n; ++i) {
  26188. dest[i] = buffer[offset++];
  26189. }
  26190. this.targetObject.needsUpdate = true;
  26191. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26192. var dest = this.resolvedProperty;
  26193. for (var i = 0, n = dest.length; i !== n; ++i) {
  26194. dest[i] = buffer[offset++];
  26195. }
  26196. this.targetObject.matrixWorldNeedsUpdate = true;
  26197. }], [// ArrayElement
  26198. function setValue_arrayElement(buffer, offset) {
  26199. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26200. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26201. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26202. this.targetObject.needsUpdate = true;
  26203. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26204. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26205. this.targetObject.matrixWorldNeedsUpdate = true;
  26206. }], [// HasToFromArray
  26207. function setValue_fromArray(buffer, offset) {
  26208. this.resolvedProperty.fromArray(buffer, offset);
  26209. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26210. this.resolvedProperty.fromArray(buffer, offset);
  26211. this.targetObject.needsUpdate = true;
  26212. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26213. this.resolvedProperty.fromArray(buffer, offset);
  26214. this.targetObject.matrixWorldNeedsUpdate = true;
  26215. }]],
  26216. getValue: function getValue_unbound(targetArray, offset) {
  26217. this.bind();
  26218. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26219. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26220. // prototype version of these methods with one that represents
  26221. // the bound state. When the property is not found, the methods
  26222. // become no-ops.
  26223. },
  26224. setValue: function getValue_unbound(sourceArray, offset) {
  26225. this.bind();
  26226. this.setValue(sourceArray, offset);
  26227. },
  26228. // create getter / setter pair for a property in the scene graph
  26229. bind: function bind() {
  26230. var targetObject = this.node;
  26231. var parsedPath = this.parsedPath;
  26232. var objectName = parsedPath.objectName;
  26233. var propertyName = parsedPath.propertyName;
  26234. var propertyIndex = parsedPath.propertyIndex;
  26235. if (!targetObject) {
  26236. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26237. this.node = targetObject;
  26238. } // set fail state so we can just 'return' on error
  26239. this.getValue = this._getValue_unavailable;
  26240. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26241. if (!targetObject) {
  26242. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26243. return;
  26244. }
  26245. if (objectName) {
  26246. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26247. switch (objectName) {
  26248. case 'materials':
  26249. if (!targetObject.material) {
  26250. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26251. return;
  26252. }
  26253. if (!targetObject.material.materials) {
  26254. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26255. return;
  26256. }
  26257. targetObject = targetObject.material.materials;
  26258. break;
  26259. case 'bones':
  26260. if (!targetObject.skeleton) {
  26261. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26262. return;
  26263. } // potential future optimization: skip this if propertyIndex is already an integer
  26264. // and convert the integer string to a true integer.
  26265. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26266. for (var i = 0; i < targetObject.length; i++) {
  26267. if (targetObject[i].name === objectIndex) {
  26268. objectIndex = i;
  26269. break;
  26270. }
  26271. }
  26272. break;
  26273. default:
  26274. if (targetObject[objectName] === undefined) {
  26275. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26276. return;
  26277. }
  26278. targetObject = targetObject[objectName];
  26279. }
  26280. if (objectIndex !== undefined) {
  26281. if (targetObject[objectIndex] === undefined) {
  26282. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26283. return;
  26284. }
  26285. targetObject = targetObject[objectIndex];
  26286. }
  26287. } // resolve property
  26288. var nodeProperty = targetObject[propertyName];
  26289. if (nodeProperty === undefined) {
  26290. var nodeName = parsedPath.nodeName;
  26291. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26292. return;
  26293. } // determine versioning scheme
  26294. var versioning = this.Versioning.None;
  26295. this.targetObject = targetObject;
  26296. if (targetObject.needsUpdate !== undefined) {
  26297. // material
  26298. versioning = this.Versioning.NeedsUpdate;
  26299. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26300. // node transform
  26301. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26302. } // determine how the property gets bound
  26303. var bindingType = this.BindingType.Direct;
  26304. if (propertyIndex !== undefined) {
  26305. // access a sub element of the property array (only primitives are supported right now)
  26306. if (propertyName === 'morphTargetInfluences') {
  26307. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26308. // support resolving morphTarget names into indices.
  26309. if (!targetObject.geometry) {
  26310. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26311. return;
  26312. }
  26313. if (targetObject.geometry.isBufferGeometry) {
  26314. if (!targetObject.geometry.morphAttributes) {
  26315. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26316. return;
  26317. }
  26318. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26319. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26320. }
  26321. } else {
  26322. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26323. return;
  26324. }
  26325. }
  26326. bindingType = this.BindingType.ArrayElement;
  26327. this.resolvedProperty = nodeProperty;
  26328. this.propertyIndex = propertyIndex;
  26329. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26330. // must use copy for Object3D.Euler/Quaternion
  26331. bindingType = this.BindingType.HasFromToArray;
  26332. this.resolvedProperty = nodeProperty;
  26333. } else if (Array.isArray(nodeProperty)) {
  26334. bindingType = this.BindingType.EntireArray;
  26335. this.resolvedProperty = nodeProperty;
  26336. } else {
  26337. this.propertyName = propertyName;
  26338. } // select getter / setter
  26339. this.getValue = this.GetterByBindingType[bindingType];
  26340. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26341. },
  26342. unbind: function unbind() {
  26343. this.node = null; // back to the prototype version of getValue / setValue
  26344. // note: avoiding to mutate the shape of 'this' via 'delete'
  26345. this.getValue = this._getValue_unbound;
  26346. this.setValue = this._setValue_unbound;
  26347. }
  26348. }); // DECLARE ALIAS AFTER assign prototype
  26349. Object.assign(PropertyBinding.prototype, {
  26350. // initial state of these methods that calls 'bind'
  26351. _getValue_unbound: PropertyBinding.prototype.getValue,
  26352. _setValue_unbound: PropertyBinding.prototype.setValue
  26353. });
  26354. /**
  26355. *
  26356. * A group of objects that receives a shared animation state.
  26357. *
  26358. * Usage:
  26359. *
  26360. * - Add objects you would otherwise pass as 'root' to the
  26361. * constructor or the .clipAction method of AnimationMixer.
  26362. *
  26363. * - Instead pass this object as 'root'.
  26364. *
  26365. * - You can also add and remove objects later when the mixer
  26366. * is running.
  26367. *
  26368. * Note:
  26369. *
  26370. * Objects of this class appear as one object to the mixer,
  26371. * so cache control of the individual objects must be done
  26372. * on the group.
  26373. *
  26374. * Limitation:
  26375. *
  26376. * - The animated properties must be compatible among the
  26377. * all objects in the group.
  26378. *
  26379. * - A single property can either be controlled through a
  26380. * target group or directly, but not both.
  26381. */
  26382. function AnimationObjectGroup() {
  26383. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26384. this._objects = Array.prototype.slice.call(arguments);
  26385. this.nCachedObjects_ = 0; // threshold
  26386. // note: read by PropertyBinding.Composite
  26387. var indices = {};
  26388. this._indicesByUUID = indices; // for bookkeeping
  26389. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26390. indices[arguments[i].uuid] = i;
  26391. }
  26392. this._paths = []; // inside: string
  26393. this._parsedPaths = []; // inside: { we don't care, here }
  26394. this._bindings = []; // inside: Array< PropertyBinding >
  26395. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26396. var scope = this;
  26397. this.stats = {
  26398. objects: {
  26399. get total() {
  26400. return scope._objects.length;
  26401. },
  26402. get inUse() {
  26403. return this.total - scope.nCachedObjects_;
  26404. }
  26405. },
  26406. get bindingsPerObject() {
  26407. return scope._bindings.length;
  26408. }
  26409. };
  26410. }
  26411. Object.assign(AnimationObjectGroup.prototype, {
  26412. isAnimationObjectGroup: true,
  26413. add: function add() {
  26414. var objects = this._objects,
  26415. indicesByUUID = this._indicesByUUID,
  26416. paths = this._paths,
  26417. parsedPaths = this._parsedPaths,
  26418. bindings = this._bindings,
  26419. nBindings = bindings.length;
  26420. var knownObject = undefined,
  26421. nObjects = objects.length,
  26422. nCachedObjects = this.nCachedObjects_;
  26423. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26424. var object = arguments[i],
  26425. uuid = object.uuid;
  26426. var index = indicesByUUID[uuid];
  26427. if (index === undefined) {
  26428. // unknown object -> add it to the ACTIVE region
  26429. index = nObjects++;
  26430. indicesByUUID[uuid] = index;
  26431. objects.push(object); // accounting is done, now do the same for all bindings
  26432. for (var j = 0, m = nBindings; j !== m; ++j) {
  26433. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26434. }
  26435. } else if (index < nCachedObjects) {
  26436. knownObject = objects[index]; // move existing object to the ACTIVE region
  26437. var firstActiveIndex = --nCachedObjects,
  26438. lastCachedObject = objects[firstActiveIndex];
  26439. indicesByUUID[lastCachedObject.uuid] = index;
  26440. objects[index] = lastCachedObject;
  26441. indicesByUUID[uuid] = firstActiveIndex;
  26442. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26443. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26444. var bindingsForPath = bindings[_j],
  26445. lastCached = bindingsForPath[firstActiveIndex];
  26446. var binding = bindingsForPath[index];
  26447. bindingsForPath[index] = lastCached;
  26448. if (binding === undefined) {
  26449. // since we do not bother to create new bindings
  26450. // for objects that are cached, the binding may
  26451. // or may not exist
  26452. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26453. }
  26454. bindingsForPath[firstActiveIndex] = binding;
  26455. }
  26456. } else if (objects[index] !== knownObject) {
  26457. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26458. } // else the object is already where we want it to be
  26459. } // for arguments
  26460. this.nCachedObjects_ = nCachedObjects;
  26461. },
  26462. remove: function remove() {
  26463. var objects = this._objects,
  26464. indicesByUUID = this._indicesByUUID,
  26465. bindings = this._bindings,
  26466. nBindings = bindings.length;
  26467. var nCachedObjects = this.nCachedObjects_;
  26468. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26469. var object = arguments[i],
  26470. uuid = object.uuid,
  26471. index = indicesByUUID[uuid];
  26472. if (index !== undefined && index >= nCachedObjects) {
  26473. // move existing object into the CACHED region
  26474. var lastCachedIndex = nCachedObjects++,
  26475. firstActiveObject = objects[lastCachedIndex];
  26476. indicesByUUID[firstActiveObject.uuid] = index;
  26477. objects[index] = firstActiveObject;
  26478. indicesByUUID[uuid] = lastCachedIndex;
  26479. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26480. for (var j = 0, m = nBindings; j !== m; ++j) {
  26481. var bindingsForPath = bindings[j],
  26482. firstActive = bindingsForPath[lastCachedIndex],
  26483. binding = bindingsForPath[index];
  26484. bindingsForPath[index] = firstActive;
  26485. bindingsForPath[lastCachedIndex] = binding;
  26486. }
  26487. }
  26488. } // for arguments
  26489. this.nCachedObjects_ = nCachedObjects;
  26490. },
  26491. // remove & forget
  26492. uncache: function uncache() {
  26493. var objects = this._objects,
  26494. indicesByUUID = this._indicesByUUID,
  26495. bindings = this._bindings,
  26496. nBindings = bindings.length;
  26497. var nCachedObjects = this.nCachedObjects_,
  26498. nObjects = objects.length;
  26499. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26500. var object = arguments[i],
  26501. uuid = object.uuid,
  26502. index = indicesByUUID[uuid];
  26503. if (index !== undefined) {
  26504. delete indicesByUUID[uuid];
  26505. if (index < nCachedObjects) {
  26506. // object is cached, shrink the CACHED region
  26507. var firstActiveIndex = --nCachedObjects,
  26508. lastCachedObject = objects[firstActiveIndex],
  26509. lastIndex = --nObjects,
  26510. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26511. indicesByUUID[lastCachedObject.uuid] = index;
  26512. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26513. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26514. objects[firstActiveIndex] = lastObject;
  26515. objects.pop(); // accounting is done, now do the same for all bindings
  26516. for (var j = 0, m = nBindings; j !== m; ++j) {
  26517. var bindingsForPath = bindings[j],
  26518. lastCached = bindingsForPath[firstActiveIndex],
  26519. last = bindingsForPath[lastIndex];
  26520. bindingsForPath[index] = lastCached;
  26521. bindingsForPath[firstActiveIndex] = last;
  26522. bindingsForPath.pop();
  26523. }
  26524. } else {
  26525. // object is active, just swap with the last and pop
  26526. var _lastIndex = --nObjects,
  26527. _lastObject = objects[_lastIndex];
  26528. if (_lastIndex > 0) {
  26529. indicesByUUID[_lastObject.uuid] = index;
  26530. }
  26531. objects[index] = _lastObject;
  26532. objects.pop(); // accounting is done, now do the same for all bindings
  26533. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26534. var _bindingsForPath = bindings[_j2];
  26535. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26536. _bindingsForPath.pop();
  26537. }
  26538. } // cached or active
  26539. } // if object is known
  26540. } // for arguments
  26541. this.nCachedObjects_ = nCachedObjects;
  26542. },
  26543. // Internal interface used by befriended PropertyBinding.Composite:
  26544. subscribe_: function subscribe_(path, parsedPath) {
  26545. // returns an array of bindings for the given path that is changed
  26546. // according to the contained objects in the group
  26547. var indicesByPath = this._bindingsIndicesByPath;
  26548. var index = indicesByPath[path];
  26549. var bindings = this._bindings;
  26550. if (index !== undefined) return bindings[index];
  26551. var paths = this._paths,
  26552. parsedPaths = this._parsedPaths,
  26553. objects = this._objects,
  26554. nObjects = objects.length,
  26555. nCachedObjects = this.nCachedObjects_,
  26556. bindingsForPath = new Array(nObjects);
  26557. index = bindings.length;
  26558. indicesByPath[path] = index;
  26559. paths.push(path);
  26560. parsedPaths.push(parsedPath);
  26561. bindings.push(bindingsForPath);
  26562. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26563. var object = objects[i];
  26564. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26565. }
  26566. return bindingsForPath;
  26567. },
  26568. unsubscribe_: function unsubscribe_(path) {
  26569. // tells the group to forget about a property path and no longer
  26570. // update the array previously obtained with 'subscribe_'
  26571. var indicesByPath = this._bindingsIndicesByPath,
  26572. index = indicesByPath[path];
  26573. if (index !== undefined) {
  26574. var paths = this._paths,
  26575. parsedPaths = this._parsedPaths,
  26576. bindings = this._bindings,
  26577. lastBindingsIndex = bindings.length - 1,
  26578. lastBindings = bindings[lastBindingsIndex],
  26579. lastBindingsPath = path[lastBindingsIndex];
  26580. indicesByPath[lastBindingsPath] = index;
  26581. bindings[index] = lastBindings;
  26582. bindings.pop();
  26583. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26584. parsedPaths.pop();
  26585. paths[index] = paths[lastBindingsIndex];
  26586. paths.pop();
  26587. }
  26588. }
  26589. });
  26590. var AnimationAction = /*#__PURE__*/function () {
  26591. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26592. if (localRoot === void 0) {
  26593. localRoot = null;
  26594. }
  26595. if (blendMode === void 0) {
  26596. blendMode = clip.blendMode;
  26597. }
  26598. this._mixer = mixer;
  26599. this._clip = clip;
  26600. this._localRoot = localRoot;
  26601. this.blendMode = blendMode;
  26602. var tracks = clip.tracks,
  26603. nTracks = tracks.length,
  26604. interpolants = new Array(nTracks);
  26605. var interpolantSettings = {
  26606. endingStart: ZeroCurvatureEnding,
  26607. endingEnd: ZeroCurvatureEnding
  26608. };
  26609. for (var i = 0; i !== nTracks; ++i) {
  26610. var interpolant = tracks[i].createInterpolant(null);
  26611. interpolants[i] = interpolant;
  26612. interpolant.settings = interpolantSettings;
  26613. }
  26614. this._interpolantSettings = interpolantSettings;
  26615. this._interpolants = interpolants; // bound by the mixer
  26616. // inside: PropertyMixer (managed by the mixer)
  26617. this._propertyBindings = new Array(nTracks);
  26618. this._cacheIndex = null; // for the memory manager
  26619. this._byClipCacheIndex = null; // for the memory manager
  26620. this._timeScaleInterpolant = null;
  26621. this._weightInterpolant = null;
  26622. this.loop = LoopRepeat;
  26623. this._loopCount = -1; // global mixer time when the action is to be started
  26624. // it's set back to 'null' upon start of the action
  26625. this._startTime = null; // scaled local time of the action
  26626. // gets clamped or wrapped to 0..clip.duration according to loop
  26627. this.time = 0;
  26628. this.timeScale = 1;
  26629. this._effectiveTimeScale = 1;
  26630. this.weight = 1;
  26631. this._effectiveWeight = 1;
  26632. this.repetitions = Infinity; // no. of repetitions when looping
  26633. this.paused = false; // true -> zero effective time scale
  26634. this.enabled = true; // false -> zero effective weight
  26635. this.clampWhenFinished = false; // keep feeding the last frame?
  26636. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26637. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26638. } // State & Scheduling
  26639. var _proto = AnimationAction.prototype;
  26640. _proto.play = function play() {
  26641. this._mixer._activateAction(this);
  26642. return this;
  26643. };
  26644. _proto.stop = function stop() {
  26645. this._mixer._deactivateAction(this);
  26646. return this.reset();
  26647. };
  26648. _proto.reset = function reset() {
  26649. this.paused = false;
  26650. this.enabled = true;
  26651. this.time = 0; // restart clip
  26652. this._loopCount = -1; // forget previous loops
  26653. this._startTime = null; // forget scheduling
  26654. return this.stopFading().stopWarping();
  26655. };
  26656. _proto.isRunning = function isRunning() {
  26657. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26658. } // return true when play has been called
  26659. ;
  26660. _proto.isScheduled = function isScheduled() {
  26661. return this._mixer._isActiveAction(this);
  26662. };
  26663. _proto.startAt = function startAt(time) {
  26664. this._startTime = time;
  26665. return this;
  26666. };
  26667. _proto.setLoop = function setLoop(mode, repetitions) {
  26668. this.loop = mode;
  26669. this.repetitions = repetitions;
  26670. return this;
  26671. } // Weight
  26672. // set the weight stopping any scheduled fading
  26673. // although .enabled = false yields an effective weight of zero, this
  26674. // method does *not* change .enabled, because it would be confusing
  26675. ;
  26676. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26677. this.weight = weight; // note: same logic as when updated at runtime
  26678. this._effectiveWeight = this.enabled ? weight : 0;
  26679. return this.stopFading();
  26680. } // return the weight considering fading and .enabled
  26681. ;
  26682. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26683. return this._effectiveWeight;
  26684. };
  26685. _proto.fadeIn = function fadeIn(duration) {
  26686. return this._scheduleFading(duration, 0, 1);
  26687. };
  26688. _proto.fadeOut = function fadeOut(duration) {
  26689. return this._scheduleFading(duration, 1, 0);
  26690. };
  26691. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26692. fadeOutAction.fadeOut(duration);
  26693. this.fadeIn(duration);
  26694. if (warp) {
  26695. var fadeInDuration = this._clip.duration,
  26696. fadeOutDuration = fadeOutAction._clip.duration,
  26697. startEndRatio = fadeOutDuration / fadeInDuration,
  26698. endStartRatio = fadeInDuration / fadeOutDuration;
  26699. fadeOutAction.warp(1.0, startEndRatio, duration);
  26700. this.warp(endStartRatio, 1.0, duration);
  26701. }
  26702. return this;
  26703. };
  26704. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26705. return fadeInAction.crossFadeFrom(this, duration, warp);
  26706. };
  26707. _proto.stopFading = function stopFading() {
  26708. var weightInterpolant = this._weightInterpolant;
  26709. if (weightInterpolant !== null) {
  26710. this._weightInterpolant = null;
  26711. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26712. }
  26713. return this;
  26714. } // Time Scale Control
  26715. // set the time scale stopping any scheduled warping
  26716. // although .paused = true yields an effective time scale of zero, this
  26717. // method does *not* change .paused, because it would be confusing
  26718. ;
  26719. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26720. this.timeScale = timeScale;
  26721. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26722. return this.stopWarping();
  26723. } // return the time scale considering warping and .paused
  26724. ;
  26725. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26726. return this._effectiveTimeScale;
  26727. };
  26728. _proto.setDuration = function setDuration(duration) {
  26729. this.timeScale = this._clip.duration / duration;
  26730. return this.stopWarping();
  26731. };
  26732. _proto.syncWith = function syncWith(action) {
  26733. this.time = action.time;
  26734. this.timeScale = action.timeScale;
  26735. return this.stopWarping();
  26736. };
  26737. _proto.halt = function halt(duration) {
  26738. return this.warp(this._effectiveTimeScale, 0, duration);
  26739. };
  26740. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26741. var mixer = this._mixer,
  26742. now = mixer.time,
  26743. timeScale = this.timeScale;
  26744. var interpolant = this._timeScaleInterpolant;
  26745. if (interpolant === null) {
  26746. interpolant = mixer._lendControlInterpolant();
  26747. this._timeScaleInterpolant = interpolant;
  26748. }
  26749. var times = interpolant.parameterPositions,
  26750. values = interpolant.sampleValues;
  26751. times[0] = now;
  26752. times[1] = now + duration;
  26753. values[0] = startTimeScale / timeScale;
  26754. values[1] = endTimeScale / timeScale;
  26755. return this;
  26756. };
  26757. _proto.stopWarping = function stopWarping() {
  26758. var timeScaleInterpolant = this._timeScaleInterpolant;
  26759. if (timeScaleInterpolant !== null) {
  26760. this._timeScaleInterpolant = null;
  26761. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26762. }
  26763. return this;
  26764. } // Object Accessors
  26765. ;
  26766. _proto.getMixer = function getMixer() {
  26767. return this._mixer;
  26768. };
  26769. _proto.getClip = function getClip() {
  26770. return this._clip;
  26771. };
  26772. _proto.getRoot = function getRoot() {
  26773. return this._localRoot || this._mixer._root;
  26774. } // Interna
  26775. ;
  26776. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26777. // called by the mixer
  26778. if (!this.enabled) {
  26779. // call ._updateWeight() to update ._effectiveWeight
  26780. this._updateWeight(time);
  26781. return;
  26782. }
  26783. var startTime = this._startTime;
  26784. if (startTime !== null) {
  26785. // check for scheduled start of action
  26786. var timeRunning = (time - startTime) * timeDirection;
  26787. if (timeRunning < 0 || timeDirection === 0) {
  26788. return; // yet to come / don't decide when delta = 0
  26789. } // start
  26790. this._startTime = null; // unschedule
  26791. deltaTime = timeDirection * timeRunning;
  26792. } // apply time scale and advance time
  26793. deltaTime *= this._updateTimeScale(time);
  26794. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26795. // an effective weight of 0
  26796. var weight = this._updateWeight(time);
  26797. if (weight > 0) {
  26798. var _interpolants = this._interpolants;
  26799. var propertyMixers = this._propertyBindings;
  26800. switch (this.blendMode) {
  26801. case AdditiveAnimationBlendMode:
  26802. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26803. _interpolants[j].evaluate(clipTime);
  26804. propertyMixers[j].accumulateAdditive(weight);
  26805. }
  26806. break;
  26807. case NormalAnimationBlendMode:
  26808. default:
  26809. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26810. _interpolants[_j].evaluate(clipTime);
  26811. propertyMixers[_j].accumulate(accuIndex, weight);
  26812. }
  26813. }
  26814. }
  26815. };
  26816. _proto._updateWeight = function _updateWeight(time) {
  26817. var weight = 0;
  26818. if (this.enabled) {
  26819. weight = this.weight;
  26820. var interpolant = this._weightInterpolant;
  26821. if (interpolant !== null) {
  26822. var interpolantValue = interpolant.evaluate(time)[0];
  26823. weight *= interpolantValue;
  26824. if (time > interpolant.parameterPositions[1]) {
  26825. this.stopFading();
  26826. if (interpolantValue === 0) {
  26827. // faded out, disable
  26828. this.enabled = false;
  26829. }
  26830. }
  26831. }
  26832. }
  26833. this._effectiveWeight = weight;
  26834. return weight;
  26835. };
  26836. _proto._updateTimeScale = function _updateTimeScale(time) {
  26837. var timeScale = 0;
  26838. if (!this.paused) {
  26839. timeScale = this.timeScale;
  26840. var interpolant = this._timeScaleInterpolant;
  26841. if (interpolant !== null) {
  26842. var interpolantValue = interpolant.evaluate(time)[0];
  26843. timeScale *= interpolantValue;
  26844. if (time > interpolant.parameterPositions[1]) {
  26845. this.stopWarping();
  26846. if (timeScale === 0) {
  26847. // motion has halted, pause
  26848. this.paused = true;
  26849. } else {
  26850. // warp done - apply final time scale
  26851. this.timeScale = timeScale;
  26852. }
  26853. }
  26854. }
  26855. }
  26856. this._effectiveTimeScale = timeScale;
  26857. return timeScale;
  26858. };
  26859. _proto._updateTime = function _updateTime(deltaTime) {
  26860. var duration = this._clip.duration;
  26861. var loop = this.loop;
  26862. var time = this.time + deltaTime;
  26863. var loopCount = this._loopCount;
  26864. var pingPong = loop === LoopPingPong;
  26865. if (deltaTime === 0) {
  26866. if (loopCount === -1) return time;
  26867. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26868. }
  26869. if (loop === LoopOnce) {
  26870. if (loopCount === -1) {
  26871. // just started
  26872. this._loopCount = 0;
  26873. this._setEndings(true, true, false);
  26874. }
  26875. handle_stop: {
  26876. if (time >= duration) {
  26877. time = duration;
  26878. } else if (time < 0) {
  26879. time = 0;
  26880. } else {
  26881. this.time = time;
  26882. break handle_stop;
  26883. }
  26884. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26885. this.time = time;
  26886. this._mixer.dispatchEvent({
  26887. type: 'finished',
  26888. action: this,
  26889. direction: deltaTime < 0 ? -1 : 1
  26890. });
  26891. }
  26892. } else {
  26893. // repetitive Repeat or PingPong
  26894. if (loopCount === -1) {
  26895. // just started
  26896. if (deltaTime >= 0) {
  26897. loopCount = 0;
  26898. this._setEndings(true, this.repetitions === 0, pingPong);
  26899. } else {
  26900. // when looping in reverse direction, the initial
  26901. // transition through zero counts as a repetition,
  26902. // so leave loopCount at -1
  26903. this._setEndings(this.repetitions === 0, true, pingPong);
  26904. }
  26905. }
  26906. if (time >= duration || time < 0) {
  26907. // wrap around
  26908. var loopDelta = Math.floor(time / duration); // signed
  26909. time -= duration * loopDelta;
  26910. loopCount += Math.abs(loopDelta);
  26911. var pending = this.repetitions - loopCount;
  26912. if (pending <= 0) {
  26913. // have to stop (switch state, clamp time, fire event)
  26914. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26915. time = deltaTime > 0 ? duration : 0;
  26916. this.time = time;
  26917. this._mixer.dispatchEvent({
  26918. type: 'finished',
  26919. action: this,
  26920. direction: deltaTime > 0 ? 1 : -1
  26921. });
  26922. } else {
  26923. // keep running
  26924. if (pending === 1) {
  26925. // entering the last round
  26926. var atStart = deltaTime < 0;
  26927. this._setEndings(atStart, !atStart, pingPong);
  26928. } else {
  26929. this._setEndings(false, false, pingPong);
  26930. }
  26931. this._loopCount = loopCount;
  26932. this.time = time;
  26933. this._mixer.dispatchEvent({
  26934. type: 'loop',
  26935. action: this,
  26936. loopDelta: loopDelta
  26937. });
  26938. }
  26939. } else {
  26940. this.time = time;
  26941. }
  26942. if (pingPong && (loopCount & 1) === 1) {
  26943. // invert time for the "pong round"
  26944. return duration - time;
  26945. }
  26946. }
  26947. return time;
  26948. };
  26949. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26950. var settings = this._interpolantSettings;
  26951. if (pingPong) {
  26952. settings.endingStart = ZeroSlopeEnding;
  26953. settings.endingEnd = ZeroSlopeEnding;
  26954. } else {
  26955. // assuming for LoopOnce atStart == atEnd == true
  26956. if (atStart) {
  26957. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26958. } else {
  26959. settings.endingStart = WrapAroundEnding;
  26960. }
  26961. if (atEnd) {
  26962. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26963. } else {
  26964. settings.endingEnd = WrapAroundEnding;
  26965. }
  26966. }
  26967. };
  26968. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26969. var mixer = this._mixer,
  26970. now = mixer.time;
  26971. var interpolant = this._weightInterpolant;
  26972. if (interpolant === null) {
  26973. interpolant = mixer._lendControlInterpolant();
  26974. this._weightInterpolant = interpolant;
  26975. }
  26976. var times = interpolant.parameterPositions,
  26977. values = interpolant.sampleValues;
  26978. times[0] = now;
  26979. values[0] = weightNow;
  26980. times[1] = now + duration;
  26981. values[1] = weightThen;
  26982. return this;
  26983. };
  26984. return AnimationAction;
  26985. }();
  26986. function AnimationMixer(root) {
  26987. this._root = root;
  26988. this._initMemoryManager();
  26989. this._accuIndex = 0;
  26990. this.time = 0;
  26991. this.timeScale = 1.0;
  26992. }
  26993. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26994. constructor: AnimationMixer,
  26995. _bindAction: function _bindAction(action, prototypeAction) {
  26996. var root = action._localRoot || this._root,
  26997. tracks = action._clip.tracks,
  26998. nTracks = tracks.length,
  26999. bindings = action._propertyBindings,
  27000. interpolants = action._interpolants,
  27001. rootUuid = root.uuid,
  27002. bindingsByRoot = this._bindingsByRootAndName;
  27003. var bindingsByName = bindingsByRoot[rootUuid];
  27004. if (bindingsByName === undefined) {
  27005. bindingsByName = {};
  27006. bindingsByRoot[rootUuid] = bindingsByName;
  27007. }
  27008. for (var i = 0; i !== nTracks; ++i) {
  27009. var track = tracks[i],
  27010. trackName = track.name;
  27011. var binding = bindingsByName[trackName];
  27012. if (binding !== undefined) {
  27013. bindings[i] = binding;
  27014. } else {
  27015. binding = bindings[i];
  27016. if (binding !== undefined) {
  27017. // existing binding, make sure the cache knows
  27018. if (binding._cacheIndex === null) {
  27019. ++binding.referenceCount;
  27020. this._addInactiveBinding(binding, rootUuid, trackName);
  27021. }
  27022. continue;
  27023. }
  27024. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  27025. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  27026. ++binding.referenceCount;
  27027. this._addInactiveBinding(binding, rootUuid, trackName);
  27028. bindings[i] = binding;
  27029. }
  27030. interpolants[i].resultBuffer = binding.buffer;
  27031. }
  27032. },
  27033. _activateAction: function _activateAction(action) {
  27034. if (!this._isActiveAction(action)) {
  27035. if (action._cacheIndex === null) {
  27036. // this action has been forgotten by the cache, but the user
  27037. // appears to be still using it -> rebind
  27038. var rootUuid = (action._localRoot || this._root).uuid,
  27039. clipUuid = action._clip.uuid,
  27040. actionsForClip = this._actionsByClip[clipUuid];
  27041. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  27042. this._addInactiveAction(action, clipUuid, rootUuid);
  27043. }
  27044. var bindings = action._propertyBindings; // increment reference counts / sort out state
  27045. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27046. var binding = bindings[i];
  27047. if (binding.useCount++ === 0) {
  27048. this._lendBinding(binding);
  27049. binding.saveOriginalState();
  27050. }
  27051. }
  27052. this._lendAction(action);
  27053. }
  27054. },
  27055. _deactivateAction: function _deactivateAction(action) {
  27056. if (this._isActiveAction(action)) {
  27057. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  27058. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27059. var binding = bindings[i];
  27060. if (--binding.useCount === 0) {
  27061. binding.restoreOriginalState();
  27062. this._takeBackBinding(binding);
  27063. }
  27064. }
  27065. this._takeBackAction(action);
  27066. }
  27067. },
  27068. // Memory manager
  27069. _initMemoryManager: function _initMemoryManager() {
  27070. this._actions = []; // 'nActiveActions' followed by inactive ones
  27071. this._nActiveActions = 0;
  27072. this._actionsByClip = {}; // inside:
  27073. // {
  27074. // knownActions: Array< AnimationAction > - used as prototypes
  27075. // actionByRoot: AnimationAction - lookup
  27076. // }
  27077. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27078. this._nActiveBindings = 0;
  27079. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27080. this._controlInterpolants = []; // same game as above
  27081. this._nActiveControlInterpolants = 0;
  27082. var scope = this;
  27083. this.stats = {
  27084. actions: {
  27085. get total() {
  27086. return scope._actions.length;
  27087. },
  27088. get inUse() {
  27089. return scope._nActiveActions;
  27090. }
  27091. },
  27092. bindings: {
  27093. get total() {
  27094. return scope._bindings.length;
  27095. },
  27096. get inUse() {
  27097. return scope._nActiveBindings;
  27098. }
  27099. },
  27100. controlInterpolants: {
  27101. get total() {
  27102. return scope._controlInterpolants.length;
  27103. },
  27104. get inUse() {
  27105. return scope._nActiveControlInterpolants;
  27106. }
  27107. }
  27108. };
  27109. },
  27110. // Memory management for AnimationAction objects
  27111. _isActiveAction: function _isActiveAction(action) {
  27112. var index = action._cacheIndex;
  27113. return index !== null && index < this._nActiveActions;
  27114. },
  27115. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  27116. var actions = this._actions,
  27117. actionsByClip = this._actionsByClip;
  27118. var actionsForClip = actionsByClip[clipUuid];
  27119. if (actionsForClip === undefined) {
  27120. actionsForClip = {
  27121. knownActions: [action],
  27122. actionByRoot: {}
  27123. };
  27124. action._byClipCacheIndex = 0;
  27125. actionsByClip[clipUuid] = actionsForClip;
  27126. } else {
  27127. var knownActions = actionsForClip.knownActions;
  27128. action._byClipCacheIndex = knownActions.length;
  27129. knownActions.push(action);
  27130. }
  27131. action._cacheIndex = actions.length;
  27132. actions.push(action);
  27133. actionsForClip.actionByRoot[rootUuid] = action;
  27134. },
  27135. _removeInactiveAction: function _removeInactiveAction(action) {
  27136. var actions = this._actions,
  27137. lastInactiveAction = actions[actions.length - 1],
  27138. cacheIndex = action._cacheIndex;
  27139. lastInactiveAction._cacheIndex = cacheIndex;
  27140. actions[cacheIndex] = lastInactiveAction;
  27141. actions.pop();
  27142. action._cacheIndex = null;
  27143. var clipUuid = action._clip.uuid,
  27144. actionsByClip = this._actionsByClip,
  27145. actionsForClip = actionsByClip[clipUuid],
  27146. knownActionsForClip = actionsForClip.knownActions,
  27147. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27148. byClipCacheIndex = action._byClipCacheIndex;
  27149. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27150. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27151. knownActionsForClip.pop();
  27152. action._byClipCacheIndex = null;
  27153. var actionByRoot = actionsForClip.actionByRoot,
  27154. rootUuid = (action._localRoot || this._root).uuid;
  27155. delete actionByRoot[rootUuid];
  27156. if (knownActionsForClip.length === 0) {
  27157. delete actionsByClip[clipUuid];
  27158. }
  27159. this._removeInactiveBindingsForAction(action);
  27160. },
  27161. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27162. var bindings = action._propertyBindings;
  27163. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27164. var binding = bindings[i];
  27165. if (--binding.referenceCount === 0) {
  27166. this._removeInactiveBinding(binding);
  27167. }
  27168. }
  27169. },
  27170. _lendAction: function _lendAction(action) {
  27171. // [ active actions | inactive actions ]
  27172. // [ active actions >| inactive actions ]
  27173. // s a
  27174. // <-swap->
  27175. // a s
  27176. var actions = this._actions,
  27177. prevIndex = action._cacheIndex,
  27178. lastActiveIndex = this._nActiveActions++,
  27179. firstInactiveAction = actions[lastActiveIndex];
  27180. action._cacheIndex = lastActiveIndex;
  27181. actions[lastActiveIndex] = action;
  27182. firstInactiveAction._cacheIndex = prevIndex;
  27183. actions[prevIndex] = firstInactiveAction;
  27184. },
  27185. _takeBackAction: function _takeBackAction(action) {
  27186. // [ active actions | inactive actions ]
  27187. // [ active actions |< inactive actions ]
  27188. // a s
  27189. // <-swap->
  27190. // s a
  27191. var actions = this._actions,
  27192. prevIndex = action._cacheIndex,
  27193. firstInactiveIndex = --this._nActiveActions,
  27194. lastActiveAction = actions[firstInactiveIndex];
  27195. action._cacheIndex = firstInactiveIndex;
  27196. actions[firstInactiveIndex] = action;
  27197. lastActiveAction._cacheIndex = prevIndex;
  27198. actions[prevIndex] = lastActiveAction;
  27199. },
  27200. // Memory management for PropertyMixer objects
  27201. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27202. var bindingsByRoot = this._bindingsByRootAndName,
  27203. bindings = this._bindings;
  27204. var bindingByName = bindingsByRoot[rootUuid];
  27205. if (bindingByName === undefined) {
  27206. bindingByName = {};
  27207. bindingsByRoot[rootUuid] = bindingByName;
  27208. }
  27209. bindingByName[trackName] = binding;
  27210. binding._cacheIndex = bindings.length;
  27211. bindings.push(binding);
  27212. },
  27213. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27214. var bindings = this._bindings,
  27215. propBinding = binding.binding,
  27216. rootUuid = propBinding.rootNode.uuid,
  27217. trackName = propBinding.path,
  27218. bindingsByRoot = this._bindingsByRootAndName,
  27219. bindingByName = bindingsByRoot[rootUuid],
  27220. lastInactiveBinding = bindings[bindings.length - 1],
  27221. cacheIndex = binding._cacheIndex;
  27222. lastInactiveBinding._cacheIndex = cacheIndex;
  27223. bindings[cacheIndex] = lastInactiveBinding;
  27224. bindings.pop();
  27225. delete bindingByName[trackName];
  27226. if (Object.keys(bindingByName).length === 0) {
  27227. delete bindingsByRoot[rootUuid];
  27228. }
  27229. },
  27230. _lendBinding: function _lendBinding(binding) {
  27231. var bindings = this._bindings,
  27232. prevIndex = binding._cacheIndex,
  27233. lastActiveIndex = this._nActiveBindings++,
  27234. firstInactiveBinding = bindings[lastActiveIndex];
  27235. binding._cacheIndex = lastActiveIndex;
  27236. bindings[lastActiveIndex] = binding;
  27237. firstInactiveBinding._cacheIndex = prevIndex;
  27238. bindings[prevIndex] = firstInactiveBinding;
  27239. },
  27240. _takeBackBinding: function _takeBackBinding(binding) {
  27241. var bindings = this._bindings,
  27242. prevIndex = binding._cacheIndex,
  27243. firstInactiveIndex = --this._nActiveBindings,
  27244. lastActiveBinding = bindings[firstInactiveIndex];
  27245. binding._cacheIndex = firstInactiveIndex;
  27246. bindings[firstInactiveIndex] = binding;
  27247. lastActiveBinding._cacheIndex = prevIndex;
  27248. bindings[prevIndex] = lastActiveBinding;
  27249. },
  27250. // Memory management of Interpolants for weight and time scale
  27251. _lendControlInterpolant: function _lendControlInterpolant() {
  27252. var interpolants = this._controlInterpolants,
  27253. lastActiveIndex = this._nActiveControlInterpolants++;
  27254. var interpolant = interpolants[lastActiveIndex];
  27255. if (interpolant === undefined) {
  27256. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27257. interpolant.__cacheIndex = lastActiveIndex;
  27258. interpolants[lastActiveIndex] = interpolant;
  27259. }
  27260. return interpolant;
  27261. },
  27262. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27263. var interpolants = this._controlInterpolants,
  27264. prevIndex = interpolant.__cacheIndex,
  27265. firstInactiveIndex = --this._nActiveControlInterpolants,
  27266. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27267. interpolant.__cacheIndex = firstInactiveIndex;
  27268. interpolants[firstInactiveIndex] = interpolant;
  27269. lastActiveInterpolant.__cacheIndex = prevIndex;
  27270. interpolants[prevIndex] = lastActiveInterpolant;
  27271. },
  27272. _controlInterpolantsResultBuffer: new Float32Array(1),
  27273. // return an action for a clip optionally using a custom root target
  27274. // object (this method allocates a lot of dynamic memory in case a
  27275. // previously unknown clip/root combination is specified)
  27276. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27277. var root = optionalRoot || this._root,
  27278. rootUuid = root.uuid;
  27279. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27280. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27281. var actionsForClip = this._actionsByClip[clipUuid];
  27282. var prototypeAction = null;
  27283. if (blendMode === undefined) {
  27284. if (clipObject !== null) {
  27285. blendMode = clipObject.blendMode;
  27286. } else {
  27287. blendMode = NormalAnimationBlendMode;
  27288. }
  27289. }
  27290. if (actionsForClip !== undefined) {
  27291. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27292. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27293. return existingAction;
  27294. } // we know the clip, so we don't have to parse all
  27295. // the bindings again but can just copy
  27296. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27297. if (clipObject === null) clipObject = prototypeAction._clip;
  27298. } // clip must be known when specified via string
  27299. if (clipObject === null) return null; // allocate all resources required to run it
  27300. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27301. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27302. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27303. return newAction;
  27304. },
  27305. // get an existing action
  27306. existingAction: function existingAction(clip, optionalRoot) {
  27307. var root = optionalRoot || this._root,
  27308. rootUuid = root.uuid,
  27309. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27310. clipUuid = clipObject ? clipObject.uuid : clip,
  27311. actionsForClip = this._actionsByClip[clipUuid];
  27312. if (actionsForClip !== undefined) {
  27313. return actionsForClip.actionByRoot[rootUuid] || null;
  27314. }
  27315. return null;
  27316. },
  27317. // deactivates all previously scheduled actions
  27318. stopAllAction: function stopAllAction() {
  27319. var actions = this._actions,
  27320. nActions = this._nActiveActions;
  27321. for (var i = nActions - 1; i >= 0; --i) {
  27322. actions[i].stop();
  27323. }
  27324. return this;
  27325. },
  27326. // advance the time and update apply the animation
  27327. update: function update(deltaTime) {
  27328. deltaTime *= this.timeScale;
  27329. var actions = this._actions,
  27330. nActions = this._nActiveActions,
  27331. time = this.time += deltaTime,
  27332. timeDirection = Math.sign(deltaTime),
  27333. accuIndex = this._accuIndex ^= 1; // run active actions
  27334. for (var i = 0; i !== nActions; ++i) {
  27335. var action = actions[i];
  27336. action._update(time, deltaTime, timeDirection, accuIndex);
  27337. } // update scene graph
  27338. var bindings = this._bindings,
  27339. nBindings = this._nActiveBindings;
  27340. for (var _i = 0; _i !== nBindings; ++_i) {
  27341. bindings[_i].apply(accuIndex);
  27342. }
  27343. return this;
  27344. },
  27345. // Allows you to seek to a specific time in an animation.
  27346. setTime: function setTime(timeInSeconds) {
  27347. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27348. for (var i = 0; i < this._actions.length; i++) {
  27349. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27350. }
  27351. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27352. },
  27353. // return this mixer's root target object
  27354. getRoot: function getRoot() {
  27355. return this._root;
  27356. },
  27357. // free all resources specific to a particular clip
  27358. uncacheClip: function uncacheClip(clip) {
  27359. var actions = this._actions,
  27360. clipUuid = clip.uuid,
  27361. actionsByClip = this._actionsByClip,
  27362. actionsForClip = actionsByClip[clipUuid];
  27363. if (actionsForClip !== undefined) {
  27364. // note: just calling _removeInactiveAction would mess up the
  27365. // iteration state and also require updating the state we can
  27366. // just throw away
  27367. var actionsToRemove = actionsForClip.knownActions;
  27368. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27369. var action = actionsToRemove[i];
  27370. this._deactivateAction(action);
  27371. var cacheIndex = action._cacheIndex,
  27372. lastInactiveAction = actions[actions.length - 1];
  27373. action._cacheIndex = null;
  27374. action._byClipCacheIndex = null;
  27375. lastInactiveAction._cacheIndex = cacheIndex;
  27376. actions[cacheIndex] = lastInactiveAction;
  27377. actions.pop();
  27378. this._removeInactiveBindingsForAction(action);
  27379. }
  27380. delete actionsByClip[clipUuid];
  27381. }
  27382. },
  27383. // free all resources specific to a particular root target object
  27384. uncacheRoot: function uncacheRoot(root) {
  27385. var rootUuid = root.uuid,
  27386. actionsByClip = this._actionsByClip;
  27387. for (var clipUuid in actionsByClip) {
  27388. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27389. action = actionByRoot[rootUuid];
  27390. if (action !== undefined) {
  27391. this._deactivateAction(action);
  27392. this._removeInactiveAction(action);
  27393. }
  27394. }
  27395. var bindingsByRoot = this._bindingsByRootAndName,
  27396. bindingByName = bindingsByRoot[rootUuid];
  27397. if (bindingByName !== undefined) {
  27398. for (var trackName in bindingByName) {
  27399. var binding = bindingByName[trackName];
  27400. binding.restoreOriginalState();
  27401. this._removeInactiveBinding(binding);
  27402. }
  27403. }
  27404. },
  27405. // remove a targeted clip from the cache
  27406. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27407. var action = this.existingAction(clip, optionalRoot);
  27408. if (action !== null) {
  27409. this._deactivateAction(action);
  27410. this._removeInactiveAction(action);
  27411. }
  27412. }
  27413. });
  27414. var Uniform = /*#__PURE__*/function () {
  27415. function Uniform(value) {
  27416. if (typeof value === 'string') {
  27417. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27418. value = arguments[1];
  27419. }
  27420. this.value = value;
  27421. }
  27422. var _proto = Uniform.prototype;
  27423. _proto.clone = function clone() {
  27424. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27425. };
  27426. return Uniform;
  27427. }();
  27428. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27429. InterleavedBuffer.call(this, array, stride);
  27430. this.meshPerAttribute = meshPerAttribute || 1;
  27431. }
  27432. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27433. constructor: InstancedInterleavedBuffer,
  27434. isInstancedInterleavedBuffer: true,
  27435. copy: function copy(source) {
  27436. InterleavedBuffer.prototype.copy.call(this, source);
  27437. this.meshPerAttribute = source.meshPerAttribute;
  27438. return this;
  27439. },
  27440. clone: function clone(data) {
  27441. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27442. ib.meshPerAttribute = this.meshPerAttribute;
  27443. return ib;
  27444. },
  27445. toJSON: function toJSON(data) {
  27446. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27447. json.isInstancedInterleavedBuffer = true;
  27448. json.meshPerAttribute = this.meshPerAttribute;
  27449. return json;
  27450. }
  27451. });
  27452. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27453. this.buffer = buffer;
  27454. this.type = type;
  27455. this.itemSize = itemSize;
  27456. this.elementSize = elementSize;
  27457. this.count = count;
  27458. this.version = 0;
  27459. }
  27460. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27461. set: function set(value) {
  27462. if (value === true) this.version++;
  27463. }
  27464. });
  27465. Object.assign(GLBufferAttribute.prototype, {
  27466. isGLBufferAttribute: true,
  27467. setBuffer: function setBuffer(buffer) {
  27468. this.buffer = buffer;
  27469. return this;
  27470. },
  27471. setType: function setType(type, elementSize) {
  27472. this.type = type;
  27473. this.elementSize = elementSize;
  27474. return this;
  27475. },
  27476. setItemSize: function setItemSize(itemSize) {
  27477. this.itemSize = itemSize;
  27478. return this;
  27479. },
  27480. setCount: function setCount(count) {
  27481. this.count = count;
  27482. return this;
  27483. }
  27484. });
  27485. function Raycaster(origin, direction, near, far) {
  27486. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27487. this.near = near || 0;
  27488. this.far = far || Infinity;
  27489. this.camera = null;
  27490. this.layers = new Layers();
  27491. this.params = {
  27492. Mesh: {},
  27493. Line: {
  27494. threshold: 1
  27495. },
  27496. LOD: {},
  27497. Points: {
  27498. threshold: 1
  27499. },
  27500. Sprite: {}
  27501. };
  27502. Object.defineProperties(this.params, {
  27503. PointCloud: {
  27504. get: function get() {
  27505. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27506. return this.Points;
  27507. }
  27508. }
  27509. });
  27510. }
  27511. function ascSort(a, b) {
  27512. return a.distance - b.distance;
  27513. }
  27514. function _intersectObject(object, raycaster, intersects, recursive) {
  27515. if (object.layers.test(raycaster.layers)) {
  27516. object.raycast(raycaster, intersects);
  27517. }
  27518. if (recursive === true) {
  27519. var children = object.children;
  27520. for (var i = 0, l = children.length; i < l; i++) {
  27521. _intersectObject(children[i], raycaster, intersects, true);
  27522. }
  27523. }
  27524. }
  27525. Object.assign(Raycaster.prototype, {
  27526. set: function set(origin, direction) {
  27527. // direction is assumed to be normalized (for accurate distance calculations)
  27528. this.ray.set(origin, direction);
  27529. },
  27530. setFromCamera: function setFromCamera(coords, camera) {
  27531. if (camera && camera.isPerspectiveCamera) {
  27532. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27533. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27534. this.camera = camera;
  27535. } else if (camera && camera.isOrthographicCamera) {
  27536. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27537. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27538. this.camera = camera;
  27539. } else {
  27540. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27541. }
  27542. },
  27543. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27544. var intersects = optionalTarget || [];
  27545. _intersectObject(object, this, intersects, recursive);
  27546. intersects.sort(ascSort);
  27547. return intersects;
  27548. },
  27549. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27550. var intersects = optionalTarget || [];
  27551. if (Array.isArray(objects) === false) {
  27552. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27553. return intersects;
  27554. }
  27555. for (var i = 0, l = objects.length; i < l; i++) {
  27556. _intersectObject(objects[i], this, intersects, recursive);
  27557. }
  27558. intersects.sort(ascSort);
  27559. return intersects;
  27560. }
  27561. });
  27562. /**
  27563. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27564. *
  27565. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27566. * The azimuthal angle (theta) is measured from the positive z-axis.
  27567. */
  27568. var Spherical = /*#__PURE__*/function () {
  27569. function Spherical(radius, phi, theta) {
  27570. if (radius === void 0) {
  27571. radius = 1;
  27572. }
  27573. if (phi === void 0) {
  27574. phi = 0;
  27575. }
  27576. if (theta === void 0) {
  27577. theta = 0;
  27578. }
  27579. this.radius = radius;
  27580. this.phi = phi; // polar angle
  27581. this.theta = theta; // azimuthal angle
  27582. return this;
  27583. }
  27584. var _proto = Spherical.prototype;
  27585. _proto.set = function set(radius, phi, theta) {
  27586. this.radius = radius;
  27587. this.phi = phi;
  27588. this.theta = theta;
  27589. return this;
  27590. };
  27591. _proto.clone = function clone() {
  27592. return new this.constructor().copy(this);
  27593. };
  27594. _proto.copy = function copy(other) {
  27595. this.radius = other.radius;
  27596. this.phi = other.phi;
  27597. this.theta = other.theta;
  27598. return this;
  27599. } // restrict phi to be betwee EPS and PI-EPS
  27600. ;
  27601. _proto.makeSafe = function makeSafe() {
  27602. var EPS = 0.000001;
  27603. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27604. return this;
  27605. };
  27606. _proto.setFromVector3 = function setFromVector3(v) {
  27607. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27608. };
  27609. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27610. this.radius = Math.sqrt(x * x + y * y + z * z);
  27611. if (this.radius === 0) {
  27612. this.theta = 0;
  27613. this.phi = 0;
  27614. } else {
  27615. this.theta = Math.atan2(x, z);
  27616. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27617. }
  27618. return this;
  27619. };
  27620. return Spherical;
  27621. }();
  27622. /**
  27623. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27624. */
  27625. var Cylindrical = /*#__PURE__*/function () {
  27626. function Cylindrical(radius, theta, y) {
  27627. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27628. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27629. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27630. return this;
  27631. }
  27632. var _proto = Cylindrical.prototype;
  27633. _proto.set = function set(radius, theta, y) {
  27634. this.radius = radius;
  27635. this.theta = theta;
  27636. this.y = y;
  27637. return this;
  27638. };
  27639. _proto.clone = function clone() {
  27640. return new this.constructor().copy(this);
  27641. };
  27642. _proto.copy = function copy(other) {
  27643. this.radius = other.radius;
  27644. this.theta = other.theta;
  27645. this.y = other.y;
  27646. return this;
  27647. };
  27648. _proto.setFromVector3 = function setFromVector3(v) {
  27649. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27650. };
  27651. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27652. this.radius = Math.sqrt(x * x + z * z);
  27653. this.theta = Math.atan2(x, z);
  27654. this.y = y;
  27655. return this;
  27656. };
  27657. return Cylindrical;
  27658. }();
  27659. var _vector$8 = /*@__PURE__*/new Vector2();
  27660. var Box2 = /*#__PURE__*/function () {
  27661. function Box2(min, max) {
  27662. Object.defineProperty(this, 'isBox2', {
  27663. value: true
  27664. });
  27665. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27666. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27667. }
  27668. var _proto = Box2.prototype;
  27669. _proto.set = function set(min, max) {
  27670. this.min.copy(min);
  27671. this.max.copy(max);
  27672. return this;
  27673. };
  27674. _proto.setFromPoints = function setFromPoints(points) {
  27675. this.makeEmpty();
  27676. for (var i = 0, il = points.length; i < il; i++) {
  27677. this.expandByPoint(points[i]);
  27678. }
  27679. return this;
  27680. };
  27681. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27682. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27683. this.min.copy(center).sub(halfSize);
  27684. this.max.copy(center).add(halfSize);
  27685. return this;
  27686. };
  27687. _proto.clone = function clone() {
  27688. return new this.constructor().copy(this);
  27689. };
  27690. _proto.copy = function copy(box) {
  27691. this.min.copy(box.min);
  27692. this.max.copy(box.max);
  27693. return this;
  27694. };
  27695. _proto.makeEmpty = function makeEmpty() {
  27696. this.min.x = this.min.y = +Infinity;
  27697. this.max.x = this.max.y = -Infinity;
  27698. return this;
  27699. };
  27700. _proto.isEmpty = function isEmpty() {
  27701. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27702. return this.max.x < this.min.x || this.max.y < this.min.y;
  27703. };
  27704. _proto.getCenter = function getCenter(target) {
  27705. if (target === undefined) {
  27706. console.warn('THREE.Box2: .getCenter() target is now required');
  27707. target = new Vector2();
  27708. }
  27709. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27710. };
  27711. _proto.getSize = function getSize(target) {
  27712. if (target === undefined) {
  27713. console.warn('THREE.Box2: .getSize() target is now required');
  27714. target = new Vector2();
  27715. }
  27716. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27717. };
  27718. _proto.expandByPoint = function expandByPoint(point) {
  27719. this.min.min(point);
  27720. this.max.max(point);
  27721. return this;
  27722. };
  27723. _proto.expandByVector = function expandByVector(vector) {
  27724. this.min.sub(vector);
  27725. this.max.add(vector);
  27726. return this;
  27727. };
  27728. _proto.expandByScalar = function expandByScalar(scalar) {
  27729. this.min.addScalar(-scalar);
  27730. this.max.addScalar(scalar);
  27731. return this;
  27732. };
  27733. _proto.containsPoint = function containsPoint(point) {
  27734. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27735. };
  27736. _proto.containsBox = function containsBox(box) {
  27737. 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;
  27738. };
  27739. _proto.getParameter = function getParameter(point, target) {
  27740. // This can potentially have a divide by zero if the box
  27741. // has a size dimension of 0.
  27742. if (target === undefined) {
  27743. console.warn('THREE.Box2: .getParameter() target is now required');
  27744. target = new Vector2();
  27745. }
  27746. 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));
  27747. };
  27748. _proto.intersectsBox = function intersectsBox(box) {
  27749. // using 4 splitting planes to rule out intersections
  27750. 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;
  27751. };
  27752. _proto.clampPoint = function clampPoint(point, target) {
  27753. if (target === undefined) {
  27754. console.warn('THREE.Box2: .clampPoint() target is now required');
  27755. target = new Vector2();
  27756. }
  27757. return target.copy(point).clamp(this.min, this.max);
  27758. };
  27759. _proto.distanceToPoint = function distanceToPoint(point) {
  27760. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27761. return clampedPoint.sub(point).length();
  27762. };
  27763. _proto.intersect = function intersect(box) {
  27764. this.min.max(box.min);
  27765. this.max.min(box.max);
  27766. return this;
  27767. };
  27768. _proto.union = function union(box) {
  27769. this.min.min(box.min);
  27770. this.max.max(box.max);
  27771. return this;
  27772. };
  27773. _proto.translate = function translate(offset) {
  27774. this.min.add(offset);
  27775. this.max.add(offset);
  27776. return this;
  27777. };
  27778. _proto.equals = function equals(box) {
  27779. return box.min.equals(this.min) && box.max.equals(this.max);
  27780. };
  27781. return Box2;
  27782. }();
  27783. var _startP = /*@__PURE__*/new Vector3();
  27784. var _startEnd = /*@__PURE__*/new Vector3();
  27785. var Line3 = /*#__PURE__*/function () {
  27786. function Line3(start, end) {
  27787. this.start = start !== undefined ? start : new Vector3();
  27788. this.end = end !== undefined ? end : new Vector3();
  27789. }
  27790. var _proto = Line3.prototype;
  27791. _proto.set = function set(start, end) {
  27792. this.start.copy(start);
  27793. this.end.copy(end);
  27794. return this;
  27795. };
  27796. _proto.clone = function clone() {
  27797. return new this.constructor().copy(this);
  27798. };
  27799. _proto.copy = function copy(line) {
  27800. this.start.copy(line.start);
  27801. this.end.copy(line.end);
  27802. return this;
  27803. };
  27804. _proto.getCenter = function getCenter(target) {
  27805. if (target === undefined) {
  27806. console.warn('THREE.Line3: .getCenter() target is now required');
  27807. target = new Vector3();
  27808. }
  27809. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27810. };
  27811. _proto.delta = function delta(target) {
  27812. if (target === undefined) {
  27813. console.warn('THREE.Line3: .delta() target is now required');
  27814. target = new Vector3();
  27815. }
  27816. return target.subVectors(this.end, this.start);
  27817. };
  27818. _proto.distanceSq = function distanceSq() {
  27819. return this.start.distanceToSquared(this.end);
  27820. };
  27821. _proto.distance = function distance() {
  27822. return this.start.distanceTo(this.end);
  27823. };
  27824. _proto.at = function at(t, target) {
  27825. if (target === undefined) {
  27826. console.warn('THREE.Line3: .at() target is now required');
  27827. target = new Vector3();
  27828. }
  27829. return this.delta(target).multiplyScalar(t).add(this.start);
  27830. };
  27831. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27832. _startP.subVectors(point, this.start);
  27833. _startEnd.subVectors(this.end, this.start);
  27834. var startEnd2 = _startEnd.dot(_startEnd);
  27835. var startEnd_startP = _startEnd.dot(_startP);
  27836. var t = startEnd_startP / startEnd2;
  27837. if (clampToLine) {
  27838. t = MathUtils.clamp(t, 0, 1);
  27839. }
  27840. return t;
  27841. };
  27842. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27843. var t = this.closestPointToPointParameter(point, clampToLine);
  27844. if (target === undefined) {
  27845. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27846. target = new Vector3();
  27847. }
  27848. return this.delta(target).multiplyScalar(t).add(this.start);
  27849. };
  27850. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27851. this.start.applyMatrix4(matrix);
  27852. this.end.applyMatrix4(matrix);
  27853. return this;
  27854. };
  27855. _proto.equals = function equals(line) {
  27856. return line.start.equals(this.start) && line.end.equals(this.end);
  27857. };
  27858. return Line3;
  27859. }();
  27860. function ImmediateRenderObject(material) {
  27861. Object3D.call(this);
  27862. this.material = material;
  27863. this.render = function ()
  27864. /* renderCallback */
  27865. {};
  27866. this.hasPositions = false;
  27867. this.hasNormals = false;
  27868. this.hasColors = false;
  27869. this.hasUvs = false;
  27870. this.positionArray = null;
  27871. this.normalArray = null;
  27872. this.colorArray = null;
  27873. this.uvArray = null;
  27874. this.count = 0;
  27875. }
  27876. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27877. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27878. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27879. var _vector$9 = /*@__PURE__*/new Vector3();
  27880. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27881. _inheritsLoose(SpotLightHelper, _Object3D);
  27882. function SpotLightHelper(light, color) {
  27883. var _this;
  27884. _this = _Object3D.call(this) || this;
  27885. _this.light = light;
  27886. _this.light.updateMatrixWorld();
  27887. _this.matrix = light.matrixWorld;
  27888. _this.matrixAutoUpdate = false;
  27889. _this.color = color;
  27890. var geometry = new BufferGeometry();
  27891. 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];
  27892. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27893. var p1 = i / l * Math.PI * 2;
  27894. var p2 = j / l * Math.PI * 2;
  27895. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27896. }
  27897. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27898. var material = new LineBasicMaterial({
  27899. fog: false,
  27900. toneMapped: false
  27901. });
  27902. _this.cone = new LineSegments(geometry, material);
  27903. _this.add(_this.cone);
  27904. _this.update();
  27905. return _this;
  27906. }
  27907. var _proto = SpotLightHelper.prototype;
  27908. _proto.dispose = function dispose() {
  27909. this.cone.geometry.dispose();
  27910. this.cone.material.dispose();
  27911. };
  27912. _proto.update = function update() {
  27913. this.light.updateMatrixWorld();
  27914. var coneLength = this.light.distance ? this.light.distance : 1000;
  27915. var coneWidth = coneLength * Math.tan(this.light.angle);
  27916. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27917. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  27918. this.cone.lookAt(_vector$9);
  27919. if (this.color !== undefined) {
  27920. this.cone.material.color.set(this.color);
  27921. } else {
  27922. this.cone.material.color.copy(this.light.color);
  27923. }
  27924. };
  27925. return SpotLightHelper;
  27926. }(Object3D);
  27927. var _vector$a = /*@__PURE__*/new Vector3();
  27928. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27929. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27930. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27931. _inheritsLoose(SkeletonHelper, _LineSegments);
  27932. function SkeletonHelper(object) {
  27933. var _this;
  27934. var bones = getBoneList(object);
  27935. var geometry = new BufferGeometry();
  27936. var vertices = [];
  27937. var colors = [];
  27938. var color1 = new Color(0, 0, 1);
  27939. var color2 = new Color(0, 1, 0);
  27940. for (var i = 0; i < bones.length; i++) {
  27941. var bone = bones[i];
  27942. if (bone.parent && bone.parent.isBone) {
  27943. vertices.push(0, 0, 0);
  27944. vertices.push(0, 0, 0);
  27945. colors.push(color1.r, color1.g, color1.b);
  27946. colors.push(color2.r, color2.g, color2.b);
  27947. }
  27948. }
  27949. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27950. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27951. var material = new LineBasicMaterial({
  27952. vertexColors: true,
  27953. depthTest: false,
  27954. depthWrite: false,
  27955. toneMapped: false,
  27956. transparent: true
  27957. });
  27958. _this = _LineSegments.call(this, geometry, material) || this;
  27959. _this.type = 'SkeletonHelper';
  27960. _this.isSkeletonHelper = true;
  27961. _this.root = object;
  27962. _this.bones = bones;
  27963. _this.matrix = object.matrixWorld;
  27964. _this.matrixAutoUpdate = false;
  27965. return _this;
  27966. }
  27967. var _proto = SkeletonHelper.prototype;
  27968. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27969. var bones = this.bones;
  27970. var geometry = this.geometry;
  27971. var position = geometry.getAttribute('position');
  27972. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  27973. for (var i = 0, j = 0; i < bones.length; i++) {
  27974. var bone = bones[i];
  27975. if (bone.parent && bone.parent.isBone) {
  27976. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27977. _vector$a.setFromMatrixPosition(_boneMatrix);
  27978. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  27979. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27980. _vector$a.setFromMatrixPosition(_boneMatrix);
  27981. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  27982. j += 2;
  27983. }
  27984. }
  27985. geometry.getAttribute('position').needsUpdate = true;
  27986. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27987. };
  27988. return SkeletonHelper;
  27989. }(LineSegments);
  27990. function getBoneList(object) {
  27991. var boneList = [];
  27992. if (object && object.isBone) {
  27993. boneList.push(object);
  27994. }
  27995. for (var i = 0; i < object.children.length; i++) {
  27996. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27997. }
  27998. return boneList;
  27999. }
  28000. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  28001. _inheritsLoose(PointLightHelper, _Mesh);
  28002. function PointLightHelper(light, sphereSize, color) {
  28003. var _this;
  28004. var geometry = new SphereGeometry(sphereSize, 4, 2);
  28005. var material = new MeshBasicMaterial({
  28006. wireframe: true,
  28007. fog: false,
  28008. toneMapped: false
  28009. });
  28010. _this = _Mesh.call(this, geometry, material) || this;
  28011. _this.light = light;
  28012. _this.light.updateMatrixWorld();
  28013. _this.color = color;
  28014. _this.type = 'PointLightHelper';
  28015. _this.matrix = _this.light.matrixWorld;
  28016. _this.matrixAutoUpdate = false;
  28017. _this.update();
  28018. /*
  28019. // TODO: delete this comment?
  28020. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28021. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28022. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28023. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28024. const d = light.distance;
  28025. if ( d === 0.0 ) {
  28026. this.lightDistance.visible = false;
  28027. } else {
  28028. this.lightDistance.scale.set( d, d, d );
  28029. }
  28030. this.add( this.lightDistance );
  28031. */
  28032. return _this;
  28033. }
  28034. var _proto = PointLightHelper.prototype;
  28035. _proto.dispose = function dispose() {
  28036. this.geometry.dispose();
  28037. this.material.dispose();
  28038. };
  28039. _proto.update = function update() {
  28040. if (this.color !== undefined) {
  28041. this.material.color.set(this.color);
  28042. } else {
  28043. this.material.color.copy(this.light.color);
  28044. }
  28045. /*
  28046. const d = this.light.distance;
  28047. if ( d === 0.0 ) {
  28048. this.lightDistance.visible = false;
  28049. } else {
  28050. this.lightDistance.visible = true;
  28051. this.lightDistance.scale.set( d, d, d );
  28052. }
  28053. */
  28054. };
  28055. return PointLightHelper;
  28056. }(Mesh);
  28057. var _vector$b = /*@__PURE__*/new Vector3();
  28058. var _color1 = /*@__PURE__*/new Color();
  28059. var _color2 = /*@__PURE__*/new Color();
  28060. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  28061. _inheritsLoose(HemisphereLightHelper, _Object3D);
  28062. function HemisphereLightHelper(light, size, color) {
  28063. var _this;
  28064. _this = _Object3D.call(this) || this;
  28065. _this.light = light;
  28066. _this.light.updateMatrixWorld();
  28067. _this.matrix = light.matrixWorld;
  28068. _this.matrixAutoUpdate = false;
  28069. _this.color = color;
  28070. var geometry = new OctahedronGeometry(size);
  28071. geometry.rotateY(Math.PI * 0.5);
  28072. _this.material = new MeshBasicMaterial({
  28073. wireframe: true,
  28074. fog: false,
  28075. toneMapped: false
  28076. });
  28077. if (_this.color === undefined) _this.material.vertexColors = true;
  28078. var position = geometry.getAttribute('position');
  28079. var colors = new Float32Array(position.count * 3);
  28080. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28081. _this.add(new Mesh(geometry, _this.material));
  28082. _this.update();
  28083. return _this;
  28084. }
  28085. var _proto = HemisphereLightHelper.prototype;
  28086. _proto.dispose = function dispose() {
  28087. this.children[0].geometry.dispose();
  28088. this.children[0].material.dispose();
  28089. };
  28090. _proto.update = function update() {
  28091. var mesh = this.children[0];
  28092. if (this.color !== undefined) {
  28093. this.material.color.set(this.color);
  28094. } else {
  28095. var colors = mesh.geometry.getAttribute('color');
  28096. _color1.copy(this.light.color);
  28097. _color2.copy(this.light.groundColor);
  28098. for (var i = 0, l = colors.count; i < l; i++) {
  28099. var color = i < l / 2 ? _color1 : _color2;
  28100. colors.setXYZ(i, color.r, color.g, color.b);
  28101. }
  28102. colors.needsUpdate = true;
  28103. }
  28104. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  28105. };
  28106. return HemisphereLightHelper;
  28107. }(Object3D);
  28108. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28109. _inheritsLoose(GridHelper, _LineSegments);
  28110. function GridHelper(size, divisions, color1, color2) {
  28111. var _this;
  28112. if (size === void 0) {
  28113. size = 10;
  28114. }
  28115. if (divisions === void 0) {
  28116. divisions = 10;
  28117. }
  28118. if (color1 === void 0) {
  28119. color1 = 0x444444;
  28120. }
  28121. if (color2 === void 0) {
  28122. color2 = 0x888888;
  28123. }
  28124. color1 = new Color(color1);
  28125. color2 = new Color(color2);
  28126. var center = divisions / 2;
  28127. var step = size / divisions;
  28128. var halfSize = size / 2;
  28129. var vertices = [],
  28130. colors = [];
  28131. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28132. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28133. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28134. var color = i === center ? color1 : color2;
  28135. color.toArray(colors, j);
  28136. j += 3;
  28137. color.toArray(colors, j);
  28138. j += 3;
  28139. color.toArray(colors, j);
  28140. j += 3;
  28141. color.toArray(colors, j);
  28142. j += 3;
  28143. }
  28144. var geometry = new BufferGeometry();
  28145. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28146. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28147. var material = new LineBasicMaterial({
  28148. vertexColors: true,
  28149. toneMapped: false
  28150. });
  28151. _this = _LineSegments.call(this, geometry, material) || this;
  28152. _this.type = 'GridHelper';
  28153. return _this;
  28154. }
  28155. return GridHelper;
  28156. }(LineSegments);
  28157. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28158. _inheritsLoose(PolarGridHelper, _LineSegments);
  28159. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28160. var _this;
  28161. if (radius === void 0) {
  28162. radius = 10;
  28163. }
  28164. if (radials === void 0) {
  28165. radials = 16;
  28166. }
  28167. if (circles === void 0) {
  28168. circles = 8;
  28169. }
  28170. if (divisions === void 0) {
  28171. divisions = 64;
  28172. }
  28173. if (color1 === void 0) {
  28174. color1 = 0x444444;
  28175. }
  28176. if (color2 === void 0) {
  28177. color2 = 0x888888;
  28178. }
  28179. color1 = new Color(color1);
  28180. color2 = new Color(color2);
  28181. var vertices = [];
  28182. var colors = []; // create the radials
  28183. for (var i = 0; i <= radials; i++) {
  28184. var v = i / radials * (Math.PI * 2);
  28185. var x = Math.sin(v) * radius;
  28186. var z = Math.cos(v) * radius;
  28187. vertices.push(0, 0, 0);
  28188. vertices.push(x, 0, z);
  28189. var color = i & 1 ? color1 : color2;
  28190. colors.push(color.r, color.g, color.b);
  28191. colors.push(color.r, color.g, color.b);
  28192. } // create the circles
  28193. for (var _i = 0; _i <= circles; _i++) {
  28194. var _color = _i & 1 ? color1 : color2;
  28195. var r = radius - radius / circles * _i;
  28196. for (var j = 0; j < divisions; j++) {
  28197. // first vertex
  28198. var _v = j / divisions * (Math.PI * 2);
  28199. var _x = Math.sin(_v) * r;
  28200. var _z = Math.cos(_v) * r;
  28201. vertices.push(_x, 0, _z);
  28202. colors.push(_color.r, _color.g, _color.b); // second vertex
  28203. _v = (j + 1) / divisions * (Math.PI * 2);
  28204. _x = Math.sin(_v) * r;
  28205. _z = Math.cos(_v) * r;
  28206. vertices.push(_x, 0, _z);
  28207. colors.push(_color.r, _color.g, _color.b);
  28208. }
  28209. }
  28210. var geometry = new BufferGeometry();
  28211. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28212. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28213. var material = new LineBasicMaterial({
  28214. vertexColors: true,
  28215. toneMapped: false
  28216. });
  28217. _this = _LineSegments.call(this, geometry, material) || this;
  28218. _this.type = 'PolarGridHelper';
  28219. return _this;
  28220. }
  28221. return PolarGridHelper;
  28222. }(LineSegments);
  28223. var _v1$6 = /*@__PURE__*/new Vector3();
  28224. var _v2$3 = /*@__PURE__*/new Vector3();
  28225. var _v3$1 = /*@__PURE__*/new Vector3();
  28226. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28227. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28228. function DirectionalLightHelper(light, size, color) {
  28229. var _this;
  28230. _this = _Object3D.call(this) || this;
  28231. _this.light = light;
  28232. _this.light.updateMatrixWorld();
  28233. _this.matrix = light.matrixWorld;
  28234. _this.matrixAutoUpdate = false;
  28235. _this.color = color;
  28236. if (size === undefined) size = 1;
  28237. var geometry = new BufferGeometry();
  28238. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28239. var material = new LineBasicMaterial({
  28240. fog: false,
  28241. toneMapped: false
  28242. });
  28243. _this.lightPlane = new Line(geometry, material);
  28244. _this.add(_this.lightPlane);
  28245. geometry = new BufferGeometry();
  28246. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28247. _this.targetLine = new Line(geometry, material);
  28248. _this.add(_this.targetLine);
  28249. _this.update();
  28250. return _this;
  28251. }
  28252. var _proto = DirectionalLightHelper.prototype;
  28253. _proto.dispose = function dispose() {
  28254. this.lightPlane.geometry.dispose();
  28255. this.lightPlane.material.dispose();
  28256. this.targetLine.geometry.dispose();
  28257. this.targetLine.material.dispose();
  28258. };
  28259. _proto.update = function update() {
  28260. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28261. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28262. _v3$1.subVectors(_v2$3, _v1$6);
  28263. this.lightPlane.lookAt(_v2$3);
  28264. if (this.color !== undefined) {
  28265. this.lightPlane.material.color.set(this.color);
  28266. this.targetLine.material.color.set(this.color);
  28267. } else {
  28268. this.lightPlane.material.color.copy(this.light.color);
  28269. this.targetLine.material.color.copy(this.light.color);
  28270. }
  28271. this.targetLine.lookAt(_v2$3);
  28272. this.targetLine.scale.z = _v3$1.length();
  28273. };
  28274. return DirectionalLightHelper;
  28275. }(Object3D);
  28276. var _vector$c = /*@__PURE__*/new Vector3();
  28277. var _camera = /*@__PURE__*/new Camera();
  28278. /**
  28279. * - shows frustum, line of sight and up of the camera
  28280. * - suitable for fast updates
  28281. * - based on frustum visualization in lightgl.js shadowmap example
  28282. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28283. */
  28284. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28285. _inheritsLoose(CameraHelper, _LineSegments);
  28286. function CameraHelper(camera) {
  28287. var _this;
  28288. var geometry = new BufferGeometry();
  28289. var material = new LineBasicMaterial({
  28290. color: 0xffffff,
  28291. vertexColors: true,
  28292. toneMapped: false
  28293. });
  28294. var vertices = [];
  28295. var colors = [];
  28296. var pointMap = {}; // colors
  28297. var colorFrustum = new Color(0xffaa00);
  28298. var colorCone = new Color(0xff0000);
  28299. var colorUp = new Color(0x00aaff);
  28300. var colorTarget = new Color(0xffffff);
  28301. var colorCross = new Color(0x333333); // near
  28302. addLine('n1', 'n2', colorFrustum);
  28303. addLine('n2', 'n4', colorFrustum);
  28304. addLine('n4', 'n3', colorFrustum);
  28305. addLine('n3', 'n1', colorFrustum); // far
  28306. addLine('f1', 'f2', colorFrustum);
  28307. addLine('f2', 'f4', colorFrustum);
  28308. addLine('f4', 'f3', colorFrustum);
  28309. addLine('f3', 'f1', colorFrustum); // sides
  28310. addLine('n1', 'f1', colorFrustum);
  28311. addLine('n2', 'f2', colorFrustum);
  28312. addLine('n3', 'f3', colorFrustum);
  28313. addLine('n4', 'f4', colorFrustum); // cone
  28314. addLine('p', 'n1', colorCone);
  28315. addLine('p', 'n2', colorCone);
  28316. addLine('p', 'n3', colorCone);
  28317. addLine('p', 'n4', colorCone); // up
  28318. addLine('u1', 'u2', colorUp);
  28319. addLine('u2', 'u3', colorUp);
  28320. addLine('u3', 'u1', colorUp); // target
  28321. addLine('c', 't', colorTarget);
  28322. addLine('p', 'c', colorCross); // cross
  28323. addLine('cn1', 'cn2', colorCross);
  28324. addLine('cn3', 'cn4', colorCross);
  28325. addLine('cf1', 'cf2', colorCross);
  28326. addLine('cf3', 'cf4', colorCross);
  28327. function addLine(a, b, color) {
  28328. addPoint(a, color);
  28329. addPoint(b, color);
  28330. }
  28331. function addPoint(id, color) {
  28332. vertices.push(0, 0, 0);
  28333. colors.push(color.r, color.g, color.b);
  28334. if (pointMap[id] === undefined) {
  28335. pointMap[id] = [];
  28336. }
  28337. pointMap[id].push(vertices.length / 3 - 1);
  28338. }
  28339. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28340. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28341. _this = _LineSegments.call(this, geometry, material) || this;
  28342. _this.type = 'CameraHelper';
  28343. _this.camera = camera;
  28344. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28345. _this.matrix = camera.matrixWorld;
  28346. _this.matrixAutoUpdate = false;
  28347. _this.pointMap = pointMap;
  28348. _this.update();
  28349. return _this;
  28350. }
  28351. var _proto = CameraHelper.prototype;
  28352. _proto.update = function update() {
  28353. var geometry = this.geometry;
  28354. var pointMap = this.pointMap;
  28355. var w = 1,
  28356. h = 1; // we need just camera projection matrix inverse
  28357. // world matrix must be identity
  28358. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28359. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28360. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28361. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28362. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28363. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28364. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28365. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28366. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28367. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28368. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28369. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28370. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28371. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28372. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28373. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28374. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28375. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28376. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28377. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28378. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28379. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28380. geometry.getAttribute('position').needsUpdate = true;
  28381. };
  28382. return CameraHelper;
  28383. }(LineSegments);
  28384. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28385. _vector$c.set(x, y, z).unproject(camera);
  28386. var points = pointMap[point];
  28387. if (points !== undefined) {
  28388. var position = geometry.getAttribute('position');
  28389. for (var i = 0, l = points.length; i < l; i++) {
  28390. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28391. }
  28392. }
  28393. }
  28394. var _box$3 = /*@__PURE__*/new Box3();
  28395. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28396. _inheritsLoose(BoxHelper, _LineSegments);
  28397. function BoxHelper(object, color) {
  28398. var _this;
  28399. if (color === void 0) {
  28400. color = 0xffff00;
  28401. }
  28402. 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]);
  28403. var positions = new Float32Array(8 * 3);
  28404. var geometry = new BufferGeometry();
  28405. geometry.setIndex(new BufferAttribute(indices, 1));
  28406. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28407. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28408. color: color,
  28409. toneMapped: false
  28410. })) || this;
  28411. _this.object = object;
  28412. _this.type = 'BoxHelper';
  28413. _this.matrixAutoUpdate = false;
  28414. _this.update();
  28415. return _this;
  28416. }
  28417. var _proto = BoxHelper.prototype;
  28418. _proto.update = function update(object) {
  28419. if (object !== undefined) {
  28420. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28421. }
  28422. if (this.object !== undefined) {
  28423. _box$3.setFromObject(this.object);
  28424. }
  28425. if (_box$3.isEmpty()) return;
  28426. var min = _box$3.min;
  28427. var max = _box$3.max;
  28428. /*
  28429. 5____4
  28430. 1/___0/|
  28431. | 6__|_7
  28432. 2/___3/
  28433. 0: max.x, max.y, max.z
  28434. 1: min.x, max.y, max.z
  28435. 2: min.x, min.y, max.z
  28436. 3: max.x, min.y, max.z
  28437. 4: max.x, max.y, min.z
  28438. 5: min.x, max.y, min.z
  28439. 6: min.x, min.y, min.z
  28440. 7: max.x, min.y, min.z
  28441. */
  28442. var position = this.geometry.attributes.position;
  28443. var array = position.array;
  28444. array[0] = max.x;
  28445. array[1] = max.y;
  28446. array[2] = max.z;
  28447. array[3] = min.x;
  28448. array[4] = max.y;
  28449. array[5] = max.z;
  28450. array[6] = min.x;
  28451. array[7] = min.y;
  28452. array[8] = max.z;
  28453. array[9] = max.x;
  28454. array[10] = min.y;
  28455. array[11] = max.z;
  28456. array[12] = max.x;
  28457. array[13] = max.y;
  28458. array[14] = min.z;
  28459. array[15] = min.x;
  28460. array[16] = max.y;
  28461. array[17] = min.z;
  28462. array[18] = min.x;
  28463. array[19] = min.y;
  28464. array[20] = min.z;
  28465. array[21] = max.x;
  28466. array[22] = min.y;
  28467. array[23] = min.z;
  28468. position.needsUpdate = true;
  28469. this.geometry.computeBoundingSphere();
  28470. };
  28471. _proto.setFromObject = function setFromObject(object) {
  28472. this.object = object;
  28473. this.update();
  28474. return this;
  28475. };
  28476. _proto.copy = function copy(source) {
  28477. LineSegments.prototype.copy.call(this, source);
  28478. this.object = source.object;
  28479. return this;
  28480. };
  28481. return BoxHelper;
  28482. }(LineSegments);
  28483. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28484. _inheritsLoose(Box3Helper, _LineSegments);
  28485. function Box3Helper(box, color) {
  28486. var _this;
  28487. if (color === void 0) {
  28488. color = 0xffff00;
  28489. }
  28490. 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]);
  28491. 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];
  28492. var geometry = new BufferGeometry();
  28493. geometry.setIndex(new BufferAttribute(indices, 1));
  28494. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28495. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28496. color: color,
  28497. toneMapped: false
  28498. })) || this;
  28499. _this.box = box;
  28500. _this.type = 'Box3Helper';
  28501. _this.geometry.computeBoundingSphere();
  28502. return _this;
  28503. }
  28504. var _proto = Box3Helper.prototype;
  28505. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28506. var box = this.box;
  28507. if (box.isEmpty()) return;
  28508. box.getCenter(this.position);
  28509. box.getSize(this.scale);
  28510. this.scale.multiplyScalar(0.5);
  28511. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28512. };
  28513. return Box3Helper;
  28514. }(LineSegments);
  28515. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28516. _inheritsLoose(PlaneHelper, _Line);
  28517. function PlaneHelper(plane, size, hex) {
  28518. var _this;
  28519. if (size === void 0) {
  28520. size = 1;
  28521. }
  28522. if (hex === void 0) {
  28523. hex = 0xffff00;
  28524. }
  28525. var color = hex;
  28526. 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];
  28527. var geometry = new BufferGeometry();
  28528. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28529. geometry.computeBoundingSphere();
  28530. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28531. color: color,
  28532. toneMapped: false
  28533. })) || this;
  28534. _this.type = 'PlaneHelper';
  28535. _this.plane = plane;
  28536. _this.size = size;
  28537. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28538. var geometry2 = new BufferGeometry();
  28539. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28540. geometry2.computeBoundingSphere();
  28541. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28542. color: color,
  28543. opacity: 0.2,
  28544. transparent: true,
  28545. depthWrite: false,
  28546. toneMapped: false
  28547. })));
  28548. return _this;
  28549. }
  28550. var _proto = PlaneHelper.prototype;
  28551. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28552. var scale = -this.plane.constant;
  28553. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28554. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28555. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28556. this.lookAt(this.plane.normal);
  28557. _Line.prototype.updateMatrixWorld.call(this, force);
  28558. };
  28559. return PlaneHelper;
  28560. }(Line);
  28561. var _axis = /*@__PURE__*/new Vector3();
  28562. var _lineGeometry, _coneGeometry;
  28563. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28564. _inheritsLoose(ArrowHelper, _Object3D);
  28565. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28566. var _this;
  28567. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28568. _this.type = 'ArrowHelper';
  28569. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28570. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28571. if (length === undefined) length = 1;
  28572. if (color === undefined) color = 0xffff00;
  28573. if (headLength === undefined) headLength = 0.2 * length;
  28574. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28575. if (_lineGeometry === undefined) {
  28576. _lineGeometry = new BufferGeometry();
  28577. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28578. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28579. _coneGeometry.translate(0, -0.5, 0);
  28580. }
  28581. _this.position.copy(origin);
  28582. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28583. color: color,
  28584. toneMapped: false
  28585. }));
  28586. _this.line.matrixAutoUpdate = false;
  28587. _this.add(_this.line);
  28588. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28589. color: color,
  28590. toneMapped: false
  28591. }));
  28592. _this.cone.matrixAutoUpdate = false;
  28593. _this.add(_this.cone);
  28594. _this.setDirection(dir);
  28595. _this.setLength(length, headLength, headWidth);
  28596. return _this;
  28597. }
  28598. var _proto = ArrowHelper.prototype;
  28599. _proto.setDirection = function setDirection(dir) {
  28600. // dir is assumed to be normalized
  28601. if (dir.y > 0.99999) {
  28602. this.quaternion.set(0, 0, 0, 1);
  28603. } else if (dir.y < -0.99999) {
  28604. this.quaternion.set(1, 0, 0, 0);
  28605. } else {
  28606. _axis.set(dir.z, 0, -dir.x).normalize();
  28607. var radians = Math.acos(dir.y);
  28608. this.quaternion.setFromAxisAngle(_axis, radians);
  28609. }
  28610. };
  28611. _proto.setLength = function setLength(length, headLength, headWidth) {
  28612. if (headLength === undefined) headLength = 0.2 * length;
  28613. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28614. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28615. this.line.updateMatrix();
  28616. this.cone.scale.set(headWidth, headLength, headWidth);
  28617. this.cone.position.y = length;
  28618. this.cone.updateMatrix();
  28619. };
  28620. _proto.setColor = function setColor(color) {
  28621. this.line.material.color.set(color);
  28622. this.cone.material.color.set(color);
  28623. };
  28624. _proto.copy = function copy(source) {
  28625. _Object3D.prototype.copy.call(this, source, false);
  28626. this.line.copy(source.line);
  28627. this.cone.copy(source.cone);
  28628. return this;
  28629. };
  28630. return ArrowHelper;
  28631. }(Object3D);
  28632. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28633. _inheritsLoose(AxesHelper, _LineSegments);
  28634. function AxesHelper(size) {
  28635. var _this;
  28636. if (size === void 0) {
  28637. size = 1;
  28638. }
  28639. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28640. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28641. var geometry = new BufferGeometry();
  28642. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28643. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28644. var material = new LineBasicMaterial({
  28645. vertexColors: true,
  28646. toneMapped: false
  28647. });
  28648. _this = _LineSegments.call(this, geometry, material) || this;
  28649. _this.type = 'AxesHelper';
  28650. return _this;
  28651. }
  28652. return AxesHelper;
  28653. }(LineSegments);
  28654. var _floatView = new Float32Array(1);
  28655. var _int32View = new Int32Array(_floatView.buffer);
  28656. var DataUtils = {
  28657. // Converts float32 to float16 (stored as uint16 value).
  28658. toHalfFloat: function toHalfFloat(val) {
  28659. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28660. /* This method is faster than the OpenEXR implementation (very often
  28661. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28662. * by James Tursa?s half-precision code. */
  28663. _floatView[0] = val;
  28664. var x = _int32View[0];
  28665. var bits = x >> 16 & 0x8000;
  28666. /* Get the sign */
  28667. var m = x >> 12 & 0x07ff;
  28668. /* Keep one extra bit for rounding */
  28669. var e = x >> 23 & 0xff;
  28670. /* Using int is faster here */
  28671. /* If zero, or denormal, or exponent underflows too much for a denormal
  28672. * half, return signed zero. */
  28673. if (e < 103) return bits;
  28674. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28675. if (e > 142) {
  28676. bits |= 0x7c00;
  28677. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28678. * not Inf, so make sure we set one mantissa bit too. */
  28679. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28680. return bits;
  28681. }
  28682. /* If exponent underflows but not too much, return a denormal */
  28683. if (e < 113) {
  28684. m |= 0x0800;
  28685. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28686. * to 1, which is OK. */
  28687. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28688. return bits;
  28689. }
  28690. bits |= e - 112 << 10 | m >> 1;
  28691. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28692. * the exponent, which is OK. */
  28693. bits += m & 1;
  28694. return bits;
  28695. }
  28696. };
  28697. var _ENCODINGS;
  28698. var LOD_MIN = 4;
  28699. var LOD_MAX = 8;
  28700. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28701. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28702. // geometric shadowing function. These sigma values squared must match the
  28703. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28704. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28705. 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
  28706. // samples and exit early, but not recompile the shader.
  28707. var MAX_SAMPLES = 20;
  28708. 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);
  28709. var backgroundMaterial = new MeshBasicMaterial({
  28710. side: BackSide,
  28711. depthWrite: false,
  28712. depthTest: false
  28713. });
  28714. var backgroundBox = new Mesh(new BoxGeometry(), backgroundMaterial);
  28715. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28716. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28717. _lodPlanes = _createPlanes2._lodPlanes,
  28718. _sizeLods = _createPlanes2._sizeLods,
  28719. _sigmas = _createPlanes2._sigmas;
  28720. var _clearColor = /*@__PURE__*/new Color();
  28721. var _oldTarget = null; // Golden Ratio
  28722. var PHI = (1 + Math.sqrt(5)) / 2;
  28723. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28724. // same axis), used as axis directions evenly spread on a sphere.
  28725. 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)];
  28726. /**
  28727. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28728. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28729. * blur to be quickly accessed based on material roughness. It is packed into a
  28730. * special CubeUV format that allows us to perform custom interpolation so that
  28731. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28732. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28733. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28734. * higher roughness levels. In this way we maintain resolution to smoothly
  28735. * interpolate diffuse lighting while limiting sampling computation.
  28736. */
  28737. function convertLinearToRGBE(color) {
  28738. var maxComponent = Math.max(color.r, color.g, color.b);
  28739. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28740. color.multiplyScalar(Math.pow(2.0, -fExp));
  28741. var alpha = (fExp + 128.0) / 255.0;
  28742. return alpha;
  28743. }
  28744. var PMREMGenerator = /*#__PURE__*/function () {
  28745. function PMREMGenerator(renderer) {
  28746. this._renderer = renderer;
  28747. this._pingPongRenderTarget = null;
  28748. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28749. this._equirectShader = null;
  28750. this._cubemapShader = null;
  28751. this._compileMaterial(this._blurMaterial);
  28752. }
  28753. /**
  28754. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28755. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28756. * in radians to be applied to the scene before PMREM generation. Optional near
  28757. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28758. * is placed at the origin).
  28759. */
  28760. var _proto = PMREMGenerator.prototype;
  28761. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28762. if (sigma === void 0) {
  28763. sigma = 0;
  28764. }
  28765. if (near === void 0) {
  28766. near = 0.1;
  28767. }
  28768. if (far === void 0) {
  28769. far = 100;
  28770. }
  28771. _oldTarget = this._renderer.getRenderTarget();
  28772. var cubeUVRenderTarget = this._allocateTargets();
  28773. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28774. if (sigma > 0) {
  28775. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28776. }
  28777. this._applyPMREM(cubeUVRenderTarget);
  28778. this._cleanup(cubeUVRenderTarget);
  28779. return cubeUVRenderTarget;
  28780. }
  28781. /**
  28782. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28783. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28784. * as this matches best with the 256 x 256 cubemap output.
  28785. */
  28786. ;
  28787. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28788. return this._fromTexture(equirectangular);
  28789. }
  28790. /**
  28791. * Generates a PMREM from an cubemap texture, which can be either LDR
  28792. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28793. * as this matches best with the 256 x 256 cubemap output.
  28794. */
  28795. ;
  28796. _proto.fromCubemap = function fromCubemap(cubemap) {
  28797. return this._fromTexture(cubemap);
  28798. }
  28799. /**
  28800. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28801. * your texture's network fetch for increased concurrency.
  28802. */
  28803. ;
  28804. _proto.compileCubemapShader = function compileCubemapShader() {
  28805. if (this._cubemapShader === null) {
  28806. this._cubemapShader = _getCubemapShader();
  28807. this._compileMaterial(this._cubemapShader);
  28808. }
  28809. }
  28810. /**
  28811. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28812. * your texture's network fetch for increased concurrency.
  28813. */
  28814. ;
  28815. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28816. if (this._equirectShader === null) {
  28817. this._equirectShader = _getEquirectShader();
  28818. this._compileMaterial(this._equirectShader);
  28819. }
  28820. }
  28821. /**
  28822. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28823. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28824. * one of them will cause any others to also become unusable.
  28825. */
  28826. ;
  28827. _proto.dispose = function dispose() {
  28828. this._blurMaterial.dispose();
  28829. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28830. if (this._equirectShader !== null) this._equirectShader.dispose();
  28831. for (var i = 0; i < _lodPlanes.length; i++) {
  28832. _lodPlanes[i].dispose();
  28833. }
  28834. } // private interface
  28835. ;
  28836. _proto._cleanup = function _cleanup(outputTarget) {
  28837. this._pingPongRenderTarget.dispose();
  28838. this._renderer.setRenderTarget(_oldTarget);
  28839. outputTarget.scissorTest = false;
  28840. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28841. };
  28842. _proto._fromTexture = function _fromTexture(texture) {
  28843. _oldTarget = this._renderer.getRenderTarget();
  28844. var cubeUVRenderTarget = this._allocateTargets(texture);
  28845. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28846. this._applyPMREM(cubeUVRenderTarget);
  28847. this._cleanup(cubeUVRenderTarget);
  28848. return cubeUVRenderTarget;
  28849. };
  28850. _proto._allocateTargets = function _allocateTargets(texture) {
  28851. // warning: null texture is valid
  28852. var params = {
  28853. magFilter: NearestFilter,
  28854. minFilter: NearestFilter,
  28855. generateMipmaps: false,
  28856. type: UnsignedByteType,
  28857. format: RGBEFormat,
  28858. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28859. depthBuffer: false
  28860. };
  28861. var cubeUVRenderTarget = _createRenderTarget(params);
  28862. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28863. this._pingPongRenderTarget = _createRenderTarget(params);
  28864. return cubeUVRenderTarget;
  28865. };
  28866. _proto._compileMaterial = function _compileMaterial(material) {
  28867. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28868. this._renderer.compile(tmpMesh, _flatCamera);
  28869. };
  28870. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28871. var fov = 90;
  28872. var aspect = 1;
  28873. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28874. var upSign = [1, -1, 1, 1, 1, 1];
  28875. var forwardSign = [1, 1, 1, -1, -1, -1];
  28876. var renderer = this._renderer;
  28877. var originalAutoClear = renderer.autoClear;
  28878. var outputEncoding = renderer.outputEncoding;
  28879. var toneMapping = renderer.toneMapping;
  28880. renderer.getClearColor(_clearColor);
  28881. renderer.toneMapping = NoToneMapping;
  28882. renderer.outputEncoding = LinearEncoding;
  28883. renderer.autoClear = false;
  28884. var useSolidColor = false;
  28885. var background = scene.background;
  28886. if (background) {
  28887. if (background.isColor) {
  28888. backgroundMaterial.color.copy(background).convertSRGBToLinear();
  28889. scene.background = null;
  28890. var alpha = convertLinearToRGBE(backgroundMaterial.color);
  28891. backgroundMaterial.opacity = alpha;
  28892. useSolidColor = true;
  28893. }
  28894. } else {
  28895. backgroundMaterial.color.copy(_clearColor).convertSRGBToLinear();
  28896. var _alpha = convertLinearToRGBE(backgroundMaterial.color);
  28897. backgroundMaterial.opacity = _alpha;
  28898. useSolidColor = true;
  28899. }
  28900. for (var i = 0; i < 6; i++) {
  28901. var col = i % 3;
  28902. if (col == 0) {
  28903. cubeCamera.up.set(0, upSign[i], 0);
  28904. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28905. } else if (col == 1) {
  28906. cubeCamera.up.set(0, 0, upSign[i]);
  28907. cubeCamera.lookAt(0, forwardSign[i], 0);
  28908. } else {
  28909. cubeCamera.up.set(0, upSign[i], 0);
  28910. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28911. }
  28912. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28913. renderer.setRenderTarget(cubeUVRenderTarget);
  28914. if (useSolidColor) {
  28915. renderer.render(backgroundBox, cubeCamera);
  28916. }
  28917. renderer.render(scene, cubeCamera);
  28918. }
  28919. renderer.toneMapping = toneMapping;
  28920. renderer.outputEncoding = outputEncoding;
  28921. renderer.autoClear = originalAutoClear;
  28922. };
  28923. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28924. var renderer = this._renderer;
  28925. if (texture.isCubeTexture) {
  28926. if (this._cubemapShader == null) {
  28927. this._cubemapShader = _getCubemapShader();
  28928. }
  28929. } else {
  28930. if (this._equirectShader == null) {
  28931. this._equirectShader = _getEquirectShader();
  28932. }
  28933. }
  28934. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28935. var mesh = new Mesh(_lodPlanes[0], material);
  28936. var uniforms = material.uniforms;
  28937. uniforms['envMap'].value = texture;
  28938. if (!texture.isCubeTexture) {
  28939. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28940. }
  28941. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28942. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28943. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28944. renderer.setRenderTarget(cubeUVRenderTarget);
  28945. renderer.render(mesh, _flatCamera);
  28946. };
  28947. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28948. var renderer = this._renderer;
  28949. var autoClear = renderer.autoClear;
  28950. renderer.autoClear = false;
  28951. for (var i = 1; i < TOTAL_LODS; i++) {
  28952. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28953. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28954. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28955. }
  28956. renderer.autoClear = autoClear;
  28957. }
  28958. /**
  28959. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28960. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28961. * the blur latitudinally (around the poles), and then longitudinally (towards
  28962. * the poles) to approximate the orthogonally-separable blur. It is least
  28963. * accurate at the poles, but still does a decent job.
  28964. */
  28965. ;
  28966. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28967. var pingPongRenderTarget = this._pingPongRenderTarget;
  28968. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28969. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28970. };
  28971. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28972. var renderer = this._renderer;
  28973. var blurMaterial = this._blurMaterial;
  28974. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28975. console.error('blur direction must be either latitudinal or longitudinal!');
  28976. } // Number of standard deviations at which to cut off the discrete approximation.
  28977. var STANDARD_DEVIATIONS = 3;
  28978. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28979. var blurUniforms = blurMaterial.uniforms;
  28980. var pixels = _sizeLods[lodIn] - 1;
  28981. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28982. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28983. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28984. if (samples > MAX_SAMPLES) {
  28985. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28986. }
  28987. var weights = [];
  28988. var sum = 0;
  28989. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28990. var _x = i / sigmaPixels;
  28991. var weight = Math.exp(-_x * _x / 2);
  28992. weights.push(weight);
  28993. if (i == 0) {
  28994. sum += weight;
  28995. } else if (i < samples) {
  28996. sum += 2 * weight;
  28997. }
  28998. }
  28999. for (var _i = 0; _i < weights.length; _i++) {
  29000. weights[_i] = weights[_i] / sum;
  29001. }
  29002. blurUniforms['envMap'].value = targetIn.texture;
  29003. blurUniforms['samples'].value = samples;
  29004. blurUniforms['weights'].value = weights;
  29005. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  29006. if (poleAxis) {
  29007. blurUniforms['poleAxis'].value = poleAxis;
  29008. }
  29009. blurUniforms['dTheta'].value = radiansPerPixel;
  29010. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  29011. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29012. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29013. var outputSize = _sizeLods[lodOut];
  29014. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  29015. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  29016. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  29017. renderer.setRenderTarget(targetOut);
  29018. renderer.render(blurMesh, _flatCamera);
  29019. };
  29020. return PMREMGenerator;
  29021. }();
  29022. function _isLDR(texture) {
  29023. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  29024. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29025. }
  29026. function _createPlanes() {
  29027. var _lodPlanes = [];
  29028. var _sizeLods = [];
  29029. var _sigmas = [];
  29030. var lod = LOD_MAX;
  29031. for (var i = 0; i < TOTAL_LODS; i++) {
  29032. var sizeLod = Math.pow(2, lod);
  29033. _sizeLods.push(sizeLod);
  29034. var sigma = 1.0 / sizeLod;
  29035. if (i > LOD_MAX - LOD_MIN) {
  29036. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  29037. } else if (i == 0) {
  29038. sigma = 0;
  29039. }
  29040. _sigmas.push(sigma);
  29041. var texelSize = 1.0 / (sizeLod - 1);
  29042. var min = -texelSize / 2;
  29043. var max = 1 + texelSize / 2;
  29044. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  29045. var cubeFaces = 6;
  29046. var vertices = 6;
  29047. var positionSize = 3;
  29048. var uvSize = 2;
  29049. var faceIndexSize = 1;
  29050. var position = new Float32Array(positionSize * vertices * cubeFaces);
  29051. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  29052. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  29053. for (var face = 0; face < cubeFaces; face++) {
  29054. var x = face % 3 * 2 / 3 - 1;
  29055. var y = face > 2 ? 0 : -1;
  29056. 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];
  29057. position.set(coordinates, positionSize * vertices * face);
  29058. uv.set(uv1, uvSize * vertices * face);
  29059. var fill = [face, face, face, face, face, face];
  29060. faceIndex.set(fill, faceIndexSize * vertices * face);
  29061. }
  29062. var planes = new BufferGeometry();
  29063. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  29064. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  29065. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  29066. _lodPlanes.push(planes);
  29067. if (lod > LOD_MIN) {
  29068. lod--;
  29069. }
  29070. }
  29071. return {
  29072. _lodPlanes: _lodPlanes,
  29073. _sizeLods: _sizeLods,
  29074. _sigmas: _sigmas
  29075. };
  29076. }
  29077. function _createRenderTarget(params) {
  29078. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  29079. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29080. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29081. cubeUVRenderTarget.scissorTest = true;
  29082. return cubeUVRenderTarget;
  29083. }
  29084. function _setViewport(target, x, y, width, height) {
  29085. target.viewport.set(x, y, width, height);
  29086. target.scissor.set(x, y, width, height);
  29087. }
  29088. function _getBlurShader(maxSamples) {
  29089. var weights = new Float32Array(maxSamples);
  29090. var poleAxis = new Vector3(0, 1, 0);
  29091. var shaderMaterial = new RawShaderMaterial({
  29092. name: 'SphericalGaussianBlur',
  29093. defines: {
  29094. 'n': maxSamples
  29095. },
  29096. uniforms: {
  29097. 'envMap': {
  29098. value: null
  29099. },
  29100. 'samples': {
  29101. value: 1
  29102. },
  29103. 'weights': {
  29104. value: weights
  29105. },
  29106. 'latitudinal': {
  29107. value: false
  29108. },
  29109. 'dTheta': {
  29110. value: 0
  29111. },
  29112. 'mipInt': {
  29113. value: 0
  29114. },
  29115. 'poleAxis': {
  29116. value: poleAxis
  29117. },
  29118. 'inputEncoding': {
  29119. value: ENCODINGS[LinearEncoding]
  29120. },
  29121. 'outputEncoding': {
  29122. value: ENCODINGS[LinearEncoding]
  29123. }
  29124. },
  29125. vertexShader: _getCommonVertexShader(),
  29126. fragmentShader:
  29127. /* glsl */
  29128. "\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",
  29129. blending: NoBlending,
  29130. depthTest: false,
  29131. depthWrite: false
  29132. });
  29133. return shaderMaterial;
  29134. }
  29135. function _getEquirectShader() {
  29136. var texelSize = new Vector2(1, 1);
  29137. var shaderMaterial = new RawShaderMaterial({
  29138. name: 'EquirectangularToCubeUV',
  29139. uniforms: {
  29140. 'envMap': {
  29141. value: null
  29142. },
  29143. 'texelSize': {
  29144. value: texelSize
  29145. },
  29146. 'inputEncoding': {
  29147. value: ENCODINGS[LinearEncoding]
  29148. },
  29149. 'outputEncoding': {
  29150. value: ENCODINGS[LinearEncoding]
  29151. }
  29152. },
  29153. vertexShader: _getCommonVertexShader(),
  29154. fragmentShader:
  29155. /* glsl */
  29156. "\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",
  29157. blending: NoBlending,
  29158. depthTest: false,
  29159. depthWrite: false
  29160. });
  29161. return shaderMaterial;
  29162. }
  29163. function _getCubemapShader() {
  29164. var shaderMaterial = new RawShaderMaterial({
  29165. name: 'CubemapToCubeUV',
  29166. uniforms: {
  29167. 'envMap': {
  29168. value: null
  29169. },
  29170. 'inputEncoding': {
  29171. value: ENCODINGS[LinearEncoding]
  29172. },
  29173. 'outputEncoding': {
  29174. value: ENCODINGS[LinearEncoding]
  29175. }
  29176. },
  29177. vertexShader: _getCommonVertexShader(),
  29178. fragmentShader:
  29179. /* glsl */
  29180. "\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",
  29181. blending: NoBlending,
  29182. depthTest: false,
  29183. depthWrite: false
  29184. });
  29185. return shaderMaterial;
  29186. }
  29187. function _getCommonVertexShader() {
  29188. return (
  29189. /* glsl */
  29190. "\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"
  29191. );
  29192. }
  29193. function _getEncodings() {
  29194. return (
  29195. /* glsl */
  29196. "\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"
  29197. );
  29198. }
  29199. var LineStrip = 0;
  29200. var LinePieces = 1;
  29201. var NoColors = 0;
  29202. var FaceColors = 1;
  29203. var VertexColors = 2;
  29204. function MeshFaceMaterial(materials) {
  29205. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29206. return materials;
  29207. }
  29208. function MultiMaterial(materials) {
  29209. if (materials === void 0) {
  29210. materials = [];
  29211. }
  29212. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29213. materials.isMultiMaterial = true;
  29214. materials.materials = materials;
  29215. materials.clone = function () {
  29216. return materials.slice();
  29217. };
  29218. return materials;
  29219. }
  29220. function PointCloud(geometry, material) {
  29221. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29222. return new Points(geometry, material);
  29223. }
  29224. function Particle(material) {
  29225. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29226. return new Sprite(material);
  29227. }
  29228. function ParticleSystem(geometry, material) {
  29229. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29230. return new Points(geometry, material);
  29231. }
  29232. function PointCloudMaterial(parameters) {
  29233. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29234. return new PointsMaterial(parameters);
  29235. }
  29236. function ParticleBasicMaterial(parameters) {
  29237. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29238. return new PointsMaterial(parameters);
  29239. }
  29240. function ParticleSystemMaterial(parameters) {
  29241. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29242. return new PointsMaterial(parameters);
  29243. }
  29244. function Vertex(x, y, z) {
  29245. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29246. return new Vector3(x, y, z);
  29247. } //
  29248. function DynamicBufferAttribute(array, itemSize) {
  29249. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29250. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29251. }
  29252. function Int8Attribute(array, itemSize) {
  29253. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29254. return new Int8BufferAttribute(array, itemSize);
  29255. }
  29256. function Uint8Attribute(array, itemSize) {
  29257. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29258. return new Uint8BufferAttribute(array, itemSize);
  29259. }
  29260. function Uint8ClampedAttribute(array, itemSize) {
  29261. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29262. return new Uint8ClampedBufferAttribute(array, itemSize);
  29263. }
  29264. function Int16Attribute(array, itemSize) {
  29265. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29266. return new Int16BufferAttribute(array, itemSize);
  29267. }
  29268. function Uint16Attribute(array, itemSize) {
  29269. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29270. return new Uint16BufferAttribute(array, itemSize);
  29271. }
  29272. function Int32Attribute(array, itemSize) {
  29273. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29274. return new Int32BufferAttribute(array, itemSize);
  29275. }
  29276. function Uint32Attribute(array, itemSize) {
  29277. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29278. return new Uint32BufferAttribute(array, itemSize);
  29279. }
  29280. function Float32Attribute(array, itemSize) {
  29281. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29282. return new Float32BufferAttribute(array, itemSize);
  29283. }
  29284. function Float64Attribute(array, itemSize) {
  29285. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29286. return new Float64BufferAttribute(array, itemSize);
  29287. } //
  29288. Curve.create = function (construct, getPoint) {
  29289. console.log('THREE.Curve.create() has been deprecated');
  29290. construct.prototype = Object.create(Curve.prototype);
  29291. construct.prototype.constructor = construct;
  29292. construct.prototype.getPoint = getPoint;
  29293. return construct;
  29294. }; //
  29295. Object.assign(Path.prototype, {
  29296. fromPoints: function fromPoints(points) {
  29297. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29298. return this.setFromPoints(points);
  29299. }
  29300. }); //
  29301. function AxisHelper(size) {
  29302. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29303. return new AxesHelper(size);
  29304. }
  29305. function BoundingBoxHelper(object, color) {
  29306. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29307. return new BoxHelper(object, color);
  29308. }
  29309. function EdgesHelper(object, hex) {
  29310. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29311. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29312. color: hex !== undefined ? hex : 0xffffff
  29313. }));
  29314. }
  29315. GridHelper.prototype.setColors = function () {
  29316. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29317. };
  29318. SkeletonHelper.prototype.update = function () {
  29319. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29320. };
  29321. function WireframeHelper(object, hex) {
  29322. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29323. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29324. color: hex !== undefined ? hex : 0xffffff
  29325. }));
  29326. } //
  29327. Object.assign(Loader.prototype, {
  29328. extractUrlBase: function extractUrlBase(url) {
  29329. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29330. return LoaderUtils.extractUrlBase(url);
  29331. }
  29332. });
  29333. Loader.Handlers = {
  29334. add: function add()
  29335. /* regex, loader */
  29336. {
  29337. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29338. },
  29339. get: function get()
  29340. /* file */
  29341. {
  29342. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29343. }
  29344. };
  29345. function XHRLoader(manager) {
  29346. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29347. return new FileLoader(manager);
  29348. }
  29349. function BinaryTextureLoader(manager) {
  29350. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29351. return new DataTextureLoader(manager);
  29352. } //
  29353. Object.assign(Box2.prototype, {
  29354. center: function center(optionalTarget) {
  29355. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29356. return this.getCenter(optionalTarget);
  29357. },
  29358. empty: function empty() {
  29359. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29360. return this.isEmpty();
  29361. },
  29362. isIntersectionBox: function isIntersectionBox(box) {
  29363. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29364. return this.intersectsBox(box);
  29365. },
  29366. size: function size(optionalTarget) {
  29367. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29368. return this.getSize(optionalTarget);
  29369. }
  29370. });
  29371. Object.assign(Box3.prototype, {
  29372. center: function center(optionalTarget) {
  29373. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29374. return this.getCenter(optionalTarget);
  29375. },
  29376. empty: function empty() {
  29377. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29378. return this.isEmpty();
  29379. },
  29380. isIntersectionBox: function isIntersectionBox(box) {
  29381. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29382. return this.intersectsBox(box);
  29383. },
  29384. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29385. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29386. return this.intersectsSphere(sphere);
  29387. },
  29388. size: function size(optionalTarget) {
  29389. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29390. return this.getSize(optionalTarget);
  29391. }
  29392. });
  29393. Object.assign(Sphere.prototype, {
  29394. empty: function empty() {
  29395. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29396. return this.isEmpty();
  29397. }
  29398. });
  29399. Frustum.prototype.setFromMatrix = function (m) {
  29400. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29401. return this.setFromProjectionMatrix(m);
  29402. };
  29403. Line3.prototype.center = function (optionalTarget) {
  29404. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29405. return this.getCenter(optionalTarget);
  29406. };
  29407. Object.assign(MathUtils, {
  29408. random16: function random16() {
  29409. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29410. return Math.random();
  29411. },
  29412. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29413. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29414. return MathUtils.floorPowerOfTwo(value);
  29415. },
  29416. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29417. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29418. return MathUtils.ceilPowerOfTwo(value);
  29419. }
  29420. });
  29421. Object.assign(Matrix3.prototype, {
  29422. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29423. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29424. return this.toArray(array, offset);
  29425. },
  29426. multiplyVector3: function multiplyVector3(vector) {
  29427. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29428. return vector.applyMatrix3(this);
  29429. },
  29430. multiplyVector3Array: function multiplyVector3Array()
  29431. /* a */
  29432. {
  29433. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29434. },
  29435. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29436. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29437. return attribute.applyMatrix3(this);
  29438. },
  29439. applyToVector3Array: function applyToVector3Array()
  29440. /* array, offset, length */
  29441. {
  29442. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29443. },
  29444. getInverse: function getInverse(matrix) {
  29445. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29446. return this.copy(matrix).invert();
  29447. }
  29448. });
  29449. Object.assign(Matrix4.prototype, {
  29450. extractPosition: function extractPosition(m) {
  29451. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29452. return this.copyPosition(m);
  29453. },
  29454. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29455. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29456. return this.toArray(array, offset);
  29457. },
  29458. getPosition: function getPosition() {
  29459. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29460. return new Vector3().setFromMatrixColumn(this, 3);
  29461. },
  29462. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29463. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29464. return this.makeRotationFromQuaternion(q);
  29465. },
  29466. multiplyToArray: function multiplyToArray() {
  29467. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29468. },
  29469. multiplyVector3: function multiplyVector3(vector) {
  29470. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29471. return vector.applyMatrix4(this);
  29472. },
  29473. multiplyVector4: function multiplyVector4(vector) {
  29474. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29475. return vector.applyMatrix4(this);
  29476. },
  29477. multiplyVector3Array: function multiplyVector3Array()
  29478. /* a */
  29479. {
  29480. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29481. },
  29482. rotateAxis: function rotateAxis(v) {
  29483. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29484. v.transformDirection(this);
  29485. },
  29486. crossVector: function crossVector(vector) {
  29487. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29488. return vector.applyMatrix4(this);
  29489. },
  29490. translate: function translate() {
  29491. console.error('THREE.Matrix4: .translate() has been removed.');
  29492. },
  29493. rotateX: function rotateX() {
  29494. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29495. },
  29496. rotateY: function rotateY() {
  29497. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29498. },
  29499. rotateZ: function rotateZ() {
  29500. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29501. },
  29502. rotateByAxis: function rotateByAxis() {
  29503. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29504. },
  29505. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29506. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29507. return attribute.applyMatrix4(this);
  29508. },
  29509. applyToVector3Array: function applyToVector3Array()
  29510. /* array, offset, length */
  29511. {
  29512. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29513. },
  29514. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29515. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29516. return this.makePerspective(left, right, top, bottom, near, far);
  29517. },
  29518. getInverse: function getInverse(matrix) {
  29519. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29520. return this.copy(matrix).invert();
  29521. }
  29522. });
  29523. Plane.prototype.isIntersectionLine = function (line) {
  29524. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29525. return this.intersectsLine(line);
  29526. };
  29527. Object.assign(Quaternion.prototype, {
  29528. multiplyVector3: function multiplyVector3(vector) {
  29529. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29530. return vector.applyQuaternion(this);
  29531. },
  29532. inverse: function inverse() {
  29533. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29534. return this.invert();
  29535. }
  29536. });
  29537. Object.assign(Ray.prototype, {
  29538. isIntersectionBox: function isIntersectionBox(box) {
  29539. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29540. return this.intersectsBox(box);
  29541. },
  29542. isIntersectionPlane: function isIntersectionPlane(plane) {
  29543. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29544. return this.intersectsPlane(plane);
  29545. },
  29546. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29547. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29548. return this.intersectsSphere(sphere);
  29549. }
  29550. });
  29551. Object.assign(Triangle.prototype, {
  29552. area: function area() {
  29553. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29554. return this.getArea();
  29555. },
  29556. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29557. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29558. return this.getBarycoord(point, target);
  29559. },
  29560. midpoint: function midpoint(target) {
  29561. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29562. return this.getMidpoint(target);
  29563. },
  29564. normal: function normal(target) {
  29565. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29566. return this.getNormal(target);
  29567. },
  29568. plane: function plane(target) {
  29569. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29570. return this.getPlane(target);
  29571. }
  29572. });
  29573. Object.assign(Triangle, {
  29574. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29575. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29576. return Triangle.getBarycoord(point, a, b, c, target);
  29577. },
  29578. normal: function normal(a, b, c, target) {
  29579. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29580. return Triangle.getNormal(a, b, c, target);
  29581. }
  29582. });
  29583. Object.assign(Shape.prototype, {
  29584. extractAllPoints: function extractAllPoints(divisions) {
  29585. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29586. return this.extractPoints(divisions);
  29587. },
  29588. extrude: function extrude(options) {
  29589. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29590. return new ExtrudeGeometry(this, options);
  29591. },
  29592. makeGeometry: function makeGeometry(options) {
  29593. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29594. return new ShapeGeometry(this, options);
  29595. }
  29596. });
  29597. Object.assign(Vector2.prototype, {
  29598. fromAttribute: function fromAttribute(attribute, index, offset) {
  29599. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29600. return this.fromBufferAttribute(attribute, index, offset);
  29601. },
  29602. distanceToManhattan: function distanceToManhattan(v) {
  29603. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29604. return this.manhattanDistanceTo(v);
  29605. },
  29606. lengthManhattan: function lengthManhattan() {
  29607. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29608. return this.manhattanLength();
  29609. }
  29610. });
  29611. Object.assign(Vector3.prototype, {
  29612. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29613. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29614. },
  29615. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29616. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29617. },
  29618. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29619. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29620. return this.setFromMatrixPosition(m);
  29621. },
  29622. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29623. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29624. return this.setFromMatrixScale(m);
  29625. },
  29626. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29627. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29628. return this.setFromMatrixColumn(matrix, index);
  29629. },
  29630. applyProjection: function applyProjection(m) {
  29631. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29632. return this.applyMatrix4(m);
  29633. },
  29634. fromAttribute: function fromAttribute(attribute, index, offset) {
  29635. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29636. return this.fromBufferAttribute(attribute, index, offset);
  29637. },
  29638. distanceToManhattan: function distanceToManhattan(v) {
  29639. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29640. return this.manhattanDistanceTo(v);
  29641. },
  29642. lengthManhattan: function lengthManhattan() {
  29643. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29644. return this.manhattanLength();
  29645. }
  29646. });
  29647. Object.assign(Vector4.prototype, {
  29648. fromAttribute: function fromAttribute(attribute, index, offset) {
  29649. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29650. return this.fromBufferAttribute(attribute, index, offset);
  29651. },
  29652. lengthManhattan: function lengthManhattan() {
  29653. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29654. return this.manhattanLength();
  29655. }
  29656. }); //
  29657. Object.assign(Object3D.prototype, {
  29658. getChildByName: function getChildByName(name) {
  29659. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29660. return this.getObjectByName(name);
  29661. },
  29662. renderDepth: function renderDepth() {
  29663. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29664. },
  29665. translate: function translate(distance, axis) {
  29666. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29667. return this.translateOnAxis(axis, distance);
  29668. },
  29669. getWorldRotation: function getWorldRotation() {
  29670. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29671. },
  29672. applyMatrix: function applyMatrix(matrix) {
  29673. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29674. return this.applyMatrix4(matrix);
  29675. }
  29676. });
  29677. Object.defineProperties(Object3D.prototype, {
  29678. eulerOrder: {
  29679. get: function get() {
  29680. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29681. return this.rotation.order;
  29682. },
  29683. set: function set(value) {
  29684. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29685. this.rotation.order = value;
  29686. }
  29687. },
  29688. useQuaternion: {
  29689. get: function get() {
  29690. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29691. },
  29692. set: function set() {
  29693. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29694. }
  29695. }
  29696. });
  29697. Object.assign(Mesh.prototype, {
  29698. setDrawMode: function setDrawMode() {
  29699. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29700. }
  29701. });
  29702. Object.defineProperties(Mesh.prototype, {
  29703. drawMode: {
  29704. get: function get() {
  29705. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29706. return TrianglesDrawMode;
  29707. },
  29708. set: function set() {
  29709. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29710. }
  29711. }
  29712. });
  29713. Object.defineProperties(LOD.prototype, {
  29714. objects: {
  29715. get: function get() {
  29716. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29717. return this.levels;
  29718. }
  29719. }
  29720. });
  29721. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29722. get: function get() {
  29723. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29724. },
  29725. set: function set() {
  29726. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29727. }
  29728. });
  29729. SkinnedMesh.prototype.initBones = function () {
  29730. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29731. };
  29732. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29733. get: function get() {
  29734. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29735. return this.arcLengthDivisions;
  29736. },
  29737. set: function set(value) {
  29738. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29739. this.arcLengthDivisions = value;
  29740. }
  29741. }); //
  29742. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29743. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29744. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29745. this.setFocalLength(focalLength);
  29746. }; //
  29747. Object.defineProperties(Light.prototype, {
  29748. onlyShadow: {
  29749. set: function set() {
  29750. console.warn('THREE.Light: .onlyShadow has been removed.');
  29751. }
  29752. },
  29753. shadowCameraFov: {
  29754. set: function set(value) {
  29755. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29756. this.shadow.camera.fov = value;
  29757. }
  29758. },
  29759. shadowCameraLeft: {
  29760. set: function set(value) {
  29761. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29762. this.shadow.camera.left = value;
  29763. }
  29764. },
  29765. shadowCameraRight: {
  29766. set: function set(value) {
  29767. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29768. this.shadow.camera.right = value;
  29769. }
  29770. },
  29771. shadowCameraTop: {
  29772. set: function set(value) {
  29773. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29774. this.shadow.camera.top = value;
  29775. }
  29776. },
  29777. shadowCameraBottom: {
  29778. set: function set(value) {
  29779. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29780. this.shadow.camera.bottom = value;
  29781. }
  29782. },
  29783. shadowCameraNear: {
  29784. set: function set(value) {
  29785. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29786. this.shadow.camera.near = value;
  29787. }
  29788. },
  29789. shadowCameraFar: {
  29790. set: function set(value) {
  29791. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29792. this.shadow.camera.far = value;
  29793. }
  29794. },
  29795. shadowCameraVisible: {
  29796. set: function set() {
  29797. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29798. }
  29799. },
  29800. shadowBias: {
  29801. set: function set(value) {
  29802. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29803. this.shadow.bias = value;
  29804. }
  29805. },
  29806. shadowDarkness: {
  29807. set: function set() {
  29808. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29809. }
  29810. },
  29811. shadowMapWidth: {
  29812. set: function set(value) {
  29813. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29814. this.shadow.mapSize.width = value;
  29815. }
  29816. },
  29817. shadowMapHeight: {
  29818. set: function set(value) {
  29819. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29820. this.shadow.mapSize.height = value;
  29821. }
  29822. }
  29823. }); //
  29824. Object.defineProperties(BufferAttribute.prototype, {
  29825. length: {
  29826. get: function get() {
  29827. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29828. return this.array.length;
  29829. }
  29830. },
  29831. dynamic: {
  29832. get: function get() {
  29833. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29834. return this.usage === DynamicDrawUsage;
  29835. },
  29836. set: function set()
  29837. /* value */
  29838. {
  29839. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29840. this.setUsage(DynamicDrawUsage);
  29841. }
  29842. }
  29843. });
  29844. Object.assign(BufferAttribute.prototype, {
  29845. setDynamic: function setDynamic(value) {
  29846. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29847. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29848. return this;
  29849. },
  29850. copyIndicesArray: function copyIndicesArray()
  29851. /* indices */
  29852. {
  29853. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29854. },
  29855. setArray: function setArray()
  29856. /* array */
  29857. {
  29858. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29859. }
  29860. });
  29861. Object.assign(BufferGeometry.prototype, {
  29862. addIndex: function addIndex(index) {
  29863. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29864. this.setIndex(index);
  29865. },
  29866. addAttribute: function addAttribute(name, attribute) {
  29867. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29868. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29869. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29870. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29871. }
  29872. if (name === 'index') {
  29873. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29874. this.setIndex(attribute);
  29875. return this;
  29876. }
  29877. return this.setAttribute(name, attribute);
  29878. },
  29879. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29880. if (indexOffset !== undefined) {
  29881. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29882. }
  29883. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29884. this.addGroup(start, count);
  29885. },
  29886. clearDrawCalls: function clearDrawCalls() {
  29887. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29888. this.clearGroups();
  29889. },
  29890. computeOffsets: function computeOffsets() {
  29891. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29892. },
  29893. removeAttribute: function removeAttribute(name) {
  29894. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29895. return this.deleteAttribute(name);
  29896. },
  29897. applyMatrix: function applyMatrix(matrix) {
  29898. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29899. return this.applyMatrix4(matrix);
  29900. }
  29901. });
  29902. Object.defineProperties(BufferGeometry.prototype, {
  29903. drawcalls: {
  29904. get: function get() {
  29905. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29906. return this.groups;
  29907. }
  29908. },
  29909. offsets: {
  29910. get: function get() {
  29911. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29912. return this.groups;
  29913. }
  29914. }
  29915. });
  29916. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29917. maxInstancedCount: {
  29918. get: function get() {
  29919. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29920. return this.instanceCount;
  29921. },
  29922. set: function set(value) {
  29923. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29924. this.instanceCount = value;
  29925. }
  29926. }
  29927. });
  29928. Object.defineProperties(Raycaster.prototype, {
  29929. linePrecision: {
  29930. get: function get() {
  29931. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29932. return this.params.Line.threshold;
  29933. },
  29934. set: function set(value) {
  29935. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29936. this.params.Line.threshold = value;
  29937. }
  29938. }
  29939. });
  29940. Object.defineProperties(InterleavedBuffer.prototype, {
  29941. dynamic: {
  29942. get: function get() {
  29943. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29944. return this.usage === DynamicDrawUsage;
  29945. },
  29946. set: function set(value) {
  29947. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29948. this.setUsage(value);
  29949. }
  29950. }
  29951. });
  29952. Object.assign(InterleavedBuffer.prototype, {
  29953. setDynamic: function setDynamic(value) {
  29954. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29955. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29956. return this;
  29957. },
  29958. setArray: function setArray()
  29959. /* array */
  29960. {
  29961. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29962. }
  29963. }); //
  29964. Object.assign(ExtrudeGeometry.prototype, {
  29965. getArrays: function getArrays() {
  29966. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  29967. },
  29968. addShapeList: function addShapeList() {
  29969. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  29970. },
  29971. addShape: function addShape() {
  29972. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  29973. }
  29974. }); //
  29975. Object.assign(Scene.prototype, {
  29976. dispose: function dispose() {
  29977. console.error('THREE.Scene: .dispose() has been removed.');
  29978. }
  29979. }); //
  29980. Object.defineProperties(Uniform.prototype, {
  29981. dynamic: {
  29982. set: function set() {
  29983. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29984. }
  29985. },
  29986. onUpdate: {
  29987. value: function value() {
  29988. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29989. return this;
  29990. }
  29991. }
  29992. }); //
  29993. Object.defineProperties(Material.prototype, {
  29994. wrapAround: {
  29995. get: function get() {
  29996. console.warn('THREE.Material: .wrapAround has been removed.');
  29997. },
  29998. set: function set() {
  29999. console.warn('THREE.Material: .wrapAround has been removed.');
  30000. }
  30001. },
  30002. overdraw: {
  30003. get: function get() {
  30004. console.warn('THREE.Material: .overdraw has been removed.');
  30005. },
  30006. set: function set() {
  30007. console.warn('THREE.Material: .overdraw has been removed.');
  30008. }
  30009. },
  30010. wrapRGB: {
  30011. get: function get() {
  30012. console.warn('THREE.Material: .wrapRGB has been removed.');
  30013. return new Color();
  30014. }
  30015. },
  30016. shading: {
  30017. get: function get() {
  30018. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30019. },
  30020. set: function set(value) {
  30021. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30022. this.flatShading = value === FlatShading;
  30023. }
  30024. },
  30025. stencilMask: {
  30026. get: function get() {
  30027. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30028. return this.stencilFuncMask;
  30029. },
  30030. set: function set(value) {
  30031. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30032. this.stencilFuncMask = value;
  30033. }
  30034. }
  30035. });
  30036. Object.defineProperties(MeshPhongMaterial.prototype, {
  30037. metal: {
  30038. get: function get() {
  30039. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30040. return false;
  30041. },
  30042. set: function set() {
  30043. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30044. }
  30045. }
  30046. });
  30047. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30048. transparency: {
  30049. get: function get() {
  30050. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30051. return this.transmission;
  30052. },
  30053. set: function set(value) {
  30054. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30055. this.transmission = value;
  30056. }
  30057. }
  30058. });
  30059. Object.defineProperties(ShaderMaterial.prototype, {
  30060. derivatives: {
  30061. get: function get() {
  30062. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30063. return this.extensions.derivatives;
  30064. },
  30065. set: function set(value) {
  30066. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30067. this.extensions.derivatives = value;
  30068. }
  30069. }
  30070. }); //
  30071. Object.assign(WebGLRenderer.prototype, {
  30072. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  30073. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30074. this.setRenderTarget(renderTarget);
  30075. this.clear(color, depth, stencil);
  30076. },
  30077. animate: function animate(callback) {
  30078. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30079. this.setAnimationLoop(callback);
  30080. },
  30081. getCurrentRenderTarget: function getCurrentRenderTarget() {
  30082. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30083. return this.getRenderTarget();
  30084. },
  30085. getMaxAnisotropy: function getMaxAnisotropy() {
  30086. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30087. return this.capabilities.getMaxAnisotropy();
  30088. },
  30089. getPrecision: function getPrecision() {
  30090. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30091. return this.capabilities.precision;
  30092. },
  30093. resetGLState: function resetGLState() {
  30094. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30095. return this.state.reset();
  30096. },
  30097. supportsFloatTextures: function supportsFloatTextures() {
  30098. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30099. return this.extensions.get('OES_texture_float');
  30100. },
  30101. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30102. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30103. return this.extensions.get('OES_texture_half_float');
  30104. },
  30105. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30106. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30107. return this.extensions.get('OES_standard_derivatives');
  30108. },
  30109. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30110. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30111. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30112. },
  30113. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30114. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30115. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30116. },
  30117. supportsBlendMinMax: function supportsBlendMinMax() {
  30118. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30119. return this.extensions.get('EXT_blend_minmax');
  30120. },
  30121. supportsVertexTextures: function supportsVertexTextures() {
  30122. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30123. return this.capabilities.vertexTextures;
  30124. },
  30125. supportsInstancedArrays: function supportsInstancedArrays() {
  30126. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30127. return this.extensions.get('ANGLE_instanced_arrays');
  30128. },
  30129. enableScissorTest: function enableScissorTest(boolean) {
  30130. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30131. this.setScissorTest(boolean);
  30132. },
  30133. initMaterial: function initMaterial() {
  30134. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30135. },
  30136. addPrePlugin: function addPrePlugin() {
  30137. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30138. },
  30139. addPostPlugin: function addPostPlugin() {
  30140. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30141. },
  30142. updateShadowMap: function updateShadowMap() {
  30143. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30144. },
  30145. setFaceCulling: function setFaceCulling() {
  30146. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30147. },
  30148. allocTextureUnit: function allocTextureUnit() {
  30149. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30150. },
  30151. setTexture: function setTexture() {
  30152. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30153. },
  30154. setTexture2D: function setTexture2D() {
  30155. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30156. },
  30157. setTextureCube: function setTextureCube() {
  30158. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30159. },
  30160. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30161. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30162. return this.getActiveMipmapLevel();
  30163. }
  30164. });
  30165. Object.defineProperties(WebGLRenderer.prototype, {
  30166. shadowMapEnabled: {
  30167. get: function get() {
  30168. return this.shadowMap.enabled;
  30169. },
  30170. set: function set(value) {
  30171. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30172. this.shadowMap.enabled = value;
  30173. }
  30174. },
  30175. shadowMapType: {
  30176. get: function get() {
  30177. return this.shadowMap.type;
  30178. },
  30179. set: function set(value) {
  30180. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30181. this.shadowMap.type = value;
  30182. }
  30183. },
  30184. shadowMapCullFace: {
  30185. get: function get() {
  30186. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30187. return undefined;
  30188. },
  30189. set: function set()
  30190. /* value */
  30191. {
  30192. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30193. }
  30194. },
  30195. context: {
  30196. get: function get() {
  30197. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30198. return this.getContext();
  30199. }
  30200. },
  30201. vr: {
  30202. get: function get() {
  30203. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30204. return this.xr;
  30205. }
  30206. },
  30207. gammaInput: {
  30208. get: function get() {
  30209. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30210. return false;
  30211. },
  30212. set: function set() {
  30213. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30214. }
  30215. },
  30216. gammaOutput: {
  30217. get: function get() {
  30218. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30219. return false;
  30220. },
  30221. set: function set(value) {
  30222. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30223. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30224. }
  30225. },
  30226. toneMappingWhitePoint: {
  30227. get: function get() {
  30228. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30229. return 1.0;
  30230. },
  30231. set: function set() {
  30232. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30233. }
  30234. }
  30235. });
  30236. Object.defineProperties(WebGLShadowMap.prototype, {
  30237. cullFace: {
  30238. get: function get() {
  30239. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30240. return undefined;
  30241. },
  30242. set: function set()
  30243. /* cullFace */
  30244. {
  30245. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30246. }
  30247. },
  30248. renderReverseSided: {
  30249. get: function get() {
  30250. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30251. return undefined;
  30252. },
  30253. set: function set() {
  30254. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30255. }
  30256. },
  30257. renderSingleSided: {
  30258. get: function get() {
  30259. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30260. return undefined;
  30261. },
  30262. set: function set() {
  30263. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30264. }
  30265. }
  30266. });
  30267. function WebGLRenderTargetCube(width, height, options) {
  30268. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30269. return new WebGLCubeRenderTarget(width, options);
  30270. } //
  30271. Object.defineProperties(WebGLRenderTarget.prototype, {
  30272. wrapS: {
  30273. get: function get() {
  30274. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30275. return this.texture.wrapS;
  30276. },
  30277. set: function set(value) {
  30278. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30279. this.texture.wrapS = value;
  30280. }
  30281. },
  30282. wrapT: {
  30283. get: function get() {
  30284. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30285. return this.texture.wrapT;
  30286. },
  30287. set: function set(value) {
  30288. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30289. this.texture.wrapT = value;
  30290. }
  30291. },
  30292. magFilter: {
  30293. get: function get() {
  30294. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30295. return this.texture.magFilter;
  30296. },
  30297. set: function set(value) {
  30298. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30299. this.texture.magFilter = value;
  30300. }
  30301. },
  30302. minFilter: {
  30303. get: function get() {
  30304. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30305. return this.texture.minFilter;
  30306. },
  30307. set: function set(value) {
  30308. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30309. this.texture.minFilter = value;
  30310. }
  30311. },
  30312. anisotropy: {
  30313. get: function get() {
  30314. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30315. return this.texture.anisotropy;
  30316. },
  30317. set: function set(value) {
  30318. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30319. this.texture.anisotropy = value;
  30320. }
  30321. },
  30322. offset: {
  30323. get: function get() {
  30324. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30325. return this.texture.offset;
  30326. },
  30327. set: function set(value) {
  30328. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30329. this.texture.offset = value;
  30330. }
  30331. },
  30332. repeat: {
  30333. get: function get() {
  30334. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30335. return this.texture.repeat;
  30336. },
  30337. set: function set(value) {
  30338. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30339. this.texture.repeat = value;
  30340. }
  30341. },
  30342. format: {
  30343. get: function get() {
  30344. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30345. return this.texture.format;
  30346. },
  30347. set: function set(value) {
  30348. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30349. this.texture.format = value;
  30350. }
  30351. },
  30352. type: {
  30353. get: function get() {
  30354. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30355. return this.texture.type;
  30356. },
  30357. set: function set(value) {
  30358. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30359. this.texture.type = value;
  30360. }
  30361. },
  30362. generateMipmaps: {
  30363. get: function get() {
  30364. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30365. return this.texture.generateMipmaps;
  30366. },
  30367. set: function set(value) {
  30368. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30369. this.texture.generateMipmaps = value;
  30370. }
  30371. }
  30372. }); //
  30373. Object.defineProperties(Audio.prototype, {
  30374. load: {
  30375. value: function value(file) {
  30376. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30377. var scope = this;
  30378. var audioLoader = new AudioLoader();
  30379. audioLoader.load(file, function (buffer) {
  30380. scope.setBuffer(buffer);
  30381. });
  30382. return this;
  30383. }
  30384. },
  30385. startTime: {
  30386. set: function set() {
  30387. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30388. }
  30389. }
  30390. });
  30391. AudioAnalyser.prototype.getData = function () {
  30392. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30393. return this.getFrequencyData();
  30394. }; //
  30395. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30396. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30397. return this.update(renderer, scene);
  30398. };
  30399. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30400. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30401. return this.renderTarget.clear(renderer, color, depth, stencil);
  30402. };
  30403. ImageUtils.crossOrigin = undefined;
  30404. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30405. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30406. var loader = new TextureLoader();
  30407. loader.setCrossOrigin(this.crossOrigin);
  30408. var texture = loader.load(url, onLoad, undefined, onError);
  30409. if (mapping) texture.mapping = mapping;
  30410. return texture;
  30411. };
  30412. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30413. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30414. var loader = new CubeTextureLoader();
  30415. loader.setCrossOrigin(this.crossOrigin);
  30416. var texture = loader.load(urls, onLoad, undefined, onError);
  30417. if (mapping) texture.mapping = mapping;
  30418. return texture;
  30419. };
  30420. ImageUtils.loadCompressedTexture = function () {
  30421. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30422. };
  30423. ImageUtils.loadCompressedTextureCube = function () {
  30424. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30425. }; //
  30426. function CanvasRenderer() {
  30427. console.error('THREE.CanvasRenderer has been removed');
  30428. } //
  30429. function JSONLoader() {
  30430. console.error('THREE.JSONLoader has been removed.');
  30431. } //
  30432. var SceneUtils = {
  30433. createMultiMaterialObject: function createMultiMaterialObject()
  30434. /* geometry, materials */
  30435. {
  30436. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30437. },
  30438. detach: function detach()
  30439. /* child, parent, scene */
  30440. {
  30441. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30442. },
  30443. attach: function attach()
  30444. /* child, scene, parent */
  30445. {
  30446. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30447. }
  30448. }; //
  30449. function LensFlare() {
  30450. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30451. }
  30452. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30453. /* eslint-disable no-undef */
  30454. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30455. detail: {
  30456. revision: REVISION
  30457. }
  30458. }));
  30459. /* eslint-enable no-undef */
  30460. }
  30461. if (typeof window !== 'undefined') {
  30462. if (window.__THREE__) {
  30463. console.warn('WARNING: Multiple instances of Three.js being imported.');
  30464. } else {
  30465. window.__THREE__ = REVISION;
  30466. }
  30467. }
  30468. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30469. exports.AddEquation = AddEquation;
  30470. exports.AddOperation = AddOperation;
  30471. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30472. exports.AdditiveBlending = AdditiveBlending;
  30473. exports.AlphaFormat = AlphaFormat;
  30474. exports.AlwaysDepth = AlwaysDepth;
  30475. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30476. exports.AmbientLight = AmbientLight;
  30477. exports.AmbientLightProbe = AmbientLightProbe;
  30478. exports.AnimationClip = AnimationClip;
  30479. exports.AnimationLoader = AnimationLoader;
  30480. exports.AnimationMixer = AnimationMixer;
  30481. exports.AnimationObjectGroup = AnimationObjectGroup;
  30482. exports.AnimationUtils = AnimationUtils;
  30483. exports.ArcCurve = ArcCurve;
  30484. exports.ArrayCamera = ArrayCamera;
  30485. exports.ArrowHelper = ArrowHelper;
  30486. exports.Audio = Audio;
  30487. exports.AudioAnalyser = AudioAnalyser;
  30488. exports.AudioContext = AudioContext;
  30489. exports.AudioListener = AudioListener;
  30490. exports.AudioLoader = AudioLoader;
  30491. exports.AxesHelper = AxesHelper;
  30492. exports.AxisHelper = AxisHelper;
  30493. exports.BackSide = BackSide;
  30494. exports.BasicDepthPacking = BasicDepthPacking;
  30495. exports.BasicShadowMap = BasicShadowMap;
  30496. exports.BinaryTextureLoader = BinaryTextureLoader;
  30497. exports.Bone = Bone;
  30498. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30499. exports.BoundingBoxHelper = BoundingBoxHelper;
  30500. exports.Box2 = Box2;
  30501. exports.Box3 = Box3;
  30502. exports.Box3Helper = Box3Helper;
  30503. exports.BoxBufferGeometry = BoxGeometry;
  30504. exports.BoxGeometry = BoxGeometry;
  30505. exports.BoxHelper = BoxHelper;
  30506. exports.BufferAttribute = BufferAttribute;
  30507. exports.BufferGeometry = BufferGeometry;
  30508. exports.BufferGeometryLoader = BufferGeometryLoader;
  30509. exports.ByteType = ByteType;
  30510. exports.Cache = Cache;
  30511. exports.Camera = Camera;
  30512. exports.CameraHelper = CameraHelper;
  30513. exports.CanvasRenderer = CanvasRenderer;
  30514. exports.CanvasTexture = CanvasTexture;
  30515. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30516. exports.CineonToneMapping = CineonToneMapping;
  30517. exports.CircleBufferGeometry = CircleGeometry;
  30518. exports.CircleGeometry = CircleGeometry;
  30519. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30520. exports.Clock = Clock;
  30521. exports.Color = Color;
  30522. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30523. exports.CompressedTexture = CompressedTexture;
  30524. exports.CompressedTextureLoader = CompressedTextureLoader;
  30525. exports.ConeBufferGeometry = ConeGeometry;
  30526. exports.ConeGeometry = ConeGeometry;
  30527. exports.CubeCamera = CubeCamera;
  30528. exports.CubeReflectionMapping = CubeReflectionMapping;
  30529. exports.CubeRefractionMapping = CubeRefractionMapping;
  30530. exports.CubeTexture = CubeTexture;
  30531. exports.CubeTextureLoader = CubeTextureLoader;
  30532. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30533. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30534. exports.CubicBezierCurve = CubicBezierCurve;
  30535. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30536. exports.CubicInterpolant = CubicInterpolant;
  30537. exports.CullFaceBack = CullFaceBack;
  30538. exports.CullFaceFront = CullFaceFront;
  30539. exports.CullFaceFrontBack = CullFaceFrontBack;
  30540. exports.CullFaceNone = CullFaceNone;
  30541. exports.Curve = Curve;
  30542. exports.CurvePath = CurvePath;
  30543. exports.CustomBlending = CustomBlending;
  30544. exports.CustomToneMapping = CustomToneMapping;
  30545. exports.CylinderBufferGeometry = CylinderGeometry;
  30546. exports.CylinderGeometry = CylinderGeometry;
  30547. exports.Cylindrical = Cylindrical;
  30548. exports.DataTexture = DataTexture;
  30549. exports.DataTexture2DArray = DataTexture2DArray;
  30550. exports.DataTexture3D = DataTexture3D;
  30551. exports.DataTextureLoader = DataTextureLoader;
  30552. exports.DataUtils = DataUtils;
  30553. exports.DecrementStencilOp = DecrementStencilOp;
  30554. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30555. exports.DefaultLoadingManager = DefaultLoadingManager;
  30556. exports.DepthFormat = DepthFormat;
  30557. exports.DepthStencilFormat = DepthStencilFormat;
  30558. exports.DepthTexture = DepthTexture;
  30559. exports.DirectionalLight = DirectionalLight;
  30560. exports.DirectionalLightHelper = DirectionalLightHelper;
  30561. exports.DiscreteInterpolant = DiscreteInterpolant;
  30562. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30563. exports.DodecahedronGeometry = DodecahedronGeometry;
  30564. exports.DoubleSide = DoubleSide;
  30565. exports.DstAlphaFactor = DstAlphaFactor;
  30566. exports.DstColorFactor = DstColorFactor;
  30567. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30568. exports.DynamicCopyUsage = DynamicCopyUsage;
  30569. exports.DynamicDrawUsage = DynamicDrawUsage;
  30570. exports.DynamicReadUsage = DynamicReadUsage;
  30571. exports.EdgesGeometry = EdgesGeometry;
  30572. exports.EdgesHelper = EdgesHelper;
  30573. exports.EllipseCurve = EllipseCurve;
  30574. exports.EqualDepth = EqualDepth;
  30575. exports.EqualStencilFunc = EqualStencilFunc;
  30576. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30577. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30578. exports.Euler = Euler;
  30579. exports.EventDispatcher = EventDispatcher;
  30580. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30581. exports.ExtrudeGeometry = ExtrudeGeometry;
  30582. exports.FaceColors = FaceColors;
  30583. exports.FileLoader = FileLoader;
  30584. exports.FlatShading = FlatShading;
  30585. exports.Float16BufferAttribute = Float16BufferAttribute;
  30586. exports.Float32Attribute = Float32Attribute;
  30587. exports.Float32BufferAttribute = Float32BufferAttribute;
  30588. exports.Float64Attribute = Float64Attribute;
  30589. exports.Float64BufferAttribute = Float64BufferAttribute;
  30590. exports.FloatType = FloatType;
  30591. exports.Fog = Fog;
  30592. exports.FogExp2 = FogExp2;
  30593. exports.Font = Font;
  30594. exports.FontLoader = FontLoader;
  30595. exports.FrontSide = FrontSide;
  30596. exports.Frustum = Frustum;
  30597. exports.GLBufferAttribute = GLBufferAttribute;
  30598. exports.GLSL1 = GLSL1;
  30599. exports.GLSL3 = GLSL3;
  30600. exports.GammaEncoding = GammaEncoding;
  30601. exports.GreaterDepth = GreaterDepth;
  30602. exports.GreaterEqualDepth = GreaterEqualDepth;
  30603. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30604. exports.GreaterStencilFunc = GreaterStencilFunc;
  30605. exports.GridHelper = GridHelper;
  30606. exports.Group = Group;
  30607. exports.HalfFloatType = HalfFloatType;
  30608. exports.HemisphereLight = HemisphereLight;
  30609. exports.HemisphereLightHelper = HemisphereLightHelper;
  30610. exports.HemisphereLightProbe = HemisphereLightProbe;
  30611. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30612. exports.IcosahedronGeometry = IcosahedronGeometry;
  30613. exports.ImageBitmapLoader = ImageBitmapLoader;
  30614. exports.ImageLoader = ImageLoader;
  30615. exports.ImageUtils = ImageUtils;
  30616. exports.ImmediateRenderObject = ImmediateRenderObject;
  30617. exports.IncrementStencilOp = IncrementStencilOp;
  30618. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30619. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30620. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30621. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30622. exports.InstancedMesh = InstancedMesh;
  30623. exports.Int16Attribute = Int16Attribute;
  30624. exports.Int16BufferAttribute = Int16BufferAttribute;
  30625. exports.Int32Attribute = Int32Attribute;
  30626. exports.Int32BufferAttribute = Int32BufferAttribute;
  30627. exports.Int8Attribute = Int8Attribute;
  30628. exports.Int8BufferAttribute = Int8BufferAttribute;
  30629. exports.IntType = IntType;
  30630. exports.InterleavedBuffer = InterleavedBuffer;
  30631. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30632. exports.Interpolant = Interpolant;
  30633. exports.InterpolateDiscrete = InterpolateDiscrete;
  30634. exports.InterpolateLinear = InterpolateLinear;
  30635. exports.InterpolateSmooth = InterpolateSmooth;
  30636. exports.InvertStencilOp = InvertStencilOp;
  30637. exports.JSONLoader = JSONLoader;
  30638. exports.KeepStencilOp = KeepStencilOp;
  30639. exports.KeyframeTrack = KeyframeTrack;
  30640. exports.LOD = LOD;
  30641. exports.LatheBufferGeometry = LatheGeometry;
  30642. exports.LatheGeometry = LatheGeometry;
  30643. exports.Layers = Layers;
  30644. exports.LensFlare = LensFlare;
  30645. exports.LessDepth = LessDepth;
  30646. exports.LessEqualDepth = LessEqualDepth;
  30647. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30648. exports.LessStencilFunc = LessStencilFunc;
  30649. exports.Light = Light;
  30650. exports.LightProbe = LightProbe;
  30651. exports.Line = Line;
  30652. exports.Line3 = Line3;
  30653. exports.LineBasicMaterial = LineBasicMaterial;
  30654. exports.LineCurve = LineCurve;
  30655. exports.LineCurve3 = LineCurve3;
  30656. exports.LineDashedMaterial = LineDashedMaterial;
  30657. exports.LineLoop = LineLoop;
  30658. exports.LinePieces = LinePieces;
  30659. exports.LineSegments = LineSegments;
  30660. exports.LineStrip = LineStrip;
  30661. exports.LinearEncoding = LinearEncoding;
  30662. exports.LinearFilter = LinearFilter;
  30663. exports.LinearInterpolant = LinearInterpolant;
  30664. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30665. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30666. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30667. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30668. exports.LinearToneMapping = LinearToneMapping;
  30669. exports.Loader = Loader;
  30670. exports.LoaderUtils = LoaderUtils;
  30671. exports.LoadingManager = LoadingManager;
  30672. exports.LogLuvEncoding = LogLuvEncoding;
  30673. exports.LoopOnce = LoopOnce;
  30674. exports.LoopPingPong = LoopPingPong;
  30675. exports.LoopRepeat = LoopRepeat;
  30676. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30677. exports.LuminanceFormat = LuminanceFormat;
  30678. exports.MOUSE = MOUSE;
  30679. exports.Material = Material;
  30680. exports.MaterialLoader = MaterialLoader;
  30681. exports.Math = MathUtils;
  30682. exports.MathUtils = MathUtils;
  30683. exports.Matrix3 = Matrix3;
  30684. exports.Matrix4 = Matrix4;
  30685. exports.MaxEquation = MaxEquation;
  30686. exports.Mesh = Mesh;
  30687. exports.MeshBasicMaterial = MeshBasicMaterial;
  30688. exports.MeshDepthMaterial = MeshDepthMaterial;
  30689. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30690. exports.MeshFaceMaterial = MeshFaceMaterial;
  30691. exports.MeshLambertMaterial = MeshLambertMaterial;
  30692. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30693. exports.MeshNormalMaterial = MeshNormalMaterial;
  30694. exports.MeshPhongMaterial = MeshPhongMaterial;
  30695. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30696. exports.MeshStandardMaterial = MeshStandardMaterial;
  30697. exports.MeshToonMaterial = MeshToonMaterial;
  30698. exports.MinEquation = MinEquation;
  30699. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30700. exports.MixOperation = MixOperation;
  30701. exports.MultiMaterial = MultiMaterial;
  30702. exports.MultiplyBlending = MultiplyBlending;
  30703. exports.MultiplyOperation = MultiplyOperation;
  30704. exports.NearestFilter = NearestFilter;
  30705. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30706. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30707. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30708. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30709. exports.NeverDepth = NeverDepth;
  30710. exports.NeverStencilFunc = NeverStencilFunc;
  30711. exports.NoBlending = NoBlending;
  30712. exports.NoColors = NoColors;
  30713. exports.NoToneMapping = NoToneMapping;
  30714. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30715. exports.NormalBlending = NormalBlending;
  30716. exports.NotEqualDepth = NotEqualDepth;
  30717. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30718. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30719. exports.Object3D = Object3D;
  30720. exports.ObjectLoader = ObjectLoader;
  30721. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30722. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30723. exports.OctahedronGeometry = OctahedronGeometry;
  30724. exports.OneFactor = OneFactor;
  30725. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30726. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30727. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30728. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30729. exports.OrthographicCamera = OrthographicCamera;
  30730. exports.PCFShadowMap = PCFShadowMap;
  30731. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30732. exports.PMREMGenerator = PMREMGenerator;
  30733. exports.ParametricBufferGeometry = ParametricGeometry;
  30734. exports.ParametricGeometry = ParametricGeometry;
  30735. exports.Particle = Particle;
  30736. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30737. exports.ParticleSystem = ParticleSystem;
  30738. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30739. exports.Path = Path;
  30740. exports.PerspectiveCamera = PerspectiveCamera;
  30741. exports.Plane = Plane;
  30742. exports.PlaneBufferGeometry = PlaneGeometry;
  30743. exports.PlaneGeometry = PlaneGeometry;
  30744. exports.PlaneHelper = PlaneHelper;
  30745. exports.PointCloud = PointCloud;
  30746. exports.PointCloudMaterial = PointCloudMaterial;
  30747. exports.PointLight = PointLight;
  30748. exports.PointLightHelper = PointLightHelper;
  30749. exports.Points = Points;
  30750. exports.PointsMaterial = PointsMaterial;
  30751. exports.PolarGridHelper = PolarGridHelper;
  30752. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30753. exports.PolyhedronGeometry = PolyhedronGeometry;
  30754. exports.PositionalAudio = PositionalAudio;
  30755. exports.PropertyBinding = PropertyBinding;
  30756. exports.PropertyMixer = PropertyMixer;
  30757. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30758. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30759. exports.Quaternion = Quaternion;
  30760. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30761. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30762. exports.REVISION = REVISION;
  30763. exports.RGBADepthPacking = RGBADepthPacking;
  30764. exports.RGBAFormat = RGBAFormat;
  30765. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30766. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30767. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30768. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30769. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30770. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30771. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30772. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30773. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30774. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30775. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30776. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30777. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30778. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30779. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30780. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30781. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30782. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30783. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30784. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30785. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30786. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30787. exports.RGBDEncoding = RGBDEncoding;
  30788. exports.RGBEEncoding = RGBEEncoding;
  30789. exports.RGBEFormat = RGBEFormat;
  30790. exports.RGBFormat = RGBFormat;
  30791. exports.RGBIntegerFormat = RGBIntegerFormat;
  30792. exports.RGBM16Encoding = RGBM16Encoding;
  30793. exports.RGBM7Encoding = RGBM7Encoding;
  30794. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30795. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30796. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30797. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30798. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30799. exports.RGFormat = RGFormat;
  30800. exports.RGIntegerFormat = RGIntegerFormat;
  30801. exports.RawShaderMaterial = RawShaderMaterial;
  30802. exports.Ray = Ray;
  30803. exports.Raycaster = Raycaster;
  30804. exports.RectAreaLight = RectAreaLight;
  30805. exports.RedFormat = RedFormat;
  30806. exports.RedIntegerFormat = RedIntegerFormat;
  30807. exports.ReinhardToneMapping = ReinhardToneMapping;
  30808. exports.RepeatWrapping = RepeatWrapping;
  30809. exports.ReplaceStencilOp = ReplaceStencilOp;
  30810. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30811. exports.RingBufferGeometry = RingGeometry;
  30812. exports.RingGeometry = RingGeometry;
  30813. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30814. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30815. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30816. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30817. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30818. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30819. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30820. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30821. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30822. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30823. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30824. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30825. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30826. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30827. exports.Scene = Scene;
  30828. exports.SceneUtils = SceneUtils;
  30829. exports.ShaderChunk = ShaderChunk;
  30830. exports.ShaderLib = ShaderLib;
  30831. exports.ShaderMaterial = ShaderMaterial;
  30832. exports.ShadowMaterial = ShadowMaterial;
  30833. exports.Shape = Shape;
  30834. exports.ShapeBufferGeometry = ShapeGeometry;
  30835. exports.ShapeGeometry = ShapeGeometry;
  30836. exports.ShapePath = ShapePath;
  30837. exports.ShapeUtils = ShapeUtils;
  30838. exports.ShortType = ShortType;
  30839. exports.Skeleton = Skeleton;
  30840. exports.SkeletonHelper = SkeletonHelper;
  30841. exports.SkinnedMesh = SkinnedMesh;
  30842. exports.SmoothShading = SmoothShading;
  30843. exports.Sphere = Sphere;
  30844. exports.SphereBufferGeometry = SphereGeometry;
  30845. exports.SphereGeometry = SphereGeometry;
  30846. exports.Spherical = Spherical;
  30847. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30848. exports.SplineCurve = SplineCurve;
  30849. exports.SpotLight = SpotLight;
  30850. exports.SpotLightHelper = SpotLightHelper;
  30851. exports.Sprite = Sprite;
  30852. exports.SpriteMaterial = SpriteMaterial;
  30853. exports.SrcAlphaFactor = SrcAlphaFactor;
  30854. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30855. exports.SrcColorFactor = SrcColorFactor;
  30856. exports.StaticCopyUsage = StaticCopyUsage;
  30857. exports.StaticDrawUsage = StaticDrawUsage;
  30858. exports.StaticReadUsage = StaticReadUsage;
  30859. exports.StereoCamera = StereoCamera;
  30860. exports.StreamCopyUsage = StreamCopyUsage;
  30861. exports.StreamDrawUsage = StreamDrawUsage;
  30862. exports.StreamReadUsage = StreamReadUsage;
  30863. exports.StringKeyframeTrack = StringKeyframeTrack;
  30864. exports.SubtractEquation = SubtractEquation;
  30865. exports.SubtractiveBlending = SubtractiveBlending;
  30866. exports.TOUCH = TOUCH;
  30867. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30868. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  30869. exports.TetrahedronGeometry = TetrahedronGeometry;
  30870. exports.TextBufferGeometry = TextGeometry;
  30871. exports.TextGeometry = TextGeometry;
  30872. exports.Texture = Texture;
  30873. exports.TextureLoader = TextureLoader;
  30874. exports.TorusBufferGeometry = TorusGeometry;
  30875. exports.TorusGeometry = TorusGeometry;
  30876. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  30877. exports.TorusKnotGeometry = TorusKnotGeometry;
  30878. exports.Triangle = Triangle;
  30879. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30880. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30881. exports.TrianglesDrawMode = TrianglesDrawMode;
  30882. exports.TubeBufferGeometry = TubeGeometry;
  30883. exports.TubeGeometry = TubeGeometry;
  30884. exports.UVMapping = UVMapping;
  30885. exports.Uint16Attribute = Uint16Attribute;
  30886. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30887. exports.Uint32Attribute = Uint32Attribute;
  30888. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30889. exports.Uint8Attribute = Uint8Attribute;
  30890. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30891. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30892. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30893. exports.Uniform = Uniform;
  30894. exports.UniformsLib = UniformsLib;
  30895. exports.UniformsUtils = UniformsUtils;
  30896. exports.UnsignedByteType = UnsignedByteType;
  30897. exports.UnsignedInt248Type = UnsignedInt248Type;
  30898. exports.UnsignedIntType = UnsignedIntType;
  30899. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30900. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30901. exports.UnsignedShort565Type = UnsignedShort565Type;
  30902. exports.UnsignedShortType = UnsignedShortType;
  30903. exports.VSMShadowMap = VSMShadowMap;
  30904. exports.Vector2 = Vector2;
  30905. exports.Vector3 = Vector3;
  30906. exports.Vector4 = Vector4;
  30907. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30908. exports.Vertex = Vertex;
  30909. exports.VertexColors = VertexColors;
  30910. exports.VideoTexture = VideoTexture;
  30911. exports.WebGL1Renderer = WebGL1Renderer;
  30912. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30913. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30914. exports.WebGLRenderTarget = WebGLRenderTarget;
  30915. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30916. exports.WebGLRenderer = WebGLRenderer;
  30917. exports.WebGLUtils = WebGLUtils;
  30918. exports.WireframeGeometry = WireframeGeometry;
  30919. exports.WireframeHelper = WireframeHelper;
  30920. exports.WrapAroundEnding = WrapAroundEnding;
  30921. exports.XHRLoader = XHRLoader;
  30922. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30923. exports.ZeroFactor = ZeroFactor;
  30924. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30925. exports.ZeroStencilOp = ZeroStencilOp;
  30926. exports.sRGBEncoding = sRGBEncoding;
  30927. Object.defineProperty(exports, '__esModule', { value: true });
  30928. })));