three.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. var REVISION = '125dev';
  55. var MOUSE = {
  56. LEFT: 0,
  57. MIDDLE: 1,
  58. RIGHT: 2,
  59. ROTATE: 0,
  60. DOLLY: 1,
  61. PAN: 2
  62. };
  63. var TOUCH = {
  64. ROTATE: 0,
  65. PAN: 1,
  66. DOLLY_PAN: 2,
  67. DOLLY_ROTATE: 3
  68. };
  69. var CullFaceNone = 0;
  70. var CullFaceBack = 1;
  71. var CullFaceFront = 2;
  72. var CullFaceFrontBack = 3;
  73. var BasicShadowMap = 0;
  74. var PCFShadowMap = 1;
  75. var PCFSoftShadowMap = 2;
  76. var VSMShadowMap = 3;
  77. var FrontSide = 0;
  78. var BackSide = 1;
  79. var DoubleSide = 2;
  80. var FlatShading = 1;
  81. var SmoothShading = 2;
  82. var NoBlending = 0;
  83. var NormalBlending = 1;
  84. var AdditiveBlending = 2;
  85. var SubtractiveBlending = 3;
  86. var MultiplyBlending = 4;
  87. var CustomBlending = 5;
  88. var AddEquation = 100;
  89. var SubtractEquation = 101;
  90. var ReverseSubtractEquation = 102;
  91. var MinEquation = 103;
  92. var MaxEquation = 104;
  93. var ZeroFactor = 200;
  94. var OneFactor = 201;
  95. var SrcColorFactor = 202;
  96. var OneMinusSrcColorFactor = 203;
  97. var SrcAlphaFactor = 204;
  98. var OneMinusSrcAlphaFactor = 205;
  99. var DstAlphaFactor = 206;
  100. var OneMinusDstAlphaFactor = 207;
  101. var DstColorFactor = 208;
  102. var OneMinusDstColorFactor = 209;
  103. var SrcAlphaSaturateFactor = 210;
  104. var NeverDepth = 0;
  105. var AlwaysDepth = 1;
  106. var LessDepth = 2;
  107. var LessEqualDepth = 3;
  108. var EqualDepth = 4;
  109. var GreaterEqualDepth = 5;
  110. var GreaterDepth = 6;
  111. var NotEqualDepth = 7;
  112. var MultiplyOperation = 0;
  113. var MixOperation = 1;
  114. var AddOperation = 2;
  115. var NoToneMapping = 0;
  116. var LinearToneMapping = 1;
  117. var ReinhardToneMapping = 2;
  118. var CineonToneMapping = 3;
  119. var ACESFilmicToneMapping = 4;
  120. var CustomToneMapping = 5;
  121. var UVMapping = 300;
  122. var CubeReflectionMapping = 301;
  123. var CubeRefractionMapping = 302;
  124. var EquirectangularReflectionMapping = 303;
  125. var EquirectangularRefractionMapping = 304;
  126. var CubeUVReflectionMapping = 306;
  127. var CubeUVRefractionMapping = 307;
  128. var RepeatWrapping = 1000;
  129. var ClampToEdgeWrapping = 1001;
  130. var MirroredRepeatWrapping = 1002;
  131. var NearestFilter = 1003;
  132. var NearestMipmapNearestFilter = 1004;
  133. var NearestMipMapNearestFilter = 1004;
  134. var NearestMipmapLinearFilter = 1005;
  135. var NearestMipMapLinearFilter = 1005;
  136. var LinearFilter = 1006;
  137. var LinearMipmapNearestFilter = 1007;
  138. var LinearMipMapNearestFilter = 1007;
  139. var LinearMipmapLinearFilter = 1008;
  140. var LinearMipMapLinearFilter = 1008;
  141. var UnsignedByteType = 1009;
  142. var ByteType = 1010;
  143. var ShortType = 1011;
  144. var UnsignedShortType = 1012;
  145. var IntType = 1013;
  146. var UnsignedIntType = 1014;
  147. var FloatType = 1015;
  148. var HalfFloatType = 1016;
  149. var UnsignedShort4444Type = 1017;
  150. var UnsignedShort5551Type = 1018;
  151. var UnsignedShort565Type = 1019;
  152. var UnsignedInt248Type = 1020;
  153. var AlphaFormat = 1021;
  154. var RGBFormat = 1022;
  155. var RGBAFormat = 1023;
  156. var LuminanceFormat = 1024;
  157. var LuminanceAlphaFormat = 1025;
  158. var RGBEFormat = RGBAFormat;
  159. var DepthFormat = 1026;
  160. var DepthStencilFormat = 1027;
  161. var RedFormat = 1028;
  162. var RedIntegerFormat = 1029;
  163. var RGFormat = 1030;
  164. var RGIntegerFormat = 1031;
  165. var RGBIntegerFormat = 1032;
  166. var RGBAIntegerFormat = 1033;
  167. var RGB_S3TC_DXT1_Format = 33776;
  168. var RGBA_S3TC_DXT1_Format = 33777;
  169. var RGBA_S3TC_DXT3_Format = 33778;
  170. var RGBA_S3TC_DXT5_Format = 33779;
  171. var RGB_PVRTC_4BPPV1_Format = 35840;
  172. var RGB_PVRTC_2BPPV1_Format = 35841;
  173. var RGBA_PVRTC_4BPPV1_Format = 35842;
  174. var RGBA_PVRTC_2BPPV1_Format = 35843;
  175. var RGB_ETC1_Format = 36196;
  176. var RGB_ETC2_Format = 37492;
  177. var RGBA_ETC2_EAC_Format = 37496;
  178. var RGBA_ASTC_4x4_Format = 37808;
  179. var RGBA_ASTC_5x4_Format = 37809;
  180. var RGBA_ASTC_5x5_Format = 37810;
  181. var RGBA_ASTC_6x5_Format = 37811;
  182. var RGBA_ASTC_6x6_Format = 37812;
  183. var RGBA_ASTC_8x5_Format = 37813;
  184. var RGBA_ASTC_8x6_Format = 37814;
  185. var RGBA_ASTC_8x8_Format = 37815;
  186. var RGBA_ASTC_10x5_Format = 37816;
  187. var RGBA_ASTC_10x6_Format = 37817;
  188. var RGBA_ASTC_10x8_Format = 37818;
  189. var RGBA_ASTC_10x10_Format = 37819;
  190. var RGBA_ASTC_12x10_Format = 37820;
  191. var RGBA_ASTC_12x12_Format = 37821;
  192. var RGBA_BPTC_Format = 36492;
  193. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  194. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  195. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  196. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  197. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  198. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  199. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  200. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  201. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  202. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  203. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  204. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  205. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  206. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  207. var LoopOnce = 2200;
  208. var LoopRepeat = 2201;
  209. var LoopPingPong = 2202;
  210. var InterpolateDiscrete = 2300;
  211. var InterpolateLinear = 2301;
  212. var InterpolateSmooth = 2302;
  213. var ZeroCurvatureEnding = 2400;
  214. var ZeroSlopeEnding = 2401;
  215. var WrapAroundEnding = 2402;
  216. var NormalAnimationBlendMode = 2500;
  217. var AdditiveAnimationBlendMode = 2501;
  218. var TrianglesDrawMode = 0;
  219. var TriangleStripDrawMode = 1;
  220. var TriangleFanDrawMode = 2;
  221. var LinearEncoding = 3000;
  222. var sRGBEncoding = 3001;
  223. var GammaEncoding = 3007;
  224. var RGBEEncoding = 3002;
  225. var LogLuvEncoding = 3003;
  226. var RGBM7Encoding = 3004;
  227. var RGBM16Encoding = 3005;
  228. var RGBDEncoding = 3006;
  229. var BasicDepthPacking = 3200;
  230. var RGBADepthPacking = 3201;
  231. var TangentSpaceNormalMap = 0;
  232. var ObjectSpaceNormalMap = 1;
  233. var ZeroStencilOp = 0;
  234. var KeepStencilOp = 7680;
  235. var ReplaceStencilOp = 7681;
  236. var IncrementStencilOp = 7682;
  237. var DecrementStencilOp = 7683;
  238. var IncrementWrapStencilOp = 34055;
  239. var DecrementWrapStencilOp = 34056;
  240. var InvertStencilOp = 5386;
  241. var NeverStencilFunc = 512;
  242. var LessStencilFunc = 513;
  243. var EqualStencilFunc = 514;
  244. var LessEqualStencilFunc = 515;
  245. var GreaterStencilFunc = 516;
  246. var NotEqualStencilFunc = 517;
  247. var GreaterEqualStencilFunc = 518;
  248. var AlwaysStencilFunc = 519;
  249. var StaticDrawUsage = 35044;
  250. var DynamicDrawUsage = 35048;
  251. var StreamDrawUsage = 35040;
  252. var StaticReadUsage = 35045;
  253. var DynamicReadUsage = 35049;
  254. var StreamReadUsage = 35041;
  255. var StaticCopyUsage = 35046;
  256. var DynamicCopyUsage = 35050;
  257. var StreamCopyUsage = 35042;
  258. var GLSL1 = '100';
  259. var GLSL3 = '300 es';
  260. /**
  261. * https://github.com/mrdoob/eventdispatcher.js/
  262. */
  263. function EventDispatcher() {}
  264. Object.assign(EventDispatcher.prototype, {
  265. addEventListener: function addEventListener(type, listener) {
  266. if (this._listeners === undefined) this._listeners = {};
  267. var listeners = this._listeners;
  268. if (listeners[type] === undefined) {
  269. listeners[type] = [];
  270. }
  271. if (listeners[type].indexOf(listener) === -1) {
  272. listeners[type].push(listener);
  273. }
  274. },
  275. hasEventListener: function hasEventListener(type, listener) {
  276. if (this._listeners === undefined) return false;
  277. var listeners = this._listeners;
  278. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  279. },
  280. removeEventListener: function removeEventListener(type, listener) {
  281. if (this._listeners === undefined) return;
  282. var listeners = this._listeners;
  283. var listenerArray = listeners[type];
  284. if (listenerArray !== undefined) {
  285. var index = listenerArray.indexOf(listener);
  286. if (index !== -1) {
  287. listenerArray.splice(index, 1);
  288. }
  289. }
  290. },
  291. dispatchEvent: function dispatchEvent(event) {
  292. if (this._listeners === undefined) return;
  293. var listeners = this._listeners;
  294. var listenerArray = listeners[event.type];
  295. if (listenerArray !== undefined) {
  296. event.target = this; // Make a copy, in case listeners are removed while iterating.
  297. var array = listenerArray.slice(0);
  298. for (var i = 0, l = array.length; i < l; i++) {
  299. array[i].call(this, event);
  300. }
  301. }
  302. }
  303. });
  304. var _lut = [];
  305. for (var i = 0; i < 256; i++) {
  306. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  307. }
  308. var _seed = 1234567;
  309. var MathUtils = {
  310. DEG2RAD: Math.PI / 180,
  311. RAD2DEG: 180 / Math.PI,
  312. generateUUID: function generateUUID() {
  313. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  314. var d0 = Math.random() * 0xffffffff | 0;
  315. var d1 = Math.random() * 0xffffffff | 0;
  316. var d2 = Math.random() * 0xffffffff | 0;
  317. var d3 = Math.random() * 0xffffffff | 0;
  318. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  319. return uuid.toUpperCase();
  320. },
  321. clamp: function clamp(value, min, max) {
  322. return Math.max(min, Math.min(max, value));
  323. },
  324. // compute euclidian modulo of m % n
  325. // https://en.wikipedia.org/wiki/Modulo_operation
  326. euclideanModulo: function euclideanModulo(n, m) {
  327. return (n % m + m) % m;
  328. },
  329. // Linear mapping from range <a1, a2> to range <b1, b2>
  330. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  331. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  332. },
  333. // https://en.wikipedia.org/wiki/Linear_interpolation
  334. lerp: function lerp(x, y, t) {
  335. return (1 - t) * x + t * y;
  336. },
  337. // http://en.wikipedia.org/wiki/Smoothstep
  338. smoothstep: function smoothstep(x, min, max) {
  339. if (x <= min) return 0;
  340. if (x >= max) return 1;
  341. x = (x - min) / (max - min);
  342. return x * x * (3 - 2 * x);
  343. },
  344. smootherstep: function smootherstep(x, min, max) {
  345. if (x <= min) return 0;
  346. if (x >= max) return 1;
  347. x = (x - min) / (max - min);
  348. return x * x * x * (x * (x * 6 - 15) + 10);
  349. },
  350. // Random integer from <low, high> interval
  351. randInt: function randInt(low, high) {
  352. return low + Math.floor(Math.random() * (high - low + 1));
  353. },
  354. // Random float from <low, high> interval
  355. randFloat: function randFloat(low, high) {
  356. return low + Math.random() * (high - low);
  357. },
  358. // Random float from <-range/2, range/2> interval
  359. randFloatSpread: function randFloatSpread(range) {
  360. return range * (0.5 - Math.random());
  361. },
  362. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  363. seededRandom: function seededRandom(s) {
  364. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  365. _seed = _seed * 16807 % 2147483647;
  366. return (_seed - 1) / 2147483646;
  367. },
  368. degToRad: function degToRad(degrees) {
  369. return degrees * MathUtils.DEG2RAD;
  370. },
  371. radToDeg: function radToDeg(radians) {
  372. return radians * MathUtils.RAD2DEG;
  373. },
  374. isPowerOfTwo: function isPowerOfTwo(value) {
  375. return (value & value - 1) === 0 && value !== 0;
  376. },
  377. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  378. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  379. },
  380. floorPowerOfTwo: function floorPowerOfTwo(value) {
  381. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  382. },
  383. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  384. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  385. // rotations are applied to the axes in the order specified by 'order'
  386. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  387. // angles are in radians
  388. var cos = Math.cos;
  389. var sin = Math.sin;
  390. var c2 = cos(b / 2);
  391. var s2 = sin(b / 2);
  392. var c13 = cos((a + c) / 2);
  393. var s13 = sin((a + c) / 2);
  394. var c1_3 = cos((a - c) / 2);
  395. var s1_3 = sin((a - c) / 2);
  396. var c3_1 = cos((c - a) / 2);
  397. var s3_1 = sin((c - a) / 2);
  398. switch (order) {
  399. case 'XYX':
  400. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  401. break;
  402. case 'YZY':
  403. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  404. break;
  405. case 'ZXZ':
  406. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  407. break;
  408. case 'XZX':
  409. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  410. break;
  411. case 'YXY':
  412. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  413. break;
  414. case 'ZYZ':
  415. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  416. break;
  417. default:
  418. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  419. }
  420. }
  421. };
  422. function _defineProperties(target, props) {
  423. for (var i = 0; i < props.length; i++) {
  424. var descriptor = props[i];
  425. descriptor.enumerable = descriptor.enumerable || false;
  426. descriptor.configurable = true;
  427. if ("value" in descriptor) descriptor.writable = true;
  428. Object.defineProperty(target, descriptor.key, descriptor);
  429. }
  430. }
  431. function _createClass(Constructor, protoProps, staticProps) {
  432. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  433. if (staticProps) _defineProperties(Constructor, staticProps);
  434. return Constructor;
  435. }
  436. function _inheritsLoose(subClass, superClass) {
  437. subClass.prototype = Object.create(superClass.prototype);
  438. subClass.prototype.constructor = subClass;
  439. subClass.__proto__ = superClass;
  440. }
  441. function _assertThisInitialized(self) {
  442. if (self === void 0) {
  443. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  444. }
  445. return self;
  446. }
  447. var Vector2 = /*#__PURE__*/function () {
  448. function Vector2(x, y) {
  449. if (x === void 0) {
  450. x = 0;
  451. }
  452. if (y === void 0) {
  453. y = 0;
  454. }
  455. Object.defineProperty(this, 'isVector2', {
  456. value: true
  457. });
  458. this.x = x;
  459. this.y = y;
  460. }
  461. var _proto = Vector2.prototype;
  462. _proto.set = function set(x, y) {
  463. this.x = x;
  464. this.y = y;
  465. return this;
  466. };
  467. _proto.setScalar = function setScalar(scalar) {
  468. this.x = scalar;
  469. this.y = scalar;
  470. return this;
  471. };
  472. _proto.setX = function setX(x) {
  473. this.x = x;
  474. return this;
  475. };
  476. _proto.setY = function setY(y) {
  477. this.y = y;
  478. return this;
  479. };
  480. _proto.setComponent = function setComponent(index, value) {
  481. switch (index) {
  482. case 0:
  483. this.x = value;
  484. break;
  485. case 1:
  486. this.y = value;
  487. break;
  488. default:
  489. throw new Error('index is out of range: ' + index);
  490. }
  491. return this;
  492. };
  493. _proto.getComponent = function getComponent(index) {
  494. switch (index) {
  495. case 0:
  496. return this.x;
  497. case 1:
  498. return this.y;
  499. default:
  500. throw new Error('index is out of range: ' + index);
  501. }
  502. };
  503. _proto.clone = function clone() {
  504. return new this.constructor(this.x, this.y);
  505. };
  506. _proto.copy = function copy(v) {
  507. this.x = v.x;
  508. this.y = v.y;
  509. return this;
  510. };
  511. _proto.add = function add(v, w) {
  512. if (w !== undefined) {
  513. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  514. return this.addVectors(v, w);
  515. }
  516. this.x += v.x;
  517. this.y += v.y;
  518. return this;
  519. };
  520. _proto.addScalar = function addScalar(s) {
  521. this.x += s;
  522. this.y += s;
  523. return this;
  524. };
  525. _proto.addVectors = function addVectors(a, b) {
  526. this.x = a.x + b.x;
  527. this.y = a.y + b.y;
  528. return this;
  529. };
  530. _proto.addScaledVector = function addScaledVector(v, s) {
  531. this.x += v.x * s;
  532. this.y += v.y * s;
  533. return this;
  534. };
  535. _proto.sub = function sub(v, w) {
  536. if (w !== undefined) {
  537. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  538. return this.subVectors(v, w);
  539. }
  540. this.x -= v.x;
  541. this.y -= v.y;
  542. return this;
  543. };
  544. _proto.subScalar = function subScalar(s) {
  545. this.x -= s;
  546. this.y -= s;
  547. return this;
  548. };
  549. _proto.subVectors = function subVectors(a, b) {
  550. this.x = a.x - b.x;
  551. this.y = a.y - b.y;
  552. return this;
  553. };
  554. _proto.multiply = function multiply(v) {
  555. this.x *= v.x;
  556. this.y *= v.y;
  557. return this;
  558. };
  559. _proto.multiplyScalar = function multiplyScalar(scalar) {
  560. this.x *= scalar;
  561. this.y *= scalar;
  562. return this;
  563. };
  564. _proto.divide = function divide(v) {
  565. this.x /= v.x;
  566. this.y /= v.y;
  567. return this;
  568. };
  569. _proto.divideScalar = function divideScalar(scalar) {
  570. return this.multiplyScalar(1 / scalar);
  571. };
  572. _proto.applyMatrix3 = function applyMatrix3(m) {
  573. var x = this.x,
  574. y = this.y;
  575. var e = m.elements;
  576. this.x = e[0] * x + e[3] * y + e[6];
  577. this.y = e[1] * x + e[4] * y + e[7];
  578. return this;
  579. };
  580. _proto.min = function min(v) {
  581. this.x = Math.min(this.x, v.x);
  582. this.y = Math.min(this.y, v.y);
  583. return this;
  584. };
  585. _proto.max = function max(v) {
  586. this.x = Math.max(this.x, v.x);
  587. this.y = Math.max(this.y, v.y);
  588. return this;
  589. };
  590. _proto.clamp = function clamp(min, max) {
  591. // assumes min < max, componentwise
  592. this.x = Math.max(min.x, Math.min(max.x, this.x));
  593. this.y = Math.max(min.y, Math.min(max.y, this.y));
  594. return this;
  595. };
  596. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  597. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  598. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  599. return this;
  600. };
  601. _proto.clampLength = function clampLength(min, max) {
  602. var length = this.length();
  603. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  604. };
  605. _proto.floor = function floor() {
  606. this.x = Math.floor(this.x);
  607. this.y = Math.floor(this.y);
  608. return this;
  609. };
  610. _proto.ceil = function ceil() {
  611. this.x = Math.ceil(this.x);
  612. this.y = Math.ceil(this.y);
  613. return this;
  614. };
  615. _proto.round = function round() {
  616. this.x = Math.round(this.x);
  617. this.y = Math.round(this.y);
  618. return this;
  619. };
  620. _proto.roundToZero = function roundToZero() {
  621. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  622. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  623. return this;
  624. };
  625. _proto.negate = function negate() {
  626. this.x = -this.x;
  627. this.y = -this.y;
  628. return this;
  629. };
  630. _proto.dot = function dot(v) {
  631. return this.x * v.x + this.y * v.y;
  632. };
  633. _proto.cross = function cross(v) {
  634. return this.x * v.y - this.y * v.x;
  635. };
  636. _proto.lengthSq = function lengthSq() {
  637. return this.x * this.x + this.y * this.y;
  638. };
  639. _proto.length = function length() {
  640. return Math.sqrt(this.x * this.x + this.y * this.y);
  641. };
  642. _proto.manhattanLength = function manhattanLength() {
  643. return Math.abs(this.x) + Math.abs(this.y);
  644. };
  645. _proto.normalize = function normalize() {
  646. return this.divideScalar(this.length() || 1);
  647. };
  648. _proto.angle = function angle() {
  649. // computes the angle in radians with respect to the positive x-axis
  650. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  651. return angle;
  652. };
  653. _proto.distanceTo = function distanceTo(v) {
  654. return Math.sqrt(this.distanceToSquared(v));
  655. };
  656. _proto.distanceToSquared = function distanceToSquared(v) {
  657. var dx = this.x - v.x,
  658. dy = this.y - v.y;
  659. return dx * dx + dy * dy;
  660. };
  661. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  662. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  663. };
  664. _proto.setLength = function setLength(length) {
  665. return this.normalize().multiplyScalar(length);
  666. };
  667. _proto.lerp = function lerp(v, alpha) {
  668. this.x += (v.x - this.x) * alpha;
  669. this.y += (v.y - this.y) * alpha;
  670. return this;
  671. };
  672. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  673. this.x = v1.x + (v2.x - v1.x) * alpha;
  674. this.y = v1.y + (v2.y - v1.y) * alpha;
  675. return this;
  676. };
  677. _proto.equals = function equals(v) {
  678. return v.x === this.x && v.y === this.y;
  679. };
  680. _proto.fromArray = function fromArray(array, offset) {
  681. if (offset === void 0) {
  682. offset = 0;
  683. }
  684. this.x = array[offset];
  685. this.y = array[offset + 1];
  686. return this;
  687. };
  688. _proto.toArray = function toArray(array, offset) {
  689. if (array === void 0) {
  690. array = [];
  691. }
  692. if (offset === void 0) {
  693. offset = 0;
  694. }
  695. array[offset] = this.x;
  696. array[offset + 1] = this.y;
  697. return array;
  698. };
  699. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  700. if (offset !== undefined) {
  701. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  702. }
  703. this.x = attribute.getX(index);
  704. this.y = attribute.getY(index);
  705. return this;
  706. };
  707. _proto.rotateAround = function rotateAround(center, angle) {
  708. var c = Math.cos(angle),
  709. s = Math.sin(angle);
  710. var x = this.x - center.x;
  711. var y = this.y - center.y;
  712. this.x = x * c - y * s + center.x;
  713. this.y = x * s + y * c + center.y;
  714. return this;
  715. };
  716. _proto.random = function random() {
  717. this.x = Math.random();
  718. this.y = Math.random();
  719. return this;
  720. };
  721. _createClass(Vector2, [{
  722. key: "width",
  723. get: function get() {
  724. return this.x;
  725. },
  726. set: function set(value) {
  727. this.x = value;
  728. }
  729. }, {
  730. key: "height",
  731. get: function get() {
  732. return this.y;
  733. },
  734. set: function set(value) {
  735. this.y = value;
  736. }
  737. }]);
  738. return Vector2;
  739. }();
  740. var Matrix3 = /*#__PURE__*/function () {
  741. function Matrix3() {
  742. Object.defineProperty(this, 'isMatrix3', {
  743. value: true
  744. });
  745. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  746. if (arguments.length > 0) {
  747. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  748. }
  749. }
  750. var _proto = Matrix3.prototype;
  751. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  752. var te = this.elements;
  753. te[0] = n11;
  754. te[1] = n21;
  755. te[2] = n31;
  756. te[3] = n12;
  757. te[4] = n22;
  758. te[5] = n32;
  759. te[6] = n13;
  760. te[7] = n23;
  761. te[8] = n33;
  762. return this;
  763. };
  764. _proto.identity = function identity() {
  765. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  766. return this;
  767. };
  768. _proto.clone = function clone() {
  769. return new this.constructor().fromArray(this.elements);
  770. };
  771. _proto.copy = function copy(m) {
  772. var te = this.elements;
  773. var me = m.elements;
  774. te[0] = me[0];
  775. te[1] = me[1];
  776. te[2] = me[2];
  777. te[3] = me[3];
  778. te[4] = me[4];
  779. te[5] = me[5];
  780. te[6] = me[6];
  781. te[7] = me[7];
  782. te[8] = me[8];
  783. return this;
  784. };
  785. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  786. xAxis.setFromMatrix3Column(this, 0);
  787. yAxis.setFromMatrix3Column(this, 1);
  788. zAxis.setFromMatrix3Column(this, 2);
  789. return this;
  790. };
  791. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  792. var me = m.elements;
  793. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  794. return this;
  795. };
  796. _proto.multiply = function multiply(m) {
  797. return this.multiplyMatrices(this, m);
  798. };
  799. _proto.premultiply = function premultiply(m) {
  800. return this.multiplyMatrices(m, this);
  801. };
  802. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  803. var ae = a.elements;
  804. var be = b.elements;
  805. var te = this.elements;
  806. var a11 = ae[0],
  807. a12 = ae[3],
  808. a13 = ae[6];
  809. var a21 = ae[1],
  810. a22 = ae[4],
  811. a23 = ae[7];
  812. var a31 = ae[2],
  813. a32 = ae[5],
  814. a33 = ae[8];
  815. var b11 = be[0],
  816. b12 = be[3],
  817. b13 = be[6];
  818. var b21 = be[1],
  819. b22 = be[4],
  820. b23 = be[7];
  821. var b31 = be[2],
  822. b32 = be[5],
  823. b33 = be[8];
  824. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  825. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  826. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  827. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  828. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  829. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  830. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  831. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  832. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  833. return this;
  834. };
  835. _proto.multiplyScalar = function multiplyScalar(s) {
  836. var te = this.elements;
  837. te[0] *= s;
  838. te[3] *= s;
  839. te[6] *= s;
  840. te[1] *= s;
  841. te[4] *= s;
  842. te[7] *= s;
  843. te[2] *= s;
  844. te[5] *= s;
  845. te[8] *= s;
  846. return this;
  847. };
  848. _proto.determinant = function determinant() {
  849. var te = this.elements;
  850. var a = te[0],
  851. b = te[1],
  852. c = te[2],
  853. d = te[3],
  854. e = te[4],
  855. f = te[5],
  856. g = te[6],
  857. h = te[7],
  858. i = te[8];
  859. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  860. };
  861. _proto.invert = function invert() {
  862. var te = this.elements,
  863. n11 = te[0],
  864. n21 = te[1],
  865. n31 = te[2],
  866. n12 = te[3],
  867. n22 = te[4],
  868. n32 = te[5],
  869. n13 = te[6],
  870. n23 = te[7],
  871. n33 = te[8],
  872. t11 = n33 * n22 - n32 * n23,
  873. t12 = n32 * n13 - n33 * n12,
  874. t13 = n23 * n12 - n22 * n13,
  875. det = n11 * t11 + n21 * t12 + n31 * t13;
  876. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  877. var detInv = 1 / det;
  878. te[0] = t11 * detInv;
  879. te[1] = (n31 * n23 - n33 * n21) * detInv;
  880. te[2] = (n32 * n21 - n31 * n22) * detInv;
  881. te[3] = t12 * detInv;
  882. te[4] = (n33 * n11 - n31 * n13) * detInv;
  883. te[5] = (n31 * n12 - n32 * n11) * detInv;
  884. te[6] = t13 * detInv;
  885. te[7] = (n21 * n13 - n23 * n11) * detInv;
  886. te[8] = (n22 * n11 - n21 * n12) * detInv;
  887. return this;
  888. };
  889. _proto.transpose = function transpose() {
  890. var tmp;
  891. var m = this.elements;
  892. tmp = m[1];
  893. m[1] = m[3];
  894. m[3] = tmp;
  895. tmp = m[2];
  896. m[2] = m[6];
  897. m[6] = tmp;
  898. tmp = m[5];
  899. m[5] = m[7];
  900. m[7] = tmp;
  901. return this;
  902. };
  903. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  904. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  905. };
  906. _proto.transposeIntoArray = function transposeIntoArray(r) {
  907. var m = this.elements;
  908. r[0] = m[0];
  909. r[1] = m[3];
  910. r[2] = m[6];
  911. r[3] = m[1];
  912. r[4] = m[4];
  913. r[5] = m[7];
  914. r[6] = m[2];
  915. r[7] = m[5];
  916. r[8] = m[8];
  917. return this;
  918. };
  919. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  920. var c = Math.cos(rotation);
  921. var s = Math.sin(rotation);
  922. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  923. return this;
  924. };
  925. _proto.scale = function scale(sx, sy) {
  926. var te = this.elements;
  927. te[0] *= sx;
  928. te[3] *= sx;
  929. te[6] *= sx;
  930. te[1] *= sy;
  931. te[4] *= sy;
  932. te[7] *= sy;
  933. return this;
  934. };
  935. _proto.rotate = function rotate(theta) {
  936. var c = Math.cos(theta);
  937. var s = Math.sin(theta);
  938. var te = this.elements;
  939. var a11 = te[0],
  940. a12 = te[3],
  941. a13 = te[6];
  942. var a21 = te[1],
  943. a22 = te[4],
  944. a23 = te[7];
  945. te[0] = c * a11 + s * a21;
  946. te[3] = c * a12 + s * a22;
  947. te[6] = c * a13 + s * a23;
  948. te[1] = -s * a11 + c * a21;
  949. te[4] = -s * a12 + c * a22;
  950. te[7] = -s * a13 + c * a23;
  951. return this;
  952. };
  953. _proto.translate = function translate(tx, ty) {
  954. var te = this.elements;
  955. te[0] += tx * te[2];
  956. te[3] += tx * te[5];
  957. te[6] += tx * te[8];
  958. te[1] += ty * te[2];
  959. te[4] += ty * te[5];
  960. te[7] += ty * te[8];
  961. return this;
  962. };
  963. _proto.equals = function equals(matrix) {
  964. var te = this.elements;
  965. var me = matrix.elements;
  966. for (var i = 0; i < 9; i++) {
  967. if (te[i] !== me[i]) return false;
  968. }
  969. return true;
  970. };
  971. _proto.fromArray = function fromArray(array, offset) {
  972. if (offset === void 0) {
  973. offset = 0;
  974. }
  975. for (var i = 0; i < 9; i++) {
  976. this.elements[i] = array[i + offset];
  977. }
  978. return this;
  979. };
  980. _proto.toArray = function toArray(array, offset) {
  981. if (array === void 0) {
  982. array = [];
  983. }
  984. if (offset === void 0) {
  985. offset = 0;
  986. }
  987. var te = this.elements;
  988. array[offset] = te[0];
  989. array[offset + 1] = te[1];
  990. array[offset + 2] = te[2];
  991. array[offset + 3] = te[3];
  992. array[offset + 4] = te[4];
  993. array[offset + 5] = te[5];
  994. array[offset + 6] = te[6];
  995. array[offset + 7] = te[7];
  996. array[offset + 8] = te[8];
  997. return array;
  998. };
  999. return Matrix3;
  1000. }();
  1001. var _canvas;
  1002. var ImageUtils = {
  1003. getDataURL: function getDataURL(image) {
  1004. if (/^data:/i.test(image.src)) {
  1005. return image.src;
  1006. }
  1007. if (typeof HTMLCanvasElement == 'undefined') {
  1008. return image.src;
  1009. }
  1010. var canvas;
  1011. if (image instanceof HTMLCanvasElement) {
  1012. canvas = image;
  1013. } else {
  1014. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1015. _canvas.width = image.width;
  1016. _canvas.height = image.height;
  1017. var context = _canvas.getContext('2d');
  1018. if (image instanceof ImageData) {
  1019. context.putImageData(image, 0, 0);
  1020. } else {
  1021. context.drawImage(image, 0, 0, image.width, image.height);
  1022. }
  1023. canvas = _canvas;
  1024. }
  1025. if (canvas.width > 2048 || canvas.height > 2048) {
  1026. return canvas.toDataURL('image/jpeg', 0.6);
  1027. } else {
  1028. return canvas.toDataURL('image/png');
  1029. }
  1030. }
  1031. };
  1032. var textureId = 0;
  1033. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1034. if (image === void 0) {
  1035. image = Texture.DEFAULT_IMAGE;
  1036. }
  1037. if (mapping === void 0) {
  1038. mapping = Texture.DEFAULT_MAPPING;
  1039. }
  1040. if (wrapS === void 0) {
  1041. wrapS = ClampToEdgeWrapping;
  1042. }
  1043. if (wrapT === void 0) {
  1044. wrapT = ClampToEdgeWrapping;
  1045. }
  1046. if (magFilter === void 0) {
  1047. magFilter = LinearFilter;
  1048. }
  1049. if (minFilter === void 0) {
  1050. minFilter = LinearMipmapLinearFilter;
  1051. }
  1052. if (format === void 0) {
  1053. format = RGBAFormat;
  1054. }
  1055. if (type === void 0) {
  1056. type = UnsignedByteType;
  1057. }
  1058. if (anisotropy === void 0) {
  1059. anisotropy = 1;
  1060. }
  1061. if (encoding === void 0) {
  1062. encoding = LinearEncoding;
  1063. }
  1064. Object.defineProperty(this, 'id', {
  1065. value: textureId++
  1066. });
  1067. this.uuid = MathUtils.generateUUID();
  1068. this.name = '';
  1069. this.image = image;
  1070. this.mipmaps = [];
  1071. this.mapping = mapping;
  1072. this.wrapS = wrapS;
  1073. this.wrapT = wrapT;
  1074. this.magFilter = magFilter;
  1075. this.minFilter = minFilter;
  1076. this.anisotropy = anisotropy;
  1077. this.format = format;
  1078. this.internalFormat = null;
  1079. this.type = type;
  1080. this.offset = new Vector2(0, 0);
  1081. this.repeat = new Vector2(1, 1);
  1082. this.center = new Vector2(0, 0);
  1083. this.rotation = 0;
  1084. this.matrixAutoUpdate = true;
  1085. this.matrix = new Matrix3();
  1086. this.generateMipmaps = true;
  1087. this.premultiplyAlpha = false;
  1088. this.flipY = true;
  1089. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1090. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1091. //
  1092. // Also changing the encoding after already used by a Material will not automatically make the Material
  1093. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1094. this.encoding = encoding;
  1095. this.version = 0;
  1096. this.onUpdate = null;
  1097. }
  1098. Texture.DEFAULT_IMAGE = undefined;
  1099. Texture.DEFAULT_MAPPING = UVMapping;
  1100. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1101. constructor: Texture,
  1102. isTexture: true,
  1103. updateMatrix: function updateMatrix() {
  1104. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1105. },
  1106. clone: function clone() {
  1107. return new this.constructor().copy(this);
  1108. },
  1109. copy: function copy(source) {
  1110. this.name = source.name;
  1111. this.image = source.image;
  1112. this.mipmaps = source.mipmaps.slice(0);
  1113. this.mapping = source.mapping;
  1114. this.wrapS = source.wrapS;
  1115. this.wrapT = source.wrapT;
  1116. this.magFilter = source.magFilter;
  1117. this.minFilter = source.minFilter;
  1118. this.anisotropy = source.anisotropy;
  1119. this.format = source.format;
  1120. this.internalFormat = source.internalFormat;
  1121. this.type = source.type;
  1122. this.offset.copy(source.offset);
  1123. this.repeat.copy(source.repeat);
  1124. this.center.copy(source.center);
  1125. this.rotation = source.rotation;
  1126. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1127. this.matrix.copy(source.matrix);
  1128. this.generateMipmaps = source.generateMipmaps;
  1129. this.premultiplyAlpha = source.premultiplyAlpha;
  1130. this.flipY = source.flipY;
  1131. this.unpackAlignment = source.unpackAlignment;
  1132. this.encoding = source.encoding;
  1133. return this;
  1134. },
  1135. toJSON: function toJSON(meta) {
  1136. var isRootObject = meta === undefined || typeof meta === 'string';
  1137. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1138. return meta.textures[this.uuid];
  1139. }
  1140. var output = {
  1141. metadata: {
  1142. version: 4.5,
  1143. type: 'Texture',
  1144. generator: 'Texture.toJSON'
  1145. },
  1146. uuid: this.uuid,
  1147. name: this.name,
  1148. mapping: this.mapping,
  1149. repeat: [this.repeat.x, this.repeat.y],
  1150. offset: [this.offset.x, this.offset.y],
  1151. center: [this.center.x, this.center.y],
  1152. rotation: this.rotation,
  1153. wrap: [this.wrapS, this.wrapT],
  1154. format: this.format,
  1155. type: this.type,
  1156. encoding: this.encoding,
  1157. minFilter: this.minFilter,
  1158. magFilter: this.magFilter,
  1159. anisotropy: this.anisotropy,
  1160. flipY: this.flipY,
  1161. premultiplyAlpha: this.premultiplyAlpha,
  1162. unpackAlignment: this.unpackAlignment
  1163. };
  1164. if (this.image !== undefined) {
  1165. // TODO: Move to THREE.Image
  1166. var image = this.image;
  1167. if (image.uuid === undefined) {
  1168. image.uuid = MathUtils.generateUUID(); // UGH
  1169. }
  1170. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1171. var url;
  1172. if (Array.isArray(image)) {
  1173. // process array of images e.g. CubeTexture
  1174. url = [];
  1175. for (var i = 0, l = image.length; i < l; i++) {
  1176. // check cube texture with data textures
  1177. if (image[i].isDataTexture) {
  1178. url.push(serializeImage(image[i].image));
  1179. } else {
  1180. url.push(serializeImage(image[i]));
  1181. }
  1182. }
  1183. } else {
  1184. // process single image
  1185. url = serializeImage(image);
  1186. }
  1187. meta.images[image.uuid] = {
  1188. uuid: image.uuid,
  1189. url: url
  1190. };
  1191. }
  1192. output.image = image.uuid;
  1193. }
  1194. if (!isRootObject) {
  1195. meta.textures[this.uuid] = output;
  1196. }
  1197. return output;
  1198. },
  1199. dispose: function dispose() {
  1200. this.dispatchEvent({
  1201. type: 'dispose'
  1202. });
  1203. },
  1204. transformUv: function transformUv(uv) {
  1205. if (this.mapping !== UVMapping) return uv;
  1206. uv.applyMatrix3(this.matrix);
  1207. if (uv.x < 0 || uv.x > 1) {
  1208. switch (this.wrapS) {
  1209. case RepeatWrapping:
  1210. uv.x = uv.x - Math.floor(uv.x);
  1211. break;
  1212. case ClampToEdgeWrapping:
  1213. uv.x = uv.x < 0 ? 0 : 1;
  1214. break;
  1215. case MirroredRepeatWrapping:
  1216. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1217. uv.x = Math.ceil(uv.x) - uv.x;
  1218. } else {
  1219. uv.x = uv.x - Math.floor(uv.x);
  1220. }
  1221. break;
  1222. }
  1223. }
  1224. if (uv.y < 0 || uv.y > 1) {
  1225. switch (this.wrapT) {
  1226. case RepeatWrapping:
  1227. uv.y = uv.y - Math.floor(uv.y);
  1228. break;
  1229. case ClampToEdgeWrapping:
  1230. uv.y = uv.y < 0 ? 0 : 1;
  1231. break;
  1232. case MirroredRepeatWrapping:
  1233. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1234. uv.y = Math.ceil(uv.y) - uv.y;
  1235. } else {
  1236. uv.y = uv.y - Math.floor(uv.y);
  1237. }
  1238. break;
  1239. }
  1240. }
  1241. if (this.flipY) {
  1242. uv.y = 1 - uv.y;
  1243. }
  1244. return uv;
  1245. }
  1246. });
  1247. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1248. set: function set(value) {
  1249. if (value === true) this.version++;
  1250. }
  1251. });
  1252. function serializeImage(image) {
  1253. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1254. // default images
  1255. return ImageUtils.getDataURL(image);
  1256. } else {
  1257. if (image.data) {
  1258. // images of DataTexture
  1259. return {
  1260. data: Array.prototype.slice.call(image.data),
  1261. width: image.width,
  1262. height: image.height,
  1263. type: image.data.constructor.name
  1264. };
  1265. } else {
  1266. console.warn('THREE.Texture: Unable to serialize Texture.');
  1267. return {};
  1268. }
  1269. }
  1270. }
  1271. var Vector4 = /*#__PURE__*/function () {
  1272. function Vector4(x, y, z, w) {
  1273. if (x === void 0) {
  1274. x = 0;
  1275. }
  1276. if (y === void 0) {
  1277. y = 0;
  1278. }
  1279. if (z === void 0) {
  1280. z = 0;
  1281. }
  1282. if (w === void 0) {
  1283. w = 1;
  1284. }
  1285. Object.defineProperty(this, 'isVector4', {
  1286. value: true
  1287. });
  1288. this.x = x;
  1289. this.y = y;
  1290. this.z = z;
  1291. this.w = w;
  1292. }
  1293. var _proto = Vector4.prototype;
  1294. _proto.set = function set(x, y, z, w) {
  1295. this.x = x;
  1296. this.y = y;
  1297. this.z = z;
  1298. this.w = w;
  1299. return this;
  1300. };
  1301. _proto.setScalar = function setScalar(scalar) {
  1302. this.x = scalar;
  1303. this.y = scalar;
  1304. this.z = scalar;
  1305. this.w = scalar;
  1306. return this;
  1307. };
  1308. _proto.setX = function setX(x) {
  1309. this.x = x;
  1310. return this;
  1311. };
  1312. _proto.setY = function setY(y) {
  1313. this.y = y;
  1314. return this;
  1315. };
  1316. _proto.setZ = function setZ(z) {
  1317. this.z = z;
  1318. return this;
  1319. };
  1320. _proto.setW = function setW(w) {
  1321. this.w = w;
  1322. return this;
  1323. };
  1324. _proto.setComponent = function setComponent(index, value) {
  1325. switch (index) {
  1326. case 0:
  1327. this.x = value;
  1328. break;
  1329. case 1:
  1330. this.y = value;
  1331. break;
  1332. case 2:
  1333. this.z = value;
  1334. break;
  1335. case 3:
  1336. this.w = value;
  1337. break;
  1338. default:
  1339. throw new Error('index is out of range: ' + index);
  1340. }
  1341. return this;
  1342. };
  1343. _proto.getComponent = function getComponent(index) {
  1344. switch (index) {
  1345. case 0:
  1346. return this.x;
  1347. case 1:
  1348. return this.y;
  1349. case 2:
  1350. return this.z;
  1351. case 3:
  1352. return this.w;
  1353. default:
  1354. throw new Error('index is out of range: ' + index);
  1355. }
  1356. };
  1357. _proto.clone = function clone() {
  1358. return new this.constructor(this.x, this.y, this.z, this.w);
  1359. };
  1360. _proto.copy = function copy(v) {
  1361. this.x = v.x;
  1362. this.y = v.y;
  1363. this.z = v.z;
  1364. this.w = v.w !== undefined ? v.w : 1;
  1365. return this;
  1366. };
  1367. _proto.add = function add(v, w) {
  1368. if (w !== undefined) {
  1369. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1370. return this.addVectors(v, w);
  1371. }
  1372. this.x += v.x;
  1373. this.y += v.y;
  1374. this.z += v.z;
  1375. this.w += v.w;
  1376. return this;
  1377. };
  1378. _proto.addScalar = function addScalar(s) {
  1379. this.x += s;
  1380. this.y += s;
  1381. this.z += s;
  1382. this.w += s;
  1383. return this;
  1384. };
  1385. _proto.addVectors = function addVectors(a, b) {
  1386. this.x = a.x + b.x;
  1387. this.y = a.y + b.y;
  1388. this.z = a.z + b.z;
  1389. this.w = a.w + b.w;
  1390. return this;
  1391. };
  1392. _proto.addScaledVector = function addScaledVector(v, s) {
  1393. this.x += v.x * s;
  1394. this.y += v.y * s;
  1395. this.z += v.z * s;
  1396. this.w += v.w * s;
  1397. return this;
  1398. };
  1399. _proto.sub = function sub(v, w) {
  1400. if (w !== undefined) {
  1401. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1402. return this.subVectors(v, w);
  1403. }
  1404. this.x -= v.x;
  1405. this.y -= v.y;
  1406. this.z -= v.z;
  1407. this.w -= v.w;
  1408. return this;
  1409. };
  1410. _proto.subScalar = function subScalar(s) {
  1411. this.x -= s;
  1412. this.y -= s;
  1413. this.z -= s;
  1414. this.w -= s;
  1415. return this;
  1416. };
  1417. _proto.subVectors = function subVectors(a, b) {
  1418. this.x = a.x - b.x;
  1419. this.y = a.y - b.y;
  1420. this.z = a.z - b.z;
  1421. this.w = a.w - b.w;
  1422. return this;
  1423. };
  1424. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1425. this.x *= scalar;
  1426. this.y *= scalar;
  1427. this.z *= scalar;
  1428. this.w *= scalar;
  1429. return this;
  1430. };
  1431. _proto.applyMatrix4 = function applyMatrix4(m) {
  1432. var x = this.x,
  1433. y = this.y,
  1434. z = this.z,
  1435. w = this.w;
  1436. var e = m.elements;
  1437. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1438. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1439. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1440. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1441. return this;
  1442. };
  1443. _proto.divideScalar = function divideScalar(scalar) {
  1444. return this.multiplyScalar(1 / scalar);
  1445. };
  1446. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1447. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1448. // q is assumed to be normalized
  1449. this.w = 2 * Math.acos(q.w);
  1450. var s = Math.sqrt(1 - q.w * q.w);
  1451. if (s < 0.0001) {
  1452. this.x = 1;
  1453. this.y = 0;
  1454. this.z = 0;
  1455. } else {
  1456. this.x = q.x / s;
  1457. this.y = q.y / s;
  1458. this.z = q.z / s;
  1459. }
  1460. return this;
  1461. };
  1462. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1463. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1464. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1465. var angle, x, y, z; // variables for result
  1466. var epsilon = 0.01,
  1467. // margin to allow for rounding errors
  1468. epsilon2 = 0.1,
  1469. // margin to distinguish between 0 and 180 degrees
  1470. te = m.elements,
  1471. m11 = te[0],
  1472. m12 = te[4],
  1473. m13 = te[8],
  1474. m21 = te[1],
  1475. m22 = te[5],
  1476. m23 = te[9],
  1477. m31 = te[2],
  1478. m32 = te[6],
  1479. m33 = te[10];
  1480. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1481. // singularity found
  1482. // first check for identity matrix which must have +1 for all terms
  1483. // in leading diagonal and zero in other terms
  1484. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1485. // this singularity is identity matrix so angle = 0
  1486. this.set(1, 0, 0, 0);
  1487. return this; // zero angle, arbitrary axis
  1488. } // otherwise this singularity is angle = 180
  1489. angle = Math.PI;
  1490. var xx = (m11 + 1) / 2;
  1491. var yy = (m22 + 1) / 2;
  1492. var zz = (m33 + 1) / 2;
  1493. var xy = (m12 + m21) / 4;
  1494. var xz = (m13 + m31) / 4;
  1495. var yz = (m23 + m32) / 4;
  1496. if (xx > yy && xx > zz) {
  1497. // m11 is the largest diagonal term
  1498. if (xx < epsilon) {
  1499. x = 0;
  1500. y = 0.707106781;
  1501. z = 0.707106781;
  1502. } else {
  1503. x = Math.sqrt(xx);
  1504. y = xy / x;
  1505. z = xz / x;
  1506. }
  1507. } else if (yy > zz) {
  1508. // m22 is the largest diagonal term
  1509. if (yy < epsilon) {
  1510. x = 0.707106781;
  1511. y = 0;
  1512. z = 0.707106781;
  1513. } else {
  1514. y = Math.sqrt(yy);
  1515. x = xy / y;
  1516. z = yz / y;
  1517. }
  1518. } else {
  1519. // m33 is the largest diagonal term so base result on this
  1520. if (zz < epsilon) {
  1521. x = 0.707106781;
  1522. y = 0.707106781;
  1523. z = 0;
  1524. } else {
  1525. z = Math.sqrt(zz);
  1526. x = xz / z;
  1527. y = yz / z;
  1528. }
  1529. }
  1530. this.set(x, y, z, angle);
  1531. return this; // return 180 deg rotation
  1532. } // as we have reached here there are no singularities so we can handle normally
  1533. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1534. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1535. // caught by singularity test above, but I've left it in just in case
  1536. this.x = (m32 - m23) / s;
  1537. this.y = (m13 - m31) / s;
  1538. this.z = (m21 - m12) / s;
  1539. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1540. return this;
  1541. };
  1542. _proto.min = function min(v) {
  1543. this.x = Math.min(this.x, v.x);
  1544. this.y = Math.min(this.y, v.y);
  1545. this.z = Math.min(this.z, v.z);
  1546. this.w = Math.min(this.w, v.w);
  1547. return this;
  1548. };
  1549. _proto.max = function max(v) {
  1550. this.x = Math.max(this.x, v.x);
  1551. this.y = Math.max(this.y, v.y);
  1552. this.z = Math.max(this.z, v.z);
  1553. this.w = Math.max(this.w, v.w);
  1554. return this;
  1555. };
  1556. _proto.clamp = function clamp(min, max) {
  1557. // assumes min < max, componentwise
  1558. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1559. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1560. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1561. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1562. return this;
  1563. };
  1564. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1565. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1566. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1567. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1568. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1569. return this;
  1570. };
  1571. _proto.clampLength = function clampLength(min, max) {
  1572. var length = this.length();
  1573. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1574. };
  1575. _proto.floor = function floor() {
  1576. this.x = Math.floor(this.x);
  1577. this.y = Math.floor(this.y);
  1578. this.z = Math.floor(this.z);
  1579. this.w = Math.floor(this.w);
  1580. return this;
  1581. };
  1582. _proto.ceil = function ceil() {
  1583. this.x = Math.ceil(this.x);
  1584. this.y = Math.ceil(this.y);
  1585. this.z = Math.ceil(this.z);
  1586. this.w = Math.ceil(this.w);
  1587. return this;
  1588. };
  1589. _proto.round = function round() {
  1590. this.x = Math.round(this.x);
  1591. this.y = Math.round(this.y);
  1592. this.z = Math.round(this.z);
  1593. this.w = Math.round(this.w);
  1594. return this;
  1595. };
  1596. _proto.roundToZero = function roundToZero() {
  1597. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1598. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1599. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1600. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1601. return this;
  1602. };
  1603. _proto.negate = function negate() {
  1604. this.x = -this.x;
  1605. this.y = -this.y;
  1606. this.z = -this.z;
  1607. this.w = -this.w;
  1608. return this;
  1609. };
  1610. _proto.dot = function dot(v) {
  1611. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1612. };
  1613. _proto.lengthSq = function lengthSq() {
  1614. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1615. };
  1616. _proto.length = function length() {
  1617. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1618. };
  1619. _proto.manhattanLength = function manhattanLength() {
  1620. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1621. };
  1622. _proto.normalize = function normalize() {
  1623. return this.divideScalar(this.length() || 1);
  1624. };
  1625. _proto.setLength = function setLength(length) {
  1626. return this.normalize().multiplyScalar(length);
  1627. };
  1628. _proto.lerp = function lerp(v, alpha) {
  1629. this.x += (v.x - this.x) * alpha;
  1630. this.y += (v.y - this.y) * alpha;
  1631. this.z += (v.z - this.z) * alpha;
  1632. this.w += (v.w - this.w) * alpha;
  1633. return this;
  1634. };
  1635. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1636. this.x = v1.x + (v2.x - v1.x) * alpha;
  1637. this.y = v1.y + (v2.y - v1.y) * alpha;
  1638. this.z = v1.z + (v2.z - v1.z) * alpha;
  1639. this.w = v1.w + (v2.w - v1.w) * alpha;
  1640. return this;
  1641. };
  1642. _proto.equals = function equals(v) {
  1643. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1644. };
  1645. _proto.fromArray = function fromArray(array, offset) {
  1646. if (offset === void 0) {
  1647. offset = 0;
  1648. }
  1649. this.x = array[offset];
  1650. this.y = array[offset + 1];
  1651. this.z = array[offset + 2];
  1652. this.w = array[offset + 3];
  1653. return this;
  1654. };
  1655. _proto.toArray = function toArray(array, offset) {
  1656. if (array === void 0) {
  1657. array = [];
  1658. }
  1659. if (offset === void 0) {
  1660. offset = 0;
  1661. }
  1662. array[offset] = this.x;
  1663. array[offset + 1] = this.y;
  1664. array[offset + 2] = this.z;
  1665. array[offset + 3] = this.w;
  1666. return array;
  1667. };
  1668. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1669. if (offset !== undefined) {
  1670. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1671. }
  1672. this.x = attribute.getX(index);
  1673. this.y = attribute.getY(index);
  1674. this.z = attribute.getZ(index);
  1675. this.w = attribute.getW(index);
  1676. return this;
  1677. };
  1678. _proto.random = function random() {
  1679. this.x = Math.random();
  1680. this.y = Math.random();
  1681. this.z = Math.random();
  1682. this.w = Math.random();
  1683. return this;
  1684. };
  1685. _createClass(Vector4, [{
  1686. key: "width",
  1687. get: function get() {
  1688. return this.z;
  1689. },
  1690. set: function set(value) {
  1691. this.z = value;
  1692. }
  1693. }, {
  1694. key: "height",
  1695. get: function get() {
  1696. return this.w;
  1697. },
  1698. set: function set(value) {
  1699. this.w = value;
  1700. }
  1701. }]);
  1702. return Vector4;
  1703. }();
  1704. /*
  1705. In options, we can specify:
  1706. * Texture parameters for an auto-generated target texture
  1707. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1708. */
  1709. function WebGLRenderTarget(width, height, options) {
  1710. this.width = width;
  1711. this.height = height;
  1712. this.scissor = new Vector4(0, 0, width, height);
  1713. this.scissorTest = false;
  1714. this.viewport = new Vector4(0, 0, width, height);
  1715. options = options || {};
  1716. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1717. this.texture.image = {};
  1718. this.texture.image.width = width;
  1719. this.texture.image.height = height;
  1720. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1721. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1722. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1723. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1724. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1725. }
  1726. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1727. constructor: WebGLRenderTarget,
  1728. isWebGLRenderTarget: true,
  1729. setSize: function setSize(width, height) {
  1730. if (this.width !== width || this.height !== height) {
  1731. this.width = width;
  1732. this.height = height;
  1733. this.texture.image.width = width;
  1734. this.texture.image.height = height;
  1735. this.dispose();
  1736. }
  1737. this.viewport.set(0, 0, width, height);
  1738. this.scissor.set(0, 0, width, height);
  1739. },
  1740. clone: function clone() {
  1741. return new this.constructor().copy(this);
  1742. },
  1743. copy: function copy(source) {
  1744. this.width = source.width;
  1745. this.height = source.height;
  1746. this.viewport.copy(source.viewport);
  1747. this.texture = source.texture.clone();
  1748. this.depthBuffer = source.depthBuffer;
  1749. this.stencilBuffer = source.stencilBuffer;
  1750. this.depthTexture = source.depthTexture;
  1751. return this;
  1752. },
  1753. dispose: function dispose() {
  1754. this.dispatchEvent({
  1755. type: 'dispose'
  1756. });
  1757. }
  1758. });
  1759. function WebGLMultisampleRenderTarget(width, height, options) {
  1760. WebGLRenderTarget.call(this, width, height, options);
  1761. this.samples = 4;
  1762. }
  1763. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1764. constructor: WebGLMultisampleRenderTarget,
  1765. isWebGLMultisampleRenderTarget: true,
  1766. copy: function copy(source) {
  1767. WebGLRenderTarget.prototype.copy.call(this, source);
  1768. this.samples = source.samples;
  1769. return this;
  1770. }
  1771. });
  1772. var Quaternion = /*#__PURE__*/function () {
  1773. function Quaternion(x, y, z, w) {
  1774. if (x === void 0) {
  1775. x = 0;
  1776. }
  1777. if (y === void 0) {
  1778. y = 0;
  1779. }
  1780. if (z === void 0) {
  1781. z = 0;
  1782. }
  1783. if (w === void 0) {
  1784. w = 1;
  1785. }
  1786. Object.defineProperty(this, 'isQuaternion', {
  1787. value: true
  1788. });
  1789. this._x = x;
  1790. this._y = y;
  1791. this._z = z;
  1792. this._w = w;
  1793. }
  1794. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1795. return qm.copy(qa).slerp(qb, t);
  1796. };
  1797. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1798. // fuzz-free, array-based Quaternion SLERP operation
  1799. var x0 = src0[srcOffset0 + 0],
  1800. y0 = src0[srcOffset0 + 1],
  1801. z0 = src0[srcOffset0 + 2],
  1802. w0 = src0[srcOffset0 + 3];
  1803. var x1 = src1[srcOffset1 + 0],
  1804. y1 = src1[srcOffset1 + 1],
  1805. z1 = src1[srcOffset1 + 2],
  1806. w1 = src1[srcOffset1 + 3];
  1807. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1808. var s = 1 - t;
  1809. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1810. dir = cos >= 0 ? 1 : -1,
  1811. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1812. if (sqrSin > Number.EPSILON) {
  1813. var sin = Math.sqrt(sqrSin),
  1814. len = Math.atan2(sin, cos * dir);
  1815. s = Math.sin(s * len) / sin;
  1816. t = Math.sin(t * len) / sin;
  1817. }
  1818. var tDir = t * dir;
  1819. x0 = x0 * s + x1 * tDir;
  1820. y0 = y0 * s + y1 * tDir;
  1821. z0 = z0 * s + z1 * tDir;
  1822. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1823. if (s === 1 - t) {
  1824. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1825. x0 *= f;
  1826. y0 *= f;
  1827. z0 *= f;
  1828. w0 *= f;
  1829. }
  1830. }
  1831. dst[dstOffset] = x0;
  1832. dst[dstOffset + 1] = y0;
  1833. dst[dstOffset + 2] = z0;
  1834. dst[dstOffset + 3] = w0;
  1835. };
  1836. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1837. var x0 = src0[srcOffset0];
  1838. var y0 = src0[srcOffset0 + 1];
  1839. var z0 = src0[srcOffset0 + 2];
  1840. var w0 = src0[srcOffset0 + 3];
  1841. var x1 = src1[srcOffset1];
  1842. var y1 = src1[srcOffset1 + 1];
  1843. var z1 = src1[srcOffset1 + 2];
  1844. var w1 = src1[srcOffset1 + 3];
  1845. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1846. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1847. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1848. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1849. return dst;
  1850. };
  1851. var _proto = Quaternion.prototype;
  1852. _proto.set = function set(x, y, z, w) {
  1853. this._x = x;
  1854. this._y = y;
  1855. this._z = z;
  1856. this._w = w;
  1857. this._onChangeCallback();
  1858. return this;
  1859. };
  1860. _proto.clone = function clone() {
  1861. return new this.constructor(this._x, this._y, this._z, this._w);
  1862. };
  1863. _proto.copy = function copy(quaternion) {
  1864. this._x = quaternion.x;
  1865. this._y = quaternion.y;
  1866. this._z = quaternion.z;
  1867. this._w = quaternion.w;
  1868. this._onChangeCallback();
  1869. return this;
  1870. };
  1871. _proto.setFromEuler = function setFromEuler(euler, update) {
  1872. if (!(euler && euler.isEuler)) {
  1873. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1874. }
  1875. var x = euler._x,
  1876. y = euler._y,
  1877. z = euler._z,
  1878. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1879. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1880. // content/SpinCalc.m
  1881. var cos = Math.cos;
  1882. var sin = Math.sin;
  1883. var c1 = cos(x / 2);
  1884. var c2 = cos(y / 2);
  1885. var c3 = cos(z / 2);
  1886. var s1 = sin(x / 2);
  1887. var s2 = sin(y / 2);
  1888. var s3 = sin(z / 2);
  1889. switch (order) {
  1890. case 'XYZ':
  1891. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1892. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1893. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1894. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1895. break;
  1896. case 'YXZ':
  1897. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1898. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1899. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1900. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1901. break;
  1902. case 'ZXY':
  1903. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1904. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1905. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1906. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1907. break;
  1908. case 'ZYX':
  1909. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1910. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1911. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1912. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1913. break;
  1914. case 'YZX':
  1915. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1916. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1917. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1918. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1919. break;
  1920. case 'XZY':
  1921. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1922. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1923. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1924. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1925. break;
  1926. default:
  1927. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1928. }
  1929. if (update !== false) this._onChangeCallback();
  1930. return this;
  1931. };
  1932. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1933. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1934. // assumes axis is normalized
  1935. var halfAngle = angle / 2,
  1936. s = Math.sin(halfAngle);
  1937. this._x = axis.x * s;
  1938. this._y = axis.y * s;
  1939. this._z = axis.z * s;
  1940. this._w = Math.cos(halfAngle);
  1941. this._onChangeCallback();
  1942. return this;
  1943. };
  1944. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1945. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1946. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1947. var te = m.elements,
  1948. m11 = te[0],
  1949. m12 = te[4],
  1950. m13 = te[8],
  1951. m21 = te[1],
  1952. m22 = te[5],
  1953. m23 = te[9],
  1954. m31 = te[2],
  1955. m32 = te[6],
  1956. m33 = te[10],
  1957. trace = m11 + m22 + m33;
  1958. if (trace > 0) {
  1959. var s = 0.5 / Math.sqrt(trace + 1.0);
  1960. this._w = 0.25 / s;
  1961. this._x = (m32 - m23) * s;
  1962. this._y = (m13 - m31) * s;
  1963. this._z = (m21 - m12) * s;
  1964. } else if (m11 > m22 && m11 > m33) {
  1965. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1966. this._w = (m32 - m23) / _s;
  1967. this._x = 0.25 * _s;
  1968. this._y = (m12 + m21) / _s;
  1969. this._z = (m13 + m31) / _s;
  1970. } else if (m22 > m33) {
  1971. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1972. this._w = (m13 - m31) / _s2;
  1973. this._x = (m12 + m21) / _s2;
  1974. this._y = 0.25 * _s2;
  1975. this._z = (m23 + m32) / _s2;
  1976. } else {
  1977. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1978. this._w = (m21 - m12) / _s3;
  1979. this._x = (m13 + m31) / _s3;
  1980. this._y = (m23 + m32) / _s3;
  1981. this._z = 0.25 * _s3;
  1982. }
  1983. this._onChangeCallback();
  1984. return this;
  1985. };
  1986. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1987. // assumes direction vectors vFrom and vTo are normalized
  1988. var EPS = 0.000001;
  1989. var r = vFrom.dot(vTo) + 1;
  1990. if (r < EPS) {
  1991. r = 0;
  1992. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1993. this._x = -vFrom.y;
  1994. this._y = vFrom.x;
  1995. this._z = 0;
  1996. this._w = r;
  1997. } else {
  1998. this._x = 0;
  1999. this._y = -vFrom.z;
  2000. this._z = vFrom.y;
  2001. this._w = r;
  2002. }
  2003. } else {
  2004. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2005. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2006. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2007. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2008. this._w = r;
  2009. }
  2010. return this.normalize();
  2011. };
  2012. _proto.angleTo = function angleTo(q) {
  2013. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2014. };
  2015. _proto.rotateTowards = function rotateTowards(q, step) {
  2016. var angle = this.angleTo(q);
  2017. if (angle === 0) return this;
  2018. var t = Math.min(1, step / angle);
  2019. this.slerp(q, t);
  2020. return this;
  2021. };
  2022. _proto.identity = function identity() {
  2023. return this.set(0, 0, 0, 1);
  2024. };
  2025. _proto.invert = function invert() {
  2026. // quaternion is assumed to have unit length
  2027. return this.conjugate();
  2028. };
  2029. _proto.conjugate = function conjugate() {
  2030. this._x *= -1;
  2031. this._y *= -1;
  2032. this._z *= -1;
  2033. this._onChangeCallback();
  2034. return this;
  2035. };
  2036. _proto.dot = function dot(v) {
  2037. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2038. };
  2039. _proto.lengthSq = function lengthSq() {
  2040. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2041. };
  2042. _proto.length = function length() {
  2043. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2044. };
  2045. _proto.normalize = function normalize() {
  2046. var l = this.length();
  2047. if (l === 0) {
  2048. this._x = 0;
  2049. this._y = 0;
  2050. this._z = 0;
  2051. this._w = 1;
  2052. } else {
  2053. l = 1 / l;
  2054. this._x = this._x * l;
  2055. this._y = this._y * l;
  2056. this._z = this._z * l;
  2057. this._w = this._w * l;
  2058. }
  2059. this._onChangeCallback();
  2060. return this;
  2061. };
  2062. _proto.multiply = function multiply(q, p) {
  2063. if (p !== undefined) {
  2064. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2065. return this.multiplyQuaternions(q, p);
  2066. }
  2067. return this.multiplyQuaternions(this, q);
  2068. };
  2069. _proto.premultiply = function premultiply(q) {
  2070. return this.multiplyQuaternions(q, this);
  2071. };
  2072. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2073. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2074. var qax = a._x,
  2075. qay = a._y,
  2076. qaz = a._z,
  2077. qaw = a._w;
  2078. var qbx = b._x,
  2079. qby = b._y,
  2080. qbz = b._z,
  2081. qbw = b._w;
  2082. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2083. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2084. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2085. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2086. this._onChangeCallback();
  2087. return this;
  2088. };
  2089. _proto.slerp = function slerp(qb, t) {
  2090. if (t === 0) return this;
  2091. if (t === 1) return this.copy(qb);
  2092. var x = this._x,
  2093. y = this._y,
  2094. z = this._z,
  2095. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2096. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2097. if (cosHalfTheta < 0) {
  2098. this._w = -qb._w;
  2099. this._x = -qb._x;
  2100. this._y = -qb._y;
  2101. this._z = -qb._z;
  2102. cosHalfTheta = -cosHalfTheta;
  2103. } else {
  2104. this.copy(qb);
  2105. }
  2106. if (cosHalfTheta >= 1.0) {
  2107. this._w = w;
  2108. this._x = x;
  2109. this._y = y;
  2110. this._z = z;
  2111. return this;
  2112. }
  2113. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2114. if (sqrSinHalfTheta <= Number.EPSILON) {
  2115. var s = 1 - t;
  2116. this._w = s * w + t * this._w;
  2117. this._x = s * x + t * this._x;
  2118. this._y = s * y + t * this._y;
  2119. this._z = s * z + t * this._z;
  2120. this.normalize();
  2121. this._onChangeCallback();
  2122. return this;
  2123. }
  2124. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2125. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2126. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2127. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2128. this._w = w * ratioA + this._w * ratioB;
  2129. this._x = x * ratioA + this._x * ratioB;
  2130. this._y = y * ratioA + this._y * ratioB;
  2131. this._z = z * ratioA + this._z * ratioB;
  2132. this._onChangeCallback();
  2133. return this;
  2134. };
  2135. _proto.equals = function equals(quaternion) {
  2136. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2137. };
  2138. _proto.fromArray = function fromArray(array, offset) {
  2139. if (offset === void 0) {
  2140. offset = 0;
  2141. }
  2142. this._x = array[offset];
  2143. this._y = array[offset + 1];
  2144. this._z = array[offset + 2];
  2145. this._w = array[offset + 3];
  2146. this._onChangeCallback();
  2147. return this;
  2148. };
  2149. _proto.toArray = function toArray(array, offset) {
  2150. if (array === void 0) {
  2151. array = [];
  2152. }
  2153. if (offset === void 0) {
  2154. offset = 0;
  2155. }
  2156. array[offset] = this._x;
  2157. array[offset + 1] = this._y;
  2158. array[offset + 2] = this._z;
  2159. array[offset + 3] = this._w;
  2160. return array;
  2161. };
  2162. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2163. this._x = attribute.getX(index);
  2164. this._y = attribute.getY(index);
  2165. this._z = attribute.getZ(index);
  2166. this._w = attribute.getW(index);
  2167. return this;
  2168. };
  2169. _proto._onChange = function _onChange(callback) {
  2170. this._onChangeCallback = callback;
  2171. return this;
  2172. };
  2173. _proto._onChangeCallback = function _onChangeCallback() {};
  2174. _createClass(Quaternion, [{
  2175. key: "x",
  2176. get: function get() {
  2177. return this._x;
  2178. },
  2179. set: function set(value) {
  2180. this._x = value;
  2181. this._onChangeCallback();
  2182. }
  2183. }, {
  2184. key: "y",
  2185. get: function get() {
  2186. return this._y;
  2187. },
  2188. set: function set(value) {
  2189. this._y = value;
  2190. this._onChangeCallback();
  2191. }
  2192. }, {
  2193. key: "z",
  2194. get: function get() {
  2195. return this._z;
  2196. },
  2197. set: function set(value) {
  2198. this._z = value;
  2199. this._onChangeCallback();
  2200. }
  2201. }, {
  2202. key: "w",
  2203. get: function get() {
  2204. return this._w;
  2205. },
  2206. set: function set(value) {
  2207. this._w = value;
  2208. this._onChangeCallback();
  2209. }
  2210. }]);
  2211. return Quaternion;
  2212. }();
  2213. var Vector3 = /*#__PURE__*/function () {
  2214. function Vector3(x, y, z) {
  2215. if (x === void 0) {
  2216. x = 0;
  2217. }
  2218. if (y === void 0) {
  2219. y = 0;
  2220. }
  2221. if (z === void 0) {
  2222. z = 0;
  2223. }
  2224. Object.defineProperty(this, 'isVector3', {
  2225. value: true
  2226. });
  2227. this.x = x;
  2228. this.y = y;
  2229. this.z = z;
  2230. }
  2231. var _proto = Vector3.prototype;
  2232. _proto.set = function set(x, y, z) {
  2233. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2234. this.x = x;
  2235. this.y = y;
  2236. this.z = z;
  2237. return this;
  2238. };
  2239. _proto.setScalar = function setScalar(scalar) {
  2240. this.x = scalar;
  2241. this.y = scalar;
  2242. this.z = scalar;
  2243. return this;
  2244. };
  2245. _proto.setX = function setX(x) {
  2246. this.x = x;
  2247. return this;
  2248. };
  2249. _proto.setY = function setY(y) {
  2250. this.y = y;
  2251. return this;
  2252. };
  2253. _proto.setZ = function setZ(z) {
  2254. this.z = z;
  2255. return this;
  2256. };
  2257. _proto.setComponent = function setComponent(index, value) {
  2258. switch (index) {
  2259. case 0:
  2260. this.x = value;
  2261. break;
  2262. case 1:
  2263. this.y = value;
  2264. break;
  2265. case 2:
  2266. this.z = value;
  2267. break;
  2268. default:
  2269. throw new Error('index is out of range: ' + index);
  2270. }
  2271. return this;
  2272. };
  2273. _proto.getComponent = function getComponent(index) {
  2274. switch (index) {
  2275. case 0:
  2276. return this.x;
  2277. case 1:
  2278. return this.y;
  2279. case 2:
  2280. return this.z;
  2281. default:
  2282. throw new Error('index is out of range: ' + index);
  2283. }
  2284. };
  2285. _proto.clone = function clone() {
  2286. return new this.constructor(this.x, this.y, this.z);
  2287. };
  2288. _proto.copy = function copy(v) {
  2289. this.x = v.x;
  2290. this.y = v.y;
  2291. this.z = v.z;
  2292. return this;
  2293. };
  2294. _proto.add = function add(v, w) {
  2295. if (w !== undefined) {
  2296. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2297. return this.addVectors(v, w);
  2298. }
  2299. this.x += v.x;
  2300. this.y += v.y;
  2301. this.z += v.z;
  2302. return this;
  2303. };
  2304. _proto.addScalar = function addScalar(s) {
  2305. this.x += s;
  2306. this.y += s;
  2307. this.z += s;
  2308. return this;
  2309. };
  2310. _proto.addVectors = function addVectors(a, b) {
  2311. this.x = a.x + b.x;
  2312. this.y = a.y + b.y;
  2313. this.z = a.z + b.z;
  2314. return this;
  2315. };
  2316. _proto.addScaledVector = function addScaledVector(v, s) {
  2317. this.x += v.x * s;
  2318. this.y += v.y * s;
  2319. this.z += v.z * s;
  2320. return this;
  2321. };
  2322. _proto.sub = function sub(v, w) {
  2323. if (w !== undefined) {
  2324. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2325. return this.subVectors(v, w);
  2326. }
  2327. this.x -= v.x;
  2328. this.y -= v.y;
  2329. this.z -= v.z;
  2330. return this;
  2331. };
  2332. _proto.subScalar = function subScalar(s) {
  2333. this.x -= s;
  2334. this.y -= s;
  2335. this.z -= s;
  2336. return this;
  2337. };
  2338. _proto.subVectors = function subVectors(a, b) {
  2339. this.x = a.x - b.x;
  2340. this.y = a.y - b.y;
  2341. this.z = a.z - b.z;
  2342. return this;
  2343. };
  2344. _proto.multiply = function multiply(v, w) {
  2345. if (w !== undefined) {
  2346. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2347. return this.multiplyVectors(v, w);
  2348. }
  2349. this.x *= v.x;
  2350. this.y *= v.y;
  2351. this.z *= v.z;
  2352. return this;
  2353. };
  2354. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2355. this.x *= scalar;
  2356. this.y *= scalar;
  2357. this.z *= scalar;
  2358. return this;
  2359. };
  2360. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2361. this.x = a.x * b.x;
  2362. this.y = a.y * b.y;
  2363. this.z = a.z * b.z;
  2364. return this;
  2365. };
  2366. _proto.applyEuler = function applyEuler(euler) {
  2367. if (!(euler && euler.isEuler)) {
  2368. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2369. }
  2370. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2371. };
  2372. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2373. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2374. };
  2375. _proto.applyMatrix3 = function applyMatrix3(m) {
  2376. var x = this.x,
  2377. y = this.y,
  2378. z = this.z;
  2379. var e = m.elements;
  2380. this.x = e[0] * x + e[3] * y + e[6] * z;
  2381. this.y = e[1] * x + e[4] * y + e[7] * z;
  2382. this.z = e[2] * x + e[5] * y + e[8] * z;
  2383. return this;
  2384. };
  2385. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2386. return this.applyMatrix3(m).normalize();
  2387. };
  2388. _proto.applyMatrix4 = function applyMatrix4(m) {
  2389. var x = this.x,
  2390. y = this.y,
  2391. z = this.z;
  2392. var e = m.elements;
  2393. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2394. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2395. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2396. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2397. return this;
  2398. };
  2399. _proto.applyQuaternion = function applyQuaternion(q) {
  2400. var x = this.x,
  2401. y = this.y,
  2402. z = this.z;
  2403. var qx = q.x,
  2404. qy = q.y,
  2405. qz = q.z,
  2406. qw = q.w; // calculate quat * vector
  2407. var ix = qw * x + qy * z - qz * y;
  2408. var iy = qw * y + qz * x - qx * z;
  2409. var iz = qw * z + qx * y - qy * x;
  2410. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2411. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2412. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2413. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2414. return this;
  2415. };
  2416. _proto.project = function project(camera) {
  2417. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2418. };
  2419. _proto.unproject = function unproject(camera) {
  2420. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2421. };
  2422. _proto.transformDirection = function transformDirection(m) {
  2423. // input: THREE.Matrix4 affine matrix
  2424. // vector interpreted as a direction
  2425. var x = this.x,
  2426. y = this.y,
  2427. z = this.z;
  2428. var e = m.elements;
  2429. this.x = e[0] * x + e[4] * y + e[8] * z;
  2430. this.y = e[1] * x + e[5] * y + e[9] * z;
  2431. this.z = e[2] * x + e[6] * y + e[10] * z;
  2432. return this.normalize();
  2433. };
  2434. _proto.divide = function divide(v) {
  2435. this.x /= v.x;
  2436. this.y /= v.y;
  2437. this.z /= v.z;
  2438. return this;
  2439. };
  2440. _proto.divideScalar = function divideScalar(scalar) {
  2441. return this.multiplyScalar(1 / scalar);
  2442. };
  2443. _proto.min = function min(v) {
  2444. this.x = Math.min(this.x, v.x);
  2445. this.y = Math.min(this.y, v.y);
  2446. this.z = Math.min(this.z, v.z);
  2447. return this;
  2448. };
  2449. _proto.max = function max(v) {
  2450. this.x = Math.max(this.x, v.x);
  2451. this.y = Math.max(this.y, v.y);
  2452. this.z = Math.max(this.z, v.z);
  2453. return this;
  2454. };
  2455. _proto.clamp = function clamp(min, max) {
  2456. // assumes min < max, componentwise
  2457. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2458. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2459. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2460. return this;
  2461. };
  2462. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2463. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2464. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2465. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2466. return this;
  2467. };
  2468. _proto.clampLength = function clampLength(min, max) {
  2469. var length = this.length();
  2470. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2471. };
  2472. _proto.floor = function floor() {
  2473. this.x = Math.floor(this.x);
  2474. this.y = Math.floor(this.y);
  2475. this.z = Math.floor(this.z);
  2476. return this;
  2477. };
  2478. _proto.ceil = function ceil() {
  2479. this.x = Math.ceil(this.x);
  2480. this.y = Math.ceil(this.y);
  2481. this.z = Math.ceil(this.z);
  2482. return this;
  2483. };
  2484. _proto.round = function round() {
  2485. this.x = Math.round(this.x);
  2486. this.y = Math.round(this.y);
  2487. this.z = Math.round(this.z);
  2488. return this;
  2489. };
  2490. _proto.roundToZero = function roundToZero() {
  2491. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2492. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2493. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2494. return this;
  2495. };
  2496. _proto.negate = function negate() {
  2497. this.x = -this.x;
  2498. this.y = -this.y;
  2499. this.z = -this.z;
  2500. return this;
  2501. };
  2502. _proto.dot = function dot(v) {
  2503. return this.x * v.x + this.y * v.y + this.z * v.z;
  2504. } // TODO lengthSquared?
  2505. ;
  2506. _proto.lengthSq = function lengthSq() {
  2507. return this.x * this.x + this.y * this.y + this.z * this.z;
  2508. };
  2509. _proto.length = function length() {
  2510. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2511. };
  2512. _proto.manhattanLength = function manhattanLength() {
  2513. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2514. };
  2515. _proto.normalize = function normalize() {
  2516. return this.divideScalar(this.length() || 1);
  2517. };
  2518. _proto.setLength = function setLength(length) {
  2519. return this.normalize().multiplyScalar(length);
  2520. };
  2521. _proto.lerp = function lerp(v, alpha) {
  2522. this.x += (v.x - this.x) * alpha;
  2523. this.y += (v.y - this.y) * alpha;
  2524. this.z += (v.z - this.z) * alpha;
  2525. return this;
  2526. };
  2527. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2528. this.x = v1.x + (v2.x - v1.x) * alpha;
  2529. this.y = v1.y + (v2.y - v1.y) * alpha;
  2530. this.z = v1.z + (v2.z - v1.z) * alpha;
  2531. return this;
  2532. };
  2533. _proto.cross = function cross(v, w) {
  2534. if (w !== undefined) {
  2535. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2536. return this.crossVectors(v, w);
  2537. }
  2538. return this.crossVectors(this, v);
  2539. };
  2540. _proto.crossVectors = function crossVectors(a, b) {
  2541. var ax = a.x,
  2542. ay = a.y,
  2543. az = a.z;
  2544. var bx = b.x,
  2545. by = b.y,
  2546. bz = b.z;
  2547. this.x = ay * bz - az * by;
  2548. this.y = az * bx - ax * bz;
  2549. this.z = ax * by - ay * bx;
  2550. return this;
  2551. };
  2552. _proto.projectOnVector = function projectOnVector(v) {
  2553. var denominator = v.lengthSq();
  2554. if (denominator === 0) return this.set(0, 0, 0);
  2555. var scalar = v.dot(this) / denominator;
  2556. return this.copy(v).multiplyScalar(scalar);
  2557. };
  2558. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2559. _vector.copy(this).projectOnVector(planeNormal);
  2560. return this.sub(_vector);
  2561. };
  2562. _proto.reflect = function reflect(normal) {
  2563. // reflect incident vector off plane orthogonal to normal
  2564. // normal is assumed to have unit length
  2565. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2566. };
  2567. _proto.angleTo = function angleTo(v) {
  2568. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2569. if (denominator === 0) return Math.PI / 2;
  2570. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2571. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2572. };
  2573. _proto.distanceTo = function distanceTo(v) {
  2574. return Math.sqrt(this.distanceToSquared(v));
  2575. };
  2576. _proto.distanceToSquared = function distanceToSquared(v) {
  2577. var dx = this.x - v.x,
  2578. dy = this.y - v.y,
  2579. dz = this.z - v.z;
  2580. return dx * dx + dy * dy + dz * dz;
  2581. };
  2582. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2583. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2584. };
  2585. _proto.setFromSpherical = function setFromSpherical(s) {
  2586. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2587. };
  2588. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2589. var sinPhiRadius = Math.sin(phi) * radius;
  2590. this.x = sinPhiRadius * Math.sin(theta);
  2591. this.y = Math.cos(phi) * radius;
  2592. this.z = sinPhiRadius * Math.cos(theta);
  2593. return this;
  2594. };
  2595. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2596. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2597. };
  2598. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2599. this.x = radius * Math.sin(theta);
  2600. this.y = y;
  2601. this.z = radius * Math.cos(theta);
  2602. return this;
  2603. };
  2604. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2605. var e = m.elements;
  2606. this.x = e[12];
  2607. this.y = e[13];
  2608. this.z = e[14];
  2609. return this;
  2610. };
  2611. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2612. var sx = this.setFromMatrixColumn(m, 0).length();
  2613. var sy = this.setFromMatrixColumn(m, 1).length();
  2614. var sz = this.setFromMatrixColumn(m, 2).length();
  2615. this.x = sx;
  2616. this.y = sy;
  2617. this.z = sz;
  2618. return this;
  2619. };
  2620. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2621. return this.fromArray(m.elements, index * 4);
  2622. };
  2623. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2624. return this.fromArray(m.elements, index * 3);
  2625. };
  2626. _proto.equals = function equals(v) {
  2627. return v.x === this.x && v.y === this.y && v.z === this.z;
  2628. };
  2629. _proto.fromArray = function fromArray(array, offset) {
  2630. if (offset === void 0) {
  2631. offset = 0;
  2632. }
  2633. this.x = array[offset];
  2634. this.y = array[offset + 1];
  2635. this.z = array[offset + 2];
  2636. return this;
  2637. };
  2638. _proto.toArray = function toArray(array, offset) {
  2639. if (array === void 0) {
  2640. array = [];
  2641. }
  2642. if (offset === void 0) {
  2643. offset = 0;
  2644. }
  2645. array[offset] = this.x;
  2646. array[offset + 1] = this.y;
  2647. array[offset + 2] = this.z;
  2648. return array;
  2649. };
  2650. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2651. if (offset !== undefined) {
  2652. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2653. }
  2654. this.x = attribute.getX(index);
  2655. this.y = attribute.getY(index);
  2656. this.z = attribute.getZ(index);
  2657. return this;
  2658. };
  2659. _proto.random = function random() {
  2660. this.x = Math.random();
  2661. this.y = Math.random();
  2662. this.z = Math.random();
  2663. return this;
  2664. };
  2665. return Vector3;
  2666. }();
  2667. var _vector = /*@__PURE__*/new Vector3();
  2668. var _quaternion = /*@__PURE__*/new Quaternion();
  2669. var Box3 = /*#__PURE__*/function () {
  2670. function Box3(min, max) {
  2671. Object.defineProperty(this, 'isBox3', {
  2672. value: true
  2673. });
  2674. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2675. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2676. }
  2677. var _proto = Box3.prototype;
  2678. _proto.set = function set(min, max) {
  2679. this.min.copy(min);
  2680. this.max.copy(max);
  2681. return this;
  2682. };
  2683. _proto.setFromArray = function setFromArray(array) {
  2684. var minX = +Infinity;
  2685. var minY = +Infinity;
  2686. var minZ = +Infinity;
  2687. var maxX = -Infinity;
  2688. var maxY = -Infinity;
  2689. var maxZ = -Infinity;
  2690. for (var i = 0, l = array.length; i < l; i += 3) {
  2691. var x = array[i];
  2692. var y = array[i + 1];
  2693. var z = array[i + 2];
  2694. if (x < minX) minX = x;
  2695. if (y < minY) minY = y;
  2696. if (z < minZ) minZ = z;
  2697. if (x > maxX) maxX = x;
  2698. if (y > maxY) maxY = y;
  2699. if (z > maxZ) maxZ = z;
  2700. }
  2701. this.min.set(minX, minY, minZ);
  2702. this.max.set(maxX, maxY, maxZ);
  2703. return this;
  2704. };
  2705. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2706. var minX = +Infinity;
  2707. var minY = +Infinity;
  2708. var minZ = +Infinity;
  2709. var maxX = -Infinity;
  2710. var maxY = -Infinity;
  2711. var maxZ = -Infinity;
  2712. for (var i = 0, l = attribute.count; i < l; i++) {
  2713. var x = attribute.getX(i);
  2714. var y = attribute.getY(i);
  2715. var z = attribute.getZ(i);
  2716. if (x < minX) minX = x;
  2717. if (y < minY) minY = y;
  2718. if (z < minZ) minZ = z;
  2719. if (x > maxX) maxX = x;
  2720. if (y > maxY) maxY = y;
  2721. if (z > maxZ) maxZ = z;
  2722. }
  2723. this.min.set(minX, minY, minZ);
  2724. this.max.set(maxX, maxY, maxZ);
  2725. return this;
  2726. };
  2727. _proto.setFromPoints = function setFromPoints(points) {
  2728. this.makeEmpty();
  2729. for (var i = 0, il = points.length; i < il; i++) {
  2730. this.expandByPoint(points[i]);
  2731. }
  2732. return this;
  2733. };
  2734. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2735. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2736. this.min.copy(center).sub(halfSize);
  2737. this.max.copy(center).add(halfSize);
  2738. return this;
  2739. };
  2740. _proto.setFromObject = function setFromObject(object) {
  2741. this.makeEmpty();
  2742. return this.expandByObject(object);
  2743. };
  2744. _proto.clone = function clone() {
  2745. return new this.constructor().copy(this);
  2746. };
  2747. _proto.copy = function copy(box) {
  2748. this.min.copy(box.min);
  2749. this.max.copy(box.max);
  2750. return this;
  2751. };
  2752. _proto.makeEmpty = function makeEmpty() {
  2753. this.min.x = this.min.y = this.min.z = +Infinity;
  2754. this.max.x = this.max.y = this.max.z = -Infinity;
  2755. return this;
  2756. };
  2757. _proto.isEmpty = function isEmpty() {
  2758. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2759. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2760. };
  2761. _proto.getCenter = function getCenter(target) {
  2762. if (target === undefined) {
  2763. console.warn('THREE.Box3: .getCenter() target is now required');
  2764. target = new Vector3();
  2765. }
  2766. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2767. };
  2768. _proto.getSize = function getSize(target) {
  2769. if (target === undefined) {
  2770. console.warn('THREE.Box3: .getSize() target is now required');
  2771. target = new Vector3();
  2772. }
  2773. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2774. };
  2775. _proto.expandByPoint = function expandByPoint(point) {
  2776. this.min.min(point);
  2777. this.max.max(point);
  2778. return this;
  2779. };
  2780. _proto.expandByVector = function expandByVector(vector) {
  2781. this.min.sub(vector);
  2782. this.max.add(vector);
  2783. return this;
  2784. };
  2785. _proto.expandByScalar = function expandByScalar(scalar) {
  2786. this.min.addScalar(-scalar);
  2787. this.max.addScalar(scalar);
  2788. return this;
  2789. };
  2790. _proto.expandByObject = function expandByObject(object) {
  2791. // Computes the world-axis-aligned bounding box of an object (including its children),
  2792. // accounting for both the object's, and children's, world transforms
  2793. object.updateWorldMatrix(false, false);
  2794. var geometry = object.geometry;
  2795. if (geometry !== undefined) {
  2796. if (geometry.boundingBox === null) {
  2797. geometry.computeBoundingBox();
  2798. }
  2799. _box.copy(geometry.boundingBox);
  2800. _box.applyMatrix4(object.matrixWorld);
  2801. this.union(_box);
  2802. }
  2803. var children = object.children;
  2804. for (var i = 0, l = children.length; i < l; i++) {
  2805. this.expandByObject(children[i]);
  2806. }
  2807. return this;
  2808. };
  2809. _proto.containsPoint = function containsPoint(point) {
  2810. 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;
  2811. };
  2812. _proto.containsBox = function containsBox(box) {
  2813. 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;
  2814. };
  2815. _proto.getParameter = function getParameter(point, target) {
  2816. // This can potentially have a divide by zero if the box
  2817. // has a size dimension of 0.
  2818. if (target === undefined) {
  2819. console.warn('THREE.Box3: .getParameter() target is now required');
  2820. target = new Vector3();
  2821. }
  2822. 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));
  2823. };
  2824. _proto.intersectsBox = function intersectsBox(box) {
  2825. // using 6 splitting planes to rule out intersections.
  2826. 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;
  2827. };
  2828. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2829. // Find the point on the AABB closest to the sphere center.
  2830. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2831. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2832. };
  2833. _proto.intersectsPlane = function intersectsPlane(plane) {
  2834. // We compute the minimum and maximum dot product values. If those values
  2835. // are on the same side (back or front) of the plane, then there is no intersection.
  2836. var min, max;
  2837. if (plane.normal.x > 0) {
  2838. min = plane.normal.x * this.min.x;
  2839. max = plane.normal.x * this.max.x;
  2840. } else {
  2841. min = plane.normal.x * this.max.x;
  2842. max = plane.normal.x * this.min.x;
  2843. }
  2844. if (plane.normal.y > 0) {
  2845. min += plane.normal.y * this.min.y;
  2846. max += plane.normal.y * this.max.y;
  2847. } else {
  2848. min += plane.normal.y * this.max.y;
  2849. max += plane.normal.y * this.min.y;
  2850. }
  2851. if (plane.normal.z > 0) {
  2852. min += plane.normal.z * this.min.z;
  2853. max += plane.normal.z * this.max.z;
  2854. } else {
  2855. min += plane.normal.z * this.max.z;
  2856. max += plane.normal.z * this.min.z;
  2857. }
  2858. return min <= -plane.constant && max >= -plane.constant;
  2859. };
  2860. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2861. if (this.isEmpty()) {
  2862. return false;
  2863. } // compute box center and extents
  2864. this.getCenter(_center);
  2865. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2866. _v0.subVectors(triangle.a, _center);
  2867. _v1.subVectors(triangle.b, _center);
  2868. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2869. _f0.subVectors(_v1, _v0);
  2870. _f1.subVectors(_v2, _v1);
  2871. _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
  2872. // 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
  2873. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2874. 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];
  2875. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2876. return false;
  2877. } // test 3 face normals from the aabb
  2878. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2879. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2880. return false;
  2881. } // finally testing the face normal of the triangle
  2882. // use already existing triangle edge vectors here
  2883. _triangleNormal.crossVectors(_f0, _f1);
  2884. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2885. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2886. };
  2887. _proto.clampPoint = function clampPoint(point, target) {
  2888. if (target === undefined) {
  2889. console.warn('THREE.Box3: .clampPoint() target is now required');
  2890. target = new Vector3();
  2891. }
  2892. return target.copy(point).clamp(this.min, this.max);
  2893. };
  2894. _proto.distanceToPoint = function distanceToPoint(point) {
  2895. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2896. return clampedPoint.sub(point).length();
  2897. };
  2898. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2899. if (target === undefined) {
  2900. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2901. }
  2902. this.getCenter(target.center);
  2903. target.radius = this.getSize(_vector$1).length() * 0.5;
  2904. return target;
  2905. };
  2906. _proto.intersect = function intersect(box) {
  2907. this.min.max(box.min);
  2908. 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.
  2909. if (this.isEmpty()) this.makeEmpty();
  2910. return this;
  2911. };
  2912. _proto.union = function union(box) {
  2913. this.min.min(box.min);
  2914. this.max.max(box.max);
  2915. return this;
  2916. };
  2917. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2918. // transform of empty box is an empty box.
  2919. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2920. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2921. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2922. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2923. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2924. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2925. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2926. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2927. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2928. this.setFromPoints(_points);
  2929. return this;
  2930. };
  2931. _proto.translate = function translate(offset) {
  2932. this.min.add(offset);
  2933. this.max.add(offset);
  2934. return this;
  2935. };
  2936. _proto.equals = function equals(box) {
  2937. return box.min.equals(this.min) && box.max.equals(this.max);
  2938. };
  2939. return Box3;
  2940. }();
  2941. function satForAxes(axes, v0, v1, v2, extents) {
  2942. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2943. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2944. 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
  2945. var p0 = v0.dot(_testAxis);
  2946. var p1 = v1.dot(_testAxis);
  2947. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2948. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2949. // points of the projected triangle are outside the projected half-length of the aabb
  2950. // the axis is seperating and we can exit
  2951. return false;
  2952. }
  2953. }
  2954. return true;
  2955. }
  2956. 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()];
  2957. var _vector$1 = /*@__PURE__*/new Vector3();
  2958. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2959. var _v0 = /*@__PURE__*/new Vector3();
  2960. var _v1 = /*@__PURE__*/new Vector3();
  2961. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2962. var _f0 = /*@__PURE__*/new Vector3();
  2963. var _f1 = /*@__PURE__*/new Vector3();
  2964. var _f2 = /*@__PURE__*/new Vector3();
  2965. var _center = /*@__PURE__*/new Vector3();
  2966. var _extents = /*@__PURE__*/new Vector3();
  2967. var _triangleNormal = /*@__PURE__*/new Vector3();
  2968. var _testAxis = /*@__PURE__*/new Vector3();
  2969. var _box$1 = /*@__PURE__*/new Box3();
  2970. var Sphere = /*#__PURE__*/function () {
  2971. function Sphere(center, radius) {
  2972. this.center = center !== undefined ? center : new Vector3();
  2973. this.radius = radius !== undefined ? radius : -1;
  2974. }
  2975. var _proto = Sphere.prototype;
  2976. _proto.set = function set(center, radius) {
  2977. this.center.copy(center);
  2978. this.radius = radius;
  2979. return this;
  2980. };
  2981. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2982. var center = this.center;
  2983. if (optionalCenter !== undefined) {
  2984. center.copy(optionalCenter);
  2985. } else {
  2986. _box$1.setFromPoints(points).getCenter(center);
  2987. }
  2988. var maxRadiusSq = 0;
  2989. for (var i = 0, il = points.length; i < il; i++) {
  2990. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2991. }
  2992. this.radius = Math.sqrt(maxRadiusSq);
  2993. return this;
  2994. };
  2995. _proto.clone = function clone() {
  2996. return new this.constructor().copy(this);
  2997. };
  2998. _proto.copy = function copy(sphere) {
  2999. this.center.copy(sphere.center);
  3000. this.radius = sphere.radius;
  3001. return this;
  3002. };
  3003. _proto.isEmpty = function isEmpty() {
  3004. return this.radius < 0;
  3005. };
  3006. _proto.makeEmpty = function makeEmpty() {
  3007. this.center.set(0, 0, 0);
  3008. this.radius = -1;
  3009. return this;
  3010. };
  3011. _proto.containsPoint = function containsPoint(point) {
  3012. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3013. };
  3014. _proto.distanceToPoint = function distanceToPoint(point) {
  3015. return point.distanceTo(this.center) - this.radius;
  3016. };
  3017. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3018. var radiusSum = this.radius + sphere.radius;
  3019. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3020. };
  3021. _proto.intersectsBox = function intersectsBox(box) {
  3022. return box.intersectsSphere(this);
  3023. };
  3024. _proto.intersectsPlane = function intersectsPlane(plane) {
  3025. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3026. };
  3027. _proto.clampPoint = function clampPoint(point, target) {
  3028. var deltaLengthSq = this.center.distanceToSquared(point);
  3029. if (target === undefined) {
  3030. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3031. target = new Vector3();
  3032. }
  3033. target.copy(point);
  3034. if (deltaLengthSq > this.radius * this.radius) {
  3035. target.sub(this.center).normalize();
  3036. target.multiplyScalar(this.radius).add(this.center);
  3037. }
  3038. return target;
  3039. };
  3040. _proto.getBoundingBox = function getBoundingBox(target) {
  3041. if (target === undefined) {
  3042. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3043. target = new Box3();
  3044. }
  3045. if (this.isEmpty()) {
  3046. // Empty sphere produces empty bounding box
  3047. target.makeEmpty();
  3048. return target;
  3049. }
  3050. target.set(this.center, this.center);
  3051. target.expandByScalar(this.radius);
  3052. return target;
  3053. };
  3054. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3055. this.center.applyMatrix4(matrix);
  3056. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3057. return this;
  3058. };
  3059. _proto.translate = function translate(offset) {
  3060. this.center.add(offset);
  3061. return this;
  3062. };
  3063. _proto.equals = function equals(sphere) {
  3064. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3065. };
  3066. return Sphere;
  3067. }();
  3068. var _vector$2 = /*@__PURE__*/new Vector3();
  3069. var _segCenter = /*@__PURE__*/new Vector3();
  3070. var _segDir = /*@__PURE__*/new Vector3();
  3071. var _diff = /*@__PURE__*/new Vector3();
  3072. var _edge1 = /*@__PURE__*/new Vector3();
  3073. var _edge2 = /*@__PURE__*/new Vector3();
  3074. var _normal = /*@__PURE__*/new Vector3();
  3075. var Ray = /*#__PURE__*/function () {
  3076. function Ray(origin, direction) {
  3077. this.origin = origin !== undefined ? origin : new Vector3();
  3078. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3079. }
  3080. var _proto = Ray.prototype;
  3081. _proto.set = function set(origin, direction) {
  3082. this.origin.copy(origin);
  3083. this.direction.copy(direction);
  3084. return this;
  3085. };
  3086. _proto.clone = function clone() {
  3087. return new this.constructor().copy(this);
  3088. };
  3089. _proto.copy = function copy(ray) {
  3090. this.origin.copy(ray.origin);
  3091. this.direction.copy(ray.direction);
  3092. return this;
  3093. };
  3094. _proto.at = function at(t, target) {
  3095. if (target === undefined) {
  3096. console.warn('THREE.Ray: .at() target is now required');
  3097. target = new Vector3();
  3098. }
  3099. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3100. };
  3101. _proto.lookAt = function lookAt(v) {
  3102. this.direction.copy(v).sub(this.origin).normalize();
  3103. return this;
  3104. };
  3105. _proto.recast = function recast(t) {
  3106. this.origin.copy(this.at(t, _vector$2));
  3107. return this;
  3108. };
  3109. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3110. if (target === undefined) {
  3111. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3112. target = new Vector3();
  3113. }
  3114. target.subVectors(point, this.origin);
  3115. var directionDistance = target.dot(this.direction);
  3116. if (directionDistance < 0) {
  3117. return target.copy(this.origin);
  3118. }
  3119. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3120. };
  3121. _proto.distanceToPoint = function distanceToPoint(point) {
  3122. return Math.sqrt(this.distanceSqToPoint(point));
  3123. };
  3124. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3125. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3126. if (directionDistance < 0) {
  3127. return this.origin.distanceToSquared(point);
  3128. }
  3129. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3130. return _vector$2.distanceToSquared(point);
  3131. };
  3132. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3133. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3134. // It returns the min distance between the ray and the segment
  3135. // defined by v0 and v1
  3136. // It can also set two optional targets :
  3137. // - The closest point on the ray
  3138. // - The closest point on the segment
  3139. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3140. _segDir.copy(v1).sub(v0).normalize();
  3141. _diff.copy(this.origin).sub(_segCenter);
  3142. var segExtent = v0.distanceTo(v1) * 0.5;
  3143. var a01 = -this.direction.dot(_segDir);
  3144. var b0 = _diff.dot(this.direction);
  3145. var b1 = -_diff.dot(_segDir);
  3146. var c = _diff.lengthSq();
  3147. var det = Math.abs(1 - a01 * a01);
  3148. var s0, s1, sqrDist, extDet;
  3149. if (det > 0) {
  3150. // The ray and segment are not parallel.
  3151. s0 = a01 * b1 - b0;
  3152. s1 = a01 * b0 - b1;
  3153. extDet = segExtent * det;
  3154. if (s0 >= 0) {
  3155. if (s1 >= -extDet) {
  3156. if (s1 <= extDet) {
  3157. // region 0
  3158. // Minimum at interior points of ray and segment.
  3159. var invDet = 1 / det;
  3160. s0 *= invDet;
  3161. s1 *= invDet;
  3162. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3163. } else {
  3164. // region 1
  3165. s1 = segExtent;
  3166. s0 = Math.max(0, -(a01 * s1 + b0));
  3167. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3168. }
  3169. } else {
  3170. // region 5
  3171. s1 = -segExtent;
  3172. s0 = Math.max(0, -(a01 * s1 + b0));
  3173. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3174. }
  3175. } else {
  3176. if (s1 <= -extDet) {
  3177. // region 4
  3178. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3179. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3180. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3181. } else if (s1 <= extDet) {
  3182. // region 3
  3183. s0 = 0;
  3184. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3185. sqrDist = s1 * (s1 + 2 * b1) + c;
  3186. } else {
  3187. // region 2
  3188. s0 = Math.max(0, -(a01 * segExtent + b0));
  3189. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3190. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3191. }
  3192. }
  3193. } else {
  3194. // Ray and segment are parallel.
  3195. s1 = a01 > 0 ? -segExtent : segExtent;
  3196. s0 = Math.max(0, -(a01 * s1 + b0));
  3197. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3198. }
  3199. if (optionalPointOnRay) {
  3200. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3201. }
  3202. if (optionalPointOnSegment) {
  3203. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3204. }
  3205. return sqrDist;
  3206. };
  3207. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3208. _vector$2.subVectors(sphere.center, this.origin);
  3209. var tca = _vector$2.dot(this.direction);
  3210. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3211. var radius2 = sphere.radius * sphere.radius;
  3212. if (d2 > radius2) return null;
  3213. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3214. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3215. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3216. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3217. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3218. // in order to always return an intersect point that is in front of the ray.
  3219. 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
  3220. return this.at(t0, target);
  3221. };
  3222. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3223. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3224. };
  3225. _proto.distanceToPlane = function distanceToPlane(plane) {
  3226. var denominator = plane.normal.dot(this.direction);
  3227. if (denominator === 0) {
  3228. // line is coplanar, return origin
  3229. if (plane.distanceToPoint(this.origin) === 0) {
  3230. return 0;
  3231. } // Null is preferable to undefined since undefined means.... it is undefined
  3232. return null;
  3233. }
  3234. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3235. return t >= 0 ? t : null;
  3236. };
  3237. _proto.intersectPlane = function intersectPlane(plane, target) {
  3238. var t = this.distanceToPlane(plane);
  3239. if (t === null) {
  3240. return null;
  3241. }
  3242. return this.at(t, target);
  3243. };
  3244. _proto.intersectsPlane = function intersectsPlane(plane) {
  3245. // check if the ray lies on the plane first
  3246. var distToPoint = plane.distanceToPoint(this.origin);
  3247. if (distToPoint === 0) {
  3248. return true;
  3249. }
  3250. var denominator = plane.normal.dot(this.direction);
  3251. if (denominator * distToPoint < 0) {
  3252. return true;
  3253. } // ray origin is behind the plane (and is pointing behind it)
  3254. return false;
  3255. };
  3256. _proto.intersectBox = function intersectBox(box, target) {
  3257. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3258. var invdirx = 1 / this.direction.x,
  3259. invdiry = 1 / this.direction.y,
  3260. invdirz = 1 / this.direction.z;
  3261. var origin = this.origin;
  3262. if (invdirx >= 0) {
  3263. tmin = (box.min.x - origin.x) * invdirx;
  3264. tmax = (box.max.x - origin.x) * invdirx;
  3265. } else {
  3266. tmin = (box.max.x - origin.x) * invdirx;
  3267. tmax = (box.min.x - origin.x) * invdirx;
  3268. }
  3269. if (invdiry >= 0) {
  3270. tymin = (box.min.y - origin.y) * invdiry;
  3271. tymax = (box.max.y - origin.y) * invdiry;
  3272. } else {
  3273. tymin = (box.max.y - origin.y) * invdiry;
  3274. tymax = (box.min.y - origin.y) * invdiry;
  3275. }
  3276. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3277. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3278. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3279. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3280. if (invdirz >= 0) {
  3281. tzmin = (box.min.z - origin.z) * invdirz;
  3282. tzmax = (box.max.z - origin.z) * invdirz;
  3283. } else {
  3284. tzmin = (box.max.z - origin.z) * invdirz;
  3285. tzmax = (box.min.z - origin.z) * invdirz;
  3286. }
  3287. if (tmin > tzmax || tzmin > tmax) return null;
  3288. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3289. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3290. if (tmax < 0) return null;
  3291. return this.at(tmin >= 0 ? tmin : tmax, target);
  3292. };
  3293. _proto.intersectsBox = function intersectsBox(box) {
  3294. return this.intersectBox(box, _vector$2) !== null;
  3295. };
  3296. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3297. // Compute the offset origin, edges, and normal.
  3298. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3299. _edge1.subVectors(b, a);
  3300. _edge2.subVectors(c, a);
  3301. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3302. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3303. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3304. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3305. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3306. var DdN = this.direction.dot(_normal);
  3307. var sign;
  3308. if (DdN > 0) {
  3309. if (backfaceCulling) return null;
  3310. sign = 1;
  3311. } else if (DdN < 0) {
  3312. sign = -1;
  3313. DdN = -DdN;
  3314. } else {
  3315. return null;
  3316. }
  3317. _diff.subVectors(this.origin, a);
  3318. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3319. if (DdQxE2 < 0) {
  3320. return null;
  3321. }
  3322. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3323. if (DdE1xQ < 0) {
  3324. return null;
  3325. } // b1+b2 > 1, no intersection
  3326. if (DdQxE2 + DdE1xQ > DdN) {
  3327. return null;
  3328. } // Line intersects triangle, check if ray does.
  3329. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3330. if (QdN < 0) {
  3331. return null;
  3332. } // Ray intersects triangle.
  3333. return this.at(QdN / DdN, target);
  3334. };
  3335. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3336. this.origin.applyMatrix4(matrix4);
  3337. this.direction.transformDirection(matrix4);
  3338. return this;
  3339. };
  3340. _proto.equals = function equals(ray) {
  3341. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3342. };
  3343. return Ray;
  3344. }();
  3345. var Matrix4 = /*#__PURE__*/function () {
  3346. function Matrix4() {
  3347. Object.defineProperty(this, 'isMatrix4', {
  3348. value: true
  3349. });
  3350. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3351. if (arguments.length > 0) {
  3352. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3353. }
  3354. }
  3355. var _proto = Matrix4.prototype;
  3356. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3357. var te = this.elements;
  3358. te[0] = n11;
  3359. te[4] = n12;
  3360. te[8] = n13;
  3361. te[12] = n14;
  3362. te[1] = n21;
  3363. te[5] = n22;
  3364. te[9] = n23;
  3365. te[13] = n24;
  3366. te[2] = n31;
  3367. te[6] = n32;
  3368. te[10] = n33;
  3369. te[14] = n34;
  3370. te[3] = n41;
  3371. te[7] = n42;
  3372. te[11] = n43;
  3373. te[15] = n44;
  3374. return this;
  3375. };
  3376. _proto.identity = function identity() {
  3377. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3378. return this;
  3379. };
  3380. _proto.clone = function clone() {
  3381. return new Matrix4().fromArray(this.elements);
  3382. };
  3383. _proto.copy = function copy(m) {
  3384. var te = this.elements;
  3385. var me = m.elements;
  3386. te[0] = me[0];
  3387. te[1] = me[1];
  3388. te[2] = me[2];
  3389. te[3] = me[3];
  3390. te[4] = me[4];
  3391. te[5] = me[5];
  3392. te[6] = me[6];
  3393. te[7] = me[7];
  3394. te[8] = me[8];
  3395. te[9] = me[9];
  3396. te[10] = me[10];
  3397. te[11] = me[11];
  3398. te[12] = me[12];
  3399. te[13] = me[13];
  3400. te[14] = me[14];
  3401. te[15] = me[15];
  3402. return this;
  3403. };
  3404. _proto.copyPosition = function copyPosition(m) {
  3405. var te = this.elements,
  3406. me = m.elements;
  3407. te[12] = me[12];
  3408. te[13] = me[13];
  3409. te[14] = me[14];
  3410. return this;
  3411. };
  3412. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  3413. var me = m.elements;
  3414. 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);
  3415. return this;
  3416. };
  3417. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3418. xAxis.setFromMatrixColumn(this, 0);
  3419. yAxis.setFromMatrixColumn(this, 1);
  3420. zAxis.setFromMatrixColumn(this, 2);
  3421. return this;
  3422. };
  3423. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3424. 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);
  3425. return this;
  3426. };
  3427. _proto.extractRotation = function extractRotation(m) {
  3428. // this method does not support reflection matrices
  3429. var te = this.elements;
  3430. var me = m.elements;
  3431. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3432. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3433. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3434. te[0] = me[0] * scaleX;
  3435. te[1] = me[1] * scaleX;
  3436. te[2] = me[2] * scaleX;
  3437. te[3] = 0;
  3438. te[4] = me[4] * scaleY;
  3439. te[5] = me[5] * scaleY;
  3440. te[6] = me[6] * scaleY;
  3441. te[7] = 0;
  3442. te[8] = me[8] * scaleZ;
  3443. te[9] = me[9] * scaleZ;
  3444. te[10] = me[10] * scaleZ;
  3445. te[11] = 0;
  3446. te[12] = 0;
  3447. te[13] = 0;
  3448. te[14] = 0;
  3449. te[15] = 1;
  3450. return this;
  3451. };
  3452. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3453. if (!(euler && euler.isEuler)) {
  3454. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3455. }
  3456. var te = this.elements;
  3457. var x = euler.x,
  3458. y = euler.y,
  3459. z = euler.z;
  3460. var a = Math.cos(x),
  3461. b = Math.sin(x);
  3462. var c = Math.cos(y),
  3463. d = Math.sin(y);
  3464. var e = Math.cos(z),
  3465. f = Math.sin(z);
  3466. if (euler.order === 'XYZ') {
  3467. var ae = a * e,
  3468. af = a * f,
  3469. be = b * e,
  3470. bf = b * f;
  3471. te[0] = c * e;
  3472. te[4] = -c * f;
  3473. te[8] = d;
  3474. te[1] = af + be * d;
  3475. te[5] = ae - bf * d;
  3476. te[9] = -b * c;
  3477. te[2] = bf - ae * d;
  3478. te[6] = be + af * d;
  3479. te[10] = a * c;
  3480. } else if (euler.order === 'YXZ') {
  3481. var ce = c * e,
  3482. cf = c * f,
  3483. de = d * e,
  3484. df = d * f;
  3485. te[0] = ce + df * b;
  3486. te[4] = de * b - cf;
  3487. te[8] = a * d;
  3488. te[1] = a * f;
  3489. te[5] = a * e;
  3490. te[9] = -b;
  3491. te[2] = cf * b - de;
  3492. te[6] = df + ce * b;
  3493. te[10] = a * c;
  3494. } else if (euler.order === 'ZXY') {
  3495. var _ce = c * e,
  3496. _cf = c * f,
  3497. _de = d * e,
  3498. _df = d * f;
  3499. te[0] = _ce - _df * b;
  3500. te[4] = -a * f;
  3501. te[8] = _de + _cf * b;
  3502. te[1] = _cf + _de * b;
  3503. te[5] = a * e;
  3504. te[9] = _df - _ce * b;
  3505. te[2] = -a * d;
  3506. te[6] = b;
  3507. te[10] = a * c;
  3508. } else if (euler.order === 'ZYX') {
  3509. var _ae = a * e,
  3510. _af = a * f,
  3511. _be = b * e,
  3512. _bf = b * f;
  3513. te[0] = c * e;
  3514. te[4] = _be * d - _af;
  3515. te[8] = _ae * d + _bf;
  3516. te[1] = c * f;
  3517. te[5] = _bf * d + _ae;
  3518. te[9] = _af * d - _be;
  3519. te[2] = -d;
  3520. te[6] = b * c;
  3521. te[10] = a * c;
  3522. } else if (euler.order === 'YZX') {
  3523. var ac = a * c,
  3524. ad = a * d,
  3525. bc = b * c,
  3526. bd = b * d;
  3527. te[0] = c * e;
  3528. te[4] = bd - ac * f;
  3529. te[8] = bc * f + ad;
  3530. te[1] = f;
  3531. te[5] = a * e;
  3532. te[9] = -b * e;
  3533. te[2] = -d * e;
  3534. te[6] = ad * f + bc;
  3535. te[10] = ac - bd * f;
  3536. } else if (euler.order === 'XZY') {
  3537. var _ac = a * c,
  3538. _ad = a * d,
  3539. _bc = b * c,
  3540. _bd = b * d;
  3541. te[0] = c * e;
  3542. te[4] = -f;
  3543. te[8] = d * e;
  3544. te[1] = _ac * f + _bd;
  3545. te[5] = a * e;
  3546. te[9] = _ad * f - _bc;
  3547. te[2] = _bc * f - _ad;
  3548. te[6] = b * e;
  3549. te[10] = _bd * f + _ac;
  3550. } // bottom row
  3551. te[3] = 0;
  3552. te[7] = 0;
  3553. te[11] = 0; // last column
  3554. te[12] = 0;
  3555. te[13] = 0;
  3556. te[14] = 0;
  3557. te[15] = 1;
  3558. return this;
  3559. };
  3560. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3561. return this.compose(_zero, q, _one);
  3562. };
  3563. _proto.lookAt = function lookAt(eye, target, up) {
  3564. var te = this.elements;
  3565. _z.subVectors(eye, target);
  3566. if (_z.lengthSq() === 0) {
  3567. // eye and target are in the same position
  3568. _z.z = 1;
  3569. }
  3570. _z.normalize();
  3571. _x.crossVectors(up, _z);
  3572. if (_x.lengthSq() === 0) {
  3573. // up and z are parallel
  3574. if (Math.abs(up.z) === 1) {
  3575. _z.x += 0.0001;
  3576. } else {
  3577. _z.z += 0.0001;
  3578. }
  3579. _z.normalize();
  3580. _x.crossVectors(up, _z);
  3581. }
  3582. _x.normalize();
  3583. _y.crossVectors(_z, _x);
  3584. te[0] = _x.x;
  3585. te[4] = _y.x;
  3586. te[8] = _z.x;
  3587. te[1] = _x.y;
  3588. te[5] = _y.y;
  3589. te[9] = _z.y;
  3590. te[2] = _x.z;
  3591. te[6] = _y.z;
  3592. te[10] = _z.z;
  3593. return this;
  3594. };
  3595. _proto.multiply = function multiply(m, n) {
  3596. if (n !== undefined) {
  3597. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3598. return this.multiplyMatrices(m, n);
  3599. }
  3600. return this.multiplyMatrices(this, m);
  3601. };
  3602. _proto.premultiply = function premultiply(m) {
  3603. return this.multiplyMatrices(m, this);
  3604. };
  3605. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3606. var ae = a.elements;
  3607. var be = b.elements;
  3608. var te = this.elements;
  3609. var a11 = ae[0],
  3610. a12 = ae[4],
  3611. a13 = ae[8],
  3612. a14 = ae[12];
  3613. var a21 = ae[1],
  3614. a22 = ae[5],
  3615. a23 = ae[9],
  3616. a24 = ae[13];
  3617. var a31 = ae[2],
  3618. a32 = ae[6],
  3619. a33 = ae[10],
  3620. a34 = ae[14];
  3621. var a41 = ae[3],
  3622. a42 = ae[7],
  3623. a43 = ae[11],
  3624. a44 = ae[15];
  3625. var b11 = be[0],
  3626. b12 = be[4],
  3627. b13 = be[8],
  3628. b14 = be[12];
  3629. var b21 = be[1],
  3630. b22 = be[5],
  3631. b23 = be[9],
  3632. b24 = be[13];
  3633. var b31 = be[2],
  3634. b32 = be[6],
  3635. b33 = be[10],
  3636. b34 = be[14];
  3637. var b41 = be[3],
  3638. b42 = be[7],
  3639. b43 = be[11],
  3640. b44 = be[15];
  3641. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3642. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3643. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3644. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3645. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3646. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3647. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3648. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3649. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3650. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3651. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3652. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3653. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3654. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3655. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3656. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3657. return this;
  3658. };
  3659. _proto.multiplyScalar = function multiplyScalar(s) {
  3660. var te = this.elements;
  3661. te[0] *= s;
  3662. te[4] *= s;
  3663. te[8] *= s;
  3664. te[12] *= s;
  3665. te[1] *= s;
  3666. te[5] *= s;
  3667. te[9] *= s;
  3668. te[13] *= s;
  3669. te[2] *= s;
  3670. te[6] *= s;
  3671. te[10] *= s;
  3672. te[14] *= s;
  3673. te[3] *= s;
  3674. te[7] *= s;
  3675. te[11] *= s;
  3676. te[15] *= s;
  3677. return this;
  3678. };
  3679. _proto.determinant = function determinant() {
  3680. var te = this.elements;
  3681. var n11 = te[0],
  3682. n12 = te[4],
  3683. n13 = te[8],
  3684. n14 = te[12];
  3685. var n21 = te[1],
  3686. n22 = te[5],
  3687. n23 = te[9],
  3688. n24 = te[13];
  3689. var n31 = te[2],
  3690. n32 = te[6],
  3691. n33 = te[10],
  3692. n34 = te[14];
  3693. var n41 = te[3],
  3694. n42 = te[7],
  3695. n43 = te[11],
  3696. n44 = te[15]; //TODO: make this more efficient
  3697. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3698. 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);
  3699. };
  3700. _proto.transpose = function transpose() {
  3701. var te = this.elements;
  3702. var tmp;
  3703. tmp = te[1];
  3704. te[1] = te[4];
  3705. te[4] = tmp;
  3706. tmp = te[2];
  3707. te[2] = te[8];
  3708. te[8] = tmp;
  3709. tmp = te[6];
  3710. te[6] = te[9];
  3711. te[9] = tmp;
  3712. tmp = te[3];
  3713. te[3] = te[12];
  3714. te[12] = tmp;
  3715. tmp = te[7];
  3716. te[7] = te[13];
  3717. te[13] = tmp;
  3718. tmp = te[11];
  3719. te[11] = te[14];
  3720. te[14] = tmp;
  3721. return this;
  3722. };
  3723. _proto.setPosition = function setPosition(x, y, z) {
  3724. var te = this.elements;
  3725. if (x.isVector3) {
  3726. te[12] = x.x;
  3727. te[13] = x.y;
  3728. te[14] = x.z;
  3729. } else {
  3730. te[12] = x;
  3731. te[13] = y;
  3732. te[14] = z;
  3733. }
  3734. return this;
  3735. };
  3736. _proto.invert = function invert() {
  3737. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3738. var te = this.elements,
  3739. n11 = te[0],
  3740. n21 = te[1],
  3741. n31 = te[2],
  3742. n41 = te[3],
  3743. n12 = te[4],
  3744. n22 = te[5],
  3745. n32 = te[6],
  3746. n42 = te[7],
  3747. n13 = te[8],
  3748. n23 = te[9],
  3749. n33 = te[10],
  3750. n43 = te[11],
  3751. n14 = te[12],
  3752. n24 = te[13],
  3753. n34 = te[14],
  3754. n44 = te[15],
  3755. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3756. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3757. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3758. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3759. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3760. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3761. var detInv = 1 / det;
  3762. te[0] = t11 * detInv;
  3763. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3764. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3765. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3766. te[4] = t12 * detInv;
  3767. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3768. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3769. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3770. te[8] = t13 * detInv;
  3771. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3772. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3773. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3774. te[12] = t14 * detInv;
  3775. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3776. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3777. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3778. return this;
  3779. };
  3780. _proto.scale = function scale(v) {
  3781. var te = this.elements;
  3782. var x = v.x,
  3783. y = v.y,
  3784. z = v.z;
  3785. te[0] *= x;
  3786. te[4] *= y;
  3787. te[8] *= z;
  3788. te[1] *= x;
  3789. te[5] *= y;
  3790. te[9] *= z;
  3791. te[2] *= x;
  3792. te[6] *= y;
  3793. te[10] *= z;
  3794. te[3] *= x;
  3795. te[7] *= y;
  3796. te[11] *= z;
  3797. return this;
  3798. };
  3799. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3800. var te = this.elements;
  3801. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3802. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3803. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3804. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3805. };
  3806. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3807. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3808. return this;
  3809. };
  3810. _proto.makeRotationX = function makeRotationX(theta) {
  3811. var c = Math.cos(theta),
  3812. s = Math.sin(theta);
  3813. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3814. return this;
  3815. };
  3816. _proto.makeRotationY = function makeRotationY(theta) {
  3817. var c = Math.cos(theta),
  3818. s = Math.sin(theta);
  3819. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3820. return this;
  3821. };
  3822. _proto.makeRotationZ = function makeRotationZ(theta) {
  3823. var c = Math.cos(theta),
  3824. s = Math.sin(theta);
  3825. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3826. return this;
  3827. };
  3828. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3829. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3830. var c = Math.cos(angle);
  3831. var s = Math.sin(angle);
  3832. var t = 1 - c;
  3833. var x = axis.x,
  3834. y = axis.y,
  3835. z = axis.z;
  3836. var tx = t * x,
  3837. ty = t * y;
  3838. 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);
  3839. return this;
  3840. };
  3841. _proto.makeScale = function makeScale(x, y, z) {
  3842. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3843. return this;
  3844. };
  3845. _proto.makeShear = function makeShear(x, y, z) {
  3846. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3847. return this;
  3848. };
  3849. _proto.compose = function compose(position, quaternion, scale) {
  3850. var te = this.elements;
  3851. var x = quaternion._x,
  3852. y = quaternion._y,
  3853. z = quaternion._z,
  3854. w = quaternion._w;
  3855. var x2 = x + x,
  3856. y2 = y + y,
  3857. z2 = z + z;
  3858. var xx = x * x2,
  3859. xy = x * y2,
  3860. xz = x * z2;
  3861. var yy = y * y2,
  3862. yz = y * z2,
  3863. zz = z * z2;
  3864. var wx = w * x2,
  3865. wy = w * y2,
  3866. wz = w * z2;
  3867. var sx = scale.x,
  3868. sy = scale.y,
  3869. sz = scale.z;
  3870. te[0] = (1 - (yy + zz)) * sx;
  3871. te[1] = (xy + wz) * sx;
  3872. te[2] = (xz - wy) * sx;
  3873. te[3] = 0;
  3874. te[4] = (xy - wz) * sy;
  3875. te[5] = (1 - (xx + zz)) * sy;
  3876. te[6] = (yz + wx) * sy;
  3877. te[7] = 0;
  3878. te[8] = (xz + wy) * sz;
  3879. te[9] = (yz - wx) * sz;
  3880. te[10] = (1 - (xx + yy)) * sz;
  3881. te[11] = 0;
  3882. te[12] = position.x;
  3883. te[13] = position.y;
  3884. te[14] = position.z;
  3885. te[15] = 1;
  3886. return this;
  3887. };
  3888. _proto.decompose = function decompose(position, quaternion, scale) {
  3889. var te = this.elements;
  3890. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3891. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3892. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3893. var det = this.determinant();
  3894. if (det < 0) sx = -sx;
  3895. position.x = te[12];
  3896. position.y = te[13];
  3897. position.z = te[14]; // scale the rotation part
  3898. _m1.copy(this);
  3899. var invSX = 1 / sx;
  3900. var invSY = 1 / sy;
  3901. var invSZ = 1 / sz;
  3902. _m1.elements[0] *= invSX;
  3903. _m1.elements[1] *= invSX;
  3904. _m1.elements[2] *= invSX;
  3905. _m1.elements[4] *= invSY;
  3906. _m1.elements[5] *= invSY;
  3907. _m1.elements[6] *= invSY;
  3908. _m1.elements[8] *= invSZ;
  3909. _m1.elements[9] *= invSZ;
  3910. _m1.elements[10] *= invSZ;
  3911. quaternion.setFromRotationMatrix(_m1);
  3912. scale.x = sx;
  3913. scale.y = sy;
  3914. scale.z = sz;
  3915. return this;
  3916. };
  3917. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3918. if (far === undefined) {
  3919. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3920. }
  3921. var te = this.elements;
  3922. var x = 2 * near / (right - left);
  3923. var y = 2 * near / (top - bottom);
  3924. var a = (right + left) / (right - left);
  3925. var b = (top + bottom) / (top - bottom);
  3926. var c = -(far + near) / (far - near);
  3927. var d = -2 * far * near / (far - near);
  3928. te[0] = x;
  3929. te[4] = 0;
  3930. te[8] = a;
  3931. te[12] = 0;
  3932. te[1] = 0;
  3933. te[5] = y;
  3934. te[9] = b;
  3935. te[13] = 0;
  3936. te[2] = 0;
  3937. te[6] = 0;
  3938. te[10] = c;
  3939. te[14] = d;
  3940. te[3] = 0;
  3941. te[7] = 0;
  3942. te[11] = -1;
  3943. te[15] = 0;
  3944. return this;
  3945. };
  3946. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3947. var te = this.elements;
  3948. var w = 1.0 / (right - left);
  3949. var h = 1.0 / (top - bottom);
  3950. var p = 1.0 / (far - near);
  3951. var x = (right + left) * w;
  3952. var y = (top + bottom) * h;
  3953. var z = (far + near) * p;
  3954. te[0] = 2 * w;
  3955. te[4] = 0;
  3956. te[8] = 0;
  3957. te[12] = -x;
  3958. te[1] = 0;
  3959. te[5] = 2 * h;
  3960. te[9] = 0;
  3961. te[13] = -y;
  3962. te[2] = 0;
  3963. te[6] = 0;
  3964. te[10] = -2 * p;
  3965. te[14] = -z;
  3966. te[3] = 0;
  3967. te[7] = 0;
  3968. te[11] = 0;
  3969. te[15] = 1;
  3970. return this;
  3971. };
  3972. _proto.equals = function equals(matrix) {
  3973. var te = this.elements;
  3974. var me = matrix.elements;
  3975. for (var i = 0; i < 16; i++) {
  3976. if (te[i] !== me[i]) return false;
  3977. }
  3978. return true;
  3979. };
  3980. _proto.fromArray = function fromArray(array, offset) {
  3981. if (offset === void 0) {
  3982. offset = 0;
  3983. }
  3984. for (var i = 0; i < 16; i++) {
  3985. this.elements[i] = array[i + offset];
  3986. }
  3987. return this;
  3988. };
  3989. _proto.toArray = function toArray(array, offset) {
  3990. if (array === void 0) {
  3991. array = [];
  3992. }
  3993. if (offset === void 0) {
  3994. offset = 0;
  3995. }
  3996. var te = this.elements;
  3997. array[offset] = te[0];
  3998. array[offset + 1] = te[1];
  3999. array[offset + 2] = te[2];
  4000. array[offset + 3] = te[3];
  4001. array[offset + 4] = te[4];
  4002. array[offset + 5] = te[5];
  4003. array[offset + 6] = te[6];
  4004. array[offset + 7] = te[7];
  4005. array[offset + 8] = te[8];
  4006. array[offset + 9] = te[9];
  4007. array[offset + 10] = te[10];
  4008. array[offset + 11] = te[11];
  4009. array[offset + 12] = te[12];
  4010. array[offset + 13] = te[13];
  4011. array[offset + 14] = te[14];
  4012. array[offset + 15] = te[15];
  4013. return array;
  4014. };
  4015. return Matrix4;
  4016. }();
  4017. var _v1$1 = /*@__PURE__*/new Vector3();
  4018. var _m1 = /*@__PURE__*/new Matrix4();
  4019. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4020. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4021. var _x = /*@__PURE__*/new Vector3();
  4022. var _y = /*@__PURE__*/new Vector3();
  4023. var _z = /*@__PURE__*/new Vector3();
  4024. var Euler = /*#__PURE__*/function () {
  4025. function Euler(x, y, z, order) {
  4026. if (x === void 0) {
  4027. x = 0;
  4028. }
  4029. if (y === void 0) {
  4030. y = 0;
  4031. }
  4032. if (z === void 0) {
  4033. z = 0;
  4034. }
  4035. if (order === void 0) {
  4036. order = Euler.DefaultOrder;
  4037. }
  4038. Object.defineProperty(this, 'isEuler', {
  4039. value: true
  4040. });
  4041. this._x = x;
  4042. this._y = y;
  4043. this._z = z;
  4044. this._order = order;
  4045. }
  4046. var _proto = Euler.prototype;
  4047. _proto.set = function set(x, y, z, order) {
  4048. this._x = x;
  4049. this._y = y;
  4050. this._z = z;
  4051. this._order = order || this._order;
  4052. this._onChangeCallback();
  4053. return this;
  4054. };
  4055. _proto.clone = function clone() {
  4056. return new this.constructor(this._x, this._y, this._z, this._order);
  4057. };
  4058. _proto.copy = function copy(euler) {
  4059. this._x = euler._x;
  4060. this._y = euler._y;
  4061. this._z = euler._z;
  4062. this._order = euler._order;
  4063. this._onChangeCallback();
  4064. return this;
  4065. };
  4066. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4067. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4068. var te = m.elements;
  4069. var m11 = te[0],
  4070. m12 = te[4],
  4071. m13 = te[8];
  4072. var m21 = te[1],
  4073. m22 = te[5],
  4074. m23 = te[9];
  4075. var m31 = te[2],
  4076. m32 = te[6],
  4077. m33 = te[10];
  4078. order = order || this._order;
  4079. switch (order) {
  4080. case 'XYZ':
  4081. this._y = Math.asin(clamp(m13, -1, 1));
  4082. if (Math.abs(m13) < 0.9999999) {
  4083. this._x = Math.atan2(-m23, m33);
  4084. this._z = Math.atan2(-m12, m11);
  4085. } else {
  4086. this._x = Math.atan2(m32, m22);
  4087. this._z = 0;
  4088. }
  4089. break;
  4090. case 'YXZ':
  4091. this._x = Math.asin(-clamp(m23, -1, 1));
  4092. if (Math.abs(m23) < 0.9999999) {
  4093. this._y = Math.atan2(m13, m33);
  4094. this._z = Math.atan2(m21, m22);
  4095. } else {
  4096. this._y = Math.atan2(-m31, m11);
  4097. this._z = 0;
  4098. }
  4099. break;
  4100. case 'ZXY':
  4101. this._x = Math.asin(clamp(m32, -1, 1));
  4102. if (Math.abs(m32) < 0.9999999) {
  4103. this._y = Math.atan2(-m31, m33);
  4104. this._z = Math.atan2(-m12, m22);
  4105. } else {
  4106. this._y = 0;
  4107. this._z = Math.atan2(m21, m11);
  4108. }
  4109. break;
  4110. case 'ZYX':
  4111. this._y = Math.asin(-clamp(m31, -1, 1));
  4112. if (Math.abs(m31) < 0.9999999) {
  4113. this._x = Math.atan2(m32, m33);
  4114. this._z = Math.atan2(m21, m11);
  4115. } else {
  4116. this._x = 0;
  4117. this._z = Math.atan2(-m12, m22);
  4118. }
  4119. break;
  4120. case 'YZX':
  4121. this._z = Math.asin(clamp(m21, -1, 1));
  4122. if (Math.abs(m21) < 0.9999999) {
  4123. this._x = Math.atan2(-m23, m22);
  4124. this._y = Math.atan2(-m31, m11);
  4125. } else {
  4126. this._x = 0;
  4127. this._y = Math.atan2(m13, m33);
  4128. }
  4129. break;
  4130. case 'XZY':
  4131. this._z = Math.asin(-clamp(m12, -1, 1));
  4132. if (Math.abs(m12) < 0.9999999) {
  4133. this._x = Math.atan2(m32, m22);
  4134. this._y = Math.atan2(m13, m11);
  4135. } else {
  4136. this._x = Math.atan2(-m23, m33);
  4137. this._y = 0;
  4138. }
  4139. break;
  4140. default:
  4141. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4142. }
  4143. this._order = order;
  4144. if (update !== false) this._onChangeCallback();
  4145. return this;
  4146. };
  4147. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4148. _matrix.makeRotationFromQuaternion(q);
  4149. return this.setFromRotationMatrix(_matrix, order, update);
  4150. };
  4151. _proto.setFromVector3 = function setFromVector3(v, order) {
  4152. return this.set(v.x, v.y, v.z, order || this._order);
  4153. };
  4154. _proto.reorder = function reorder(newOrder) {
  4155. // WARNING: this discards revolution information -bhouston
  4156. _quaternion$1.setFromEuler(this);
  4157. return this.setFromQuaternion(_quaternion$1, newOrder);
  4158. };
  4159. _proto.equals = function equals(euler) {
  4160. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4161. };
  4162. _proto.fromArray = function fromArray(array) {
  4163. this._x = array[0];
  4164. this._y = array[1];
  4165. this._z = array[2];
  4166. if (array[3] !== undefined) this._order = array[3];
  4167. this._onChangeCallback();
  4168. return this;
  4169. };
  4170. _proto.toArray = function toArray(array, offset) {
  4171. if (array === void 0) {
  4172. array = [];
  4173. }
  4174. if (offset === void 0) {
  4175. offset = 0;
  4176. }
  4177. array[offset] = this._x;
  4178. array[offset + 1] = this._y;
  4179. array[offset + 2] = this._z;
  4180. array[offset + 3] = this._order;
  4181. return array;
  4182. };
  4183. _proto.toVector3 = function toVector3(optionalResult) {
  4184. if (optionalResult) {
  4185. return optionalResult.set(this._x, this._y, this._z);
  4186. } else {
  4187. return new Vector3(this._x, this._y, this._z);
  4188. }
  4189. };
  4190. _proto._onChange = function _onChange(callback) {
  4191. this._onChangeCallback = callback;
  4192. return this;
  4193. };
  4194. _proto._onChangeCallback = function _onChangeCallback() {};
  4195. _createClass(Euler, [{
  4196. key: "x",
  4197. get: function get() {
  4198. return this._x;
  4199. },
  4200. set: function set(value) {
  4201. this._x = value;
  4202. this._onChangeCallback();
  4203. }
  4204. }, {
  4205. key: "y",
  4206. get: function get() {
  4207. return this._y;
  4208. },
  4209. set: function set(value) {
  4210. this._y = value;
  4211. this._onChangeCallback();
  4212. }
  4213. }, {
  4214. key: "z",
  4215. get: function get() {
  4216. return this._z;
  4217. },
  4218. set: function set(value) {
  4219. this._z = value;
  4220. this._onChangeCallback();
  4221. }
  4222. }, {
  4223. key: "order",
  4224. get: function get() {
  4225. return this._order;
  4226. },
  4227. set: function set(value) {
  4228. this._order = value;
  4229. this._onChangeCallback();
  4230. }
  4231. }]);
  4232. return Euler;
  4233. }();
  4234. Euler.DefaultOrder = 'XYZ';
  4235. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4236. var _matrix = /*@__PURE__*/new Matrix4();
  4237. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4238. var Layers = /*#__PURE__*/function () {
  4239. function Layers() {
  4240. this.mask = 1 | 0;
  4241. }
  4242. var _proto = Layers.prototype;
  4243. _proto.set = function set(channel) {
  4244. this.mask = 1 << channel | 0;
  4245. };
  4246. _proto.enable = function enable(channel) {
  4247. this.mask |= 1 << channel | 0;
  4248. };
  4249. _proto.enableAll = function enableAll() {
  4250. this.mask = 0xffffffff | 0;
  4251. };
  4252. _proto.toggle = function toggle(channel) {
  4253. this.mask ^= 1 << channel | 0;
  4254. };
  4255. _proto.disable = function disable(channel) {
  4256. this.mask &= ~(1 << channel | 0);
  4257. };
  4258. _proto.disableAll = function disableAll() {
  4259. this.mask = 0;
  4260. };
  4261. _proto.test = function test(layers) {
  4262. return (this.mask & layers.mask) !== 0;
  4263. };
  4264. return Layers;
  4265. }();
  4266. var _object3DId = 0;
  4267. var _v1$2 = new Vector3();
  4268. var _q1 = new Quaternion();
  4269. var _m1$1 = new Matrix4();
  4270. var _target = new Vector3();
  4271. var _position = new Vector3();
  4272. var _scale = new Vector3();
  4273. var _quaternion$2 = new Quaternion();
  4274. var _xAxis = new Vector3(1, 0, 0);
  4275. var _yAxis = new Vector3(0, 1, 0);
  4276. var _zAxis = new Vector3(0, 0, 1);
  4277. var _addedEvent = {
  4278. type: 'added'
  4279. };
  4280. var _removedEvent = {
  4281. type: 'removed'
  4282. };
  4283. function Object3D() {
  4284. Object.defineProperty(this, 'id', {
  4285. value: _object3DId++
  4286. });
  4287. this.uuid = MathUtils.generateUUID();
  4288. this.name = '';
  4289. this.type = 'Object3D';
  4290. this.parent = null;
  4291. this.children = [];
  4292. this.up = Object3D.DefaultUp.clone();
  4293. var position = new Vector3();
  4294. var rotation = new Euler();
  4295. var quaternion = new Quaternion();
  4296. var scale = new Vector3(1, 1, 1);
  4297. function onRotationChange() {
  4298. quaternion.setFromEuler(rotation, false);
  4299. }
  4300. function onQuaternionChange() {
  4301. rotation.setFromQuaternion(quaternion, undefined, false);
  4302. }
  4303. rotation._onChange(onRotationChange);
  4304. quaternion._onChange(onQuaternionChange);
  4305. Object.defineProperties(this, {
  4306. position: {
  4307. configurable: true,
  4308. enumerable: true,
  4309. value: position
  4310. },
  4311. rotation: {
  4312. configurable: true,
  4313. enumerable: true,
  4314. value: rotation
  4315. },
  4316. quaternion: {
  4317. configurable: true,
  4318. enumerable: true,
  4319. value: quaternion
  4320. },
  4321. scale: {
  4322. configurable: true,
  4323. enumerable: true,
  4324. value: scale
  4325. },
  4326. modelViewMatrix: {
  4327. value: new Matrix4()
  4328. },
  4329. normalMatrix: {
  4330. value: new Matrix3()
  4331. }
  4332. });
  4333. this.matrix = new Matrix4();
  4334. this.matrixWorld = new Matrix4();
  4335. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4336. this.matrixWorldNeedsUpdate = false;
  4337. this.layers = new Layers();
  4338. this.visible = true;
  4339. this.castShadow = false;
  4340. this.receiveShadow = false;
  4341. this.frustumCulled = true;
  4342. this.renderOrder = 0;
  4343. this.animations = [];
  4344. this.userData = {};
  4345. }
  4346. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4347. Object3D.DefaultMatrixAutoUpdate = true;
  4348. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4349. constructor: Object3D,
  4350. isObject3D: true,
  4351. onBeforeRender: function onBeforeRender() {},
  4352. onAfterRender: function onAfterRender() {},
  4353. applyMatrix4: function applyMatrix4(matrix) {
  4354. if (this.matrixAutoUpdate) this.updateMatrix();
  4355. this.matrix.premultiply(matrix);
  4356. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4357. },
  4358. applyQuaternion: function applyQuaternion(q) {
  4359. this.quaternion.premultiply(q);
  4360. return this;
  4361. },
  4362. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4363. // assumes axis is normalized
  4364. this.quaternion.setFromAxisAngle(axis, angle);
  4365. },
  4366. setRotationFromEuler: function setRotationFromEuler(euler) {
  4367. this.quaternion.setFromEuler(euler, true);
  4368. },
  4369. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4370. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4371. this.quaternion.setFromRotationMatrix(m);
  4372. },
  4373. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4374. // assumes q is normalized
  4375. this.quaternion.copy(q);
  4376. },
  4377. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4378. // rotate object on axis in object space
  4379. // axis is assumed to be normalized
  4380. _q1.setFromAxisAngle(axis, angle);
  4381. this.quaternion.multiply(_q1);
  4382. return this;
  4383. },
  4384. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4385. // rotate object on axis in world space
  4386. // axis is assumed to be normalized
  4387. // method assumes no rotated parent
  4388. _q1.setFromAxisAngle(axis, angle);
  4389. this.quaternion.premultiply(_q1);
  4390. return this;
  4391. },
  4392. rotateX: function rotateX(angle) {
  4393. return this.rotateOnAxis(_xAxis, angle);
  4394. },
  4395. rotateY: function rotateY(angle) {
  4396. return this.rotateOnAxis(_yAxis, angle);
  4397. },
  4398. rotateZ: function rotateZ(angle) {
  4399. return this.rotateOnAxis(_zAxis, angle);
  4400. },
  4401. translateOnAxis: function translateOnAxis(axis, distance) {
  4402. // translate object by distance along axis in object space
  4403. // axis is assumed to be normalized
  4404. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4405. this.position.add(_v1$2.multiplyScalar(distance));
  4406. return this;
  4407. },
  4408. translateX: function translateX(distance) {
  4409. return this.translateOnAxis(_xAxis, distance);
  4410. },
  4411. translateY: function translateY(distance) {
  4412. return this.translateOnAxis(_yAxis, distance);
  4413. },
  4414. translateZ: function translateZ(distance) {
  4415. return this.translateOnAxis(_zAxis, distance);
  4416. },
  4417. localToWorld: function localToWorld(vector) {
  4418. return vector.applyMatrix4(this.matrixWorld);
  4419. },
  4420. worldToLocal: function worldToLocal(vector) {
  4421. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  4422. },
  4423. lookAt: function lookAt(x, y, z) {
  4424. // This method does not support objects having non-uniformly-scaled parent(s)
  4425. if (x.isVector3) {
  4426. _target.copy(x);
  4427. } else {
  4428. _target.set(x, y, z);
  4429. }
  4430. var parent = this.parent;
  4431. this.updateWorldMatrix(true, false);
  4432. _position.setFromMatrixPosition(this.matrixWorld);
  4433. if (this.isCamera || this.isLight) {
  4434. _m1$1.lookAt(_position, _target, this.up);
  4435. } else {
  4436. _m1$1.lookAt(_target, _position, this.up);
  4437. }
  4438. this.quaternion.setFromRotationMatrix(_m1$1);
  4439. if (parent) {
  4440. _m1$1.extractRotation(parent.matrixWorld);
  4441. _q1.setFromRotationMatrix(_m1$1);
  4442. this.quaternion.premultiply(_q1.invert());
  4443. }
  4444. },
  4445. add: function add(object) {
  4446. if (arguments.length > 1) {
  4447. for (var i = 0; i < arguments.length; i++) {
  4448. this.add(arguments[i]);
  4449. }
  4450. return this;
  4451. }
  4452. if (object === this) {
  4453. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  4454. return this;
  4455. }
  4456. if (object && object.isObject3D) {
  4457. if (object.parent !== null) {
  4458. object.parent.remove(object);
  4459. }
  4460. object.parent = this;
  4461. this.children.push(object);
  4462. object.dispatchEvent(_addedEvent);
  4463. } else {
  4464. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  4465. }
  4466. return this;
  4467. },
  4468. remove: function remove(object) {
  4469. if (arguments.length > 1) {
  4470. for (var i = 0; i < arguments.length; i++) {
  4471. this.remove(arguments[i]);
  4472. }
  4473. return this;
  4474. }
  4475. var index = this.children.indexOf(object);
  4476. if (index !== -1) {
  4477. object.parent = null;
  4478. this.children.splice(index, 1);
  4479. object.dispatchEvent(_removedEvent);
  4480. }
  4481. return this;
  4482. },
  4483. clear: function clear() {
  4484. for (var i = 0; i < this.children.length; i++) {
  4485. var object = this.children[i];
  4486. object.parent = null;
  4487. object.dispatchEvent(_removedEvent);
  4488. }
  4489. this.children.length = 0;
  4490. return this;
  4491. },
  4492. attach: function attach(object) {
  4493. // adds object as a child of this, while maintaining the object's world transform
  4494. this.updateWorldMatrix(true, false);
  4495. _m1$1.copy(this.matrixWorld).invert();
  4496. if (object.parent !== null) {
  4497. object.parent.updateWorldMatrix(true, false);
  4498. _m1$1.multiply(object.parent.matrixWorld);
  4499. }
  4500. object.applyMatrix4(_m1$1);
  4501. object.updateWorldMatrix(false, false);
  4502. this.add(object);
  4503. return this;
  4504. },
  4505. getObjectById: function getObjectById(id) {
  4506. return this.getObjectByProperty('id', id);
  4507. },
  4508. getObjectByName: function getObjectByName(name) {
  4509. return this.getObjectByProperty('name', name);
  4510. },
  4511. getObjectByProperty: function getObjectByProperty(name, value) {
  4512. if (this[name] === value) return this;
  4513. for (var i = 0, l = this.children.length; i < l; i++) {
  4514. var child = this.children[i];
  4515. var object = child.getObjectByProperty(name, value);
  4516. if (object !== undefined) {
  4517. return object;
  4518. }
  4519. }
  4520. return undefined;
  4521. },
  4522. getWorldPosition: function getWorldPosition(target) {
  4523. if (target === undefined) {
  4524. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4525. target = new Vector3();
  4526. }
  4527. this.updateWorldMatrix(true, false);
  4528. return target.setFromMatrixPosition(this.matrixWorld);
  4529. },
  4530. getWorldQuaternion: function getWorldQuaternion(target) {
  4531. if (target === undefined) {
  4532. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4533. target = new Quaternion();
  4534. }
  4535. this.updateWorldMatrix(true, false);
  4536. this.matrixWorld.decompose(_position, target, _scale);
  4537. return target;
  4538. },
  4539. getWorldScale: function getWorldScale(target) {
  4540. if (target === undefined) {
  4541. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4542. target = new Vector3();
  4543. }
  4544. this.updateWorldMatrix(true, false);
  4545. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4546. return target;
  4547. },
  4548. getWorldDirection: function getWorldDirection(target) {
  4549. if (target === undefined) {
  4550. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4551. target = new Vector3();
  4552. }
  4553. this.updateWorldMatrix(true, false);
  4554. var e = this.matrixWorld.elements;
  4555. return target.set(e[8], e[9], e[10]).normalize();
  4556. },
  4557. raycast: function raycast() {},
  4558. traverse: function traverse(callback) {
  4559. callback(this);
  4560. var children = this.children;
  4561. for (var i = 0, l = children.length; i < l; i++) {
  4562. children[i].traverse(callback);
  4563. }
  4564. },
  4565. traverseVisible: function traverseVisible(callback) {
  4566. if (this.visible === false) return;
  4567. callback(this);
  4568. var children = this.children;
  4569. for (var i = 0, l = children.length; i < l; i++) {
  4570. children[i].traverseVisible(callback);
  4571. }
  4572. },
  4573. traverseAncestors: function traverseAncestors(callback) {
  4574. var parent = this.parent;
  4575. if (parent !== null) {
  4576. callback(parent);
  4577. parent.traverseAncestors(callback);
  4578. }
  4579. },
  4580. updateMatrix: function updateMatrix() {
  4581. this.matrix.compose(this.position, this.quaternion, this.scale);
  4582. this.matrixWorldNeedsUpdate = true;
  4583. },
  4584. updateMatrixWorld: function updateMatrixWorld(force) {
  4585. if (this.matrixAutoUpdate) this.updateMatrix();
  4586. if (this.matrixWorldNeedsUpdate || force) {
  4587. if (this.parent === null) {
  4588. this.matrixWorld.copy(this.matrix);
  4589. } else {
  4590. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4591. }
  4592. this.matrixWorldNeedsUpdate = false;
  4593. force = true;
  4594. } // update children
  4595. var children = this.children;
  4596. for (var i = 0, l = children.length; i < l; i++) {
  4597. children[i].updateMatrixWorld(force);
  4598. }
  4599. },
  4600. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4601. var parent = this.parent;
  4602. if (updateParents === true && parent !== null) {
  4603. parent.updateWorldMatrix(true, false);
  4604. }
  4605. if (this.matrixAutoUpdate) this.updateMatrix();
  4606. if (this.parent === null) {
  4607. this.matrixWorld.copy(this.matrix);
  4608. } else {
  4609. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4610. } // update children
  4611. if (updateChildren === true) {
  4612. var children = this.children;
  4613. for (var i = 0, l = children.length; i < l; i++) {
  4614. children[i].updateWorldMatrix(false, true);
  4615. }
  4616. }
  4617. },
  4618. toJSON: function toJSON(meta) {
  4619. // meta is a string when called from JSON.stringify
  4620. var isRootObject = meta === undefined || typeof meta === 'string';
  4621. var output = {}; // meta is a hash used to collect geometries, materials.
  4622. // not providing it implies that this is the root object
  4623. // being serialized.
  4624. if (isRootObject) {
  4625. // initialize meta obj
  4626. meta = {
  4627. geometries: {},
  4628. materials: {},
  4629. textures: {},
  4630. images: {},
  4631. shapes: {},
  4632. skeletons: {},
  4633. animations: {}
  4634. };
  4635. output.metadata = {
  4636. version: 4.5,
  4637. type: 'Object',
  4638. generator: 'Object3D.toJSON'
  4639. };
  4640. } // standard Object3D serialization
  4641. var object = {};
  4642. object.uuid = this.uuid;
  4643. object.type = this.type;
  4644. if (this.name !== '') object.name = this.name;
  4645. if (this.castShadow === true) object.castShadow = true;
  4646. if (this.receiveShadow === true) object.receiveShadow = true;
  4647. if (this.visible === false) object.visible = false;
  4648. if (this.frustumCulled === false) object.frustumCulled = false;
  4649. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4650. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4651. object.layers = this.layers.mask;
  4652. object.matrix = this.matrix.toArray();
  4653. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4654. if (this.isInstancedMesh) {
  4655. object.type = 'InstancedMesh';
  4656. object.count = this.count;
  4657. object.instanceMatrix = this.instanceMatrix.toJSON();
  4658. } //
  4659. function serialize(library, element) {
  4660. if (library[element.uuid] === undefined) {
  4661. library[element.uuid] = element.toJSON(meta);
  4662. }
  4663. return element.uuid;
  4664. }
  4665. if (this.isMesh || this.isLine || this.isPoints) {
  4666. object.geometry = serialize(meta.geometries, this.geometry);
  4667. var parameters = this.geometry.parameters;
  4668. if (parameters !== undefined && parameters.shapes !== undefined) {
  4669. var shapes = parameters.shapes;
  4670. if (Array.isArray(shapes)) {
  4671. for (var i = 0, l = shapes.length; i < l; i++) {
  4672. var shape = shapes[i];
  4673. serialize(meta.shapes, shape);
  4674. }
  4675. } else {
  4676. serialize(meta.shapes, shapes);
  4677. }
  4678. }
  4679. }
  4680. if (this.isSkinnedMesh) {
  4681. object.bindMode = this.bindMode;
  4682. object.bindMatrix = this.bindMatrix.toArray();
  4683. if (this.skeleton !== undefined) {
  4684. serialize(meta.skeletons, this.skeleton);
  4685. object.skeleton = this.skeleton.uuid;
  4686. }
  4687. }
  4688. if (this.material !== undefined) {
  4689. if (Array.isArray(this.material)) {
  4690. var uuids = [];
  4691. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4692. uuids.push(serialize(meta.materials, this.material[_i]));
  4693. }
  4694. object.material = uuids;
  4695. } else {
  4696. object.material = serialize(meta.materials, this.material);
  4697. }
  4698. } //
  4699. if (this.children.length > 0) {
  4700. object.children = [];
  4701. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4702. object.children.push(this.children[_i2].toJSON(meta).object);
  4703. }
  4704. } //
  4705. if (this.animations.length > 0) {
  4706. object.animations = [];
  4707. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  4708. var animation = this.animations[_i3];
  4709. object.animations.push(serialize(meta.animations, animation));
  4710. }
  4711. }
  4712. if (isRootObject) {
  4713. var geometries = extractFromCache(meta.geometries);
  4714. var materials = extractFromCache(meta.materials);
  4715. var textures = extractFromCache(meta.textures);
  4716. var images = extractFromCache(meta.images);
  4717. var _shapes = extractFromCache(meta.shapes);
  4718. var skeletons = extractFromCache(meta.skeletons);
  4719. var animations = extractFromCache(meta.animations);
  4720. if (geometries.length > 0) output.geometries = geometries;
  4721. if (materials.length > 0) output.materials = materials;
  4722. if (textures.length > 0) output.textures = textures;
  4723. if (images.length > 0) output.images = images;
  4724. if (_shapes.length > 0) output.shapes = _shapes;
  4725. if (skeletons.length > 0) output.skeletons = skeletons;
  4726. if (animations.length > 0) output.animations = animations;
  4727. }
  4728. output.object = object;
  4729. return output; // extract data from the cache hash
  4730. // remove metadata on each item
  4731. // and return as array
  4732. function extractFromCache(cache) {
  4733. var values = [];
  4734. for (var key in cache) {
  4735. var data = cache[key];
  4736. delete data.metadata;
  4737. values.push(data);
  4738. }
  4739. return values;
  4740. }
  4741. },
  4742. clone: function clone(recursive) {
  4743. return new this.constructor().copy(this, recursive);
  4744. },
  4745. copy: function copy(source, recursive) {
  4746. if (recursive === void 0) {
  4747. recursive = true;
  4748. }
  4749. this.name = source.name;
  4750. this.up.copy(source.up);
  4751. this.position.copy(source.position);
  4752. this.rotation.order = source.rotation.order;
  4753. this.quaternion.copy(source.quaternion);
  4754. this.scale.copy(source.scale);
  4755. this.matrix.copy(source.matrix);
  4756. this.matrixWorld.copy(source.matrixWorld);
  4757. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4758. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4759. this.layers.mask = source.layers.mask;
  4760. this.visible = source.visible;
  4761. this.castShadow = source.castShadow;
  4762. this.receiveShadow = source.receiveShadow;
  4763. this.frustumCulled = source.frustumCulled;
  4764. this.renderOrder = source.renderOrder;
  4765. this.userData = JSON.parse(JSON.stringify(source.userData));
  4766. if (recursive === true) {
  4767. for (var i = 0; i < source.children.length; i++) {
  4768. var child = source.children[i];
  4769. this.add(child.clone());
  4770. }
  4771. }
  4772. return this;
  4773. }
  4774. });
  4775. var _vector1 = /*@__PURE__*/new Vector3();
  4776. var _vector2 = /*@__PURE__*/new Vector3();
  4777. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4778. var Plane = /*#__PURE__*/function () {
  4779. function Plane(normal, constant) {
  4780. Object.defineProperty(this, 'isPlane', {
  4781. value: true
  4782. }); // normal is assumed to be normalized
  4783. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4784. this.constant = constant !== undefined ? constant : 0;
  4785. }
  4786. var _proto = Plane.prototype;
  4787. _proto.set = function set(normal, constant) {
  4788. this.normal.copy(normal);
  4789. this.constant = constant;
  4790. return this;
  4791. };
  4792. _proto.setComponents = function setComponents(x, y, z, w) {
  4793. this.normal.set(x, y, z);
  4794. this.constant = w;
  4795. return this;
  4796. };
  4797. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4798. this.normal.copy(normal);
  4799. this.constant = -point.dot(this.normal);
  4800. return this;
  4801. };
  4802. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4803. 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)?
  4804. this.setFromNormalAndCoplanarPoint(normal, a);
  4805. return this;
  4806. };
  4807. _proto.clone = function clone() {
  4808. return new this.constructor().copy(this);
  4809. };
  4810. _proto.copy = function copy(plane) {
  4811. this.normal.copy(plane.normal);
  4812. this.constant = plane.constant;
  4813. return this;
  4814. };
  4815. _proto.normalize = function normalize() {
  4816. // Note: will lead to a divide by zero if the plane is invalid.
  4817. var inverseNormalLength = 1.0 / this.normal.length();
  4818. this.normal.multiplyScalar(inverseNormalLength);
  4819. this.constant *= inverseNormalLength;
  4820. return this;
  4821. };
  4822. _proto.negate = function negate() {
  4823. this.constant *= -1;
  4824. this.normal.negate();
  4825. return this;
  4826. };
  4827. _proto.distanceToPoint = function distanceToPoint(point) {
  4828. return this.normal.dot(point) + this.constant;
  4829. };
  4830. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4831. return this.distanceToPoint(sphere.center) - sphere.radius;
  4832. };
  4833. _proto.projectPoint = function projectPoint(point, target) {
  4834. if (target === undefined) {
  4835. console.warn('THREE.Plane: .projectPoint() target is now required');
  4836. target = new Vector3();
  4837. }
  4838. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4839. };
  4840. _proto.intersectLine = function intersectLine(line, target) {
  4841. if (target === undefined) {
  4842. console.warn('THREE.Plane: .intersectLine() target is now required');
  4843. target = new Vector3();
  4844. }
  4845. var direction = line.delta(_vector1);
  4846. var denominator = this.normal.dot(direction);
  4847. if (denominator === 0) {
  4848. // line is coplanar, return origin
  4849. if (this.distanceToPoint(line.start) === 0) {
  4850. return target.copy(line.start);
  4851. } // Unsure if this is the correct method to handle this case.
  4852. return undefined;
  4853. }
  4854. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4855. if (t < 0 || t > 1) {
  4856. return undefined;
  4857. }
  4858. return target.copy(direction).multiplyScalar(t).add(line.start);
  4859. };
  4860. _proto.intersectsLine = function intersectsLine(line) {
  4861. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4862. var startSign = this.distanceToPoint(line.start);
  4863. var endSign = this.distanceToPoint(line.end);
  4864. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4865. };
  4866. _proto.intersectsBox = function intersectsBox(box) {
  4867. return box.intersectsPlane(this);
  4868. };
  4869. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4870. return sphere.intersectsPlane(this);
  4871. };
  4872. _proto.coplanarPoint = function coplanarPoint(target) {
  4873. if (target === undefined) {
  4874. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4875. target = new Vector3();
  4876. }
  4877. return target.copy(this.normal).multiplyScalar(-this.constant);
  4878. };
  4879. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4880. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4881. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4882. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4883. this.constant = -referencePoint.dot(normal);
  4884. return this;
  4885. };
  4886. _proto.translate = function translate(offset) {
  4887. this.constant -= offset.dot(this.normal);
  4888. return this;
  4889. };
  4890. _proto.equals = function equals(plane) {
  4891. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4892. };
  4893. return Plane;
  4894. }();
  4895. var _v0$1 = /*@__PURE__*/new Vector3();
  4896. var _v1$3 = /*@__PURE__*/new Vector3();
  4897. var _v2$1 = /*@__PURE__*/new Vector3();
  4898. var _v3 = /*@__PURE__*/new Vector3();
  4899. var _vab = /*@__PURE__*/new Vector3();
  4900. var _vac = /*@__PURE__*/new Vector3();
  4901. var _vbc = /*@__PURE__*/new Vector3();
  4902. var _vap = /*@__PURE__*/new Vector3();
  4903. var _vbp = /*@__PURE__*/new Vector3();
  4904. var _vcp = /*@__PURE__*/new Vector3();
  4905. var Triangle = /*#__PURE__*/function () {
  4906. function Triangle(a, b, c) {
  4907. this.a = a !== undefined ? a : new Vector3();
  4908. this.b = b !== undefined ? b : new Vector3();
  4909. this.c = c !== undefined ? c : new Vector3();
  4910. }
  4911. Triangle.getNormal = function getNormal(a, b, c, target) {
  4912. if (target === undefined) {
  4913. console.warn('THREE.Triangle: .getNormal() target is now required');
  4914. target = new Vector3();
  4915. }
  4916. target.subVectors(c, b);
  4917. _v0$1.subVectors(a, b);
  4918. target.cross(_v0$1);
  4919. var targetLengthSq = target.lengthSq();
  4920. if (targetLengthSq > 0) {
  4921. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4922. }
  4923. return target.set(0, 0, 0);
  4924. } // static/instance method to calculate barycentric coordinates
  4925. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4926. ;
  4927. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4928. _v0$1.subVectors(c, a);
  4929. _v1$3.subVectors(b, a);
  4930. _v2$1.subVectors(point, a);
  4931. var dot00 = _v0$1.dot(_v0$1);
  4932. var dot01 = _v0$1.dot(_v1$3);
  4933. var dot02 = _v0$1.dot(_v2$1);
  4934. var dot11 = _v1$3.dot(_v1$3);
  4935. var dot12 = _v1$3.dot(_v2$1);
  4936. var denom = dot00 * dot11 - dot01 * dot01;
  4937. if (target === undefined) {
  4938. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4939. target = new Vector3();
  4940. } // collinear or singular triangle
  4941. if (denom === 0) {
  4942. // arbitrary location outside of triangle?
  4943. // not sure if this is the best idea, maybe should be returning undefined
  4944. return target.set(-2, -1, -1);
  4945. }
  4946. var invDenom = 1 / denom;
  4947. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4948. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4949. return target.set(1 - u - v, v, u);
  4950. };
  4951. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4952. this.getBarycoord(point, a, b, c, _v3);
  4953. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4954. };
  4955. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4956. this.getBarycoord(point, p1, p2, p3, _v3);
  4957. target.set(0, 0);
  4958. target.addScaledVector(uv1, _v3.x);
  4959. target.addScaledVector(uv2, _v3.y);
  4960. target.addScaledVector(uv3, _v3.z);
  4961. return target;
  4962. };
  4963. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4964. _v0$1.subVectors(c, b);
  4965. _v1$3.subVectors(a, b); // strictly front facing
  4966. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4967. };
  4968. var _proto = Triangle.prototype;
  4969. _proto.set = function set(a, b, c) {
  4970. this.a.copy(a);
  4971. this.b.copy(b);
  4972. this.c.copy(c);
  4973. return this;
  4974. };
  4975. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4976. this.a.copy(points[i0]);
  4977. this.b.copy(points[i1]);
  4978. this.c.copy(points[i2]);
  4979. return this;
  4980. };
  4981. _proto.clone = function clone() {
  4982. return new this.constructor().copy(this);
  4983. };
  4984. _proto.copy = function copy(triangle) {
  4985. this.a.copy(triangle.a);
  4986. this.b.copy(triangle.b);
  4987. this.c.copy(triangle.c);
  4988. return this;
  4989. };
  4990. _proto.getArea = function getArea() {
  4991. _v0$1.subVectors(this.c, this.b);
  4992. _v1$3.subVectors(this.a, this.b);
  4993. return _v0$1.cross(_v1$3).length() * 0.5;
  4994. };
  4995. _proto.getMidpoint = function getMidpoint(target) {
  4996. if (target === undefined) {
  4997. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4998. target = new Vector3();
  4999. }
  5000. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5001. };
  5002. _proto.getNormal = function getNormal(target) {
  5003. return Triangle.getNormal(this.a, this.b, this.c, target);
  5004. };
  5005. _proto.getPlane = function getPlane(target) {
  5006. if (target === undefined) {
  5007. console.warn('THREE.Triangle: .getPlane() target is now required');
  5008. target = new Plane();
  5009. }
  5010. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5011. };
  5012. _proto.getBarycoord = function getBarycoord(point, target) {
  5013. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5014. };
  5015. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5016. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5017. };
  5018. _proto.containsPoint = function containsPoint(point) {
  5019. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5020. };
  5021. _proto.isFrontFacing = function isFrontFacing(direction) {
  5022. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5023. };
  5024. _proto.intersectsBox = function intersectsBox(box) {
  5025. return box.intersectsTriangle(this);
  5026. };
  5027. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5028. if (target === undefined) {
  5029. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5030. target = new Vector3();
  5031. }
  5032. var a = this.a,
  5033. b = this.b,
  5034. c = this.c;
  5035. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5036. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5037. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5038. // basically, we're distinguishing which of the voronoi regions of the triangle
  5039. // the point lies in with the minimum amount of redundant computation.
  5040. _vab.subVectors(b, a);
  5041. _vac.subVectors(c, a);
  5042. _vap.subVectors(p, a);
  5043. var d1 = _vab.dot(_vap);
  5044. var d2 = _vac.dot(_vap);
  5045. if (d1 <= 0 && d2 <= 0) {
  5046. // vertex region of A; barycentric coords (1, 0, 0)
  5047. return target.copy(a);
  5048. }
  5049. _vbp.subVectors(p, b);
  5050. var d3 = _vab.dot(_vbp);
  5051. var d4 = _vac.dot(_vbp);
  5052. if (d3 >= 0 && d4 <= d3) {
  5053. // vertex region of B; barycentric coords (0, 1, 0)
  5054. return target.copy(b);
  5055. }
  5056. var vc = d1 * d4 - d3 * d2;
  5057. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5058. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5059. return target.copy(a).addScaledVector(_vab, v);
  5060. }
  5061. _vcp.subVectors(p, c);
  5062. var d5 = _vab.dot(_vcp);
  5063. var d6 = _vac.dot(_vcp);
  5064. if (d6 >= 0 && d5 <= d6) {
  5065. // vertex region of C; barycentric coords (0, 0, 1)
  5066. return target.copy(c);
  5067. }
  5068. var vb = d5 * d2 - d1 * d6;
  5069. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5070. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5071. return target.copy(a).addScaledVector(_vac, w);
  5072. }
  5073. var va = d3 * d6 - d5 * d4;
  5074. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5075. _vbc.subVectors(c, b);
  5076. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5077. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5078. } // face region
  5079. var denom = 1 / (va + vb + vc); // u = va * denom
  5080. v = vb * denom;
  5081. w = vc * denom;
  5082. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5083. };
  5084. _proto.equals = function equals(triangle) {
  5085. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5086. };
  5087. return Triangle;
  5088. }();
  5089. var _colorKeywords = {
  5090. 'aliceblue': 0xF0F8FF,
  5091. 'antiquewhite': 0xFAEBD7,
  5092. 'aqua': 0x00FFFF,
  5093. 'aquamarine': 0x7FFFD4,
  5094. 'azure': 0xF0FFFF,
  5095. 'beige': 0xF5F5DC,
  5096. 'bisque': 0xFFE4C4,
  5097. 'black': 0x000000,
  5098. 'blanchedalmond': 0xFFEBCD,
  5099. 'blue': 0x0000FF,
  5100. 'blueviolet': 0x8A2BE2,
  5101. 'brown': 0xA52A2A,
  5102. 'burlywood': 0xDEB887,
  5103. 'cadetblue': 0x5F9EA0,
  5104. 'chartreuse': 0x7FFF00,
  5105. 'chocolate': 0xD2691E,
  5106. 'coral': 0xFF7F50,
  5107. 'cornflowerblue': 0x6495ED,
  5108. 'cornsilk': 0xFFF8DC,
  5109. 'crimson': 0xDC143C,
  5110. 'cyan': 0x00FFFF,
  5111. 'darkblue': 0x00008B,
  5112. 'darkcyan': 0x008B8B,
  5113. 'darkgoldenrod': 0xB8860B,
  5114. 'darkgray': 0xA9A9A9,
  5115. 'darkgreen': 0x006400,
  5116. 'darkgrey': 0xA9A9A9,
  5117. 'darkkhaki': 0xBDB76B,
  5118. 'darkmagenta': 0x8B008B,
  5119. 'darkolivegreen': 0x556B2F,
  5120. 'darkorange': 0xFF8C00,
  5121. 'darkorchid': 0x9932CC,
  5122. 'darkred': 0x8B0000,
  5123. 'darksalmon': 0xE9967A,
  5124. 'darkseagreen': 0x8FBC8F,
  5125. 'darkslateblue': 0x483D8B,
  5126. 'darkslategray': 0x2F4F4F,
  5127. 'darkslategrey': 0x2F4F4F,
  5128. 'darkturquoise': 0x00CED1,
  5129. 'darkviolet': 0x9400D3,
  5130. 'deeppink': 0xFF1493,
  5131. 'deepskyblue': 0x00BFFF,
  5132. 'dimgray': 0x696969,
  5133. 'dimgrey': 0x696969,
  5134. 'dodgerblue': 0x1E90FF,
  5135. 'firebrick': 0xB22222,
  5136. 'floralwhite': 0xFFFAF0,
  5137. 'forestgreen': 0x228B22,
  5138. 'fuchsia': 0xFF00FF,
  5139. 'gainsboro': 0xDCDCDC,
  5140. 'ghostwhite': 0xF8F8FF,
  5141. 'gold': 0xFFD700,
  5142. 'goldenrod': 0xDAA520,
  5143. 'gray': 0x808080,
  5144. 'green': 0x008000,
  5145. 'greenyellow': 0xADFF2F,
  5146. 'grey': 0x808080,
  5147. 'honeydew': 0xF0FFF0,
  5148. 'hotpink': 0xFF69B4,
  5149. 'indianred': 0xCD5C5C,
  5150. 'indigo': 0x4B0082,
  5151. 'ivory': 0xFFFFF0,
  5152. 'khaki': 0xF0E68C,
  5153. 'lavender': 0xE6E6FA,
  5154. 'lavenderblush': 0xFFF0F5,
  5155. 'lawngreen': 0x7CFC00,
  5156. 'lemonchiffon': 0xFFFACD,
  5157. 'lightblue': 0xADD8E6,
  5158. 'lightcoral': 0xF08080,
  5159. 'lightcyan': 0xE0FFFF,
  5160. 'lightgoldenrodyellow': 0xFAFAD2,
  5161. 'lightgray': 0xD3D3D3,
  5162. 'lightgreen': 0x90EE90,
  5163. 'lightgrey': 0xD3D3D3,
  5164. 'lightpink': 0xFFB6C1,
  5165. 'lightsalmon': 0xFFA07A,
  5166. 'lightseagreen': 0x20B2AA,
  5167. 'lightskyblue': 0x87CEFA,
  5168. 'lightslategray': 0x778899,
  5169. 'lightslategrey': 0x778899,
  5170. 'lightsteelblue': 0xB0C4DE,
  5171. 'lightyellow': 0xFFFFE0,
  5172. 'lime': 0x00FF00,
  5173. 'limegreen': 0x32CD32,
  5174. 'linen': 0xFAF0E6,
  5175. 'magenta': 0xFF00FF,
  5176. 'maroon': 0x800000,
  5177. 'mediumaquamarine': 0x66CDAA,
  5178. 'mediumblue': 0x0000CD,
  5179. 'mediumorchid': 0xBA55D3,
  5180. 'mediumpurple': 0x9370DB,
  5181. 'mediumseagreen': 0x3CB371,
  5182. 'mediumslateblue': 0x7B68EE,
  5183. 'mediumspringgreen': 0x00FA9A,
  5184. 'mediumturquoise': 0x48D1CC,
  5185. 'mediumvioletred': 0xC71585,
  5186. 'midnightblue': 0x191970,
  5187. 'mintcream': 0xF5FFFA,
  5188. 'mistyrose': 0xFFE4E1,
  5189. 'moccasin': 0xFFE4B5,
  5190. 'navajowhite': 0xFFDEAD,
  5191. 'navy': 0x000080,
  5192. 'oldlace': 0xFDF5E6,
  5193. 'olive': 0x808000,
  5194. 'olivedrab': 0x6B8E23,
  5195. 'orange': 0xFFA500,
  5196. 'orangered': 0xFF4500,
  5197. 'orchid': 0xDA70D6,
  5198. 'palegoldenrod': 0xEEE8AA,
  5199. 'palegreen': 0x98FB98,
  5200. 'paleturquoise': 0xAFEEEE,
  5201. 'palevioletred': 0xDB7093,
  5202. 'papayawhip': 0xFFEFD5,
  5203. 'peachpuff': 0xFFDAB9,
  5204. 'peru': 0xCD853F,
  5205. 'pink': 0xFFC0CB,
  5206. 'plum': 0xDDA0DD,
  5207. 'powderblue': 0xB0E0E6,
  5208. 'purple': 0x800080,
  5209. 'rebeccapurple': 0x663399,
  5210. 'red': 0xFF0000,
  5211. 'rosybrown': 0xBC8F8F,
  5212. 'royalblue': 0x4169E1,
  5213. 'saddlebrown': 0x8B4513,
  5214. 'salmon': 0xFA8072,
  5215. 'sandybrown': 0xF4A460,
  5216. 'seagreen': 0x2E8B57,
  5217. 'seashell': 0xFFF5EE,
  5218. 'sienna': 0xA0522D,
  5219. 'silver': 0xC0C0C0,
  5220. 'skyblue': 0x87CEEB,
  5221. 'slateblue': 0x6A5ACD,
  5222. 'slategray': 0x708090,
  5223. 'slategrey': 0x708090,
  5224. 'snow': 0xFFFAFA,
  5225. 'springgreen': 0x00FF7F,
  5226. 'steelblue': 0x4682B4,
  5227. 'tan': 0xD2B48C,
  5228. 'teal': 0x008080,
  5229. 'thistle': 0xD8BFD8,
  5230. 'tomato': 0xFF6347,
  5231. 'turquoise': 0x40E0D0,
  5232. 'violet': 0xEE82EE,
  5233. 'wheat': 0xF5DEB3,
  5234. 'white': 0xFFFFFF,
  5235. 'whitesmoke': 0xF5F5F5,
  5236. 'yellow': 0xFFFF00,
  5237. 'yellowgreen': 0x9ACD32
  5238. };
  5239. var _hslA = {
  5240. h: 0,
  5241. s: 0,
  5242. l: 0
  5243. };
  5244. var _hslB = {
  5245. h: 0,
  5246. s: 0,
  5247. l: 0
  5248. };
  5249. function hue2rgb(p, q, t) {
  5250. if (t < 0) t += 1;
  5251. if (t > 1) t -= 1;
  5252. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5253. if (t < 1 / 2) return q;
  5254. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5255. return p;
  5256. }
  5257. function SRGBToLinear(c) {
  5258. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5259. }
  5260. function LinearToSRGB(c) {
  5261. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5262. }
  5263. var Color = /*#__PURE__*/function () {
  5264. function Color(r, g, b) {
  5265. Object.defineProperty(this, 'isColor', {
  5266. value: true
  5267. });
  5268. if (g === undefined && b === undefined) {
  5269. // r is THREE.Color, hex or string
  5270. return this.set(r);
  5271. }
  5272. return this.setRGB(r, g, b);
  5273. }
  5274. var _proto = Color.prototype;
  5275. _proto.set = function set(value) {
  5276. if (value && value.isColor) {
  5277. this.copy(value);
  5278. } else if (typeof value === 'number') {
  5279. this.setHex(value);
  5280. } else if (typeof value === 'string') {
  5281. this.setStyle(value);
  5282. }
  5283. return this;
  5284. };
  5285. _proto.setScalar = function setScalar(scalar) {
  5286. this.r = scalar;
  5287. this.g = scalar;
  5288. this.b = scalar;
  5289. return this;
  5290. };
  5291. _proto.setHex = function setHex(hex) {
  5292. hex = Math.floor(hex);
  5293. this.r = (hex >> 16 & 255) / 255;
  5294. this.g = (hex >> 8 & 255) / 255;
  5295. this.b = (hex & 255) / 255;
  5296. return this;
  5297. };
  5298. _proto.setRGB = function setRGB(r, g, b) {
  5299. this.r = r;
  5300. this.g = g;
  5301. this.b = b;
  5302. return this;
  5303. };
  5304. _proto.setHSL = function setHSL(h, s, l) {
  5305. // h,s,l ranges are in 0.0 - 1.0
  5306. h = MathUtils.euclideanModulo(h, 1);
  5307. s = MathUtils.clamp(s, 0, 1);
  5308. l = MathUtils.clamp(l, 0, 1);
  5309. if (s === 0) {
  5310. this.r = this.g = this.b = l;
  5311. } else {
  5312. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5313. var q = 2 * l - p;
  5314. this.r = hue2rgb(q, p, h + 1 / 3);
  5315. this.g = hue2rgb(q, p, h);
  5316. this.b = hue2rgb(q, p, h - 1 / 3);
  5317. }
  5318. return this;
  5319. };
  5320. _proto.setStyle = function setStyle(style) {
  5321. function handleAlpha(string) {
  5322. if (string === undefined) return;
  5323. if (parseFloat(string) < 1) {
  5324. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5325. }
  5326. }
  5327. var m;
  5328. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5329. // rgb / hsl
  5330. var color;
  5331. var name = m[1];
  5332. var components = m[2];
  5333. switch (name) {
  5334. case 'rgb':
  5335. case 'rgba':
  5336. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5337. // rgb(255,0,0) rgba(255,0,0,0.5)
  5338. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5339. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5340. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5341. handleAlpha(color[4]);
  5342. return this;
  5343. }
  5344. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5345. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5346. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5347. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5348. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5349. handleAlpha(color[4]);
  5350. return this;
  5351. }
  5352. break;
  5353. case 'hsl':
  5354. case 'hsla':
  5355. if (color = /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  5356. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5357. var h = parseFloat(color[1]) / 360;
  5358. var s = parseInt(color[2], 10) / 100;
  5359. var l = parseInt(color[3], 10) / 100;
  5360. handleAlpha(color[4]);
  5361. return this.setHSL(h, s, l);
  5362. }
  5363. break;
  5364. }
  5365. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  5366. // hex color
  5367. var hex = m[1];
  5368. var size = hex.length;
  5369. if (size === 3) {
  5370. // #ff0
  5371. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5372. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5373. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5374. return this;
  5375. } else if (size === 6) {
  5376. // #ff0000
  5377. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5378. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5379. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5380. return this;
  5381. }
  5382. }
  5383. if (style && style.length > 0) {
  5384. return this.setColorName(style);
  5385. }
  5386. return this;
  5387. };
  5388. _proto.setColorName = function setColorName(style) {
  5389. // color keywords
  5390. var hex = _colorKeywords[style];
  5391. if (hex !== undefined) {
  5392. // red
  5393. this.setHex(hex);
  5394. } else {
  5395. // unknown color
  5396. console.warn('THREE.Color: Unknown color ' + style);
  5397. }
  5398. return this;
  5399. };
  5400. _proto.clone = function clone() {
  5401. return new this.constructor(this.r, this.g, this.b);
  5402. };
  5403. _proto.copy = function copy(color) {
  5404. this.r = color.r;
  5405. this.g = color.g;
  5406. this.b = color.b;
  5407. return this;
  5408. };
  5409. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5410. if (gammaFactor === void 0) {
  5411. gammaFactor = 2.0;
  5412. }
  5413. this.r = Math.pow(color.r, gammaFactor);
  5414. this.g = Math.pow(color.g, gammaFactor);
  5415. this.b = Math.pow(color.b, gammaFactor);
  5416. return this;
  5417. };
  5418. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5419. if (gammaFactor === void 0) {
  5420. gammaFactor = 2.0;
  5421. }
  5422. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5423. this.r = Math.pow(color.r, safeInverse);
  5424. this.g = Math.pow(color.g, safeInverse);
  5425. this.b = Math.pow(color.b, safeInverse);
  5426. return this;
  5427. };
  5428. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5429. this.copyGammaToLinear(this, gammaFactor);
  5430. return this;
  5431. };
  5432. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5433. this.copyLinearToGamma(this, gammaFactor);
  5434. return this;
  5435. };
  5436. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5437. this.r = SRGBToLinear(color.r);
  5438. this.g = SRGBToLinear(color.g);
  5439. this.b = SRGBToLinear(color.b);
  5440. return this;
  5441. };
  5442. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5443. this.r = LinearToSRGB(color.r);
  5444. this.g = LinearToSRGB(color.g);
  5445. this.b = LinearToSRGB(color.b);
  5446. return this;
  5447. };
  5448. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5449. this.copySRGBToLinear(this);
  5450. return this;
  5451. };
  5452. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5453. this.copyLinearToSRGB(this);
  5454. return this;
  5455. };
  5456. _proto.getHex = function getHex() {
  5457. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5458. };
  5459. _proto.getHexString = function getHexString() {
  5460. return ('000000' + this.getHex().toString(16)).slice(-6);
  5461. };
  5462. _proto.getHSL = function getHSL(target) {
  5463. // h,s,l ranges are in 0.0 - 1.0
  5464. if (target === undefined) {
  5465. console.warn('THREE.Color: .getHSL() target is now required');
  5466. target = {
  5467. h: 0,
  5468. s: 0,
  5469. l: 0
  5470. };
  5471. }
  5472. var r = this.r,
  5473. g = this.g,
  5474. b = this.b;
  5475. var max = Math.max(r, g, b);
  5476. var min = Math.min(r, g, b);
  5477. var hue, saturation;
  5478. var lightness = (min + max) / 2.0;
  5479. if (min === max) {
  5480. hue = 0;
  5481. saturation = 0;
  5482. } else {
  5483. var delta = max - min;
  5484. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5485. switch (max) {
  5486. case r:
  5487. hue = (g - b) / delta + (g < b ? 6 : 0);
  5488. break;
  5489. case g:
  5490. hue = (b - r) / delta + 2;
  5491. break;
  5492. case b:
  5493. hue = (r - g) / delta + 4;
  5494. break;
  5495. }
  5496. hue /= 6;
  5497. }
  5498. target.h = hue;
  5499. target.s = saturation;
  5500. target.l = lightness;
  5501. return target;
  5502. };
  5503. _proto.getStyle = function getStyle() {
  5504. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5505. };
  5506. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5507. this.getHSL(_hslA);
  5508. _hslA.h += h;
  5509. _hslA.s += s;
  5510. _hslA.l += l;
  5511. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5512. return this;
  5513. };
  5514. _proto.add = function add(color) {
  5515. this.r += color.r;
  5516. this.g += color.g;
  5517. this.b += color.b;
  5518. return this;
  5519. };
  5520. _proto.addColors = function addColors(color1, color2) {
  5521. this.r = color1.r + color2.r;
  5522. this.g = color1.g + color2.g;
  5523. this.b = color1.b + color2.b;
  5524. return this;
  5525. };
  5526. _proto.addScalar = function addScalar(s) {
  5527. this.r += s;
  5528. this.g += s;
  5529. this.b += s;
  5530. return this;
  5531. };
  5532. _proto.sub = function sub(color) {
  5533. this.r = Math.max(0, this.r - color.r);
  5534. this.g = Math.max(0, this.g - color.g);
  5535. this.b = Math.max(0, this.b - color.b);
  5536. return this;
  5537. };
  5538. _proto.multiply = function multiply(color) {
  5539. this.r *= color.r;
  5540. this.g *= color.g;
  5541. this.b *= color.b;
  5542. return this;
  5543. };
  5544. _proto.multiplyScalar = function multiplyScalar(s) {
  5545. this.r *= s;
  5546. this.g *= s;
  5547. this.b *= s;
  5548. return this;
  5549. };
  5550. _proto.lerp = function lerp(color, alpha) {
  5551. this.r += (color.r - this.r) * alpha;
  5552. this.g += (color.g - this.g) * alpha;
  5553. this.b += (color.b - this.b) * alpha;
  5554. return this;
  5555. };
  5556. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5557. this.getHSL(_hslA);
  5558. color.getHSL(_hslB);
  5559. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5560. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5561. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5562. this.setHSL(h, s, l);
  5563. return this;
  5564. };
  5565. _proto.equals = function equals(c) {
  5566. return c.r === this.r && c.g === this.g && c.b === this.b;
  5567. };
  5568. _proto.fromArray = function fromArray(array, offset) {
  5569. if (offset === void 0) {
  5570. offset = 0;
  5571. }
  5572. this.r = array[offset];
  5573. this.g = array[offset + 1];
  5574. this.b = array[offset + 2];
  5575. return this;
  5576. };
  5577. _proto.toArray = function toArray(array, offset) {
  5578. if (array === void 0) {
  5579. array = [];
  5580. }
  5581. if (offset === void 0) {
  5582. offset = 0;
  5583. }
  5584. array[offset] = this.r;
  5585. array[offset + 1] = this.g;
  5586. array[offset + 2] = this.b;
  5587. return array;
  5588. };
  5589. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5590. this.r = attribute.getX(index);
  5591. this.g = attribute.getY(index);
  5592. this.b = attribute.getZ(index);
  5593. if (attribute.normalized === true) {
  5594. // assuming Uint8Array
  5595. this.r /= 255;
  5596. this.g /= 255;
  5597. this.b /= 255;
  5598. }
  5599. return this;
  5600. };
  5601. _proto.toJSON = function toJSON() {
  5602. return this.getHex();
  5603. };
  5604. return Color;
  5605. }();
  5606. Color.NAMES = _colorKeywords;
  5607. Color.prototype.r = 1;
  5608. Color.prototype.g = 1;
  5609. Color.prototype.b = 1;
  5610. var Face3 = /*#__PURE__*/function () {
  5611. function Face3(a, b, c, normal, color, materialIndex) {
  5612. if (materialIndex === void 0) {
  5613. materialIndex = 0;
  5614. }
  5615. this.a = a;
  5616. this.b = b;
  5617. this.c = c;
  5618. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5619. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5620. this.color = color && color.isColor ? color : new Color();
  5621. this.vertexColors = Array.isArray(color) ? color : [];
  5622. this.materialIndex = materialIndex;
  5623. }
  5624. var _proto = Face3.prototype;
  5625. _proto.clone = function clone() {
  5626. return new this.constructor().copy(this);
  5627. };
  5628. _proto.copy = function copy(source) {
  5629. this.a = source.a;
  5630. this.b = source.b;
  5631. this.c = source.c;
  5632. this.normal.copy(source.normal);
  5633. this.color.copy(source.color);
  5634. this.materialIndex = source.materialIndex;
  5635. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5636. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5637. }
  5638. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5639. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5640. }
  5641. return this;
  5642. };
  5643. return Face3;
  5644. }();
  5645. var materialId = 0;
  5646. function Material() {
  5647. Object.defineProperty(this, 'id', {
  5648. value: materialId++
  5649. });
  5650. this.uuid = MathUtils.generateUUID();
  5651. this.name = '';
  5652. this.type = 'Material';
  5653. this.fog = true;
  5654. this.blending = NormalBlending;
  5655. this.side = FrontSide;
  5656. this.flatShading = false;
  5657. this.vertexColors = false;
  5658. this.opacity = 1;
  5659. this.transparent = false;
  5660. this.blendSrc = SrcAlphaFactor;
  5661. this.blendDst = OneMinusSrcAlphaFactor;
  5662. this.blendEquation = AddEquation;
  5663. this.blendSrcAlpha = null;
  5664. this.blendDstAlpha = null;
  5665. this.blendEquationAlpha = null;
  5666. this.depthFunc = LessEqualDepth;
  5667. this.depthTest = true;
  5668. this.depthWrite = true;
  5669. this.stencilWriteMask = 0xff;
  5670. this.stencilFunc = AlwaysStencilFunc;
  5671. this.stencilRef = 0;
  5672. this.stencilFuncMask = 0xff;
  5673. this.stencilFail = KeepStencilOp;
  5674. this.stencilZFail = KeepStencilOp;
  5675. this.stencilZPass = KeepStencilOp;
  5676. this.stencilWrite = false;
  5677. this.clippingPlanes = null;
  5678. this.clipIntersection = false;
  5679. this.clipShadows = false;
  5680. this.shadowSide = null;
  5681. this.colorWrite = true;
  5682. this.precision = null; // override the renderer's default precision for this material
  5683. this.polygonOffset = false;
  5684. this.polygonOffsetFactor = 0;
  5685. this.polygonOffsetUnits = 0;
  5686. this.dithering = false;
  5687. this.alphaTest = 0;
  5688. this.premultipliedAlpha = false;
  5689. this.visible = true;
  5690. this.toneMapped = true;
  5691. this.userData = {};
  5692. this.version = 0;
  5693. }
  5694. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5695. constructor: Material,
  5696. isMaterial: true,
  5697. onBeforeCompile: function onBeforeCompile()
  5698. /* shaderobject, renderer */
  5699. {},
  5700. customProgramCacheKey: function customProgramCacheKey() {
  5701. return this.onBeforeCompile.toString();
  5702. },
  5703. setValues: function setValues(values) {
  5704. if (values === undefined) return;
  5705. for (var key in values) {
  5706. var newValue = values[key];
  5707. if (newValue === undefined) {
  5708. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  5709. continue;
  5710. } // for backward compatability if shading is set in the constructor
  5711. if (key === 'shading') {
  5712. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5713. this.flatShading = newValue === FlatShading ? true : false;
  5714. continue;
  5715. }
  5716. var currentValue = this[key];
  5717. if (currentValue === undefined) {
  5718. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  5719. continue;
  5720. }
  5721. if (currentValue && currentValue.isColor) {
  5722. currentValue.set(newValue);
  5723. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5724. currentValue.copy(newValue);
  5725. } else {
  5726. this[key] = newValue;
  5727. }
  5728. }
  5729. },
  5730. toJSON: function toJSON(meta) {
  5731. var isRoot = meta === undefined || typeof meta === 'string';
  5732. if (isRoot) {
  5733. meta = {
  5734. textures: {},
  5735. images: {}
  5736. };
  5737. }
  5738. var data = {
  5739. metadata: {
  5740. version: 4.5,
  5741. type: 'Material',
  5742. generator: 'Material.toJSON'
  5743. }
  5744. }; // standard Material serialization
  5745. data.uuid = this.uuid;
  5746. data.type = this.type;
  5747. if (this.name !== '') data.name = this.name;
  5748. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5749. if (this.roughness !== undefined) data.roughness = this.roughness;
  5750. if (this.metalness !== undefined) data.metalness = this.metalness;
  5751. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5752. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5753. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5754. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5755. if (this.shininess !== undefined) data.shininess = this.shininess;
  5756. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5757. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5758. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5759. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5760. }
  5761. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5762. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5763. }
  5764. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5765. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5766. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5767. }
  5768. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5769. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5770. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5771. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5772. if (this.aoMap && this.aoMap.isTexture) {
  5773. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5774. data.aoMapIntensity = this.aoMapIntensity;
  5775. }
  5776. if (this.bumpMap && this.bumpMap.isTexture) {
  5777. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5778. data.bumpScale = this.bumpScale;
  5779. }
  5780. if (this.normalMap && this.normalMap.isTexture) {
  5781. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5782. data.normalMapType = this.normalMapType;
  5783. data.normalScale = this.normalScale.toArray();
  5784. }
  5785. if (this.displacementMap && this.displacementMap.isTexture) {
  5786. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5787. data.displacementScale = this.displacementScale;
  5788. data.displacementBias = this.displacementBias;
  5789. }
  5790. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5791. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5792. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5793. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5794. if (this.envMap && this.envMap.isTexture) {
  5795. data.envMap = this.envMap.toJSON(meta).uuid;
  5796. data.reflectivity = this.reflectivity; // Scale behind envMap
  5797. data.refractionRatio = this.refractionRatio;
  5798. if (this.combine !== undefined) data.combine = this.combine;
  5799. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5800. }
  5801. if (this.gradientMap && this.gradientMap.isTexture) {
  5802. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5803. }
  5804. if (this.size !== undefined) data.size = this.size;
  5805. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5806. if (this.blending !== NormalBlending) data.blending = this.blending;
  5807. if (this.flatShading === true) data.flatShading = this.flatShading;
  5808. if (this.side !== FrontSide) data.side = this.side;
  5809. if (this.vertexColors) data.vertexColors = true;
  5810. if (this.opacity < 1) data.opacity = this.opacity;
  5811. if (this.transparent === true) data.transparent = this.transparent;
  5812. data.depthFunc = this.depthFunc;
  5813. data.depthTest = this.depthTest;
  5814. data.depthWrite = this.depthWrite;
  5815. data.stencilWrite = this.stencilWrite;
  5816. data.stencilWriteMask = this.stencilWriteMask;
  5817. data.stencilFunc = this.stencilFunc;
  5818. data.stencilRef = this.stencilRef;
  5819. data.stencilFuncMask = this.stencilFuncMask;
  5820. data.stencilFail = this.stencilFail;
  5821. data.stencilZFail = this.stencilZFail;
  5822. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5823. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5824. if (this.polygonOffset === true) data.polygonOffset = true;
  5825. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5826. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5827. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5828. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5829. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5830. if (this.scale !== undefined) data.scale = this.scale;
  5831. if (this.dithering === true) data.dithering = true;
  5832. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5833. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5834. if (this.wireframe === true) data.wireframe = this.wireframe;
  5835. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5836. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5837. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5838. if (this.morphTargets === true) data.morphTargets = true;
  5839. if (this.morphNormals === true) data.morphNormals = true;
  5840. if (this.skinning === true) data.skinning = true;
  5841. if (this.visible === false) data.visible = false;
  5842. if (this.toneMapped === false) data.toneMapped = false;
  5843. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5844. function extractFromCache(cache) {
  5845. var values = [];
  5846. for (var key in cache) {
  5847. var _data = cache[key];
  5848. delete _data.metadata;
  5849. values.push(_data);
  5850. }
  5851. return values;
  5852. }
  5853. if (isRoot) {
  5854. var textures = extractFromCache(meta.textures);
  5855. var images = extractFromCache(meta.images);
  5856. if (textures.length > 0) data.textures = textures;
  5857. if (images.length > 0) data.images = images;
  5858. }
  5859. return data;
  5860. },
  5861. clone: function clone() {
  5862. return new this.constructor().copy(this);
  5863. },
  5864. copy: function copy(source) {
  5865. this.name = source.name;
  5866. this.fog = source.fog;
  5867. this.blending = source.blending;
  5868. this.side = source.side;
  5869. this.flatShading = source.flatShading;
  5870. this.vertexColors = source.vertexColors;
  5871. this.opacity = source.opacity;
  5872. this.transparent = source.transparent;
  5873. this.blendSrc = source.blendSrc;
  5874. this.blendDst = source.blendDst;
  5875. this.blendEquation = source.blendEquation;
  5876. this.blendSrcAlpha = source.blendSrcAlpha;
  5877. this.blendDstAlpha = source.blendDstAlpha;
  5878. this.blendEquationAlpha = source.blendEquationAlpha;
  5879. this.depthFunc = source.depthFunc;
  5880. this.depthTest = source.depthTest;
  5881. this.depthWrite = source.depthWrite;
  5882. this.stencilWriteMask = source.stencilWriteMask;
  5883. this.stencilFunc = source.stencilFunc;
  5884. this.stencilRef = source.stencilRef;
  5885. this.stencilFuncMask = source.stencilFuncMask;
  5886. this.stencilFail = source.stencilFail;
  5887. this.stencilZFail = source.stencilZFail;
  5888. this.stencilZPass = source.stencilZPass;
  5889. this.stencilWrite = source.stencilWrite;
  5890. var srcPlanes = source.clippingPlanes;
  5891. var dstPlanes = null;
  5892. if (srcPlanes !== null) {
  5893. var n = srcPlanes.length;
  5894. dstPlanes = new Array(n);
  5895. for (var i = 0; i !== n; ++i) {
  5896. dstPlanes[i] = srcPlanes[i].clone();
  5897. }
  5898. }
  5899. this.clippingPlanes = dstPlanes;
  5900. this.clipIntersection = source.clipIntersection;
  5901. this.clipShadows = source.clipShadows;
  5902. this.shadowSide = source.shadowSide;
  5903. this.colorWrite = source.colorWrite;
  5904. this.precision = source.precision;
  5905. this.polygonOffset = source.polygonOffset;
  5906. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5907. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5908. this.dithering = source.dithering;
  5909. this.alphaTest = source.alphaTest;
  5910. this.premultipliedAlpha = source.premultipliedAlpha;
  5911. this.visible = source.visible;
  5912. this.toneMapped = source.toneMapped;
  5913. this.userData = JSON.parse(JSON.stringify(source.userData));
  5914. return this;
  5915. },
  5916. dispose: function dispose() {
  5917. this.dispatchEvent({
  5918. type: 'dispose'
  5919. });
  5920. }
  5921. });
  5922. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5923. set: function set(value) {
  5924. if (value === true) this.version++;
  5925. }
  5926. });
  5927. /**
  5928. * parameters = {
  5929. * color: <hex>,
  5930. * opacity: <float>,
  5931. * map: new THREE.Texture( <Image> ),
  5932. *
  5933. * lightMap: new THREE.Texture( <Image> ),
  5934. * lightMapIntensity: <float>
  5935. *
  5936. * aoMap: new THREE.Texture( <Image> ),
  5937. * aoMapIntensity: <float>
  5938. *
  5939. * specularMap: new THREE.Texture( <Image> ),
  5940. *
  5941. * alphaMap: new THREE.Texture( <Image> ),
  5942. *
  5943. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5944. * combine: THREE.Multiply,
  5945. * reflectivity: <float>,
  5946. * refractionRatio: <float>,
  5947. *
  5948. * depthTest: <bool>,
  5949. * depthWrite: <bool>,
  5950. *
  5951. * wireframe: <boolean>,
  5952. * wireframeLinewidth: <float>,
  5953. *
  5954. * skinning: <bool>,
  5955. * morphTargets: <bool>
  5956. * }
  5957. */
  5958. function MeshBasicMaterial(parameters) {
  5959. Material.call(this);
  5960. this.type = 'MeshBasicMaterial';
  5961. this.color = new Color(0xffffff); // emissive
  5962. this.map = null;
  5963. this.lightMap = null;
  5964. this.lightMapIntensity = 1.0;
  5965. this.aoMap = null;
  5966. this.aoMapIntensity = 1.0;
  5967. this.specularMap = null;
  5968. this.alphaMap = null;
  5969. this.envMap = null;
  5970. this.combine = MultiplyOperation;
  5971. this.reflectivity = 1;
  5972. this.refractionRatio = 0.98;
  5973. this.wireframe = false;
  5974. this.wireframeLinewidth = 1;
  5975. this.wireframeLinecap = 'round';
  5976. this.wireframeLinejoin = 'round';
  5977. this.skinning = false;
  5978. this.morphTargets = false;
  5979. this.setValues(parameters);
  5980. }
  5981. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5982. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5983. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5984. MeshBasicMaterial.prototype.copy = function (source) {
  5985. Material.prototype.copy.call(this, source);
  5986. this.color.copy(source.color);
  5987. this.map = source.map;
  5988. this.lightMap = source.lightMap;
  5989. this.lightMapIntensity = source.lightMapIntensity;
  5990. this.aoMap = source.aoMap;
  5991. this.aoMapIntensity = source.aoMapIntensity;
  5992. this.specularMap = source.specularMap;
  5993. this.alphaMap = source.alphaMap;
  5994. this.envMap = source.envMap;
  5995. this.combine = source.combine;
  5996. this.reflectivity = source.reflectivity;
  5997. this.refractionRatio = source.refractionRatio;
  5998. this.wireframe = source.wireframe;
  5999. this.wireframeLinewidth = source.wireframeLinewidth;
  6000. this.wireframeLinecap = source.wireframeLinecap;
  6001. this.wireframeLinejoin = source.wireframeLinejoin;
  6002. this.skinning = source.skinning;
  6003. this.morphTargets = source.morphTargets;
  6004. return this;
  6005. };
  6006. var _vector$3 = new Vector3();
  6007. var _vector2$1 = new Vector2();
  6008. function BufferAttribute(array, itemSize, normalized) {
  6009. if (Array.isArray(array)) {
  6010. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6011. }
  6012. this.name = '';
  6013. this.array = array;
  6014. this.itemSize = itemSize;
  6015. this.count = array !== undefined ? array.length / itemSize : 0;
  6016. this.normalized = normalized === true;
  6017. this.usage = StaticDrawUsage;
  6018. this.updateRange = {
  6019. offset: 0,
  6020. count: -1
  6021. };
  6022. this.version = 0;
  6023. }
  6024. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6025. set: function set(value) {
  6026. if (value === true) this.version++;
  6027. }
  6028. });
  6029. Object.assign(BufferAttribute.prototype, {
  6030. isBufferAttribute: true,
  6031. onUploadCallback: function onUploadCallback() {},
  6032. setUsage: function setUsage(value) {
  6033. this.usage = value;
  6034. return this;
  6035. },
  6036. copy: function copy(source) {
  6037. this.name = source.name;
  6038. this.array = new source.array.constructor(source.array);
  6039. this.itemSize = source.itemSize;
  6040. this.count = source.count;
  6041. this.normalized = source.normalized;
  6042. this.usage = source.usage;
  6043. return this;
  6044. },
  6045. copyAt: function copyAt(index1, attribute, index2) {
  6046. index1 *= this.itemSize;
  6047. index2 *= attribute.itemSize;
  6048. for (var i = 0, l = this.itemSize; i < l; i++) {
  6049. this.array[index1 + i] = attribute.array[index2 + i];
  6050. }
  6051. return this;
  6052. },
  6053. copyArray: function copyArray(array) {
  6054. this.array.set(array);
  6055. return this;
  6056. },
  6057. copyColorsArray: function copyColorsArray(colors) {
  6058. var array = this.array;
  6059. var offset = 0;
  6060. for (var i = 0, l = colors.length; i < l; i++) {
  6061. var color = colors[i];
  6062. if (color === undefined) {
  6063. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6064. color = new Color();
  6065. }
  6066. array[offset++] = color.r;
  6067. array[offset++] = color.g;
  6068. array[offset++] = color.b;
  6069. }
  6070. return this;
  6071. },
  6072. copyVector2sArray: function copyVector2sArray(vectors) {
  6073. var array = this.array;
  6074. var offset = 0;
  6075. for (var i = 0, l = vectors.length; i < l; i++) {
  6076. var vector = vectors[i];
  6077. if (vector === undefined) {
  6078. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6079. vector = new Vector2();
  6080. }
  6081. array[offset++] = vector.x;
  6082. array[offset++] = vector.y;
  6083. }
  6084. return this;
  6085. },
  6086. copyVector3sArray: function copyVector3sArray(vectors) {
  6087. var array = this.array;
  6088. var offset = 0;
  6089. for (var i = 0, l = vectors.length; i < l; i++) {
  6090. var vector = vectors[i];
  6091. if (vector === undefined) {
  6092. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6093. vector = new Vector3();
  6094. }
  6095. array[offset++] = vector.x;
  6096. array[offset++] = vector.y;
  6097. array[offset++] = vector.z;
  6098. }
  6099. return this;
  6100. },
  6101. copyVector4sArray: function copyVector4sArray(vectors) {
  6102. var array = this.array;
  6103. var offset = 0;
  6104. for (var i = 0, l = vectors.length; i < l; i++) {
  6105. var vector = vectors[i];
  6106. if (vector === undefined) {
  6107. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6108. vector = new Vector4();
  6109. }
  6110. array[offset++] = vector.x;
  6111. array[offset++] = vector.y;
  6112. array[offset++] = vector.z;
  6113. array[offset++] = vector.w;
  6114. }
  6115. return this;
  6116. },
  6117. applyMatrix3: function applyMatrix3(m) {
  6118. if (this.itemSize === 2) {
  6119. for (var i = 0, l = this.count; i < l; i++) {
  6120. _vector2$1.fromBufferAttribute(this, i);
  6121. _vector2$1.applyMatrix3(m);
  6122. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6123. }
  6124. } else if (this.itemSize === 3) {
  6125. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6126. _vector$3.fromBufferAttribute(this, _i);
  6127. _vector$3.applyMatrix3(m);
  6128. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6129. }
  6130. }
  6131. return this;
  6132. },
  6133. applyMatrix4: function applyMatrix4(m) {
  6134. for (var i = 0, l = this.count; i < l; i++) {
  6135. _vector$3.x = this.getX(i);
  6136. _vector$3.y = this.getY(i);
  6137. _vector$3.z = this.getZ(i);
  6138. _vector$3.applyMatrix4(m);
  6139. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6140. }
  6141. return this;
  6142. },
  6143. applyNormalMatrix: function applyNormalMatrix(m) {
  6144. for (var i = 0, l = this.count; i < l; i++) {
  6145. _vector$3.x = this.getX(i);
  6146. _vector$3.y = this.getY(i);
  6147. _vector$3.z = this.getZ(i);
  6148. _vector$3.applyNormalMatrix(m);
  6149. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6150. }
  6151. return this;
  6152. },
  6153. transformDirection: function transformDirection(m) {
  6154. for (var i = 0, l = this.count; i < l; i++) {
  6155. _vector$3.x = this.getX(i);
  6156. _vector$3.y = this.getY(i);
  6157. _vector$3.z = this.getZ(i);
  6158. _vector$3.transformDirection(m);
  6159. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6160. }
  6161. return this;
  6162. },
  6163. set: function set(value, offset) {
  6164. if (offset === void 0) {
  6165. offset = 0;
  6166. }
  6167. this.array.set(value, offset);
  6168. return this;
  6169. },
  6170. getX: function getX(index) {
  6171. return this.array[index * this.itemSize];
  6172. },
  6173. setX: function setX(index, x) {
  6174. this.array[index * this.itemSize] = x;
  6175. return this;
  6176. },
  6177. getY: function getY(index) {
  6178. return this.array[index * this.itemSize + 1];
  6179. },
  6180. setY: function setY(index, y) {
  6181. this.array[index * this.itemSize + 1] = y;
  6182. return this;
  6183. },
  6184. getZ: function getZ(index) {
  6185. return this.array[index * this.itemSize + 2];
  6186. },
  6187. setZ: function setZ(index, z) {
  6188. this.array[index * this.itemSize + 2] = z;
  6189. return this;
  6190. },
  6191. getW: function getW(index) {
  6192. return this.array[index * this.itemSize + 3];
  6193. },
  6194. setW: function setW(index, w) {
  6195. this.array[index * this.itemSize + 3] = w;
  6196. return this;
  6197. },
  6198. setXY: function setXY(index, x, y) {
  6199. index *= this.itemSize;
  6200. this.array[index + 0] = x;
  6201. this.array[index + 1] = y;
  6202. return this;
  6203. },
  6204. setXYZ: function setXYZ(index, x, y, z) {
  6205. index *= this.itemSize;
  6206. this.array[index + 0] = x;
  6207. this.array[index + 1] = y;
  6208. this.array[index + 2] = z;
  6209. return this;
  6210. },
  6211. setXYZW: function setXYZW(index, x, y, z, w) {
  6212. index *= this.itemSize;
  6213. this.array[index + 0] = x;
  6214. this.array[index + 1] = y;
  6215. this.array[index + 2] = z;
  6216. this.array[index + 3] = w;
  6217. return this;
  6218. },
  6219. onUpload: function onUpload(callback) {
  6220. this.onUploadCallback = callback;
  6221. return this;
  6222. },
  6223. clone: function clone() {
  6224. return new this.constructor(this.array, this.itemSize).copy(this);
  6225. },
  6226. toJSON: function toJSON() {
  6227. return {
  6228. itemSize: this.itemSize,
  6229. type: this.array.constructor.name,
  6230. array: Array.prototype.slice.call(this.array),
  6231. normalized: this.normalized
  6232. };
  6233. }
  6234. }); //
  6235. function Int8BufferAttribute(array, itemSize, normalized) {
  6236. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6237. }
  6238. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6239. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6240. function Uint8BufferAttribute(array, itemSize, normalized) {
  6241. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6242. }
  6243. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6244. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6245. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6246. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6247. }
  6248. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6249. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6250. function Int16BufferAttribute(array, itemSize, normalized) {
  6251. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6252. }
  6253. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6254. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6255. function Uint16BufferAttribute(array, itemSize, normalized) {
  6256. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6257. }
  6258. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6259. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6260. function Int32BufferAttribute(array, itemSize, normalized) {
  6261. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6262. }
  6263. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6264. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6265. function Uint32BufferAttribute(array, itemSize, normalized) {
  6266. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6267. }
  6268. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6269. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6270. function Float16BufferAttribute(array, itemSize, normalized) {
  6271. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6272. }
  6273. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6274. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6275. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6276. function Float32BufferAttribute(array, itemSize, normalized) {
  6277. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6278. }
  6279. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6280. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6281. function Float64BufferAttribute(array, itemSize, normalized) {
  6282. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6283. }
  6284. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6285. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6286. var DirectGeometry = /*#__PURE__*/function () {
  6287. function DirectGeometry() {
  6288. this.vertices = [];
  6289. this.normals = [];
  6290. this.colors = [];
  6291. this.uvs = [];
  6292. this.uvs2 = [];
  6293. this.groups = [];
  6294. this.morphTargets = {};
  6295. this.skinWeights = [];
  6296. this.skinIndices = []; // this.lineDistances = [];
  6297. this.boundingBox = null;
  6298. this.boundingSphere = null; // update flags
  6299. this.verticesNeedUpdate = false;
  6300. this.normalsNeedUpdate = false;
  6301. this.colorsNeedUpdate = false;
  6302. this.uvsNeedUpdate = false;
  6303. this.groupsNeedUpdate = false;
  6304. }
  6305. var _proto = DirectGeometry.prototype;
  6306. _proto.computeGroups = function computeGroups(geometry) {
  6307. var groups = [];
  6308. var group, i;
  6309. var materialIndex = undefined;
  6310. var faces = geometry.faces;
  6311. for (i = 0; i < faces.length; i++) {
  6312. var face = faces[i]; // materials
  6313. if (face.materialIndex !== materialIndex) {
  6314. materialIndex = face.materialIndex;
  6315. if (group !== undefined) {
  6316. group.count = i * 3 - group.start;
  6317. groups.push(group);
  6318. }
  6319. group = {
  6320. start: i * 3,
  6321. materialIndex: materialIndex
  6322. };
  6323. }
  6324. }
  6325. if (group !== undefined) {
  6326. group.count = i * 3 - group.start;
  6327. groups.push(group);
  6328. }
  6329. this.groups = groups;
  6330. };
  6331. _proto.fromGeometry = function fromGeometry(geometry) {
  6332. var faces = geometry.faces;
  6333. var vertices = geometry.vertices;
  6334. var faceVertexUvs = geometry.faceVertexUvs;
  6335. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6336. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6337. var morphTargets = geometry.morphTargets;
  6338. var morphTargetsLength = morphTargets.length;
  6339. var morphTargetsPosition;
  6340. if (morphTargetsLength > 0) {
  6341. morphTargetsPosition = [];
  6342. for (var i = 0; i < morphTargetsLength; i++) {
  6343. morphTargetsPosition[i] = {
  6344. name: morphTargets[i].name,
  6345. data: []
  6346. };
  6347. }
  6348. this.morphTargets.position = morphTargetsPosition;
  6349. }
  6350. var morphNormals = geometry.morphNormals;
  6351. var morphNormalsLength = morphNormals.length;
  6352. var morphTargetsNormal;
  6353. if (morphNormalsLength > 0) {
  6354. morphTargetsNormal = [];
  6355. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6356. morphTargetsNormal[_i] = {
  6357. name: morphNormals[_i].name,
  6358. data: []
  6359. };
  6360. }
  6361. this.morphTargets.normal = morphTargetsNormal;
  6362. } // skins
  6363. var skinIndices = geometry.skinIndices;
  6364. var skinWeights = geometry.skinWeights;
  6365. var hasSkinIndices = skinIndices.length === vertices.length;
  6366. var hasSkinWeights = skinWeights.length === vertices.length; //
  6367. if (vertices.length > 0 && faces.length === 0) {
  6368. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6369. }
  6370. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6371. var face = faces[_i2];
  6372. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6373. var vertexNormals = face.vertexNormals;
  6374. if (vertexNormals.length === 3) {
  6375. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6376. } else {
  6377. var normal = face.normal;
  6378. this.normals.push(normal, normal, normal);
  6379. }
  6380. var vertexColors = face.vertexColors;
  6381. if (vertexColors.length === 3) {
  6382. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6383. } else {
  6384. var color = face.color;
  6385. this.colors.push(color, color, color);
  6386. }
  6387. if (hasFaceVertexUv === true) {
  6388. var vertexUvs = faceVertexUvs[0][_i2];
  6389. if (vertexUvs !== undefined) {
  6390. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6391. } else {
  6392. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6393. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6394. }
  6395. }
  6396. if (hasFaceVertexUv2 === true) {
  6397. var _vertexUvs = faceVertexUvs[1][_i2];
  6398. if (_vertexUvs !== undefined) {
  6399. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6400. } else {
  6401. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6402. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6403. }
  6404. } // morphs
  6405. for (var j = 0; j < morphTargetsLength; j++) {
  6406. var morphTarget = morphTargets[j].vertices;
  6407. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6408. }
  6409. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6410. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6411. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6412. } // skins
  6413. if (hasSkinIndices) {
  6414. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6415. }
  6416. if (hasSkinWeights) {
  6417. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6418. }
  6419. }
  6420. this.computeGroups(geometry);
  6421. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6422. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6423. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6424. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6425. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6426. if (geometry.boundingSphere !== null) {
  6427. this.boundingSphere = geometry.boundingSphere.clone();
  6428. }
  6429. if (geometry.boundingBox !== null) {
  6430. this.boundingBox = geometry.boundingBox.clone();
  6431. }
  6432. return this;
  6433. };
  6434. return DirectGeometry;
  6435. }();
  6436. function arrayMax(array) {
  6437. if (array.length === 0) return -Infinity;
  6438. var max = array[0];
  6439. for (var i = 1, l = array.length; i < l; ++i) {
  6440. if (array[i] > max) max = array[i];
  6441. }
  6442. return max;
  6443. }
  6444. var TYPED_ARRAYS = {
  6445. Int8Array: Int8Array,
  6446. Uint8Array: Uint8Array,
  6447. // Workaround for IE11 pre KB2929437. See #11440
  6448. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6449. Int16Array: Int16Array,
  6450. Uint16Array: Uint16Array,
  6451. Int32Array: Int32Array,
  6452. Uint32Array: Uint32Array,
  6453. Float32Array: Float32Array,
  6454. Float64Array: Float64Array
  6455. };
  6456. function getTypedArray(type, buffer) {
  6457. return new TYPED_ARRAYS[type](buffer);
  6458. }
  6459. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6460. var _m1$2 = new Matrix4();
  6461. var _obj = new Object3D();
  6462. var _offset = new Vector3();
  6463. var _box$2 = new Box3();
  6464. var _boxMorphTargets = new Box3();
  6465. var _vector$4 = new Vector3();
  6466. function BufferGeometry() {
  6467. Object.defineProperty(this, 'id', {
  6468. value: _bufferGeometryId += 2
  6469. });
  6470. this.uuid = MathUtils.generateUUID();
  6471. this.name = '';
  6472. this.type = 'BufferGeometry';
  6473. this.index = null;
  6474. this.attributes = {};
  6475. this.morphAttributes = {};
  6476. this.morphTargetsRelative = false;
  6477. this.groups = [];
  6478. this.boundingBox = null;
  6479. this.boundingSphere = null;
  6480. this.drawRange = {
  6481. start: 0,
  6482. count: Infinity
  6483. };
  6484. this.userData = {};
  6485. }
  6486. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6487. constructor: BufferGeometry,
  6488. isBufferGeometry: true,
  6489. getIndex: function getIndex() {
  6490. return this.index;
  6491. },
  6492. setIndex: function setIndex(index) {
  6493. if (Array.isArray(index)) {
  6494. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6495. } else {
  6496. this.index = index;
  6497. }
  6498. return this;
  6499. },
  6500. getAttribute: function getAttribute(name) {
  6501. return this.attributes[name];
  6502. },
  6503. setAttribute: function setAttribute(name, attribute) {
  6504. this.attributes[name] = attribute;
  6505. return this;
  6506. },
  6507. deleteAttribute: function deleteAttribute(name) {
  6508. delete this.attributes[name];
  6509. return this;
  6510. },
  6511. hasAttribute: function hasAttribute(name) {
  6512. return this.attributes[name] !== undefined;
  6513. },
  6514. addGroup: function addGroup(start, count, materialIndex) {
  6515. if (materialIndex === void 0) {
  6516. materialIndex = 0;
  6517. }
  6518. this.groups.push({
  6519. start: start,
  6520. count: count,
  6521. materialIndex: materialIndex
  6522. });
  6523. },
  6524. clearGroups: function clearGroups() {
  6525. this.groups = [];
  6526. },
  6527. setDrawRange: function setDrawRange(start, count) {
  6528. this.drawRange.start = start;
  6529. this.drawRange.count = count;
  6530. },
  6531. applyMatrix4: function applyMatrix4(matrix) {
  6532. var position = this.attributes.position;
  6533. if (position !== undefined) {
  6534. position.applyMatrix4(matrix);
  6535. position.needsUpdate = true;
  6536. }
  6537. var normal = this.attributes.normal;
  6538. if (normal !== undefined) {
  6539. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6540. normal.applyNormalMatrix(normalMatrix);
  6541. normal.needsUpdate = true;
  6542. }
  6543. var tangent = this.attributes.tangent;
  6544. if (tangent !== undefined) {
  6545. tangent.transformDirection(matrix);
  6546. tangent.needsUpdate = true;
  6547. }
  6548. if (this.boundingBox !== null) {
  6549. this.computeBoundingBox();
  6550. }
  6551. if (this.boundingSphere !== null) {
  6552. this.computeBoundingSphere();
  6553. }
  6554. return this;
  6555. },
  6556. rotateX: function rotateX(angle) {
  6557. // rotate geometry around world x-axis
  6558. _m1$2.makeRotationX(angle);
  6559. this.applyMatrix4(_m1$2);
  6560. return this;
  6561. },
  6562. rotateY: function rotateY(angle) {
  6563. // rotate geometry around world y-axis
  6564. _m1$2.makeRotationY(angle);
  6565. this.applyMatrix4(_m1$2);
  6566. return this;
  6567. },
  6568. rotateZ: function rotateZ(angle) {
  6569. // rotate geometry around world z-axis
  6570. _m1$2.makeRotationZ(angle);
  6571. this.applyMatrix4(_m1$2);
  6572. return this;
  6573. },
  6574. translate: function translate(x, y, z) {
  6575. // translate geometry
  6576. _m1$2.makeTranslation(x, y, z);
  6577. this.applyMatrix4(_m1$2);
  6578. return this;
  6579. },
  6580. scale: function scale(x, y, z) {
  6581. // scale geometry
  6582. _m1$2.makeScale(x, y, z);
  6583. this.applyMatrix4(_m1$2);
  6584. return this;
  6585. },
  6586. lookAt: function lookAt(vector) {
  6587. _obj.lookAt(vector);
  6588. _obj.updateMatrix();
  6589. this.applyMatrix4(_obj.matrix);
  6590. return this;
  6591. },
  6592. center: function center() {
  6593. this.computeBoundingBox();
  6594. this.boundingBox.getCenter(_offset).negate();
  6595. this.translate(_offset.x, _offset.y, _offset.z);
  6596. return this;
  6597. },
  6598. setFromObject: function setFromObject(object) {
  6599. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6600. var geometry = object.geometry;
  6601. if (object.isPoints || object.isLine) {
  6602. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6603. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6604. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6605. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6606. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6607. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6608. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6609. }
  6610. if (geometry.boundingSphere !== null) {
  6611. this.boundingSphere = geometry.boundingSphere.clone();
  6612. }
  6613. if (geometry.boundingBox !== null) {
  6614. this.boundingBox = geometry.boundingBox.clone();
  6615. }
  6616. } else if (object.isMesh) {
  6617. if (geometry && geometry.isGeometry) {
  6618. this.fromGeometry(geometry);
  6619. }
  6620. }
  6621. return this;
  6622. },
  6623. setFromPoints: function setFromPoints(points) {
  6624. var position = [];
  6625. for (var i = 0, l = points.length; i < l; i++) {
  6626. var point = points[i];
  6627. position.push(point.x, point.y, point.z || 0);
  6628. }
  6629. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6630. return this;
  6631. },
  6632. updateFromObject: function updateFromObject(object) {
  6633. var geometry = object.geometry;
  6634. if (object.isMesh) {
  6635. var direct = geometry.__directGeometry;
  6636. if (geometry.elementsNeedUpdate === true) {
  6637. direct = undefined;
  6638. geometry.elementsNeedUpdate = false;
  6639. }
  6640. if (direct === undefined) {
  6641. return this.fromGeometry(geometry);
  6642. }
  6643. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6644. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6645. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6646. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6647. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6648. geometry.verticesNeedUpdate = false;
  6649. geometry.normalsNeedUpdate = false;
  6650. geometry.colorsNeedUpdate = false;
  6651. geometry.uvsNeedUpdate = false;
  6652. geometry.groupsNeedUpdate = false;
  6653. geometry = direct;
  6654. }
  6655. if (geometry.verticesNeedUpdate === true) {
  6656. var attribute = this.attributes.position;
  6657. if (attribute !== undefined) {
  6658. attribute.copyVector3sArray(geometry.vertices);
  6659. attribute.needsUpdate = true;
  6660. }
  6661. geometry.verticesNeedUpdate = false;
  6662. }
  6663. if (geometry.normalsNeedUpdate === true) {
  6664. var _attribute = this.attributes.normal;
  6665. if (_attribute !== undefined) {
  6666. _attribute.copyVector3sArray(geometry.normals);
  6667. _attribute.needsUpdate = true;
  6668. }
  6669. geometry.normalsNeedUpdate = false;
  6670. }
  6671. if (geometry.colorsNeedUpdate === true) {
  6672. var _attribute2 = this.attributes.color;
  6673. if (_attribute2 !== undefined) {
  6674. _attribute2.copyColorsArray(geometry.colors);
  6675. _attribute2.needsUpdate = true;
  6676. }
  6677. geometry.colorsNeedUpdate = false;
  6678. }
  6679. if (geometry.uvsNeedUpdate) {
  6680. var _attribute3 = this.attributes.uv;
  6681. if (_attribute3 !== undefined) {
  6682. _attribute3.copyVector2sArray(geometry.uvs);
  6683. _attribute3.needsUpdate = true;
  6684. }
  6685. geometry.uvsNeedUpdate = false;
  6686. }
  6687. if (geometry.lineDistancesNeedUpdate) {
  6688. var _attribute4 = this.attributes.lineDistance;
  6689. if (_attribute4 !== undefined) {
  6690. _attribute4.copyArray(geometry.lineDistances);
  6691. _attribute4.needsUpdate = true;
  6692. }
  6693. geometry.lineDistancesNeedUpdate = false;
  6694. }
  6695. if (geometry.groupsNeedUpdate) {
  6696. geometry.computeGroups(object.geometry);
  6697. this.groups = geometry.groups;
  6698. geometry.groupsNeedUpdate = false;
  6699. }
  6700. return this;
  6701. },
  6702. fromGeometry: function fromGeometry(geometry) {
  6703. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6704. return this.fromDirectGeometry(geometry.__directGeometry);
  6705. },
  6706. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6707. var positions = new Float32Array(geometry.vertices.length * 3);
  6708. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6709. if (geometry.normals.length > 0) {
  6710. var normals = new Float32Array(geometry.normals.length * 3);
  6711. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6712. }
  6713. if (geometry.colors.length > 0) {
  6714. var colors = new Float32Array(geometry.colors.length * 3);
  6715. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6716. }
  6717. if (geometry.uvs.length > 0) {
  6718. var uvs = new Float32Array(geometry.uvs.length * 2);
  6719. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6720. }
  6721. if (geometry.uvs2.length > 0) {
  6722. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6723. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6724. } // groups
  6725. this.groups = geometry.groups; // morphs
  6726. for (var name in geometry.morphTargets) {
  6727. var array = [];
  6728. var morphTargets = geometry.morphTargets[name];
  6729. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6730. var morphTarget = morphTargets[i];
  6731. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6732. attribute.name = morphTarget.name;
  6733. array.push(attribute.copyVector3sArray(morphTarget.data));
  6734. }
  6735. this.morphAttributes[name] = array;
  6736. } // skinning
  6737. if (geometry.skinIndices.length > 0) {
  6738. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6739. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6740. }
  6741. if (geometry.skinWeights.length > 0) {
  6742. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6743. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6744. } //
  6745. if (geometry.boundingSphere !== null) {
  6746. this.boundingSphere = geometry.boundingSphere.clone();
  6747. }
  6748. if (geometry.boundingBox !== null) {
  6749. this.boundingBox = geometry.boundingBox.clone();
  6750. }
  6751. return this;
  6752. },
  6753. computeBoundingBox: function computeBoundingBox() {
  6754. if (this.boundingBox === null) {
  6755. this.boundingBox = new Box3();
  6756. }
  6757. var position = this.attributes.position;
  6758. var morphAttributesPosition = this.morphAttributes.position;
  6759. if (position && position.isGLBufferAttribute) {
  6760. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6761. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6762. return;
  6763. }
  6764. if (position !== undefined) {
  6765. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6766. if (morphAttributesPosition) {
  6767. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6768. var morphAttribute = morphAttributesPosition[i];
  6769. _box$2.setFromBufferAttribute(morphAttribute);
  6770. if (this.morphTargetsRelative) {
  6771. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6772. this.boundingBox.expandByPoint(_vector$4);
  6773. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6774. this.boundingBox.expandByPoint(_vector$4);
  6775. } else {
  6776. this.boundingBox.expandByPoint(_box$2.min);
  6777. this.boundingBox.expandByPoint(_box$2.max);
  6778. }
  6779. }
  6780. }
  6781. } else {
  6782. this.boundingBox.makeEmpty();
  6783. }
  6784. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6785. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6786. }
  6787. },
  6788. computeBoundingSphere: function computeBoundingSphere() {
  6789. if (this.boundingSphere === null) {
  6790. this.boundingSphere = new Sphere();
  6791. }
  6792. var position = this.attributes.position;
  6793. var morphAttributesPosition = this.morphAttributes.position;
  6794. if (position && position.isGLBufferAttribute) {
  6795. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6796. this.boundingSphere.set(new Vector3(), Infinity);
  6797. return;
  6798. }
  6799. if (position) {
  6800. // first, find the center of the bounding sphere
  6801. var center = this.boundingSphere.center;
  6802. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6803. if (morphAttributesPosition) {
  6804. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6805. var morphAttribute = morphAttributesPosition[i];
  6806. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6807. if (this.morphTargetsRelative) {
  6808. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6809. _box$2.expandByPoint(_vector$4);
  6810. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6811. _box$2.expandByPoint(_vector$4);
  6812. } else {
  6813. _box$2.expandByPoint(_boxMorphTargets.min);
  6814. _box$2.expandByPoint(_boxMorphTargets.max);
  6815. }
  6816. }
  6817. }
  6818. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6819. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6820. var maxRadiusSq = 0;
  6821. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6822. _vector$4.fromBufferAttribute(position, _i);
  6823. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6824. } // process morph attributes if present
  6825. if (morphAttributesPosition) {
  6826. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6827. var _morphAttribute = morphAttributesPosition[_i2];
  6828. var morphTargetsRelative = this.morphTargetsRelative;
  6829. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6830. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6831. if (morphTargetsRelative) {
  6832. _offset.fromBufferAttribute(position, j);
  6833. _vector$4.add(_offset);
  6834. }
  6835. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6836. }
  6837. }
  6838. }
  6839. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6840. if (isNaN(this.boundingSphere.radius)) {
  6841. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6842. }
  6843. }
  6844. },
  6845. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6846. },
  6847. computeVertexNormals: function computeVertexNormals() {
  6848. var index = this.index;
  6849. var positionAttribute = this.getAttribute('position');
  6850. if (positionAttribute !== undefined) {
  6851. var normalAttribute = this.getAttribute('normal');
  6852. if (normalAttribute === undefined) {
  6853. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6854. this.setAttribute('normal', normalAttribute);
  6855. } else {
  6856. // reset existing normals to zero
  6857. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6858. normalAttribute.setXYZ(i, 0, 0, 0);
  6859. }
  6860. }
  6861. var pA = new Vector3(),
  6862. pB = new Vector3(),
  6863. pC = new Vector3();
  6864. var nA = new Vector3(),
  6865. nB = new Vector3(),
  6866. nC = new Vector3();
  6867. var cb = new Vector3(),
  6868. ab = new Vector3(); // indexed elements
  6869. if (index) {
  6870. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6871. var vA = index.getX(_i3 + 0);
  6872. var vB = index.getX(_i3 + 1);
  6873. var vC = index.getX(_i3 + 2);
  6874. pA.fromBufferAttribute(positionAttribute, vA);
  6875. pB.fromBufferAttribute(positionAttribute, vB);
  6876. pC.fromBufferAttribute(positionAttribute, vC);
  6877. cb.subVectors(pC, pB);
  6878. ab.subVectors(pA, pB);
  6879. cb.cross(ab);
  6880. nA.fromBufferAttribute(normalAttribute, vA);
  6881. nB.fromBufferAttribute(normalAttribute, vB);
  6882. nC.fromBufferAttribute(normalAttribute, vC);
  6883. nA.add(cb);
  6884. nB.add(cb);
  6885. nC.add(cb);
  6886. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6887. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6888. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6889. }
  6890. } else {
  6891. // non-indexed elements (unconnected triangle soup)
  6892. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6893. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6894. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6895. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6896. cb.subVectors(pC, pB);
  6897. ab.subVectors(pA, pB);
  6898. cb.cross(ab);
  6899. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6900. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6901. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6902. }
  6903. }
  6904. this.normalizeNormals();
  6905. normalAttribute.needsUpdate = true;
  6906. }
  6907. },
  6908. merge: function merge(geometry, offset) {
  6909. if (!(geometry && geometry.isBufferGeometry)) {
  6910. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6911. return;
  6912. }
  6913. if (offset === undefined) {
  6914. offset = 0;
  6915. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6916. }
  6917. var attributes = this.attributes;
  6918. for (var key in attributes) {
  6919. if (geometry.attributes[key] === undefined) continue;
  6920. var attribute1 = attributes[key];
  6921. var attributeArray1 = attribute1.array;
  6922. var attribute2 = geometry.attributes[key];
  6923. var attributeArray2 = attribute2.array;
  6924. var attributeOffset = attribute2.itemSize * offset;
  6925. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6926. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6927. attributeArray1[j] = attributeArray2[i];
  6928. }
  6929. }
  6930. return this;
  6931. },
  6932. normalizeNormals: function normalizeNormals() {
  6933. var normals = this.attributes.normal;
  6934. for (var i = 0, il = normals.count; i < il; i++) {
  6935. _vector$4.fromBufferAttribute(normals, i);
  6936. _vector$4.normalize();
  6937. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6938. }
  6939. },
  6940. toNonIndexed: function toNonIndexed() {
  6941. function convertBufferAttribute(attribute, indices) {
  6942. var array = attribute.array;
  6943. var itemSize = attribute.itemSize;
  6944. var normalized = attribute.normalized;
  6945. var array2 = new array.constructor(indices.length * itemSize);
  6946. var index = 0,
  6947. index2 = 0;
  6948. for (var i = 0, l = indices.length; i < l; i++) {
  6949. index = indices[i] * itemSize;
  6950. for (var j = 0; j < itemSize; j++) {
  6951. array2[index2++] = array[index++];
  6952. }
  6953. }
  6954. return new BufferAttribute(array2, itemSize, normalized);
  6955. } //
  6956. if (this.index === null) {
  6957. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6958. return this;
  6959. }
  6960. var geometry2 = new BufferGeometry();
  6961. var indices = this.index.array;
  6962. var attributes = this.attributes; // attributes
  6963. for (var name in attributes) {
  6964. var attribute = attributes[name];
  6965. var newAttribute = convertBufferAttribute(attribute, indices);
  6966. geometry2.setAttribute(name, newAttribute);
  6967. } // morph attributes
  6968. var morphAttributes = this.morphAttributes;
  6969. for (var _name in morphAttributes) {
  6970. var morphArray = [];
  6971. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6972. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6973. var _attribute5 = morphAttribute[i];
  6974. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6975. morphArray.push(_newAttribute);
  6976. }
  6977. geometry2.morphAttributes[_name] = morphArray;
  6978. }
  6979. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6980. var groups = this.groups;
  6981. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6982. var group = groups[_i5];
  6983. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6984. }
  6985. return geometry2;
  6986. },
  6987. toJSON: function toJSON() {
  6988. var data = {
  6989. metadata: {
  6990. version: 4.5,
  6991. type: 'BufferGeometry',
  6992. generator: 'BufferGeometry.toJSON'
  6993. }
  6994. }; // standard BufferGeometry serialization
  6995. data.uuid = this.uuid;
  6996. data.type = this.type;
  6997. if (this.name !== '') data.name = this.name;
  6998. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6999. if (this.parameters !== undefined) {
  7000. var parameters = this.parameters;
  7001. for (var key in parameters) {
  7002. if (parameters[key] !== undefined) data[key] = parameters[key];
  7003. }
  7004. return data;
  7005. }
  7006. data.data = {
  7007. attributes: {}
  7008. };
  7009. var index = this.index;
  7010. if (index !== null) {
  7011. data.data.index = {
  7012. type: index.array.constructor.name,
  7013. array: Array.prototype.slice.call(index.array)
  7014. };
  7015. }
  7016. var attributes = this.attributes;
  7017. for (var _key in attributes) {
  7018. var attribute = attributes[_key];
  7019. var attributeData = attribute.toJSON(data.data);
  7020. if (attribute.name !== '') attributeData.name = attribute.name;
  7021. data.data.attributes[_key] = attributeData;
  7022. }
  7023. var morphAttributes = {};
  7024. var hasMorphAttributes = false;
  7025. for (var _key2 in this.morphAttributes) {
  7026. var attributeArray = this.morphAttributes[_key2];
  7027. var array = [];
  7028. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7029. var _attribute6 = attributeArray[i];
  7030. var _attributeData = _attribute6.toJSON(data.data);
  7031. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  7032. array.push(_attributeData);
  7033. }
  7034. if (array.length > 0) {
  7035. morphAttributes[_key2] = array;
  7036. hasMorphAttributes = true;
  7037. }
  7038. }
  7039. if (hasMorphAttributes) {
  7040. data.data.morphAttributes = morphAttributes;
  7041. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7042. }
  7043. var groups = this.groups;
  7044. if (groups.length > 0) {
  7045. data.data.groups = JSON.parse(JSON.stringify(groups));
  7046. }
  7047. var boundingSphere = this.boundingSphere;
  7048. if (boundingSphere !== null) {
  7049. data.data.boundingSphere = {
  7050. center: boundingSphere.center.toArray(),
  7051. radius: boundingSphere.radius
  7052. };
  7053. }
  7054. return data;
  7055. },
  7056. clone: function clone() {
  7057. /*
  7058. // Handle primitives
  7059. const parameters = this.parameters;
  7060. if ( parameters !== undefined ) {
  7061. const values = [];
  7062. for ( const key in parameters ) {
  7063. values.push( parameters[ key ] );
  7064. }
  7065. const geometry = Object.create( this.constructor.prototype );
  7066. this.constructor.apply( geometry, values );
  7067. return geometry;
  7068. }
  7069. return new this.constructor().copy( this );
  7070. */
  7071. return new BufferGeometry().copy(this);
  7072. },
  7073. copy: function copy(source) {
  7074. // reset
  7075. this.index = null;
  7076. this.attributes = {};
  7077. this.morphAttributes = {};
  7078. this.groups = [];
  7079. this.boundingBox = null;
  7080. this.boundingSphere = null; // used for storing cloned, shared data
  7081. var data = {}; // name
  7082. this.name = source.name; // index
  7083. var index = source.index;
  7084. if (index !== null) {
  7085. this.setIndex(index.clone(data));
  7086. } // attributes
  7087. var attributes = source.attributes;
  7088. for (var name in attributes) {
  7089. var attribute = attributes[name];
  7090. this.setAttribute(name, attribute.clone(data));
  7091. } // morph attributes
  7092. var morphAttributes = source.morphAttributes;
  7093. for (var _name2 in morphAttributes) {
  7094. var array = [];
  7095. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7096. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7097. array.push(morphAttribute[i].clone(data));
  7098. }
  7099. this.morphAttributes[_name2] = array;
  7100. }
  7101. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7102. var groups = source.groups;
  7103. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  7104. var group = groups[_i6];
  7105. this.addGroup(group.start, group.count, group.materialIndex);
  7106. } // bounding box
  7107. var boundingBox = source.boundingBox;
  7108. if (boundingBox !== null) {
  7109. this.boundingBox = boundingBox.clone();
  7110. } // bounding sphere
  7111. var boundingSphere = source.boundingSphere;
  7112. if (boundingSphere !== null) {
  7113. this.boundingSphere = boundingSphere.clone();
  7114. } // draw range
  7115. this.drawRange.start = source.drawRange.start;
  7116. this.drawRange.count = source.drawRange.count; // user data
  7117. this.userData = source.userData;
  7118. return this;
  7119. },
  7120. dispose: function dispose() {
  7121. this.dispatchEvent({
  7122. type: 'dispose'
  7123. });
  7124. }
  7125. });
  7126. var _inverseMatrix = new Matrix4();
  7127. var _ray = new Ray();
  7128. var _sphere = new Sphere();
  7129. var _vA = new Vector3();
  7130. var _vB = new Vector3();
  7131. var _vC = new Vector3();
  7132. var _tempA = new Vector3();
  7133. var _tempB = new Vector3();
  7134. var _tempC = new Vector3();
  7135. var _morphA = new Vector3();
  7136. var _morphB = new Vector3();
  7137. var _morphC = new Vector3();
  7138. var _uvA = new Vector2();
  7139. var _uvB = new Vector2();
  7140. var _uvC = new Vector2();
  7141. var _intersectionPoint = new Vector3();
  7142. var _intersectionPointWorld = new Vector3();
  7143. function Mesh(geometry, material) {
  7144. if (geometry === void 0) {
  7145. geometry = new BufferGeometry();
  7146. }
  7147. if (material === void 0) {
  7148. material = new MeshBasicMaterial();
  7149. }
  7150. Object3D.call(this);
  7151. this.type = 'Mesh';
  7152. this.geometry = geometry;
  7153. this.material = material;
  7154. this.updateMorphTargets();
  7155. }
  7156. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7157. constructor: Mesh,
  7158. isMesh: true,
  7159. copy: function copy(source) {
  7160. Object3D.prototype.copy.call(this, source);
  7161. if (source.morphTargetInfluences !== undefined) {
  7162. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7163. }
  7164. if (source.morphTargetDictionary !== undefined) {
  7165. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7166. }
  7167. this.material = source.material;
  7168. this.geometry = source.geometry;
  7169. return this;
  7170. },
  7171. updateMorphTargets: function updateMorphTargets() {
  7172. var geometry = this.geometry;
  7173. if (geometry.isBufferGeometry) {
  7174. var morphAttributes = geometry.morphAttributes;
  7175. var keys = Object.keys(morphAttributes);
  7176. if (keys.length > 0) {
  7177. var morphAttribute = morphAttributes[keys[0]];
  7178. if (morphAttribute !== undefined) {
  7179. this.morphTargetInfluences = [];
  7180. this.morphTargetDictionary = {};
  7181. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7182. var name = morphAttribute[m].name || String(m);
  7183. this.morphTargetInfluences.push(0);
  7184. this.morphTargetDictionary[name] = m;
  7185. }
  7186. }
  7187. }
  7188. } else {
  7189. var morphTargets = geometry.morphTargets;
  7190. if (morphTargets !== undefined && morphTargets.length > 0) {
  7191. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7192. }
  7193. }
  7194. },
  7195. raycast: function raycast(raycaster, intersects) {
  7196. var geometry = this.geometry;
  7197. var material = this.material;
  7198. var matrixWorld = this.matrixWorld;
  7199. if (material === undefined) return; // Checking boundingSphere distance to ray
  7200. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7201. _sphere.copy(geometry.boundingSphere);
  7202. _sphere.applyMatrix4(matrixWorld);
  7203. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7204. _inverseMatrix.copy(matrixWorld).invert();
  7205. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7206. if (geometry.boundingBox !== null) {
  7207. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7208. }
  7209. var intersection;
  7210. if (geometry.isBufferGeometry) {
  7211. var index = geometry.index;
  7212. var position = geometry.attributes.position;
  7213. var morphPosition = geometry.morphAttributes.position;
  7214. var morphTargetsRelative = geometry.morphTargetsRelative;
  7215. var uv = geometry.attributes.uv;
  7216. var uv2 = geometry.attributes.uv2;
  7217. var groups = geometry.groups;
  7218. var drawRange = geometry.drawRange;
  7219. if (index !== null) {
  7220. // indexed buffer geometry
  7221. if (Array.isArray(material)) {
  7222. for (var i = 0, il = groups.length; i < il; i++) {
  7223. var group = groups[i];
  7224. var groupMaterial = material[group.materialIndex];
  7225. var start = Math.max(group.start, drawRange.start);
  7226. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7227. for (var j = start, jl = end; j < jl; j += 3) {
  7228. var a = index.getX(j);
  7229. var b = index.getX(j + 1);
  7230. var c = index.getX(j + 2);
  7231. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7232. if (intersection) {
  7233. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7234. intersection.face.materialIndex = group.materialIndex;
  7235. intersects.push(intersection);
  7236. }
  7237. }
  7238. }
  7239. } else {
  7240. var _start = Math.max(0, drawRange.start);
  7241. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7242. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7243. var _a = index.getX(_i);
  7244. var _b = index.getX(_i + 1);
  7245. var _c = index.getX(_i + 2);
  7246. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7247. if (intersection) {
  7248. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7249. intersects.push(intersection);
  7250. }
  7251. }
  7252. }
  7253. } else if (position !== undefined) {
  7254. // non-indexed buffer geometry
  7255. if (Array.isArray(material)) {
  7256. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7257. var _group = groups[_i2];
  7258. var _groupMaterial = material[_group.materialIndex];
  7259. var _start2 = Math.max(_group.start, drawRange.start);
  7260. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7261. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7262. var _a2 = _j;
  7263. var _b2 = _j + 1;
  7264. var _c2 = _j + 2;
  7265. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7266. if (intersection) {
  7267. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7268. intersection.face.materialIndex = _group.materialIndex;
  7269. intersects.push(intersection);
  7270. }
  7271. }
  7272. }
  7273. } else {
  7274. var _start3 = Math.max(0, drawRange.start);
  7275. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7276. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7277. var _a3 = _i3;
  7278. var _b3 = _i3 + 1;
  7279. var _c3 = _i3 + 2;
  7280. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7281. if (intersection) {
  7282. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7283. intersects.push(intersection);
  7284. }
  7285. }
  7286. }
  7287. }
  7288. } else if (geometry.isGeometry) {
  7289. var isMultiMaterial = Array.isArray(material);
  7290. var vertices = geometry.vertices;
  7291. var faces = geometry.faces;
  7292. var uvs;
  7293. var faceVertexUvs = geometry.faceVertexUvs[0];
  7294. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7295. for (var f = 0, fl = faces.length; f < fl; f++) {
  7296. var face = faces[f];
  7297. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7298. if (faceMaterial === undefined) continue;
  7299. var fvA = vertices[face.a];
  7300. var fvB = vertices[face.b];
  7301. var fvC = vertices[face.c];
  7302. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7303. if (intersection) {
  7304. if (uvs && uvs[f]) {
  7305. var uvs_f = uvs[f];
  7306. _uvA.copy(uvs_f[0]);
  7307. _uvB.copy(uvs_f[1]);
  7308. _uvC.copy(uvs_f[2]);
  7309. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7310. }
  7311. intersection.face = face;
  7312. intersection.faceIndex = f;
  7313. intersects.push(intersection);
  7314. }
  7315. }
  7316. }
  7317. }
  7318. });
  7319. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7320. var intersect;
  7321. if (material.side === BackSide) {
  7322. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7323. } else {
  7324. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7325. }
  7326. if (intersect === null) return null;
  7327. _intersectionPointWorld.copy(point);
  7328. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7329. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7330. if (distance < raycaster.near || distance > raycaster.far) return null;
  7331. return {
  7332. distance: distance,
  7333. point: _intersectionPointWorld.clone(),
  7334. object: object
  7335. };
  7336. }
  7337. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7338. _vA.fromBufferAttribute(position, a);
  7339. _vB.fromBufferAttribute(position, b);
  7340. _vC.fromBufferAttribute(position, c);
  7341. var morphInfluences = object.morphTargetInfluences;
  7342. if (material.morphTargets && morphPosition && morphInfluences) {
  7343. _morphA.set(0, 0, 0);
  7344. _morphB.set(0, 0, 0);
  7345. _morphC.set(0, 0, 0);
  7346. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7347. var influence = morphInfluences[i];
  7348. var morphAttribute = morphPosition[i];
  7349. if (influence === 0) continue;
  7350. _tempA.fromBufferAttribute(morphAttribute, a);
  7351. _tempB.fromBufferAttribute(morphAttribute, b);
  7352. _tempC.fromBufferAttribute(morphAttribute, c);
  7353. if (morphTargetsRelative) {
  7354. _morphA.addScaledVector(_tempA, influence);
  7355. _morphB.addScaledVector(_tempB, influence);
  7356. _morphC.addScaledVector(_tempC, influence);
  7357. } else {
  7358. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7359. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7360. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7361. }
  7362. }
  7363. _vA.add(_morphA);
  7364. _vB.add(_morphB);
  7365. _vC.add(_morphC);
  7366. }
  7367. if (object.isSkinnedMesh) {
  7368. object.boneTransform(a, _vA);
  7369. object.boneTransform(b, _vB);
  7370. object.boneTransform(c, _vC);
  7371. }
  7372. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7373. if (intersection) {
  7374. if (uv) {
  7375. _uvA.fromBufferAttribute(uv, a);
  7376. _uvB.fromBufferAttribute(uv, b);
  7377. _uvC.fromBufferAttribute(uv, c);
  7378. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7379. }
  7380. if (uv2) {
  7381. _uvA.fromBufferAttribute(uv2, a);
  7382. _uvB.fromBufferAttribute(uv2, b);
  7383. _uvC.fromBufferAttribute(uv2, c);
  7384. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7385. }
  7386. var face = new Face3(a, b, c);
  7387. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7388. intersection.face = face;
  7389. }
  7390. return intersection;
  7391. }
  7392. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7393. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7394. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7395. var _this;
  7396. if (width === void 0) {
  7397. width = 1;
  7398. }
  7399. if (height === void 0) {
  7400. height = 1;
  7401. }
  7402. if (depth === void 0) {
  7403. depth = 1;
  7404. }
  7405. if (widthSegments === void 0) {
  7406. widthSegments = 1;
  7407. }
  7408. if (heightSegments === void 0) {
  7409. heightSegments = 1;
  7410. }
  7411. if (depthSegments === void 0) {
  7412. depthSegments = 1;
  7413. }
  7414. _this = _BufferGeometry.call(this) || this;
  7415. _this.type = 'BoxBufferGeometry';
  7416. _this.parameters = {
  7417. width: width,
  7418. height: height,
  7419. depth: depth,
  7420. widthSegments: widthSegments,
  7421. heightSegments: heightSegments,
  7422. depthSegments: depthSegments
  7423. };
  7424. var scope = _assertThisInitialized(_this); // segments
  7425. widthSegments = Math.floor(widthSegments);
  7426. heightSegments = Math.floor(heightSegments);
  7427. depthSegments = Math.floor(depthSegments); // buffers
  7428. var indices = [];
  7429. var vertices = [];
  7430. var normals = [];
  7431. var uvs = []; // helper variables
  7432. var numberOfVertices = 0;
  7433. var groupStart = 0; // build each side of the box geometry
  7434. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7435. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7436. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7437. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7438. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7439. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7440. // build geometry
  7441. _this.setIndex(indices);
  7442. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7443. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7444. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7445. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7446. var segmentWidth = width / gridX;
  7447. var segmentHeight = height / gridY;
  7448. var widthHalf = width / 2;
  7449. var heightHalf = height / 2;
  7450. var depthHalf = depth / 2;
  7451. var gridX1 = gridX + 1;
  7452. var gridY1 = gridY + 1;
  7453. var vertexCounter = 0;
  7454. var groupCount = 0;
  7455. var vector = new Vector3(); // generate vertices, normals and uvs
  7456. for (var iy = 0; iy < gridY1; iy++) {
  7457. var y = iy * segmentHeight - heightHalf;
  7458. for (var ix = 0; ix < gridX1; ix++) {
  7459. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7460. vector[u] = x * udir;
  7461. vector[v] = y * vdir;
  7462. vector[w] = depthHalf; // now apply vector to vertex buffer
  7463. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7464. vector[u] = 0;
  7465. vector[v] = 0;
  7466. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7467. normals.push(vector.x, vector.y, vector.z); // uvs
  7468. uvs.push(ix / gridX);
  7469. uvs.push(1 - iy / gridY); // counters
  7470. vertexCounter += 1;
  7471. }
  7472. } // indices
  7473. // 1. you need three indices to draw a single face
  7474. // 2. a single segment consists of two faces
  7475. // 3. so we need to generate six (2*3) indices per segment
  7476. for (var _iy = 0; _iy < gridY; _iy++) {
  7477. for (var _ix = 0; _ix < gridX; _ix++) {
  7478. var a = numberOfVertices + _ix + gridX1 * _iy;
  7479. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7480. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7481. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7482. indices.push(a, b, d);
  7483. indices.push(b, c, d); // increase counter
  7484. groupCount += 6;
  7485. }
  7486. } // add a group to the geometry. this will ensure multi material support
  7487. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7488. groupStart += groupCount; // update total number of vertices
  7489. numberOfVertices += vertexCounter;
  7490. }
  7491. return _this;
  7492. }
  7493. return BoxBufferGeometry;
  7494. }(BufferGeometry);
  7495. /**
  7496. * Uniform Utilities
  7497. */
  7498. function cloneUniforms(src) {
  7499. var dst = {};
  7500. for (var u in src) {
  7501. dst[u] = {};
  7502. for (var p in src[u]) {
  7503. var property = src[u][p];
  7504. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7505. dst[u][p] = property.clone();
  7506. } else if (Array.isArray(property)) {
  7507. dst[u][p] = property.slice();
  7508. } else {
  7509. dst[u][p] = property;
  7510. }
  7511. }
  7512. }
  7513. return dst;
  7514. }
  7515. function mergeUniforms(uniforms) {
  7516. var merged = {};
  7517. for (var u = 0; u < uniforms.length; u++) {
  7518. var tmp = cloneUniforms(uniforms[u]);
  7519. for (var p in tmp) {
  7520. merged[p] = tmp[p];
  7521. }
  7522. }
  7523. return merged;
  7524. } // Legacy
  7525. var UniformsUtils = {
  7526. clone: cloneUniforms,
  7527. merge: mergeUniforms
  7528. };
  7529. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7530. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7531. /**
  7532. * parameters = {
  7533. * defines: { "label" : "value" },
  7534. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7535. *
  7536. * fragmentShader: <string>,
  7537. * vertexShader: <string>,
  7538. *
  7539. * wireframe: <boolean>,
  7540. * wireframeLinewidth: <float>,
  7541. *
  7542. * lights: <bool>,
  7543. *
  7544. * skinning: <bool>,
  7545. * morphTargets: <bool>,
  7546. * morphNormals: <bool>
  7547. * }
  7548. */
  7549. function ShaderMaterial(parameters) {
  7550. Material.call(this);
  7551. this.type = 'ShaderMaterial';
  7552. this.defines = {};
  7553. this.uniforms = {};
  7554. this.vertexShader = default_vertex;
  7555. this.fragmentShader = default_fragment;
  7556. this.linewidth = 1;
  7557. this.wireframe = false;
  7558. this.wireframeLinewidth = 1;
  7559. this.fog = false; // set to use scene fog
  7560. this.lights = false; // set to use scene lights
  7561. this.clipping = false; // set to use user-defined clipping planes
  7562. this.skinning = false; // set to use skinning attribute streams
  7563. this.morphTargets = false; // set to use morph targets
  7564. this.morphNormals = false; // set to use morph normals
  7565. this.extensions = {
  7566. derivatives: false,
  7567. // set to use derivatives
  7568. fragDepth: false,
  7569. // set to use fragment depth values
  7570. drawBuffers: false,
  7571. // set to use draw buffers
  7572. shaderTextureLOD: false // set to use shader texture LOD
  7573. }; // When rendered geometry doesn't include these attributes but the material does,
  7574. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7575. this.defaultAttributeValues = {
  7576. 'color': [1, 1, 1],
  7577. 'uv': [0, 0],
  7578. 'uv2': [0, 0]
  7579. };
  7580. this.index0AttributeName = undefined;
  7581. this.uniformsNeedUpdate = false;
  7582. this.glslVersion = null;
  7583. if (parameters !== undefined) {
  7584. if (parameters.attributes !== undefined) {
  7585. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7586. }
  7587. this.setValues(parameters);
  7588. }
  7589. }
  7590. ShaderMaterial.prototype = Object.create(Material.prototype);
  7591. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7592. ShaderMaterial.prototype.isShaderMaterial = true;
  7593. ShaderMaterial.prototype.copy = function (source) {
  7594. Material.prototype.copy.call(this, source);
  7595. this.fragmentShader = source.fragmentShader;
  7596. this.vertexShader = source.vertexShader;
  7597. this.uniforms = cloneUniforms(source.uniforms);
  7598. this.defines = Object.assign({}, source.defines);
  7599. this.wireframe = source.wireframe;
  7600. this.wireframeLinewidth = source.wireframeLinewidth;
  7601. this.lights = source.lights;
  7602. this.clipping = source.clipping;
  7603. this.skinning = source.skinning;
  7604. this.morphTargets = source.morphTargets;
  7605. this.morphNormals = source.morphNormals;
  7606. this.extensions = Object.assign({}, source.extensions);
  7607. this.glslVersion = source.glslVersion;
  7608. return this;
  7609. };
  7610. ShaderMaterial.prototype.toJSON = function (meta) {
  7611. var data = Material.prototype.toJSON.call(this, meta);
  7612. data.glslVersion = this.glslVersion;
  7613. data.uniforms = {};
  7614. for (var name in this.uniforms) {
  7615. var uniform = this.uniforms[name];
  7616. var value = uniform.value;
  7617. if (value && value.isTexture) {
  7618. data.uniforms[name] = {
  7619. type: 't',
  7620. value: value.toJSON(meta).uuid
  7621. };
  7622. } else if (value && value.isColor) {
  7623. data.uniforms[name] = {
  7624. type: 'c',
  7625. value: value.getHex()
  7626. };
  7627. } else if (value && value.isVector2) {
  7628. data.uniforms[name] = {
  7629. type: 'v2',
  7630. value: value.toArray()
  7631. };
  7632. } else if (value && value.isVector3) {
  7633. data.uniforms[name] = {
  7634. type: 'v3',
  7635. value: value.toArray()
  7636. };
  7637. } else if (value && value.isVector4) {
  7638. data.uniforms[name] = {
  7639. type: 'v4',
  7640. value: value.toArray()
  7641. };
  7642. } else if (value && value.isMatrix3) {
  7643. data.uniforms[name] = {
  7644. type: 'm3',
  7645. value: value.toArray()
  7646. };
  7647. } else if (value && value.isMatrix4) {
  7648. data.uniforms[name] = {
  7649. type: 'm4',
  7650. value: value.toArray()
  7651. };
  7652. } else {
  7653. data.uniforms[name] = {
  7654. value: value
  7655. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7656. }
  7657. }
  7658. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7659. data.vertexShader = this.vertexShader;
  7660. data.fragmentShader = this.fragmentShader;
  7661. var extensions = {};
  7662. for (var key in this.extensions) {
  7663. if (this.extensions[key] === true) extensions[key] = true;
  7664. }
  7665. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7666. return data;
  7667. };
  7668. function Camera() {
  7669. Object3D.call(this);
  7670. this.type = 'Camera';
  7671. this.matrixWorldInverse = new Matrix4();
  7672. this.projectionMatrix = new Matrix4();
  7673. this.projectionMatrixInverse = new Matrix4();
  7674. }
  7675. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7676. constructor: Camera,
  7677. isCamera: true,
  7678. copy: function copy(source, recursive) {
  7679. Object3D.prototype.copy.call(this, source, recursive);
  7680. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7681. this.projectionMatrix.copy(source.projectionMatrix);
  7682. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7683. return this;
  7684. },
  7685. getWorldDirection: function getWorldDirection(target) {
  7686. if (target === undefined) {
  7687. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7688. target = new Vector3();
  7689. }
  7690. this.updateWorldMatrix(true, false);
  7691. var e = this.matrixWorld.elements;
  7692. return target.set(-e[8], -e[9], -e[10]).normalize();
  7693. },
  7694. updateMatrixWorld: function updateMatrixWorld(force) {
  7695. Object3D.prototype.updateMatrixWorld.call(this, force);
  7696. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7697. },
  7698. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7699. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7700. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7701. },
  7702. clone: function clone() {
  7703. return new this.constructor().copy(this);
  7704. }
  7705. });
  7706. function PerspectiveCamera(fov, aspect, near, far) {
  7707. if (fov === void 0) {
  7708. fov = 50;
  7709. }
  7710. if (aspect === void 0) {
  7711. aspect = 1;
  7712. }
  7713. if (near === void 0) {
  7714. near = 0.1;
  7715. }
  7716. if (far === void 0) {
  7717. far = 2000;
  7718. }
  7719. Camera.call(this);
  7720. this.type = 'PerspectiveCamera';
  7721. this.fov = fov;
  7722. this.zoom = 1;
  7723. this.near = near;
  7724. this.far = far;
  7725. this.focus = 10;
  7726. this.aspect = aspect;
  7727. this.view = null;
  7728. this.filmGauge = 35; // width of the film (default in millimeters)
  7729. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7730. this.updateProjectionMatrix();
  7731. }
  7732. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7733. constructor: PerspectiveCamera,
  7734. isPerspectiveCamera: true,
  7735. copy: function copy(source, recursive) {
  7736. Camera.prototype.copy.call(this, source, recursive);
  7737. this.fov = source.fov;
  7738. this.zoom = source.zoom;
  7739. this.near = source.near;
  7740. this.far = source.far;
  7741. this.focus = source.focus;
  7742. this.aspect = source.aspect;
  7743. this.view = source.view === null ? null : Object.assign({}, source.view);
  7744. this.filmGauge = source.filmGauge;
  7745. this.filmOffset = source.filmOffset;
  7746. return this;
  7747. },
  7748. /**
  7749. * Sets the FOV by focal length in respect to the current .filmGauge.
  7750. *
  7751. * The default film gauge is 35, so that the focal length can be specified for
  7752. * a 35mm (full frame) camera.
  7753. *
  7754. * Values for focal length and film gauge must have the same unit.
  7755. */
  7756. setFocalLength: function setFocalLength(focalLength) {
  7757. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7758. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7759. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7760. this.updateProjectionMatrix();
  7761. },
  7762. /**
  7763. * Calculates the focal length from the current .fov and .filmGauge.
  7764. */
  7765. getFocalLength: function getFocalLength() {
  7766. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7767. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7768. },
  7769. getEffectiveFOV: function getEffectiveFOV() {
  7770. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7771. },
  7772. getFilmWidth: function getFilmWidth() {
  7773. // film not completely covered in portrait format (aspect < 1)
  7774. return this.filmGauge * Math.min(this.aspect, 1);
  7775. },
  7776. getFilmHeight: function getFilmHeight() {
  7777. // film not completely covered in landscape format (aspect > 1)
  7778. return this.filmGauge / Math.max(this.aspect, 1);
  7779. },
  7780. /**
  7781. * Sets an offset in a larger frustum. This is useful for multi-window or
  7782. * multi-monitor/multi-machine setups.
  7783. *
  7784. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7785. * the monitors are in grid like this
  7786. *
  7787. * +---+---+---+
  7788. * | A | B | C |
  7789. * +---+---+---+
  7790. * | D | E | F |
  7791. * +---+---+---+
  7792. *
  7793. * then for each monitor you would call it like this
  7794. *
  7795. * const w = 1920;
  7796. * const h = 1080;
  7797. * const fullWidth = w * 3;
  7798. * const fullHeight = h * 2;
  7799. *
  7800. * --A--
  7801. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7802. * --B--
  7803. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7804. * --C--
  7805. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7806. * --D--
  7807. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7808. * --E--
  7809. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7810. * --F--
  7811. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7812. *
  7813. * Note there is no reason monitors have to be the same size or in a grid.
  7814. */
  7815. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7816. this.aspect = fullWidth / fullHeight;
  7817. if (this.view === null) {
  7818. this.view = {
  7819. enabled: true,
  7820. fullWidth: 1,
  7821. fullHeight: 1,
  7822. offsetX: 0,
  7823. offsetY: 0,
  7824. width: 1,
  7825. height: 1
  7826. };
  7827. }
  7828. this.view.enabled = true;
  7829. this.view.fullWidth = fullWidth;
  7830. this.view.fullHeight = fullHeight;
  7831. this.view.offsetX = x;
  7832. this.view.offsetY = y;
  7833. this.view.width = width;
  7834. this.view.height = height;
  7835. this.updateProjectionMatrix();
  7836. },
  7837. clearViewOffset: function clearViewOffset() {
  7838. if (this.view !== null) {
  7839. this.view.enabled = false;
  7840. }
  7841. this.updateProjectionMatrix();
  7842. },
  7843. updateProjectionMatrix: function updateProjectionMatrix() {
  7844. var near = this.near;
  7845. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7846. var height = 2 * top;
  7847. var width = this.aspect * height;
  7848. var left = -0.5 * width;
  7849. var view = this.view;
  7850. if (this.view !== null && this.view.enabled) {
  7851. var fullWidth = view.fullWidth,
  7852. fullHeight = view.fullHeight;
  7853. left += view.offsetX * width / fullWidth;
  7854. top -= view.offsetY * height / fullHeight;
  7855. width *= view.width / fullWidth;
  7856. height *= view.height / fullHeight;
  7857. }
  7858. var skew = this.filmOffset;
  7859. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7860. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7861. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  7862. },
  7863. toJSON: function toJSON(meta) {
  7864. var data = Object3D.prototype.toJSON.call(this, meta);
  7865. data.object.fov = this.fov;
  7866. data.object.zoom = this.zoom;
  7867. data.object.near = this.near;
  7868. data.object.far = this.far;
  7869. data.object.focus = this.focus;
  7870. data.object.aspect = this.aspect;
  7871. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7872. data.object.filmGauge = this.filmGauge;
  7873. data.object.filmOffset = this.filmOffset;
  7874. return data;
  7875. }
  7876. });
  7877. var fov = 90,
  7878. aspect = 1;
  7879. function CubeCamera(near, far, renderTarget) {
  7880. Object3D.call(this);
  7881. this.type = 'CubeCamera';
  7882. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7883. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7884. return;
  7885. }
  7886. this.renderTarget = renderTarget;
  7887. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7888. cameraPX.layers = this.layers;
  7889. cameraPX.up.set(0, -1, 0);
  7890. cameraPX.lookAt(new Vector3(1, 0, 0));
  7891. this.add(cameraPX);
  7892. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7893. cameraNX.layers = this.layers;
  7894. cameraNX.up.set(0, -1, 0);
  7895. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7896. this.add(cameraNX);
  7897. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7898. cameraPY.layers = this.layers;
  7899. cameraPY.up.set(0, 0, 1);
  7900. cameraPY.lookAt(new Vector3(0, 1, 0));
  7901. this.add(cameraPY);
  7902. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7903. cameraNY.layers = this.layers;
  7904. cameraNY.up.set(0, 0, -1);
  7905. cameraNY.lookAt(new Vector3(0, -1, 0));
  7906. this.add(cameraNY);
  7907. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7908. cameraPZ.layers = this.layers;
  7909. cameraPZ.up.set(0, -1, 0);
  7910. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7911. this.add(cameraPZ);
  7912. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7913. cameraNZ.layers = this.layers;
  7914. cameraNZ.up.set(0, -1, 0);
  7915. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7916. this.add(cameraNZ);
  7917. this.update = function (renderer, scene) {
  7918. if (this.parent === null) this.updateMatrixWorld();
  7919. var currentXrEnabled = renderer.xr.enabled;
  7920. var currentRenderTarget = renderer.getRenderTarget();
  7921. renderer.xr.enabled = false;
  7922. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7923. renderTarget.texture.generateMipmaps = false;
  7924. renderer.setRenderTarget(renderTarget, 0);
  7925. renderer.render(scene, cameraPX);
  7926. renderer.setRenderTarget(renderTarget, 1);
  7927. renderer.render(scene, cameraNX);
  7928. renderer.setRenderTarget(renderTarget, 2);
  7929. renderer.render(scene, cameraPY);
  7930. renderer.setRenderTarget(renderTarget, 3);
  7931. renderer.render(scene, cameraNY);
  7932. renderer.setRenderTarget(renderTarget, 4);
  7933. renderer.render(scene, cameraPZ);
  7934. renderTarget.texture.generateMipmaps = generateMipmaps;
  7935. renderer.setRenderTarget(renderTarget, 5);
  7936. renderer.render(scene, cameraNZ);
  7937. renderer.setRenderTarget(currentRenderTarget);
  7938. renderer.xr.enabled = currentXrEnabled;
  7939. };
  7940. }
  7941. CubeCamera.prototype = Object.create(Object3D.prototype);
  7942. CubeCamera.prototype.constructor = CubeCamera;
  7943. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7944. images = images !== undefined ? images : [];
  7945. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7946. format = format !== undefined ? format : RGBFormat;
  7947. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7948. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  7949. //
  7950. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7951. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7952. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7953. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7954. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7955. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7956. this._needsFlipEnvMap = true;
  7957. }
  7958. CubeTexture.prototype = Object.create(Texture.prototype);
  7959. CubeTexture.prototype.constructor = CubeTexture;
  7960. CubeTexture.prototype.isCubeTexture = true;
  7961. Object.defineProperty(CubeTexture.prototype, 'images', {
  7962. get: function get() {
  7963. return this.image;
  7964. },
  7965. set: function set(value) {
  7966. this.image = value;
  7967. }
  7968. });
  7969. function WebGLCubeRenderTarget(size, options, dummy) {
  7970. if (Number.isInteger(options)) {
  7971. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7972. options = dummy;
  7973. }
  7974. WebGLRenderTarget.call(this, size, size, options);
  7975. options = options || {};
  7976. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7977. this.texture._needsFlipEnvMap = false;
  7978. }
  7979. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7980. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7981. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7982. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7983. this.texture.type = texture.type;
  7984. this.texture.format = RGBAFormat; // see #18859
  7985. this.texture.encoding = texture.encoding;
  7986. this.texture.generateMipmaps = texture.generateMipmaps;
  7987. this.texture.minFilter = texture.minFilter;
  7988. this.texture.magFilter = texture.magFilter;
  7989. var shader = {
  7990. uniforms: {
  7991. tEquirect: {
  7992. value: null
  7993. }
  7994. },
  7995. vertexShader:
  7996. /* glsl */
  7997. "\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t#include <begin_vertex>\n\t\t\t\t#include <project_vertex>\n\n\t\t\t}\n\t\t",
  7998. fragmentShader:
  7999. /* glsl */
  8000. "\n\n\t\t\tuniform sampler2D tEquirect;\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t}\n\t\t"
  8001. };
  8002. var geometry = new BoxBufferGeometry(5, 5, 5);
  8003. var material = new ShaderMaterial({
  8004. name: 'CubemapFromEquirect',
  8005. uniforms: cloneUniforms(shader.uniforms),
  8006. vertexShader: shader.vertexShader,
  8007. fragmentShader: shader.fragmentShader,
  8008. side: BackSide,
  8009. blending: NoBlending
  8010. });
  8011. material.uniforms.tEquirect.value = texture;
  8012. var mesh = new Mesh(geometry, material);
  8013. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8014. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8015. var camera = new CubeCamera(1, 10, this);
  8016. camera.update(renderer, mesh);
  8017. texture.minFilter = currentMinFilter;
  8018. mesh.geometry.dispose();
  8019. mesh.material.dispose();
  8020. return this;
  8021. };
  8022. WebGLCubeRenderTarget.prototype.clear = function (renderer, color, depth, stencil) {
  8023. var currentRenderTarget = renderer.getRenderTarget();
  8024. for (var i = 0; i < 6; i++) {
  8025. renderer.setRenderTarget(this, i);
  8026. renderer.clear(color, depth, stencil);
  8027. }
  8028. renderer.setRenderTarget(currentRenderTarget);
  8029. };
  8030. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8031. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8032. this.image = {
  8033. data: data || null,
  8034. width: width || 1,
  8035. height: height || 1
  8036. };
  8037. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8038. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8039. this.generateMipmaps = false;
  8040. this.flipY = false;
  8041. this.unpackAlignment = 1;
  8042. this.needsUpdate = true;
  8043. }
  8044. DataTexture.prototype = Object.create(Texture.prototype);
  8045. DataTexture.prototype.constructor = DataTexture;
  8046. DataTexture.prototype.isDataTexture = true;
  8047. var _sphere$1 = /*@__PURE__*/new Sphere();
  8048. var _vector$5 = /*@__PURE__*/new Vector3();
  8049. var Frustum = /*#__PURE__*/function () {
  8050. function Frustum(p0, p1, p2, p3, p4, p5) {
  8051. 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()];
  8052. }
  8053. var _proto = Frustum.prototype;
  8054. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8055. var planes = this.planes;
  8056. planes[0].copy(p0);
  8057. planes[1].copy(p1);
  8058. planes[2].copy(p2);
  8059. planes[3].copy(p3);
  8060. planes[4].copy(p4);
  8061. planes[5].copy(p5);
  8062. return this;
  8063. };
  8064. _proto.clone = function clone() {
  8065. return new this.constructor().copy(this);
  8066. };
  8067. _proto.copy = function copy(frustum) {
  8068. var planes = this.planes;
  8069. for (var i = 0; i < 6; i++) {
  8070. planes[i].copy(frustum.planes[i]);
  8071. }
  8072. return this;
  8073. };
  8074. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8075. var planes = this.planes;
  8076. var me = m.elements;
  8077. var me0 = me[0],
  8078. me1 = me[1],
  8079. me2 = me[2],
  8080. me3 = me[3];
  8081. var me4 = me[4],
  8082. me5 = me[5],
  8083. me6 = me[6],
  8084. me7 = me[7];
  8085. var me8 = me[8],
  8086. me9 = me[9],
  8087. me10 = me[10],
  8088. me11 = me[11];
  8089. var me12 = me[12],
  8090. me13 = me[13],
  8091. me14 = me[14],
  8092. me15 = me[15];
  8093. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8094. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8095. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8096. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8097. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8098. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8099. return this;
  8100. };
  8101. _proto.intersectsObject = function intersectsObject(object) {
  8102. var geometry = object.geometry;
  8103. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8104. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8105. return this.intersectsSphere(_sphere$1);
  8106. };
  8107. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8108. _sphere$1.center.set(0, 0, 0);
  8109. _sphere$1.radius = 0.7071067811865476;
  8110. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8111. return this.intersectsSphere(_sphere$1);
  8112. };
  8113. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8114. var planes = this.planes;
  8115. var center = sphere.center;
  8116. var negRadius = -sphere.radius;
  8117. for (var i = 0; i < 6; i++) {
  8118. var distance = planes[i].distanceToPoint(center);
  8119. if (distance < negRadius) {
  8120. return false;
  8121. }
  8122. }
  8123. return true;
  8124. };
  8125. _proto.intersectsBox = function intersectsBox(box) {
  8126. var planes = this.planes;
  8127. for (var i = 0; i < 6; i++) {
  8128. var plane = planes[i]; // corner at max distance
  8129. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8130. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8131. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8132. if (plane.distanceToPoint(_vector$5) < 0) {
  8133. return false;
  8134. }
  8135. }
  8136. return true;
  8137. };
  8138. _proto.containsPoint = function containsPoint(point) {
  8139. var planes = this.planes;
  8140. for (var i = 0; i < 6; i++) {
  8141. if (planes[i].distanceToPoint(point) < 0) {
  8142. return false;
  8143. }
  8144. }
  8145. return true;
  8146. };
  8147. return Frustum;
  8148. }();
  8149. function WebGLAnimation() {
  8150. var context = null;
  8151. var isAnimating = false;
  8152. var animationLoop = null;
  8153. var requestId = null;
  8154. function onAnimationFrame(time, frame) {
  8155. animationLoop(time, frame);
  8156. requestId = context.requestAnimationFrame(onAnimationFrame);
  8157. }
  8158. return {
  8159. start: function start() {
  8160. if (isAnimating === true) return;
  8161. if (animationLoop === null) return;
  8162. requestId = context.requestAnimationFrame(onAnimationFrame);
  8163. isAnimating = true;
  8164. },
  8165. stop: function stop() {
  8166. context.cancelAnimationFrame(requestId);
  8167. isAnimating = false;
  8168. },
  8169. setAnimationLoop: function setAnimationLoop(callback) {
  8170. animationLoop = callback;
  8171. },
  8172. setContext: function setContext(value) {
  8173. context = value;
  8174. }
  8175. };
  8176. }
  8177. function WebGLAttributes(gl, capabilities) {
  8178. var isWebGL2 = capabilities.isWebGL2;
  8179. var buffers = new WeakMap();
  8180. function createBuffer(attribute, bufferType) {
  8181. var array = attribute.array;
  8182. var usage = attribute.usage;
  8183. var buffer = gl.createBuffer();
  8184. gl.bindBuffer(bufferType, buffer);
  8185. gl.bufferData(bufferType, array, usage);
  8186. attribute.onUploadCallback();
  8187. var type = 5126;
  8188. if (array instanceof Float32Array) {
  8189. type = 5126;
  8190. } else if (array instanceof Float64Array) {
  8191. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8192. } else if (array instanceof Uint16Array) {
  8193. if (attribute.isFloat16BufferAttribute) {
  8194. if (isWebGL2) {
  8195. type = 5131;
  8196. } else {
  8197. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8198. }
  8199. } else {
  8200. type = 5123;
  8201. }
  8202. } else if (array instanceof Int16Array) {
  8203. type = 5122;
  8204. } else if (array instanceof Uint32Array) {
  8205. type = 5125;
  8206. } else if (array instanceof Int32Array) {
  8207. type = 5124;
  8208. } else if (array instanceof Int8Array) {
  8209. type = 5120;
  8210. } else if (array instanceof Uint8Array) {
  8211. type = 5121;
  8212. }
  8213. return {
  8214. buffer: buffer,
  8215. type: type,
  8216. bytesPerElement: array.BYTES_PER_ELEMENT,
  8217. version: attribute.version
  8218. };
  8219. }
  8220. function updateBuffer(buffer, attribute, bufferType) {
  8221. var array = attribute.array;
  8222. var updateRange = attribute.updateRange;
  8223. gl.bindBuffer(bufferType, buffer);
  8224. if (updateRange.count === -1) {
  8225. // Not using update ranges
  8226. gl.bufferSubData(bufferType, 0, array);
  8227. } else {
  8228. if (isWebGL2) {
  8229. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8230. } else {
  8231. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8232. }
  8233. updateRange.count = -1; // reset range
  8234. }
  8235. } //
  8236. function get(attribute) {
  8237. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8238. return buffers.get(attribute);
  8239. }
  8240. function remove(attribute) {
  8241. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8242. var data = buffers.get(attribute);
  8243. if (data) {
  8244. gl.deleteBuffer(data.buffer);
  8245. buffers.delete(attribute);
  8246. }
  8247. }
  8248. function update(attribute, bufferType) {
  8249. if (attribute.isGLBufferAttribute) {
  8250. var cached = buffers.get(attribute);
  8251. if (!cached || cached.version < attribute.version) {
  8252. buffers.set(attribute, {
  8253. buffer: attribute.buffer,
  8254. type: attribute.type,
  8255. bytesPerElement: attribute.elementSize,
  8256. version: attribute.version
  8257. });
  8258. }
  8259. return;
  8260. }
  8261. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8262. var data = buffers.get(attribute);
  8263. if (data === undefined) {
  8264. buffers.set(attribute, createBuffer(attribute, bufferType));
  8265. } else if (data.version < attribute.version) {
  8266. updateBuffer(data.buffer, attribute, bufferType);
  8267. data.version = attribute.version;
  8268. }
  8269. }
  8270. return {
  8271. get: get,
  8272. remove: remove,
  8273. update: update
  8274. };
  8275. }
  8276. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8277. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8278. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8279. var _this;
  8280. if (width === void 0) {
  8281. width = 1;
  8282. }
  8283. if (height === void 0) {
  8284. height = 1;
  8285. }
  8286. if (widthSegments === void 0) {
  8287. widthSegments = 1;
  8288. }
  8289. if (heightSegments === void 0) {
  8290. heightSegments = 1;
  8291. }
  8292. _this = _BufferGeometry.call(this) || this;
  8293. _this.type = 'PlaneBufferGeometry';
  8294. _this.parameters = {
  8295. width: width,
  8296. height: height,
  8297. widthSegments: widthSegments,
  8298. heightSegments: heightSegments
  8299. };
  8300. var width_half = width / 2;
  8301. var height_half = height / 2;
  8302. var gridX = Math.floor(widthSegments);
  8303. var gridY = Math.floor(heightSegments);
  8304. var gridX1 = gridX + 1;
  8305. var gridY1 = gridY + 1;
  8306. var segment_width = width / gridX;
  8307. var segment_height = height / gridY; //
  8308. var indices = [];
  8309. var vertices = [];
  8310. var normals = [];
  8311. var uvs = [];
  8312. for (var iy = 0; iy < gridY1; iy++) {
  8313. var y = iy * segment_height - height_half;
  8314. for (var ix = 0; ix < gridX1; ix++) {
  8315. var x = ix * segment_width - width_half;
  8316. vertices.push(x, -y, 0);
  8317. normals.push(0, 0, 1);
  8318. uvs.push(ix / gridX);
  8319. uvs.push(1 - iy / gridY);
  8320. }
  8321. }
  8322. for (var _iy = 0; _iy < gridY; _iy++) {
  8323. for (var _ix = 0; _ix < gridX; _ix++) {
  8324. var a = _ix + gridX1 * _iy;
  8325. var b = _ix + gridX1 * (_iy + 1);
  8326. var c = _ix + 1 + gridX1 * (_iy + 1);
  8327. var d = _ix + 1 + gridX1 * _iy;
  8328. indices.push(a, b, d);
  8329. indices.push(b, c, d);
  8330. }
  8331. }
  8332. _this.setIndex(indices);
  8333. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8334. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8335. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8336. return _this;
  8337. }
  8338. return PlaneBufferGeometry;
  8339. }(BufferGeometry);
  8340. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8341. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8342. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8343. 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";
  8344. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8345. var begin_vertex = "vec3 transformed = vec3( position );";
  8346. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8347. 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";
  8348. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  8349. 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";
  8350. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8351. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8352. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8353. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8354. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8355. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8356. 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";
  8357. 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}";
  8358. 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";
  8359. 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";
  8360. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8361. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8362. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8363. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8364. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8365. 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}";
  8366. 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";
  8367. 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";
  8368. 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";
  8369. 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";
  8370. 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";
  8371. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8372. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8373. 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";
  8374. 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";
  8375. 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}";
  8376. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8377. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8378. 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";
  8379. 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";
  8380. 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";
  8381. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8382. 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)";
  8383. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8384. 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)";
  8385. 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";
  8386. 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}";
  8387. 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";
  8388. 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";
  8389. 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";
  8390. 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";
  8391. 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";
  8392. 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";
  8393. 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";
  8394. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8395. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8396. 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";
  8397. 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";
  8398. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8399. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8400. 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";
  8401. 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";
  8402. 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";
  8403. var normal_fragment_begin = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  8404. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  8405. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8406. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8407. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN );\n\t#endif\n#endif";
  8408. 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";
  8409. 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}";
  8410. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8411. 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;";
  8412. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8413. 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";
  8414. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8415. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8416. 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";
  8417. 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";
  8418. 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";
  8419. 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}";
  8420. 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";
  8421. 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";
  8422. 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";
  8423. 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";
  8424. 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";
  8425. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8426. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8427. 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; }";
  8428. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8429. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8430. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8431. 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";
  8432. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8433. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8434. 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";
  8435. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8436. 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";
  8437. 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}";
  8438. 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}";
  8439. 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}";
  8440. 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}";
  8441. 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}";
  8442. 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}";
  8443. 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}";
  8444. 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}";
  8445. 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}";
  8446. 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}";
  8447. 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}";
  8448. 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}";
  8449. 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}";
  8450. 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}";
  8451. 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}";
  8452. 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}";
  8453. 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}";
  8454. 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}";
  8455. 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}";
  8456. 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}";
  8457. 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}";
  8458. 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}";
  8459. 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}";
  8460. 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}";
  8461. 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}";
  8462. 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}";
  8463. 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}";
  8464. 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}";
  8465. 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}";
  8466. 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}";
  8467. 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}";
  8468. 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}";
  8469. var ShaderChunk = {
  8470. alphamap_fragment: alphamap_fragment,
  8471. alphamap_pars_fragment: alphamap_pars_fragment,
  8472. alphatest_fragment: alphatest_fragment,
  8473. aomap_fragment: aomap_fragment,
  8474. aomap_pars_fragment: aomap_pars_fragment,
  8475. begin_vertex: begin_vertex,
  8476. beginnormal_vertex: beginnormal_vertex,
  8477. bsdfs: bsdfs,
  8478. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8479. clipping_planes_fragment: clipping_planes_fragment,
  8480. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8481. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8482. clipping_planes_vertex: clipping_planes_vertex,
  8483. color_fragment: color_fragment,
  8484. color_pars_fragment: color_pars_fragment,
  8485. color_pars_vertex: color_pars_vertex,
  8486. color_vertex: color_vertex,
  8487. common: common,
  8488. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8489. defaultnormal_vertex: defaultnormal_vertex,
  8490. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8491. displacementmap_vertex: displacementmap_vertex,
  8492. emissivemap_fragment: emissivemap_fragment,
  8493. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8494. encodings_fragment: encodings_fragment,
  8495. encodings_pars_fragment: encodings_pars_fragment,
  8496. envmap_fragment: envmap_fragment,
  8497. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8498. envmap_pars_fragment: envmap_pars_fragment,
  8499. envmap_pars_vertex: envmap_pars_vertex,
  8500. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8501. envmap_vertex: envmap_vertex,
  8502. fog_vertex: fog_vertex,
  8503. fog_pars_vertex: fog_pars_vertex,
  8504. fog_fragment: fog_fragment,
  8505. fog_pars_fragment: fog_pars_fragment,
  8506. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8507. lightmap_fragment: lightmap_fragment,
  8508. lightmap_pars_fragment: lightmap_pars_fragment,
  8509. lights_lambert_vertex: lights_lambert_vertex,
  8510. lights_pars_begin: lights_pars_begin,
  8511. lights_toon_fragment: lights_toon_fragment,
  8512. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8513. lights_phong_fragment: lights_phong_fragment,
  8514. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8515. lights_physical_fragment: lights_physical_fragment,
  8516. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8517. lights_fragment_begin: lights_fragment_begin,
  8518. lights_fragment_maps: lights_fragment_maps,
  8519. lights_fragment_end: lights_fragment_end,
  8520. logdepthbuf_fragment: logdepthbuf_fragment,
  8521. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8522. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8523. logdepthbuf_vertex: logdepthbuf_vertex,
  8524. map_fragment: map_fragment,
  8525. map_pars_fragment: map_pars_fragment,
  8526. map_particle_fragment: map_particle_fragment,
  8527. map_particle_pars_fragment: map_particle_pars_fragment,
  8528. metalnessmap_fragment: metalnessmap_fragment,
  8529. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8530. morphnormal_vertex: morphnormal_vertex,
  8531. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8532. morphtarget_vertex: morphtarget_vertex,
  8533. normal_fragment_begin: normal_fragment_begin,
  8534. normal_fragment_maps: normal_fragment_maps,
  8535. normalmap_pars_fragment: normalmap_pars_fragment,
  8536. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8537. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8538. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8539. packing: packing,
  8540. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8541. project_vertex: project_vertex,
  8542. dithering_fragment: dithering_fragment,
  8543. dithering_pars_fragment: dithering_pars_fragment,
  8544. roughnessmap_fragment: roughnessmap_fragment,
  8545. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8546. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8547. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8548. shadowmap_vertex: shadowmap_vertex,
  8549. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8550. skinbase_vertex: skinbase_vertex,
  8551. skinning_pars_vertex: skinning_pars_vertex,
  8552. skinning_vertex: skinning_vertex,
  8553. skinnormal_vertex: skinnormal_vertex,
  8554. specularmap_fragment: specularmap_fragment,
  8555. specularmap_pars_fragment: specularmap_pars_fragment,
  8556. tonemapping_fragment: tonemapping_fragment,
  8557. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8558. transmissionmap_fragment: transmissionmap_fragment,
  8559. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8560. uv_pars_fragment: uv_pars_fragment,
  8561. uv_pars_vertex: uv_pars_vertex,
  8562. uv_vertex: uv_vertex,
  8563. uv2_pars_fragment: uv2_pars_fragment,
  8564. uv2_pars_vertex: uv2_pars_vertex,
  8565. uv2_vertex: uv2_vertex,
  8566. worldpos_vertex: worldpos_vertex,
  8567. background_frag: background_frag,
  8568. background_vert: background_vert,
  8569. cube_frag: cube_frag,
  8570. cube_vert: cube_vert,
  8571. depth_frag: depth_frag,
  8572. depth_vert: depth_vert,
  8573. distanceRGBA_frag: distanceRGBA_frag,
  8574. distanceRGBA_vert: distanceRGBA_vert,
  8575. equirect_frag: equirect_frag,
  8576. equirect_vert: equirect_vert,
  8577. linedashed_frag: linedashed_frag,
  8578. linedashed_vert: linedashed_vert,
  8579. meshbasic_frag: meshbasic_frag,
  8580. meshbasic_vert: meshbasic_vert,
  8581. meshlambert_frag: meshlambert_frag,
  8582. meshlambert_vert: meshlambert_vert,
  8583. meshmatcap_frag: meshmatcap_frag,
  8584. meshmatcap_vert: meshmatcap_vert,
  8585. meshtoon_frag: meshtoon_frag,
  8586. meshtoon_vert: meshtoon_vert,
  8587. meshphong_frag: meshphong_frag,
  8588. meshphong_vert: meshphong_vert,
  8589. meshphysical_frag: meshphysical_frag,
  8590. meshphysical_vert: meshphysical_vert,
  8591. normal_frag: normal_frag,
  8592. normal_vert: normal_vert,
  8593. points_frag: points_frag,
  8594. points_vert: points_vert,
  8595. shadow_frag: shadow_frag,
  8596. shadow_vert: shadow_vert,
  8597. sprite_frag: sprite_frag,
  8598. sprite_vert: sprite_vert
  8599. };
  8600. /**
  8601. * Uniforms library for shared webgl shaders
  8602. */
  8603. var UniformsLib = {
  8604. common: {
  8605. diffuse: {
  8606. value: new Color(0xeeeeee)
  8607. },
  8608. opacity: {
  8609. value: 1.0
  8610. },
  8611. map: {
  8612. value: null
  8613. },
  8614. uvTransform: {
  8615. value: new Matrix3()
  8616. },
  8617. uv2Transform: {
  8618. value: new Matrix3()
  8619. },
  8620. alphaMap: {
  8621. value: null
  8622. }
  8623. },
  8624. specularmap: {
  8625. specularMap: {
  8626. value: null
  8627. }
  8628. },
  8629. envmap: {
  8630. envMap: {
  8631. value: null
  8632. },
  8633. flipEnvMap: {
  8634. value: -1
  8635. },
  8636. reflectivity: {
  8637. value: 1.0
  8638. },
  8639. refractionRatio: {
  8640. value: 0.98
  8641. },
  8642. maxMipLevel: {
  8643. value: 0
  8644. }
  8645. },
  8646. aomap: {
  8647. aoMap: {
  8648. value: null
  8649. },
  8650. aoMapIntensity: {
  8651. value: 1
  8652. }
  8653. },
  8654. lightmap: {
  8655. lightMap: {
  8656. value: null
  8657. },
  8658. lightMapIntensity: {
  8659. value: 1
  8660. }
  8661. },
  8662. emissivemap: {
  8663. emissiveMap: {
  8664. value: null
  8665. }
  8666. },
  8667. bumpmap: {
  8668. bumpMap: {
  8669. value: null
  8670. },
  8671. bumpScale: {
  8672. value: 1
  8673. }
  8674. },
  8675. normalmap: {
  8676. normalMap: {
  8677. value: null
  8678. },
  8679. normalScale: {
  8680. value: new Vector2(1, 1)
  8681. }
  8682. },
  8683. displacementmap: {
  8684. displacementMap: {
  8685. value: null
  8686. },
  8687. displacementScale: {
  8688. value: 1
  8689. },
  8690. displacementBias: {
  8691. value: 0
  8692. }
  8693. },
  8694. roughnessmap: {
  8695. roughnessMap: {
  8696. value: null
  8697. }
  8698. },
  8699. metalnessmap: {
  8700. metalnessMap: {
  8701. value: null
  8702. }
  8703. },
  8704. gradientmap: {
  8705. gradientMap: {
  8706. value: null
  8707. }
  8708. },
  8709. fog: {
  8710. fogDensity: {
  8711. value: 0.00025
  8712. },
  8713. fogNear: {
  8714. value: 1
  8715. },
  8716. fogFar: {
  8717. value: 2000
  8718. },
  8719. fogColor: {
  8720. value: new Color(0xffffff)
  8721. }
  8722. },
  8723. lights: {
  8724. ambientLightColor: {
  8725. value: []
  8726. },
  8727. lightProbe: {
  8728. value: []
  8729. },
  8730. directionalLights: {
  8731. value: [],
  8732. properties: {
  8733. direction: {},
  8734. color: {}
  8735. }
  8736. },
  8737. directionalLightShadows: {
  8738. value: [],
  8739. properties: {
  8740. shadowBias: {},
  8741. shadowNormalBias: {},
  8742. shadowRadius: {},
  8743. shadowMapSize: {}
  8744. }
  8745. },
  8746. directionalShadowMap: {
  8747. value: []
  8748. },
  8749. directionalShadowMatrix: {
  8750. value: []
  8751. },
  8752. spotLights: {
  8753. value: [],
  8754. properties: {
  8755. color: {},
  8756. position: {},
  8757. direction: {},
  8758. distance: {},
  8759. coneCos: {},
  8760. penumbraCos: {},
  8761. decay: {}
  8762. }
  8763. },
  8764. spotLightShadows: {
  8765. value: [],
  8766. properties: {
  8767. shadowBias: {},
  8768. shadowNormalBias: {},
  8769. shadowRadius: {},
  8770. shadowMapSize: {}
  8771. }
  8772. },
  8773. spotShadowMap: {
  8774. value: []
  8775. },
  8776. spotShadowMatrix: {
  8777. value: []
  8778. },
  8779. pointLights: {
  8780. value: [],
  8781. properties: {
  8782. color: {},
  8783. position: {},
  8784. decay: {},
  8785. distance: {}
  8786. }
  8787. },
  8788. pointLightShadows: {
  8789. value: [],
  8790. properties: {
  8791. shadowBias: {},
  8792. shadowNormalBias: {},
  8793. shadowRadius: {},
  8794. shadowMapSize: {},
  8795. shadowCameraNear: {},
  8796. shadowCameraFar: {}
  8797. }
  8798. },
  8799. pointShadowMap: {
  8800. value: []
  8801. },
  8802. pointShadowMatrix: {
  8803. value: []
  8804. },
  8805. hemisphereLights: {
  8806. value: [],
  8807. properties: {
  8808. direction: {},
  8809. skyColor: {},
  8810. groundColor: {}
  8811. }
  8812. },
  8813. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8814. rectAreaLights: {
  8815. value: [],
  8816. properties: {
  8817. color: {},
  8818. position: {},
  8819. width: {},
  8820. height: {}
  8821. }
  8822. },
  8823. ltc_1: {
  8824. value: null
  8825. },
  8826. ltc_2: {
  8827. value: null
  8828. }
  8829. },
  8830. points: {
  8831. diffuse: {
  8832. value: new Color(0xeeeeee)
  8833. },
  8834. opacity: {
  8835. value: 1.0
  8836. },
  8837. size: {
  8838. value: 1.0
  8839. },
  8840. scale: {
  8841. value: 1.0
  8842. },
  8843. map: {
  8844. value: null
  8845. },
  8846. alphaMap: {
  8847. value: null
  8848. },
  8849. uvTransform: {
  8850. value: new Matrix3()
  8851. }
  8852. },
  8853. sprite: {
  8854. diffuse: {
  8855. value: new Color(0xeeeeee)
  8856. },
  8857. opacity: {
  8858. value: 1.0
  8859. },
  8860. center: {
  8861. value: new Vector2(0.5, 0.5)
  8862. },
  8863. rotation: {
  8864. value: 0.0
  8865. },
  8866. map: {
  8867. value: null
  8868. },
  8869. alphaMap: {
  8870. value: null
  8871. },
  8872. uvTransform: {
  8873. value: new Matrix3()
  8874. }
  8875. }
  8876. };
  8877. var ShaderLib = {
  8878. basic: {
  8879. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8880. vertexShader: ShaderChunk.meshbasic_vert,
  8881. fragmentShader: ShaderChunk.meshbasic_frag
  8882. },
  8883. lambert: {
  8884. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8885. emissive: {
  8886. value: new Color(0x000000)
  8887. }
  8888. }]),
  8889. vertexShader: ShaderChunk.meshlambert_vert,
  8890. fragmentShader: ShaderChunk.meshlambert_frag
  8891. },
  8892. phong: {
  8893. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8894. emissive: {
  8895. value: new Color(0x000000)
  8896. },
  8897. specular: {
  8898. value: new Color(0x111111)
  8899. },
  8900. shininess: {
  8901. value: 30
  8902. }
  8903. }]),
  8904. vertexShader: ShaderChunk.meshphong_vert,
  8905. fragmentShader: ShaderChunk.meshphong_frag
  8906. },
  8907. standard: {
  8908. 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, {
  8909. emissive: {
  8910. value: new Color(0x000000)
  8911. },
  8912. roughness: {
  8913. value: 1.0
  8914. },
  8915. metalness: {
  8916. value: 0.0
  8917. },
  8918. envMapIntensity: {
  8919. value: 1
  8920. } // temporary
  8921. }]),
  8922. vertexShader: ShaderChunk.meshphysical_vert,
  8923. fragmentShader: ShaderChunk.meshphysical_frag
  8924. },
  8925. toon: {
  8926. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8927. emissive: {
  8928. value: new Color(0x000000)
  8929. }
  8930. }]),
  8931. vertexShader: ShaderChunk.meshtoon_vert,
  8932. fragmentShader: ShaderChunk.meshtoon_frag
  8933. },
  8934. matcap: {
  8935. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8936. matcap: {
  8937. value: null
  8938. }
  8939. }]),
  8940. vertexShader: ShaderChunk.meshmatcap_vert,
  8941. fragmentShader: ShaderChunk.meshmatcap_frag
  8942. },
  8943. points: {
  8944. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8945. vertexShader: ShaderChunk.points_vert,
  8946. fragmentShader: ShaderChunk.points_frag
  8947. },
  8948. dashed: {
  8949. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8950. scale: {
  8951. value: 1
  8952. },
  8953. dashSize: {
  8954. value: 1
  8955. },
  8956. totalSize: {
  8957. value: 2
  8958. }
  8959. }]),
  8960. vertexShader: ShaderChunk.linedashed_vert,
  8961. fragmentShader: ShaderChunk.linedashed_frag
  8962. },
  8963. depth: {
  8964. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8965. vertexShader: ShaderChunk.depth_vert,
  8966. fragmentShader: ShaderChunk.depth_frag
  8967. },
  8968. normal: {
  8969. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8970. opacity: {
  8971. value: 1.0
  8972. }
  8973. }]),
  8974. vertexShader: ShaderChunk.normal_vert,
  8975. fragmentShader: ShaderChunk.normal_frag
  8976. },
  8977. sprite: {
  8978. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8979. vertexShader: ShaderChunk.sprite_vert,
  8980. fragmentShader: ShaderChunk.sprite_frag
  8981. },
  8982. background: {
  8983. uniforms: {
  8984. uvTransform: {
  8985. value: new Matrix3()
  8986. },
  8987. t2D: {
  8988. value: null
  8989. }
  8990. },
  8991. vertexShader: ShaderChunk.background_vert,
  8992. fragmentShader: ShaderChunk.background_frag
  8993. },
  8994. /* -------------------------------------------------------------------------
  8995. // Cube map shader
  8996. ------------------------------------------------------------------------- */
  8997. cube: {
  8998. uniforms: mergeUniforms([UniformsLib.envmap, {
  8999. opacity: {
  9000. value: 1.0
  9001. }
  9002. }]),
  9003. vertexShader: ShaderChunk.cube_vert,
  9004. fragmentShader: ShaderChunk.cube_frag
  9005. },
  9006. equirect: {
  9007. uniforms: {
  9008. tEquirect: {
  9009. value: null
  9010. }
  9011. },
  9012. vertexShader: ShaderChunk.equirect_vert,
  9013. fragmentShader: ShaderChunk.equirect_frag
  9014. },
  9015. distanceRGBA: {
  9016. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9017. referencePosition: {
  9018. value: new Vector3()
  9019. },
  9020. nearDistance: {
  9021. value: 1
  9022. },
  9023. farDistance: {
  9024. value: 1000
  9025. }
  9026. }]),
  9027. vertexShader: ShaderChunk.distanceRGBA_vert,
  9028. fragmentShader: ShaderChunk.distanceRGBA_frag
  9029. },
  9030. shadow: {
  9031. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9032. color: {
  9033. value: new Color(0x00000)
  9034. },
  9035. opacity: {
  9036. value: 1.0
  9037. }
  9038. }]),
  9039. vertexShader: ShaderChunk.shadow_vert,
  9040. fragmentShader: ShaderChunk.shadow_frag
  9041. }
  9042. };
  9043. ShaderLib.physical = {
  9044. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9045. clearcoat: {
  9046. value: 0
  9047. },
  9048. clearcoatMap: {
  9049. value: null
  9050. },
  9051. clearcoatRoughness: {
  9052. value: 0
  9053. },
  9054. clearcoatRoughnessMap: {
  9055. value: null
  9056. },
  9057. clearcoatNormalScale: {
  9058. value: new Vector2(1, 1)
  9059. },
  9060. clearcoatNormalMap: {
  9061. value: null
  9062. },
  9063. sheen: {
  9064. value: new Color(0x000000)
  9065. },
  9066. transmission: {
  9067. value: 0
  9068. },
  9069. transmissionMap: {
  9070. value: null
  9071. }
  9072. }]),
  9073. vertexShader: ShaderChunk.meshphysical_vert,
  9074. fragmentShader: ShaderChunk.meshphysical_frag
  9075. };
  9076. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9077. var clearColor = new Color(0x000000);
  9078. var clearAlpha = 0;
  9079. var planeMesh;
  9080. var boxMesh;
  9081. var currentBackground = null;
  9082. var currentBackgroundVersion = 0;
  9083. var currentTonemapping = null;
  9084. function render(renderList, scene, camera, forceClear) {
  9085. var background = scene.isScene === true ? scene.background : null;
  9086. if (background && background.isTexture) {
  9087. background = cubemaps.get(background);
  9088. } // Ignore background in AR
  9089. // TODO: Reconsider this.
  9090. var xr = renderer.xr;
  9091. var session = xr.getSession && xr.getSession();
  9092. if (session && session.environmentBlendMode === 'additive') {
  9093. background = null;
  9094. }
  9095. if (background === null) {
  9096. setClear(clearColor, clearAlpha);
  9097. } else if (background && background.isColor) {
  9098. setClear(background, 1);
  9099. forceClear = true;
  9100. }
  9101. if (renderer.autoClear || forceClear) {
  9102. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9103. }
  9104. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9105. if (boxMesh === undefined) {
  9106. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  9107. name: 'BackgroundCubeMaterial',
  9108. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9109. vertexShader: ShaderLib.cube.vertexShader,
  9110. fragmentShader: ShaderLib.cube.fragmentShader,
  9111. side: BackSide,
  9112. depthTest: false,
  9113. depthWrite: false,
  9114. fog: false
  9115. }));
  9116. boxMesh.geometry.deleteAttribute('normal');
  9117. boxMesh.geometry.deleteAttribute('uv');
  9118. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9119. this.matrixWorld.copyPosition(camera.matrixWorld);
  9120. }; // enable code injection for non-built-in material
  9121. Object.defineProperty(boxMesh.material, 'envMap', {
  9122. get: function get() {
  9123. return this.uniforms.envMap.value;
  9124. }
  9125. });
  9126. objects.update(boxMesh);
  9127. }
  9128. if (background.isWebGLCubeRenderTarget) {
  9129. // TODO Deprecate
  9130. background = background.texture;
  9131. }
  9132. boxMesh.material.uniforms.envMap.value = background;
  9133. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9134. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9135. boxMesh.material.needsUpdate = true;
  9136. currentBackground = background;
  9137. currentBackgroundVersion = background.version;
  9138. currentTonemapping = renderer.toneMapping;
  9139. } // push to the pre-sorted opaque render list
  9140. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9141. } else if (background && background.isTexture) {
  9142. if (planeMesh === undefined) {
  9143. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  9144. name: 'BackgroundMaterial',
  9145. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9146. vertexShader: ShaderLib.background.vertexShader,
  9147. fragmentShader: ShaderLib.background.fragmentShader,
  9148. side: FrontSide,
  9149. depthTest: false,
  9150. depthWrite: false,
  9151. fog: false
  9152. }));
  9153. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9154. Object.defineProperty(planeMesh.material, 'map', {
  9155. get: function get() {
  9156. return this.uniforms.t2D.value;
  9157. }
  9158. });
  9159. objects.update(planeMesh);
  9160. }
  9161. planeMesh.material.uniforms.t2D.value = background;
  9162. if (background.matrixAutoUpdate === true) {
  9163. background.updateMatrix();
  9164. }
  9165. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9166. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9167. planeMesh.material.needsUpdate = true;
  9168. currentBackground = background;
  9169. currentBackgroundVersion = background.version;
  9170. currentTonemapping = renderer.toneMapping;
  9171. } // push to the pre-sorted opaque render list
  9172. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9173. }
  9174. }
  9175. function setClear(color, alpha) {
  9176. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9177. }
  9178. return {
  9179. getClearColor: function getClearColor() {
  9180. return clearColor;
  9181. },
  9182. setClearColor: function setClearColor(color, alpha) {
  9183. if (alpha === void 0) {
  9184. alpha = 1;
  9185. }
  9186. clearColor.set(color);
  9187. clearAlpha = alpha;
  9188. setClear(clearColor, clearAlpha);
  9189. },
  9190. getClearAlpha: function getClearAlpha() {
  9191. return clearAlpha;
  9192. },
  9193. setClearAlpha: function setClearAlpha(alpha) {
  9194. clearAlpha = alpha;
  9195. setClear(clearColor, clearAlpha);
  9196. },
  9197. render: render
  9198. };
  9199. }
  9200. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9201. var maxVertexAttributes = gl.getParameter(34921);
  9202. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9203. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9204. var bindingStates = {};
  9205. var defaultState = createBindingState(null);
  9206. var currentState = defaultState;
  9207. function setup(object, material, program, geometry, index) {
  9208. var updateBuffers = false;
  9209. if (vaoAvailable) {
  9210. var state = getBindingState(geometry, program, material);
  9211. if (currentState !== state) {
  9212. currentState = state;
  9213. bindVertexArrayObject(currentState.object);
  9214. }
  9215. updateBuffers = needsUpdate(geometry, index);
  9216. if (updateBuffers) saveCache(geometry, index);
  9217. } else {
  9218. var wireframe = material.wireframe === true;
  9219. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9220. currentState.geometry = geometry.id;
  9221. currentState.program = program.id;
  9222. currentState.wireframe = wireframe;
  9223. updateBuffers = true;
  9224. }
  9225. }
  9226. if (object.isInstancedMesh === true) {
  9227. updateBuffers = true;
  9228. }
  9229. if (index !== null) {
  9230. attributes.update(index, 34963);
  9231. }
  9232. if (updateBuffers) {
  9233. setupVertexAttributes(object, material, program, geometry);
  9234. if (index !== null) {
  9235. gl.bindBuffer(34963, attributes.get(index).buffer);
  9236. }
  9237. }
  9238. }
  9239. function createVertexArrayObject() {
  9240. if (capabilities.isWebGL2) return gl.createVertexArray();
  9241. return extension.createVertexArrayOES();
  9242. }
  9243. function bindVertexArrayObject(vao) {
  9244. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9245. return extension.bindVertexArrayOES(vao);
  9246. }
  9247. function deleteVertexArrayObject(vao) {
  9248. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9249. return extension.deleteVertexArrayOES(vao);
  9250. }
  9251. function getBindingState(geometry, program, material) {
  9252. var wireframe = material.wireframe === true;
  9253. var programMap = bindingStates[geometry.id];
  9254. if (programMap === undefined) {
  9255. programMap = {};
  9256. bindingStates[geometry.id] = programMap;
  9257. }
  9258. var stateMap = programMap[program.id];
  9259. if (stateMap === undefined) {
  9260. stateMap = {};
  9261. programMap[program.id] = stateMap;
  9262. }
  9263. var state = stateMap[wireframe];
  9264. if (state === undefined) {
  9265. state = createBindingState(createVertexArrayObject());
  9266. stateMap[wireframe] = state;
  9267. }
  9268. return state;
  9269. }
  9270. function createBindingState(vao) {
  9271. var newAttributes = [];
  9272. var enabledAttributes = [];
  9273. var attributeDivisors = [];
  9274. for (var i = 0; i < maxVertexAttributes; i++) {
  9275. newAttributes[i] = 0;
  9276. enabledAttributes[i] = 0;
  9277. attributeDivisors[i] = 0;
  9278. }
  9279. return {
  9280. // for backward compatibility on non-VAO support browser
  9281. geometry: null,
  9282. program: null,
  9283. wireframe: false,
  9284. newAttributes: newAttributes,
  9285. enabledAttributes: enabledAttributes,
  9286. attributeDivisors: attributeDivisors,
  9287. object: vao,
  9288. attributes: {},
  9289. index: null
  9290. };
  9291. }
  9292. function needsUpdate(geometry, index) {
  9293. var cachedAttributes = currentState.attributes;
  9294. var geometryAttributes = geometry.attributes;
  9295. var attributesNum = 0;
  9296. for (var key in geometryAttributes) {
  9297. var cachedAttribute = cachedAttributes[key];
  9298. var geometryAttribute = geometryAttributes[key];
  9299. if (cachedAttribute === undefined) return true;
  9300. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9301. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9302. attributesNum++;
  9303. }
  9304. if (currentState.attributesNum !== attributesNum) return true;
  9305. if (currentState.index !== index) return true;
  9306. return false;
  9307. }
  9308. function saveCache(geometry, index) {
  9309. var cache = {};
  9310. var attributes = geometry.attributes;
  9311. var attributesNum = 0;
  9312. for (var key in attributes) {
  9313. var attribute = attributes[key];
  9314. var data = {};
  9315. data.attribute = attribute;
  9316. if (attribute.data) {
  9317. data.data = attribute.data;
  9318. }
  9319. cache[key] = data;
  9320. attributesNum++;
  9321. }
  9322. currentState.attributes = cache;
  9323. currentState.attributesNum = attributesNum;
  9324. currentState.index = index;
  9325. }
  9326. function initAttributes() {
  9327. var newAttributes = currentState.newAttributes;
  9328. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9329. newAttributes[i] = 0;
  9330. }
  9331. }
  9332. function enableAttribute(attribute) {
  9333. enableAttributeAndDivisor(attribute, 0);
  9334. }
  9335. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9336. var newAttributes = currentState.newAttributes;
  9337. var enabledAttributes = currentState.enabledAttributes;
  9338. var attributeDivisors = currentState.attributeDivisors;
  9339. newAttributes[attribute] = 1;
  9340. if (enabledAttributes[attribute] === 0) {
  9341. gl.enableVertexAttribArray(attribute);
  9342. enabledAttributes[attribute] = 1;
  9343. }
  9344. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9345. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9346. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9347. attributeDivisors[attribute] = meshPerAttribute;
  9348. }
  9349. }
  9350. function disableUnusedAttributes() {
  9351. var newAttributes = currentState.newAttributes;
  9352. var enabledAttributes = currentState.enabledAttributes;
  9353. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9354. if (enabledAttributes[i] !== newAttributes[i]) {
  9355. gl.disableVertexAttribArray(i);
  9356. enabledAttributes[i] = 0;
  9357. }
  9358. }
  9359. }
  9360. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9361. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9362. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9363. } else {
  9364. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9365. }
  9366. }
  9367. function setupVertexAttributes(object, material, program, geometry) {
  9368. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9369. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9370. }
  9371. initAttributes();
  9372. var geometryAttributes = geometry.attributes;
  9373. var programAttributes = program.getAttributes();
  9374. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9375. for (var name in programAttributes) {
  9376. var programAttribute = programAttributes[name];
  9377. if (programAttribute >= 0) {
  9378. var geometryAttribute = geometryAttributes[name];
  9379. if (geometryAttribute !== undefined) {
  9380. var normalized = geometryAttribute.normalized;
  9381. var size = geometryAttribute.itemSize;
  9382. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9383. if (attribute === undefined) continue;
  9384. var buffer = attribute.buffer;
  9385. var type = attribute.type;
  9386. var bytesPerElement = attribute.bytesPerElement;
  9387. if (geometryAttribute.isInterleavedBufferAttribute) {
  9388. var data = geometryAttribute.data;
  9389. var stride = data.stride;
  9390. var offset = geometryAttribute.offset;
  9391. if (data && data.isInstancedInterleavedBuffer) {
  9392. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9393. if (geometry._maxInstanceCount === undefined) {
  9394. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9395. }
  9396. } else {
  9397. enableAttribute(programAttribute);
  9398. }
  9399. gl.bindBuffer(34962, buffer);
  9400. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9401. } else {
  9402. if (geometryAttribute.isInstancedBufferAttribute) {
  9403. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9404. if (geometry._maxInstanceCount === undefined) {
  9405. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9406. }
  9407. } else {
  9408. enableAttribute(programAttribute);
  9409. }
  9410. gl.bindBuffer(34962, buffer);
  9411. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9412. }
  9413. } else if (name === 'instanceMatrix') {
  9414. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9415. if (_attribute === undefined) continue;
  9416. var _buffer = _attribute.buffer;
  9417. var _type = _attribute.type;
  9418. enableAttributeAndDivisor(programAttribute + 0, 1);
  9419. enableAttributeAndDivisor(programAttribute + 1, 1);
  9420. enableAttributeAndDivisor(programAttribute + 2, 1);
  9421. enableAttributeAndDivisor(programAttribute + 3, 1);
  9422. gl.bindBuffer(34962, _buffer);
  9423. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9424. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9425. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9426. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9427. } else if (name === 'instanceColor') {
  9428. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9429. if (_attribute2 === undefined) continue;
  9430. var _buffer2 = _attribute2.buffer;
  9431. var _type2 = _attribute2.type;
  9432. enableAttributeAndDivisor(programAttribute, 1);
  9433. gl.bindBuffer(34962, _buffer2);
  9434. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9435. } else if (materialDefaultAttributeValues !== undefined) {
  9436. var value = materialDefaultAttributeValues[name];
  9437. if (value !== undefined) {
  9438. switch (value.length) {
  9439. case 2:
  9440. gl.vertexAttrib2fv(programAttribute, value);
  9441. break;
  9442. case 3:
  9443. gl.vertexAttrib3fv(programAttribute, value);
  9444. break;
  9445. case 4:
  9446. gl.vertexAttrib4fv(programAttribute, value);
  9447. break;
  9448. default:
  9449. gl.vertexAttrib1fv(programAttribute, value);
  9450. }
  9451. }
  9452. }
  9453. }
  9454. }
  9455. disableUnusedAttributes();
  9456. }
  9457. function dispose() {
  9458. reset();
  9459. for (var geometryId in bindingStates) {
  9460. var programMap = bindingStates[geometryId];
  9461. for (var programId in programMap) {
  9462. var stateMap = programMap[programId];
  9463. for (var wireframe in stateMap) {
  9464. deleteVertexArrayObject(stateMap[wireframe].object);
  9465. delete stateMap[wireframe];
  9466. }
  9467. delete programMap[programId];
  9468. }
  9469. delete bindingStates[geometryId];
  9470. }
  9471. }
  9472. function releaseStatesOfGeometry(geometry) {
  9473. if (bindingStates[geometry.id] === undefined) return;
  9474. var programMap = bindingStates[geometry.id];
  9475. for (var programId in programMap) {
  9476. var stateMap = programMap[programId];
  9477. for (var wireframe in stateMap) {
  9478. deleteVertexArrayObject(stateMap[wireframe].object);
  9479. delete stateMap[wireframe];
  9480. }
  9481. delete programMap[programId];
  9482. }
  9483. delete bindingStates[geometry.id];
  9484. }
  9485. function releaseStatesOfProgram(program) {
  9486. for (var geometryId in bindingStates) {
  9487. var programMap = bindingStates[geometryId];
  9488. if (programMap[program.id] === undefined) continue;
  9489. var stateMap = programMap[program.id];
  9490. for (var wireframe in stateMap) {
  9491. deleteVertexArrayObject(stateMap[wireframe].object);
  9492. delete stateMap[wireframe];
  9493. }
  9494. delete programMap[program.id];
  9495. }
  9496. }
  9497. function reset() {
  9498. resetDefaultState();
  9499. if (currentState === defaultState) return;
  9500. currentState = defaultState;
  9501. bindVertexArrayObject(currentState.object);
  9502. } // for backward-compatilibity
  9503. function resetDefaultState() {
  9504. defaultState.geometry = null;
  9505. defaultState.program = null;
  9506. defaultState.wireframe = false;
  9507. }
  9508. return {
  9509. setup: setup,
  9510. reset: reset,
  9511. resetDefaultState: resetDefaultState,
  9512. dispose: dispose,
  9513. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9514. releaseStatesOfProgram: releaseStatesOfProgram,
  9515. initAttributes: initAttributes,
  9516. enableAttribute: enableAttribute,
  9517. disableUnusedAttributes: disableUnusedAttributes
  9518. };
  9519. }
  9520. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9521. var isWebGL2 = capabilities.isWebGL2;
  9522. var mode;
  9523. function setMode(value) {
  9524. mode = value;
  9525. }
  9526. function render(start, count) {
  9527. gl.drawArrays(mode, start, count);
  9528. info.update(count, mode, 1);
  9529. }
  9530. function renderInstances(start, count, primcount) {
  9531. if (primcount === 0) return;
  9532. var extension, methodName;
  9533. if (isWebGL2) {
  9534. extension = gl;
  9535. methodName = 'drawArraysInstanced';
  9536. } else {
  9537. extension = extensions.get('ANGLE_instanced_arrays');
  9538. methodName = 'drawArraysInstancedANGLE';
  9539. if (extension === null) {
  9540. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9541. return;
  9542. }
  9543. }
  9544. extension[methodName](mode, start, count, primcount);
  9545. info.update(count, mode, primcount);
  9546. } //
  9547. this.setMode = setMode;
  9548. this.render = render;
  9549. this.renderInstances = renderInstances;
  9550. }
  9551. function WebGLCapabilities(gl, extensions, parameters) {
  9552. var maxAnisotropy;
  9553. function getMaxAnisotropy() {
  9554. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9555. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9556. if (extension !== null) {
  9557. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9558. } else {
  9559. maxAnisotropy = 0;
  9560. }
  9561. return maxAnisotropy;
  9562. }
  9563. function getMaxPrecision(precision) {
  9564. if (precision === 'highp') {
  9565. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9566. return 'highp';
  9567. }
  9568. precision = 'mediump';
  9569. }
  9570. if (precision === 'mediump') {
  9571. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9572. return 'mediump';
  9573. }
  9574. }
  9575. return 'lowp';
  9576. }
  9577. /* eslint-disable no-undef */
  9578. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9579. /* eslint-enable no-undef */
  9580. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9581. var maxPrecision = getMaxPrecision(precision);
  9582. if (maxPrecision !== precision) {
  9583. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9584. precision = maxPrecision;
  9585. }
  9586. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9587. var maxTextures = gl.getParameter(34930);
  9588. var maxVertexTextures = gl.getParameter(35660);
  9589. var maxTextureSize = gl.getParameter(3379);
  9590. var maxCubemapSize = gl.getParameter(34076);
  9591. var maxAttributes = gl.getParameter(34921);
  9592. var maxVertexUniforms = gl.getParameter(36347);
  9593. var maxVaryings = gl.getParameter(36348);
  9594. var maxFragmentUniforms = gl.getParameter(36349);
  9595. var vertexTextures = maxVertexTextures > 0;
  9596. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9597. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9598. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9599. return {
  9600. isWebGL2: isWebGL2,
  9601. getMaxAnisotropy: getMaxAnisotropy,
  9602. getMaxPrecision: getMaxPrecision,
  9603. precision: precision,
  9604. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9605. maxTextures: maxTextures,
  9606. maxVertexTextures: maxVertexTextures,
  9607. maxTextureSize: maxTextureSize,
  9608. maxCubemapSize: maxCubemapSize,
  9609. maxAttributes: maxAttributes,
  9610. maxVertexUniforms: maxVertexUniforms,
  9611. maxVaryings: maxVaryings,
  9612. maxFragmentUniforms: maxFragmentUniforms,
  9613. vertexTextures: vertexTextures,
  9614. floatFragmentTextures: floatFragmentTextures,
  9615. floatVertexTextures: floatVertexTextures,
  9616. maxSamples: maxSamples
  9617. };
  9618. }
  9619. function WebGLClipping(properties) {
  9620. var scope = this;
  9621. var globalState = null,
  9622. numGlobalPlanes = 0,
  9623. localClippingEnabled = false,
  9624. renderingShadows = false;
  9625. var plane = new Plane(),
  9626. viewNormalMatrix = new Matrix3(),
  9627. uniform = {
  9628. value: null,
  9629. needsUpdate: false
  9630. };
  9631. this.uniform = uniform;
  9632. this.numPlanes = 0;
  9633. this.numIntersection = 0;
  9634. this.init = function (planes, enableLocalClipping, camera) {
  9635. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9636. // run another frame in order to reset the state:
  9637. numGlobalPlanes !== 0 || localClippingEnabled;
  9638. localClippingEnabled = enableLocalClipping;
  9639. globalState = projectPlanes(planes, camera, 0);
  9640. numGlobalPlanes = planes.length;
  9641. return enabled;
  9642. };
  9643. this.beginShadows = function () {
  9644. renderingShadows = true;
  9645. projectPlanes(null);
  9646. };
  9647. this.endShadows = function () {
  9648. renderingShadows = false;
  9649. resetGlobalState();
  9650. };
  9651. this.setState = function (material, camera, useCache) {
  9652. var planes = material.clippingPlanes,
  9653. clipIntersection = material.clipIntersection,
  9654. clipShadows = material.clipShadows;
  9655. var materialProperties = properties.get(material);
  9656. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9657. // there's no local clipping
  9658. if (renderingShadows) {
  9659. // there's no global clipping
  9660. projectPlanes(null);
  9661. } else {
  9662. resetGlobalState();
  9663. }
  9664. } else {
  9665. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9666. lGlobal = nGlobal * 4;
  9667. var dstArray = materialProperties.clippingState || null;
  9668. uniform.value = dstArray; // ensure unique state
  9669. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9670. for (var i = 0; i !== lGlobal; ++i) {
  9671. dstArray[i] = globalState[i];
  9672. }
  9673. materialProperties.clippingState = dstArray;
  9674. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9675. this.numPlanes += nGlobal;
  9676. }
  9677. };
  9678. function resetGlobalState() {
  9679. if (uniform.value !== globalState) {
  9680. uniform.value = globalState;
  9681. uniform.needsUpdate = numGlobalPlanes > 0;
  9682. }
  9683. scope.numPlanes = numGlobalPlanes;
  9684. scope.numIntersection = 0;
  9685. }
  9686. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9687. var nPlanes = planes !== null ? planes.length : 0;
  9688. var dstArray = null;
  9689. if (nPlanes !== 0) {
  9690. dstArray = uniform.value;
  9691. if (skipTransform !== true || dstArray === null) {
  9692. var flatSize = dstOffset + nPlanes * 4,
  9693. viewMatrix = camera.matrixWorldInverse;
  9694. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9695. if (dstArray === null || dstArray.length < flatSize) {
  9696. dstArray = new Float32Array(flatSize);
  9697. }
  9698. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9699. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9700. plane.normal.toArray(dstArray, i4);
  9701. dstArray[i4 + 3] = plane.constant;
  9702. }
  9703. }
  9704. uniform.value = dstArray;
  9705. uniform.needsUpdate = true;
  9706. }
  9707. scope.numPlanes = nPlanes;
  9708. scope.numIntersection = 0;
  9709. return dstArray;
  9710. }
  9711. }
  9712. function WebGLCubeMaps(renderer) {
  9713. var cubemaps = new WeakMap();
  9714. function mapTextureMapping(texture, mapping) {
  9715. if (mapping === EquirectangularReflectionMapping) {
  9716. texture.mapping = CubeReflectionMapping;
  9717. } else if (mapping === EquirectangularRefractionMapping) {
  9718. texture.mapping = CubeRefractionMapping;
  9719. }
  9720. return texture;
  9721. }
  9722. function get(texture) {
  9723. if (texture && texture.isTexture) {
  9724. var mapping = texture.mapping;
  9725. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9726. if (cubemaps.has(texture)) {
  9727. var cubemap = cubemaps.get(texture).texture;
  9728. return mapTextureMapping(cubemap, texture.mapping);
  9729. } else {
  9730. var image = texture.image;
  9731. if (image && image.height > 0) {
  9732. var currentRenderList = renderer.getRenderList();
  9733. var currentRenderTarget = renderer.getRenderTarget();
  9734. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9735. renderTarget.fromEquirectangularTexture(renderer, texture);
  9736. cubemaps.set(texture, renderTarget);
  9737. renderer.setRenderTarget(currentRenderTarget);
  9738. renderer.setRenderList(currentRenderList);
  9739. texture.addEventListener('dispose', onTextureDispose);
  9740. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9741. } else {
  9742. // image not yet ready. try the conversion next frame
  9743. return null;
  9744. }
  9745. }
  9746. }
  9747. }
  9748. return texture;
  9749. }
  9750. function onTextureDispose(event) {
  9751. var texture = event.target;
  9752. texture.removeEventListener('dispose', onTextureDispose);
  9753. var cubemap = cubemaps.get(texture);
  9754. if (cubemap !== undefined) {
  9755. cubemaps.delete(texture);
  9756. cubemap.dispose();
  9757. }
  9758. }
  9759. function dispose() {
  9760. cubemaps = new WeakMap();
  9761. }
  9762. return {
  9763. get: get,
  9764. dispose: dispose
  9765. };
  9766. }
  9767. function WebGLExtensions(gl) {
  9768. var extensions = {};
  9769. return {
  9770. has: function has(name) {
  9771. if (extensions[name] !== undefined) {
  9772. return extensions[name] !== null;
  9773. }
  9774. var extension;
  9775. switch (name) {
  9776. case 'WEBGL_depth_texture':
  9777. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9778. break;
  9779. case 'EXT_texture_filter_anisotropic':
  9780. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9781. break;
  9782. case 'WEBGL_compressed_texture_s3tc':
  9783. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9784. break;
  9785. case 'WEBGL_compressed_texture_pvrtc':
  9786. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9787. break;
  9788. default:
  9789. extension = gl.getExtension(name);
  9790. }
  9791. extensions[name] = extension;
  9792. return extension !== null;
  9793. },
  9794. get: function get(name) {
  9795. if (!this.has(name)) {
  9796. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9797. }
  9798. return extensions[name];
  9799. }
  9800. };
  9801. }
  9802. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9803. var geometries = new WeakMap();
  9804. var wireframeAttributes = new WeakMap();
  9805. function onGeometryDispose(event) {
  9806. var geometry = event.target;
  9807. var buffergeometry = geometries.get(geometry);
  9808. if (buffergeometry.index !== null) {
  9809. attributes.remove(buffergeometry.index);
  9810. }
  9811. for (var name in buffergeometry.attributes) {
  9812. attributes.remove(buffergeometry.attributes[name]);
  9813. }
  9814. geometry.removeEventListener('dispose', onGeometryDispose);
  9815. geometries.delete(geometry);
  9816. var attribute = wireframeAttributes.get(buffergeometry);
  9817. if (attribute) {
  9818. attributes.remove(attribute);
  9819. wireframeAttributes.delete(buffergeometry);
  9820. }
  9821. bindingStates.releaseStatesOfGeometry(buffergeometry);
  9822. if (geometry.isInstancedBufferGeometry === true) {
  9823. delete geometry._maxInstanceCount;
  9824. } //
  9825. info.memory.geometries--;
  9826. }
  9827. function get(object, geometry) {
  9828. var buffergeometry = geometries.get(geometry);
  9829. if (buffergeometry) return buffergeometry;
  9830. geometry.addEventListener('dispose', onGeometryDispose);
  9831. if (geometry.isBufferGeometry) {
  9832. buffergeometry = geometry;
  9833. } else if (geometry.isGeometry) {
  9834. if (geometry._bufferGeometry === undefined) {
  9835. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9836. }
  9837. buffergeometry = geometry._bufferGeometry;
  9838. }
  9839. geometries.set(geometry, buffergeometry);
  9840. info.memory.geometries++;
  9841. return buffergeometry;
  9842. }
  9843. function update(geometry) {
  9844. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9845. for (var name in geometryAttributes) {
  9846. attributes.update(geometryAttributes[name], 34962);
  9847. } // morph targets
  9848. var morphAttributes = geometry.morphAttributes;
  9849. for (var _name in morphAttributes) {
  9850. var array = morphAttributes[_name];
  9851. for (var i = 0, l = array.length; i < l; i++) {
  9852. attributes.update(array[i], 34962);
  9853. }
  9854. }
  9855. }
  9856. function updateWireframeAttribute(geometry) {
  9857. var indices = [];
  9858. var geometryIndex = geometry.index;
  9859. var geometryPosition = geometry.attributes.position;
  9860. var version = 0;
  9861. if (geometryIndex !== null) {
  9862. var array = geometryIndex.array;
  9863. version = geometryIndex.version;
  9864. for (var i = 0, l = array.length; i < l; i += 3) {
  9865. var a = array[i + 0];
  9866. var b = array[i + 1];
  9867. var c = array[i + 2];
  9868. indices.push(a, b, b, c, c, a);
  9869. }
  9870. } else {
  9871. var _array = geometryPosition.array;
  9872. version = geometryPosition.version;
  9873. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9874. var _a = _i + 0;
  9875. var _b = _i + 1;
  9876. var _c = _i + 2;
  9877. indices.push(_a, _b, _b, _c, _c, _a);
  9878. }
  9879. }
  9880. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9881. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9882. //
  9883. var previousAttribute = wireframeAttributes.get(geometry);
  9884. if (previousAttribute) attributes.remove(previousAttribute); //
  9885. wireframeAttributes.set(geometry, attribute);
  9886. }
  9887. function getWireframeAttribute(geometry) {
  9888. var currentAttribute = wireframeAttributes.get(geometry);
  9889. if (currentAttribute) {
  9890. var geometryIndex = geometry.index;
  9891. if (geometryIndex !== null) {
  9892. // if the attribute is obsolete, create a new one
  9893. if (currentAttribute.version < geometryIndex.version) {
  9894. updateWireframeAttribute(geometry);
  9895. }
  9896. }
  9897. } else {
  9898. updateWireframeAttribute(geometry);
  9899. }
  9900. return wireframeAttributes.get(geometry);
  9901. }
  9902. return {
  9903. get: get,
  9904. update: update,
  9905. getWireframeAttribute: getWireframeAttribute
  9906. };
  9907. }
  9908. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9909. var isWebGL2 = capabilities.isWebGL2;
  9910. var mode;
  9911. function setMode(value) {
  9912. mode = value;
  9913. }
  9914. var type, bytesPerElement;
  9915. function setIndex(value) {
  9916. type = value.type;
  9917. bytesPerElement = value.bytesPerElement;
  9918. }
  9919. function render(start, count) {
  9920. gl.drawElements(mode, count, type, start * bytesPerElement);
  9921. info.update(count, mode, 1);
  9922. }
  9923. function renderInstances(start, count, primcount) {
  9924. if (primcount === 0) return;
  9925. var extension, methodName;
  9926. if (isWebGL2) {
  9927. extension = gl;
  9928. methodName = 'drawElementsInstanced';
  9929. } else {
  9930. extension = extensions.get('ANGLE_instanced_arrays');
  9931. methodName = 'drawElementsInstancedANGLE';
  9932. if (extension === null) {
  9933. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9934. return;
  9935. }
  9936. }
  9937. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9938. info.update(count, mode, primcount);
  9939. } //
  9940. this.setMode = setMode;
  9941. this.setIndex = setIndex;
  9942. this.render = render;
  9943. this.renderInstances = renderInstances;
  9944. }
  9945. function WebGLInfo(gl) {
  9946. var memory = {
  9947. geometries: 0,
  9948. textures: 0
  9949. };
  9950. var render = {
  9951. frame: 0,
  9952. calls: 0,
  9953. triangles: 0,
  9954. points: 0,
  9955. lines: 0
  9956. };
  9957. function update(count, mode, instanceCount) {
  9958. render.calls++;
  9959. switch (mode) {
  9960. case 4:
  9961. render.triangles += instanceCount * (count / 3);
  9962. break;
  9963. case 1:
  9964. render.lines += instanceCount * (count / 2);
  9965. break;
  9966. case 3:
  9967. render.lines += instanceCount * (count - 1);
  9968. break;
  9969. case 2:
  9970. render.lines += instanceCount * count;
  9971. break;
  9972. case 0:
  9973. render.points += instanceCount * count;
  9974. break;
  9975. default:
  9976. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9977. break;
  9978. }
  9979. }
  9980. function reset() {
  9981. render.frame++;
  9982. render.calls = 0;
  9983. render.triangles = 0;
  9984. render.points = 0;
  9985. render.lines = 0;
  9986. }
  9987. return {
  9988. memory: memory,
  9989. render: render,
  9990. programs: null,
  9991. autoReset: true,
  9992. reset: reset,
  9993. update: update
  9994. };
  9995. }
  9996. function numericalSort(a, b) {
  9997. return a[0] - b[0];
  9998. }
  9999. function absNumericalSort(a, b) {
  10000. return Math.abs(b[1]) - Math.abs(a[1]);
  10001. }
  10002. function WebGLMorphtargets(gl) {
  10003. var influencesList = {};
  10004. var morphInfluences = new Float32Array(8);
  10005. var workInfluences = [];
  10006. for (var i = 0; i < 8; i++) {
  10007. workInfluences[i] = [i, 0];
  10008. }
  10009. function update(object, geometry, material, program) {
  10010. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10011. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10012. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10013. var influences = influencesList[geometry.id];
  10014. if (influences === undefined) {
  10015. // initialise list
  10016. influences = [];
  10017. for (var _i = 0; _i < length; _i++) {
  10018. influences[_i] = [_i, 0];
  10019. }
  10020. influencesList[geometry.id] = influences;
  10021. } // Collect influences
  10022. for (var _i2 = 0; _i2 < length; _i2++) {
  10023. var influence = influences[_i2];
  10024. influence[0] = _i2;
  10025. influence[1] = objectInfluences[_i2];
  10026. }
  10027. influences.sort(absNumericalSort);
  10028. for (var _i3 = 0; _i3 < 8; _i3++) {
  10029. if (_i3 < length && influences[_i3][1]) {
  10030. workInfluences[_i3][0] = influences[_i3][0];
  10031. workInfluences[_i3][1] = influences[_i3][1];
  10032. } else {
  10033. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10034. workInfluences[_i3][1] = 0;
  10035. }
  10036. }
  10037. workInfluences.sort(numericalSort);
  10038. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10039. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10040. var morphInfluencesSum = 0;
  10041. for (var _i4 = 0; _i4 < 8; _i4++) {
  10042. var _influence = workInfluences[_i4];
  10043. var index = _influence[0];
  10044. var value = _influence[1];
  10045. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10046. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10047. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10048. }
  10049. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10050. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10051. }
  10052. morphInfluences[_i4] = value;
  10053. morphInfluencesSum += value;
  10054. } else {
  10055. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10056. geometry.deleteAttribute('morphTarget' + _i4);
  10057. }
  10058. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10059. geometry.deleteAttribute('morphNormal' + _i4);
  10060. }
  10061. morphInfluences[_i4] = 0;
  10062. }
  10063. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10064. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10065. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10066. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10067. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10068. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10069. }
  10070. return {
  10071. update: update
  10072. };
  10073. }
  10074. function WebGLObjects(gl, geometries, attributes, info) {
  10075. var updateMap = new WeakMap();
  10076. function update(object) {
  10077. var frame = info.render.frame;
  10078. var geometry = object.geometry;
  10079. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10080. if (updateMap.get(buffergeometry) !== frame) {
  10081. if (geometry.isGeometry) {
  10082. buffergeometry.updateFromObject(object);
  10083. }
  10084. geometries.update(buffergeometry);
  10085. updateMap.set(buffergeometry, frame);
  10086. }
  10087. if (object.isInstancedMesh) {
  10088. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10089. object.addEventListener('dispose', onInstancedMeshDispose);
  10090. }
  10091. attributes.update(object.instanceMatrix, 34962);
  10092. if (object.instanceColor !== null) {
  10093. attributes.update(object.instanceColor, 34962);
  10094. }
  10095. }
  10096. return buffergeometry;
  10097. }
  10098. function dispose() {
  10099. updateMap = new WeakMap();
  10100. }
  10101. function onInstancedMeshDispose(event) {
  10102. var instancedMesh = event.target;
  10103. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10104. attributes.remove(instancedMesh.instanceMatrix);
  10105. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10106. }
  10107. return {
  10108. update: update,
  10109. dispose: dispose
  10110. };
  10111. }
  10112. function DataTexture2DArray(data, width, height, depth) {
  10113. if (data === void 0) {
  10114. data = null;
  10115. }
  10116. if (width === void 0) {
  10117. width = 1;
  10118. }
  10119. if (height === void 0) {
  10120. height = 1;
  10121. }
  10122. if (depth === void 0) {
  10123. depth = 1;
  10124. }
  10125. Texture.call(this, null);
  10126. this.image = {
  10127. data: data,
  10128. width: width,
  10129. height: height,
  10130. depth: depth
  10131. };
  10132. this.magFilter = NearestFilter;
  10133. this.minFilter = NearestFilter;
  10134. this.wrapR = ClampToEdgeWrapping;
  10135. this.generateMipmaps = false;
  10136. this.flipY = false;
  10137. this.needsUpdate = true;
  10138. }
  10139. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10140. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10141. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10142. function DataTexture3D(data, width, height, depth) {
  10143. if (data === void 0) {
  10144. data = null;
  10145. }
  10146. if (width === void 0) {
  10147. width = 1;
  10148. }
  10149. if (height === void 0) {
  10150. height = 1;
  10151. }
  10152. if (depth === void 0) {
  10153. depth = 1;
  10154. }
  10155. // We're going to add .setXXX() methods for setting properties later.
  10156. // Users can still set in DataTexture3D directly.
  10157. //
  10158. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10159. // texture.anisotropy = 16;
  10160. //
  10161. // See #14839
  10162. Texture.call(this, null);
  10163. this.image = {
  10164. data: data,
  10165. width: width,
  10166. height: height,
  10167. depth: depth
  10168. };
  10169. this.magFilter = NearestFilter;
  10170. this.minFilter = NearestFilter;
  10171. this.wrapR = ClampToEdgeWrapping;
  10172. this.generateMipmaps = false;
  10173. this.flipY = false;
  10174. this.needsUpdate = true;
  10175. }
  10176. DataTexture3D.prototype = Object.create(Texture.prototype);
  10177. DataTexture3D.prototype.constructor = DataTexture3D;
  10178. DataTexture3D.prototype.isDataTexture3D = true;
  10179. /**
  10180. * Uniforms of a program.
  10181. * Those form a tree structure with a special top-level container for the root,
  10182. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10183. *
  10184. *
  10185. * Properties of inner nodes including the top-level container:
  10186. *
  10187. * .seq - array of nested uniforms
  10188. * .map - nested uniforms by name
  10189. *
  10190. *
  10191. * Methods of all nodes except the top-level container:
  10192. *
  10193. * .setValue( gl, value, [textures] )
  10194. *
  10195. * uploads a uniform value(s)
  10196. * the 'textures' parameter is needed for sampler uniforms
  10197. *
  10198. *
  10199. * Static methods of the top-level container (textures factorizations):
  10200. *
  10201. * .upload( gl, seq, values, textures )
  10202. *
  10203. * sets uniforms in 'seq' to 'values[id].value'
  10204. *
  10205. * .seqWithValue( seq, values ) : filteredSeq
  10206. *
  10207. * filters 'seq' entries with corresponding entry in values
  10208. *
  10209. *
  10210. * Methods of the top-level container (textures factorizations):
  10211. *
  10212. * .setValue( gl, name, value, textures )
  10213. *
  10214. * sets uniform with name 'name' to 'value'
  10215. *
  10216. * .setOptional( gl, obj, prop )
  10217. *
  10218. * like .set for an optional property of the object
  10219. *
  10220. */
  10221. var emptyTexture = new Texture();
  10222. var emptyTexture2dArray = new DataTexture2DArray();
  10223. var emptyTexture3d = new DataTexture3D();
  10224. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10225. // Array Caches (provide typed arrays for temporary by size)
  10226. var arrayCacheF32 = [];
  10227. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10228. var mat4array = new Float32Array(16);
  10229. var mat3array = new Float32Array(9);
  10230. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10231. function flatten(array, nBlocks, blockSize) {
  10232. var firstElem = array[0];
  10233. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10234. // see http://jacksondunstan.com/articles/983
  10235. var n = nBlocks * blockSize;
  10236. var r = arrayCacheF32[n];
  10237. if (r === undefined) {
  10238. r = new Float32Array(n);
  10239. arrayCacheF32[n] = r;
  10240. }
  10241. if (nBlocks !== 0) {
  10242. firstElem.toArray(r, 0);
  10243. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10244. offset += blockSize;
  10245. array[i].toArray(r, offset);
  10246. }
  10247. }
  10248. return r;
  10249. }
  10250. function arraysEqual(a, b) {
  10251. if (a.length !== b.length) return false;
  10252. for (var i = 0, l = a.length; i < l; i++) {
  10253. if (a[i] !== b[i]) return false;
  10254. }
  10255. return true;
  10256. }
  10257. function copyArray(a, b) {
  10258. for (var i = 0, l = b.length; i < l; i++) {
  10259. a[i] = b[i];
  10260. }
  10261. } // Texture unit allocation
  10262. function allocTexUnits(textures, n) {
  10263. var r = arrayCacheI32[n];
  10264. if (r === undefined) {
  10265. r = new Int32Array(n);
  10266. arrayCacheI32[n] = r;
  10267. }
  10268. for (var i = 0; i !== n; ++i) {
  10269. r[i] = textures.allocateTextureUnit();
  10270. }
  10271. return r;
  10272. } // --- Setters ---
  10273. // Note: Defining these methods externally, because they come in a bunch
  10274. // and this way their names minify.
  10275. // Single scalar
  10276. function setValueV1f(gl, v) {
  10277. var cache = this.cache;
  10278. if (cache[0] === v) return;
  10279. gl.uniform1f(this.addr, v);
  10280. cache[0] = v;
  10281. } // Single float vector (from flat array or THREE.VectorN)
  10282. function setValueV2f(gl, v) {
  10283. var cache = this.cache;
  10284. if (v.x !== undefined) {
  10285. if (cache[0] !== v.x || cache[1] !== v.y) {
  10286. gl.uniform2f(this.addr, v.x, v.y);
  10287. cache[0] = v.x;
  10288. cache[1] = v.y;
  10289. }
  10290. } else {
  10291. if (arraysEqual(cache, v)) return;
  10292. gl.uniform2fv(this.addr, v);
  10293. copyArray(cache, v);
  10294. }
  10295. }
  10296. function setValueV3f(gl, v) {
  10297. var cache = this.cache;
  10298. if (v.x !== undefined) {
  10299. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10300. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10301. cache[0] = v.x;
  10302. cache[1] = v.y;
  10303. cache[2] = v.z;
  10304. }
  10305. } else if (v.r !== undefined) {
  10306. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10307. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10308. cache[0] = v.r;
  10309. cache[1] = v.g;
  10310. cache[2] = v.b;
  10311. }
  10312. } else {
  10313. if (arraysEqual(cache, v)) return;
  10314. gl.uniform3fv(this.addr, v);
  10315. copyArray(cache, v);
  10316. }
  10317. }
  10318. function setValueV4f(gl, v) {
  10319. var cache = this.cache;
  10320. if (v.x !== undefined) {
  10321. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10322. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10323. cache[0] = v.x;
  10324. cache[1] = v.y;
  10325. cache[2] = v.z;
  10326. cache[3] = v.w;
  10327. }
  10328. } else {
  10329. if (arraysEqual(cache, v)) return;
  10330. gl.uniform4fv(this.addr, v);
  10331. copyArray(cache, v);
  10332. }
  10333. } // Single matrix (from flat array or MatrixN)
  10334. function setValueM2(gl, v) {
  10335. var cache = this.cache;
  10336. var elements = v.elements;
  10337. if (elements === undefined) {
  10338. if (arraysEqual(cache, v)) return;
  10339. gl.uniformMatrix2fv(this.addr, false, v);
  10340. copyArray(cache, v);
  10341. } else {
  10342. if (arraysEqual(cache, elements)) return;
  10343. mat2array.set(elements);
  10344. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10345. copyArray(cache, elements);
  10346. }
  10347. }
  10348. function setValueM3(gl, v) {
  10349. var cache = this.cache;
  10350. var elements = v.elements;
  10351. if (elements === undefined) {
  10352. if (arraysEqual(cache, v)) return;
  10353. gl.uniformMatrix3fv(this.addr, false, v);
  10354. copyArray(cache, v);
  10355. } else {
  10356. if (arraysEqual(cache, elements)) return;
  10357. mat3array.set(elements);
  10358. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10359. copyArray(cache, elements);
  10360. }
  10361. }
  10362. function setValueM4(gl, v) {
  10363. var cache = this.cache;
  10364. var elements = v.elements;
  10365. if (elements === undefined) {
  10366. if (arraysEqual(cache, v)) return;
  10367. gl.uniformMatrix4fv(this.addr, false, v);
  10368. copyArray(cache, v);
  10369. } else {
  10370. if (arraysEqual(cache, elements)) return;
  10371. mat4array.set(elements);
  10372. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10373. copyArray(cache, elements);
  10374. }
  10375. } // Single texture (2D / Cube)
  10376. function setValueT1(gl, v, textures) {
  10377. var cache = this.cache;
  10378. var unit = textures.allocateTextureUnit();
  10379. if (cache[0] !== unit) {
  10380. gl.uniform1i(this.addr, unit);
  10381. cache[0] = unit;
  10382. }
  10383. textures.safeSetTexture2D(v || emptyTexture, unit);
  10384. }
  10385. function setValueT2DArray1(gl, v, textures) {
  10386. var cache = this.cache;
  10387. var unit = textures.allocateTextureUnit();
  10388. if (cache[0] !== unit) {
  10389. gl.uniform1i(this.addr, unit);
  10390. cache[0] = unit;
  10391. }
  10392. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10393. }
  10394. function setValueT3D1(gl, v, textures) {
  10395. var cache = this.cache;
  10396. var unit = textures.allocateTextureUnit();
  10397. if (cache[0] !== unit) {
  10398. gl.uniform1i(this.addr, unit);
  10399. cache[0] = unit;
  10400. }
  10401. textures.setTexture3D(v || emptyTexture3d, unit);
  10402. }
  10403. function setValueT6(gl, v, textures) {
  10404. var cache = this.cache;
  10405. var unit = textures.allocateTextureUnit();
  10406. if (cache[0] !== unit) {
  10407. gl.uniform1i(this.addr, unit);
  10408. cache[0] = unit;
  10409. }
  10410. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10411. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10412. function setValueV1i(gl, v) {
  10413. var cache = this.cache;
  10414. if (cache[0] === v) return;
  10415. gl.uniform1i(this.addr, v);
  10416. cache[0] = v;
  10417. }
  10418. function setValueV2i(gl, v) {
  10419. var cache = this.cache;
  10420. if (arraysEqual(cache, v)) return;
  10421. gl.uniform2iv(this.addr, v);
  10422. copyArray(cache, v);
  10423. }
  10424. function setValueV3i(gl, v) {
  10425. var cache = this.cache;
  10426. if (arraysEqual(cache, v)) return;
  10427. gl.uniform3iv(this.addr, v);
  10428. copyArray(cache, v);
  10429. }
  10430. function setValueV4i(gl, v) {
  10431. var cache = this.cache;
  10432. if (arraysEqual(cache, v)) return;
  10433. gl.uniform4iv(this.addr, v);
  10434. copyArray(cache, v);
  10435. } // uint
  10436. function setValueV1ui(gl, v) {
  10437. var cache = this.cache;
  10438. if (cache[0] === v) return;
  10439. gl.uniform1ui(this.addr, v);
  10440. cache[0] = v;
  10441. } // Helper to pick the right setter for the singular case
  10442. function getSingularSetter(type) {
  10443. switch (type) {
  10444. case 0x1406:
  10445. return setValueV1f;
  10446. // FLOAT
  10447. case 0x8b50:
  10448. return setValueV2f;
  10449. // _VEC2
  10450. case 0x8b51:
  10451. return setValueV3f;
  10452. // _VEC3
  10453. case 0x8b52:
  10454. return setValueV4f;
  10455. // _VEC4
  10456. case 0x8b5a:
  10457. return setValueM2;
  10458. // _MAT2
  10459. case 0x8b5b:
  10460. return setValueM3;
  10461. // _MAT3
  10462. case 0x8b5c:
  10463. return setValueM4;
  10464. // _MAT4
  10465. case 0x1404:
  10466. case 0x8b56:
  10467. return setValueV1i;
  10468. // INT, BOOL
  10469. case 0x8b53:
  10470. case 0x8b57:
  10471. return setValueV2i;
  10472. // _VEC2
  10473. case 0x8b54:
  10474. case 0x8b58:
  10475. return setValueV3i;
  10476. // _VEC3
  10477. case 0x8b55:
  10478. case 0x8b59:
  10479. return setValueV4i;
  10480. // _VEC4
  10481. case 0x1405:
  10482. return setValueV1ui;
  10483. // UINT
  10484. case 0x8b5e: // SAMPLER_2D
  10485. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10486. case 0x8dca: // INT_SAMPLER_2D
  10487. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10488. case 0x8b62:
  10489. // SAMPLER_2D_SHADOW
  10490. return setValueT1;
  10491. case 0x8b5f: // SAMPLER_3D
  10492. case 0x8dcb: // INT_SAMPLER_3D
  10493. case 0x8dd3:
  10494. // UNSIGNED_INT_SAMPLER_3D
  10495. return setValueT3D1;
  10496. case 0x8b60: // SAMPLER_CUBE
  10497. case 0x8dcc: // INT_SAMPLER_CUBE
  10498. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10499. case 0x8dc5:
  10500. // SAMPLER_CUBE_SHADOW
  10501. return setValueT6;
  10502. case 0x8dc1: // SAMPLER_2D_ARRAY
  10503. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10504. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10505. case 0x8dc4:
  10506. // SAMPLER_2D_ARRAY_SHADOW
  10507. return setValueT2DArray1;
  10508. }
  10509. } // Array of scalars
  10510. function setValueV1fArray(gl, v) {
  10511. gl.uniform1fv(this.addr, v);
  10512. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10513. function setValueV1iArray(gl, v) {
  10514. gl.uniform1iv(this.addr, v);
  10515. }
  10516. function setValueV2iArray(gl, v) {
  10517. gl.uniform2iv(this.addr, v);
  10518. }
  10519. function setValueV3iArray(gl, v) {
  10520. gl.uniform3iv(this.addr, v);
  10521. }
  10522. function setValueV4iArray(gl, v) {
  10523. gl.uniform4iv(this.addr, v);
  10524. } // Array of vectors (flat or from THREE classes)
  10525. function setValueV2fArray(gl, v) {
  10526. var data = flatten(v, this.size, 2);
  10527. gl.uniform2fv(this.addr, data);
  10528. }
  10529. function setValueV3fArray(gl, v) {
  10530. var data = flatten(v, this.size, 3);
  10531. gl.uniform3fv(this.addr, data);
  10532. }
  10533. function setValueV4fArray(gl, v) {
  10534. var data = flatten(v, this.size, 4);
  10535. gl.uniform4fv(this.addr, data);
  10536. } // Array of matrices (flat or from THREE clases)
  10537. function setValueM2Array(gl, v) {
  10538. var data = flatten(v, this.size, 4);
  10539. gl.uniformMatrix2fv(this.addr, false, data);
  10540. }
  10541. function setValueM3Array(gl, v) {
  10542. var data = flatten(v, this.size, 9);
  10543. gl.uniformMatrix3fv(this.addr, false, data);
  10544. }
  10545. function setValueM4Array(gl, v) {
  10546. var data = flatten(v, this.size, 16);
  10547. gl.uniformMatrix4fv(this.addr, false, data);
  10548. } // Array of textures (2D / Cube)
  10549. function setValueT1Array(gl, v, textures) {
  10550. var n = v.length;
  10551. var units = allocTexUnits(textures, n);
  10552. gl.uniform1iv(this.addr, units);
  10553. for (var i = 0; i !== n; ++i) {
  10554. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10555. }
  10556. }
  10557. function setValueT6Array(gl, v, textures) {
  10558. var n = v.length;
  10559. var units = allocTexUnits(textures, n);
  10560. gl.uniform1iv(this.addr, units);
  10561. for (var i = 0; i !== n; ++i) {
  10562. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10563. }
  10564. } // Helper to pick the right setter for a pure (bottom-level) array
  10565. function getPureArraySetter(type) {
  10566. switch (type) {
  10567. case 0x1406:
  10568. return setValueV1fArray;
  10569. // FLOAT
  10570. case 0x8b50:
  10571. return setValueV2fArray;
  10572. // _VEC2
  10573. case 0x8b51:
  10574. return setValueV3fArray;
  10575. // _VEC3
  10576. case 0x8b52:
  10577. return setValueV4fArray;
  10578. // _VEC4
  10579. case 0x8b5a:
  10580. return setValueM2Array;
  10581. // _MAT2
  10582. case 0x8b5b:
  10583. return setValueM3Array;
  10584. // _MAT3
  10585. case 0x8b5c:
  10586. return setValueM4Array;
  10587. // _MAT4
  10588. case 0x1404:
  10589. case 0x8b56:
  10590. return setValueV1iArray;
  10591. // INT, BOOL
  10592. case 0x8b53:
  10593. case 0x8b57:
  10594. return setValueV2iArray;
  10595. // _VEC2
  10596. case 0x8b54:
  10597. case 0x8b58:
  10598. return setValueV3iArray;
  10599. // _VEC3
  10600. case 0x8b55:
  10601. case 0x8b59:
  10602. return setValueV4iArray;
  10603. // _VEC4
  10604. case 0x8b5e: // SAMPLER_2D
  10605. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10606. case 0x8dca: // INT_SAMPLER_2D
  10607. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10608. case 0x8b62:
  10609. // SAMPLER_2D_SHADOW
  10610. return setValueT1Array;
  10611. case 0x8b60: // SAMPLER_CUBE
  10612. case 0x8dcc: // INT_SAMPLER_CUBE
  10613. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10614. case 0x8dc5:
  10615. // SAMPLER_CUBE_SHADOW
  10616. return setValueT6Array;
  10617. }
  10618. } // --- Uniform Classes ---
  10619. function SingleUniform(id, activeInfo, addr) {
  10620. this.id = id;
  10621. this.addr = addr;
  10622. this.cache = [];
  10623. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10624. }
  10625. function PureArrayUniform(id, activeInfo, addr) {
  10626. this.id = id;
  10627. this.addr = addr;
  10628. this.cache = [];
  10629. this.size = activeInfo.size;
  10630. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10631. }
  10632. PureArrayUniform.prototype.updateCache = function (data) {
  10633. var cache = this.cache;
  10634. if (data instanceof Float32Array && cache.length !== data.length) {
  10635. this.cache = new Float32Array(data.length);
  10636. }
  10637. copyArray(cache, data);
  10638. };
  10639. function StructuredUniform(id) {
  10640. this.id = id;
  10641. this.seq = [];
  10642. this.map = {};
  10643. }
  10644. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10645. var seq = this.seq;
  10646. for (var i = 0, n = seq.length; i !== n; ++i) {
  10647. var u = seq[i];
  10648. u.setValue(gl, value[u.id], textures);
  10649. }
  10650. }; // --- Top-level ---
  10651. // Parser - builds up the property tree from the path strings
  10652. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  10653. // - the identifier (member name or array index)
  10654. // - followed by an optional right bracket (found when array index)
  10655. // - followed by an optional left bracket or dot (type of subscript)
  10656. //
  10657. // Note: These portions can be read in a non-overlapping fashion and
  10658. // allow straightforward parsing of the hierarchy that WebGL encodes
  10659. // in the uniform names.
  10660. function addUniform(container, uniformObject) {
  10661. container.seq.push(uniformObject);
  10662. container.map[uniformObject.id] = uniformObject;
  10663. }
  10664. function parseUniform(activeInfo, addr, container) {
  10665. var path = activeInfo.name,
  10666. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10667. RePathPart.lastIndex = 0;
  10668. while (true) {
  10669. var match = RePathPart.exec(path),
  10670. matchEnd = RePathPart.lastIndex;
  10671. var id = match[1];
  10672. var idIsIndex = match[2] === ']',
  10673. subscript = match[3];
  10674. if (idIsIndex) id = id | 0; // convert to integer
  10675. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10676. // bare name or "pure" bottom-level array "[0]" suffix
  10677. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10678. break;
  10679. } else {
  10680. // step into inner node / create it in case it doesn't exist
  10681. var map = container.map;
  10682. var next = map[id];
  10683. if (next === undefined) {
  10684. next = new StructuredUniform(id);
  10685. addUniform(container, next);
  10686. }
  10687. container = next;
  10688. }
  10689. }
  10690. } // Root Container
  10691. function WebGLUniforms(gl, program) {
  10692. this.seq = [];
  10693. this.map = {};
  10694. var n = gl.getProgramParameter(program, 35718);
  10695. for (var i = 0; i < n; ++i) {
  10696. var info = gl.getActiveUniform(program, i),
  10697. addr = gl.getUniformLocation(program, info.name);
  10698. parseUniform(info, addr, this);
  10699. }
  10700. }
  10701. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10702. var u = this.map[name];
  10703. if (u !== undefined) u.setValue(gl, value, textures);
  10704. };
  10705. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10706. var v = object[name];
  10707. if (v !== undefined) this.setValue(gl, name, v);
  10708. }; // Static interface
  10709. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10710. for (var i = 0, n = seq.length; i !== n; ++i) {
  10711. var u = seq[i],
  10712. v = values[u.id];
  10713. if (v.needsUpdate !== false) {
  10714. // note: always updating when .needsUpdate is undefined
  10715. u.setValue(gl, v.value, textures);
  10716. }
  10717. }
  10718. };
  10719. WebGLUniforms.seqWithValue = function (seq, values) {
  10720. var r = [];
  10721. for (var i = 0, n = seq.length; i !== n; ++i) {
  10722. var u = seq[i];
  10723. if (u.id in values) r.push(u);
  10724. }
  10725. return r;
  10726. };
  10727. function WebGLShader(gl, type, string) {
  10728. var shader = gl.createShader(type);
  10729. gl.shaderSource(shader, string);
  10730. gl.compileShader(shader);
  10731. return shader;
  10732. }
  10733. var programIdCount = 0;
  10734. function addLineNumbers(string) {
  10735. var lines = string.split('\n');
  10736. for (var i = 0; i < lines.length; i++) {
  10737. lines[i] = i + 1 + ': ' + lines[i];
  10738. }
  10739. return lines.join('\n');
  10740. }
  10741. function getEncodingComponents(encoding) {
  10742. switch (encoding) {
  10743. case LinearEncoding:
  10744. return ['Linear', '( value )'];
  10745. case sRGBEncoding:
  10746. return ['sRGB', '( value )'];
  10747. case RGBEEncoding:
  10748. return ['RGBE', '( value )'];
  10749. case RGBM7Encoding:
  10750. return ['RGBM', '( value, 7.0 )'];
  10751. case RGBM16Encoding:
  10752. return ['RGBM', '( value, 16.0 )'];
  10753. case RGBDEncoding:
  10754. return ['RGBD', '( value, 256.0 )'];
  10755. case GammaEncoding:
  10756. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10757. case LogLuvEncoding:
  10758. return ['LogLuv', '( value )'];
  10759. default:
  10760. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10761. return ['Linear', '( value )'];
  10762. }
  10763. }
  10764. function getShaderErrors(gl, shader, type) {
  10765. var status = gl.getShaderParameter(shader, 35713);
  10766. var log = gl.getShaderInfoLog(shader).trim();
  10767. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10768. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10769. var source = gl.getShaderSource(shader);
  10770. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10771. }
  10772. function getTexelDecodingFunction(functionName, encoding) {
  10773. var components = getEncodingComponents(encoding);
  10774. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10775. }
  10776. function getTexelEncodingFunction(functionName, encoding) {
  10777. var components = getEncodingComponents(encoding);
  10778. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10779. }
  10780. function getToneMappingFunction(functionName, toneMapping) {
  10781. var toneMappingName;
  10782. switch (toneMapping) {
  10783. case LinearToneMapping:
  10784. toneMappingName = 'Linear';
  10785. break;
  10786. case ReinhardToneMapping:
  10787. toneMappingName = 'Reinhard';
  10788. break;
  10789. case CineonToneMapping:
  10790. toneMappingName = 'OptimizedCineon';
  10791. break;
  10792. case ACESFilmicToneMapping:
  10793. toneMappingName = 'ACESFilmic';
  10794. break;
  10795. case CustomToneMapping:
  10796. toneMappingName = 'Custom';
  10797. break;
  10798. default:
  10799. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10800. toneMappingName = 'Linear';
  10801. }
  10802. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10803. }
  10804. function generateExtensions(parameters) {
  10805. 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' : ''];
  10806. return chunks.filter(filterEmptyLine).join('\n');
  10807. }
  10808. function generateDefines(defines) {
  10809. var chunks = [];
  10810. for (var name in defines) {
  10811. var value = defines[name];
  10812. if (value === false) continue;
  10813. chunks.push('#define ' + name + ' ' + value);
  10814. }
  10815. return chunks.join('\n');
  10816. }
  10817. function fetchAttributeLocations(gl, program) {
  10818. var attributes = {};
  10819. var n = gl.getProgramParameter(program, 35721);
  10820. for (var i = 0; i < n; i++) {
  10821. var info = gl.getActiveAttrib(program, i);
  10822. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10823. attributes[name] = gl.getAttribLocation(program, name);
  10824. }
  10825. return attributes;
  10826. }
  10827. function filterEmptyLine(string) {
  10828. return string !== '';
  10829. }
  10830. function replaceLightNums(string, parameters) {
  10831. 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);
  10832. }
  10833. function replaceClippingPlaneNums(string, parameters) {
  10834. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10835. } // Resolve Includes
  10836. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10837. function resolveIncludes(string) {
  10838. return string.replace(includePattern, includeReplacer);
  10839. }
  10840. function includeReplacer(match, include) {
  10841. var string = ShaderChunk[include];
  10842. if (string === undefined) {
  10843. throw new Error('Can not resolve #include <' + include + '>');
  10844. }
  10845. return resolveIncludes(string);
  10846. } // Unroll Loops
  10847. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10848. 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;
  10849. function unrollLoops(string) {
  10850. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10851. }
  10852. function deprecatedLoopReplacer(match, start, end, snippet) {
  10853. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10854. return loopReplacer(match, start, end, snippet);
  10855. }
  10856. function loopReplacer(match, start, end, snippet) {
  10857. var string = '';
  10858. for (var i = parseInt(start); i < parseInt(end); i++) {
  10859. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10860. }
  10861. return string;
  10862. } //
  10863. function generatePrecision(parameters) {
  10864. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  10865. if (parameters.precision === 'highp') {
  10866. precisionstring += '\n#define HIGH_PRECISION';
  10867. } else if (parameters.precision === 'mediump') {
  10868. precisionstring += '\n#define MEDIUM_PRECISION';
  10869. } else if (parameters.precision === 'lowp') {
  10870. precisionstring += '\n#define LOW_PRECISION';
  10871. }
  10872. return precisionstring;
  10873. }
  10874. function generateShadowMapTypeDefine(parameters) {
  10875. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10876. if (parameters.shadowMapType === PCFShadowMap) {
  10877. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10878. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10879. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10880. } else if (parameters.shadowMapType === VSMShadowMap) {
  10881. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10882. }
  10883. return shadowMapTypeDefine;
  10884. }
  10885. function generateEnvMapTypeDefine(parameters) {
  10886. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10887. if (parameters.envMap) {
  10888. switch (parameters.envMapMode) {
  10889. case CubeReflectionMapping:
  10890. case CubeRefractionMapping:
  10891. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10892. break;
  10893. case CubeUVReflectionMapping:
  10894. case CubeUVRefractionMapping:
  10895. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10896. break;
  10897. }
  10898. }
  10899. return envMapTypeDefine;
  10900. }
  10901. function generateEnvMapModeDefine(parameters) {
  10902. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10903. if (parameters.envMap) {
  10904. switch (parameters.envMapMode) {
  10905. case CubeRefractionMapping:
  10906. case CubeUVRefractionMapping:
  10907. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10908. break;
  10909. }
  10910. }
  10911. return envMapModeDefine;
  10912. }
  10913. function generateEnvMapBlendingDefine(parameters) {
  10914. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10915. if (parameters.envMap) {
  10916. switch (parameters.combine) {
  10917. case MultiplyOperation:
  10918. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10919. break;
  10920. case MixOperation:
  10921. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10922. break;
  10923. case AddOperation:
  10924. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10925. break;
  10926. }
  10927. }
  10928. return envMapBlendingDefine;
  10929. }
  10930. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10931. var gl = renderer.getContext();
  10932. var defines = parameters.defines;
  10933. var vertexShader = parameters.vertexShader;
  10934. var fragmentShader = parameters.fragmentShader;
  10935. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10936. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10937. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10938. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10939. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10940. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10941. var customDefines = generateDefines(defines);
  10942. var program = gl.createProgram();
  10943. var prefixVertex, prefixFragment;
  10944. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  10945. if (parameters.isRawShaderMaterial) {
  10946. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10947. if (prefixVertex.length > 0) {
  10948. prefixVertex += '\n';
  10949. }
  10950. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10951. if (prefixFragment.length > 0) {
  10952. prefixFragment += '\n';
  10953. }
  10954. } else {
  10955. 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');
  10956. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10957. '#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
  10958. 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
  10959. 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');
  10960. }
  10961. vertexShader = resolveIncludes(vertexShader);
  10962. vertexShader = replaceLightNums(vertexShader, parameters);
  10963. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10964. fragmentShader = resolveIncludes(fragmentShader);
  10965. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10966. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10967. vertexShader = unrollLoops(vertexShader);
  10968. fragmentShader = unrollLoops(fragmentShader);
  10969. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10970. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10971. versionString = '#version 300 es\n';
  10972. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10973. 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;
  10974. }
  10975. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10976. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10977. // console.log( '*FRAGMENT*', fragmentGlsl );
  10978. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10979. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10980. gl.attachShader(program, glVertexShader);
  10981. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10982. if (parameters.index0AttributeName !== undefined) {
  10983. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10984. } else if (parameters.morphTargets === true) {
  10985. // programs with morphTargets displace position out of attribute 0
  10986. gl.bindAttribLocation(program, 0, 'position');
  10987. }
  10988. gl.linkProgram(program); // check for link errors
  10989. if (renderer.debug.checkShaderErrors) {
  10990. var programLog = gl.getProgramInfoLog(program).trim();
  10991. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10992. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10993. var runnable = true;
  10994. var haveDiagnostics = true;
  10995. if (gl.getProgramParameter(program, 35714) === false) {
  10996. runnable = false;
  10997. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10998. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10999. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11000. } else if (programLog !== '') {
  11001. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11002. } else if (vertexLog === '' || fragmentLog === '') {
  11003. haveDiagnostics = false;
  11004. }
  11005. if (haveDiagnostics) {
  11006. this.diagnostics = {
  11007. runnable: runnable,
  11008. programLog: programLog,
  11009. vertexShader: {
  11010. log: vertexLog,
  11011. prefix: prefixVertex
  11012. },
  11013. fragmentShader: {
  11014. log: fragmentLog,
  11015. prefix: prefixFragment
  11016. }
  11017. };
  11018. }
  11019. } // Clean up
  11020. // Crashes in iOS9 and iOS10. #18402
  11021. // gl.detachShader( program, glVertexShader );
  11022. // gl.detachShader( program, glFragmentShader );
  11023. gl.deleteShader(glVertexShader);
  11024. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11025. var cachedUniforms;
  11026. this.getUniforms = function () {
  11027. if (cachedUniforms === undefined) {
  11028. cachedUniforms = new WebGLUniforms(gl, program);
  11029. }
  11030. return cachedUniforms;
  11031. }; // set up caching for attribute locations
  11032. var cachedAttributes;
  11033. this.getAttributes = function () {
  11034. if (cachedAttributes === undefined) {
  11035. cachedAttributes = fetchAttributeLocations(gl, program);
  11036. }
  11037. return cachedAttributes;
  11038. }; // free resource
  11039. this.destroy = function () {
  11040. bindingStates.releaseStatesOfProgram(this);
  11041. gl.deleteProgram(program);
  11042. this.program = undefined;
  11043. }; //
  11044. this.name = parameters.shaderName;
  11045. this.id = programIdCount++;
  11046. this.cacheKey = cacheKey;
  11047. this.usedTimes = 1;
  11048. this.program = program;
  11049. this.vertexShader = glVertexShader;
  11050. this.fragmentShader = glFragmentShader;
  11051. return this;
  11052. }
  11053. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11054. var programs = [];
  11055. var isWebGL2 = capabilities.isWebGL2;
  11056. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11057. var floatVertexTextures = capabilities.floatVertexTextures;
  11058. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11059. var vertexTextures = capabilities.vertexTextures;
  11060. var precision = capabilities.precision;
  11061. var shaderIDs = {
  11062. MeshDepthMaterial: 'depth',
  11063. MeshDistanceMaterial: 'distanceRGBA',
  11064. MeshNormalMaterial: 'normal',
  11065. MeshBasicMaterial: 'basic',
  11066. MeshLambertMaterial: 'lambert',
  11067. MeshPhongMaterial: 'phong',
  11068. MeshToonMaterial: 'toon',
  11069. MeshStandardMaterial: 'physical',
  11070. MeshPhysicalMaterial: 'physical',
  11071. MeshMatcapMaterial: 'matcap',
  11072. LineBasicMaterial: 'basic',
  11073. LineDashedMaterial: 'dashed',
  11074. PointsMaterial: 'points',
  11075. ShadowMaterial: 'shadow',
  11076. SpriteMaterial: 'sprite'
  11077. };
  11078. 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'];
  11079. function getMaxBones(object) {
  11080. var skeleton = object.skeleton;
  11081. var bones = skeleton.bones;
  11082. if (floatVertexTextures) {
  11083. return 1024;
  11084. } else {
  11085. // default for when object is not specified
  11086. // ( for example when prebuilding shader to be used with multiple objects )
  11087. //
  11088. // - leave some extra space for other uniforms
  11089. // - limit here is ANGLE's 254 max uniform vectors
  11090. // (up to 54 should be safe)
  11091. var nVertexUniforms = maxVertexUniforms;
  11092. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11093. var maxBones = Math.min(nVertexMatrices, bones.length);
  11094. if (maxBones < bones.length) {
  11095. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11096. return 0;
  11097. }
  11098. return maxBones;
  11099. }
  11100. }
  11101. function getTextureEncodingFromMap(map) {
  11102. var encoding;
  11103. if (map && map.isTexture) {
  11104. encoding = map.encoding;
  11105. } else if (map && map.isWebGLRenderTarget) {
  11106. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11107. encoding = map.texture.encoding;
  11108. } else {
  11109. encoding = LinearEncoding;
  11110. }
  11111. return encoding;
  11112. }
  11113. function getParameters(material, lights, shadows, scene, object) {
  11114. var fog = scene.fog;
  11115. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11116. var envMap = cubemaps.get(material.envMap || environment);
  11117. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11118. // (not to blow over maxLights budget)
  11119. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11120. if (material.precision !== null) {
  11121. precision = capabilities.getMaxPrecision(material.precision);
  11122. if (precision !== material.precision) {
  11123. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11124. }
  11125. }
  11126. var vertexShader, fragmentShader;
  11127. if (shaderID) {
  11128. var shader = ShaderLib[shaderID];
  11129. vertexShader = shader.vertexShader;
  11130. fragmentShader = shader.fragmentShader;
  11131. } else {
  11132. vertexShader = material.vertexShader;
  11133. fragmentShader = material.fragmentShader;
  11134. }
  11135. var currentRenderTarget = renderer.getRenderTarget();
  11136. var parameters = {
  11137. isWebGL2: isWebGL2,
  11138. shaderID: shaderID,
  11139. shaderName: material.type,
  11140. vertexShader: vertexShader,
  11141. fragmentShader: fragmentShader,
  11142. defines: material.defines,
  11143. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11144. glslVersion: material.glslVersion,
  11145. precision: precision,
  11146. instancing: object.isInstancedMesh === true,
  11147. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11148. supportsVertexTextures: vertexTextures,
  11149. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11150. map: !!material.map,
  11151. mapEncoding: getTextureEncodingFromMap(material.map),
  11152. matcap: !!material.matcap,
  11153. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11154. envMap: !!envMap,
  11155. envMapMode: envMap && envMap.mapping,
  11156. envMapEncoding: getTextureEncodingFromMap(envMap),
  11157. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11158. lightMap: !!material.lightMap,
  11159. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11160. aoMap: !!material.aoMap,
  11161. emissiveMap: !!material.emissiveMap,
  11162. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11163. bumpMap: !!material.bumpMap,
  11164. normalMap: !!material.normalMap,
  11165. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11166. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11167. clearcoatMap: !!material.clearcoatMap,
  11168. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11169. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11170. displacementMap: !!material.displacementMap,
  11171. roughnessMap: !!material.roughnessMap,
  11172. metalnessMap: !!material.metalnessMap,
  11173. specularMap: !!material.specularMap,
  11174. alphaMap: !!material.alphaMap,
  11175. gradientMap: !!material.gradientMap,
  11176. sheen: !!material.sheen,
  11177. transmissionMap: !!material.transmissionMap,
  11178. combine: material.combine,
  11179. vertexTangents: material.normalMap && material.vertexTangents,
  11180. vertexColors: material.vertexColors,
  11181. 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,
  11182. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11183. fog: !!fog,
  11184. useFog: material.fog,
  11185. fogExp2: fog && fog.isFogExp2,
  11186. flatShading: material.flatShading,
  11187. sizeAttenuation: material.sizeAttenuation,
  11188. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11189. skinning: material.skinning && maxBones > 0,
  11190. maxBones: maxBones,
  11191. useVertexTexture: floatVertexTextures,
  11192. morphTargets: material.morphTargets,
  11193. morphNormals: material.morphNormals,
  11194. maxMorphTargets: renderer.maxMorphTargets,
  11195. maxMorphNormals: renderer.maxMorphNormals,
  11196. numDirLights: lights.directional.length,
  11197. numPointLights: lights.point.length,
  11198. numSpotLights: lights.spot.length,
  11199. numRectAreaLights: lights.rectArea.length,
  11200. numHemiLights: lights.hemi.length,
  11201. numDirLightShadows: lights.directionalShadowMap.length,
  11202. numPointLightShadows: lights.pointShadowMap.length,
  11203. numSpotLightShadows: lights.spotShadowMap.length,
  11204. numClippingPlanes: clipping.numPlanes,
  11205. numClipIntersection: clipping.numIntersection,
  11206. dithering: material.dithering,
  11207. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11208. shadowMapType: renderer.shadowMap.type,
  11209. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11210. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11211. premultipliedAlpha: material.premultipliedAlpha,
  11212. alphaTest: material.alphaTest,
  11213. doubleSided: material.side === DoubleSide,
  11214. flipSided: material.side === BackSide,
  11215. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11216. index0AttributeName: material.index0AttributeName,
  11217. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11218. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11219. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11220. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11221. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11222. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11223. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11224. customProgramCacheKey: material.customProgramCacheKey()
  11225. };
  11226. return parameters;
  11227. }
  11228. function getProgramCacheKey(parameters) {
  11229. var array = [];
  11230. if (parameters.shaderID) {
  11231. array.push(parameters.shaderID);
  11232. } else {
  11233. array.push(parameters.fragmentShader);
  11234. array.push(parameters.vertexShader);
  11235. }
  11236. if (parameters.defines !== undefined) {
  11237. for (var name in parameters.defines) {
  11238. array.push(name);
  11239. array.push(parameters.defines[name]);
  11240. }
  11241. }
  11242. if (parameters.isRawShaderMaterial === false) {
  11243. for (var i = 0; i < parameterNames.length; i++) {
  11244. array.push(parameters[parameterNames[i]]);
  11245. }
  11246. array.push(renderer.outputEncoding);
  11247. array.push(renderer.gammaFactor);
  11248. }
  11249. array.push(parameters.customProgramCacheKey);
  11250. return array.join();
  11251. }
  11252. function getUniforms(material) {
  11253. var shaderID = shaderIDs[material.type];
  11254. var uniforms;
  11255. if (shaderID) {
  11256. var shader = ShaderLib[shaderID];
  11257. uniforms = UniformsUtils.clone(shader.uniforms);
  11258. } else {
  11259. uniforms = material.uniforms;
  11260. }
  11261. return uniforms;
  11262. }
  11263. function acquireProgram(parameters, cacheKey) {
  11264. var program; // Check if code has been already compiled
  11265. for (var p = 0, pl = programs.length; p < pl; p++) {
  11266. var preexistingProgram = programs[p];
  11267. if (preexistingProgram.cacheKey === cacheKey) {
  11268. program = preexistingProgram;
  11269. ++program.usedTimes;
  11270. break;
  11271. }
  11272. }
  11273. if (program === undefined) {
  11274. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11275. programs.push(program);
  11276. }
  11277. return program;
  11278. }
  11279. function releaseProgram(program) {
  11280. if (--program.usedTimes === 0) {
  11281. // Remove from unordered set
  11282. var i = programs.indexOf(program);
  11283. programs[i] = programs[programs.length - 1];
  11284. programs.pop(); // Free WebGL resources
  11285. program.destroy();
  11286. }
  11287. }
  11288. return {
  11289. getParameters: getParameters,
  11290. getProgramCacheKey: getProgramCacheKey,
  11291. getUniforms: getUniforms,
  11292. acquireProgram: acquireProgram,
  11293. releaseProgram: releaseProgram,
  11294. // Exposed for resource monitoring & error feedback via renderer.info:
  11295. programs: programs
  11296. };
  11297. }
  11298. function WebGLProperties() {
  11299. var properties = new WeakMap();
  11300. function get(object) {
  11301. var map = properties.get(object);
  11302. if (map === undefined) {
  11303. map = {};
  11304. properties.set(object, map);
  11305. }
  11306. return map;
  11307. }
  11308. function remove(object) {
  11309. properties.delete(object);
  11310. }
  11311. function update(object, key, value) {
  11312. properties.get(object)[key] = value;
  11313. }
  11314. function dispose() {
  11315. properties = new WeakMap();
  11316. }
  11317. return {
  11318. get: get,
  11319. remove: remove,
  11320. update: update,
  11321. dispose: dispose
  11322. };
  11323. }
  11324. function painterSortStable(a, b) {
  11325. if (a.groupOrder !== b.groupOrder) {
  11326. return a.groupOrder - b.groupOrder;
  11327. } else if (a.renderOrder !== b.renderOrder) {
  11328. return a.renderOrder - b.renderOrder;
  11329. } else if (a.program !== b.program) {
  11330. return a.program.id - b.program.id;
  11331. } else if (a.material.id !== b.material.id) {
  11332. return a.material.id - b.material.id;
  11333. } else if (a.z !== b.z) {
  11334. return a.z - b.z;
  11335. } else {
  11336. return a.id - b.id;
  11337. }
  11338. }
  11339. function reversePainterSortStable(a, b) {
  11340. if (a.groupOrder !== b.groupOrder) {
  11341. return a.groupOrder - b.groupOrder;
  11342. } else if (a.renderOrder !== b.renderOrder) {
  11343. return a.renderOrder - b.renderOrder;
  11344. } else if (a.z !== b.z) {
  11345. return b.z - a.z;
  11346. } else {
  11347. return a.id - b.id;
  11348. }
  11349. }
  11350. function WebGLRenderList(properties) {
  11351. var renderItems = [];
  11352. var renderItemsIndex = 0;
  11353. var opaque = [];
  11354. var transparent = [];
  11355. var defaultProgram = {
  11356. id: -1
  11357. };
  11358. function init() {
  11359. renderItemsIndex = 0;
  11360. opaque.length = 0;
  11361. transparent.length = 0;
  11362. }
  11363. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11364. var renderItem = renderItems[renderItemsIndex];
  11365. var materialProperties = properties.get(material);
  11366. if (renderItem === undefined) {
  11367. renderItem = {
  11368. id: object.id,
  11369. object: object,
  11370. geometry: geometry,
  11371. material: material,
  11372. program: materialProperties.program || defaultProgram,
  11373. groupOrder: groupOrder,
  11374. renderOrder: object.renderOrder,
  11375. z: z,
  11376. group: group
  11377. };
  11378. renderItems[renderItemsIndex] = renderItem;
  11379. } else {
  11380. renderItem.id = object.id;
  11381. renderItem.object = object;
  11382. renderItem.geometry = geometry;
  11383. renderItem.material = material;
  11384. renderItem.program = materialProperties.program || defaultProgram;
  11385. renderItem.groupOrder = groupOrder;
  11386. renderItem.renderOrder = object.renderOrder;
  11387. renderItem.z = z;
  11388. renderItem.group = group;
  11389. }
  11390. renderItemsIndex++;
  11391. return renderItem;
  11392. }
  11393. function push(object, geometry, material, groupOrder, z, group) {
  11394. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11395. (material.transparent === true ? transparent : opaque).push(renderItem);
  11396. }
  11397. function unshift(object, geometry, material, groupOrder, z, group) {
  11398. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11399. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11400. }
  11401. function sort(customOpaqueSort, customTransparentSort) {
  11402. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11403. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11404. }
  11405. function finish() {
  11406. // Clear references from inactive renderItems in the list
  11407. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11408. var renderItem = renderItems[i];
  11409. if (renderItem.id === null) break;
  11410. renderItem.id = null;
  11411. renderItem.object = null;
  11412. renderItem.geometry = null;
  11413. renderItem.material = null;
  11414. renderItem.program = null;
  11415. renderItem.group = null;
  11416. }
  11417. }
  11418. return {
  11419. opaque: opaque,
  11420. transparent: transparent,
  11421. init: init,
  11422. push: push,
  11423. unshift: unshift,
  11424. finish: finish,
  11425. sort: sort
  11426. };
  11427. }
  11428. function WebGLRenderLists(properties) {
  11429. var lists = new WeakMap();
  11430. function get(scene, camera) {
  11431. var cameras = lists.get(scene);
  11432. var list;
  11433. if (cameras === undefined) {
  11434. list = new WebGLRenderList(properties);
  11435. lists.set(scene, new WeakMap());
  11436. lists.get(scene).set(camera, list);
  11437. } else {
  11438. list = cameras.get(camera);
  11439. if (list === undefined) {
  11440. list = new WebGLRenderList(properties);
  11441. cameras.set(camera, list);
  11442. }
  11443. }
  11444. return list;
  11445. }
  11446. function dispose() {
  11447. lists = new WeakMap();
  11448. }
  11449. return {
  11450. get: get,
  11451. dispose: dispose
  11452. };
  11453. }
  11454. function UniformsCache() {
  11455. var lights = {};
  11456. return {
  11457. get: function get(light) {
  11458. if (lights[light.id] !== undefined) {
  11459. return lights[light.id];
  11460. }
  11461. var uniforms;
  11462. switch (light.type) {
  11463. case 'DirectionalLight':
  11464. uniforms = {
  11465. direction: new Vector3(),
  11466. color: new Color()
  11467. };
  11468. break;
  11469. case 'SpotLight':
  11470. uniforms = {
  11471. position: new Vector3(),
  11472. direction: new Vector3(),
  11473. color: new Color(),
  11474. distance: 0,
  11475. coneCos: 0,
  11476. penumbraCos: 0,
  11477. decay: 0
  11478. };
  11479. break;
  11480. case 'PointLight':
  11481. uniforms = {
  11482. position: new Vector3(),
  11483. color: new Color(),
  11484. distance: 0,
  11485. decay: 0
  11486. };
  11487. break;
  11488. case 'HemisphereLight':
  11489. uniforms = {
  11490. direction: new Vector3(),
  11491. skyColor: new Color(),
  11492. groundColor: new Color()
  11493. };
  11494. break;
  11495. case 'RectAreaLight':
  11496. uniforms = {
  11497. color: new Color(),
  11498. position: new Vector3(),
  11499. halfWidth: new Vector3(),
  11500. halfHeight: new Vector3()
  11501. };
  11502. break;
  11503. }
  11504. lights[light.id] = uniforms;
  11505. return uniforms;
  11506. }
  11507. };
  11508. }
  11509. function ShadowUniformsCache() {
  11510. var lights = {};
  11511. return {
  11512. get: function get(light) {
  11513. if (lights[light.id] !== undefined) {
  11514. return lights[light.id];
  11515. }
  11516. var uniforms;
  11517. switch (light.type) {
  11518. case 'DirectionalLight':
  11519. uniforms = {
  11520. shadowBias: 0,
  11521. shadowNormalBias: 0,
  11522. shadowRadius: 1,
  11523. shadowMapSize: new Vector2()
  11524. };
  11525. break;
  11526. case 'SpotLight':
  11527. uniforms = {
  11528. shadowBias: 0,
  11529. shadowNormalBias: 0,
  11530. shadowRadius: 1,
  11531. shadowMapSize: new Vector2()
  11532. };
  11533. break;
  11534. case 'PointLight':
  11535. uniforms = {
  11536. shadowBias: 0,
  11537. shadowNormalBias: 0,
  11538. shadowRadius: 1,
  11539. shadowMapSize: new Vector2(),
  11540. shadowCameraNear: 1,
  11541. shadowCameraFar: 1000
  11542. };
  11543. break;
  11544. // TODO (abelnation): set RectAreaLight shadow uniforms
  11545. }
  11546. lights[light.id] = uniforms;
  11547. return uniforms;
  11548. }
  11549. };
  11550. }
  11551. var nextVersion = 0;
  11552. function shadowCastingLightsFirst(lightA, lightB) {
  11553. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11554. }
  11555. function WebGLLights(extensions, capabilities) {
  11556. var cache = new UniformsCache();
  11557. var shadowCache = ShadowUniformsCache();
  11558. var state = {
  11559. version: 0,
  11560. hash: {
  11561. directionalLength: -1,
  11562. pointLength: -1,
  11563. spotLength: -1,
  11564. rectAreaLength: -1,
  11565. hemiLength: -1,
  11566. numDirectionalShadows: -1,
  11567. numPointShadows: -1,
  11568. numSpotShadows: -1
  11569. },
  11570. ambient: [0, 0, 0],
  11571. probe: [],
  11572. directional: [],
  11573. directionalShadow: [],
  11574. directionalShadowMap: [],
  11575. directionalShadowMatrix: [],
  11576. spot: [],
  11577. spotShadow: [],
  11578. spotShadowMap: [],
  11579. spotShadowMatrix: [],
  11580. rectArea: [],
  11581. rectAreaLTC1: null,
  11582. rectAreaLTC2: null,
  11583. point: [],
  11584. pointShadow: [],
  11585. pointShadowMap: [],
  11586. pointShadowMatrix: [],
  11587. hemi: []
  11588. };
  11589. for (var i = 0; i < 9; i++) {
  11590. state.probe.push(new Vector3());
  11591. }
  11592. var vector3 = new Vector3();
  11593. var matrix4 = new Matrix4();
  11594. var matrix42 = new Matrix4();
  11595. function setup(lights) {
  11596. var r = 0,
  11597. g = 0,
  11598. b = 0;
  11599. for (var _i = 0; _i < 9; _i++) {
  11600. state.probe[_i].set(0, 0, 0);
  11601. }
  11602. var directionalLength = 0;
  11603. var pointLength = 0;
  11604. var spotLength = 0;
  11605. var rectAreaLength = 0;
  11606. var hemiLength = 0;
  11607. var numDirectionalShadows = 0;
  11608. var numPointShadows = 0;
  11609. var numSpotShadows = 0;
  11610. lights.sort(shadowCastingLightsFirst);
  11611. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11612. var light = lights[_i2];
  11613. var color = light.color;
  11614. var intensity = light.intensity;
  11615. var distance = light.distance;
  11616. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11617. if (light.isAmbientLight) {
  11618. r += color.r * intensity;
  11619. g += color.g * intensity;
  11620. b += color.b * intensity;
  11621. } else if (light.isLightProbe) {
  11622. for (var j = 0; j < 9; j++) {
  11623. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11624. }
  11625. } else if (light.isDirectionalLight) {
  11626. var uniforms = cache.get(light);
  11627. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11628. if (light.castShadow) {
  11629. var shadow = light.shadow;
  11630. var shadowUniforms = shadowCache.get(light);
  11631. shadowUniforms.shadowBias = shadow.bias;
  11632. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11633. shadowUniforms.shadowRadius = shadow.radius;
  11634. shadowUniforms.shadowMapSize = shadow.mapSize;
  11635. state.directionalShadow[directionalLength] = shadowUniforms;
  11636. state.directionalShadowMap[directionalLength] = shadowMap;
  11637. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11638. numDirectionalShadows++;
  11639. }
  11640. state.directional[directionalLength] = uniforms;
  11641. directionalLength++;
  11642. } else if (light.isSpotLight) {
  11643. var _uniforms = cache.get(light);
  11644. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11645. _uniforms.color.copy(color).multiplyScalar(intensity);
  11646. _uniforms.distance = distance;
  11647. _uniforms.coneCos = Math.cos(light.angle);
  11648. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11649. _uniforms.decay = light.decay;
  11650. if (light.castShadow) {
  11651. var _shadow = light.shadow;
  11652. var _shadowUniforms = shadowCache.get(light);
  11653. _shadowUniforms.shadowBias = _shadow.bias;
  11654. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11655. _shadowUniforms.shadowRadius = _shadow.radius;
  11656. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11657. state.spotShadow[spotLength] = _shadowUniforms;
  11658. state.spotShadowMap[spotLength] = shadowMap;
  11659. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11660. numSpotShadows++;
  11661. }
  11662. state.spot[spotLength] = _uniforms;
  11663. spotLength++;
  11664. } else if (light.isRectAreaLight) {
  11665. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11666. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11667. // (b) intensity is the brightness of the light
  11668. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11669. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11670. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11671. state.rectArea[rectAreaLength] = _uniforms2;
  11672. rectAreaLength++;
  11673. } else if (light.isPointLight) {
  11674. var _uniforms3 = cache.get(light);
  11675. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11676. _uniforms3.distance = light.distance;
  11677. _uniforms3.decay = light.decay;
  11678. if (light.castShadow) {
  11679. var _shadow2 = light.shadow;
  11680. var _shadowUniforms2 = shadowCache.get(light);
  11681. _shadowUniforms2.shadowBias = _shadow2.bias;
  11682. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11683. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11684. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11685. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11686. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11687. state.pointShadow[pointLength] = _shadowUniforms2;
  11688. state.pointShadowMap[pointLength] = shadowMap;
  11689. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11690. numPointShadows++;
  11691. }
  11692. state.point[pointLength] = _uniforms3;
  11693. pointLength++;
  11694. } else if (light.isHemisphereLight) {
  11695. var _uniforms4 = cache.get(light);
  11696. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11697. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11698. state.hemi[hemiLength] = _uniforms4;
  11699. hemiLength++;
  11700. }
  11701. }
  11702. if (rectAreaLength > 0) {
  11703. if (capabilities.isWebGL2) {
  11704. // WebGL 2
  11705. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11706. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11707. } else {
  11708. // WebGL 1
  11709. if (extensions.has('OES_texture_float_linear') === true) {
  11710. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11711. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11712. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  11713. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11714. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11715. } else {
  11716. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  11717. }
  11718. }
  11719. }
  11720. state.ambient[0] = r;
  11721. state.ambient[1] = g;
  11722. state.ambient[2] = b;
  11723. var hash = state.hash;
  11724. 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) {
  11725. state.directional.length = directionalLength;
  11726. state.spot.length = spotLength;
  11727. state.rectArea.length = rectAreaLength;
  11728. state.point.length = pointLength;
  11729. state.hemi.length = hemiLength;
  11730. state.directionalShadow.length = numDirectionalShadows;
  11731. state.directionalShadowMap.length = numDirectionalShadows;
  11732. state.pointShadow.length = numPointShadows;
  11733. state.pointShadowMap.length = numPointShadows;
  11734. state.spotShadow.length = numSpotShadows;
  11735. state.spotShadowMap.length = numSpotShadows;
  11736. state.directionalShadowMatrix.length = numDirectionalShadows;
  11737. state.pointShadowMatrix.length = numPointShadows;
  11738. state.spotShadowMatrix.length = numSpotShadows;
  11739. hash.directionalLength = directionalLength;
  11740. hash.pointLength = pointLength;
  11741. hash.spotLength = spotLength;
  11742. hash.rectAreaLength = rectAreaLength;
  11743. hash.hemiLength = hemiLength;
  11744. hash.numDirectionalShadows = numDirectionalShadows;
  11745. hash.numPointShadows = numPointShadows;
  11746. hash.numSpotShadows = numSpotShadows;
  11747. state.version = nextVersion++;
  11748. }
  11749. }
  11750. function setupView(lights, camera) {
  11751. var directionalLength = 0;
  11752. var pointLength = 0;
  11753. var spotLength = 0;
  11754. var rectAreaLength = 0;
  11755. var hemiLength = 0;
  11756. var viewMatrix = camera.matrixWorldInverse;
  11757. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  11758. var light = lights[_i3];
  11759. if (light.isDirectionalLight) {
  11760. var uniforms = state.directional[directionalLength];
  11761. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11762. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11763. uniforms.direction.sub(vector3);
  11764. uniforms.direction.transformDirection(viewMatrix);
  11765. directionalLength++;
  11766. } else if (light.isSpotLight) {
  11767. var _uniforms5 = state.spot[spotLength];
  11768. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  11769. _uniforms5.position.applyMatrix4(viewMatrix);
  11770. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  11771. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11772. _uniforms5.direction.sub(vector3);
  11773. _uniforms5.direction.transformDirection(viewMatrix);
  11774. spotLength++;
  11775. } else if (light.isRectAreaLight) {
  11776. var _uniforms6 = state.rectArea[rectAreaLength];
  11777. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  11778. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11779. matrix42.identity();
  11780. matrix4.copy(light.matrixWorld);
  11781. matrix4.premultiply(viewMatrix);
  11782. matrix42.extractRotation(matrix4);
  11783. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11784. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11785. _uniforms6.halfWidth.applyMatrix4(matrix42);
  11786. _uniforms6.halfHeight.applyMatrix4(matrix42);
  11787. rectAreaLength++;
  11788. } else if (light.isPointLight) {
  11789. var _uniforms7 = state.point[pointLength];
  11790. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  11791. _uniforms7.position.applyMatrix4(viewMatrix);
  11792. pointLength++;
  11793. } else if (light.isHemisphereLight) {
  11794. var _uniforms8 = state.hemi[hemiLength];
  11795. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  11796. _uniforms8.direction.transformDirection(viewMatrix);
  11797. _uniforms8.direction.normalize();
  11798. hemiLength++;
  11799. }
  11800. }
  11801. }
  11802. return {
  11803. setup: setup,
  11804. setupView: setupView,
  11805. state: state
  11806. };
  11807. }
  11808. function WebGLRenderState(extensions, capabilities) {
  11809. var lights = new WebGLLights(extensions, capabilities);
  11810. var lightsArray = [];
  11811. var shadowsArray = [];
  11812. function init() {
  11813. lightsArray.length = 0;
  11814. shadowsArray.length = 0;
  11815. }
  11816. function pushLight(light) {
  11817. lightsArray.push(light);
  11818. }
  11819. function pushShadow(shadowLight) {
  11820. shadowsArray.push(shadowLight);
  11821. }
  11822. function setupLights() {
  11823. lights.setup(lightsArray);
  11824. }
  11825. function setupLightsView(camera) {
  11826. lights.setupView(lightsArray, camera);
  11827. }
  11828. var state = {
  11829. lightsArray: lightsArray,
  11830. shadowsArray: shadowsArray,
  11831. lights: lights
  11832. };
  11833. return {
  11834. init: init,
  11835. state: state,
  11836. setupLights: setupLights,
  11837. setupLightsView: setupLightsView,
  11838. pushLight: pushLight,
  11839. pushShadow: pushShadow
  11840. };
  11841. }
  11842. function WebGLRenderStates(extensions, capabilities) {
  11843. var renderStates = new WeakMap();
  11844. function get(scene, renderCallDepth) {
  11845. if (renderCallDepth === void 0) {
  11846. renderCallDepth = 0;
  11847. }
  11848. var renderState;
  11849. if (renderStates.has(scene) === false) {
  11850. renderState = new WebGLRenderState(extensions, capabilities);
  11851. renderStates.set(scene, []);
  11852. renderStates.get(scene).push(renderState);
  11853. } else {
  11854. if (renderCallDepth >= renderStates.get(scene).length) {
  11855. renderState = new WebGLRenderState(extensions, capabilities);
  11856. renderStates.get(scene).push(renderState);
  11857. } else {
  11858. renderState = renderStates.get(scene)[renderCallDepth];
  11859. }
  11860. }
  11861. return renderState;
  11862. }
  11863. function dispose() {
  11864. renderStates = new WeakMap();
  11865. }
  11866. return {
  11867. get: get,
  11868. dispose: dispose
  11869. };
  11870. }
  11871. /**
  11872. * parameters = {
  11873. *
  11874. * opacity: <float>,
  11875. *
  11876. * map: new THREE.Texture( <Image> ),
  11877. *
  11878. * alphaMap: new THREE.Texture( <Image> ),
  11879. *
  11880. * displacementMap: new THREE.Texture( <Image> ),
  11881. * displacementScale: <float>,
  11882. * displacementBias: <float>,
  11883. *
  11884. * wireframe: <boolean>,
  11885. * wireframeLinewidth: <float>
  11886. * }
  11887. */
  11888. function MeshDepthMaterial(parameters) {
  11889. Material.call(this);
  11890. this.type = 'MeshDepthMaterial';
  11891. this.depthPacking = BasicDepthPacking;
  11892. this.skinning = false;
  11893. this.morphTargets = false;
  11894. this.map = null;
  11895. this.alphaMap = null;
  11896. this.displacementMap = null;
  11897. this.displacementScale = 1;
  11898. this.displacementBias = 0;
  11899. this.wireframe = false;
  11900. this.wireframeLinewidth = 1;
  11901. this.fog = false;
  11902. this.setValues(parameters);
  11903. }
  11904. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11905. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11906. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11907. MeshDepthMaterial.prototype.copy = function (source) {
  11908. Material.prototype.copy.call(this, source);
  11909. this.depthPacking = source.depthPacking;
  11910. this.skinning = source.skinning;
  11911. this.morphTargets = source.morphTargets;
  11912. this.map = source.map;
  11913. this.alphaMap = source.alphaMap;
  11914. this.displacementMap = source.displacementMap;
  11915. this.displacementScale = source.displacementScale;
  11916. this.displacementBias = source.displacementBias;
  11917. this.wireframe = source.wireframe;
  11918. this.wireframeLinewidth = source.wireframeLinewidth;
  11919. return this;
  11920. };
  11921. /**
  11922. * parameters = {
  11923. *
  11924. * referencePosition: <float>,
  11925. * nearDistance: <float>,
  11926. * farDistance: <float>,
  11927. *
  11928. * skinning: <bool>,
  11929. * morphTargets: <bool>,
  11930. *
  11931. * map: new THREE.Texture( <Image> ),
  11932. *
  11933. * alphaMap: new THREE.Texture( <Image> ),
  11934. *
  11935. * displacementMap: new THREE.Texture( <Image> ),
  11936. * displacementScale: <float>,
  11937. * displacementBias: <float>
  11938. *
  11939. * }
  11940. */
  11941. function MeshDistanceMaterial(parameters) {
  11942. Material.call(this);
  11943. this.type = 'MeshDistanceMaterial';
  11944. this.referencePosition = new Vector3();
  11945. this.nearDistance = 1;
  11946. this.farDistance = 1000;
  11947. this.skinning = false;
  11948. this.morphTargets = false;
  11949. this.map = null;
  11950. this.alphaMap = null;
  11951. this.displacementMap = null;
  11952. this.displacementScale = 1;
  11953. this.displacementBias = 0;
  11954. this.fog = false;
  11955. this.setValues(parameters);
  11956. }
  11957. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11958. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11959. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11960. MeshDistanceMaterial.prototype.copy = function (source) {
  11961. Material.prototype.copy.call(this, source);
  11962. this.referencePosition.copy(source.referencePosition);
  11963. this.nearDistance = source.nearDistance;
  11964. this.farDistance = source.farDistance;
  11965. this.skinning = source.skinning;
  11966. this.morphTargets = source.morphTargets;
  11967. this.map = source.map;
  11968. this.alphaMap = source.alphaMap;
  11969. this.displacementMap = source.displacementMap;
  11970. this.displacementScale = source.displacementScale;
  11971. this.displacementBias = source.displacementBias;
  11972. return this;
  11973. };
  11974. 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}";
  11975. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11976. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11977. var _frustum = new Frustum();
  11978. var _shadowMapSize = new Vector2(),
  11979. _viewportSize = new Vector2(),
  11980. _viewport = new Vector4(),
  11981. _depthMaterials = [],
  11982. _distanceMaterials = [],
  11983. _materialCache = {};
  11984. var shadowSide = {
  11985. 0: BackSide,
  11986. 1: FrontSide,
  11987. 2: DoubleSide
  11988. };
  11989. var shadowMaterialVertical = new ShaderMaterial({
  11990. defines: {
  11991. SAMPLE_RATE: 2.0 / 8.0,
  11992. HALF_SAMPLE_RATE: 1.0 / 8.0
  11993. },
  11994. uniforms: {
  11995. shadow_pass: {
  11996. value: null
  11997. },
  11998. resolution: {
  11999. value: new Vector2()
  12000. },
  12001. radius: {
  12002. value: 4.0
  12003. }
  12004. },
  12005. vertexShader: vsm_vert,
  12006. fragmentShader: vsm_frag
  12007. });
  12008. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12009. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12010. var fullScreenTri = new BufferGeometry();
  12011. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12012. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12013. var scope = this;
  12014. this.enabled = false;
  12015. this.autoUpdate = true;
  12016. this.needsUpdate = false;
  12017. this.type = PCFShadowMap;
  12018. this.render = function (lights, scene, camera) {
  12019. if (scope.enabled === false) return;
  12020. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12021. if (lights.length === 0) return;
  12022. var currentRenderTarget = _renderer.getRenderTarget();
  12023. var activeCubeFace = _renderer.getActiveCubeFace();
  12024. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12025. var _state = _renderer.state; // Set GL state for depth map.
  12026. _state.setBlending(NoBlending);
  12027. _state.buffers.color.setClear(1, 1, 1, 1);
  12028. _state.buffers.depth.setTest(true);
  12029. _state.setScissorTest(false); // render depth map
  12030. for (var i = 0, il = lights.length; i < il; i++) {
  12031. var light = lights[i];
  12032. var shadow = light.shadow;
  12033. if (shadow === undefined) {
  12034. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12035. continue;
  12036. }
  12037. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12038. _shadowMapSize.copy(shadow.mapSize);
  12039. var shadowFrameExtents = shadow.getFrameExtents();
  12040. _shadowMapSize.multiply(shadowFrameExtents);
  12041. _viewportSize.copy(shadow.mapSize);
  12042. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12043. if (_shadowMapSize.x > maxTextureSize) {
  12044. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12045. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12046. shadow.mapSize.x = _viewportSize.x;
  12047. }
  12048. if (_shadowMapSize.y > maxTextureSize) {
  12049. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12050. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12051. shadow.mapSize.y = _viewportSize.y;
  12052. }
  12053. }
  12054. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12055. var pars = {
  12056. minFilter: LinearFilter,
  12057. magFilter: LinearFilter,
  12058. format: RGBAFormat
  12059. };
  12060. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12061. shadow.map.texture.name = light.name + '.shadowMap';
  12062. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12063. shadow.camera.updateProjectionMatrix();
  12064. }
  12065. if (shadow.map === null) {
  12066. var _pars = {
  12067. minFilter: NearestFilter,
  12068. magFilter: NearestFilter,
  12069. format: RGBAFormat
  12070. };
  12071. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12072. shadow.map.texture.name = light.name + '.shadowMap';
  12073. shadow.camera.updateProjectionMatrix();
  12074. }
  12075. _renderer.setRenderTarget(shadow.map);
  12076. _renderer.clear();
  12077. var viewportCount = shadow.getViewportCount();
  12078. for (var vp = 0; vp < viewportCount; vp++) {
  12079. var viewport = shadow.getViewport(vp);
  12080. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12081. _state.viewport(_viewport);
  12082. shadow.updateMatrices(light, vp);
  12083. _frustum = shadow.getFrustum();
  12084. renderObject(scene, camera, shadow.camera, light, this.type);
  12085. } // do blur pass for VSM
  12086. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12087. VSMPass(shadow, camera);
  12088. }
  12089. shadow.needsUpdate = false;
  12090. }
  12091. scope.needsUpdate = false;
  12092. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12093. };
  12094. function VSMPass(shadow, camera) {
  12095. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12096. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12097. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12098. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12099. _renderer.setRenderTarget(shadow.mapPass);
  12100. _renderer.clear();
  12101. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12102. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12103. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12104. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12105. _renderer.setRenderTarget(shadow.map);
  12106. _renderer.clear();
  12107. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12108. }
  12109. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12110. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12111. var material = _depthMaterials[index];
  12112. if (material === undefined) {
  12113. material = new MeshDepthMaterial({
  12114. depthPacking: RGBADepthPacking,
  12115. morphTargets: useMorphing,
  12116. skinning: useSkinning
  12117. });
  12118. _depthMaterials[index] = material;
  12119. }
  12120. return material;
  12121. }
  12122. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12123. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12124. var material = _distanceMaterials[index];
  12125. if (material === undefined) {
  12126. material = new MeshDistanceMaterial({
  12127. morphTargets: useMorphing,
  12128. skinning: useSkinning
  12129. });
  12130. _distanceMaterials[index] = material;
  12131. }
  12132. return material;
  12133. }
  12134. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12135. var result = null;
  12136. var getMaterialVariant = getDepthMaterialVariant;
  12137. var customMaterial = object.customDepthMaterial;
  12138. if (light.isPointLight === true) {
  12139. getMaterialVariant = getDistanceMaterialVariant;
  12140. customMaterial = object.customDistanceMaterial;
  12141. }
  12142. if (customMaterial === undefined) {
  12143. var useMorphing = false;
  12144. if (material.morphTargets === true) {
  12145. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12146. }
  12147. var useSkinning = false;
  12148. if (object.isSkinnedMesh === true) {
  12149. if (material.skinning === true) {
  12150. useSkinning = true;
  12151. } else {
  12152. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12153. }
  12154. }
  12155. var useInstancing = object.isInstancedMesh === true;
  12156. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12157. } else {
  12158. result = customMaterial;
  12159. }
  12160. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12161. // in this case we need a unique material instance reflecting the
  12162. // appropriate state
  12163. var keyA = result.uuid,
  12164. keyB = material.uuid;
  12165. var materialsForVariant = _materialCache[keyA];
  12166. if (materialsForVariant === undefined) {
  12167. materialsForVariant = {};
  12168. _materialCache[keyA] = materialsForVariant;
  12169. }
  12170. var cachedMaterial = materialsForVariant[keyB];
  12171. if (cachedMaterial === undefined) {
  12172. cachedMaterial = result.clone();
  12173. materialsForVariant[keyB] = cachedMaterial;
  12174. }
  12175. result = cachedMaterial;
  12176. }
  12177. result.visible = material.visible;
  12178. result.wireframe = material.wireframe;
  12179. if (type === VSMShadowMap) {
  12180. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12181. } else {
  12182. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12183. }
  12184. result.clipShadows = material.clipShadows;
  12185. result.clippingPlanes = material.clippingPlanes;
  12186. result.clipIntersection = material.clipIntersection;
  12187. result.wireframeLinewidth = material.wireframeLinewidth;
  12188. result.linewidth = material.linewidth;
  12189. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12190. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12191. result.nearDistance = shadowCameraNear;
  12192. result.farDistance = shadowCameraFar;
  12193. }
  12194. return result;
  12195. }
  12196. function renderObject(object, camera, shadowCamera, light, type) {
  12197. if (object.visible === false) return;
  12198. var visible = object.layers.test(camera.layers);
  12199. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12200. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12201. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12202. var geometry = _objects.update(object);
  12203. var material = object.material;
  12204. if (Array.isArray(material)) {
  12205. var groups = geometry.groups;
  12206. for (var k = 0, kl = groups.length; k < kl; k++) {
  12207. var group = groups[k];
  12208. var groupMaterial = material[group.materialIndex];
  12209. if (groupMaterial && groupMaterial.visible) {
  12210. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12211. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12212. }
  12213. }
  12214. } else if (material.visible) {
  12215. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12216. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12217. }
  12218. }
  12219. }
  12220. var children = object.children;
  12221. for (var i = 0, l = children.length; i < l; i++) {
  12222. renderObject(children[i], camera, shadowCamera, light, type);
  12223. }
  12224. }
  12225. }
  12226. function WebGLState(gl, extensions, capabilities) {
  12227. var _equationToGL, _factorToGL;
  12228. var isWebGL2 = capabilities.isWebGL2;
  12229. function ColorBuffer() {
  12230. var locked = false;
  12231. var color = new Vector4();
  12232. var currentColorMask = null;
  12233. var currentColorClear = new Vector4(0, 0, 0, 0);
  12234. return {
  12235. setMask: function setMask(colorMask) {
  12236. if (currentColorMask !== colorMask && !locked) {
  12237. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12238. currentColorMask = colorMask;
  12239. }
  12240. },
  12241. setLocked: function setLocked(lock) {
  12242. locked = lock;
  12243. },
  12244. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12245. if (premultipliedAlpha === true) {
  12246. r *= a;
  12247. g *= a;
  12248. b *= a;
  12249. }
  12250. color.set(r, g, b, a);
  12251. if (currentColorClear.equals(color) === false) {
  12252. gl.clearColor(r, g, b, a);
  12253. currentColorClear.copy(color);
  12254. }
  12255. },
  12256. reset: function reset() {
  12257. locked = false;
  12258. currentColorMask = null;
  12259. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12260. }
  12261. };
  12262. }
  12263. function DepthBuffer() {
  12264. var locked = false;
  12265. var currentDepthMask = null;
  12266. var currentDepthFunc = null;
  12267. var currentDepthClear = null;
  12268. return {
  12269. setTest: function setTest(depthTest) {
  12270. if (depthTest) {
  12271. enable(2929);
  12272. } else {
  12273. disable(2929);
  12274. }
  12275. },
  12276. setMask: function setMask(depthMask) {
  12277. if (currentDepthMask !== depthMask && !locked) {
  12278. gl.depthMask(depthMask);
  12279. currentDepthMask = depthMask;
  12280. }
  12281. },
  12282. setFunc: function setFunc(depthFunc) {
  12283. if (currentDepthFunc !== depthFunc) {
  12284. if (depthFunc) {
  12285. switch (depthFunc) {
  12286. case NeverDepth:
  12287. gl.depthFunc(512);
  12288. break;
  12289. case AlwaysDepth:
  12290. gl.depthFunc(519);
  12291. break;
  12292. case LessDepth:
  12293. gl.depthFunc(513);
  12294. break;
  12295. case LessEqualDepth:
  12296. gl.depthFunc(515);
  12297. break;
  12298. case EqualDepth:
  12299. gl.depthFunc(514);
  12300. break;
  12301. case GreaterEqualDepth:
  12302. gl.depthFunc(518);
  12303. break;
  12304. case GreaterDepth:
  12305. gl.depthFunc(516);
  12306. break;
  12307. case NotEqualDepth:
  12308. gl.depthFunc(517);
  12309. break;
  12310. default:
  12311. gl.depthFunc(515);
  12312. }
  12313. } else {
  12314. gl.depthFunc(515);
  12315. }
  12316. currentDepthFunc = depthFunc;
  12317. }
  12318. },
  12319. setLocked: function setLocked(lock) {
  12320. locked = lock;
  12321. },
  12322. setClear: function setClear(depth) {
  12323. if (currentDepthClear !== depth) {
  12324. gl.clearDepth(depth);
  12325. currentDepthClear = depth;
  12326. }
  12327. },
  12328. reset: function reset() {
  12329. locked = false;
  12330. currentDepthMask = null;
  12331. currentDepthFunc = null;
  12332. currentDepthClear = null;
  12333. }
  12334. };
  12335. }
  12336. function StencilBuffer() {
  12337. var locked = false;
  12338. var currentStencilMask = null;
  12339. var currentStencilFunc = null;
  12340. var currentStencilRef = null;
  12341. var currentStencilFuncMask = null;
  12342. var currentStencilFail = null;
  12343. var currentStencilZFail = null;
  12344. var currentStencilZPass = null;
  12345. var currentStencilClear = null;
  12346. return {
  12347. setTest: function setTest(stencilTest) {
  12348. if (!locked) {
  12349. if (stencilTest) {
  12350. enable(2960);
  12351. } else {
  12352. disable(2960);
  12353. }
  12354. }
  12355. },
  12356. setMask: function setMask(stencilMask) {
  12357. if (currentStencilMask !== stencilMask && !locked) {
  12358. gl.stencilMask(stencilMask);
  12359. currentStencilMask = stencilMask;
  12360. }
  12361. },
  12362. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12363. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12364. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12365. currentStencilFunc = stencilFunc;
  12366. currentStencilRef = stencilRef;
  12367. currentStencilFuncMask = stencilMask;
  12368. }
  12369. },
  12370. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12371. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12372. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12373. currentStencilFail = stencilFail;
  12374. currentStencilZFail = stencilZFail;
  12375. currentStencilZPass = stencilZPass;
  12376. }
  12377. },
  12378. setLocked: function setLocked(lock) {
  12379. locked = lock;
  12380. },
  12381. setClear: function setClear(stencil) {
  12382. if (currentStencilClear !== stencil) {
  12383. gl.clearStencil(stencil);
  12384. currentStencilClear = stencil;
  12385. }
  12386. },
  12387. reset: function reset() {
  12388. locked = false;
  12389. currentStencilMask = null;
  12390. currentStencilFunc = null;
  12391. currentStencilRef = null;
  12392. currentStencilFuncMask = null;
  12393. currentStencilFail = null;
  12394. currentStencilZFail = null;
  12395. currentStencilZPass = null;
  12396. currentStencilClear = null;
  12397. }
  12398. };
  12399. } //
  12400. var colorBuffer = new ColorBuffer();
  12401. var depthBuffer = new DepthBuffer();
  12402. var stencilBuffer = new StencilBuffer();
  12403. var enabledCapabilities = {};
  12404. var currentProgram = null;
  12405. var currentBlendingEnabled = null;
  12406. var currentBlending = null;
  12407. var currentBlendEquation = null;
  12408. var currentBlendSrc = null;
  12409. var currentBlendDst = null;
  12410. var currentBlendEquationAlpha = null;
  12411. var currentBlendSrcAlpha = null;
  12412. var currentBlendDstAlpha = null;
  12413. var currentPremultipledAlpha = false;
  12414. var currentFlipSided = null;
  12415. var currentCullFace = null;
  12416. var currentLineWidth = null;
  12417. var currentPolygonOffsetFactor = null;
  12418. var currentPolygonOffsetUnits = null;
  12419. var maxTextures = gl.getParameter(35661);
  12420. var lineWidthAvailable = false;
  12421. var version = 0;
  12422. var glVersion = gl.getParameter(7938);
  12423. if (glVersion.indexOf('WebGL') !== -1) {
  12424. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12425. lineWidthAvailable = version >= 1.0;
  12426. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12427. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12428. lineWidthAvailable = version >= 2.0;
  12429. }
  12430. var currentTextureSlot = null;
  12431. var currentBoundTextures = {};
  12432. var currentScissor = new Vector4();
  12433. var currentViewport = new Vector4();
  12434. function createTexture(type, target, count) {
  12435. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12436. var texture = gl.createTexture();
  12437. gl.bindTexture(type, texture);
  12438. gl.texParameteri(type, 10241, 9728);
  12439. gl.texParameteri(type, 10240, 9728);
  12440. for (var i = 0; i < count; i++) {
  12441. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12442. }
  12443. return texture;
  12444. }
  12445. var emptyTextures = {};
  12446. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12447. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12448. colorBuffer.setClear(0, 0, 0, 1);
  12449. depthBuffer.setClear(1);
  12450. stencilBuffer.setClear(0);
  12451. enable(2929);
  12452. depthBuffer.setFunc(LessEqualDepth);
  12453. setFlipSided(false);
  12454. setCullFace(CullFaceBack);
  12455. enable(2884);
  12456. setBlending(NoBlending); //
  12457. function enable(id) {
  12458. if (enabledCapabilities[id] !== true) {
  12459. gl.enable(id);
  12460. enabledCapabilities[id] = true;
  12461. }
  12462. }
  12463. function disable(id) {
  12464. if (enabledCapabilities[id] !== false) {
  12465. gl.disable(id);
  12466. enabledCapabilities[id] = false;
  12467. }
  12468. }
  12469. function useProgram(program) {
  12470. if (currentProgram !== program) {
  12471. gl.useProgram(program);
  12472. currentProgram = program;
  12473. return true;
  12474. }
  12475. return false;
  12476. }
  12477. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12478. if (isWebGL2) {
  12479. equationToGL[MinEquation] = 32775;
  12480. equationToGL[MaxEquation] = 32776;
  12481. } else {
  12482. var extension = extensions.get('EXT_blend_minmax');
  12483. if (extension !== null) {
  12484. equationToGL[MinEquation] = extension.MIN_EXT;
  12485. equationToGL[MaxEquation] = extension.MAX_EXT;
  12486. }
  12487. }
  12488. 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);
  12489. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12490. if (blending === NoBlending) {
  12491. if (currentBlendingEnabled) {
  12492. disable(3042);
  12493. currentBlendingEnabled = false;
  12494. }
  12495. return;
  12496. }
  12497. if (!currentBlendingEnabled) {
  12498. enable(3042);
  12499. currentBlendingEnabled = true;
  12500. }
  12501. if (blending !== CustomBlending) {
  12502. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12503. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12504. gl.blendEquation(32774);
  12505. currentBlendEquation = AddEquation;
  12506. currentBlendEquationAlpha = AddEquation;
  12507. }
  12508. if (premultipliedAlpha) {
  12509. switch (blending) {
  12510. case NormalBlending:
  12511. gl.blendFuncSeparate(1, 771, 1, 771);
  12512. break;
  12513. case AdditiveBlending:
  12514. gl.blendFunc(1, 1);
  12515. break;
  12516. case SubtractiveBlending:
  12517. gl.blendFuncSeparate(0, 0, 769, 771);
  12518. break;
  12519. case MultiplyBlending:
  12520. gl.blendFuncSeparate(0, 768, 0, 770);
  12521. break;
  12522. default:
  12523. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12524. break;
  12525. }
  12526. } else {
  12527. switch (blending) {
  12528. case NormalBlending:
  12529. gl.blendFuncSeparate(770, 771, 1, 771);
  12530. break;
  12531. case AdditiveBlending:
  12532. gl.blendFunc(770, 1);
  12533. break;
  12534. case SubtractiveBlending:
  12535. gl.blendFunc(0, 769);
  12536. break;
  12537. case MultiplyBlending:
  12538. gl.blendFunc(0, 768);
  12539. break;
  12540. default:
  12541. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12542. break;
  12543. }
  12544. }
  12545. currentBlendSrc = null;
  12546. currentBlendDst = null;
  12547. currentBlendSrcAlpha = null;
  12548. currentBlendDstAlpha = null;
  12549. currentBlending = blending;
  12550. currentPremultipledAlpha = premultipliedAlpha;
  12551. }
  12552. return;
  12553. } // custom blending
  12554. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12555. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12556. blendDstAlpha = blendDstAlpha || blendDst;
  12557. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12558. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12559. currentBlendEquation = blendEquation;
  12560. currentBlendEquationAlpha = blendEquationAlpha;
  12561. }
  12562. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12563. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12564. currentBlendSrc = blendSrc;
  12565. currentBlendDst = blendDst;
  12566. currentBlendSrcAlpha = blendSrcAlpha;
  12567. currentBlendDstAlpha = blendDstAlpha;
  12568. }
  12569. currentBlending = blending;
  12570. currentPremultipledAlpha = null;
  12571. }
  12572. function setMaterial(material, frontFaceCW) {
  12573. material.side === DoubleSide ? disable(2884) : enable(2884);
  12574. var flipSided = material.side === BackSide;
  12575. if (frontFaceCW) flipSided = !flipSided;
  12576. setFlipSided(flipSided);
  12577. 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);
  12578. depthBuffer.setFunc(material.depthFunc);
  12579. depthBuffer.setTest(material.depthTest);
  12580. depthBuffer.setMask(material.depthWrite);
  12581. colorBuffer.setMask(material.colorWrite);
  12582. var stencilWrite = material.stencilWrite;
  12583. stencilBuffer.setTest(stencilWrite);
  12584. if (stencilWrite) {
  12585. stencilBuffer.setMask(material.stencilWriteMask);
  12586. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12587. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12588. }
  12589. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12590. } //
  12591. function setFlipSided(flipSided) {
  12592. if (currentFlipSided !== flipSided) {
  12593. if (flipSided) {
  12594. gl.frontFace(2304);
  12595. } else {
  12596. gl.frontFace(2305);
  12597. }
  12598. currentFlipSided = flipSided;
  12599. }
  12600. }
  12601. function setCullFace(cullFace) {
  12602. if (cullFace !== CullFaceNone) {
  12603. enable(2884);
  12604. if (cullFace !== currentCullFace) {
  12605. if (cullFace === CullFaceBack) {
  12606. gl.cullFace(1029);
  12607. } else if (cullFace === CullFaceFront) {
  12608. gl.cullFace(1028);
  12609. } else {
  12610. gl.cullFace(1032);
  12611. }
  12612. }
  12613. } else {
  12614. disable(2884);
  12615. }
  12616. currentCullFace = cullFace;
  12617. }
  12618. function setLineWidth(width) {
  12619. if (width !== currentLineWidth) {
  12620. if (lineWidthAvailable) gl.lineWidth(width);
  12621. currentLineWidth = width;
  12622. }
  12623. }
  12624. function setPolygonOffset(polygonOffset, factor, units) {
  12625. if (polygonOffset) {
  12626. enable(32823);
  12627. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12628. gl.polygonOffset(factor, units);
  12629. currentPolygonOffsetFactor = factor;
  12630. currentPolygonOffsetUnits = units;
  12631. }
  12632. } else {
  12633. disable(32823);
  12634. }
  12635. }
  12636. function setScissorTest(scissorTest) {
  12637. if (scissorTest) {
  12638. enable(3089);
  12639. } else {
  12640. disable(3089);
  12641. }
  12642. } // texture
  12643. function activeTexture(webglSlot) {
  12644. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12645. if (currentTextureSlot !== webglSlot) {
  12646. gl.activeTexture(webglSlot);
  12647. currentTextureSlot = webglSlot;
  12648. }
  12649. }
  12650. function bindTexture(webglType, webglTexture) {
  12651. if (currentTextureSlot === null) {
  12652. activeTexture();
  12653. }
  12654. var boundTexture = currentBoundTextures[currentTextureSlot];
  12655. if (boundTexture === undefined) {
  12656. boundTexture = {
  12657. type: undefined,
  12658. texture: undefined
  12659. };
  12660. currentBoundTextures[currentTextureSlot] = boundTexture;
  12661. }
  12662. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12663. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12664. boundTexture.type = webglType;
  12665. boundTexture.texture = webglTexture;
  12666. }
  12667. }
  12668. function unbindTexture() {
  12669. var boundTexture = currentBoundTextures[currentTextureSlot];
  12670. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12671. gl.bindTexture(boundTexture.type, null);
  12672. boundTexture.type = undefined;
  12673. boundTexture.texture = undefined;
  12674. }
  12675. }
  12676. function compressedTexImage2D() {
  12677. try {
  12678. gl.compressedTexImage2D.apply(gl, arguments);
  12679. } catch (error) {
  12680. console.error('THREE.WebGLState:', error);
  12681. }
  12682. }
  12683. function texImage2D() {
  12684. try {
  12685. gl.texImage2D.apply(gl, arguments);
  12686. } catch (error) {
  12687. console.error('THREE.WebGLState:', error);
  12688. }
  12689. }
  12690. function texImage3D() {
  12691. try {
  12692. gl.texImage3D.apply(gl, arguments);
  12693. } catch (error) {
  12694. console.error('THREE.WebGLState:', error);
  12695. }
  12696. } //
  12697. function scissor(scissor) {
  12698. if (currentScissor.equals(scissor) === false) {
  12699. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12700. currentScissor.copy(scissor);
  12701. }
  12702. }
  12703. function viewport(viewport) {
  12704. if (currentViewport.equals(viewport) === false) {
  12705. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12706. currentViewport.copy(viewport);
  12707. }
  12708. } //
  12709. function reset() {
  12710. enabledCapabilities = {};
  12711. currentTextureSlot = null;
  12712. currentBoundTextures = {};
  12713. currentProgram = null;
  12714. currentBlendingEnabled = null;
  12715. currentBlending = null;
  12716. currentBlendEquation = null;
  12717. currentBlendSrc = null;
  12718. currentBlendDst = null;
  12719. currentBlendEquationAlpha = null;
  12720. currentBlendSrcAlpha = null;
  12721. currentBlendDstAlpha = null;
  12722. currentPremultipledAlpha = false;
  12723. currentFlipSided = null;
  12724. currentCullFace = null;
  12725. currentLineWidth = null;
  12726. currentPolygonOffsetFactor = null;
  12727. currentPolygonOffsetUnits = null;
  12728. colorBuffer.reset();
  12729. depthBuffer.reset();
  12730. stencilBuffer.reset();
  12731. }
  12732. return {
  12733. buffers: {
  12734. color: colorBuffer,
  12735. depth: depthBuffer,
  12736. stencil: stencilBuffer
  12737. },
  12738. enable: enable,
  12739. disable: disable,
  12740. useProgram: useProgram,
  12741. setBlending: setBlending,
  12742. setMaterial: setMaterial,
  12743. setFlipSided: setFlipSided,
  12744. setCullFace: setCullFace,
  12745. setLineWidth: setLineWidth,
  12746. setPolygonOffset: setPolygonOffset,
  12747. setScissorTest: setScissorTest,
  12748. activeTexture: activeTexture,
  12749. bindTexture: bindTexture,
  12750. unbindTexture: unbindTexture,
  12751. compressedTexImage2D: compressedTexImage2D,
  12752. texImage2D: texImage2D,
  12753. texImage3D: texImage3D,
  12754. scissor: scissor,
  12755. viewport: viewport,
  12756. reset: reset
  12757. };
  12758. }
  12759. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12760. var _wrappingToGL, _filterToGL;
  12761. var isWebGL2 = capabilities.isWebGL2;
  12762. var maxTextures = capabilities.maxTextures;
  12763. var maxCubemapSize = capabilities.maxCubemapSize;
  12764. var maxTextureSize = capabilities.maxTextureSize;
  12765. var maxSamples = capabilities.maxSamples;
  12766. var _videoTextures = new WeakMap();
  12767. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12768. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12769. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12770. var useOffscreenCanvas = false;
  12771. try {
  12772. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  12773. } catch (err) {// Ignore any errors
  12774. }
  12775. function createCanvas(width, height) {
  12776. // Use OffscreenCanvas when available. Specially needed in web workers
  12777. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12778. }
  12779. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12780. var scale = 1; // handle case if texture exceeds max size
  12781. if (image.width > maxSize || image.height > maxSize) {
  12782. scale = maxSize / Math.max(image.width, image.height);
  12783. } // only perform resize if necessary
  12784. if (scale < 1 || needsPowerOfTwo === true) {
  12785. // only perform resize for certain image types
  12786. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12787. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12788. var width = floor(scale * image.width);
  12789. var height = floor(scale * image.height);
  12790. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12791. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12792. canvas.width = width;
  12793. canvas.height = height;
  12794. var context = canvas.getContext('2d');
  12795. context.drawImage(image, 0, 0, width, height);
  12796. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12797. return canvas;
  12798. } else {
  12799. if ('data' in image) {
  12800. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12801. }
  12802. return image;
  12803. }
  12804. }
  12805. return image;
  12806. }
  12807. function isPowerOfTwo(image) {
  12808. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12809. }
  12810. function textureNeedsPowerOfTwo(texture) {
  12811. if (isWebGL2) return false;
  12812. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12813. }
  12814. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12815. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12816. }
  12817. function generateMipmap(target, texture, width, height) {
  12818. _gl.generateMipmap(target);
  12819. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12820. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12821. }
  12822. function getInternalFormat(internalFormatName, glFormat, glType) {
  12823. if (isWebGL2 === false) return glFormat;
  12824. if (internalFormatName !== null) {
  12825. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12826. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12827. }
  12828. var internalFormat = glFormat;
  12829. if (glFormat === 6403) {
  12830. if (glType === 5126) internalFormat = 33326;
  12831. if (glType === 5131) internalFormat = 33325;
  12832. if (glType === 5121) internalFormat = 33321;
  12833. }
  12834. if (glFormat === 6407) {
  12835. if (glType === 5126) internalFormat = 34837;
  12836. if (glType === 5131) internalFormat = 34843;
  12837. if (glType === 5121) internalFormat = 32849;
  12838. }
  12839. if (glFormat === 6408) {
  12840. if (glType === 5126) internalFormat = 34836;
  12841. if (glType === 5131) internalFormat = 34842;
  12842. if (glType === 5121) internalFormat = 32856;
  12843. }
  12844. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12845. extensions.get('EXT_color_buffer_float');
  12846. }
  12847. return internalFormat;
  12848. } // Fallback filters for non-power-of-2 textures
  12849. function filterFallback(f) {
  12850. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12851. return 9728;
  12852. }
  12853. return 9729;
  12854. } //
  12855. function onTextureDispose(event) {
  12856. var texture = event.target;
  12857. texture.removeEventListener('dispose', onTextureDispose);
  12858. deallocateTexture(texture);
  12859. if (texture.isVideoTexture) {
  12860. _videoTextures.delete(texture);
  12861. }
  12862. info.memory.textures--;
  12863. }
  12864. function onRenderTargetDispose(event) {
  12865. var renderTarget = event.target;
  12866. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12867. deallocateRenderTarget(renderTarget);
  12868. info.memory.textures--;
  12869. } //
  12870. function deallocateTexture(texture) {
  12871. var textureProperties = properties.get(texture);
  12872. if (textureProperties.__webglInit === undefined) return;
  12873. _gl.deleteTexture(textureProperties.__webglTexture);
  12874. properties.remove(texture);
  12875. }
  12876. function deallocateRenderTarget(renderTarget) {
  12877. var renderTargetProperties = properties.get(renderTarget);
  12878. var textureProperties = properties.get(renderTarget.texture);
  12879. if (!renderTarget) return;
  12880. if (textureProperties.__webglTexture !== undefined) {
  12881. _gl.deleteTexture(textureProperties.__webglTexture);
  12882. }
  12883. if (renderTarget.depthTexture) {
  12884. renderTarget.depthTexture.dispose();
  12885. }
  12886. if (renderTarget.isWebGLCubeRenderTarget) {
  12887. for (var i = 0; i < 6; i++) {
  12888. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12889. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12890. }
  12891. } else {
  12892. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12893. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12894. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12895. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12896. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12897. }
  12898. properties.remove(renderTarget.texture);
  12899. properties.remove(renderTarget);
  12900. } //
  12901. var textureUnits = 0;
  12902. function resetTextureUnits() {
  12903. textureUnits = 0;
  12904. }
  12905. function allocateTextureUnit() {
  12906. var textureUnit = textureUnits;
  12907. if (textureUnit >= maxTextures) {
  12908. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12909. }
  12910. textureUnits += 1;
  12911. return textureUnit;
  12912. } //
  12913. function setTexture2D(texture, slot) {
  12914. var textureProperties = properties.get(texture);
  12915. if (texture.isVideoTexture) updateVideoTexture(texture);
  12916. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12917. var image = texture.image;
  12918. if (image === undefined) {
  12919. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12920. } else if (image.complete === false) {
  12921. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12922. } else {
  12923. uploadTexture(textureProperties, texture, slot);
  12924. return;
  12925. }
  12926. }
  12927. state.activeTexture(33984 + slot);
  12928. state.bindTexture(3553, textureProperties.__webglTexture);
  12929. }
  12930. function setTexture2DArray(texture, slot) {
  12931. var textureProperties = properties.get(texture);
  12932. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12933. uploadTexture(textureProperties, texture, slot);
  12934. return;
  12935. }
  12936. state.activeTexture(33984 + slot);
  12937. state.bindTexture(35866, textureProperties.__webglTexture);
  12938. }
  12939. function setTexture3D(texture, slot) {
  12940. var textureProperties = properties.get(texture);
  12941. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12942. uploadTexture(textureProperties, texture, slot);
  12943. return;
  12944. }
  12945. state.activeTexture(33984 + slot);
  12946. state.bindTexture(32879, textureProperties.__webglTexture);
  12947. }
  12948. function setTextureCube(texture, slot) {
  12949. var textureProperties = properties.get(texture);
  12950. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12951. uploadCubeTexture(textureProperties, texture, slot);
  12952. return;
  12953. }
  12954. state.activeTexture(33984 + slot);
  12955. state.bindTexture(34067, textureProperties.__webglTexture);
  12956. }
  12957. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12958. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12959. function setTextureParameters(textureType, texture, supportsMips) {
  12960. if (supportsMips) {
  12961. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12962. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12963. if (textureType === 32879 || textureType === 35866) {
  12964. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12965. }
  12966. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12967. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12968. } else {
  12969. _gl.texParameteri(textureType, 10242, 33071);
  12970. _gl.texParameteri(textureType, 10243, 33071);
  12971. if (textureType === 32879 || textureType === 35866) {
  12972. _gl.texParameteri(textureType, 32882, 33071);
  12973. }
  12974. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12975. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12976. }
  12977. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12978. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12979. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12980. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12981. }
  12982. }
  12983. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12984. if (extension) {
  12985. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12986. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12987. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12988. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12989. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12990. }
  12991. }
  12992. }
  12993. function initTexture(textureProperties, texture) {
  12994. if (textureProperties.__webglInit === undefined) {
  12995. textureProperties.__webglInit = true;
  12996. texture.addEventListener('dispose', onTextureDispose);
  12997. textureProperties.__webglTexture = _gl.createTexture();
  12998. info.memory.textures++;
  12999. }
  13000. }
  13001. function uploadTexture(textureProperties, texture, slot) {
  13002. var textureType = 3553;
  13003. if (texture.isDataTexture2DArray) textureType = 35866;
  13004. if (texture.isDataTexture3D) textureType = 32879;
  13005. initTexture(textureProperties, texture);
  13006. state.activeTexture(33984 + slot);
  13007. state.bindTexture(textureType, textureProperties.__webglTexture);
  13008. _gl.pixelStorei(37440, texture.flipY);
  13009. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13010. _gl.pixelStorei(3317, texture.unpackAlignment);
  13011. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13012. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13013. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13014. glFormat = utils.convert(texture.format);
  13015. var glType = utils.convert(texture.type),
  13016. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13017. setTextureParameters(textureType, texture, supportsMips);
  13018. var mipmap;
  13019. var mipmaps = texture.mipmaps;
  13020. if (texture.isDepthTexture) {
  13021. // populate depth texture with dummy data
  13022. glInternalFormat = 6402;
  13023. if (isWebGL2) {
  13024. if (texture.type === FloatType) {
  13025. glInternalFormat = 36012;
  13026. } else if (texture.type === UnsignedIntType) {
  13027. glInternalFormat = 33190;
  13028. } else if (texture.type === UnsignedInt248Type) {
  13029. glInternalFormat = 35056;
  13030. } else {
  13031. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13032. }
  13033. } else {
  13034. if (texture.type === FloatType) {
  13035. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13036. }
  13037. } // validation checks for WebGL 1
  13038. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13039. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13040. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13041. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13042. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13043. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13044. texture.type = UnsignedShortType;
  13045. glType = utils.convert(texture.type);
  13046. }
  13047. }
  13048. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13049. // Depth stencil textures need the DEPTH_STENCIL internal format
  13050. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13051. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13052. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13053. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13054. if (texture.type !== UnsignedInt248Type) {
  13055. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13056. texture.type = UnsignedInt248Type;
  13057. glType = utils.convert(texture.type);
  13058. }
  13059. } //
  13060. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13061. } else if (texture.isDataTexture) {
  13062. // use manually created mipmaps if available
  13063. // if there are no manual mipmaps
  13064. // set 0 level mipmap and then use GL to generate other mipmap levels
  13065. if (mipmaps.length > 0 && supportsMips) {
  13066. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13067. mipmap = mipmaps[i];
  13068. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13069. }
  13070. texture.generateMipmaps = false;
  13071. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13072. } else {
  13073. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13074. textureProperties.__maxMipLevel = 0;
  13075. }
  13076. } else if (texture.isCompressedTexture) {
  13077. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13078. mipmap = mipmaps[_i];
  13079. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13080. if (glFormat !== null) {
  13081. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13082. } else {
  13083. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13084. }
  13085. } else {
  13086. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13087. }
  13088. }
  13089. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13090. } else if (texture.isDataTexture2DArray) {
  13091. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13092. textureProperties.__maxMipLevel = 0;
  13093. } else if (texture.isDataTexture3D) {
  13094. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13095. textureProperties.__maxMipLevel = 0;
  13096. } else {
  13097. // regular Texture (image, video, canvas)
  13098. // use manually created mipmaps if available
  13099. // if there are no manual mipmaps
  13100. // set 0 level mipmap and then use GL to generate other mipmap levels
  13101. if (mipmaps.length > 0 && supportsMips) {
  13102. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13103. mipmap = mipmaps[_i2];
  13104. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13105. }
  13106. texture.generateMipmaps = false;
  13107. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13108. } else {
  13109. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13110. textureProperties.__maxMipLevel = 0;
  13111. }
  13112. }
  13113. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13114. generateMipmap(textureType, texture, image.width, image.height);
  13115. }
  13116. textureProperties.__version = texture.version;
  13117. if (texture.onUpdate) texture.onUpdate(texture);
  13118. }
  13119. function uploadCubeTexture(textureProperties, texture, slot) {
  13120. if (texture.image.length !== 6) return;
  13121. initTexture(textureProperties, texture);
  13122. state.activeTexture(33984 + slot);
  13123. state.bindTexture(34067, textureProperties.__webglTexture);
  13124. _gl.pixelStorei(37440, texture.flipY);
  13125. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13126. _gl.pixelStorei(3317, texture.unpackAlignment);
  13127. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13128. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13129. var cubeImage = [];
  13130. for (var i = 0; i < 6; i++) {
  13131. if (!isCompressed && !isDataTexture) {
  13132. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13133. } else {
  13134. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13135. }
  13136. }
  13137. var image = cubeImage[0],
  13138. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13139. glFormat = utils.convert(texture.format),
  13140. glType = utils.convert(texture.type),
  13141. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13142. setTextureParameters(34067, texture, supportsMips);
  13143. var mipmaps;
  13144. if (isCompressed) {
  13145. for (var _i3 = 0; _i3 < 6; _i3++) {
  13146. mipmaps = cubeImage[_i3].mipmaps;
  13147. for (var j = 0; j < mipmaps.length; j++) {
  13148. var mipmap = mipmaps[j];
  13149. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13150. if (glFormat !== null) {
  13151. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13152. } else {
  13153. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13154. }
  13155. } else {
  13156. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13157. }
  13158. }
  13159. }
  13160. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13161. } else {
  13162. mipmaps = texture.mipmaps;
  13163. for (var _i4 = 0; _i4 < 6; _i4++) {
  13164. if (isDataTexture) {
  13165. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13166. for (var _j = 0; _j < mipmaps.length; _j++) {
  13167. var _mipmap = mipmaps[_j];
  13168. var mipmapImage = _mipmap.image[_i4].image;
  13169. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13170. }
  13171. } else {
  13172. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13173. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13174. var _mipmap2 = mipmaps[_j2];
  13175. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13176. }
  13177. }
  13178. }
  13179. textureProperties.__maxMipLevel = mipmaps.length;
  13180. }
  13181. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13182. // We assume images for cube map have the same size.
  13183. generateMipmap(34067, texture, image.width, image.height);
  13184. }
  13185. textureProperties.__version = texture.version;
  13186. if (texture.onUpdate) texture.onUpdate(texture);
  13187. } // Render targets
  13188. // Setup storage for target texture and bind it to correct framebuffer
  13189. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13190. var glFormat = utils.convert(renderTarget.texture.format);
  13191. var glType = utils.convert(renderTarget.texture.type);
  13192. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13193. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13194. _gl.bindFramebuffer(36160, framebuffer);
  13195. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13196. _gl.bindFramebuffer(36160, null);
  13197. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13198. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13199. _gl.bindRenderbuffer(36161, renderbuffer);
  13200. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13201. var glInternalFormat = 33189;
  13202. if (isMultisample) {
  13203. var depthTexture = renderTarget.depthTexture;
  13204. if (depthTexture && depthTexture.isDepthTexture) {
  13205. if (depthTexture.type === FloatType) {
  13206. glInternalFormat = 36012;
  13207. } else if (depthTexture.type === UnsignedIntType) {
  13208. glInternalFormat = 33190;
  13209. }
  13210. }
  13211. var samples = getRenderTargetSamples(renderTarget);
  13212. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13213. } else {
  13214. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13215. }
  13216. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13217. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13218. if (isMultisample) {
  13219. var _samples = getRenderTargetSamples(renderTarget);
  13220. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13221. } else {
  13222. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13223. }
  13224. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13225. } else {
  13226. var glFormat = utils.convert(renderTarget.texture.format);
  13227. var glType = utils.convert(renderTarget.texture.type);
  13228. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13229. if (isMultisample) {
  13230. var _samples2 = getRenderTargetSamples(renderTarget);
  13231. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13232. } else {
  13233. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13234. }
  13235. }
  13236. _gl.bindRenderbuffer(36161, null);
  13237. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13238. function setupDepthTexture(framebuffer, renderTarget) {
  13239. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13240. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13241. _gl.bindFramebuffer(36160, framebuffer);
  13242. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13243. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13244. } // upload an empty depth texture with framebuffer size
  13245. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13246. renderTarget.depthTexture.image.width = renderTarget.width;
  13247. renderTarget.depthTexture.image.height = renderTarget.height;
  13248. renderTarget.depthTexture.needsUpdate = true;
  13249. }
  13250. setTexture2D(renderTarget.depthTexture, 0);
  13251. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13252. if (renderTarget.depthTexture.format === DepthFormat) {
  13253. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13254. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13255. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13256. } else {
  13257. throw new Error('Unknown depthTexture format');
  13258. }
  13259. } // Setup GL resources for a non-texture depth buffer
  13260. function setupDepthRenderbuffer(renderTarget) {
  13261. var renderTargetProperties = properties.get(renderTarget);
  13262. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13263. if (renderTarget.depthTexture) {
  13264. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13265. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13266. } else {
  13267. if (isCube) {
  13268. renderTargetProperties.__webglDepthbuffer = [];
  13269. for (var i = 0; i < 6; i++) {
  13270. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13271. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13272. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13273. }
  13274. } else {
  13275. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13276. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13277. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13278. }
  13279. }
  13280. _gl.bindFramebuffer(36160, null);
  13281. } // Set up GL resources for the render target
  13282. function setupRenderTarget(renderTarget) {
  13283. var renderTargetProperties = properties.get(renderTarget);
  13284. var textureProperties = properties.get(renderTarget.texture);
  13285. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13286. textureProperties.__webglTexture = _gl.createTexture();
  13287. info.memory.textures++;
  13288. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13289. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13290. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13291. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13292. renderTarget.texture.format = RGBAFormat;
  13293. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13294. } // Setup framebuffer
  13295. if (isCube) {
  13296. renderTargetProperties.__webglFramebuffer = [];
  13297. for (var i = 0; i < 6; i++) {
  13298. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13299. }
  13300. } else {
  13301. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13302. if (isMultisample) {
  13303. if (isWebGL2) {
  13304. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13305. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13306. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13307. var glFormat = utils.convert(renderTarget.texture.format);
  13308. var glType = utils.convert(renderTarget.texture.type);
  13309. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13310. var samples = getRenderTargetSamples(renderTarget);
  13311. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13312. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13313. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13314. _gl.bindRenderbuffer(36161, null);
  13315. if (renderTarget.depthBuffer) {
  13316. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13317. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13318. }
  13319. _gl.bindFramebuffer(36160, null);
  13320. } else {
  13321. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13322. }
  13323. }
  13324. } // Setup color buffer
  13325. if (isCube) {
  13326. state.bindTexture(34067, textureProperties.__webglTexture);
  13327. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13328. for (var _i5 = 0; _i5 < 6; _i5++) {
  13329. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13330. }
  13331. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13332. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13333. }
  13334. state.bindTexture(34067, null);
  13335. } else {
  13336. state.bindTexture(3553, textureProperties.__webglTexture);
  13337. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13338. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13339. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13340. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13341. }
  13342. state.bindTexture(3553, null);
  13343. } // Setup depth and stencil buffers
  13344. if (renderTarget.depthBuffer) {
  13345. setupDepthRenderbuffer(renderTarget);
  13346. }
  13347. }
  13348. function updateRenderTargetMipmap(renderTarget) {
  13349. var texture = renderTarget.texture;
  13350. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13351. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13352. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13353. var webglTexture = properties.get(texture).__webglTexture;
  13354. state.bindTexture(target, webglTexture);
  13355. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13356. state.bindTexture(target, null);
  13357. }
  13358. }
  13359. function updateMultisampleRenderTarget(renderTarget) {
  13360. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13361. if (isWebGL2) {
  13362. var renderTargetProperties = properties.get(renderTarget);
  13363. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13364. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13365. var width = renderTarget.width;
  13366. var height = renderTarget.height;
  13367. var mask = 16384;
  13368. if (renderTarget.depthBuffer) mask |= 256;
  13369. if (renderTarget.stencilBuffer) mask |= 1024;
  13370. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13371. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13372. } else {
  13373. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13374. }
  13375. }
  13376. }
  13377. function getRenderTargetSamples(renderTarget) {
  13378. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13379. }
  13380. function updateVideoTexture(texture) {
  13381. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13382. if (_videoTextures.get(texture) !== frame) {
  13383. _videoTextures.set(texture, frame);
  13384. texture.update();
  13385. }
  13386. } // backwards compatibility
  13387. var warnedTexture2D = false;
  13388. var warnedTextureCube = false;
  13389. function safeSetTexture2D(texture, slot) {
  13390. if (texture && texture.isWebGLRenderTarget) {
  13391. if (warnedTexture2D === false) {
  13392. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13393. warnedTexture2D = true;
  13394. }
  13395. texture = texture.texture;
  13396. }
  13397. setTexture2D(texture, slot);
  13398. }
  13399. function safeSetTextureCube(texture, slot) {
  13400. if (texture && texture.isWebGLCubeRenderTarget) {
  13401. if (warnedTextureCube === false) {
  13402. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13403. warnedTextureCube = true;
  13404. }
  13405. texture = texture.texture;
  13406. }
  13407. setTextureCube(texture, slot);
  13408. } //
  13409. this.allocateTextureUnit = allocateTextureUnit;
  13410. this.resetTextureUnits = resetTextureUnits;
  13411. this.setTexture2D = setTexture2D;
  13412. this.setTexture2DArray = setTexture2DArray;
  13413. this.setTexture3D = setTexture3D;
  13414. this.setTextureCube = setTextureCube;
  13415. this.setupRenderTarget = setupRenderTarget;
  13416. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13417. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13418. this.safeSetTexture2D = safeSetTexture2D;
  13419. this.safeSetTextureCube = safeSetTextureCube;
  13420. }
  13421. function WebGLUtils(gl, extensions, capabilities) {
  13422. var isWebGL2 = capabilities.isWebGL2;
  13423. function convert(p) {
  13424. var extension;
  13425. if (p === UnsignedByteType) return 5121;
  13426. if (p === UnsignedShort4444Type) return 32819;
  13427. if (p === UnsignedShort5551Type) return 32820;
  13428. if (p === UnsignedShort565Type) return 33635;
  13429. if (p === ByteType) return 5120;
  13430. if (p === ShortType) return 5122;
  13431. if (p === UnsignedShortType) return 5123;
  13432. if (p === IntType) return 5124;
  13433. if (p === UnsignedIntType) return 5125;
  13434. if (p === FloatType) return 5126;
  13435. if (p === HalfFloatType) {
  13436. if (isWebGL2) return 5131;
  13437. extension = extensions.get('OES_texture_half_float');
  13438. if (extension !== null) {
  13439. return extension.HALF_FLOAT_OES;
  13440. } else {
  13441. return null;
  13442. }
  13443. }
  13444. if (p === AlphaFormat) return 6406;
  13445. if (p === RGBFormat) return 6407;
  13446. if (p === RGBAFormat) return 6408;
  13447. if (p === LuminanceFormat) return 6409;
  13448. if (p === LuminanceAlphaFormat) return 6410;
  13449. if (p === DepthFormat) return 6402;
  13450. if (p === DepthStencilFormat) return 34041;
  13451. if (p === RedFormat) return 6403; // WebGL2 formats.
  13452. if (p === RedIntegerFormat) return 36244;
  13453. if (p === RGFormat) return 33319;
  13454. if (p === RGIntegerFormat) return 33320;
  13455. if (p === RGBIntegerFormat) return 36248;
  13456. if (p === RGBAIntegerFormat) return 36249;
  13457. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13458. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13459. if (extension !== null) {
  13460. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13461. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13462. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13463. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13464. } else {
  13465. return null;
  13466. }
  13467. }
  13468. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13469. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13470. if (extension !== null) {
  13471. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13472. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13473. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13474. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13475. } else {
  13476. return null;
  13477. }
  13478. }
  13479. if (p === RGB_ETC1_Format) {
  13480. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13481. if (extension !== null) {
  13482. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13483. } else {
  13484. return null;
  13485. }
  13486. }
  13487. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13488. extension = extensions.get('WEBGL_compressed_texture_etc');
  13489. if (extension !== null) {
  13490. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13491. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13492. }
  13493. }
  13494. 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) {
  13495. extension = extensions.get('WEBGL_compressed_texture_astc');
  13496. if (extension !== null) {
  13497. // TODO Complete?
  13498. return p;
  13499. } else {
  13500. return null;
  13501. }
  13502. }
  13503. if (p === RGBA_BPTC_Format) {
  13504. extension = extensions.get('EXT_texture_compression_bptc');
  13505. if (extension !== null) {
  13506. // TODO Complete?
  13507. return p;
  13508. } else {
  13509. return null;
  13510. }
  13511. }
  13512. if (p === UnsignedInt248Type) {
  13513. if (isWebGL2) return 34042;
  13514. extension = extensions.get('WEBGL_depth_texture');
  13515. if (extension !== null) {
  13516. return extension.UNSIGNED_INT_24_8_WEBGL;
  13517. } else {
  13518. return null;
  13519. }
  13520. }
  13521. }
  13522. return {
  13523. convert: convert
  13524. };
  13525. }
  13526. function ArrayCamera(array) {
  13527. if (array === void 0) {
  13528. array = [];
  13529. }
  13530. PerspectiveCamera.call(this);
  13531. this.cameras = array;
  13532. }
  13533. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13534. constructor: ArrayCamera,
  13535. isArrayCamera: true
  13536. });
  13537. function Group() {
  13538. Object3D.call(this);
  13539. this.type = 'Group';
  13540. }
  13541. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13542. constructor: Group,
  13543. isGroup: true
  13544. });
  13545. function WebXRController() {
  13546. this._targetRay = null;
  13547. this._grip = null;
  13548. this._hand = null;
  13549. }
  13550. Object.assign(WebXRController.prototype, {
  13551. constructor: WebXRController,
  13552. getHandSpace: function getHandSpace() {
  13553. if (this._hand === null) {
  13554. this._hand = new Group();
  13555. this._hand.matrixAutoUpdate = false;
  13556. this._hand.visible = false;
  13557. this._hand.joints = [];
  13558. this._hand.inputState = {
  13559. pinching: false
  13560. };
  13561. if (window.XRHand) {
  13562. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13563. // The transform of this joint will be updated with the joint pose on each frame
  13564. var joint = new Group();
  13565. joint.matrixAutoUpdate = false;
  13566. joint.visible = false;
  13567. this._hand.joints.push(joint); // ??
  13568. this._hand.add(joint);
  13569. }
  13570. }
  13571. }
  13572. return this._hand;
  13573. },
  13574. getTargetRaySpace: function getTargetRaySpace() {
  13575. if (this._targetRay === null) {
  13576. this._targetRay = new Group();
  13577. this._targetRay.matrixAutoUpdate = false;
  13578. this._targetRay.visible = false;
  13579. }
  13580. return this._targetRay;
  13581. },
  13582. getGripSpace: function getGripSpace() {
  13583. if (this._grip === null) {
  13584. this._grip = new Group();
  13585. this._grip.matrixAutoUpdate = false;
  13586. this._grip.visible = false;
  13587. }
  13588. return this._grip;
  13589. },
  13590. dispatchEvent: function dispatchEvent(event) {
  13591. if (this._targetRay !== null) {
  13592. this._targetRay.dispatchEvent(event);
  13593. }
  13594. if (this._grip !== null) {
  13595. this._grip.dispatchEvent(event);
  13596. }
  13597. if (this._hand !== null) {
  13598. this._hand.dispatchEvent(event);
  13599. }
  13600. return this;
  13601. },
  13602. disconnect: function disconnect(inputSource) {
  13603. this.dispatchEvent({
  13604. type: 'disconnected',
  13605. data: inputSource
  13606. });
  13607. if (this._targetRay !== null) {
  13608. this._targetRay.visible = false;
  13609. }
  13610. if (this._grip !== null) {
  13611. this._grip.visible = false;
  13612. }
  13613. if (this._hand !== null) {
  13614. this._hand.visible = false;
  13615. }
  13616. return this;
  13617. },
  13618. update: function update(inputSource, frame, referenceSpace) {
  13619. var inputPose = null;
  13620. var gripPose = null;
  13621. var handPose = null;
  13622. var targetRay = this._targetRay;
  13623. var grip = this._grip;
  13624. var hand = this._hand;
  13625. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  13626. if (hand && inputSource.hand) {
  13627. handPose = true;
  13628. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13629. if (inputSource.hand[i]) {
  13630. // Update the joints groups with the XRJoint poses
  13631. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13632. var joint = hand.joints[i];
  13633. if (jointPose !== null) {
  13634. joint.matrix.fromArray(jointPose.transform.matrix);
  13635. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13636. joint.jointRadius = jointPose.radius;
  13637. }
  13638. joint.visible = jointPose !== null; // Custom events
  13639. // Check pinch
  13640. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13641. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13642. var distance = indexTip.position.distanceTo(thumbTip.position);
  13643. var distanceToPinch = 0.02;
  13644. var threshold = 0.005;
  13645. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13646. hand.inputState.pinching = false;
  13647. this.dispatchEvent({
  13648. type: 'pinchend',
  13649. handedness: inputSource.handedness,
  13650. target: this
  13651. });
  13652. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13653. hand.inputState.pinching = true;
  13654. this.dispatchEvent({
  13655. type: 'pinchstart',
  13656. handedness: inputSource.handedness,
  13657. target: this
  13658. });
  13659. }
  13660. }
  13661. }
  13662. } else {
  13663. if (targetRay !== null) {
  13664. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13665. if (inputPose !== null) {
  13666. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13667. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13668. }
  13669. }
  13670. if (grip !== null && inputSource.gripSpace) {
  13671. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13672. if (gripPose !== null) {
  13673. grip.matrix.fromArray(gripPose.transform.matrix);
  13674. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13675. }
  13676. }
  13677. }
  13678. }
  13679. if (targetRay !== null) {
  13680. targetRay.visible = inputPose !== null;
  13681. }
  13682. if (grip !== null) {
  13683. grip.visible = gripPose !== null;
  13684. }
  13685. if (hand !== null) {
  13686. hand.visible = handPose !== null;
  13687. }
  13688. return this;
  13689. }
  13690. });
  13691. function WebXRManager(renderer, gl) {
  13692. var scope = this;
  13693. var session = null;
  13694. var framebufferScaleFactor = 1.0;
  13695. var referenceSpace = null;
  13696. var referenceSpaceType = 'local-floor';
  13697. var pose = null;
  13698. var controllers = [];
  13699. var inputSourcesMap = new Map(); //
  13700. var cameraL = new PerspectiveCamera();
  13701. cameraL.layers.enable(1);
  13702. cameraL.viewport = new Vector4();
  13703. var cameraR = new PerspectiveCamera();
  13704. cameraR.layers.enable(2);
  13705. cameraR.viewport = new Vector4();
  13706. var cameras = [cameraL, cameraR];
  13707. var cameraVR = new ArrayCamera();
  13708. cameraVR.layers.enable(1);
  13709. cameraVR.layers.enable(2);
  13710. var _currentDepthNear = null;
  13711. var _currentDepthFar = null; //
  13712. this.enabled = false;
  13713. this.isPresenting = false;
  13714. this.getController = function (index) {
  13715. var controller = controllers[index];
  13716. if (controller === undefined) {
  13717. controller = new WebXRController();
  13718. controllers[index] = controller;
  13719. }
  13720. return controller.getTargetRaySpace();
  13721. };
  13722. this.getControllerGrip = function (index) {
  13723. var controller = controllers[index];
  13724. if (controller === undefined) {
  13725. controller = new WebXRController();
  13726. controllers[index] = controller;
  13727. }
  13728. return controller.getGripSpace();
  13729. };
  13730. this.getHand = function (index) {
  13731. var controller = controllers[index];
  13732. if (controller === undefined) {
  13733. controller = new WebXRController();
  13734. controllers[index] = controller;
  13735. }
  13736. return controller.getHandSpace();
  13737. }; //
  13738. function onSessionEvent(event) {
  13739. var controller = inputSourcesMap.get(event.inputSource);
  13740. if (controller) {
  13741. controller.dispatchEvent({
  13742. type: event.type,
  13743. data: event.inputSource
  13744. });
  13745. }
  13746. }
  13747. function onSessionEnd() {
  13748. inputSourcesMap.forEach(function (controller, inputSource) {
  13749. controller.disconnect(inputSource);
  13750. });
  13751. inputSourcesMap.clear(); //
  13752. renderer.setFramebuffer(null);
  13753. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13754. animation.stop();
  13755. scope.isPresenting = false;
  13756. scope.dispatchEvent({
  13757. type: 'sessionend'
  13758. });
  13759. }
  13760. function onRequestReferenceSpace(value) {
  13761. referenceSpace = value;
  13762. animation.setContext(session);
  13763. animation.start();
  13764. scope.isPresenting = true;
  13765. scope.dispatchEvent({
  13766. type: 'sessionstart'
  13767. });
  13768. }
  13769. this.setFramebufferScaleFactor = function (value) {
  13770. framebufferScaleFactor = value;
  13771. if (scope.isPresenting === true) {
  13772. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13773. }
  13774. };
  13775. this.setReferenceSpaceType = function (value) {
  13776. referenceSpaceType = value;
  13777. if (scope.isPresenting === true) {
  13778. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13779. }
  13780. };
  13781. this.getReferenceSpace = function () {
  13782. return referenceSpace;
  13783. };
  13784. this.getSession = function () {
  13785. return session;
  13786. };
  13787. this.setSession = function (value) {
  13788. session = value;
  13789. if (session !== null) {
  13790. session.addEventListener('select', onSessionEvent);
  13791. session.addEventListener('selectstart', onSessionEvent);
  13792. session.addEventListener('selectend', onSessionEvent);
  13793. session.addEventListener('squeeze', onSessionEvent);
  13794. session.addEventListener('squeezestart', onSessionEvent);
  13795. session.addEventListener('squeezeend', onSessionEvent);
  13796. session.addEventListener('end', onSessionEnd);
  13797. var attributes = gl.getContextAttributes();
  13798. if (attributes.xrCompatible !== true) {
  13799. gl.makeXRCompatible();
  13800. }
  13801. var layerInit = {
  13802. antialias: attributes.antialias,
  13803. alpha: attributes.alpha,
  13804. depth: attributes.depth,
  13805. stencil: attributes.stencil,
  13806. framebufferScaleFactor: framebufferScaleFactor
  13807. }; // eslint-disable-next-line no-undef
  13808. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13809. session.updateRenderState({
  13810. baseLayer: baseLayer
  13811. });
  13812. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13813. session.addEventListener('inputsourceschange', updateInputSources);
  13814. }
  13815. };
  13816. function updateInputSources(event) {
  13817. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13818. for (var i = 0; i < controllers.length; i++) {
  13819. inputSourcesMap.set(inputSources[i], controllers[i]);
  13820. } // Notify disconnected
  13821. for (var _i = 0; _i < event.removed.length; _i++) {
  13822. var inputSource = event.removed[_i];
  13823. var controller = inputSourcesMap.get(inputSource);
  13824. if (controller) {
  13825. controller.dispatchEvent({
  13826. type: 'disconnected',
  13827. data: inputSource
  13828. });
  13829. inputSourcesMap.delete(inputSource);
  13830. }
  13831. } // Notify connected
  13832. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13833. var _inputSource = event.added[_i2];
  13834. var _controller = inputSourcesMap.get(_inputSource);
  13835. if (_controller) {
  13836. _controller.dispatchEvent({
  13837. type: 'connected',
  13838. data: _inputSource
  13839. });
  13840. }
  13841. }
  13842. } //
  13843. var cameraLPos = new Vector3();
  13844. var cameraRPos = new Vector3();
  13845. /**
  13846. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13847. * the cameras' projection and world matrices have already been set.
  13848. * And that near and far planes are identical for both cameras.
  13849. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13850. */
  13851. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13852. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13853. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13854. var ipd = cameraLPos.distanceTo(cameraRPos);
  13855. var projL = cameraL.projectionMatrix.elements;
  13856. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13857. // most likely identical top and bottom frustum extents.
  13858. // Use the left camera for these values.
  13859. var near = projL[14] / (projL[10] - 1);
  13860. var far = projL[14] / (projL[10] + 1);
  13861. var topFov = (projL[9] + 1) / projL[5];
  13862. var bottomFov = (projL[9] - 1) / projL[5];
  13863. var leftFov = (projL[8] - 1) / projL[0];
  13864. var rightFov = (projR[8] + 1) / projR[0];
  13865. var left = near * leftFov;
  13866. var right = near * rightFov; // Calculate the new camera's position offset from the
  13867. // left camera. xOffset should be roughly half `ipd`.
  13868. var zOffset = ipd / (-leftFov + rightFov);
  13869. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13870. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13871. camera.translateX(xOffset);
  13872. camera.translateZ(zOffset);
  13873. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13874. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  13875. // the values so that the near plane's position does not change in world space,
  13876. // although must now be relative to the new union camera.
  13877. var near2 = near + zOffset;
  13878. var far2 = far + zOffset;
  13879. var left2 = left - xOffset;
  13880. var right2 = right + (ipd - xOffset);
  13881. var top2 = topFov * far / far2 * near2;
  13882. var bottom2 = bottomFov * far / far2 * near2;
  13883. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13884. }
  13885. function updateCamera(camera, parent) {
  13886. if (parent === null) {
  13887. camera.matrixWorld.copy(camera.matrix);
  13888. } else {
  13889. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13890. }
  13891. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  13892. }
  13893. this.getCamera = function (camera) {
  13894. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13895. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13896. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13897. // Note that the new renderState won't apply until the next frame. See #18320
  13898. session.updateRenderState({
  13899. depthNear: cameraVR.near,
  13900. depthFar: cameraVR.far
  13901. });
  13902. _currentDepthNear = cameraVR.near;
  13903. _currentDepthFar = cameraVR.far;
  13904. }
  13905. var parent = camera.parent;
  13906. var cameras = cameraVR.cameras;
  13907. updateCamera(cameraVR, parent);
  13908. for (var i = 0; i < cameras.length; i++) {
  13909. updateCamera(cameras[i], parent);
  13910. } // update camera and its children
  13911. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13912. var children = camera.children;
  13913. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13914. children[_i3].updateMatrixWorld(true);
  13915. } // update projection matrix for proper view frustum culling
  13916. if (cameras.length === 2) {
  13917. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13918. } else {
  13919. // assume single camera setup (AR)
  13920. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13921. }
  13922. return cameraVR;
  13923. }; // Animation Loop
  13924. var onAnimationFrameCallback = null;
  13925. function onAnimationFrame(time, frame) {
  13926. pose = frame.getViewerPose(referenceSpace);
  13927. if (pose !== null) {
  13928. var views = pose.views;
  13929. var baseLayer = session.renderState.baseLayer;
  13930. renderer.setFramebuffer(baseLayer.framebuffer);
  13931. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13932. if (views.length !== cameraVR.cameras.length) {
  13933. cameraVR.cameras.length = 0;
  13934. cameraVRNeedsUpdate = true;
  13935. }
  13936. for (var i = 0; i < views.length; i++) {
  13937. var view = views[i];
  13938. var viewport = baseLayer.getViewport(view);
  13939. var camera = cameras[i];
  13940. camera.matrix.fromArray(view.transform.matrix);
  13941. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13942. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13943. if (i === 0) {
  13944. cameraVR.matrix.copy(camera.matrix);
  13945. }
  13946. if (cameraVRNeedsUpdate === true) {
  13947. cameraVR.cameras.push(camera);
  13948. }
  13949. }
  13950. } //
  13951. var inputSources = session.inputSources;
  13952. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13953. var controller = controllers[_i4];
  13954. var inputSource = inputSources[_i4];
  13955. controller.update(inputSource, frame, referenceSpace);
  13956. }
  13957. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13958. }
  13959. var animation = new WebGLAnimation();
  13960. animation.setAnimationLoop(onAnimationFrame);
  13961. this.setAnimationLoop = function (callback) {
  13962. onAnimationFrameCallback = callback;
  13963. };
  13964. this.dispose = function () {};
  13965. }
  13966. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13967. function WebGLMaterials(properties) {
  13968. function refreshFogUniforms(uniforms, fog) {
  13969. uniforms.fogColor.value.copy(fog.color);
  13970. if (fog.isFog) {
  13971. uniforms.fogNear.value = fog.near;
  13972. uniforms.fogFar.value = fog.far;
  13973. } else if (fog.isFogExp2) {
  13974. uniforms.fogDensity.value = fog.density;
  13975. }
  13976. }
  13977. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13978. if (material.isMeshBasicMaterial) {
  13979. refreshUniformsCommon(uniforms, material);
  13980. } else if (material.isMeshLambertMaterial) {
  13981. refreshUniformsCommon(uniforms, material);
  13982. refreshUniformsLambert(uniforms, material);
  13983. } else if (material.isMeshToonMaterial) {
  13984. refreshUniformsCommon(uniforms, material);
  13985. refreshUniformsToon(uniforms, material);
  13986. } else if (material.isMeshPhongMaterial) {
  13987. refreshUniformsCommon(uniforms, material);
  13988. refreshUniformsPhong(uniforms, material);
  13989. } else if (material.isMeshStandardMaterial) {
  13990. refreshUniformsCommon(uniforms, material);
  13991. if (material.isMeshPhysicalMaterial) {
  13992. refreshUniformsPhysical(uniforms, material);
  13993. } else {
  13994. refreshUniformsStandard(uniforms, material);
  13995. }
  13996. } else if (material.isMeshMatcapMaterial) {
  13997. refreshUniformsCommon(uniforms, material);
  13998. refreshUniformsMatcap(uniforms, material);
  13999. } else if (material.isMeshDepthMaterial) {
  14000. refreshUniformsCommon(uniforms, material);
  14001. refreshUniformsDepth(uniforms, material);
  14002. } else if (material.isMeshDistanceMaterial) {
  14003. refreshUniformsCommon(uniforms, material);
  14004. refreshUniformsDistance(uniforms, material);
  14005. } else if (material.isMeshNormalMaterial) {
  14006. refreshUniformsCommon(uniforms, material);
  14007. refreshUniformsNormal(uniforms, material);
  14008. } else if (material.isLineBasicMaterial) {
  14009. refreshUniformsLine(uniforms, material);
  14010. if (material.isLineDashedMaterial) {
  14011. refreshUniformsDash(uniforms, material);
  14012. }
  14013. } else if (material.isPointsMaterial) {
  14014. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14015. } else if (material.isSpriteMaterial) {
  14016. refreshUniformsSprites(uniforms, material);
  14017. } else if (material.isShadowMaterial) {
  14018. uniforms.color.value.copy(material.color);
  14019. uniforms.opacity.value = material.opacity;
  14020. } else if (material.isShaderMaterial) {
  14021. material.uniformsNeedUpdate = false; // #15581
  14022. }
  14023. }
  14024. function refreshUniformsCommon(uniforms, material) {
  14025. uniforms.opacity.value = material.opacity;
  14026. if (material.color) {
  14027. uniforms.diffuse.value.copy(material.color);
  14028. }
  14029. if (material.emissive) {
  14030. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14031. }
  14032. if (material.map) {
  14033. uniforms.map.value = material.map;
  14034. }
  14035. if (material.alphaMap) {
  14036. uniforms.alphaMap.value = material.alphaMap;
  14037. }
  14038. if (material.specularMap) {
  14039. uniforms.specularMap.value = material.specularMap;
  14040. }
  14041. var envMap = properties.get(material).envMap;
  14042. if (envMap) {
  14043. uniforms.envMap.value = envMap;
  14044. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14045. uniforms.reflectivity.value = material.reflectivity;
  14046. uniforms.refractionRatio.value = material.refractionRatio;
  14047. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14048. if (maxMipLevel !== undefined) {
  14049. uniforms.maxMipLevel.value = maxMipLevel;
  14050. }
  14051. }
  14052. if (material.lightMap) {
  14053. uniforms.lightMap.value = material.lightMap;
  14054. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14055. }
  14056. if (material.aoMap) {
  14057. uniforms.aoMap.value = material.aoMap;
  14058. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14059. } // uv repeat and offset setting priorities
  14060. // 1. color map
  14061. // 2. specular map
  14062. // 3. displacementMap map
  14063. // 4. normal map
  14064. // 5. bump map
  14065. // 6. roughnessMap map
  14066. // 7. metalnessMap map
  14067. // 8. alphaMap map
  14068. // 9. emissiveMap map
  14069. // 10. clearcoat map
  14070. // 11. clearcoat normal map
  14071. // 12. clearcoat roughnessMap map
  14072. var uvScaleMap;
  14073. if (material.map) {
  14074. uvScaleMap = material.map;
  14075. } else if (material.specularMap) {
  14076. uvScaleMap = material.specularMap;
  14077. } else if (material.displacementMap) {
  14078. uvScaleMap = material.displacementMap;
  14079. } else if (material.normalMap) {
  14080. uvScaleMap = material.normalMap;
  14081. } else if (material.bumpMap) {
  14082. uvScaleMap = material.bumpMap;
  14083. } else if (material.roughnessMap) {
  14084. uvScaleMap = material.roughnessMap;
  14085. } else if (material.metalnessMap) {
  14086. uvScaleMap = material.metalnessMap;
  14087. } else if (material.alphaMap) {
  14088. uvScaleMap = material.alphaMap;
  14089. } else if (material.emissiveMap) {
  14090. uvScaleMap = material.emissiveMap;
  14091. } else if (material.clearcoatMap) {
  14092. uvScaleMap = material.clearcoatMap;
  14093. } else if (material.clearcoatNormalMap) {
  14094. uvScaleMap = material.clearcoatNormalMap;
  14095. } else if (material.clearcoatRoughnessMap) {
  14096. uvScaleMap = material.clearcoatRoughnessMap;
  14097. }
  14098. if (uvScaleMap !== undefined) {
  14099. // backwards compatibility
  14100. if (uvScaleMap.isWebGLRenderTarget) {
  14101. uvScaleMap = uvScaleMap.texture;
  14102. }
  14103. if (uvScaleMap.matrixAutoUpdate === true) {
  14104. uvScaleMap.updateMatrix();
  14105. }
  14106. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14107. } // uv repeat and offset setting priorities for uv2
  14108. // 1. ao map
  14109. // 2. light map
  14110. var uv2ScaleMap;
  14111. if (material.aoMap) {
  14112. uv2ScaleMap = material.aoMap;
  14113. } else if (material.lightMap) {
  14114. uv2ScaleMap = material.lightMap;
  14115. }
  14116. if (uv2ScaleMap !== undefined) {
  14117. // backwards compatibility
  14118. if (uv2ScaleMap.isWebGLRenderTarget) {
  14119. uv2ScaleMap = uv2ScaleMap.texture;
  14120. }
  14121. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14122. uv2ScaleMap.updateMatrix();
  14123. }
  14124. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14125. }
  14126. }
  14127. function refreshUniformsLine(uniforms, material) {
  14128. uniforms.diffuse.value.copy(material.color);
  14129. uniforms.opacity.value = material.opacity;
  14130. }
  14131. function refreshUniformsDash(uniforms, material) {
  14132. uniforms.dashSize.value = material.dashSize;
  14133. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14134. uniforms.scale.value = material.scale;
  14135. }
  14136. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14137. uniforms.diffuse.value.copy(material.color);
  14138. uniforms.opacity.value = material.opacity;
  14139. uniforms.size.value = material.size * pixelRatio;
  14140. uniforms.scale.value = height * 0.5;
  14141. if (material.map) {
  14142. uniforms.map.value = material.map;
  14143. }
  14144. if (material.alphaMap) {
  14145. uniforms.alphaMap.value = material.alphaMap;
  14146. } // uv repeat and offset setting priorities
  14147. // 1. color map
  14148. // 2. alpha map
  14149. var uvScaleMap;
  14150. if (material.map) {
  14151. uvScaleMap = material.map;
  14152. } else if (material.alphaMap) {
  14153. uvScaleMap = material.alphaMap;
  14154. }
  14155. if (uvScaleMap !== undefined) {
  14156. if (uvScaleMap.matrixAutoUpdate === true) {
  14157. uvScaleMap.updateMatrix();
  14158. }
  14159. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14160. }
  14161. }
  14162. function refreshUniformsSprites(uniforms, material) {
  14163. uniforms.diffuse.value.copy(material.color);
  14164. uniforms.opacity.value = material.opacity;
  14165. uniforms.rotation.value = material.rotation;
  14166. if (material.map) {
  14167. uniforms.map.value = material.map;
  14168. }
  14169. if (material.alphaMap) {
  14170. uniforms.alphaMap.value = material.alphaMap;
  14171. } // uv repeat and offset setting priorities
  14172. // 1. color map
  14173. // 2. alpha map
  14174. var uvScaleMap;
  14175. if (material.map) {
  14176. uvScaleMap = material.map;
  14177. } else if (material.alphaMap) {
  14178. uvScaleMap = material.alphaMap;
  14179. }
  14180. if (uvScaleMap !== undefined) {
  14181. if (uvScaleMap.matrixAutoUpdate === true) {
  14182. uvScaleMap.updateMatrix();
  14183. }
  14184. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14185. }
  14186. }
  14187. function refreshUniformsLambert(uniforms, material) {
  14188. if (material.emissiveMap) {
  14189. uniforms.emissiveMap.value = material.emissiveMap;
  14190. }
  14191. }
  14192. function refreshUniformsPhong(uniforms, material) {
  14193. uniforms.specular.value.copy(material.specular);
  14194. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14195. if (material.emissiveMap) {
  14196. uniforms.emissiveMap.value = material.emissiveMap;
  14197. }
  14198. if (material.bumpMap) {
  14199. uniforms.bumpMap.value = material.bumpMap;
  14200. uniforms.bumpScale.value = material.bumpScale;
  14201. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14202. }
  14203. if (material.normalMap) {
  14204. uniforms.normalMap.value = material.normalMap;
  14205. uniforms.normalScale.value.copy(material.normalScale);
  14206. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14207. }
  14208. if (material.displacementMap) {
  14209. uniforms.displacementMap.value = material.displacementMap;
  14210. uniforms.displacementScale.value = material.displacementScale;
  14211. uniforms.displacementBias.value = material.displacementBias;
  14212. }
  14213. }
  14214. function refreshUniformsToon(uniforms, material) {
  14215. if (material.gradientMap) {
  14216. uniforms.gradientMap.value = material.gradientMap;
  14217. }
  14218. if (material.emissiveMap) {
  14219. uniforms.emissiveMap.value = material.emissiveMap;
  14220. }
  14221. if (material.bumpMap) {
  14222. uniforms.bumpMap.value = material.bumpMap;
  14223. uniforms.bumpScale.value = material.bumpScale;
  14224. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14225. }
  14226. if (material.normalMap) {
  14227. uniforms.normalMap.value = material.normalMap;
  14228. uniforms.normalScale.value.copy(material.normalScale);
  14229. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14230. }
  14231. if (material.displacementMap) {
  14232. uniforms.displacementMap.value = material.displacementMap;
  14233. uniforms.displacementScale.value = material.displacementScale;
  14234. uniforms.displacementBias.value = material.displacementBias;
  14235. }
  14236. }
  14237. function refreshUniformsStandard(uniforms, material) {
  14238. uniforms.roughness.value = material.roughness;
  14239. uniforms.metalness.value = material.metalness;
  14240. if (material.roughnessMap) {
  14241. uniforms.roughnessMap.value = material.roughnessMap;
  14242. }
  14243. if (material.metalnessMap) {
  14244. uniforms.metalnessMap.value = material.metalnessMap;
  14245. }
  14246. if (material.emissiveMap) {
  14247. uniforms.emissiveMap.value = material.emissiveMap;
  14248. }
  14249. if (material.bumpMap) {
  14250. uniforms.bumpMap.value = material.bumpMap;
  14251. uniforms.bumpScale.value = material.bumpScale;
  14252. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14253. }
  14254. if (material.normalMap) {
  14255. uniforms.normalMap.value = material.normalMap;
  14256. uniforms.normalScale.value.copy(material.normalScale);
  14257. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14258. }
  14259. if (material.displacementMap) {
  14260. uniforms.displacementMap.value = material.displacementMap;
  14261. uniforms.displacementScale.value = material.displacementScale;
  14262. uniforms.displacementBias.value = material.displacementBias;
  14263. }
  14264. var envMap = properties.get(material).envMap;
  14265. if (envMap) {
  14266. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14267. uniforms.envMapIntensity.value = material.envMapIntensity;
  14268. }
  14269. }
  14270. function refreshUniformsPhysical(uniforms, material) {
  14271. refreshUniformsStandard(uniforms, material);
  14272. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14273. uniforms.clearcoat.value = material.clearcoat;
  14274. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14275. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14276. if (material.clearcoatMap) {
  14277. uniforms.clearcoatMap.value = material.clearcoatMap;
  14278. }
  14279. if (material.clearcoatRoughnessMap) {
  14280. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14281. }
  14282. if (material.clearcoatNormalMap) {
  14283. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14284. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14285. if (material.side === BackSide) {
  14286. uniforms.clearcoatNormalScale.value.negate();
  14287. }
  14288. }
  14289. uniforms.transmission.value = material.transmission;
  14290. if (material.transmissionMap) {
  14291. uniforms.transmissionMap.value = material.transmissionMap;
  14292. }
  14293. }
  14294. function refreshUniformsMatcap(uniforms, material) {
  14295. if (material.matcap) {
  14296. uniforms.matcap.value = material.matcap;
  14297. }
  14298. if (material.bumpMap) {
  14299. uniforms.bumpMap.value = material.bumpMap;
  14300. uniforms.bumpScale.value = material.bumpScale;
  14301. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14302. }
  14303. if (material.normalMap) {
  14304. uniforms.normalMap.value = material.normalMap;
  14305. uniforms.normalScale.value.copy(material.normalScale);
  14306. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14307. }
  14308. if (material.displacementMap) {
  14309. uniforms.displacementMap.value = material.displacementMap;
  14310. uniforms.displacementScale.value = material.displacementScale;
  14311. uniforms.displacementBias.value = material.displacementBias;
  14312. }
  14313. }
  14314. function refreshUniformsDepth(uniforms, material) {
  14315. if (material.displacementMap) {
  14316. uniforms.displacementMap.value = material.displacementMap;
  14317. uniforms.displacementScale.value = material.displacementScale;
  14318. uniforms.displacementBias.value = material.displacementBias;
  14319. }
  14320. }
  14321. function refreshUniformsDistance(uniforms, material) {
  14322. if (material.displacementMap) {
  14323. uniforms.displacementMap.value = material.displacementMap;
  14324. uniforms.displacementScale.value = material.displacementScale;
  14325. uniforms.displacementBias.value = material.displacementBias;
  14326. }
  14327. uniforms.referencePosition.value.copy(material.referencePosition);
  14328. uniforms.nearDistance.value = material.nearDistance;
  14329. uniforms.farDistance.value = material.farDistance;
  14330. }
  14331. function refreshUniformsNormal(uniforms, material) {
  14332. if (material.bumpMap) {
  14333. uniforms.bumpMap.value = material.bumpMap;
  14334. uniforms.bumpScale.value = material.bumpScale;
  14335. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14336. }
  14337. if (material.normalMap) {
  14338. uniforms.normalMap.value = material.normalMap;
  14339. uniforms.normalScale.value.copy(material.normalScale);
  14340. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14341. }
  14342. if (material.displacementMap) {
  14343. uniforms.displacementMap.value = material.displacementMap;
  14344. uniforms.displacementScale.value = material.displacementScale;
  14345. uniforms.displacementBias.value = material.displacementBias;
  14346. }
  14347. }
  14348. return {
  14349. refreshFogUniforms: refreshFogUniforms,
  14350. refreshMaterialUniforms: refreshMaterialUniforms
  14351. };
  14352. }
  14353. function createCanvasElement() {
  14354. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14355. canvas.style.display = 'block';
  14356. return canvas;
  14357. }
  14358. function WebGLRenderer(parameters) {
  14359. parameters = parameters || {};
  14360. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14361. _context = parameters.context !== undefined ? parameters.context : null,
  14362. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14363. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14364. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14365. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14366. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14367. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14368. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14369. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14370. var currentRenderList = null;
  14371. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14372. // We track this so that the nested render call gets its state isolated from the parent render call.
  14373. var renderStateStack = []; // public properties
  14374. this.domElement = _canvas; // Debug configuration container
  14375. this.debug = {
  14376. /**
  14377. * Enables error checking and reporting when shader programs are being compiled
  14378. * @type {boolean}
  14379. */
  14380. checkShaderErrors: true
  14381. }; // clearing
  14382. this.autoClear = true;
  14383. this.autoClearColor = true;
  14384. this.autoClearDepth = true;
  14385. this.autoClearStencil = true; // scene graph
  14386. this.sortObjects = true; // user-defined clipping
  14387. this.clippingPlanes = [];
  14388. this.localClippingEnabled = false; // physically based shading
  14389. this.gammaFactor = 2.0; // for backwards compatibility
  14390. this.outputEncoding = LinearEncoding; // physical lights
  14391. this.physicallyCorrectLights = false; // tone mapping
  14392. this.toneMapping = NoToneMapping;
  14393. this.toneMappingExposure = 1.0; // morphs
  14394. this.maxMorphTargets = 8;
  14395. this.maxMorphNormals = 4; // internal properties
  14396. var _this = this;
  14397. var _isContextLost = false; // internal state cache
  14398. var _framebuffer = null;
  14399. var _currentActiveCubeFace = 0;
  14400. var _currentActiveMipmapLevel = 0;
  14401. var _currentRenderTarget = null;
  14402. var _currentFramebuffer = null;
  14403. var _currentMaterialId = -1;
  14404. var _currentCamera = null;
  14405. var _currentViewport = new Vector4();
  14406. var _currentScissor = new Vector4();
  14407. var _currentScissorTest = null; //
  14408. var _width = _canvas.width;
  14409. var _height = _canvas.height;
  14410. var _pixelRatio = 1;
  14411. var _opaqueSort = null;
  14412. var _transparentSort = null;
  14413. var _viewport = new Vector4(0, 0, _width, _height);
  14414. var _scissor = new Vector4(0, 0, _width, _height);
  14415. var _scissorTest = false; // frustum
  14416. var _frustum = new Frustum(); // clipping
  14417. var _clippingEnabled = false;
  14418. var _localClippingEnabled = false; // camera matrices cache
  14419. var _projScreenMatrix = new Matrix4();
  14420. var _vector3 = new Vector3();
  14421. var _emptyScene = {
  14422. background: null,
  14423. fog: null,
  14424. environment: null,
  14425. overrideMaterial: null,
  14426. isScene: true
  14427. };
  14428. function getTargetPixelRatio() {
  14429. return _currentRenderTarget === null ? _pixelRatio : 1;
  14430. } // initialize
  14431. var _gl = _context;
  14432. function getContext(contextNames, contextAttributes) {
  14433. for (var i = 0; i < contextNames.length; i++) {
  14434. var contextName = contextNames[i];
  14435. var context = _canvas.getContext(contextName, contextAttributes);
  14436. if (context !== null) return context;
  14437. }
  14438. return null;
  14439. }
  14440. try {
  14441. var contextAttributes = {
  14442. alpha: _alpha,
  14443. depth: _depth,
  14444. stencil: _stencil,
  14445. antialias: _antialias,
  14446. premultipliedAlpha: _premultipliedAlpha,
  14447. preserveDrawingBuffer: _preserveDrawingBuffer,
  14448. powerPreference: _powerPreference,
  14449. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14450. }; // event listeners must be registered before WebGL context is created, see #12753
  14451. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14452. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14453. if (_gl === null) {
  14454. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14455. if (_this.isWebGL1Renderer === true) {
  14456. contextNames.shift();
  14457. }
  14458. _gl = getContext(contextNames, contextAttributes);
  14459. if (_gl === null) {
  14460. if (getContext(contextNames)) {
  14461. throw new Error('Error creating WebGL context with your selected attributes.');
  14462. } else {
  14463. throw new Error('Error creating WebGL context.');
  14464. }
  14465. }
  14466. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14467. if (_gl.getShaderPrecisionFormat === undefined) {
  14468. _gl.getShaderPrecisionFormat = function () {
  14469. return {
  14470. 'rangeMin': 1,
  14471. 'rangeMax': 1,
  14472. 'precision': 1
  14473. };
  14474. };
  14475. }
  14476. } catch (error) {
  14477. console.error('THREE.WebGLRenderer: ' + error.message);
  14478. throw error;
  14479. }
  14480. var extensions, capabilities, state, info;
  14481. var properties, textures, cubemaps, attributes, geometries, objects;
  14482. var programCache, materials, renderLists, renderStates, clipping;
  14483. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14484. var utils, bindingStates;
  14485. function initGLContext() {
  14486. extensions = new WebGLExtensions(_gl);
  14487. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14488. if (capabilities.isWebGL2 === false) {
  14489. extensions.get('WEBGL_depth_texture');
  14490. extensions.get('OES_texture_float');
  14491. extensions.get('OES_texture_half_float');
  14492. extensions.get('OES_texture_half_float_linear');
  14493. extensions.get('OES_standard_derivatives');
  14494. extensions.get('OES_element_index_uint');
  14495. extensions.get('OES_vertex_array_object');
  14496. extensions.get('ANGLE_instanced_arrays');
  14497. }
  14498. extensions.get('OES_texture_float_linear');
  14499. utils = new WebGLUtils(_gl, extensions, capabilities);
  14500. state = new WebGLState(_gl, extensions, capabilities);
  14501. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14502. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14503. info = new WebGLInfo(_gl);
  14504. properties = new WebGLProperties();
  14505. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14506. cubemaps = new WebGLCubeMaps(_this);
  14507. attributes = new WebGLAttributes(_gl, capabilities);
  14508. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14509. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14510. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14511. morphtargets = new WebGLMorphtargets(_gl);
  14512. clipping = new WebGLClipping(properties);
  14513. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14514. materials = new WebGLMaterials(properties);
  14515. renderLists = new WebGLRenderLists(properties);
  14516. renderStates = new WebGLRenderStates(extensions, capabilities);
  14517. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14518. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14519. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14520. info.programs = programCache.programs;
  14521. _this.capabilities = capabilities;
  14522. _this.extensions = extensions;
  14523. _this.properties = properties;
  14524. _this.renderLists = renderLists;
  14525. _this.state = state;
  14526. _this.info = info;
  14527. }
  14528. initGLContext(); // xr
  14529. var xr = new WebXRManager(_this, _gl);
  14530. this.xr = xr; // shadow map
  14531. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14532. this.shadowMap = shadowMap; // API
  14533. this.getContext = function () {
  14534. return _gl;
  14535. };
  14536. this.getContextAttributes = function () {
  14537. return _gl.getContextAttributes();
  14538. };
  14539. this.forceContextLoss = function () {
  14540. var extension = extensions.get('WEBGL_lose_context');
  14541. if (extension) extension.loseContext();
  14542. };
  14543. this.forceContextRestore = function () {
  14544. var extension = extensions.get('WEBGL_lose_context');
  14545. if (extension) extension.restoreContext();
  14546. };
  14547. this.getPixelRatio = function () {
  14548. return _pixelRatio;
  14549. };
  14550. this.setPixelRatio = function (value) {
  14551. if (value === undefined) return;
  14552. _pixelRatio = value;
  14553. this.setSize(_width, _height, false);
  14554. };
  14555. this.getSize = function (target) {
  14556. if (target === undefined) {
  14557. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14558. target = new Vector2();
  14559. }
  14560. return target.set(_width, _height);
  14561. };
  14562. this.setSize = function (width, height, updateStyle) {
  14563. if (xr.isPresenting) {
  14564. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14565. return;
  14566. }
  14567. _width = width;
  14568. _height = height;
  14569. _canvas.width = Math.floor(width * _pixelRatio);
  14570. _canvas.height = Math.floor(height * _pixelRatio);
  14571. if (updateStyle !== false) {
  14572. _canvas.style.width = width + 'px';
  14573. _canvas.style.height = height + 'px';
  14574. }
  14575. this.setViewport(0, 0, width, height);
  14576. };
  14577. this.getDrawingBufferSize = function (target) {
  14578. if (target === undefined) {
  14579. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14580. target = new Vector2();
  14581. }
  14582. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14583. };
  14584. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14585. _width = width;
  14586. _height = height;
  14587. _pixelRatio = pixelRatio;
  14588. _canvas.width = Math.floor(width * pixelRatio);
  14589. _canvas.height = Math.floor(height * pixelRatio);
  14590. this.setViewport(0, 0, width, height);
  14591. };
  14592. this.getCurrentViewport = function (target) {
  14593. if (target === undefined) {
  14594. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14595. target = new Vector4();
  14596. }
  14597. return target.copy(_currentViewport);
  14598. };
  14599. this.getViewport = function (target) {
  14600. return target.copy(_viewport);
  14601. };
  14602. this.setViewport = function (x, y, width, height) {
  14603. if (x.isVector4) {
  14604. _viewport.set(x.x, x.y, x.z, x.w);
  14605. } else {
  14606. _viewport.set(x, y, width, height);
  14607. }
  14608. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14609. };
  14610. this.getScissor = function (target) {
  14611. return target.copy(_scissor);
  14612. };
  14613. this.setScissor = function (x, y, width, height) {
  14614. if (x.isVector4) {
  14615. _scissor.set(x.x, x.y, x.z, x.w);
  14616. } else {
  14617. _scissor.set(x, y, width, height);
  14618. }
  14619. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14620. };
  14621. this.getScissorTest = function () {
  14622. return _scissorTest;
  14623. };
  14624. this.setScissorTest = function (boolean) {
  14625. state.setScissorTest(_scissorTest = boolean);
  14626. };
  14627. this.setOpaqueSort = function (method) {
  14628. _opaqueSort = method;
  14629. };
  14630. this.setTransparentSort = function (method) {
  14631. _transparentSort = method;
  14632. }; // Clearing
  14633. this.getClearColor = function (target) {
  14634. if (target === undefined) {
  14635. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  14636. target = new Color();
  14637. }
  14638. return target.copy(background.getClearColor());
  14639. };
  14640. this.setClearColor = function () {
  14641. background.setClearColor.apply(background, arguments);
  14642. };
  14643. this.getClearAlpha = function () {
  14644. return background.getClearAlpha();
  14645. };
  14646. this.setClearAlpha = function () {
  14647. background.setClearAlpha.apply(background, arguments);
  14648. };
  14649. this.clear = function (color, depth, stencil) {
  14650. var bits = 0;
  14651. if (color === undefined || color) bits |= 16384;
  14652. if (depth === undefined || depth) bits |= 256;
  14653. if (stencil === undefined || stencil) bits |= 1024;
  14654. _gl.clear(bits);
  14655. };
  14656. this.clearColor = function () {
  14657. this.clear(true, false, false);
  14658. };
  14659. this.clearDepth = function () {
  14660. this.clear(false, true, false);
  14661. };
  14662. this.clearStencil = function () {
  14663. this.clear(false, false, true);
  14664. }; //
  14665. this.dispose = function () {
  14666. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14667. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14668. renderLists.dispose();
  14669. renderStates.dispose();
  14670. properties.dispose();
  14671. cubemaps.dispose();
  14672. objects.dispose();
  14673. bindingStates.dispose();
  14674. xr.dispose();
  14675. animation.stop();
  14676. }; // Events
  14677. function onContextLost(event) {
  14678. event.preventDefault();
  14679. console.log('THREE.WebGLRenderer: Context Lost.');
  14680. _isContextLost = true;
  14681. }
  14682. function onContextRestore()
  14683. /* event */
  14684. {
  14685. console.log('THREE.WebGLRenderer: Context Restored.');
  14686. _isContextLost = false;
  14687. initGLContext();
  14688. }
  14689. function onMaterialDispose(event) {
  14690. var material = event.target;
  14691. material.removeEventListener('dispose', onMaterialDispose);
  14692. deallocateMaterial(material);
  14693. } // Buffer deallocation
  14694. function deallocateMaterial(material) {
  14695. releaseMaterialProgramReference(material);
  14696. properties.remove(material);
  14697. }
  14698. function releaseMaterialProgramReference(material) {
  14699. var programInfo = properties.get(material).program;
  14700. if (programInfo !== undefined) {
  14701. programCache.releaseProgram(programInfo);
  14702. }
  14703. } // Buffer rendering
  14704. function renderObjectImmediate(object, program) {
  14705. object.render(function (object) {
  14706. _this.renderBufferImmediate(object, program);
  14707. });
  14708. }
  14709. this.renderBufferImmediate = function (object, program) {
  14710. bindingStates.initAttributes();
  14711. var buffers = properties.get(object);
  14712. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14713. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14714. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14715. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14716. var programAttributes = program.getAttributes();
  14717. if (object.hasPositions) {
  14718. _gl.bindBuffer(34962, buffers.position);
  14719. _gl.bufferData(34962, object.positionArray, 35048);
  14720. bindingStates.enableAttribute(programAttributes.position);
  14721. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14722. }
  14723. if (object.hasNormals) {
  14724. _gl.bindBuffer(34962, buffers.normal);
  14725. _gl.bufferData(34962, object.normalArray, 35048);
  14726. bindingStates.enableAttribute(programAttributes.normal);
  14727. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14728. }
  14729. if (object.hasUvs) {
  14730. _gl.bindBuffer(34962, buffers.uv);
  14731. _gl.bufferData(34962, object.uvArray, 35048);
  14732. bindingStates.enableAttribute(programAttributes.uv);
  14733. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14734. }
  14735. if (object.hasColors) {
  14736. _gl.bindBuffer(34962, buffers.color);
  14737. _gl.bufferData(34962, object.colorArray, 35048);
  14738. bindingStates.enableAttribute(programAttributes.color);
  14739. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14740. }
  14741. bindingStates.disableUnusedAttributes();
  14742. _gl.drawArrays(4, 0, object.count);
  14743. object.count = 0;
  14744. };
  14745. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14746. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14747. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14748. var program = setProgram(camera, scene, material, object);
  14749. state.setMaterial(material, frontFaceCW); //
  14750. var index = geometry.index;
  14751. var position = geometry.attributes.position; //
  14752. if (index === null) {
  14753. if (position === undefined || position.count === 0) return;
  14754. } else if (index.count === 0) {
  14755. return;
  14756. } //
  14757. var rangeFactor = 1;
  14758. if (material.wireframe === true) {
  14759. index = geometries.getWireframeAttribute(geometry);
  14760. rangeFactor = 2;
  14761. }
  14762. if (material.morphTargets || material.morphNormals) {
  14763. morphtargets.update(object, geometry, material, program);
  14764. }
  14765. bindingStates.setup(object, material, program, geometry, index);
  14766. var attribute;
  14767. var renderer = bufferRenderer;
  14768. if (index !== null) {
  14769. attribute = attributes.get(index);
  14770. renderer = indexedBufferRenderer;
  14771. renderer.setIndex(attribute);
  14772. } //
  14773. var dataCount = index !== null ? index.count : position.count;
  14774. var rangeStart = geometry.drawRange.start * rangeFactor;
  14775. var rangeCount = geometry.drawRange.count * rangeFactor;
  14776. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14777. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14778. var drawStart = Math.max(rangeStart, groupStart);
  14779. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14780. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14781. if (drawCount === 0) return; //
  14782. if (object.isMesh) {
  14783. if (material.wireframe === true) {
  14784. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14785. renderer.setMode(1);
  14786. } else {
  14787. renderer.setMode(4);
  14788. }
  14789. } else if (object.isLine) {
  14790. var lineWidth = material.linewidth;
  14791. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14792. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14793. if (object.isLineSegments) {
  14794. renderer.setMode(1);
  14795. } else if (object.isLineLoop) {
  14796. renderer.setMode(2);
  14797. } else {
  14798. renderer.setMode(3);
  14799. }
  14800. } else if (object.isPoints) {
  14801. renderer.setMode(0);
  14802. } else if (object.isSprite) {
  14803. renderer.setMode(4);
  14804. }
  14805. if (object.isInstancedMesh) {
  14806. renderer.renderInstances(drawStart, drawCount, object.count);
  14807. } else if (geometry.isInstancedBufferGeometry) {
  14808. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14809. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14810. } else {
  14811. renderer.render(drawStart, drawCount);
  14812. }
  14813. }; // Compile
  14814. this.compile = function (scene, camera) {
  14815. currentRenderState = renderStates.get(scene);
  14816. currentRenderState.init();
  14817. scene.traverseVisible(function (object) {
  14818. if (object.isLight && object.layers.test(camera.layers)) {
  14819. currentRenderState.pushLight(object);
  14820. if (object.castShadow) {
  14821. currentRenderState.pushShadow(object);
  14822. }
  14823. }
  14824. });
  14825. currentRenderState.setupLights();
  14826. var compiled = new WeakMap();
  14827. scene.traverse(function (object) {
  14828. var material = object.material;
  14829. if (material) {
  14830. if (Array.isArray(material)) {
  14831. for (var i = 0; i < material.length; i++) {
  14832. var material2 = material[i];
  14833. if (compiled.has(material2) === false) {
  14834. initMaterial(material2, scene, object);
  14835. compiled.set(material2);
  14836. }
  14837. }
  14838. } else if (compiled.has(material) === false) {
  14839. initMaterial(material, scene, object);
  14840. compiled.set(material);
  14841. }
  14842. }
  14843. });
  14844. }; // Animation Loop
  14845. var onAnimationFrameCallback = null;
  14846. function onAnimationFrame(time) {
  14847. if (xr.isPresenting) return;
  14848. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14849. }
  14850. var animation = new WebGLAnimation();
  14851. animation.setAnimationLoop(onAnimationFrame);
  14852. if (typeof window !== 'undefined') animation.setContext(window);
  14853. this.setAnimationLoop = function (callback) {
  14854. onAnimationFrameCallback = callback;
  14855. xr.setAnimationLoop(callback);
  14856. callback === null ? animation.stop() : animation.start();
  14857. }; // Rendering
  14858. this.render = function (scene, camera) {
  14859. var renderTarget, forceClear;
  14860. if (arguments[2] !== undefined) {
  14861. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14862. renderTarget = arguments[2];
  14863. }
  14864. if (arguments[3] !== undefined) {
  14865. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14866. forceClear = arguments[3];
  14867. }
  14868. if (camera !== undefined && camera.isCamera !== true) {
  14869. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14870. return;
  14871. }
  14872. if (_isContextLost === true) return; // reset caching for this frame
  14873. bindingStates.resetDefaultState();
  14874. _currentMaterialId = -1;
  14875. _currentCamera = null; // update scene graph
  14876. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14877. if (camera.parent === null) camera.updateMatrixWorld();
  14878. if (xr.enabled === true && xr.isPresenting === true) {
  14879. camera = xr.getCamera(camera);
  14880. } //
  14881. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14882. currentRenderState = renderStates.get(scene, renderStateStack.length);
  14883. currentRenderState.init();
  14884. renderStateStack.push(currentRenderState);
  14885. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14886. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14887. _localClippingEnabled = this.localClippingEnabled;
  14888. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14889. currentRenderList = renderLists.get(scene, camera);
  14890. currentRenderList.init();
  14891. projectObject(scene, camera, 0, _this.sortObjects);
  14892. currentRenderList.finish();
  14893. if (_this.sortObjects === true) {
  14894. currentRenderList.sort(_opaqueSort, _transparentSort);
  14895. } //
  14896. if (_clippingEnabled === true) clipping.beginShadows();
  14897. var shadowsArray = currentRenderState.state.shadowsArray;
  14898. shadowMap.render(shadowsArray, scene, camera);
  14899. currentRenderState.setupLights();
  14900. currentRenderState.setupLightsView(camera);
  14901. if (_clippingEnabled === true) clipping.endShadows(); //
  14902. if (this.info.autoReset === true) this.info.reset();
  14903. if (renderTarget !== undefined) {
  14904. this.setRenderTarget(renderTarget);
  14905. } //
  14906. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14907. var opaqueObjects = currentRenderList.opaque;
  14908. var transparentObjects = currentRenderList.transparent;
  14909. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14910. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14911. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14912. if (_currentRenderTarget !== null) {
  14913. // Generate mipmap if we're using any kind of mipmap filtering
  14914. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14915. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14916. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14917. state.buffers.depth.setTest(true);
  14918. state.buffers.depth.setMask(true);
  14919. state.buffers.color.setMask(true);
  14920. state.setPolygonOffset(false); // _gl.finish();
  14921. renderStateStack.pop();
  14922. if (renderStateStack.length > 0) {
  14923. currentRenderState = renderStateStack[renderStateStack.length - 1];
  14924. } else {
  14925. currentRenderState = null;
  14926. }
  14927. currentRenderList = null;
  14928. };
  14929. function projectObject(object, camera, groupOrder, sortObjects) {
  14930. if (object.visible === false) return;
  14931. var visible = object.layers.test(camera.layers);
  14932. if (visible) {
  14933. if (object.isGroup) {
  14934. groupOrder = object.renderOrder;
  14935. } else if (object.isLOD) {
  14936. if (object.autoUpdate === true) object.update(camera);
  14937. } else if (object.isLight) {
  14938. currentRenderState.pushLight(object);
  14939. if (object.castShadow) {
  14940. currentRenderState.pushShadow(object);
  14941. }
  14942. } else if (object.isSprite) {
  14943. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14944. if (sortObjects) {
  14945. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14946. }
  14947. var geometry = objects.update(object);
  14948. var material = object.material;
  14949. if (material.visible) {
  14950. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14951. }
  14952. }
  14953. } else if (object.isImmediateRenderObject) {
  14954. if (sortObjects) {
  14955. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14956. }
  14957. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14958. } else if (object.isMesh || object.isLine || object.isPoints) {
  14959. if (object.isSkinnedMesh) {
  14960. // update skeleton only once in a frame
  14961. if (object.skeleton.frame !== info.render.frame) {
  14962. object.skeleton.update();
  14963. object.skeleton.frame = info.render.frame;
  14964. }
  14965. }
  14966. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14967. if (sortObjects) {
  14968. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14969. }
  14970. var _geometry = objects.update(object);
  14971. var _material = object.material;
  14972. if (Array.isArray(_material)) {
  14973. var groups = _geometry.groups;
  14974. for (var i = 0, l = groups.length; i < l; i++) {
  14975. var group = groups[i];
  14976. var groupMaterial = _material[group.materialIndex];
  14977. if (groupMaterial && groupMaterial.visible) {
  14978. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14979. }
  14980. }
  14981. } else if (_material.visible) {
  14982. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14983. }
  14984. }
  14985. }
  14986. }
  14987. var children = object.children;
  14988. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14989. projectObject(children[_i], camera, groupOrder, sortObjects);
  14990. }
  14991. }
  14992. function renderObjects(renderList, scene, camera) {
  14993. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14994. for (var i = 0, l = renderList.length; i < l; i++) {
  14995. var renderItem = renderList[i];
  14996. var object = renderItem.object;
  14997. var geometry = renderItem.geometry;
  14998. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14999. var group = renderItem.group;
  15000. if (camera.isArrayCamera) {
  15001. var cameras = camera.cameras;
  15002. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15003. var camera2 = cameras[j];
  15004. if (object.layers.test(camera2.layers)) {
  15005. state.viewport(_currentViewport.copy(camera2.viewport));
  15006. currentRenderState.setupLightsView(camera2);
  15007. renderObject(object, scene, camera2, geometry, material, group);
  15008. }
  15009. }
  15010. } else {
  15011. renderObject(object, scene, camera, geometry, material, group);
  15012. }
  15013. }
  15014. }
  15015. function renderObject(object, scene, camera, geometry, material, group) {
  15016. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15017. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15018. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15019. if (object.isImmediateRenderObject) {
  15020. var program = setProgram(camera, scene, material, object);
  15021. state.setMaterial(material);
  15022. bindingStates.reset();
  15023. renderObjectImmediate(object, program);
  15024. } else {
  15025. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15026. }
  15027. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15028. }
  15029. function initMaterial(material, scene, object) {
  15030. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15031. var materialProperties = properties.get(material);
  15032. var lights = currentRenderState.state.lights;
  15033. var shadowsArray = currentRenderState.state.shadowsArray;
  15034. var lightsStateVersion = lights.state.version;
  15035. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15036. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15037. var program = materialProperties.program;
  15038. var programChange = true;
  15039. if (program === undefined) {
  15040. // new material
  15041. material.addEventListener('dispose', onMaterialDispose);
  15042. } else if (program.cacheKey !== programCacheKey) {
  15043. // changed glsl or parameters
  15044. releaseMaterialProgramReference(material);
  15045. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15046. programChange = false;
  15047. } else if (parameters.shaderID !== undefined) {
  15048. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  15049. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15050. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  15051. return;
  15052. } else {
  15053. // only rebuild uniform list
  15054. programChange = false;
  15055. }
  15056. if (programChange) {
  15057. parameters.uniforms = programCache.getUniforms(material);
  15058. material.onBeforeCompile(parameters, _this);
  15059. program = programCache.acquireProgram(parameters, programCacheKey);
  15060. materialProperties.program = program;
  15061. materialProperties.uniforms = parameters.uniforms;
  15062. materialProperties.outputEncoding = parameters.outputEncoding;
  15063. }
  15064. var uniforms = materialProperties.uniforms;
  15065. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15066. materialProperties.numClippingPlanes = clipping.numPlanes;
  15067. materialProperties.numIntersection = clipping.numIntersection;
  15068. uniforms.clippingPlanes = clipping.uniform;
  15069. }
  15070. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15071. materialProperties.fog = scene.fog;
  15072. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  15073. materialProperties.needsLights = materialNeedsLights(material);
  15074. materialProperties.lightsStateVersion = lightsStateVersion;
  15075. if (materialProperties.needsLights) {
  15076. // wire up the material to this renderer's lighting state
  15077. uniforms.ambientLightColor.value = lights.state.ambient;
  15078. uniforms.lightProbe.value = lights.state.probe;
  15079. uniforms.directionalLights.value = lights.state.directional;
  15080. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15081. uniforms.spotLights.value = lights.state.spot;
  15082. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15083. uniforms.rectAreaLights.value = lights.state.rectArea;
  15084. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15085. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15086. uniforms.pointLights.value = lights.state.point;
  15087. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15088. uniforms.hemisphereLights.value = lights.state.hemi;
  15089. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15090. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15091. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15092. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15093. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15094. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15095. }
  15096. var progUniforms = materialProperties.program.getUniforms();
  15097. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15098. materialProperties.uniformsList = uniformsList;
  15099. }
  15100. function setProgram(camera, scene, material, object) {
  15101. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15102. textures.resetTextureUnits();
  15103. var fog = scene.fog;
  15104. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15105. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15106. var envMap = cubemaps.get(material.envMap || environment);
  15107. var materialProperties = properties.get(material);
  15108. var lights = currentRenderState.state.lights;
  15109. if (_clippingEnabled === true) {
  15110. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15111. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15112. // object instead of the material, once it becomes feasible
  15113. // (#8465, #8379)
  15114. clipping.setState(material, camera, useCache);
  15115. }
  15116. }
  15117. if (material.version === materialProperties.__version) {
  15118. if (material.fog && materialProperties.fog !== fog) {
  15119. initMaterial(material, scene, object);
  15120. } else if (materialProperties.environment !== environment) {
  15121. initMaterial(material, scene, object);
  15122. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15123. initMaterial(material, scene, object);
  15124. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15125. initMaterial(material, scene, object);
  15126. } else if (materialProperties.outputEncoding !== encoding) {
  15127. initMaterial(material, scene, object);
  15128. } else if (materialProperties.envMap !== envMap) {
  15129. initMaterial(material, scene, object);
  15130. }
  15131. } else {
  15132. initMaterial(material, scene, object);
  15133. materialProperties.__version = material.version;
  15134. }
  15135. var refreshProgram = false;
  15136. var refreshMaterial = false;
  15137. var refreshLights = false;
  15138. var program = materialProperties.program,
  15139. p_uniforms = program.getUniforms(),
  15140. m_uniforms = materialProperties.uniforms;
  15141. if (state.useProgram(program.program)) {
  15142. refreshProgram = true;
  15143. refreshMaterial = true;
  15144. refreshLights = true;
  15145. }
  15146. if (material.id !== _currentMaterialId) {
  15147. _currentMaterialId = material.id;
  15148. refreshMaterial = true;
  15149. }
  15150. if (refreshProgram || _currentCamera !== camera) {
  15151. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15152. if (capabilities.logarithmicDepthBuffer) {
  15153. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15154. }
  15155. if (_currentCamera !== camera) {
  15156. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15157. // now, in case this material supports lights - or later, when
  15158. // the next material that does gets activated:
  15159. refreshMaterial = true; // set to true on material change
  15160. refreshLights = true; // remains set until update done
  15161. } // load material specific uniforms
  15162. // (shader material also gets them for the sake of genericity)
  15163. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15164. var uCamPos = p_uniforms.map.cameraPosition;
  15165. if (uCamPos !== undefined) {
  15166. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15167. }
  15168. }
  15169. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15170. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15171. }
  15172. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15173. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15174. }
  15175. } // skinning uniforms must be set even if material didn't change
  15176. // auto-setting of texture unit for bone texture must go before other textures
  15177. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15178. if (material.skinning) {
  15179. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15180. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15181. var skeleton = object.skeleton;
  15182. if (skeleton) {
  15183. var bones = skeleton.bones;
  15184. if (capabilities.floatVertexTextures) {
  15185. if (skeleton.boneTexture === null) {
  15186. // layout (1 matrix = 4 pixels)
  15187. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15188. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15189. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15190. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15191. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15192. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15193. size = MathUtils.ceilPowerOfTwo(size);
  15194. size = Math.max(size, 4);
  15195. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15196. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15197. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15198. skeleton.boneMatrices = boneMatrices;
  15199. skeleton.boneTexture = boneTexture;
  15200. skeleton.boneTextureSize = size;
  15201. }
  15202. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15203. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15204. } else {
  15205. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15206. }
  15207. }
  15208. }
  15209. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15210. materialProperties.receiveShadow = object.receiveShadow;
  15211. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15212. }
  15213. if (refreshMaterial) {
  15214. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15215. if (materialProperties.needsLights) {
  15216. // the current material requires lighting info
  15217. // note: all lighting uniforms are always set correctly
  15218. // they simply reference the renderer's state for their
  15219. // values
  15220. //
  15221. // use the current material's .needsUpdate flags to set
  15222. // the GL state when required
  15223. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15224. } // refresh uniforms common to several materials
  15225. if (fog && material.fog) {
  15226. materials.refreshFogUniforms(m_uniforms, fog);
  15227. }
  15228. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15229. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15230. }
  15231. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15232. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15233. material.uniformsNeedUpdate = false;
  15234. }
  15235. if (material.isSpriteMaterial) {
  15236. p_uniforms.setValue(_gl, 'center', object.center);
  15237. } // common matrices
  15238. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15239. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15240. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15241. return program;
  15242. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15243. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15244. uniforms.ambientLightColor.needsUpdate = value;
  15245. uniforms.lightProbe.needsUpdate = value;
  15246. uniforms.directionalLights.needsUpdate = value;
  15247. uniforms.directionalLightShadows.needsUpdate = value;
  15248. uniforms.pointLights.needsUpdate = value;
  15249. uniforms.pointLightShadows.needsUpdate = value;
  15250. uniforms.spotLights.needsUpdate = value;
  15251. uniforms.spotLightShadows.needsUpdate = value;
  15252. uniforms.rectAreaLights.needsUpdate = value;
  15253. uniforms.hemisphereLights.needsUpdate = value;
  15254. }
  15255. function materialNeedsLights(material) {
  15256. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15257. } //
  15258. this.setFramebuffer = function (value) {
  15259. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15260. _framebuffer = value;
  15261. };
  15262. this.getActiveCubeFace = function () {
  15263. return _currentActiveCubeFace;
  15264. };
  15265. this.getActiveMipmapLevel = function () {
  15266. return _currentActiveMipmapLevel;
  15267. };
  15268. this.getRenderList = function () {
  15269. return currentRenderList;
  15270. };
  15271. this.setRenderList = function (renderList) {
  15272. currentRenderList = renderList;
  15273. };
  15274. this.getRenderTarget = function () {
  15275. return _currentRenderTarget;
  15276. };
  15277. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15278. if (activeCubeFace === void 0) {
  15279. activeCubeFace = 0;
  15280. }
  15281. if (activeMipmapLevel === void 0) {
  15282. activeMipmapLevel = 0;
  15283. }
  15284. _currentRenderTarget = renderTarget;
  15285. _currentActiveCubeFace = activeCubeFace;
  15286. _currentActiveMipmapLevel = activeMipmapLevel;
  15287. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15288. textures.setupRenderTarget(renderTarget);
  15289. }
  15290. var framebuffer = _framebuffer;
  15291. var isCube = false;
  15292. if (renderTarget) {
  15293. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15294. if (renderTarget.isWebGLCubeRenderTarget) {
  15295. framebuffer = __webglFramebuffer[activeCubeFace];
  15296. isCube = true;
  15297. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15298. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15299. } else {
  15300. framebuffer = __webglFramebuffer;
  15301. }
  15302. _currentViewport.copy(renderTarget.viewport);
  15303. _currentScissor.copy(renderTarget.scissor);
  15304. _currentScissorTest = renderTarget.scissorTest;
  15305. } else {
  15306. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15307. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15308. _currentScissorTest = _scissorTest;
  15309. }
  15310. if (_currentFramebuffer !== framebuffer) {
  15311. _gl.bindFramebuffer(36160, framebuffer);
  15312. _currentFramebuffer = framebuffer;
  15313. }
  15314. state.viewport(_currentViewport);
  15315. state.scissor(_currentScissor);
  15316. state.setScissorTest(_currentScissorTest);
  15317. if (isCube) {
  15318. var textureProperties = properties.get(renderTarget.texture);
  15319. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15320. }
  15321. };
  15322. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15323. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15324. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15325. return;
  15326. }
  15327. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15328. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15329. framebuffer = framebuffer[activeCubeFaceIndex];
  15330. }
  15331. if (framebuffer) {
  15332. var restore = false;
  15333. if (framebuffer !== _currentFramebuffer) {
  15334. _gl.bindFramebuffer(36160, framebuffer);
  15335. restore = true;
  15336. }
  15337. try {
  15338. var texture = renderTarget.texture;
  15339. var textureFormat = texture.format;
  15340. var textureType = texture.type;
  15341. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15342. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15343. return;
  15344. }
  15345. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15346. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15347. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15348. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15349. return;
  15350. }
  15351. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15352. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15353. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15354. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15355. }
  15356. } else {
  15357. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15358. }
  15359. } finally {
  15360. if (restore) {
  15361. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15362. }
  15363. }
  15364. }
  15365. };
  15366. this.copyFramebufferToTexture = function (position, texture, level) {
  15367. if (level === void 0) {
  15368. level = 0;
  15369. }
  15370. var levelScale = Math.pow(2, -level);
  15371. var width = Math.floor(texture.image.width * levelScale);
  15372. var height = Math.floor(texture.image.height * levelScale);
  15373. var glFormat = utils.convert(texture.format);
  15374. textures.setTexture2D(texture, 0);
  15375. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15376. state.unbindTexture();
  15377. };
  15378. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15379. if (level === void 0) {
  15380. level = 0;
  15381. }
  15382. var width = srcTexture.image.width;
  15383. var height = srcTexture.image.height;
  15384. var glFormat = utils.convert(dstTexture.format);
  15385. var glType = utils.convert(dstTexture.type);
  15386. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15387. // parameters, make sure they are correct for the dstTexture
  15388. _gl.pixelStorei(37440, dstTexture.flipY);
  15389. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15390. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15391. if (srcTexture.isDataTexture) {
  15392. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15393. } else {
  15394. if (srcTexture.isCompressedTexture) {
  15395. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15396. } else {
  15397. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15398. }
  15399. } // Generate mipmaps only when copying level 0
  15400. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15401. state.unbindTexture();
  15402. };
  15403. this.initTexture = function (texture) {
  15404. textures.setTexture2D(texture, 0);
  15405. state.unbindTexture();
  15406. };
  15407. this.resetState = function () {
  15408. state.reset();
  15409. bindingStates.reset();
  15410. };
  15411. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15412. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15413. detail: this
  15414. })); // eslint-disable-line no-undef
  15415. }
  15416. }
  15417. function WebGL1Renderer(parameters) {
  15418. WebGLRenderer.call(this, parameters);
  15419. }
  15420. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15421. constructor: WebGL1Renderer,
  15422. isWebGL1Renderer: true
  15423. });
  15424. var FogExp2 = /*#__PURE__*/function () {
  15425. function FogExp2(color, density) {
  15426. Object.defineProperty(this, 'isFogExp2', {
  15427. value: true
  15428. });
  15429. this.name = '';
  15430. this.color = new Color(color);
  15431. this.density = density !== undefined ? density : 0.00025;
  15432. }
  15433. var _proto = FogExp2.prototype;
  15434. _proto.clone = function clone() {
  15435. return new FogExp2(this.color, this.density);
  15436. };
  15437. _proto.toJSON = function toJSON()
  15438. /* meta */
  15439. {
  15440. return {
  15441. type: 'FogExp2',
  15442. color: this.color.getHex(),
  15443. density: this.density
  15444. };
  15445. };
  15446. return FogExp2;
  15447. }();
  15448. var Fog = /*#__PURE__*/function () {
  15449. function Fog(color, near, far) {
  15450. Object.defineProperty(this, 'isFog', {
  15451. value: true
  15452. });
  15453. this.name = '';
  15454. this.color = new Color(color);
  15455. this.near = near !== undefined ? near : 1;
  15456. this.far = far !== undefined ? far : 1000;
  15457. }
  15458. var _proto = Fog.prototype;
  15459. _proto.clone = function clone() {
  15460. return new Fog(this.color, this.near, this.far);
  15461. };
  15462. _proto.toJSON = function toJSON()
  15463. /* meta */
  15464. {
  15465. return {
  15466. type: 'Fog',
  15467. color: this.color.getHex(),
  15468. near: this.near,
  15469. far: this.far
  15470. };
  15471. };
  15472. return Fog;
  15473. }();
  15474. var Scene = /*#__PURE__*/function (_Object3D) {
  15475. _inheritsLoose(Scene, _Object3D);
  15476. function Scene() {
  15477. var _this;
  15478. _this = _Object3D.call(this) || this;
  15479. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15480. value: true
  15481. });
  15482. _this.type = 'Scene';
  15483. _this.background = null;
  15484. _this.environment = null;
  15485. _this.fog = null;
  15486. _this.overrideMaterial = null;
  15487. _this.autoUpdate = true; // checked by the renderer
  15488. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15489. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15490. detail: _assertThisInitialized(_this)
  15491. })); // eslint-disable-line no-undef
  15492. }
  15493. return _this;
  15494. }
  15495. var _proto = Scene.prototype;
  15496. _proto.copy = function copy(source, recursive) {
  15497. _Object3D.prototype.copy.call(this, source, recursive);
  15498. if (source.background !== null) this.background = source.background.clone();
  15499. if (source.environment !== null) this.environment = source.environment.clone();
  15500. if (source.fog !== null) this.fog = source.fog.clone();
  15501. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15502. this.autoUpdate = source.autoUpdate;
  15503. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15504. return this;
  15505. };
  15506. _proto.toJSON = function toJSON(meta) {
  15507. var data = _Object3D.prototype.toJSON.call(this, meta);
  15508. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15509. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15510. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15511. return data;
  15512. };
  15513. return Scene;
  15514. }(Object3D);
  15515. function InterleavedBuffer(array, stride) {
  15516. this.array = array;
  15517. this.stride = stride;
  15518. this.count = array !== undefined ? array.length / stride : 0;
  15519. this.usage = StaticDrawUsage;
  15520. this.updateRange = {
  15521. offset: 0,
  15522. count: -1
  15523. };
  15524. this.version = 0;
  15525. this.uuid = MathUtils.generateUUID();
  15526. }
  15527. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15528. set: function set(value) {
  15529. if (value === true) this.version++;
  15530. }
  15531. });
  15532. Object.assign(InterleavedBuffer.prototype, {
  15533. isInterleavedBuffer: true,
  15534. onUploadCallback: function onUploadCallback() {},
  15535. setUsage: function setUsage(value) {
  15536. this.usage = value;
  15537. return this;
  15538. },
  15539. copy: function copy(source) {
  15540. this.array = new source.array.constructor(source.array);
  15541. this.count = source.count;
  15542. this.stride = source.stride;
  15543. this.usage = source.usage;
  15544. return this;
  15545. },
  15546. copyAt: function copyAt(index1, attribute, index2) {
  15547. index1 *= this.stride;
  15548. index2 *= attribute.stride;
  15549. for (var i = 0, l = this.stride; i < l; i++) {
  15550. this.array[index1 + i] = attribute.array[index2 + i];
  15551. }
  15552. return this;
  15553. },
  15554. set: function set(value, offset) {
  15555. if (offset === void 0) {
  15556. offset = 0;
  15557. }
  15558. this.array.set(value, offset);
  15559. return this;
  15560. },
  15561. clone: function clone(data) {
  15562. if (data.arrayBuffers === undefined) {
  15563. data.arrayBuffers = {};
  15564. }
  15565. if (this.array.buffer._uuid === undefined) {
  15566. this.array.buffer._uuid = MathUtils.generateUUID();
  15567. }
  15568. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15569. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15570. }
  15571. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15572. var ib = new InterleavedBuffer(array, this.stride);
  15573. ib.setUsage(this.usage);
  15574. return ib;
  15575. },
  15576. onUpload: function onUpload(callback) {
  15577. this.onUploadCallback = callback;
  15578. return this;
  15579. },
  15580. toJSON: function toJSON(data) {
  15581. if (data.arrayBuffers === undefined) {
  15582. data.arrayBuffers = {};
  15583. } // generate UUID for array buffer if necessary
  15584. if (this.array.buffer._uuid === undefined) {
  15585. this.array.buffer._uuid = MathUtils.generateUUID();
  15586. }
  15587. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15588. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15589. } //
  15590. return {
  15591. uuid: this.uuid,
  15592. buffer: this.array.buffer._uuid,
  15593. type: this.array.constructor.name,
  15594. stride: this.stride
  15595. };
  15596. }
  15597. });
  15598. var _vector$6 = new Vector3();
  15599. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15600. this.name = '';
  15601. this.data = interleavedBuffer;
  15602. this.itemSize = itemSize;
  15603. this.offset = offset;
  15604. this.normalized = normalized === true;
  15605. }
  15606. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15607. count: {
  15608. get: function get() {
  15609. return this.data.count;
  15610. }
  15611. },
  15612. array: {
  15613. get: function get() {
  15614. return this.data.array;
  15615. }
  15616. },
  15617. needsUpdate: {
  15618. set: function set(value) {
  15619. this.data.needsUpdate = value;
  15620. }
  15621. }
  15622. });
  15623. Object.assign(InterleavedBufferAttribute.prototype, {
  15624. isInterleavedBufferAttribute: true,
  15625. applyMatrix4: function applyMatrix4(m) {
  15626. for (var i = 0, l = this.data.count; i < l; i++) {
  15627. _vector$6.x = this.getX(i);
  15628. _vector$6.y = this.getY(i);
  15629. _vector$6.z = this.getZ(i);
  15630. _vector$6.applyMatrix4(m);
  15631. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15632. }
  15633. return this;
  15634. },
  15635. setX: function setX(index, x) {
  15636. this.data.array[index * this.data.stride + this.offset] = x;
  15637. return this;
  15638. },
  15639. setY: function setY(index, y) {
  15640. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15641. return this;
  15642. },
  15643. setZ: function setZ(index, z) {
  15644. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15645. return this;
  15646. },
  15647. setW: function setW(index, w) {
  15648. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15649. return this;
  15650. },
  15651. getX: function getX(index) {
  15652. return this.data.array[index * this.data.stride + this.offset];
  15653. },
  15654. getY: function getY(index) {
  15655. return this.data.array[index * this.data.stride + this.offset + 1];
  15656. },
  15657. getZ: function getZ(index) {
  15658. return this.data.array[index * this.data.stride + this.offset + 2];
  15659. },
  15660. getW: function getW(index) {
  15661. return this.data.array[index * this.data.stride + this.offset + 3];
  15662. },
  15663. setXY: function setXY(index, x, y) {
  15664. index = index * this.data.stride + this.offset;
  15665. this.data.array[index + 0] = x;
  15666. this.data.array[index + 1] = y;
  15667. return this;
  15668. },
  15669. setXYZ: function setXYZ(index, x, y, z) {
  15670. index = index * this.data.stride + this.offset;
  15671. this.data.array[index + 0] = x;
  15672. this.data.array[index + 1] = y;
  15673. this.data.array[index + 2] = z;
  15674. return this;
  15675. },
  15676. setXYZW: function setXYZW(index, x, y, z, w) {
  15677. index = index * this.data.stride + this.offset;
  15678. this.data.array[index + 0] = x;
  15679. this.data.array[index + 1] = y;
  15680. this.data.array[index + 2] = z;
  15681. this.data.array[index + 3] = w;
  15682. return this;
  15683. },
  15684. clone: function clone(data) {
  15685. if (data === undefined) {
  15686. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15687. var array = [];
  15688. for (var i = 0; i < this.count; i++) {
  15689. var index = i * this.data.stride + this.offset;
  15690. for (var j = 0; j < this.itemSize; j++) {
  15691. array.push(this.data.array[index + j]);
  15692. }
  15693. }
  15694. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15695. } else {
  15696. if (data.interleavedBuffers === undefined) {
  15697. data.interleavedBuffers = {};
  15698. }
  15699. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15700. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15701. }
  15702. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15703. }
  15704. },
  15705. toJSON: function toJSON(data) {
  15706. if (data === undefined) {
  15707. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15708. var array = [];
  15709. for (var i = 0; i < this.count; i++) {
  15710. var index = i * this.data.stride + this.offset;
  15711. for (var j = 0; j < this.itemSize; j++) {
  15712. array.push(this.data.array[index + j]);
  15713. }
  15714. } // deinterleave data and save it as an ordinary buffer attribute for now
  15715. return {
  15716. itemSize: this.itemSize,
  15717. type: this.array.constructor.name,
  15718. array: array,
  15719. normalized: this.normalized
  15720. };
  15721. } else {
  15722. // save as true interlaved attribtue
  15723. if (data.interleavedBuffers === undefined) {
  15724. data.interleavedBuffers = {};
  15725. }
  15726. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15727. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15728. }
  15729. return {
  15730. isInterleavedBufferAttribute: true,
  15731. itemSize: this.itemSize,
  15732. data: this.data.uuid,
  15733. offset: this.offset,
  15734. normalized: this.normalized
  15735. };
  15736. }
  15737. }
  15738. });
  15739. /**
  15740. * parameters = {
  15741. * color: <hex>,
  15742. * map: new THREE.Texture( <Image> ),
  15743. * alphaMap: new THREE.Texture( <Image> ),
  15744. * rotation: <float>,
  15745. * sizeAttenuation: <bool>
  15746. * }
  15747. */
  15748. function SpriteMaterial(parameters) {
  15749. Material.call(this);
  15750. this.type = 'SpriteMaterial';
  15751. this.color = new Color(0xffffff);
  15752. this.map = null;
  15753. this.alphaMap = null;
  15754. this.rotation = 0;
  15755. this.sizeAttenuation = true;
  15756. this.transparent = true;
  15757. this.setValues(parameters);
  15758. }
  15759. SpriteMaterial.prototype = Object.create(Material.prototype);
  15760. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15761. SpriteMaterial.prototype.isSpriteMaterial = true;
  15762. SpriteMaterial.prototype.copy = function (source) {
  15763. Material.prototype.copy.call(this, source);
  15764. this.color.copy(source.color);
  15765. this.map = source.map;
  15766. this.alphaMap = source.alphaMap;
  15767. this.rotation = source.rotation;
  15768. this.sizeAttenuation = source.sizeAttenuation;
  15769. return this;
  15770. };
  15771. var _geometry;
  15772. var _intersectPoint = new Vector3();
  15773. var _worldScale = new Vector3();
  15774. var _mvPosition = new Vector3();
  15775. var _alignedPosition = new Vector2();
  15776. var _rotatedPosition = new Vector2();
  15777. var _viewWorldMatrix = new Matrix4();
  15778. var _vA$1 = new Vector3();
  15779. var _vB$1 = new Vector3();
  15780. var _vC$1 = new Vector3();
  15781. var _uvA$1 = new Vector2();
  15782. var _uvB$1 = new Vector2();
  15783. var _uvC$1 = new Vector2();
  15784. function Sprite(material) {
  15785. Object3D.call(this);
  15786. this.type = 'Sprite';
  15787. if (_geometry === undefined) {
  15788. _geometry = new BufferGeometry();
  15789. 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]);
  15790. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15791. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15792. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15793. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15794. }
  15795. this.geometry = _geometry;
  15796. this.material = material !== undefined ? material : new SpriteMaterial();
  15797. this.center = new Vector2(0.5, 0.5);
  15798. }
  15799. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15800. constructor: Sprite,
  15801. isSprite: true,
  15802. raycast: function raycast(raycaster, intersects) {
  15803. if (raycaster.camera === null) {
  15804. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15805. }
  15806. _worldScale.setFromMatrixScale(this.matrixWorld);
  15807. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15808. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15809. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15810. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15811. _worldScale.multiplyScalar(-_mvPosition.z);
  15812. }
  15813. var rotation = this.material.rotation;
  15814. var sin, cos;
  15815. if (rotation !== 0) {
  15816. cos = Math.cos(rotation);
  15817. sin = Math.sin(rotation);
  15818. }
  15819. var center = this.center;
  15820. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15821. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15822. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15823. _uvA$1.set(0, 0);
  15824. _uvB$1.set(1, 0);
  15825. _uvC$1.set(1, 1); // check first triangle
  15826. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15827. if (intersect === null) {
  15828. // check second triangle
  15829. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15830. _uvB$1.set(0, 1);
  15831. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15832. if (intersect === null) {
  15833. return;
  15834. }
  15835. }
  15836. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15837. if (distance < raycaster.near || distance > raycaster.far) return;
  15838. intersects.push({
  15839. distance: distance,
  15840. point: _intersectPoint.clone(),
  15841. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15842. face: null,
  15843. object: this
  15844. });
  15845. },
  15846. copy: function copy(source) {
  15847. Object3D.prototype.copy.call(this, source);
  15848. if (source.center !== undefined) this.center.copy(source.center);
  15849. this.material = source.material;
  15850. return this;
  15851. }
  15852. });
  15853. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15854. // compute position in camera space
  15855. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15856. if (sin !== undefined) {
  15857. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15858. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15859. } else {
  15860. _rotatedPosition.copy(_alignedPosition);
  15861. }
  15862. vertexPosition.copy(mvPosition);
  15863. vertexPosition.x += _rotatedPosition.x;
  15864. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15865. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15866. }
  15867. var _v1$4 = new Vector3();
  15868. var _v2$2 = new Vector3();
  15869. function LOD() {
  15870. Object3D.call(this);
  15871. this._currentLevel = 0;
  15872. this.type = 'LOD';
  15873. Object.defineProperties(this, {
  15874. levels: {
  15875. enumerable: true,
  15876. value: []
  15877. }
  15878. });
  15879. this.autoUpdate = true;
  15880. }
  15881. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15882. constructor: LOD,
  15883. isLOD: true,
  15884. copy: function copy(source) {
  15885. Object3D.prototype.copy.call(this, source, false);
  15886. var levels = source.levels;
  15887. for (var i = 0, l = levels.length; i < l; i++) {
  15888. var level = levels[i];
  15889. this.addLevel(level.object.clone(), level.distance);
  15890. }
  15891. this.autoUpdate = source.autoUpdate;
  15892. return this;
  15893. },
  15894. addLevel: function addLevel(object, distance) {
  15895. if (distance === void 0) {
  15896. distance = 0;
  15897. }
  15898. distance = Math.abs(distance);
  15899. var levels = this.levels;
  15900. var l;
  15901. for (l = 0; l < levels.length; l++) {
  15902. if (distance < levels[l].distance) {
  15903. break;
  15904. }
  15905. }
  15906. levels.splice(l, 0, {
  15907. distance: distance,
  15908. object: object
  15909. });
  15910. this.add(object);
  15911. return this;
  15912. },
  15913. getCurrentLevel: function getCurrentLevel() {
  15914. return this._currentLevel;
  15915. },
  15916. getObjectForDistance: function getObjectForDistance(distance) {
  15917. var levels = this.levels;
  15918. if (levels.length > 0) {
  15919. var i, l;
  15920. for (i = 1, l = levels.length; i < l; i++) {
  15921. if (distance < levels[i].distance) {
  15922. break;
  15923. }
  15924. }
  15925. return levels[i - 1].object;
  15926. }
  15927. return null;
  15928. },
  15929. raycast: function raycast(raycaster, intersects) {
  15930. var levels = this.levels;
  15931. if (levels.length > 0) {
  15932. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15933. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15934. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15935. }
  15936. },
  15937. update: function update(camera) {
  15938. var levels = this.levels;
  15939. if (levels.length > 1) {
  15940. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15941. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15942. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15943. levels[0].object.visible = true;
  15944. var i, l;
  15945. for (i = 1, l = levels.length; i < l; i++) {
  15946. if (distance >= levels[i].distance) {
  15947. levels[i - 1].object.visible = false;
  15948. levels[i].object.visible = true;
  15949. } else {
  15950. break;
  15951. }
  15952. }
  15953. this._currentLevel = i - 1;
  15954. for (; i < l; i++) {
  15955. levels[i].object.visible = false;
  15956. }
  15957. }
  15958. },
  15959. toJSON: function toJSON(meta) {
  15960. var data = Object3D.prototype.toJSON.call(this, meta);
  15961. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15962. data.object.levels = [];
  15963. var levels = this.levels;
  15964. for (var i = 0, l = levels.length; i < l; i++) {
  15965. var level = levels[i];
  15966. data.object.levels.push({
  15967. object: level.object.uuid,
  15968. distance: level.distance
  15969. });
  15970. }
  15971. return data;
  15972. }
  15973. });
  15974. var _basePosition = new Vector3();
  15975. var _skinIndex = new Vector4();
  15976. var _skinWeight = new Vector4();
  15977. var _vector$7 = new Vector3();
  15978. var _matrix$1 = new Matrix4();
  15979. function SkinnedMesh(geometry, material) {
  15980. if (geometry && geometry.isGeometry) {
  15981. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15982. }
  15983. Mesh.call(this, geometry, material);
  15984. this.type = 'SkinnedMesh';
  15985. this.bindMode = 'attached';
  15986. this.bindMatrix = new Matrix4();
  15987. this.bindMatrixInverse = new Matrix4();
  15988. }
  15989. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15990. constructor: SkinnedMesh,
  15991. isSkinnedMesh: true,
  15992. copy: function copy(source) {
  15993. Mesh.prototype.copy.call(this, source);
  15994. this.bindMode = source.bindMode;
  15995. this.bindMatrix.copy(source.bindMatrix);
  15996. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15997. this.skeleton = source.skeleton;
  15998. return this;
  15999. },
  16000. bind: function bind(skeleton, bindMatrix) {
  16001. this.skeleton = skeleton;
  16002. if (bindMatrix === undefined) {
  16003. this.updateMatrixWorld(true);
  16004. this.skeleton.calculateInverses();
  16005. bindMatrix = this.matrixWorld;
  16006. }
  16007. this.bindMatrix.copy(bindMatrix);
  16008. this.bindMatrixInverse.copy(bindMatrix).invert();
  16009. },
  16010. pose: function pose() {
  16011. this.skeleton.pose();
  16012. },
  16013. normalizeSkinWeights: function normalizeSkinWeights() {
  16014. var vector = new Vector4();
  16015. var skinWeight = this.geometry.attributes.skinWeight;
  16016. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16017. vector.x = skinWeight.getX(i);
  16018. vector.y = skinWeight.getY(i);
  16019. vector.z = skinWeight.getZ(i);
  16020. vector.w = skinWeight.getW(i);
  16021. var scale = 1.0 / vector.manhattanLength();
  16022. if (scale !== Infinity) {
  16023. vector.multiplyScalar(scale);
  16024. } else {
  16025. vector.set(1, 0, 0, 0); // do something reasonable
  16026. }
  16027. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16028. }
  16029. },
  16030. updateMatrixWorld: function updateMatrixWorld(force) {
  16031. Mesh.prototype.updateMatrixWorld.call(this, force);
  16032. if (this.bindMode === 'attached') {
  16033. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16034. } else if (this.bindMode === 'detached') {
  16035. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16036. } else {
  16037. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16038. }
  16039. },
  16040. boneTransform: function boneTransform(index, target) {
  16041. var skeleton = this.skeleton;
  16042. var geometry = this.geometry;
  16043. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16044. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16045. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16046. target.set(0, 0, 0);
  16047. for (var i = 0; i < 4; i++) {
  16048. var weight = _skinWeight.getComponent(i);
  16049. if (weight !== 0) {
  16050. var boneIndex = _skinIndex.getComponent(i);
  16051. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16052. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16053. }
  16054. }
  16055. return target.applyMatrix4(this.bindMatrixInverse);
  16056. }
  16057. });
  16058. function Bone() {
  16059. Object3D.call(this);
  16060. this.type = 'Bone';
  16061. }
  16062. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16063. constructor: Bone,
  16064. isBone: true
  16065. });
  16066. var _offsetMatrix = new Matrix4();
  16067. var _identityMatrix = new Matrix4();
  16068. function Skeleton(bones, boneInverses) {
  16069. if (bones === void 0) {
  16070. bones = [];
  16071. }
  16072. if (boneInverses === void 0) {
  16073. boneInverses = [];
  16074. }
  16075. this.uuid = MathUtils.generateUUID();
  16076. this.bones = bones.slice(0);
  16077. this.boneInverses = boneInverses;
  16078. this.boneMatrices = null;
  16079. this.boneTexture = null;
  16080. this.boneTextureSize = 0;
  16081. this.frame = -1;
  16082. this.init();
  16083. }
  16084. Object.assign(Skeleton.prototype, {
  16085. init: function init() {
  16086. var bones = this.bones;
  16087. var boneInverses = this.boneInverses;
  16088. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16089. if (boneInverses.length === 0) {
  16090. this.calculateInverses();
  16091. } else {
  16092. // handle special case
  16093. if (bones.length !== boneInverses.length) {
  16094. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16095. this.boneInverses = [];
  16096. for (var i = 0, il = this.bones.length; i < il; i++) {
  16097. this.boneInverses.push(new Matrix4());
  16098. }
  16099. }
  16100. }
  16101. },
  16102. calculateInverses: function calculateInverses() {
  16103. this.boneInverses.length = 0;
  16104. for (var i = 0, il = this.bones.length; i < il; i++) {
  16105. var inverse = new Matrix4();
  16106. if (this.bones[i]) {
  16107. inverse.copy(this.bones[i].matrixWorld).invert();
  16108. }
  16109. this.boneInverses.push(inverse);
  16110. }
  16111. },
  16112. pose: function pose() {
  16113. // recover the bind-time world matrices
  16114. for (var i = 0, il = this.bones.length; i < il; i++) {
  16115. var bone = this.bones[i];
  16116. if (bone) {
  16117. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16118. }
  16119. } // compute the local matrices, positions, rotations and scales
  16120. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16121. var _bone = this.bones[_i];
  16122. if (_bone) {
  16123. if (_bone.parent && _bone.parent.isBone) {
  16124. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16125. _bone.matrix.multiply(_bone.matrixWorld);
  16126. } else {
  16127. _bone.matrix.copy(_bone.matrixWorld);
  16128. }
  16129. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16130. }
  16131. }
  16132. },
  16133. update: function update() {
  16134. var bones = this.bones;
  16135. var boneInverses = this.boneInverses;
  16136. var boneMatrices = this.boneMatrices;
  16137. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16138. for (var i = 0, il = bones.length; i < il; i++) {
  16139. // compute the offset between the current and the original transform
  16140. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16141. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16142. _offsetMatrix.toArray(boneMatrices, i * 16);
  16143. }
  16144. if (boneTexture !== null) {
  16145. boneTexture.needsUpdate = true;
  16146. }
  16147. },
  16148. clone: function clone() {
  16149. return new Skeleton(this.bones, this.boneInverses);
  16150. },
  16151. getBoneByName: function getBoneByName(name) {
  16152. for (var i = 0, il = this.bones.length; i < il; i++) {
  16153. var bone = this.bones[i];
  16154. if (bone.name === name) {
  16155. return bone;
  16156. }
  16157. }
  16158. return undefined;
  16159. },
  16160. dispose: function dispose() {
  16161. if (this.boneTexture !== null) {
  16162. this.boneTexture.dispose();
  16163. this.boneTexture = null;
  16164. }
  16165. },
  16166. fromJSON: function fromJSON(json, bones) {
  16167. this.uuid = json.uuid;
  16168. for (var i = 0, l = json.bones.length; i < l; i++) {
  16169. var uuid = json.bones[i];
  16170. var bone = bones[uuid];
  16171. if (bone === undefined) {
  16172. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16173. bone = new Bone();
  16174. }
  16175. this.bones.push(bone);
  16176. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16177. }
  16178. this.init();
  16179. return this;
  16180. },
  16181. toJSON: function toJSON() {
  16182. var data = {
  16183. metadata: {
  16184. version: 4.5,
  16185. type: 'Skeleton',
  16186. generator: 'Skeleton.toJSON'
  16187. },
  16188. bones: [],
  16189. boneInverses: []
  16190. };
  16191. data.uuid = this.uuid;
  16192. var bones = this.bones;
  16193. var boneInverses = this.boneInverses;
  16194. for (var i = 0, l = bones.length; i < l; i++) {
  16195. var bone = bones[i];
  16196. data.bones.push(bone.uuid);
  16197. var boneInverse = boneInverses[i];
  16198. data.boneInverses.push(boneInverse.toArray());
  16199. }
  16200. return data;
  16201. }
  16202. });
  16203. var _instanceLocalMatrix = new Matrix4();
  16204. var _instanceWorldMatrix = new Matrix4();
  16205. var _instanceIntersects = [];
  16206. var _mesh = new Mesh();
  16207. function InstancedMesh(geometry, material, count) {
  16208. Mesh.call(this, geometry, material);
  16209. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16210. this.instanceColor = null;
  16211. this.count = count;
  16212. this.frustumCulled = false;
  16213. }
  16214. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16215. constructor: InstancedMesh,
  16216. isInstancedMesh: true,
  16217. copy: function copy(source) {
  16218. Mesh.prototype.copy.call(this, source);
  16219. this.instanceMatrix.copy(source.instanceMatrix);
  16220. this.count = source.count;
  16221. return this;
  16222. },
  16223. getColorAt: function getColorAt(index, color) {
  16224. color.fromArray(this.instanceColor.array, index * 3);
  16225. },
  16226. getMatrixAt: function getMatrixAt(index, matrix) {
  16227. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16228. },
  16229. raycast: function raycast(raycaster, intersects) {
  16230. var matrixWorld = this.matrixWorld;
  16231. var raycastTimes = this.count;
  16232. _mesh.geometry = this.geometry;
  16233. _mesh.material = this.material;
  16234. if (_mesh.material === undefined) return;
  16235. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16236. // calculate the world matrix for each instance
  16237. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16238. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16239. _mesh.matrixWorld = _instanceWorldMatrix;
  16240. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16241. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16242. var intersect = _instanceIntersects[i];
  16243. intersect.instanceId = instanceId;
  16244. intersect.object = this;
  16245. intersects.push(intersect);
  16246. }
  16247. _instanceIntersects.length = 0;
  16248. }
  16249. },
  16250. setColorAt: function setColorAt(index, color) {
  16251. if (this.instanceColor === null) {
  16252. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16253. }
  16254. color.toArray(this.instanceColor.array, index * 3);
  16255. },
  16256. setMatrixAt: function setMatrixAt(index, matrix) {
  16257. matrix.toArray(this.instanceMatrix.array, index * 16);
  16258. },
  16259. updateMorphTargets: function updateMorphTargets() {},
  16260. dispose: function dispose() {
  16261. this.dispatchEvent({
  16262. type: 'dispose'
  16263. });
  16264. }
  16265. });
  16266. /**
  16267. * parameters = {
  16268. * color: <hex>,
  16269. * opacity: <float>,
  16270. *
  16271. * linewidth: <float>,
  16272. * linecap: "round",
  16273. * linejoin: "round"
  16274. * }
  16275. */
  16276. function LineBasicMaterial(parameters) {
  16277. Material.call(this);
  16278. this.type = 'LineBasicMaterial';
  16279. this.color = new Color(0xffffff);
  16280. this.linewidth = 1;
  16281. this.linecap = 'round';
  16282. this.linejoin = 'round';
  16283. this.morphTargets = false;
  16284. this.setValues(parameters);
  16285. }
  16286. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16287. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16288. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16289. LineBasicMaterial.prototype.copy = function (source) {
  16290. Material.prototype.copy.call(this, source);
  16291. this.color.copy(source.color);
  16292. this.linewidth = source.linewidth;
  16293. this.linecap = source.linecap;
  16294. this.linejoin = source.linejoin;
  16295. this.morphTargets = source.morphTargets;
  16296. return this;
  16297. };
  16298. var _start = new Vector3();
  16299. var _end = new Vector3();
  16300. var _inverseMatrix$1 = new Matrix4();
  16301. var _ray$1 = new Ray();
  16302. var _sphere$2 = new Sphere();
  16303. function Line(geometry, material) {
  16304. if (geometry === void 0) {
  16305. geometry = new BufferGeometry();
  16306. }
  16307. if (material === void 0) {
  16308. material = new LineBasicMaterial();
  16309. }
  16310. Object3D.call(this);
  16311. this.type = 'Line';
  16312. this.geometry = geometry;
  16313. this.material = material;
  16314. this.updateMorphTargets();
  16315. }
  16316. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16317. constructor: Line,
  16318. isLine: true,
  16319. copy: function copy(source) {
  16320. Object3D.prototype.copy.call(this, source);
  16321. this.material = source.material;
  16322. this.geometry = source.geometry;
  16323. return this;
  16324. },
  16325. computeLineDistances: function computeLineDistances() {
  16326. var geometry = this.geometry;
  16327. if (geometry.isBufferGeometry) {
  16328. // we assume non-indexed geometry
  16329. if (geometry.index === null) {
  16330. var positionAttribute = geometry.attributes.position;
  16331. var lineDistances = [0];
  16332. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16333. _start.fromBufferAttribute(positionAttribute, i - 1);
  16334. _end.fromBufferAttribute(positionAttribute, i);
  16335. lineDistances[i] = lineDistances[i - 1];
  16336. lineDistances[i] += _start.distanceTo(_end);
  16337. }
  16338. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16339. } else {
  16340. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16341. }
  16342. } else if (geometry.isGeometry) {
  16343. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16344. }
  16345. return this;
  16346. },
  16347. raycast: function raycast(raycaster, intersects) {
  16348. var geometry = this.geometry;
  16349. var matrixWorld = this.matrixWorld;
  16350. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16351. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16352. _sphere$2.copy(geometry.boundingSphere);
  16353. _sphere$2.applyMatrix4(matrixWorld);
  16354. _sphere$2.radius += threshold;
  16355. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16356. _inverseMatrix$1.copy(matrixWorld).invert();
  16357. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16358. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16359. var localThresholdSq = localThreshold * localThreshold;
  16360. var vStart = new Vector3();
  16361. var vEnd = new Vector3();
  16362. var interSegment = new Vector3();
  16363. var interRay = new Vector3();
  16364. var step = this.isLineSegments ? 2 : 1;
  16365. if (geometry.isBufferGeometry) {
  16366. var index = geometry.index;
  16367. var attributes = geometry.attributes;
  16368. var positionAttribute = attributes.position;
  16369. if (index !== null) {
  16370. var indices = index.array;
  16371. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16372. var a = indices[i];
  16373. var b = indices[i + 1];
  16374. vStart.fromBufferAttribute(positionAttribute, a);
  16375. vEnd.fromBufferAttribute(positionAttribute, b);
  16376. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16377. if (distSq > localThresholdSq) continue;
  16378. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16379. var distance = raycaster.ray.origin.distanceTo(interRay);
  16380. if (distance < raycaster.near || distance > raycaster.far) continue;
  16381. intersects.push({
  16382. distance: distance,
  16383. // What do we want? intersection point on the ray or on the segment??
  16384. // point: raycaster.ray.at( distance ),
  16385. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16386. index: i,
  16387. face: null,
  16388. faceIndex: null,
  16389. object: this
  16390. });
  16391. }
  16392. } else {
  16393. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  16394. vStart.fromBufferAttribute(positionAttribute, _i);
  16395. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  16396. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16397. if (_distSq > localThresholdSq) continue;
  16398. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16399. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16400. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16401. intersects.push({
  16402. distance: _distance,
  16403. // What do we want? intersection point on the ray or on the segment??
  16404. // point: raycaster.ray.at( distance ),
  16405. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16406. index: _i,
  16407. face: null,
  16408. faceIndex: null,
  16409. object: this
  16410. });
  16411. }
  16412. }
  16413. } else if (geometry.isGeometry) {
  16414. var vertices = geometry.vertices;
  16415. var nbVertices = vertices.length;
  16416. for (var _i2 = 0; _i2 < nbVertices - 1; _i2 += step) {
  16417. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i2], vertices[_i2 + 1], interRay, interSegment);
  16418. if (_distSq2 > localThresholdSq) continue;
  16419. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16420. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16421. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16422. intersects.push({
  16423. distance: _distance2,
  16424. // What do we want? intersection point on the ray or on the segment??
  16425. // point: raycaster.ray.at( distance ),
  16426. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16427. index: _i2,
  16428. face: null,
  16429. faceIndex: null,
  16430. object: this
  16431. });
  16432. }
  16433. }
  16434. },
  16435. updateMorphTargets: function updateMorphTargets() {
  16436. var geometry = this.geometry;
  16437. if (geometry.isBufferGeometry) {
  16438. var morphAttributes = geometry.morphAttributes;
  16439. var keys = Object.keys(morphAttributes);
  16440. if (keys.length > 0) {
  16441. var morphAttribute = morphAttributes[keys[0]];
  16442. if (morphAttribute !== undefined) {
  16443. this.morphTargetInfluences = [];
  16444. this.morphTargetDictionary = {};
  16445. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16446. var name = morphAttribute[m].name || String(m);
  16447. this.morphTargetInfluences.push(0);
  16448. this.morphTargetDictionary[name] = m;
  16449. }
  16450. }
  16451. }
  16452. } else {
  16453. var morphTargets = geometry.morphTargets;
  16454. if (morphTargets !== undefined && morphTargets.length > 0) {
  16455. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16456. }
  16457. }
  16458. }
  16459. });
  16460. var _start$1 = new Vector3();
  16461. var _end$1 = new Vector3();
  16462. function LineSegments(geometry, material) {
  16463. Line.call(this, geometry, material);
  16464. this.type = 'LineSegments';
  16465. }
  16466. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16467. constructor: LineSegments,
  16468. isLineSegments: true,
  16469. computeLineDistances: function computeLineDistances() {
  16470. var geometry = this.geometry;
  16471. if (geometry.isBufferGeometry) {
  16472. // we assume non-indexed geometry
  16473. if (geometry.index === null) {
  16474. var positionAttribute = geometry.attributes.position;
  16475. var lineDistances = [];
  16476. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16477. _start$1.fromBufferAttribute(positionAttribute, i);
  16478. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16479. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16480. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16481. }
  16482. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16483. } else {
  16484. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16485. }
  16486. } else if (geometry.isGeometry) {
  16487. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16488. }
  16489. return this;
  16490. }
  16491. });
  16492. function LineLoop(geometry, material) {
  16493. Line.call(this, geometry, material);
  16494. this.type = 'LineLoop';
  16495. }
  16496. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16497. constructor: LineLoop,
  16498. isLineLoop: true
  16499. });
  16500. /**
  16501. * parameters = {
  16502. * color: <hex>,
  16503. * opacity: <float>,
  16504. * map: new THREE.Texture( <Image> ),
  16505. * alphaMap: new THREE.Texture( <Image> ),
  16506. *
  16507. * size: <float>,
  16508. * sizeAttenuation: <bool>
  16509. *
  16510. * morphTargets: <bool>
  16511. * }
  16512. */
  16513. function PointsMaterial(parameters) {
  16514. Material.call(this);
  16515. this.type = 'PointsMaterial';
  16516. this.color = new Color(0xffffff);
  16517. this.map = null;
  16518. this.alphaMap = null;
  16519. this.size = 1;
  16520. this.sizeAttenuation = true;
  16521. this.morphTargets = false;
  16522. this.setValues(parameters);
  16523. }
  16524. PointsMaterial.prototype = Object.create(Material.prototype);
  16525. PointsMaterial.prototype.constructor = PointsMaterial;
  16526. PointsMaterial.prototype.isPointsMaterial = true;
  16527. PointsMaterial.prototype.copy = function (source) {
  16528. Material.prototype.copy.call(this, source);
  16529. this.color.copy(source.color);
  16530. this.map = source.map;
  16531. this.alphaMap = source.alphaMap;
  16532. this.size = source.size;
  16533. this.sizeAttenuation = source.sizeAttenuation;
  16534. this.morphTargets = source.morphTargets;
  16535. return this;
  16536. };
  16537. var _inverseMatrix$2 = new Matrix4();
  16538. var _ray$2 = new Ray();
  16539. var _sphere$3 = new Sphere();
  16540. var _position$1 = new Vector3();
  16541. function Points(geometry, material) {
  16542. if (geometry === void 0) {
  16543. geometry = new BufferGeometry();
  16544. }
  16545. if (material === void 0) {
  16546. material = new PointsMaterial();
  16547. }
  16548. Object3D.call(this);
  16549. this.type = 'Points';
  16550. this.geometry = geometry;
  16551. this.material = material;
  16552. this.updateMorphTargets();
  16553. }
  16554. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16555. constructor: Points,
  16556. isPoints: true,
  16557. copy: function copy(source) {
  16558. Object3D.prototype.copy.call(this, source);
  16559. this.material = source.material;
  16560. this.geometry = source.geometry;
  16561. return this;
  16562. },
  16563. raycast: function raycast(raycaster, intersects) {
  16564. var geometry = this.geometry;
  16565. var matrixWorld = this.matrixWorld;
  16566. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16567. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16568. _sphere$3.copy(geometry.boundingSphere);
  16569. _sphere$3.applyMatrix4(matrixWorld);
  16570. _sphere$3.radius += threshold;
  16571. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16572. _inverseMatrix$2.copy(matrixWorld).invert();
  16573. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16574. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16575. var localThresholdSq = localThreshold * localThreshold;
  16576. if (geometry.isBufferGeometry) {
  16577. var index = geometry.index;
  16578. var attributes = geometry.attributes;
  16579. var positionAttribute = attributes.position;
  16580. if (index !== null) {
  16581. var indices = index.array;
  16582. for (var i = 0, il = indices.length; i < il; i++) {
  16583. var a = indices[i];
  16584. _position$1.fromBufferAttribute(positionAttribute, a);
  16585. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16586. }
  16587. } else {
  16588. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16589. _position$1.fromBufferAttribute(positionAttribute, _i);
  16590. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16591. }
  16592. }
  16593. } else {
  16594. var vertices = geometry.vertices;
  16595. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16596. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16597. }
  16598. }
  16599. },
  16600. updateMorphTargets: function updateMorphTargets() {
  16601. var geometry = this.geometry;
  16602. if (geometry.isBufferGeometry) {
  16603. var morphAttributes = geometry.morphAttributes;
  16604. var keys = Object.keys(morphAttributes);
  16605. if (keys.length > 0) {
  16606. var morphAttribute = morphAttributes[keys[0]];
  16607. if (morphAttribute !== undefined) {
  16608. this.morphTargetInfluences = [];
  16609. this.morphTargetDictionary = {};
  16610. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16611. var name = morphAttribute[m].name || String(m);
  16612. this.morphTargetInfluences.push(0);
  16613. this.morphTargetDictionary[name] = m;
  16614. }
  16615. }
  16616. }
  16617. } else {
  16618. var morphTargets = geometry.morphTargets;
  16619. if (morphTargets !== undefined && morphTargets.length > 0) {
  16620. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16621. }
  16622. }
  16623. }
  16624. });
  16625. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16626. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16627. if (rayPointDistanceSq < localThresholdSq) {
  16628. var intersectPoint = new Vector3();
  16629. _ray$2.closestPointToPoint(point, intersectPoint);
  16630. intersectPoint.applyMatrix4(matrixWorld);
  16631. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16632. if (distance < raycaster.near || distance > raycaster.far) return;
  16633. intersects.push({
  16634. distance: distance,
  16635. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16636. point: intersectPoint,
  16637. index: index,
  16638. face: null,
  16639. object: object
  16640. });
  16641. }
  16642. }
  16643. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16644. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16645. this.format = format !== undefined ? format : RGBFormat;
  16646. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16647. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16648. this.generateMipmaps = false;
  16649. var scope = this;
  16650. function updateVideo() {
  16651. scope.needsUpdate = true;
  16652. video.requestVideoFrameCallback(updateVideo);
  16653. }
  16654. if ('requestVideoFrameCallback' in video) {
  16655. video.requestVideoFrameCallback(updateVideo);
  16656. }
  16657. }
  16658. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16659. constructor: VideoTexture,
  16660. clone: function clone() {
  16661. return new this.constructor(this.image).copy(this);
  16662. },
  16663. isVideoTexture: true,
  16664. update: function update() {
  16665. var video = this.image;
  16666. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16667. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16668. this.needsUpdate = true;
  16669. }
  16670. }
  16671. });
  16672. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16673. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16674. this.image = {
  16675. width: width,
  16676. height: height
  16677. };
  16678. this.mipmaps = mipmaps; // no flipping for cube textures
  16679. // (also flipping doesn't work for compressed textures )
  16680. this.flipY = false; // can't generate mipmaps for compressed textures
  16681. // mips must be embedded in DDS files
  16682. this.generateMipmaps = false;
  16683. }
  16684. CompressedTexture.prototype = Object.create(Texture.prototype);
  16685. CompressedTexture.prototype.constructor = CompressedTexture;
  16686. CompressedTexture.prototype.isCompressedTexture = true;
  16687. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16688. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16689. this.needsUpdate = true;
  16690. }
  16691. CanvasTexture.prototype = Object.create(Texture.prototype);
  16692. CanvasTexture.prototype.constructor = CanvasTexture;
  16693. CanvasTexture.prototype.isCanvasTexture = true;
  16694. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16695. format = format !== undefined ? format : DepthFormat;
  16696. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16697. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16698. }
  16699. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16700. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16701. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16702. this.image = {
  16703. width: width,
  16704. height: height
  16705. };
  16706. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16707. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16708. this.flipY = false;
  16709. this.generateMipmaps = false;
  16710. }
  16711. DepthTexture.prototype = Object.create(Texture.prototype);
  16712. DepthTexture.prototype.constructor = DepthTexture;
  16713. DepthTexture.prototype.isDepthTexture = true;
  16714. var _geometryId = 0; // Geometry uses even numbers as Id
  16715. var _m1$3 = new Matrix4();
  16716. var _obj$1 = new Object3D();
  16717. var _offset$1 = new Vector3();
  16718. function Geometry() {
  16719. Object.defineProperty(this, 'id', {
  16720. value: _geometryId += 2
  16721. });
  16722. this.uuid = MathUtils.generateUUID();
  16723. this.name = '';
  16724. this.type = 'Geometry';
  16725. this.vertices = [];
  16726. this.colors = [];
  16727. this.faces = [];
  16728. this.faceVertexUvs = [[]];
  16729. this.morphTargets = [];
  16730. this.morphNormals = [];
  16731. this.skinWeights = [];
  16732. this.skinIndices = [];
  16733. this.lineDistances = [];
  16734. this.boundingBox = null;
  16735. this.boundingSphere = null; // update flags
  16736. this.elementsNeedUpdate = false;
  16737. this.verticesNeedUpdate = false;
  16738. this.uvsNeedUpdate = false;
  16739. this.normalsNeedUpdate = false;
  16740. this.colorsNeedUpdate = false;
  16741. this.lineDistancesNeedUpdate = false;
  16742. this.groupsNeedUpdate = false;
  16743. }
  16744. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16745. constructor: Geometry,
  16746. isGeometry: true,
  16747. applyMatrix4: function applyMatrix4(matrix) {
  16748. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16749. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16750. var vertex = this.vertices[i];
  16751. vertex.applyMatrix4(matrix);
  16752. }
  16753. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16754. var face = this.faces[_i];
  16755. face.normal.applyMatrix3(normalMatrix).normalize();
  16756. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16757. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16758. }
  16759. }
  16760. if (this.boundingBox !== null) {
  16761. this.computeBoundingBox();
  16762. }
  16763. if (this.boundingSphere !== null) {
  16764. this.computeBoundingSphere();
  16765. }
  16766. this.verticesNeedUpdate = true;
  16767. this.normalsNeedUpdate = true;
  16768. return this;
  16769. },
  16770. rotateX: function rotateX(angle) {
  16771. // rotate geometry around world x-axis
  16772. _m1$3.makeRotationX(angle);
  16773. this.applyMatrix4(_m1$3);
  16774. return this;
  16775. },
  16776. rotateY: function rotateY(angle) {
  16777. // rotate geometry around world y-axis
  16778. _m1$3.makeRotationY(angle);
  16779. this.applyMatrix4(_m1$3);
  16780. return this;
  16781. },
  16782. rotateZ: function rotateZ(angle) {
  16783. // rotate geometry around world z-axis
  16784. _m1$3.makeRotationZ(angle);
  16785. this.applyMatrix4(_m1$3);
  16786. return this;
  16787. },
  16788. translate: function translate(x, y, z) {
  16789. // translate geometry
  16790. _m1$3.makeTranslation(x, y, z);
  16791. this.applyMatrix4(_m1$3);
  16792. return this;
  16793. },
  16794. scale: function scale(x, y, z) {
  16795. // scale geometry
  16796. _m1$3.makeScale(x, y, z);
  16797. this.applyMatrix4(_m1$3);
  16798. return this;
  16799. },
  16800. lookAt: function lookAt(vector) {
  16801. _obj$1.lookAt(vector);
  16802. _obj$1.updateMatrix();
  16803. this.applyMatrix4(_obj$1.matrix);
  16804. return this;
  16805. },
  16806. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16807. var scope = this;
  16808. var index = geometry.index !== null ? geometry.index : undefined;
  16809. var attributes = geometry.attributes;
  16810. if (attributes.position === undefined) {
  16811. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16812. return this;
  16813. }
  16814. var position = attributes.position;
  16815. var normal = attributes.normal;
  16816. var color = attributes.color;
  16817. var uv = attributes.uv;
  16818. var uv2 = attributes.uv2;
  16819. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16820. for (var i = 0; i < position.count; i++) {
  16821. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16822. if (color !== undefined) {
  16823. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16824. }
  16825. }
  16826. function addFace(a, b, c, materialIndex) {
  16827. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16828. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16829. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16830. scope.faces.push(face);
  16831. if (uv !== undefined) {
  16832. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16833. }
  16834. if (uv2 !== undefined) {
  16835. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16836. }
  16837. }
  16838. var groups = geometry.groups;
  16839. if (groups.length > 0) {
  16840. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16841. var group = groups[_i2];
  16842. var start = group.start;
  16843. var count = group.count;
  16844. for (var j = start, jl = start + count; j < jl; j += 3) {
  16845. if (index !== undefined) {
  16846. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16847. } else {
  16848. addFace(j, j + 1, j + 2, group.materialIndex);
  16849. }
  16850. }
  16851. }
  16852. } else {
  16853. if (index !== undefined) {
  16854. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16855. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16856. }
  16857. } else {
  16858. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16859. addFace(_i4, _i4 + 1, _i4 + 2);
  16860. }
  16861. }
  16862. }
  16863. this.computeFaceNormals();
  16864. if (geometry.boundingBox !== null) {
  16865. this.boundingBox = geometry.boundingBox.clone();
  16866. }
  16867. if (geometry.boundingSphere !== null) {
  16868. this.boundingSphere = geometry.boundingSphere.clone();
  16869. }
  16870. return this;
  16871. },
  16872. center: function center() {
  16873. this.computeBoundingBox();
  16874. this.boundingBox.getCenter(_offset$1).negate();
  16875. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16876. return this;
  16877. },
  16878. normalize: function normalize() {
  16879. this.computeBoundingSphere();
  16880. var center = this.boundingSphere.center;
  16881. var radius = this.boundingSphere.radius;
  16882. var s = radius === 0 ? 1 : 1.0 / radius;
  16883. var matrix = new Matrix4();
  16884. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16885. this.applyMatrix4(matrix);
  16886. return this;
  16887. },
  16888. computeFaceNormals: function computeFaceNormals() {
  16889. var cb = new Vector3(),
  16890. ab = new Vector3();
  16891. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16892. var face = this.faces[f];
  16893. var vA = this.vertices[face.a];
  16894. var vB = this.vertices[face.b];
  16895. var vC = this.vertices[face.c];
  16896. cb.subVectors(vC, vB);
  16897. ab.subVectors(vA, vB);
  16898. cb.cross(ab);
  16899. cb.normalize();
  16900. face.normal.copy(cb);
  16901. }
  16902. },
  16903. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16904. if (areaWeighted === void 0) {
  16905. areaWeighted = true;
  16906. }
  16907. var vertices = new Array(this.vertices.length);
  16908. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16909. vertices[v] = new Vector3();
  16910. }
  16911. if (areaWeighted) {
  16912. // vertex normals weighted by triangle areas
  16913. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16914. var cb = new Vector3(),
  16915. ab = new Vector3();
  16916. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16917. var face = this.faces[f];
  16918. var vA = this.vertices[face.a];
  16919. var vB = this.vertices[face.b];
  16920. var vC = this.vertices[face.c];
  16921. cb.subVectors(vC, vB);
  16922. ab.subVectors(vA, vB);
  16923. cb.cross(ab);
  16924. vertices[face.a].add(cb);
  16925. vertices[face.b].add(cb);
  16926. vertices[face.c].add(cb);
  16927. }
  16928. } else {
  16929. this.computeFaceNormals();
  16930. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16931. var _face = this.faces[_f];
  16932. vertices[_face.a].add(_face.normal);
  16933. vertices[_face.b].add(_face.normal);
  16934. vertices[_face.c].add(_face.normal);
  16935. }
  16936. }
  16937. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16938. vertices[_v].normalize();
  16939. }
  16940. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16941. var _face2 = this.faces[_f2];
  16942. var vertexNormals = _face2.vertexNormals;
  16943. if (vertexNormals.length === 3) {
  16944. vertexNormals[0].copy(vertices[_face2.a]);
  16945. vertexNormals[1].copy(vertices[_face2.b]);
  16946. vertexNormals[2].copy(vertices[_face2.c]);
  16947. } else {
  16948. vertexNormals[0] = vertices[_face2.a].clone();
  16949. vertexNormals[1] = vertices[_face2.b].clone();
  16950. vertexNormals[2] = vertices[_face2.c].clone();
  16951. }
  16952. }
  16953. if (this.faces.length > 0) {
  16954. this.normalsNeedUpdate = true;
  16955. }
  16956. },
  16957. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16958. this.computeFaceNormals();
  16959. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16960. var face = this.faces[f];
  16961. var vertexNormals = face.vertexNormals;
  16962. if (vertexNormals.length === 3) {
  16963. vertexNormals[0].copy(face.normal);
  16964. vertexNormals[1].copy(face.normal);
  16965. vertexNormals[2].copy(face.normal);
  16966. } else {
  16967. vertexNormals[0] = face.normal.clone();
  16968. vertexNormals[1] = face.normal.clone();
  16969. vertexNormals[2] = face.normal.clone();
  16970. }
  16971. }
  16972. if (this.faces.length > 0) {
  16973. this.normalsNeedUpdate = true;
  16974. }
  16975. },
  16976. computeMorphNormals: function computeMorphNormals() {
  16977. // save original normals
  16978. // - create temp variables on first access
  16979. // otherwise just copy (for faster repeated calls)
  16980. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16981. var face = this.faces[f];
  16982. if (!face.__originalFaceNormal) {
  16983. face.__originalFaceNormal = face.normal.clone();
  16984. } else {
  16985. face.__originalFaceNormal.copy(face.normal);
  16986. }
  16987. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16988. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16989. if (!face.__originalVertexNormals[i]) {
  16990. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16991. } else {
  16992. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16993. }
  16994. }
  16995. } // use temp geometry to compute face and vertex normals for each morph
  16996. var tmpGeo = new Geometry();
  16997. tmpGeo.faces = this.faces;
  16998. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  16999. // create on first access
  17000. if (!this.morphNormals[_i5]) {
  17001. this.morphNormals[_i5] = {};
  17002. this.morphNormals[_i5].faceNormals = [];
  17003. this.morphNormals[_i5].vertexNormals = [];
  17004. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  17005. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  17006. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  17007. var faceNormal = new Vector3();
  17008. var vertexNormals = {
  17009. a: new Vector3(),
  17010. b: new Vector3(),
  17011. c: new Vector3()
  17012. };
  17013. dstNormalsFace.push(faceNormal);
  17014. dstNormalsVertex.push(vertexNormals);
  17015. }
  17016. }
  17017. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  17018. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  17019. tmpGeo.computeFaceNormals();
  17020. tmpGeo.computeVertexNormals(); // store morph normals
  17021. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  17022. var _face3 = this.faces[_f4];
  17023. var _faceNormal = morphNormals.faceNormals[_f4];
  17024. var _vertexNormals = morphNormals.vertexNormals[_f4];
  17025. _faceNormal.copy(_face3.normal);
  17026. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  17027. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  17028. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  17029. }
  17030. } // restore original normals
  17031. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  17032. var _face4 = this.faces[_f5];
  17033. _face4.normal = _face4.__originalFaceNormal;
  17034. _face4.vertexNormals = _face4.__originalVertexNormals;
  17035. }
  17036. },
  17037. computeBoundingBox: function computeBoundingBox() {
  17038. if (this.boundingBox === null) {
  17039. this.boundingBox = new Box3();
  17040. }
  17041. this.boundingBox.setFromPoints(this.vertices);
  17042. },
  17043. computeBoundingSphere: function computeBoundingSphere() {
  17044. if (this.boundingSphere === null) {
  17045. this.boundingSphere = new Sphere();
  17046. }
  17047. this.boundingSphere.setFromPoints(this.vertices);
  17048. },
  17049. merge: function merge(geometry, matrix, materialIndexOffset) {
  17050. if (materialIndexOffset === void 0) {
  17051. materialIndexOffset = 0;
  17052. }
  17053. if (!(geometry && geometry.isGeometry)) {
  17054. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  17055. return;
  17056. }
  17057. var normalMatrix;
  17058. var vertexOffset = this.vertices.length,
  17059. vertices1 = this.vertices,
  17060. vertices2 = geometry.vertices,
  17061. faces1 = this.faces,
  17062. faces2 = geometry.faces,
  17063. colors1 = this.colors,
  17064. colors2 = geometry.colors;
  17065. if (matrix !== undefined) {
  17066. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  17067. } // vertices
  17068. for (var i = 0, il = vertices2.length; i < il; i++) {
  17069. var vertex = vertices2[i];
  17070. var vertexCopy = vertex.clone();
  17071. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  17072. vertices1.push(vertexCopy);
  17073. } // colors
  17074. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  17075. colors1.push(colors2[_i6].clone());
  17076. } // faces
  17077. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  17078. var face = faces2[_i7];
  17079. var normal = void 0,
  17080. color = void 0;
  17081. var faceVertexNormals = face.vertexNormals,
  17082. faceVertexColors = face.vertexColors;
  17083. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  17084. faceCopy.normal.copy(face.normal);
  17085. if (normalMatrix !== undefined) {
  17086. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  17087. }
  17088. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  17089. normal = faceVertexNormals[j].clone();
  17090. if (normalMatrix !== undefined) {
  17091. normal.applyMatrix3(normalMatrix).normalize();
  17092. }
  17093. faceCopy.vertexNormals.push(normal);
  17094. }
  17095. faceCopy.color.copy(face.color);
  17096. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  17097. color = faceVertexColors[_j];
  17098. faceCopy.vertexColors.push(color.clone());
  17099. }
  17100. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  17101. faces1.push(faceCopy);
  17102. } // uvs
  17103. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  17104. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  17105. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  17106. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  17107. var uvs2 = faceVertexUvs2[_j2],
  17108. uvsCopy = [];
  17109. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  17110. uvsCopy.push(uvs2[k].clone());
  17111. }
  17112. this.faceVertexUvs[_i8].push(uvsCopy);
  17113. }
  17114. }
  17115. },
  17116. mergeMesh: function mergeMesh(mesh) {
  17117. if (!(mesh && mesh.isMesh)) {
  17118. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  17119. return;
  17120. }
  17121. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  17122. this.merge(mesh.geometry, mesh.matrix);
  17123. },
  17124. /*
  17125. * Checks for duplicate vertices with hashmap.
  17126. * Duplicated vertices are removed
  17127. * and faces' vertices are updated.
  17128. */
  17129. mergeVertices: function mergeVertices(precisionPoints) {
  17130. if (precisionPoints === void 0) {
  17131. precisionPoints = 4;
  17132. }
  17133. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  17134. var unique = [],
  17135. changes = [];
  17136. var precision = Math.pow(10, precisionPoints);
  17137. for (var i = 0, il = this.vertices.length; i < il; i++) {
  17138. var v = this.vertices[i];
  17139. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  17140. if (verticesMap[key] === undefined) {
  17141. verticesMap[key] = i;
  17142. unique.push(this.vertices[i]);
  17143. changes[i] = unique.length - 1;
  17144. } else {
  17145. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  17146. changes[i] = changes[verticesMap[key]];
  17147. }
  17148. } // if faces are completely degenerate after merging vertices, we
  17149. // have to remove them from the geometry.
  17150. var faceIndicesToRemove = [];
  17151. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  17152. var face = this.faces[_i9];
  17153. face.a = changes[face.a];
  17154. face.b = changes[face.b];
  17155. face.c = changes[face.c];
  17156. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  17157. // we have to remove the face as nothing can be saved
  17158. for (var n = 0; n < 3; n++) {
  17159. if (indices[n] === indices[(n + 1) % 3]) {
  17160. faceIndicesToRemove.push(_i9);
  17161. break;
  17162. }
  17163. }
  17164. }
  17165. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  17166. var idx = faceIndicesToRemove[_i10];
  17167. this.faces.splice(idx, 1);
  17168. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  17169. this.faceVertexUvs[j].splice(idx, 1);
  17170. }
  17171. } // Use unique set of vertices
  17172. var diff = this.vertices.length - unique.length;
  17173. this.vertices = unique;
  17174. return diff;
  17175. },
  17176. setFromPoints: function setFromPoints(points) {
  17177. this.vertices = [];
  17178. for (var i = 0, l = points.length; i < l; i++) {
  17179. var point = points[i];
  17180. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  17181. }
  17182. return this;
  17183. },
  17184. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  17185. var faces = this.faces;
  17186. var length = faces.length; // tag faces
  17187. for (var i = 0; i < length; i++) {
  17188. faces[i]._id = i;
  17189. } // sort faces
  17190. function materialIndexSort(a, b) {
  17191. return a.materialIndex - b.materialIndex;
  17192. }
  17193. faces.sort(materialIndexSort); // sort uvs
  17194. var uvs1 = this.faceVertexUvs[0];
  17195. var uvs2 = this.faceVertexUvs[1];
  17196. var newUvs1, newUvs2;
  17197. if (uvs1 && uvs1.length === length) newUvs1 = [];
  17198. if (uvs2 && uvs2.length === length) newUvs2 = [];
  17199. for (var _i11 = 0; _i11 < length; _i11++) {
  17200. var id = faces[_i11]._id;
  17201. if (newUvs1) newUvs1.push(uvs1[id]);
  17202. if (newUvs2) newUvs2.push(uvs2[id]);
  17203. }
  17204. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  17205. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  17206. },
  17207. toJSON: function toJSON() {
  17208. var data = {
  17209. metadata: {
  17210. version: 4.5,
  17211. type: 'Geometry',
  17212. generator: 'Geometry.toJSON'
  17213. }
  17214. }; // standard Geometry serialization
  17215. data.uuid = this.uuid;
  17216. data.type = this.type;
  17217. if (this.name !== '') data.name = this.name;
  17218. if (this.parameters !== undefined) {
  17219. var parameters = this.parameters;
  17220. for (var key in parameters) {
  17221. if (parameters[key] !== undefined) data[key] = parameters[key];
  17222. }
  17223. return data;
  17224. }
  17225. var vertices = [];
  17226. for (var i = 0; i < this.vertices.length; i++) {
  17227. var vertex = this.vertices[i];
  17228. vertices.push(vertex.x, vertex.y, vertex.z);
  17229. }
  17230. var faces = [];
  17231. var normals = [];
  17232. var normalsHash = {};
  17233. var colors = [];
  17234. var colorsHash = {};
  17235. var uvs = [];
  17236. var uvsHash = {};
  17237. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  17238. var face = this.faces[_i12];
  17239. var hasMaterial = true;
  17240. var hasFaceUv = false; // deprecated
  17241. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  17242. var hasFaceNormal = face.normal.length() > 0;
  17243. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  17244. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  17245. var hasFaceVertexColor = face.vertexColors.length > 0;
  17246. var faceType = 0;
  17247. faceType = setBit(faceType, 0, 0); // isQuad
  17248. faceType = setBit(faceType, 1, hasMaterial);
  17249. faceType = setBit(faceType, 2, hasFaceUv);
  17250. faceType = setBit(faceType, 3, hasFaceVertexUv);
  17251. faceType = setBit(faceType, 4, hasFaceNormal);
  17252. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  17253. faceType = setBit(faceType, 6, hasFaceColor);
  17254. faceType = setBit(faceType, 7, hasFaceVertexColor);
  17255. faces.push(faceType);
  17256. faces.push(face.a, face.b, face.c);
  17257. faces.push(face.materialIndex);
  17258. if (hasFaceVertexUv) {
  17259. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  17260. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  17261. }
  17262. if (hasFaceNormal) {
  17263. faces.push(getNormalIndex(face.normal));
  17264. }
  17265. if (hasFaceVertexNormal) {
  17266. var vertexNormals = face.vertexNormals;
  17267. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  17268. }
  17269. if (hasFaceColor) {
  17270. faces.push(getColorIndex(face.color));
  17271. }
  17272. if (hasFaceVertexColor) {
  17273. var vertexColors = face.vertexColors;
  17274. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  17275. }
  17276. }
  17277. function setBit(value, position, enabled) {
  17278. return enabled ? value | 1 << position : value & ~(1 << position);
  17279. }
  17280. function getNormalIndex(normal) {
  17281. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  17282. if (normalsHash[hash] !== undefined) {
  17283. return normalsHash[hash];
  17284. }
  17285. normalsHash[hash] = normals.length / 3;
  17286. normals.push(normal.x, normal.y, normal.z);
  17287. return normalsHash[hash];
  17288. }
  17289. function getColorIndex(color) {
  17290. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  17291. if (colorsHash[hash] !== undefined) {
  17292. return colorsHash[hash];
  17293. }
  17294. colorsHash[hash] = colors.length;
  17295. colors.push(color.getHex());
  17296. return colorsHash[hash];
  17297. }
  17298. function getUvIndex(uv) {
  17299. var hash = uv.x.toString() + uv.y.toString();
  17300. if (uvsHash[hash] !== undefined) {
  17301. return uvsHash[hash];
  17302. }
  17303. uvsHash[hash] = uvs.length / 2;
  17304. uvs.push(uv.x, uv.y);
  17305. return uvsHash[hash];
  17306. }
  17307. data.data = {};
  17308. data.data.vertices = vertices;
  17309. data.data.normals = normals;
  17310. if (colors.length > 0) data.data.colors = colors;
  17311. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  17312. data.data.faces = faces;
  17313. return data;
  17314. },
  17315. clone: function clone() {
  17316. /*
  17317. // Handle primitives
  17318. const parameters = this.parameters;
  17319. if ( parameters !== undefined ) {
  17320. const values = [];
  17321. for ( const key in parameters ) {
  17322. values.push( parameters[ key ] );
  17323. }
  17324. const geometry = Object.create( this.constructor.prototype );
  17325. this.constructor.apply( geometry, values );
  17326. return geometry;
  17327. }
  17328. return new this.constructor().copy( this );
  17329. */
  17330. return new Geometry().copy(this);
  17331. },
  17332. copy: function copy(source) {
  17333. // reset
  17334. this.vertices = [];
  17335. this.colors = [];
  17336. this.faces = [];
  17337. this.faceVertexUvs = [[]];
  17338. this.morphTargets = [];
  17339. this.morphNormals = [];
  17340. this.skinWeights = [];
  17341. this.skinIndices = [];
  17342. this.lineDistances = [];
  17343. this.boundingBox = null;
  17344. this.boundingSphere = null; // name
  17345. this.name = source.name; // vertices
  17346. var vertices = source.vertices;
  17347. for (var i = 0, il = vertices.length; i < il; i++) {
  17348. this.vertices.push(vertices[i].clone());
  17349. } // colors
  17350. var colors = source.colors;
  17351. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  17352. this.colors.push(colors[_i13].clone());
  17353. } // faces
  17354. var faces = source.faces;
  17355. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  17356. this.faces.push(faces[_i14].clone());
  17357. } // face vertex uvs
  17358. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  17359. var faceVertexUvs = source.faceVertexUvs[_i15];
  17360. if (this.faceVertexUvs[_i15] === undefined) {
  17361. this.faceVertexUvs[_i15] = [];
  17362. }
  17363. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  17364. var uvs = faceVertexUvs[j],
  17365. uvsCopy = [];
  17366. for (var k = 0, kl = uvs.length; k < kl; k++) {
  17367. var uv = uvs[k];
  17368. uvsCopy.push(uv.clone());
  17369. }
  17370. this.faceVertexUvs[_i15].push(uvsCopy);
  17371. }
  17372. } // morph targets
  17373. var morphTargets = source.morphTargets;
  17374. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  17375. var morphTarget = {};
  17376. morphTarget.name = morphTargets[_i16].name; // vertices
  17377. if (morphTargets[_i16].vertices !== undefined) {
  17378. morphTarget.vertices = [];
  17379. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  17380. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  17381. }
  17382. } // normals
  17383. if (morphTargets[_i16].normals !== undefined) {
  17384. morphTarget.normals = [];
  17385. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  17386. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  17387. }
  17388. }
  17389. this.morphTargets.push(morphTarget);
  17390. } // morph normals
  17391. var morphNormals = source.morphNormals;
  17392. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  17393. var morphNormal = {}; // vertex normals
  17394. if (morphNormals[_i17].vertexNormals !== undefined) {
  17395. morphNormal.vertexNormals = [];
  17396. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17397. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17398. var destVertexNormal = {};
  17399. destVertexNormal.a = srcVertexNormal.a.clone();
  17400. destVertexNormal.b = srcVertexNormal.b.clone();
  17401. destVertexNormal.c = srcVertexNormal.c.clone();
  17402. morphNormal.vertexNormals.push(destVertexNormal);
  17403. }
  17404. } // face normals
  17405. if (morphNormals[_i17].faceNormals !== undefined) {
  17406. morphNormal.faceNormals = [];
  17407. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17408. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17409. }
  17410. }
  17411. this.morphNormals.push(morphNormal);
  17412. } // skin weights
  17413. var skinWeights = source.skinWeights;
  17414. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17415. this.skinWeights.push(skinWeights[_i18].clone());
  17416. } // skin indices
  17417. var skinIndices = source.skinIndices;
  17418. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17419. this.skinIndices.push(skinIndices[_i19].clone());
  17420. } // line distances
  17421. var lineDistances = source.lineDistances;
  17422. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17423. this.lineDistances.push(lineDistances[_i20]);
  17424. } // bounding box
  17425. var boundingBox = source.boundingBox;
  17426. if (boundingBox !== null) {
  17427. this.boundingBox = boundingBox.clone();
  17428. } // bounding sphere
  17429. var boundingSphere = source.boundingSphere;
  17430. if (boundingSphere !== null) {
  17431. this.boundingSphere = boundingSphere.clone();
  17432. } // update flags
  17433. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17434. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17435. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17436. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17437. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17438. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17439. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17440. return this;
  17441. },
  17442. dispose: function dispose() {
  17443. this.dispatchEvent({
  17444. type: 'dispose'
  17445. });
  17446. }
  17447. });
  17448. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17449. _inheritsLoose(BoxGeometry, _Geometry);
  17450. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17451. var _this;
  17452. _this = _Geometry.call(this) || this;
  17453. _this.type = 'BoxGeometry';
  17454. _this.parameters = {
  17455. width: width,
  17456. height: height,
  17457. depth: depth,
  17458. widthSegments: widthSegments,
  17459. heightSegments: heightSegments,
  17460. depthSegments: depthSegments
  17461. };
  17462. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17463. _this.mergeVertices();
  17464. return _this;
  17465. }
  17466. return BoxGeometry;
  17467. }(Geometry);
  17468. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17469. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17470. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17471. var _this;
  17472. if (radius === void 0) {
  17473. radius = 1;
  17474. }
  17475. if (segments === void 0) {
  17476. segments = 8;
  17477. }
  17478. if (thetaStart === void 0) {
  17479. thetaStart = 0;
  17480. }
  17481. if (thetaLength === void 0) {
  17482. thetaLength = Math.PI * 2;
  17483. }
  17484. _this = _BufferGeometry.call(this) || this;
  17485. _this.type = 'CircleBufferGeometry';
  17486. _this.parameters = {
  17487. radius: radius,
  17488. segments: segments,
  17489. thetaStart: thetaStart,
  17490. thetaLength: thetaLength
  17491. };
  17492. segments = Math.max(3, segments); // buffers
  17493. var indices = [];
  17494. var vertices = [];
  17495. var normals = [];
  17496. var uvs = []; // helper variables
  17497. var vertex = new Vector3();
  17498. var uv = new Vector2(); // center point
  17499. vertices.push(0, 0, 0);
  17500. normals.push(0, 0, 1);
  17501. uvs.push(0.5, 0.5);
  17502. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17503. var segment = thetaStart + s / segments * thetaLength; // vertex
  17504. vertex.x = radius * Math.cos(segment);
  17505. vertex.y = radius * Math.sin(segment);
  17506. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17507. normals.push(0, 0, 1); // uvs
  17508. uv.x = (vertices[i] / radius + 1) / 2;
  17509. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17510. uvs.push(uv.x, uv.y);
  17511. } // indices
  17512. for (var _i = 1; _i <= segments; _i++) {
  17513. indices.push(_i, _i + 1, 0);
  17514. } // build geometry
  17515. _this.setIndex(indices);
  17516. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17517. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17518. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17519. return _this;
  17520. }
  17521. return CircleBufferGeometry;
  17522. }(BufferGeometry);
  17523. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17524. _inheritsLoose(CircleGeometry, _Geometry);
  17525. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17526. var _this;
  17527. _this = _Geometry.call(this) || this;
  17528. _this.type = 'CircleGeometry';
  17529. _this.parameters = {
  17530. radius: radius,
  17531. segments: segments,
  17532. thetaStart: thetaStart,
  17533. thetaLength: thetaLength
  17534. };
  17535. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17536. _this.mergeVertices();
  17537. return _this;
  17538. }
  17539. return CircleGeometry;
  17540. }(Geometry);
  17541. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17542. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17543. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17544. var _this;
  17545. if (radiusTop === void 0) {
  17546. radiusTop = 1;
  17547. }
  17548. if (radiusBottom === void 0) {
  17549. radiusBottom = 1;
  17550. }
  17551. if (height === void 0) {
  17552. height = 1;
  17553. }
  17554. if (radialSegments === void 0) {
  17555. radialSegments = 8;
  17556. }
  17557. if (heightSegments === void 0) {
  17558. heightSegments = 1;
  17559. }
  17560. if (openEnded === void 0) {
  17561. openEnded = false;
  17562. }
  17563. if (thetaStart === void 0) {
  17564. thetaStart = 0;
  17565. }
  17566. if (thetaLength === void 0) {
  17567. thetaLength = Math.PI * 2;
  17568. }
  17569. _this = _BufferGeometry.call(this) || this;
  17570. _this.type = 'CylinderBufferGeometry';
  17571. _this.parameters = {
  17572. radiusTop: radiusTop,
  17573. radiusBottom: radiusBottom,
  17574. height: height,
  17575. radialSegments: radialSegments,
  17576. heightSegments: heightSegments,
  17577. openEnded: openEnded,
  17578. thetaStart: thetaStart,
  17579. thetaLength: thetaLength
  17580. };
  17581. var scope = _assertThisInitialized(_this);
  17582. radialSegments = Math.floor(radialSegments);
  17583. heightSegments = Math.floor(heightSegments); // buffers
  17584. var indices = [];
  17585. var vertices = [];
  17586. var normals = [];
  17587. var uvs = []; // helper variables
  17588. var index = 0;
  17589. var indexArray = [];
  17590. var halfHeight = height / 2;
  17591. var groupStart = 0; // generate geometry
  17592. generateTorso();
  17593. if (openEnded === false) {
  17594. if (radiusTop > 0) generateCap(true);
  17595. if (radiusBottom > 0) generateCap(false);
  17596. } // build geometry
  17597. _this.setIndex(indices);
  17598. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17599. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17600. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17601. function generateTorso() {
  17602. var normal = new Vector3();
  17603. var vertex = new Vector3();
  17604. var groupCount = 0; // this will be used to calculate the normal
  17605. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17606. for (var y = 0; y <= heightSegments; y++) {
  17607. var indexRow = [];
  17608. var v = y / heightSegments; // calculate the radius of the current row
  17609. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17610. for (var x = 0; x <= radialSegments; x++) {
  17611. var u = x / radialSegments;
  17612. var theta = u * thetaLength + thetaStart;
  17613. var sinTheta = Math.sin(theta);
  17614. var cosTheta = Math.cos(theta); // vertex
  17615. vertex.x = radius * sinTheta;
  17616. vertex.y = -v * height + halfHeight;
  17617. vertex.z = radius * cosTheta;
  17618. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17619. normal.set(sinTheta, slope, cosTheta).normalize();
  17620. normals.push(normal.x, normal.y, normal.z); // uv
  17621. uvs.push(u, 1 - v); // save index of vertex in respective row
  17622. indexRow.push(index++);
  17623. } // now save vertices of the row in our index array
  17624. indexArray.push(indexRow);
  17625. } // generate indices
  17626. for (var _x = 0; _x < radialSegments; _x++) {
  17627. for (var _y = 0; _y < heightSegments; _y++) {
  17628. // we use the index array to access the correct indices
  17629. var a = indexArray[_y][_x];
  17630. var b = indexArray[_y + 1][_x];
  17631. var c = indexArray[_y + 1][_x + 1];
  17632. var d = indexArray[_y][_x + 1]; // faces
  17633. indices.push(a, b, d);
  17634. indices.push(b, c, d); // update group counter
  17635. groupCount += 6;
  17636. }
  17637. } // add a group to the geometry. this will ensure multi material support
  17638. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17639. groupStart += groupCount;
  17640. }
  17641. function generateCap(top) {
  17642. // save the index of the first center vertex
  17643. var centerIndexStart = index;
  17644. var uv = new Vector2();
  17645. var vertex = new Vector3();
  17646. var groupCount = 0;
  17647. var radius = top === true ? radiusTop : radiusBottom;
  17648. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17649. // because the geometry needs one set of uvs per face,
  17650. // we must generate a center vertex per face/segment
  17651. for (var x = 1; x <= radialSegments; x++) {
  17652. // vertex
  17653. vertices.push(0, halfHeight * sign, 0); // normal
  17654. normals.push(0, sign, 0); // uv
  17655. uvs.push(0.5, 0.5); // increase index
  17656. index++;
  17657. } // save the index of the last center vertex
  17658. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17659. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17660. var u = _x2 / radialSegments;
  17661. var theta = u * thetaLength + thetaStart;
  17662. var cosTheta = Math.cos(theta);
  17663. var sinTheta = Math.sin(theta); // vertex
  17664. vertex.x = radius * sinTheta;
  17665. vertex.y = halfHeight * sign;
  17666. vertex.z = radius * cosTheta;
  17667. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17668. normals.push(0, sign, 0); // uv
  17669. uv.x = cosTheta * 0.5 + 0.5;
  17670. uv.y = sinTheta * 0.5 * sign + 0.5;
  17671. uvs.push(uv.x, uv.y); // increase index
  17672. index++;
  17673. } // generate indices
  17674. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17675. var c = centerIndexStart + _x3;
  17676. var i = centerIndexEnd + _x3;
  17677. if (top === true) {
  17678. // face top
  17679. indices.push(i, i + 1, c);
  17680. } else {
  17681. // face bottom
  17682. indices.push(i + 1, i, c);
  17683. }
  17684. groupCount += 3;
  17685. } // add a group to the geometry. this will ensure multi material support
  17686. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17687. groupStart += groupCount;
  17688. }
  17689. return _this;
  17690. }
  17691. return CylinderBufferGeometry;
  17692. }(BufferGeometry);
  17693. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17694. _inheritsLoose(CylinderGeometry, _Geometry);
  17695. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17696. var _this;
  17697. _this = _Geometry.call(this) || this;
  17698. _this.type = 'CylinderGeometry';
  17699. _this.parameters = {
  17700. radiusTop: radiusTop,
  17701. radiusBottom: radiusBottom,
  17702. height: height,
  17703. radialSegments: radialSegments,
  17704. heightSegments: heightSegments,
  17705. openEnded: openEnded,
  17706. thetaStart: thetaStart,
  17707. thetaLength: thetaLength
  17708. };
  17709. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17710. _this.mergeVertices();
  17711. return _this;
  17712. }
  17713. return CylinderGeometry;
  17714. }(Geometry);
  17715. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17716. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17717. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17718. var _this;
  17719. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17720. _this.type = 'ConeGeometry';
  17721. _this.parameters = {
  17722. radius: radius,
  17723. height: height,
  17724. radialSegments: radialSegments,
  17725. heightSegments: heightSegments,
  17726. openEnded: openEnded,
  17727. thetaStart: thetaStart,
  17728. thetaLength: thetaLength
  17729. };
  17730. return _this;
  17731. }
  17732. return ConeGeometry;
  17733. }(CylinderGeometry);
  17734. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17735. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17736. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17737. var _this;
  17738. if (radius === void 0) {
  17739. radius = 1;
  17740. }
  17741. if (height === void 0) {
  17742. height = 1;
  17743. }
  17744. if (radialSegments === void 0) {
  17745. radialSegments = 8;
  17746. }
  17747. if (heightSegments === void 0) {
  17748. heightSegments = 1;
  17749. }
  17750. if (openEnded === void 0) {
  17751. openEnded = false;
  17752. }
  17753. if (thetaStart === void 0) {
  17754. thetaStart = 0;
  17755. }
  17756. if (thetaLength === void 0) {
  17757. thetaLength = Math.PI * 2;
  17758. }
  17759. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17760. _this.type = 'ConeBufferGeometry';
  17761. _this.parameters = {
  17762. radius: radius,
  17763. height: height,
  17764. radialSegments: radialSegments,
  17765. heightSegments: heightSegments,
  17766. openEnded: openEnded,
  17767. thetaStart: thetaStart,
  17768. thetaLength: thetaLength
  17769. };
  17770. return _this;
  17771. }
  17772. return ConeBufferGeometry;
  17773. }(CylinderBufferGeometry);
  17774. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17775. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17776. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17777. var _this;
  17778. if (radius === void 0) {
  17779. radius = 1;
  17780. }
  17781. if (detail === void 0) {
  17782. detail = 0;
  17783. }
  17784. _this = _BufferGeometry.call(this) || this;
  17785. _this.type = 'PolyhedronBufferGeometry';
  17786. _this.parameters = {
  17787. vertices: vertices,
  17788. indices: indices,
  17789. radius: radius,
  17790. detail: detail
  17791. }; // default buffer data
  17792. var vertexBuffer = [];
  17793. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17794. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17795. applyRadius(radius); // finally, create the uv data
  17796. generateUVs(); // build non-indexed geometry
  17797. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17798. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17799. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17800. if (detail === 0) {
  17801. _this.computeVertexNormals(); // flat normals
  17802. } else {
  17803. _this.normalizeNormals(); // smooth normals
  17804. } // helper functions
  17805. function subdivide(detail) {
  17806. var a = new Vector3();
  17807. var b = new Vector3();
  17808. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17809. for (var i = 0; i < indices.length; i += 3) {
  17810. // get the vertices of the face
  17811. getVertexByIndex(indices[i + 0], a);
  17812. getVertexByIndex(indices[i + 1], b);
  17813. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17814. subdivideFace(a, b, c, detail);
  17815. }
  17816. }
  17817. function subdivideFace(a, b, c, detail) {
  17818. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17819. var v = []; // construct all of the vertices for this subdivision
  17820. for (var i = 0; i <= cols; i++) {
  17821. v[i] = [];
  17822. var aj = a.clone().lerp(c, i / cols);
  17823. var bj = b.clone().lerp(c, i / cols);
  17824. var rows = cols - i;
  17825. for (var j = 0; j <= rows; j++) {
  17826. if (j === 0 && i === cols) {
  17827. v[i][j] = aj;
  17828. } else {
  17829. v[i][j] = aj.clone().lerp(bj, j / rows);
  17830. }
  17831. }
  17832. } // construct all of the faces
  17833. for (var _i = 0; _i < cols; _i++) {
  17834. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17835. var k = Math.floor(_j / 2);
  17836. if (_j % 2 === 0) {
  17837. pushVertex(v[_i][k + 1]);
  17838. pushVertex(v[_i + 1][k]);
  17839. pushVertex(v[_i][k]);
  17840. } else {
  17841. pushVertex(v[_i][k + 1]);
  17842. pushVertex(v[_i + 1][k + 1]);
  17843. pushVertex(v[_i + 1][k]);
  17844. }
  17845. }
  17846. }
  17847. }
  17848. function applyRadius(radius) {
  17849. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17850. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17851. vertex.x = vertexBuffer[i + 0];
  17852. vertex.y = vertexBuffer[i + 1];
  17853. vertex.z = vertexBuffer[i + 2];
  17854. vertex.normalize().multiplyScalar(radius);
  17855. vertexBuffer[i + 0] = vertex.x;
  17856. vertexBuffer[i + 1] = vertex.y;
  17857. vertexBuffer[i + 2] = vertex.z;
  17858. }
  17859. }
  17860. function generateUVs() {
  17861. var vertex = new Vector3();
  17862. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17863. vertex.x = vertexBuffer[i + 0];
  17864. vertex.y = vertexBuffer[i + 1];
  17865. vertex.z = vertexBuffer[i + 2];
  17866. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17867. var v = inclination(vertex) / Math.PI + 0.5;
  17868. uvBuffer.push(u, 1 - v);
  17869. }
  17870. correctUVs();
  17871. correctSeam();
  17872. }
  17873. function correctSeam() {
  17874. // handle case when face straddles the seam, see #3269
  17875. for (var i = 0; i < uvBuffer.length; i += 6) {
  17876. // uv data of a single face
  17877. var x0 = uvBuffer[i + 0];
  17878. var x1 = uvBuffer[i + 2];
  17879. var x2 = uvBuffer[i + 4];
  17880. var max = Math.max(x0, x1, x2);
  17881. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17882. if (max > 0.9 && min < 0.1) {
  17883. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17884. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17885. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17886. }
  17887. }
  17888. }
  17889. function pushVertex(vertex) {
  17890. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17891. }
  17892. function getVertexByIndex(index, vertex) {
  17893. var stride = index * 3;
  17894. vertex.x = vertices[stride + 0];
  17895. vertex.y = vertices[stride + 1];
  17896. vertex.z = vertices[stride + 2];
  17897. }
  17898. function correctUVs() {
  17899. var a = new Vector3();
  17900. var b = new Vector3();
  17901. var c = new Vector3();
  17902. var centroid = new Vector3();
  17903. var uvA = new Vector2();
  17904. var uvB = new Vector2();
  17905. var uvC = new Vector2();
  17906. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17907. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17908. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17909. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17910. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17911. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17912. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17913. centroid.copy(a).add(b).add(c).divideScalar(3);
  17914. var azi = azimuth(centroid);
  17915. correctUV(uvA, j + 0, a, azi);
  17916. correctUV(uvB, j + 2, b, azi);
  17917. correctUV(uvC, j + 4, c, azi);
  17918. }
  17919. }
  17920. function correctUV(uv, stride, vector, azimuth) {
  17921. if (azimuth < 0 && uv.x === 1) {
  17922. uvBuffer[stride] = uv.x - 1;
  17923. }
  17924. if (vector.x === 0 && vector.z === 0) {
  17925. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17926. }
  17927. } // Angle around the Y axis, counter-clockwise when looking from above.
  17928. function azimuth(vector) {
  17929. return Math.atan2(vector.z, -vector.x);
  17930. } // Angle above the XZ plane.
  17931. function inclination(vector) {
  17932. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17933. }
  17934. return _this;
  17935. }
  17936. return PolyhedronBufferGeometry;
  17937. }(BufferGeometry);
  17938. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17939. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17940. function DodecahedronBufferGeometry(radius, detail) {
  17941. var _this;
  17942. if (radius === void 0) {
  17943. radius = 1;
  17944. }
  17945. if (detail === void 0) {
  17946. detail = 0;
  17947. }
  17948. var t = (1 + Math.sqrt(5)) / 2;
  17949. var r = 1 / t;
  17950. var vertices = [// (±1, ±1, ±1)
  17951. -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/φ, ±φ)
  17952. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17953. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17954. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17955. 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];
  17956. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17957. _this.type = 'DodecahedronBufferGeometry';
  17958. _this.parameters = {
  17959. radius: radius,
  17960. detail: detail
  17961. };
  17962. return _this;
  17963. }
  17964. return DodecahedronBufferGeometry;
  17965. }(PolyhedronBufferGeometry);
  17966. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17967. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17968. function DodecahedronGeometry(radius, detail) {
  17969. var _this;
  17970. _this = _Geometry.call(this) || this;
  17971. _this.type = 'DodecahedronGeometry';
  17972. _this.parameters = {
  17973. radius: radius,
  17974. detail: detail
  17975. };
  17976. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17977. _this.mergeVertices();
  17978. return _this;
  17979. }
  17980. return DodecahedronGeometry;
  17981. }(Geometry);
  17982. var _v0$2 = new Vector3();
  17983. var _v1$5 = new Vector3();
  17984. var _normal$1 = new Vector3();
  17985. var _triangle = new Triangle();
  17986. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17987. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17988. function EdgesGeometry(geometry, thresholdAngle) {
  17989. var _this;
  17990. _this = _BufferGeometry.call(this) || this;
  17991. _this.type = 'EdgesGeometry';
  17992. _this.parameters = {
  17993. thresholdAngle: thresholdAngle
  17994. };
  17995. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17996. if (geometry.isGeometry) {
  17997. geometry = new BufferGeometry().fromGeometry(geometry);
  17998. }
  17999. var precisionPoints = 4;
  18000. var precision = Math.pow(10, precisionPoints);
  18001. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  18002. var indexAttr = geometry.getIndex();
  18003. var positionAttr = geometry.getAttribute('position');
  18004. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  18005. var indexArr = [0, 0, 0];
  18006. var vertKeys = ['a', 'b', 'c'];
  18007. var hashes = new Array(3);
  18008. var edgeData = {};
  18009. var vertices = [];
  18010. for (var i = 0; i < indexCount; i += 3) {
  18011. if (indexAttr) {
  18012. indexArr[0] = indexAttr.getX(i);
  18013. indexArr[1] = indexAttr.getX(i + 1);
  18014. indexArr[2] = indexAttr.getX(i + 2);
  18015. } else {
  18016. indexArr[0] = i;
  18017. indexArr[1] = i + 1;
  18018. indexArr[2] = i + 2;
  18019. }
  18020. var a = _triangle.a,
  18021. b = _triangle.b,
  18022. c = _triangle.c;
  18023. a.fromBufferAttribute(positionAttr, indexArr[0]);
  18024. b.fromBufferAttribute(positionAttr, indexArr[1]);
  18025. c.fromBufferAttribute(positionAttr, indexArr[2]);
  18026. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  18027. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  18028. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  18029. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  18030. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  18031. continue;
  18032. } // iterate over every edge
  18033. for (var j = 0; j < 3; j++) {
  18034. // get the first and next vertex making up the edge
  18035. var jNext = (j + 1) % 3;
  18036. var vecHash0 = hashes[j];
  18037. var vecHash1 = hashes[jNext];
  18038. var v0 = _triangle[vertKeys[j]];
  18039. var v1 = _triangle[vertKeys[jNext]];
  18040. var hash = vecHash0 + "_" + vecHash1;
  18041. var reverseHash = vecHash1 + "_" + vecHash0;
  18042. if (reverseHash in edgeData && edgeData[reverseHash]) {
  18043. // if we found a sibling edge add it into the vertex array if
  18044. // it meets the angle threshold and delete the edge from the map.
  18045. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  18046. vertices.push(v0.x, v0.y, v0.z);
  18047. vertices.push(v1.x, v1.y, v1.z);
  18048. }
  18049. edgeData[reverseHash] = null;
  18050. } else if (!(hash in edgeData)) {
  18051. // if we've already got an edge here then skip adding a new one
  18052. edgeData[hash] = {
  18053. index0: indexArr[j],
  18054. index1: indexArr[jNext],
  18055. normal: _normal$1.clone()
  18056. };
  18057. }
  18058. }
  18059. } // iterate over all remaining, unmatched edges and add them to the vertex array
  18060. for (var key in edgeData) {
  18061. if (edgeData[key]) {
  18062. var _edgeData$key = edgeData[key],
  18063. index0 = _edgeData$key.index0,
  18064. index1 = _edgeData$key.index1;
  18065. _v0$2.fromBufferAttribute(positionAttr, index0);
  18066. _v1$5.fromBufferAttribute(positionAttr, index1);
  18067. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  18068. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  18069. }
  18070. }
  18071. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18072. return _this;
  18073. }
  18074. return EdgesGeometry;
  18075. }(BufferGeometry);
  18076. /**
  18077. * Port from https://github.com/mapbox/earcut (v2.2.2)
  18078. */
  18079. var Earcut = {
  18080. triangulate: function triangulate(data, holeIndices, dim) {
  18081. dim = dim || 2;
  18082. var hasHoles = holeIndices && holeIndices.length;
  18083. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  18084. var outerNode = linkedList(data, 0, outerLen, dim, true);
  18085. var triangles = [];
  18086. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  18087. var minX, minY, maxX, maxY, x, y, invSize;
  18088. 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
  18089. if (data.length > 80 * dim) {
  18090. minX = maxX = data[0];
  18091. minY = maxY = data[1];
  18092. for (var i = dim; i < outerLen; i += dim) {
  18093. x = data[i];
  18094. y = data[i + 1];
  18095. if (x < minX) minX = x;
  18096. if (y < minY) minY = y;
  18097. if (x > maxX) maxX = x;
  18098. if (y > maxY) maxY = y;
  18099. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  18100. invSize = Math.max(maxX - minX, maxY - minY);
  18101. invSize = invSize !== 0 ? 1 / invSize : 0;
  18102. }
  18103. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  18104. return triangles;
  18105. }
  18106. }; // create a circular doubly linked list from polygon points in the specified winding order
  18107. function linkedList(data, start, end, dim, clockwise) {
  18108. var i, last;
  18109. if (clockwise === signedArea(data, start, end, dim) > 0) {
  18110. for (i = start; i < end; i += dim) {
  18111. last = insertNode(i, data[i], data[i + 1], last);
  18112. }
  18113. } else {
  18114. for (i = end - dim; i >= start; i -= dim) {
  18115. last = insertNode(i, data[i], data[i + 1], last);
  18116. }
  18117. }
  18118. if (last && equals(last, last.next)) {
  18119. removeNode(last);
  18120. last = last.next;
  18121. }
  18122. return last;
  18123. } // eliminate colinear or duplicate points
  18124. function filterPoints(start, end) {
  18125. if (!start) return start;
  18126. if (!end) end = start;
  18127. var p = start,
  18128. again;
  18129. do {
  18130. again = false;
  18131. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  18132. removeNode(p);
  18133. p = end = p.prev;
  18134. if (p === p.next) break;
  18135. again = true;
  18136. } else {
  18137. p = p.next;
  18138. }
  18139. } while (again || p !== end);
  18140. return end;
  18141. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  18142. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  18143. if (!ear) return; // interlink polygon nodes in z-order
  18144. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  18145. var stop = ear,
  18146. prev,
  18147. next; // iterate through ears, slicing them one by one
  18148. while (ear.prev !== ear.next) {
  18149. prev = ear.prev;
  18150. next = ear.next;
  18151. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  18152. // cut off the triangle
  18153. triangles.push(prev.i / dim);
  18154. triangles.push(ear.i / dim);
  18155. triangles.push(next.i / dim);
  18156. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  18157. ear = next.next;
  18158. stop = next.next;
  18159. continue;
  18160. }
  18161. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  18162. if (ear === stop) {
  18163. // try filtering points and slicing again
  18164. if (!pass) {
  18165. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  18166. } else if (pass === 1) {
  18167. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  18168. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  18169. } else if (pass === 2) {
  18170. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  18171. }
  18172. break;
  18173. }
  18174. }
  18175. } // check whether a polygon node forms a valid ear with adjacent nodes
  18176. function isEar(ear) {
  18177. var a = ear.prev,
  18178. b = ear,
  18179. c = ear.next;
  18180. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18181. // now make sure we don't have other points inside the potential ear
  18182. var p = ear.next.next;
  18183. while (p !== ear.prev) {
  18184. 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;
  18185. p = p.next;
  18186. }
  18187. return true;
  18188. }
  18189. function isEarHashed(ear, minX, minY, invSize) {
  18190. var a = ear.prev,
  18191. b = ear,
  18192. c = ear.next;
  18193. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18194. // triangle bbox; min & max are calculated like this for speed
  18195. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  18196. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  18197. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  18198. 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;
  18199. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  18200. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  18201. var p = ear.prevZ,
  18202. n = ear.nextZ; // look for points inside the triangle in both directions
  18203. while (p && p.z >= minZ && n && n.z <= maxZ) {
  18204. 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;
  18205. p = p.prevZ;
  18206. 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;
  18207. n = n.nextZ;
  18208. } // look for remaining points in decreasing z-order
  18209. while (p && p.z >= minZ) {
  18210. 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;
  18211. p = p.prevZ;
  18212. } // look for remaining points in increasing z-order
  18213. while (n && n.z <= maxZ) {
  18214. 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;
  18215. n = n.nextZ;
  18216. }
  18217. return true;
  18218. } // go through all polygon nodes and cure small local self-intersections
  18219. function cureLocalIntersections(start, triangles, dim) {
  18220. var p = start;
  18221. do {
  18222. var a = p.prev,
  18223. b = p.next.next;
  18224. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  18225. triangles.push(a.i / dim);
  18226. triangles.push(p.i / dim);
  18227. triangles.push(b.i / dim); // remove two nodes involved
  18228. removeNode(p);
  18229. removeNode(p.next);
  18230. p = start = b;
  18231. }
  18232. p = p.next;
  18233. } while (p !== start);
  18234. return filterPoints(p);
  18235. } // try splitting polygon into two and triangulate them independently
  18236. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  18237. // look for a valid diagonal that divides the polygon into two
  18238. var a = start;
  18239. do {
  18240. var b = a.next.next;
  18241. while (b !== a.prev) {
  18242. if (a.i !== b.i && isValidDiagonal(a, b)) {
  18243. // split the polygon in two by the diagonal
  18244. var c = splitPolygon(a, b); // filter colinear points around the cuts
  18245. a = filterPoints(a, a.next);
  18246. c = filterPoints(c, c.next); // run earcut on each half
  18247. earcutLinked(a, triangles, dim, minX, minY, invSize);
  18248. earcutLinked(c, triangles, dim, minX, minY, invSize);
  18249. return;
  18250. }
  18251. b = b.next;
  18252. }
  18253. a = a.next;
  18254. } while (a !== start);
  18255. } // link every hole into the outer loop, producing a single-ring polygon without holes
  18256. function eliminateHoles(data, holeIndices, outerNode, dim) {
  18257. var queue = [];
  18258. var i, len, start, end, list;
  18259. for (i = 0, len = holeIndices.length; i < len; i++) {
  18260. start = holeIndices[i] * dim;
  18261. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  18262. list = linkedList(data, start, end, dim, false);
  18263. if (list === list.next) list.steiner = true;
  18264. queue.push(getLeftmost(list));
  18265. }
  18266. queue.sort(compareX); // process holes from left to right
  18267. for (i = 0; i < queue.length; i++) {
  18268. eliminateHole(queue[i], outerNode);
  18269. outerNode = filterPoints(outerNode, outerNode.next);
  18270. }
  18271. return outerNode;
  18272. }
  18273. function compareX(a, b) {
  18274. return a.x - b.x;
  18275. } // find a bridge between vertices that connects hole with an outer ring and and link it
  18276. function eliminateHole(hole, outerNode) {
  18277. outerNode = findHoleBridge(hole, outerNode);
  18278. if (outerNode) {
  18279. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  18280. filterPoints(outerNode, outerNode.next);
  18281. filterPoints(b, b.next);
  18282. }
  18283. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18284. function findHoleBridge(hole, outerNode) {
  18285. var p = outerNode;
  18286. var hx = hole.x;
  18287. var hy = hole.y;
  18288. var qx = -Infinity,
  18289. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18290. // segment's endpoint with lesser x will be potential connection point
  18291. do {
  18292. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18293. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18294. if (x <= hx && x > qx) {
  18295. qx = x;
  18296. if (x === hx) {
  18297. if (hy === p.y) return p;
  18298. if (hy === p.next.y) return p.next;
  18299. }
  18300. m = p.x < p.next.x ? p : p.next;
  18301. }
  18302. }
  18303. p = p.next;
  18304. } while (p !== outerNode);
  18305. if (!m) return null;
  18306. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18307. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18308. // if there are no points found, we have a valid connection;
  18309. // otherwise choose the point of the minimum angle with the ray as connection point
  18310. var stop = m,
  18311. mx = m.x,
  18312. my = m.y;
  18313. var tanMin = Infinity,
  18314. tan;
  18315. p = m;
  18316. do {
  18317. 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)) {
  18318. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18319. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18320. m = p;
  18321. tanMin = tan;
  18322. }
  18323. }
  18324. p = p.next;
  18325. } while (p !== stop);
  18326. return m;
  18327. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18328. function sectorContainsSector(m, p) {
  18329. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18330. } // interlink polygon nodes in z-order
  18331. function indexCurve(start, minX, minY, invSize) {
  18332. var p = start;
  18333. do {
  18334. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18335. p.prevZ = p.prev;
  18336. p.nextZ = p.next;
  18337. p = p.next;
  18338. } while (p !== start);
  18339. p.prevZ.nextZ = null;
  18340. p.prevZ = null;
  18341. sortLinked(p);
  18342. } // Simon Tatham's linked list merge sort algorithm
  18343. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18344. function sortLinked(list) {
  18345. var i,
  18346. p,
  18347. q,
  18348. e,
  18349. tail,
  18350. numMerges,
  18351. pSize,
  18352. qSize,
  18353. inSize = 1;
  18354. do {
  18355. p = list;
  18356. list = null;
  18357. tail = null;
  18358. numMerges = 0;
  18359. while (p) {
  18360. numMerges++;
  18361. q = p;
  18362. pSize = 0;
  18363. for (i = 0; i < inSize; i++) {
  18364. pSize++;
  18365. q = q.nextZ;
  18366. if (!q) break;
  18367. }
  18368. qSize = inSize;
  18369. while (pSize > 0 || qSize > 0 && q) {
  18370. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18371. e = p;
  18372. p = p.nextZ;
  18373. pSize--;
  18374. } else {
  18375. e = q;
  18376. q = q.nextZ;
  18377. qSize--;
  18378. }
  18379. if (tail) tail.nextZ = e;else list = e;
  18380. e.prevZ = tail;
  18381. tail = e;
  18382. }
  18383. p = q;
  18384. }
  18385. tail.nextZ = null;
  18386. inSize *= 2;
  18387. } while (numMerges > 1);
  18388. return list;
  18389. } // z-order of a point given coords and inverse of the longer side of data bbox
  18390. function zOrder(x, y, minX, minY, invSize) {
  18391. // coords are transformed into non-negative 15-bit integer range
  18392. x = 32767 * (x - minX) * invSize;
  18393. y = 32767 * (y - minY) * invSize;
  18394. x = (x | x << 8) & 0x00FF00FF;
  18395. x = (x | x << 4) & 0x0F0F0F0F;
  18396. x = (x | x << 2) & 0x33333333;
  18397. x = (x | x << 1) & 0x55555555;
  18398. y = (y | y << 8) & 0x00FF00FF;
  18399. y = (y | y << 4) & 0x0F0F0F0F;
  18400. y = (y | y << 2) & 0x33333333;
  18401. y = (y | y << 1) & 0x55555555;
  18402. return x | y << 1;
  18403. } // find the leftmost node of a polygon ring
  18404. function getLeftmost(start) {
  18405. var p = start,
  18406. leftmost = start;
  18407. do {
  18408. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18409. p = p.next;
  18410. } while (p !== start);
  18411. return leftmost;
  18412. } // check if a point lies within a convex triangle
  18413. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18414. 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;
  18415. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18416. function isValidDiagonal(a, b) {
  18417. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18418. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18419. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18420. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18421. } // signed area of a triangle
  18422. function area(p, q, r) {
  18423. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18424. } // check if two points are equal
  18425. function equals(p1, p2) {
  18426. return p1.x === p2.x && p1.y === p2.y;
  18427. } // check if two segments intersect
  18428. function intersects(p1, q1, p2, q2) {
  18429. var o1 = sign(area(p1, q1, p2));
  18430. var o2 = sign(area(p1, q1, q2));
  18431. var o3 = sign(area(p2, q2, p1));
  18432. var o4 = sign(area(p2, q2, q1));
  18433. if (o1 !== o2 && o3 !== o4) return true; // general case
  18434. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18435. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18436. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18437. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18438. return false;
  18439. } // for collinear points p, q, r, check if point q lies on segment pr
  18440. function onSegment(p, q, r) {
  18441. 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);
  18442. }
  18443. function sign(num) {
  18444. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18445. } // check if a polygon diagonal intersects any polygon segments
  18446. function intersectsPolygon(a, b) {
  18447. var p = a;
  18448. do {
  18449. 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;
  18450. p = p.next;
  18451. } while (p !== a);
  18452. return false;
  18453. } // check if a polygon diagonal is locally inside the polygon
  18454. function locallyInside(a, b) {
  18455. 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;
  18456. } // check if the middle point of a polygon diagonal is inside the polygon
  18457. function middleInside(a, b) {
  18458. var p = a,
  18459. inside = false;
  18460. var px = (a.x + b.x) / 2,
  18461. py = (a.y + b.y) / 2;
  18462. do {
  18463. 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;
  18464. p = p.next;
  18465. } while (p !== a);
  18466. return inside;
  18467. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18468. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18469. function splitPolygon(a, b) {
  18470. var a2 = new Node(a.i, a.x, a.y),
  18471. b2 = new Node(b.i, b.x, b.y),
  18472. an = a.next,
  18473. bp = b.prev;
  18474. a.next = b;
  18475. b.prev = a;
  18476. a2.next = an;
  18477. an.prev = a2;
  18478. b2.next = a2;
  18479. a2.prev = b2;
  18480. bp.next = b2;
  18481. b2.prev = bp;
  18482. return b2;
  18483. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18484. function insertNode(i, x, y, last) {
  18485. var p = new Node(i, x, y);
  18486. if (!last) {
  18487. p.prev = p;
  18488. p.next = p;
  18489. } else {
  18490. p.next = last.next;
  18491. p.prev = last;
  18492. last.next.prev = p;
  18493. last.next = p;
  18494. }
  18495. return p;
  18496. }
  18497. function removeNode(p) {
  18498. p.next.prev = p.prev;
  18499. p.prev.next = p.next;
  18500. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18501. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18502. }
  18503. function Node(i, x, y) {
  18504. // vertex index in coordinates array
  18505. this.i = i; // vertex coordinates
  18506. this.x = x;
  18507. this.y = y; // previous and next vertex nodes in a polygon ring
  18508. this.prev = null;
  18509. this.next = null; // z-order curve value
  18510. this.z = null; // previous and next nodes in z-order
  18511. this.prevZ = null;
  18512. this.nextZ = null; // indicates whether this is a steiner point
  18513. this.steiner = false;
  18514. }
  18515. function signedArea(data, start, end, dim) {
  18516. var sum = 0;
  18517. for (var i = start, j = end - dim; i < end; i += dim) {
  18518. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18519. j = i;
  18520. }
  18521. return sum;
  18522. }
  18523. var ShapeUtils = {
  18524. // calculate area of the contour polygon
  18525. area: function area(contour) {
  18526. var n = contour.length;
  18527. var a = 0.0;
  18528. for (var p = n - 1, q = 0; q < n; p = q++) {
  18529. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18530. }
  18531. return a * 0.5;
  18532. },
  18533. isClockWise: function isClockWise(pts) {
  18534. return ShapeUtils.area(pts) < 0;
  18535. },
  18536. triangulateShape: function triangulateShape(contour, holes) {
  18537. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18538. var holeIndices = []; // array of hole indices
  18539. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18540. removeDupEndPts(contour);
  18541. addContour(vertices, contour); //
  18542. var holeIndex = contour.length;
  18543. holes.forEach(removeDupEndPts);
  18544. for (var i = 0; i < holes.length; i++) {
  18545. holeIndices.push(holeIndex);
  18546. holeIndex += holes[i].length;
  18547. addContour(vertices, holes[i]);
  18548. } //
  18549. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18550. for (var _i = 0; _i < triangles.length; _i += 3) {
  18551. faces.push(triangles.slice(_i, _i + 3));
  18552. }
  18553. return faces;
  18554. }
  18555. };
  18556. function removeDupEndPts(points) {
  18557. var l = points.length;
  18558. if (l > 2 && points[l - 1].equals(points[0])) {
  18559. points.pop();
  18560. }
  18561. }
  18562. function addContour(vertices, contour) {
  18563. for (var i = 0; i < contour.length; i++) {
  18564. vertices.push(contour[i].x);
  18565. vertices.push(contour[i].y);
  18566. }
  18567. }
  18568. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18569. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18570. function ExtrudeBufferGeometry(shapes, options) {
  18571. var _this;
  18572. _this = _BufferGeometry.call(this) || this;
  18573. _this.type = 'ExtrudeBufferGeometry';
  18574. _this.parameters = {
  18575. shapes: shapes,
  18576. options: options
  18577. };
  18578. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18579. var scope = _assertThisInitialized(_this);
  18580. var verticesArray = [];
  18581. var uvArray = [];
  18582. for (var i = 0, l = shapes.length; i < l; i++) {
  18583. var shape = shapes[i];
  18584. addShape(shape);
  18585. } // build geometry
  18586. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18587. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18588. _this.computeVertexNormals(); // functions
  18589. function addShape(shape) {
  18590. var placeholder = []; // options
  18591. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18592. var steps = options.steps !== undefined ? options.steps : 1;
  18593. var depth = options.depth !== undefined ? options.depth : 100;
  18594. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18595. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18596. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18597. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18598. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18599. var extrudePath = options.extrudePath;
  18600. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18601. if (options.amount !== undefined) {
  18602. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18603. depth = options.amount;
  18604. } //
  18605. var extrudePts,
  18606. extrudeByPath = false;
  18607. var splineTube, binormal, normal, position2;
  18608. if (extrudePath) {
  18609. extrudePts = extrudePath.getSpacedPoints(steps);
  18610. extrudeByPath = true;
  18611. bevelEnabled = false; // bevels not supported for path extrusion
  18612. // SETUP TNB variables
  18613. // TODO1 - have a .isClosed in spline?
  18614. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18615. binormal = new Vector3();
  18616. normal = new Vector3();
  18617. position2 = new Vector3();
  18618. } // Safeguards if bevels are not enabled
  18619. if (!bevelEnabled) {
  18620. bevelSegments = 0;
  18621. bevelThickness = 0;
  18622. bevelSize = 0;
  18623. bevelOffset = 0;
  18624. } // Variables initialization
  18625. var shapePoints = shape.extractPoints(curveSegments);
  18626. var vertices = shapePoints.shape;
  18627. var holes = shapePoints.holes;
  18628. var reverse = !ShapeUtils.isClockWise(vertices);
  18629. if (reverse) {
  18630. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18631. for (var h = 0, hl = holes.length; h < hl; h++) {
  18632. var ahole = holes[h];
  18633. if (ShapeUtils.isClockWise(ahole)) {
  18634. holes[h] = ahole.reverse();
  18635. }
  18636. }
  18637. }
  18638. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18639. /* Vertices */
  18640. var contour = vertices; // vertices has all points but contour has only points of circumference
  18641. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18642. var _ahole = holes[_h];
  18643. vertices = vertices.concat(_ahole);
  18644. }
  18645. function scalePt2(pt, vec, size) {
  18646. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18647. return vec.clone().multiplyScalar(size).add(pt);
  18648. }
  18649. var vlen = vertices.length,
  18650. flen = faces.length; // Find directions for point movement
  18651. function getBevelVec(inPt, inPrev, inNext) {
  18652. // computes for inPt the corresponding point inPt' on a new contour
  18653. // shifted by 1 unit (length of normalized vector) to the left
  18654. // if we walk along contour clockwise, this new contour is outside the old one
  18655. //
  18656. // inPt' is the intersection of the two lines parallel to the two
  18657. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18658. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18659. // good reading for geometry algorithms (here: line-line intersection)
  18660. // http://geomalgorithms.com/a05-_intersect-1.html
  18661. var v_prev_x = inPt.x - inPrev.x,
  18662. v_prev_y = inPt.y - inPrev.y;
  18663. var v_next_x = inNext.x - inPt.x,
  18664. v_next_y = inNext.y - inPt.y;
  18665. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18666. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18667. if (Math.abs(collinear0) > Number.EPSILON) {
  18668. // not collinear
  18669. // length of vectors for normalizing
  18670. var v_prev_len = Math.sqrt(v_prev_lensq);
  18671. 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
  18672. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18673. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18674. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18675. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18676. 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
  18677. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18678. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18679. // but prevent crazy spikes
  18680. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18681. if (v_trans_lensq <= 2) {
  18682. return new Vector2(v_trans_x, v_trans_y);
  18683. } else {
  18684. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18685. }
  18686. } else {
  18687. // handle special case of collinear edges
  18688. var direction_eq = false; // assumes: opposite
  18689. if (v_prev_x > Number.EPSILON) {
  18690. if (v_next_x > Number.EPSILON) {
  18691. direction_eq = true;
  18692. }
  18693. } else {
  18694. if (v_prev_x < -Number.EPSILON) {
  18695. if (v_next_x < -Number.EPSILON) {
  18696. direction_eq = true;
  18697. }
  18698. } else {
  18699. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18700. direction_eq = true;
  18701. }
  18702. }
  18703. }
  18704. if (direction_eq) {
  18705. // console.log("Warning: lines are a straight sequence");
  18706. v_trans_x = -v_prev_y;
  18707. v_trans_y = v_prev_x;
  18708. shrink_by = Math.sqrt(v_prev_lensq);
  18709. } else {
  18710. // console.log("Warning: lines are a straight spike");
  18711. v_trans_x = v_prev_x;
  18712. v_trans_y = v_prev_y;
  18713. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18714. }
  18715. }
  18716. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18717. }
  18718. var contourMovements = [];
  18719. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18720. if (j === il) j = 0;
  18721. if (k === il) k = 0; // (j)---(i)---(k)
  18722. // console.log('i,j,k', i, j , k)
  18723. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18724. }
  18725. var holesMovements = [];
  18726. var oneHoleMovements,
  18727. verticesMovements = contourMovements.concat();
  18728. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18729. var _ahole2 = holes[_h2];
  18730. oneHoleMovements = [];
  18731. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18732. if (_j === _il) _j = 0;
  18733. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18734. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18735. }
  18736. holesMovements.push(oneHoleMovements);
  18737. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18738. } // Loop bevelSegments, 1 for the front, 1 for the back
  18739. for (var b = 0; b < bevelSegments; b++) {
  18740. //for ( b = bevelSegments; b > 0; b -- ) {
  18741. var t = b / bevelSegments;
  18742. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18743. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18744. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18745. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18746. v(vert.x, vert.y, -z);
  18747. } // expand holes
  18748. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18749. var _ahole3 = holes[_h3];
  18750. oneHoleMovements = holesMovements[_h3];
  18751. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18752. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18753. v(_vert.x, _vert.y, -z);
  18754. }
  18755. }
  18756. }
  18757. var bs = bevelSize + bevelOffset; // Back facing vertices
  18758. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18759. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18760. if (!extrudeByPath) {
  18761. v(_vert2.x, _vert2.y, 0);
  18762. } else {
  18763. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18764. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18765. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18766. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18767. v(position2.x, position2.y, position2.z);
  18768. }
  18769. } // Add stepped vertices...
  18770. // Including front facing vertices
  18771. for (var s = 1; s <= steps; s++) {
  18772. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18773. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18774. if (!extrudeByPath) {
  18775. v(_vert3.x, _vert3.y, depth / steps * s);
  18776. } else {
  18777. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18778. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18779. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18780. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18781. v(position2.x, position2.y, position2.z);
  18782. }
  18783. }
  18784. } // Add bevel segments planes
  18785. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18786. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18787. var _t = _b / bevelSegments;
  18788. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18789. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18790. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18791. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18792. v(_vert4.x, _vert4.y, depth + _z);
  18793. } // expand holes
  18794. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18795. var _ahole4 = holes[_h4];
  18796. oneHoleMovements = holesMovements[_h4];
  18797. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18798. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18799. if (!extrudeByPath) {
  18800. v(_vert5.x, _vert5.y, depth + _z);
  18801. } else {
  18802. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18803. }
  18804. }
  18805. }
  18806. }
  18807. /* Faces */
  18808. // Top and bottom faces
  18809. buildLidFaces(); // Sides faces
  18810. buildSideFaces(); ///// Internal functions
  18811. function buildLidFaces() {
  18812. var start = verticesArray.length / 3;
  18813. if (bevelEnabled) {
  18814. var layer = 0; // steps + 1
  18815. var offset = vlen * layer; // Bottom faces
  18816. for (var _i9 = 0; _i9 < flen; _i9++) {
  18817. var face = faces[_i9];
  18818. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18819. }
  18820. layer = steps + bevelSegments * 2;
  18821. offset = vlen * layer; // Top faces
  18822. for (var _i10 = 0; _i10 < flen; _i10++) {
  18823. var _face = faces[_i10];
  18824. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18825. }
  18826. } else {
  18827. // Bottom faces
  18828. for (var _i11 = 0; _i11 < flen; _i11++) {
  18829. var _face2 = faces[_i11];
  18830. f3(_face2[2], _face2[1], _face2[0]);
  18831. } // Top faces
  18832. for (var _i12 = 0; _i12 < flen; _i12++) {
  18833. var _face3 = faces[_i12];
  18834. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18835. }
  18836. }
  18837. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18838. } // Create faces for the z-sides of the shape
  18839. function buildSideFaces() {
  18840. var start = verticesArray.length / 3;
  18841. var layeroffset = 0;
  18842. sidewalls(contour, layeroffset);
  18843. layeroffset += contour.length;
  18844. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18845. var _ahole5 = holes[_h5];
  18846. sidewalls(_ahole5, layeroffset); //, true
  18847. layeroffset += _ahole5.length;
  18848. }
  18849. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18850. }
  18851. function sidewalls(contour, layeroffset) {
  18852. var i = contour.length;
  18853. while (--i >= 0) {
  18854. var _j2 = i;
  18855. var _k2 = i - 1;
  18856. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18857. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18858. var slen1 = vlen * _s;
  18859. var slen2 = vlen * (_s + 1);
  18860. var a = layeroffset + _j2 + slen1,
  18861. _b2 = layeroffset + _k2 + slen1,
  18862. c = layeroffset + _k2 + slen2,
  18863. d = layeroffset + _j2 + slen2;
  18864. f4(a, _b2, c, d);
  18865. }
  18866. }
  18867. }
  18868. function v(x, y, z) {
  18869. placeholder.push(x);
  18870. placeholder.push(y);
  18871. placeholder.push(z);
  18872. }
  18873. function f3(a, b, c) {
  18874. addVertex(a);
  18875. addVertex(b);
  18876. addVertex(c);
  18877. var nextIndex = verticesArray.length / 3;
  18878. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18879. addUV(uvs[0]);
  18880. addUV(uvs[1]);
  18881. addUV(uvs[2]);
  18882. }
  18883. function f4(a, b, c, d) {
  18884. addVertex(a);
  18885. addVertex(b);
  18886. addVertex(d);
  18887. addVertex(b);
  18888. addVertex(c);
  18889. addVertex(d);
  18890. var nextIndex = verticesArray.length / 3;
  18891. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18892. addUV(uvs[0]);
  18893. addUV(uvs[1]);
  18894. addUV(uvs[3]);
  18895. addUV(uvs[1]);
  18896. addUV(uvs[2]);
  18897. addUV(uvs[3]);
  18898. }
  18899. function addVertex(index) {
  18900. verticesArray.push(placeholder[index * 3 + 0]);
  18901. verticesArray.push(placeholder[index * 3 + 1]);
  18902. verticesArray.push(placeholder[index * 3 + 2]);
  18903. }
  18904. function addUV(vector2) {
  18905. uvArray.push(vector2.x);
  18906. uvArray.push(vector2.y);
  18907. }
  18908. }
  18909. return _this;
  18910. }
  18911. var _proto = ExtrudeBufferGeometry.prototype;
  18912. _proto.toJSON = function toJSON() {
  18913. var data = BufferGeometry.prototype.toJSON.call(this);
  18914. var shapes = this.parameters.shapes;
  18915. var options = this.parameters.options;
  18916. return _toJSON(shapes, options, data);
  18917. };
  18918. return ExtrudeBufferGeometry;
  18919. }(BufferGeometry);
  18920. var WorldUVGenerator = {
  18921. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18922. var a_x = vertices[indexA * 3];
  18923. var a_y = vertices[indexA * 3 + 1];
  18924. var b_x = vertices[indexB * 3];
  18925. var b_y = vertices[indexB * 3 + 1];
  18926. var c_x = vertices[indexC * 3];
  18927. var c_y = vertices[indexC * 3 + 1];
  18928. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18929. },
  18930. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18931. var a_x = vertices[indexA * 3];
  18932. var a_y = vertices[indexA * 3 + 1];
  18933. var a_z = vertices[indexA * 3 + 2];
  18934. var b_x = vertices[indexB * 3];
  18935. var b_y = vertices[indexB * 3 + 1];
  18936. var b_z = vertices[indexB * 3 + 2];
  18937. var c_x = vertices[indexC * 3];
  18938. var c_y = vertices[indexC * 3 + 1];
  18939. var c_z = vertices[indexC * 3 + 2];
  18940. var d_x = vertices[indexD * 3];
  18941. var d_y = vertices[indexD * 3 + 1];
  18942. var d_z = vertices[indexD * 3 + 2];
  18943. if (Math.abs(a_y - b_y) < 0.01) {
  18944. 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)];
  18945. } else {
  18946. 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)];
  18947. }
  18948. }
  18949. };
  18950. function _toJSON(shapes, options, data) {
  18951. data.shapes = [];
  18952. if (Array.isArray(shapes)) {
  18953. for (var i = 0, l = shapes.length; i < l; i++) {
  18954. var shape = shapes[i];
  18955. data.shapes.push(shape.uuid);
  18956. }
  18957. } else {
  18958. data.shapes.push(shapes.uuid);
  18959. }
  18960. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18961. return data;
  18962. }
  18963. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18964. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18965. function ExtrudeGeometry(shapes, options) {
  18966. var _this;
  18967. _this = _Geometry.call(this) || this;
  18968. _this.type = 'ExtrudeGeometry';
  18969. _this.parameters = {
  18970. shapes: shapes,
  18971. options: options
  18972. };
  18973. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18974. _this.mergeVertices();
  18975. return _this;
  18976. }
  18977. var _proto = ExtrudeGeometry.prototype;
  18978. _proto.toJSON = function toJSON() {
  18979. var data = _Geometry.prototype.toJSON.call(this);
  18980. var shapes = this.parameters.shapes;
  18981. var options = this.parameters.options;
  18982. return _toJSON$1(shapes, options, data);
  18983. };
  18984. return ExtrudeGeometry;
  18985. }(Geometry);
  18986. function _toJSON$1(shapes, options, data) {
  18987. data.shapes = [];
  18988. if (Array.isArray(shapes)) {
  18989. for (var i = 0, l = shapes.length; i < l; i++) {
  18990. var shape = shapes[i];
  18991. data.shapes.push(shape.uuid);
  18992. }
  18993. } else {
  18994. data.shapes.push(shapes.uuid);
  18995. }
  18996. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18997. return data;
  18998. }
  18999. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19000. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  19001. function IcosahedronBufferGeometry(radius, detail) {
  19002. var _this;
  19003. if (radius === void 0) {
  19004. radius = 1;
  19005. }
  19006. if (detail === void 0) {
  19007. detail = 0;
  19008. }
  19009. var t = (1 + Math.sqrt(5)) / 2;
  19010. 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];
  19011. 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];
  19012. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19013. _this.type = 'IcosahedronBufferGeometry';
  19014. _this.parameters = {
  19015. radius: radius,
  19016. detail: detail
  19017. };
  19018. return _this;
  19019. }
  19020. return IcosahedronBufferGeometry;
  19021. }(PolyhedronBufferGeometry);
  19022. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19023. _inheritsLoose(IcosahedronGeometry, _Geometry);
  19024. function IcosahedronGeometry(radius, detail) {
  19025. var _this;
  19026. _this = _Geometry.call(this) || this;
  19027. _this.type = 'IcosahedronGeometry';
  19028. _this.parameters = {
  19029. radius: radius,
  19030. detail: detail
  19031. };
  19032. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  19033. _this.mergeVertices();
  19034. return _this;
  19035. }
  19036. return IcosahedronGeometry;
  19037. }(Geometry);
  19038. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19039. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  19040. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  19041. var _this;
  19042. if (segments === void 0) {
  19043. segments = 12;
  19044. }
  19045. if (phiStart === void 0) {
  19046. phiStart = 0;
  19047. }
  19048. if (phiLength === void 0) {
  19049. phiLength = Math.PI * 2;
  19050. }
  19051. _this = _BufferGeometry.call(this) || this;
  19052. _this.type = 'LatheBufferGeometry';
  19053. _this.parameters = {
  19054. points: points,
  19055. segments: segments,
  19056. phiStart: phiStart,
  19057. phiLength: phiLength
  19058. };
  19059. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  19060. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  19061. var indices = [];
  19062. var vertices = [];
  19063. var uvs = []; // helper variables
  19064. var inverseSegments = 1.0 / segments;
  19065. var vertex = new Vector3();
  19066. var uv = new Vector2(); // generate vertices and uvs
  19067. for (var i = 0; i <= segments; i++) {
  19068. var phi = phiStart + i * inverseSegments * phiLength;
  19069. var sin = Math.sin(phi);
  19070. var cos = Math.cos(phi);
  19071. for (var j = 0; j <= points.length - 1; j++) {
  19072. // vertex
  19073. vertex.x = points[j].x * sin;
  19074. vertex.y = points[j].y;
  19075. vertex.z = points[j].x * cos;
  19076. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  19077. uv.x = i / segments;
  19078. uv.y = j / (points.length - 1);
  19079. uvs.push(uv.x, uv.y);
  19080. }
  19081. } // indices
  19082. for (var _i = 0; _i < segments; _i++) {
  19083. for (var _j = 0; _j < points.length - 1; _j++) {
  19084. var base = _j + _i * points.length;
  19085. var a = base;
  19086. var b = base + points.length;
  19087. var c = base + points.length + 1;
  19088. var d = base + 1; // faces
  19089. indices.push(a, b, d);
  19090. indices.push(b, c, d);
  19091. }
  19092. } // build geometry
  19093. _this.setIndex(indices);
  19094. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19095. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  19096. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  19097. // because the corresponding vertices are identical (but still have different UVs).
  19098. if (phiLength === Math.PI * 2) {
  19099. var normals = _this.attributes.normal.array;
  19100. var n1 = new Vector3();
  19101. var n2 = new Vector3();
  19102. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  19103. var _base = segments * points.length * 3;
  19104. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  19105. // select the normal of the vertex in the first line
  19106. n1.x = normals[_j2 + 0];
  19107. n1.y = normals[_j2 + 1];
  19108. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  19109. n2.x = normals[_base + _j2 + 0];
  19110. n2.y = normals[_base + _j2 + 1];
  19111. n2.z = normals[_base + _j2 + 2]; // average normals
  19112. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  19113. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  19114. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  19115. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  19116. }
  19117. }
  19118. return _this;
  19119. }
  19120. return LatheBufferGeometry;
  19121. }(BufferGeometry);
  19122. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  19123. _inheritsLoose(LatheGeometry, _Geometry);
  19124. function LatheGeometry(points, segments, phiStart, phiLength) {
  19125. var _this;
  19126. _this = _Geometry.call(this) || this;
  19127. _this.type = 'LatheGeometry';
  19128. _this.parameters = {
  19129. points: points,
  19130. segments: segments,
  19131. phiStart: phiStart,
  19132. phiLength: phiLength
  19133. };
  19134. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  19135. _this.mergeVertices();
  19136. return _this;
  19137. }
  19138. return LatheGeometry;
  19139. }(Geometry);
  19140. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19141. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  19142. function OctahedronBufferGeometry(radius, detail) {
  19143. var _this;
  19144. if (radius === void 0) {
  19145. radius = 1;
  19146. }
  19147. if (detail === void 0) {
  19148. detail = 0;
  19149. }
  19150. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  19151. 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];
  19152. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19153. _this.type = 'OctahedronBufferGeometry';
  19154. _this.parameters = {
  19155. radius: radius,
  19156. detail: detail
  19157. };
  19158. return _this;
  19159. }
  19160. return OctahedronBufferGeometry;
  19161. }(PolyhedronBufferGeometry);
  19162. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19163. _inheritsLoose(OctahedronGeometry, _Geometry);
  19164. function OctahedronGeometry(radius, detail) {
  19165. var _this;
  19166. _this = _Geometry.call(this) || this;
  19167. _this.type = 'OctahedronGeometry';
  19168. _this.parameters = {
  19169. radius: radius,
  19170. detail: detail
  19171. };
  19172. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  19173. _this.mergeVertices();
  19174. return _this;
  19175. }
  19176. return OctahedronGeometry;
  19177. }(Geometry);
  19178. /**
  19179. * Parametric Surfaces Geometry
  19180. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  19181. */
  19182. function ParametricBufferGeometry(func, slices, stacks) {
  19183. BufferGeometry.call(this);
  19184. this.type = 'ParametricBufferGeometry';
  19185. this.parameters = {
  19186. func: func,
  19187. slices: slices,
  19188. stacks: stacks
  19189. }; // buffers
  19190. var indices = [];
  19191. var vertices = [];
  19192. var normals = [];
  19193. var uvs = [];
  19194. var EPS = 0.00001;
  19195. var normal = new Vector3();
  19196. var p0 = new Vector3(),
  19197. p1 = new Vector3();
  19198. var pu = new Vector3(),
  19199. pv = new Vector3();
  19200. if (func.length < 3) {
  19201. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  19202. } // generate vertices, normals and uvs
  19203. var sliceCount = slices + 1;
  19204. for (var i = 0; i <= stacks; i++) {
  19205. var v = i / stacks;
  19206. for (var j = 0; j <= slices; j++) {
  19207. var u = j / slices; // vertex
  19208. func(u, v, p0);
  19209. vertices.push(p0.x, p0.y, p0.z); // normal
  19210. // approximate tangent vectors via finite differences
  19211. if (u - EPS >= 0) {
  19212. func(u - EPS, v, p1);
  19213. pu.subVectors(p0, p1);
  19214. } else {
  19215. func(u + EPS, v, p1);
  19216. pu.subVectors(p1, p0);
  19217. }
  19218. if (v - EPS >= 0) {
  19219. func(u, v - EPS, p1);
  19220. pv.subVectors(p0, p1);
  19221. } else {
  19222. func(u, v + EPS, p1);
  19223. pv.subVectors(p1, p0);
  19224. } // cross product of tangent vectors returns surface normal
  19225. normal.crossVectors(pu, pv).normalize();
  19226. normals.push(normal.x, normal.y, normal.z); // uv
  19227. uvs.push(u, v);
  19228. }
  19229. } // generate indices
  19230. for (var _i = 0; _i < stacks; _i++) {
  19231. for (var _j = 0; _j < slices; _j++) {
  19232. var a = _i * sliceCount + _j;
  19233. var b = _i * sliceCount + _j + 1;
  19234. var c = (_i + 1) * sliceCount + _j + 1;
  19235. var d = (_i + 1) * sliceCount + _j; // faces one and two
  19236. indices.push(a, b, d);
  19237. indices.push(b, c, d);
  19238. }
  19239. } // build geometry
  19240. this.setIndex(indices);
  19241. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19242. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19243. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19244. }
  19245. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  19246. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  19247. /**
  19248. * Parametric Surfaces Geometry
  19249. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  19250. */
  19251. function ParametricGeometry(func, slices, stacks) {
  19252. Geometry.call(this);
  19253. this.type = 'ParametricGeometry';
  19254. this.parameters = {
  19255. func: func,
  19256. slices: slices,
  19257. stacks: stacks
  19258. };
  19259. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  19260. this.mergeVertices();
  19261. }
  19262. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  19263. ParametricGeometry.prototype.constructor = ParametricGeometry;
  19264. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  19265. _inheritsLoose(PlaneGeometry, _Geometry);
  19266. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  19267. var _this;
  19268. _this = _Geometry.call(this) || this;
  19269. _this.type = 'PlaneGeometry';
  19270. _this.parameters = {
  19271. width: width,
  19272. height: height,
  19273. widthSegments: widthSegments,
  19274. heightSegments: heightSegments
  19275. };
  19276. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  19277. _this.mergeVertices();
  19278. return _this;
  19279. }
  19280. return PlaneGeometry;
  19281. }(Geometry);
  19282. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  19283. _inheritsLoose(PolyhedronGeometry, _Geometry);
  19284. function PolyhedronGeometry(vertices, indices, radius, detail) {
  19285. var _this;
  19286. _this = _Geometry.call(this) || this;
  19287. _this.type = 'PolyhedronGeometry';
  19288. _this.parameters = {
  19289. vertices: vertices,
  19290. indices: indices,
  19291. radius: radius,
  19292. detail: detail
  19293. };
  19294. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  19295. _this.mergeVertices();
  19296. return _this;
  19297. }
  19298. return PolyhedronGeometry;
  19299. }(Geometry);
  19300. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19301. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  19302. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19303. var _this;
  19304. if (innerRadius === void 0) {
  19305. innerRadius = 0.5;
  19306. }
  19307. if (outerRadius === void 0) {
  19308. outerRadius = 1;
  19309. }
  19310. if (thetaSegments === void 0) {
  19311. thetaSegments = 8;
  19312. }
  19313. if (phiSegments === void 0) {
  19314. phiSegments = 1;
  19315. }
  19316. if (thetaStart === void 0) {
  19317. thetaStart = 0;
  19318. }
  19319. if (thetaLength === void 0) {
  19320. thetaLength = Math.PI * 2;
  19321. }
  19322. _this = _BufferGeometry.call(this) || this;
  19323. _this.type = 'RingBufferGeometry';
  19324. _this.parameters = {
  19325. innerRadius: innerRadius,
  19326. outerRadius: outerRadius,
  19327. thetaSegments: thetaSegments,
  19328. phiSegments: phiSegments,
  19329. thetaStart: thetaStart,
  19330. thetaLength: thetaLength
  19331. };
  19332. thetaSegments = Math.max(3, thetaSegments);
  19333. phiSegments = Math.max(1, phiSegments); // buffers
  19334. var indices = [];
  19335. var vertices = [];
  19336. var normals = [];
  19337. var uvs = []; // some helper variables
  19338. var radius = innerRadius;
  19339. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  19340. var vertex = new Vector3();
  19341. var uv = new Vector2(); // generate vertices, normals and uvs
  19342. for (var j = 0; j <= phiSegments; j++) {
  19343. for (var i = 0; i <= thetaSegments; i++) {
  19344. // values are generate from the inside of the ring to the outside
  19345. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  19346. vertex.x = radius * Math.cos(segment);
  19347. vertex.y = radius * Math.sin(segment);
  19348. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19349. normals.push(0, 0, 1); // uv
  19350. uv.x = (vertex.x / outerRadius + 1) / 2;
  19351. uv.y = (vertex.y / outerRadius + 1) / 2;
  19352. uvs.push(uv.x, uv.y);
  19353. } // increase the radius for next row of vertices
  19354. radius += radiusStep;
  19355. } // indices
  19356. for (var _j = 0; _j < phiSegments; _j++) {
  19357. var thetaSegmentLevel = _j * (thetaSegments + 1);
  19358. for (var _i = 0; _i < thetaSegments; _i++) {
  19359. var _segment = _i + thetaSegmentLevel;
  19360. var a = _segment;
  19361. var b = _segment + thetaSegments + 1;
  19362. var c = _segment + thetaSegments + 2;
  19363. var d = _segment + 1; // faces
  19364. indices.push(a, b, d);
  19365. indices.push(b, c, d);
  19366. }
  19367. } // build geometry
  19368. _this.setIndex(indices);
  19369. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19370. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19371. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19372. return _this;
  19373. }
  19374. return RingBufferGeometry;
  19375. }(BufferGeometry);
  19376. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  19377. _inheritsLoose(RingGeometry, _Geometry);
  19378. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19379. var _this;
  19380. _this = _Geometry.call(this) || this;
  19381. _this.type = 'RingGeometry';
  19382. _this.parameters = {
  19383. innerRadius: innerRadius,
  19384. outerRadius: outerRadius,
  19385. thetaSegments: thetaSegments,
  19386. phiSegments: phiSegments,
  19387. thetaStart: thetaStart,
  19388. thetaLength: thetaLength
  19389. };
  19390. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  19391. _this.mergeVertices();
  19392. return _this;
  19393. }
  19394. return RingGeometry;
  19395. }(Geometry);
  19396. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19397. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  19398. function ShapeBufferGeometry(shapes, curveSegments) {
  19399. var _this;
  19400. if (curveSegments === void 0) {
  19401. curveSegments = 12;
  19402. }
  19403. _this = _BufferGeometry.call(this) || this;
  19404. _this.type = 'ShapeBufferGeometry';
  19405. _this.parameters = {
  19406. shapes: shapes,
  19407. curveSegments: curveSegments
  19408. }; // buffers
  19409. var indices = [];
  19410. var vertices = [];
  19411. var normals = [];
  19412. var uvs = []; // helper variables
  19413. var groupStart = 0;
  19414. var groupCount = 0; // allow single and array values for "shapes" parameter
  19415. if (Array.isArray(shapes) === false) {
  19416. addShape(shapes);
  19417. } else {
  19418. for (var i = 0; i < shapes.length; i++) {
  19419. addShape(shapes[i]);
  19420. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19421. groupStart += groupCount;
  19422. groupCount = 0;
  19423. }
  19424. } // build geometry
  19425. _this.setIndex(indices);
  19426. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19427. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19428. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19429. function addShape(shape) {
  19430. var indexOffset = vertices.length / 3;
  19431. var points = shape.extractPoints(curveSegments);
  19432. var shapeVertices = points.shape;
  19433. var shapeHoles = points.holes; // check direction of vertices
  19434. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19435. shapeVertices = shapeVertices.reverse();
  19436. }
  19437. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19438. var shapeHole = shapeHoles[_i];
  19439. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19440. shapeHoles[_i] = shapeHole.reverse();
  19441. }
  19442. }
  19443. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19444. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19445. var _shapeHole = shapeHoles[_i2];
  19446. shapeVertices = shapeVertices.concat(_shapeHole);
  19447. } // vertices, normals, uvs
  19448. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19449. var vertex = shapeVertices[_i3];
  19450. vertices.push(vertex.x, vertex.y, 0);
  19451. normals.push(0, 0, 1);
  19452. uvs.push(vertex.x, vertex.y); // world uvs
  19453. } // incides
  19454. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19455. var face = faces[_i4];
  19456. var a = face[0] + indexOffset;
  19457. var b = face[1] + indexOffset;
  19458. var c = face[2] + indexOffset;
  19459. indices.push(a, b, c);
  19460. groupCount += 3;
  19461. }
  19462. }
  19463. return _this;
  19464. }
  19465. var _proto = ShapeBufferGeometry.prototype;
  19466. _proto.toJSON = function toJSON() {
  19467. var data = BufferGeometry.prototype.toJSON.call(this);
  19468. var shapes = this.parameters.shapes;
  19469. return _toJSON$2(shapes, data);
  19470. };
  19471. return ShapeBufferGeometry;
  19472. }(BufferGeometry);
  19473. function _toJSON$2(shapes, data) {
  19474. data.shapes = [];
  19475. if (Array.isArray(shapes)) {
  19476. for (var i = 0, l = shapes.length; i < l; i++) {
  19477. var shape = shapes[i];
  19478. data.shapes.push(shape.uuid);
  19479. }
  19480. } else {
  19481. data.shapes.push(shapes.uuid);
  19482. }
  19483. return data;
  19484. }
  19485. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  19486. _inheritsLoose(ShapeGeometry, _Geometry);
  19487. function ShapeGeometry(shapes, curveSegments) {
  19488. var _this;
  19489. _this = _Geometry.call(this) || this;
  19490. _this.type = 'ShapeGeometry';
  19491. if (typeof curveSegments === 'object') {
  19492. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19493. curveSegments = curveSegments.curveSegments;
  19494. }
  19495. _this.parameters = {
  19496. shapes: shapes,
  19497. curveSegments: curveSegments
  19498. };
  19499. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19500. _this.mergeVertices();
  19501. return _this;
  19502. }
  19503. var _proto = ShapeGeometry.prototype;
  19504. _proto.toJSON = function toJSON() {
  19505. var data = Geometry.prototype.toJSON.call(this);
  19506. var shapes = this.parameters.shapes;
  19507. return _toJSON$3(shapes, data);
  19508. };
  19509. return ShapeGeometry;
  19510. }(Geometry);
  19511. function _toJSON$3(shapes, data) {
  19512. data.shapes = [];
  19513. if (Array.isArray(shapes)) {
  19514. for (var i = 0, l = shapes.length; i < l; i++) {
  19515. var shape = shapes[i];
  19516. data.shapes.push(shape.uuid);
  19517. }
  19518. } else {
  19519. data.shapes.push(shapes.uuid);
  19520. }
  19521. return data;
  19522. }
  19523. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19524. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19525. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19526. var _this;
  19527. if (radius === void 0) {
  19528. radius = 1;
  19529. }
  19530. if (widthSegments === void 0) {
  19531. widthSegments = 8;
  19532. }
  19533. if (heightSegments === void 0) {
  19534. heightSegments = 6;
  19535. }
  19536. if (phiStart === void 0) {
  19537. phiStart = 0;
  19538. }
  19539. if (phiLength === void 0) {
  19540. phiLength = Math.PI * 2;
  19541. }
  19542. if (thetaStart === void 0) {
  19543. thetaStart = 0;
  19544. }
  19545. if (thetaLength === void 0) {
  19546. thetaLength = Math.PI;
  19547. }
  19548. _this = _BufferGeometry.call(this) || this;
  19549. _this.type = 'SphereBufferGeometry';
  19550. _this.parameters = {
  19551. radius: radius,
  19552. widthSegments: widthSegments,
  19553. heightSegments: heightSegments,
  19554. phiStart: phiStart,
  19555. phiLength: phiLength,
  19556. thetaStart: thetaStart,
  19557. thetaLength: thetaLength
  19558. };
  19559. widthSegments = Math.max(3, Math.floor(widthSegments));
  19560. heightSegments = Math.max(2, Math.floor(heightSegments));
  19561. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19562. var index = 0;
  19563. var grid = [];
  19564. var vertex = new Vector3();
  19565. var normal = new Vector3(); // buffers
  19566. var indices = [];
  19567. var vertices = [];
  19568. var normals = [];
  19569. var uvs = []; // generate vertices, normals and uvs
  19570. for (var iy = 0; iy <= heightSegments; iy++) {
  19571. var verticesRow = [];
  19572. var v = iy / heightSegments; // special case for the poles
  19573. var uOffset = 0;
  19574. if (iy == 0 && thetaStart == 0) {
  19575. uOffset = 0.5 / widthSegments;
  19576. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19577. uOffset = -0.5 / widthSegments;
  19578. }
  19579. for (var ix = 0; ix <= widthSegments; ix++) {
  19580. var u = ix / widthSegments; // vertex
  19581. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19582. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19583. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19584. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19585. normal.copy(vertex).normalize();
  19586. normals.push(normal.x, normal.y, normal.z); // uv
  19587. uvs.push(u + uOffset, 1 - v);
  19588. verticesRow.push(index++);
  19589. }
  19590. grid.push(verticesRow);
  19591. } // indices
  19592. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19593. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19594. var a = grid[_iy][_ix + 1];
  19595. var b = grid[_iy][_ix];
  19596. var c = grid[_iy + 1][_ix];
  19597. var d = grid[_iy + 1][_ix + 1];
  19598. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19599. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19600. }
  19601. } // build geometry
  19602. _this.setIndex(indices);
  19603. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19604. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19605. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19606. return _this;
  19607. }
  19608. return SphereBufferGeometry;
  19609. }(BufferGeometry);
  19610. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19611. _inheritsLoose(SphereGeometry, _Geometry);
  19612. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19613. var _this;
  19614. _this = _Geometry.call(this) || this;
  19615. _this.type = 'SphereGeometry';
  19616. _this.parameters = {
  19617. radius: radius,
  19618. widthSegments: widthSegments,
  19619. heightSegments: heightSegments,
  19620. phiStart: phiStart,
  19621. phiLength: phiLength,
  19622. thetaStart: thetaStart,
  19623. thetaLength: thetaLength
  19624. };
  19625. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19626. _this.mergeVertices();
  19627. return _this;
  19628. }
  19629. return SphereGeometry;
  19630. }(Geometry);
  19631. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19632. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19633. function TetrahedronBufferGeometry(radius, detail) {
  19634. var _this;
  19635. if (radius === void 0) {
  19636. radius = 1;
  19637. }
  19638. if (detail === void 0) {
  19639. detail = 0;
  19640. }
  19641. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19642. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19643. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19644. _this.type = 'TetrahedronBufferGeometry';
  19645. _this.parameters = {
  19646. radius: radius,
  19647. detail: detail
  19648. };
  19649. return _this;
  19650. }
  19651. return TetrahedronBufferGeometry;
  19652. }(PolyhedronBufferGeometry);
  19653. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19654. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19655. function TetrahedronGeometry(radius, detail) {
  19656. var _this;
  19657. _this = _Geometry.call(this) || this;
  19658. _this.type = 'TetrahedronGeometry';
  19659. _this.parameters = {
  19660. radius: radius,
  19661. detail: detail
  19662. };
  19663. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19664. _this.mergeVertices();
  19665. return _this;
  19666. }
  19667. return TetrahedronGeometry;
  19668. }(Geometry);
  19669. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19670. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19671. function TextBufferGeometry(text, parameters) {
  19672. var _this;
  19673. if (parameters === void 0) {
  19674. parameters = {};
  19675. }
  19676. var font = parameters.font;
  19677. if (!(font && font.isFont)) {
  19678. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19679. return new BufferGeometry() || _assertThisInitialized(_this);
  19680. }
  19681. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19682. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19683. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19684. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19685. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19686. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19687. _this.type = 'TextBufferGeometry';
  19688. return _this;
  19689. }
  19690. return TextBufferGeometry;
  19691. }(ExtrudeBufferGeometry);
  19692. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19693. _inheritsLoose(TextGeometry, _Geometry);
  19694. function TextGeometry(text, parameters) {
  19695. var _this;
  19696. _this = _Geometry.call(this) || this;
  19697. _this.type = 'TextGeometry';
  19698. _this.parameters = {
  19699. text: text,
  19700. parameters: parameters
  19701. };
  19702. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19703. _this.mergeVertices();
  19704. return _this;
  19705. }
  19706. return TextGeometry;
  19707. }(Geometry);
  19708. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19709. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19710. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19711. var _this;
  19712. if (radius === void 0) {
  19713. radius = 1;
  19714. }
  19715. if (tube === void 0) {
  19716. tube = 0.4;
  19717. }
  19718. if (radialSegments === void 0) {
  19719. radialSegments = 8;
  19720. }
  19721. if (tubularSegments === void 0) {
  19722. tubularSegments = 6;
  19723. }
  19724. if (arc === void 0) {
  19725. arc = Math.PI * 2;
  19726. }
  19727. _this = _BufferGeometry.call(this) || this;
  19728. _this.type = 'TorusBufferGeometry';
  19729. _this.parameters = {
  19730. radius: radius,
  19731. tube: tube,
  19732. radialSegments: radialSegments,
  19733. tubularSegments: tubularSegments,
  19734. arc: arc
  19735. };
  19736. radialSegments = Math.floor(radialSegments);
  19737. tubularSegments = Math.floor(tubularSegments); // buffers
  19738. var indices = [];
  19739. var vertices = [];
  19740. var normals = [];
  19741. var uvs = []; // helper variables
  19742. var center = new Vector3();
  19743. var vertex = new Vector3();
  19744. var normal = new Vector3(); // generate vertices, normals and uvs
  19745. for (var j = 0; j <= radialSegments; j++) {
  19746. for (var i = 0; i <= tubularSegments; i++) {
  19747. var u = i / tubularSegments * arc;
  19748. var v = j / radialSegments * Math.PI * 2; // vertex
  19749. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19750. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19751. vertex.z = tube * Math.sin(v);
  19752. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19753. center.x = radius * Math.cos(u);
  19754. center.y = radius * Math.sin(u);
  19755. normal.subVectors(vertex, center).normalize();
  19756. normals.push(normal.x, normal.y, normal.z); // uv
  19757. uvs.push(i / tubularSegments);
  19758. uvs.push(j / radialSegments);
  19759. }
  19760. } // generate indices
  19761. for (var _j = 1; _j <= radialSegments; _j++) {
  19762. for (var _i = 1; _i <= tubularSegments; _i++) {
  19763. // indices
  19764. var a = (tubularSegments + 1) * _j + _i - 1;
  19765. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19766. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19767. var d = (tubularSegments + 1) * _j + _i; // faces
  19768. indices.push(a, b, d);
  19769. indices.push(b, c, d);
  19770. }
  19771. } // build geometry
  19772. _this.setIndex(indices);
  19773. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19774. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19775. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19776. return _this;
  19777. }
  19778. return TorusBufferGeometry;
  19779. }(BufferGeometry);
  19780. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19781. _inheritsLoose(TorusGeometry, _Geometry);
  19782. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19783. var _this;
  19784. _this = _Geometry.call(this) || this;
  19785. _this.type = 'TorusGeometry';
  19786. _this.parameters = {
  19787. radius: radius,
  19788. tube: tube,
  19789. radialSegments: radialSegments,
  19790. tubularSegments: tubularSegments,
  19791. arc: arc
  19792. };
  19793. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19794. _this.mergeVertices();
  19795. return _this;
  19796. }
  19797. return TorusGeometry;
  19798. }(Geometry);
  19799. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19800. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19801. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19802. var _this;
  19803. if (radius === void 0) {
  19804. radius = 1;
  19805. }
  19806. if (tube === void 0) {
  19807. tube = 0.4;
  19808. }
  19809. if (tubularSegments === void 0) {
  19810. tubularSegments = 64;
  19811. }
  19812. if (radialSegments === void 0) {
  19813. radialSegments = 8;
  19814. }
  19815. if (p === void 0) {
  19816. p = 2;
  19817. }
  19818. if (q === void 0) {
  19819. q = 3;
  19820. }
  19821. _this = _BufferGeometry.call(this) || this;
  19822. _this.type = 'TorusKnotBufferGeometry';
  19823. _this.parameters = {
  19824. radius: radius,
  19825. tube: tube,
  19826. tubularSegments: tubularSegments,
  19827. radialSegments: radialSegments,
  19828. p: p,
  19829. q: q
  19830. };
  19831. tubularSegments = Math.floor(tubularSegments);
  19832. radialSegments = Math.floor(radialSegments); // buffers
  19833. var indices = [];
  19834. var vertices = [];
  19835. var normals = [];
  19836. var uvs = []; // helper variables
  19837. var vertex = new Vector3();
  19838. var normal = new Vector3();
  19839. var P1 = new Vector3();
  19840. var P2 = new Vector3();
  19841. var B = new Vector3();
  19842. var T = new Vector3();
  19843. var N = new Vector3(); // generate vertices, normals and uvs
  19844. for (var i = 0; i <= tubularSegments; ++i) {
  19845. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19846. 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.
  19847. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19848. calculatePositionOnCurve(u, p, q, radius, P1);
  19849. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19850. T.subVectors(P2, P1);
  19851. N.addVectors(P2, P1);
  19852. B.crossVectors(T, N);
  19853. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19854. B.normalize();
  19855. N.normalize();
  19856. for (var j = 0; j <= radialSegments; ++j) {
  19857. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19858. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19859. var v = j / radialSegments * Math.PI * 2;
  19860. var cx = -tube * Math.cos(v);
  19861. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19862. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19863. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19864. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19865. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19866. 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)
  19867. normal.subVectors(vertex, P1).normalize();
  19868. normals.push(normal.x, normal.y, normal.z); // uv
  19869. uvs.push(i / tubularSegments);
  19870. uvs.push(j / radialSegments);
  19871. }
  19872. } // generate indices
  19873. for (var _j = 1; _j <= tubularSegments; _j++) {
  19874. for (var _i = 1; _i <= radialSegments; _i++) {
  19875. // indices
  19876. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19877. var b = (radialSegments + 1) * _j + (_i - 1);
  19878. var c = (radialSegments + 1) * _j + _i;
  19879. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19880. indices.push(a, b, d);
  19881. indices.push(b, c, d);
  19882. }
  19883. } // build geometry
  19884. _this.setIndex(indices);
  19885. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19886. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19887. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19888. function calculatePositionOnCurve(u, p, q, radius, position) {
  19889. var cu = Math.cos(u);
  19890. var su = Math.sin(u);
  19891. var quOverP = q / p * u;
  19892. var cs = Math.cos(quOverP);
  19893. position.x = radius * (2 + cs) * 0.5 * cu;
  19894. position.y = radius * (2 + cs) * su * 0.5;
  19895. position.z = radius * Math.sin(quOverP) * 0.5;
  19896. }
  19897. return _this;
  19898. }
  19899. return TorusKnotBufferGeometry;
  19900. }(BufferGeometry);
  19901. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19902. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19903. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19904. var _this;
  19905. _this = _Geometry.call(this) || this;
  19906. _this.type = 'TorusKnotGeometry';
  19907. _this.parameters = {
  19908. radius: radius,
  19909. tube: tube,
  19910. tubularSegments: tubularSegments,
  19911. radialSegments: radialSegments,
  19912. p: p,
  19913. q: q
  19914. };
  19915. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19916. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19917. _this.mergeVertices();
  19918. return _this;
  19919. }
  19920. return TorusKnotGeometry;
  19921. }(Geometry);
  19922. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19923. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19924. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19925. var _this;
  19926. if (tubularSegments === void 0) {
  19927. tubularSegments = 64;
  19928. }
  19929. if (radius === void 0) {
  19930. radius = 1;
  19931. }
  19932. if (radialSegments === void 0) {
  19933. radialSegments = 8;
  19934. }
  19935. if (closed === void 0) {
  19936. closed = false;
  19937. }
  19938. _this = _BufferGeometry.call(this) || this;
  19939. _this.type = 'TubeBufferGeometry';
  19940. _this.parameters = {
  19941. path: path,
  19942. tubularSegments: tubularSegments,
  19943. radius: radius,
  19944. radialSegments: radialSegments,
  19945. closed: closed
  19946. };
  19947. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19948. _this.tangents = frames.tangents;
  19949. _this.normals = frames.normals;
  19950. _this.binormals = frames.binormals; // helper variables
  19951. var vertex = new Vector3();
  19952. var normal = new Vector3();
  19953. var uv = new Vector2();
  19954. var P = new Vector3(); // buffer
  19955. var vertices = [];
  19956. var normals = [];
  19957. var uvs = [];
  19958. var indices = []; // create buffer data
  19959. generateBufferData(); // build geometry
  19960. _this.setIndex(indices);
  19961. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19962. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19963. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19964. function generateBufferData() {
  19965. for (var i = 0; i < tubularSegments; i++) {
  19966. generateSegment(i);
  19967. } // if the geometry is not closed, generate the last row of vertices and normals
  19968. // at the regular position on the given path
  19969. //
  19970. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19971. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19972. // this makes it easy compute correct values for closed geometries
  19973. generateUVs(); // finally create faces
  19974. generateIndices();
  19975. }
  19976. function generateSegment(i) {
  19977. // we use getPointAt to sample evenly distributed points from the given path
  19978. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19979. var N = frames.normals[i];
  19980. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19981. for (var j = 0; j <= radialSegments; j++) {
  19982. var v = j / radialSegments * Math.PI * 2;
  19983. var sin = Math.sin(v);
  19984. var cos = -Math.cos(v); // normal
  19985. normal.x = cos * N.x + sin * B.x;
  19986. normal.y = cos * N.y + sin * B.y;
  19987. normal.z = cos * N.z + sin * B.z;
  19988. normal.normalize();
  19989. normals.push(normal.x, normal.y, normal.z); // vertex
  19990. vertex.x = P.x + radius * normal.x;
  19991. vertex.y = P.y + radius * normal.y;
  19992. vertex.z = P.z + radius * normal.z;
  19993. vertices.push(vertex.x, vertex.y, vertex.z);
  19994. }
  19995. }
  19996. function generateIndices() {
  19997. for (var j = 1; j <= tubularSegments; j++) {
  19998. for (var i = 1; i <= radialSegments; i++) {
  19999. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  20000. var b = (radialSegments + 1) * j + (i - 1);
  20001. var c = (radialSegments + 1) * j + i;
  20002. var d = (radialSegments + 1) * (j - 1) + i; // faces
  20003. indices.push(a, b, d);
  20004. indices.push(b, c, d);
  20005. }
  20006. }
  20007. }
  20008. function generateUVs() {
  20009. for (var i = 0; i <= tubularSegments; i++) {
  20010. for (var j = 0; j <= radialSegments; j++) {
  20011. uv.x = i / tubularSegments;
  20012. uv.y = j / radialSegments;
  20013. uvs.push(uv.x, uv.y);
  20014. }
  20015. }
  20016. }
  20017. return _this;
  20018. }
  20019. var _proto = TubeBufferGeometry.prototype;
  20020. _proto.toJSON = function toJSON() {
  20021. var data = BufferGeometry.prototype.toJSON.call(this);
  20022. data.path = this.parameters.path.toJSON();
  20023. return data;
  20024. };
  20025. return TubeBufferGeometry;
  20026. }(BufferGeometry);
  20027. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  20028. _inheritsLoose(TubeGeometry, _Geometry);
  20029. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  20030. var _this;
  20031. _this = _Geometry.call(this) || this;
  20032. _this.type = 'TubeGeometry';
  20033. _this.parameters = {
  20034. path: path,
  20035. tubularSegments: tubularSegments,
  20036. radius: radius,
  20037. radialSegments: radialSegments,
  20038. closed: closed
  20039. };
  20040. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  20041. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  20042. _this.tangents = bufferGeometry.tangents;
  20043. _this.normals = bufferGeometry.normals;
  20044. _this.binormals = bufferGeometry.binormals; // create geometry
  20045. _this.fromBufferGeometry(bufferGeometry);
  20046. _this.mergeVertices();
  20047. return _this;
  20048. }
  20049. return TubeGeometry;
  20050. }(Geometry);
  20051. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  20052. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  20053. function WireframeGeometry(geometry) {
  20054. var _this;
  20055. _this = _BufferGeometry.call(this) || this;
  20056. _this.type = 'WireframeGeometry'; // buffer
  20057. var vertices = []; // helper variables
  20058. var edge = [0, 0],
  20059. edges = {};
  20060. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  20061. if (geometry && geometry.isGeometry) {
  20062. // create a data structure that contains all edges without duplicates
  20063. var faces = geometry.faces;
  20064. for (var i = 0, l = faces.length; i < l; i++) {
  20065. var face = faces[i];
  20066. for (var j = 0; j < 3; j++) {
  20067. var edge1 = face[keys[j]];
  20068. var edge2 = face[keys[(j + 1) % 3]];
  20069. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  20070. edge[1] = Math.max(edge1, edge2);
  20071. var key = edge[0] + ',' + edge[1];
  20072. if (edges[key] === undefined) {
  20073. edges[key] = {
  20074. index1: edge[0],
  20075. index2: edge[1]
  20076. };
  20077. }
  20078. }
  20079. } // generate vertices
  20080. for (var _key in edges) {
  20081. var e = edges[_key];
  20082. var vertex = geometry.vertices[e.index1];
  20083. vertices.push(vertex.x, vertex.y, vertex.z);
  20084. vertex = geometry.vertices[e.index2];
  20085. vertices.push(vertex.x, vertex.y, vertex.z);
  20086. }
  20087. } else if (geometry && geometry.isBufferGeometry) {
  20088. var _vertex = new Vector3();
  20089. if (geometry.index !== null) {
  20090. // indexed BufferGeometry
  20091. var position = geometry.attributes.position;
  20092. var indices = geometry.index;
  20093. var groups = geometry.groups;
  20094. if (groups.length === 0) {
  20095. groups = [{
  20096. start: 0,
  20097. count: indices.count,
  20098. materialIndex: 0
  20099. }];
  20100. } // create a data structure that contains all eges without duplicates
  20101. for (var o = 0, ol = groups.length; o < ol; ++o) {
  20102. var group = groups[o];
  20103. var start = group.start;
  20104. var count = group.count;
  20105. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  20106. for (var _j = 0; _j < 3; _j++) {
  20107. var _edge = indices.getX(_i + _j);
  20108. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  20109. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  20110. edge[1] = Math.max(_edge, _edge2);
  20111. var _key2 = edge[0] + ',' + edge[1];
  20112. if (edges[_key2] === undefined) {
  20113. edges[_key2] = {
  20114. index1: edge[0],
  20115. index2: edge[1]
  20116. };
  20117. }
  20118. }
  20119. }
  20120. } // generate vertices
  20121. for (var _key3 in edges) {
  20122. var _e = edges[_key3];
  20123. _vertex.fromBufferAttribute(position, _e.index1);
  20124. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20125. _vertex.fromBufferAttribute(position, _e.index2);
  20126. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20127. }
  20128. } else {
  20129. // non-indexed BufferGeometry
  20130. var _position = geometry.attributes.position;
  20131. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  20132. for (var _j2 = 0; _j2 < 3; _j2++) {
  20133. // three edges per triangle, an edge is represented as (index1, index2)
  20134. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  20135. var index1 = 3 * _i2 + _j2;
  20136. _vertex.fromBufferAttribute(_position, index1);
  20137. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20138. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  20139. _vertex.fromBufferAttribute(_position, index2);
  20140. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20141. }
  20142. }
  20143. }
  20144. } // build geometry
  20145. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  20146. return _this;
  20147. }
  20148. return WireframeGeometry;
  20149. }(BufferGeometry);
  20150. var Geometries = /*#__PURE__*/Object.freeze({
  20151. __proto__: null,
  20152. BoxGeometry: BoxGeometry,
  20153. BoxBufferGeometry: BoxBufferGeometry,
  20154. CircleGeometry: CircleGeometry,
  20155. CircleBufferGeometry: CircleBufferGeometry,
  20156. ConeGeometry: ConeGeometry,
  20157. ConeBufferGeometry: ConeBufferGeometry,
  20158. CylinderGeometry: CylinderGeometry,
  20159. CylinderBufferGeometry: CylinderBufferGeometry,
  20160. DodecahedronGeometry: DodecahedronGeometry,
  20161. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  20162. EdgesGeometry: EdgesGeometry,
  20163. ExtrudeGeometry: ExtrudeGeometry,
  20164. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  20165. IcosahedronGeometry: IcosahedronGeometry,
  20166. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  20167. LatheGeometry: LatheGeometry,
  20168. LatheBufferGeometry: LatheBufferGeometry,
  20169. OctahedronGeometry: OctahedronGeometry,
  20170. OctahedronBufferGeometry: OctahedronBufferGeometry,
  20171. ParametricGeometry: ParametricGeometry,
  20172. ParametricBufferGeometry: ParametricBufferGeometry,
  20173. PlaneGeometry: PlaneGeometry,
  20174. PlaneBufferGeometry: PlaneBufferGeometry,
  20175. PolyhedronGeometry: PolyhedronGeometry,
  20176. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  20177. RingGeometry: RingGeometry,
  20178. RingBufferGeometry: RingBufferGeometry,
  20179. ShapeGeometry: ShapeGeometry,
  20180. ShapeBufferGeometry: ShapeBufferGeometry,
  20181. SphereGeometry: SphereGeometry,
  20182. SphereBufferGeometry: SphereBufferGeometry,
  20183. TetrahedronGeometry: TetrahedronGeometry,
  20184. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  20185. TextGeometry: TextGeometry,
  20186. TextBufferGeometry: TextBufferGeometry,
  20187. TorusGeometry: TorusGeometry,
  20188. TorusBufferGeometry: TorusBufferGeometry,
  20189. TorusKnotGeometry: TorusKnotGeometry,
  20190. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  20191. TubeGeometry: TubeGeometry,
  20192. TubeBufferGeometry: TubeBufferGeometry,
  20193. WireframeGeometry: WireframeGeometry
  20194. });
  20195. /**
  20196. * parameters = {
  20197. * color: <THREE.Color>
  20198. * }
  20199. */
  20200. function ShadowMaterial(parameters) {
  20201. Material.call(this);
  20202. this.type = 'ShadowMaterial';
  20203. this.color = new Color(0x000000);
  20204. this.transparent = true;
  20205. this.setValues(parameters);
  20206. }
  20207. ShadowMaterial.prototype = Object.create(Material.prototype);
  20208. ShadowMaterial.prototype.constructor = ShadowMaterial;
  20209. ShadowMaterial.prototype.isShadowMaterial = true;
  20210. ShadowMaterial.prototype.copy = function (source) {
  20211. Material.prototype.copy.call(this, source);
  20212. this.color.copy(source.color);
  20213. return this;
  20214. };
  20215. function RawShaderMaterial(parameters) {
  20216. ShaderMaterial.call(this, parameters);
  20217. this.type = 'RawShaderMaterial';
  20218. }
  20219. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  20220. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  20221. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  20222. /**
  20223. * parameters = {
  20224. * color: <hex>,
  20225. * roughness: <float>,
  20226. * metalness: <float>,
  20227. * opacity: <float>,
  20228. *
  20229. * map: new THREE.Texture( <Image> ),
  20230. *
  20231. * lightMap: new THREE.Texture( <Image> ),
  20232. * lightMapIntensity: <float>
  20233. *
  20234. * aoMap: new THREE.Texture( <Image> ),
  20235. * aoMapIntensity: <float>
  20236. *
  20237. * emissive: <hex>,
  20238. * emissiveIntensity: <float>
  20239. * emissiveMap: new THREE.Texture( <Image> ),
  20240. *
  20241. * bumpMap: new THREE.Texture( <Image> ),
  20242. * bumpScale: <float>,
  20243. *
  20244. * normalMap: new THREE.Texture( <Image> ),
  20245. * normalMapType: THREE.TangentSpaceNormalMap,
  20246. * normalScale: <Vector2>,
  20247. *
  20248. * displacementMap: new THREE.Texture( <Image> ),
  20249. * displacementScale: <float>,
  20250. * displacementBias: <float>,
  20251. *
  20252. * roughnessMap: new THREE.Texture( <Image> ),
  20253. *
  20254. * metalnessMap: new THREE.Texture( <Image> ),
  20255. *
  20256. * alphaMap: new THREE.Texture( <Image> ),
  20257. *
  20258. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20259. * envMapIntensity: <float>
  20260. *
  20261. * refractionRatio: <float>,
  20262. *
  20263. * wireframe: <boolean>,
  20264. * wireframeLinewidth: <float>,
  20265. *
  20266. * skinning: <bool>,
  20267. * morphTargets: <bool>,
  20268. * morphNormals: <bool>
  20269. * }
  20270. */
  20271. function MeshStandardMaterial(parameters) {
  20272. Material.call(this);
  20273. this.defines = {
  20274. 'STANDARD': ''
  20275. };
  20276. this.type = 'MeshStandardMaterial';
  20277. this.color = new Color(0xffffff); // diffuse
  20278. this.roughness = 1.0;
  20279. this.metalness = 0.0;
  20280. this.map = null;
  20281. this.lightMap = null;
  20282. this.lightMapIntensity = 1.0;
  20283. this.aoMap = null;
  20284. this.aoMapIntensity = 1.0;
  20285. this.emissive = new Color(0x000000);
  20286. this.emissiveIntensity = 1.0;
  20287. this.emissiveMap = null;
  20288. this.bumpMap = null;
  20289. this.bumpScale = 1;
  20290. this.normalMap = null;
  20291. this.normalMapType = TangentSpaceNormalMap;
  20292. this.normalScale = new Vector2(1, 1);
  20293. this.displacementMap = null;
  20294. this.displacementScale = 1;
  20295. this.displacementBias = 0;
  20296. this.roughnessMap = null;
  20297. this.metalnessMap = null;
  20298. this.alphaMap = null;
  20299. this.envMap = null;
  20300. this.envMapIntensity = 1.0;
  20301. this.refractionRatio = 0.98;
  20302. this.wireframe = false;
  20303. this.wireframeLinewidth = 1;
  20304. this.wireframeLinecap = 'round';
  20305. this.wireframeLinejoin = 'round';
  20306. this.skinning = false;
  20307. this.morphTargets = false;
  20308. this.morphNormals = false;
  20309. this.vertexTangents = false;
  20310. this.setValues(parameters);
  20311. }
  20312. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  20313. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  20314. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  20315. MeshStandardMaterial.prototype.copy = function (source) {
  20316. Material.prototype.copy.call(this, source);
  20317. this.defines = {
  20318. 'STANDARD': ''
  20319. };
  20320. this.color.copy(source.color);
  20321. this.roughness = source.roughness;
  20322. this.metalness = source.metalness;
  20323. this.map = source.map;
  20324. this.lightMap = source.lightMap;
  20325. this.lightMapIntensity = source.lightMapIntensity;
  20326. this.aoMap = source.aoMap;
  20327. this.aoMapIntensity = source.aoMapIntensity;
  20328. this.emissive.copy(source.emissive);
  20329. this.emissiveMap = source.emissiveMap;
  20330. this.emissiveIntensity = source.emissiveIntensity;
  20331. this.bumpMap = source.bumpMap;
  20332. this.bumpScale = source.bumpScale;
  20333. this.normalMap = source.normalMap;
  20334. this.normalMapType = source.normalMapType;
  20335. this.normalScale.copy(source.normalScale);
  20336. this.displacementMap = source.displacementMap;
  20337. this.displacementScale = source.displacementScale;
  20338. this.displacementBias = source.displacementBias;
  20339. this.roughnessMap = source.roughnessMap;
  20340. this.metalnessMap = source.metalnessMap;
  20341. this.alphaMap = source.alphaMap;
  20342. this.envMap = source.envMap;
  20343. this.envMapIntensity = source.envMapIntensity;
  20344. this.refractionRatio = source.refractionRatio;
  20345. this.wireframe = source.wireframe;
  20346. this.wireframeLinewidth = source.wireframeLinewidth;
  20347. this.wireframeLinecap = source.wireframeLinecap;
  20348. this.wireframeLinejoin = source.wireframeLinejoin;
  20349. this.skinning = source.skinning;
  20350. this.morphTargets = source.morphTargets;
  20351. this.morphNormals = source.morphNormals;
  20352. this.vertexTangents = source.vertexTangents;
  20353. return this;
  20354. };
  20355. /**
  20356. * parameters = {
  20357. * clearcoat: <float>,
  20358. * clearcoatMap: new THREE.Texture( <Image> ),
  20359. * clearcoatRoughness: <float>,
  20360. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  20361. * clearcoatNormalScale: <Vector2>,
  20362. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  20363. *
  20364. * reflectivity: <float>,
  20365. * ior: <float>,
  20366. *
  20367. * sheen: <Color>,
  20368. *
  20369. * transmission: <float>,
  20370. * transmissionMap: new THREE.Texture( <Image> )
  20371. * }
  20372. */
  20373. function MeshPhysicalMaterial(parameters) {
  20374. MeshStandardMaterial.call(this);
  20375. this.defines = {
  20376. 'STANDARD': '',
  20377. 'PHYSICAL': ''
  20378. };
  20379. this.type = 'MeshPhysicalMaterial';
  20380. this.clearcoat = 0.0;
  20381. this.clearcoatMap = null;
  20382. this.clearcoatRoughness = 0.0;
  20383. this.clearcoatRoughnessMap = null;
  20384. this.clearcoatNormalScale = new Vector2(1, 1);
  20385. this.clearcoatNormalMap = null;
  20386. this.reflectivity = 0.5; // maps to F0 = 0.04
  20387. Object.defineProperty(this, 'ior', {
  20388. get: function get() {
  20389. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  20390. },
  20391. set: function set(ior) {
  20392. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  20393. }
  20394. });
  20395. this.sheen = null; // null will disable sheen bsdf
  20396. this.transmission = 0.0;
  20397. this.transmissionMap = null;
  20398. this.setValues(parameters);
  20399. }
  20400. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  20401. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20402. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20403. MeshPhysicalMaterial.prototype.copy = function (source) {
  20404. MeshStandardMaterial.prototype.copy.call(this, source);
  20405. this.defines = {
  20406. 'STANDARD': '',
  20407. 'PHYSICAL': ''
  20408. };
  20409. this.clearcoat = source.clearcoat;
  20410. this.clearcoatMap = source.clearcoatMap;
  20411. this.clearcoatRoughness = source.clearcoatRoughness;
  20412. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  20413. this.clearcoatNormalMap = source.clearcoatNormalMap;
  20414. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  20415. this.reflectivity = source.reflectivity;
  20416. if (source.sheen) {
  20417. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  20418. } else {
  20419. this.sheen = null;
  20420. }
  20421. this.transmission = source.transmission;
  20422. this.transmissionMap = source.transmissionMap;
  20423. return this;
  20424. };
  20425. /**
  20426. * parameters = {
  20427. * color: <hex>,
  20428. * specular: <hex>,
  20429. * shininess: <float>,
  20430. * opacity: <float>,
  20431. *
  20432. * map: new THREE.Texture( <Image> ),
  20433. *
  20434. * lightMap: new THREE.Texture( <Image> ),
  20435. * lightMapIntensity: <float>
  20436. *
  20437. * aoMap: new THREE.Texture( <Image> ),
  20438. * aoMapIntensity: <float>
  20439. *
  20440. * emissive: <hex>,
  20441. * emissiveIntensity: <float>
  20442. * emissiveMap: new THREE.Texture( <Image> ),
  20443. *
  20444. * bumpMap: new THREE.Texture( <Image> ),
  20445. * bumpScale: <float>,
  20446. *
  20447. * normalMap: new THREE.Texture( <Image> ),
  20448. * normalMapType: THREE.TangentSpaceNormalMap,
  20449. * normalScale: <Vector2>,
  20450. *
  20451. * displacementMap: new THREE.Texture( <Image> ),
  20452. * displacementScale: <float>,
  20453. * displacementBias: <float>,
  20454. *
  20455. * specularMap: new THREE.Texture( <Image> ),
  20456. *
  20457. * alphaMap: new THREE.Texture( <Image> ),
  20458. *
  20459. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20460. * combine: THREE.MultiplyOperation,
  20461. * reflectivity: <float>,
  20462. * refractionRatio: <float>,
  20463. *
  20464. * wireframe: <boolean>,
  20465. * wireframeLinewidth: <float>,
  20466. *
  20467. * skinning: <bool>,
  20468. * morphTargets: <bool>,
  20469. * morphNormals: <bool>
  20470. * }
  20471. */
  20472. function MeshPhongMaterial(parameters) {
  20473. Material.call(this);
  20474. this.type = 'MeshPhongMaterial';
  20475. this.color = new Color(0xffffff); // diffuse
  20476. this.specular = new Color(0x111111);
  20477. this.shininess = 30;
  20478. this.map = null;
  20479. this.lightMap = null;
  20480. this.lightMapIntensity = 1.0;
  20481. this.aoMap = null;
  20482. this.aoMapIntensity = 1.0;
  20483. this.emissive = new Color(0x000000);
  20484. this.emissiveIntensity = 1.0;
  20485. this.emissiveMap = null;
  20486. this.bumpMap = null;
  20487. this.bumpScale = 1;
  20488. this.normalMap = null;
  20489. this.normalMapType = TangentSpaceNormalMap;
  20490. this.normalScale = new Vector2(1, 1);
  20491. this.displacementMap = null;
  20492. this.displacementScale = 1;
  20493. this.displacementBias = 0;
  20494. this.specularMap = null;
  20495. this.alphaMap = null;
  20496. this.envMap = null;
  20497. this.combine = MultiplyOperation;
  20498. this.reflectivity = 1;
  20499. this.refractionRatio = 0.98;
  20500. this.wireframe = false;
  20501. this.wireframeLinewidth = 1;
  20502. this.wireframeLinecap = 'round';
  20503. this.wireframeLinejoin = 'round';
  20504. this.skinning = false;
  20505. this.morphTargets = false;
  20506. this.morphNormals = false;
  20507. this.setValues(parameters);
  20508. }
  20509. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  20510. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20511. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20512. MeshPhongMaterial.prototype.copy = function (source) {
  20513. Material.prototype.copy.call(this, source);
  20514. this.color.copy(source.color);
  20515. this.specular.copy(source.specular);
  20516. this.shininess = source.shininess;
  20517. this.map = source.map;
  20518. this.lightMap = source.lightMap;
  20519. this.lightMapIntensity = source.lightMapIntensity;
  20520. this.aoMap = source.aoMap;
  20521. this.aoMapIntensity = source.aoMapIntensity;
  20522. this.emissive.copy(source.emissive);
  20523. this.emissiveMap = source.emissiveMap;
  20524. this.emissiveIntensity = source.emissiveIntensity;
  20525. this.bumpMap = source.bumpMap;
  20526. this.bumpScale = source.bumpScale;
  20527. this.normalMap = source.normalMap;
  20528. this.normalMapType = source.normalMapType;
  20529. this.normalScale.copy(source.normalScale);
  20530. this.displacementMap = source.displacementMap;
  20531. this.displacementScale = source.displacementScale;
  20532. this.displacementBias = source.displacementBias;
  20533. this.specularMap = source.specularMap;
  20534. this.alphaMap = source.alphaMap;
  20535. this.envMap = source.envMap;
  20536. this.combine = source.combine;
  20537. this.reflectivity = source.reflectivity;
  20538. this.refractionRatio = source.refractionRatio;
  20539. this.wireframe = source.wireframe;
  20540. this.wireframeLinewidth = source.wireframeLinewidth;
  20541. this.wireframeLinecap = source.wireframeLinecap;
  20542. this.wireframeLinejoin = source.wireframeLinejoin;
  20543. this.skinning = source.skinning;
  20544. this.morphTargets = source.morphTargets;
  20545. this.morphNormals = source.morphNormals;
  20546. return this;
  20547. };
  20548. /**
  20549. * parameters = {
  20550. * color: <hex>,
  20551. *
  20552. * map: new THREE.Texture( <Image> ),
  20553. * gradientMap: new THREE.Texture( <Image> ),
  20554. *
  20555. * lightMap: new THREE.Texture( <Image> ),
  20556. * lightMapIntensity: <float>
  20557. *
  20558. * aoMap: new THREE.Texture( <Image> ),
  20559. * aoMapIntensity: <float>
  20560. *
  20561. * emissive: <hex>,
  20562. * emissiveIntensity: <float>
  20563. * emissiveMap: new THREE.Texture( <Image> ),
  20564. *
  20565. * bumpMap: new THREE.Texture( <Image> ),
  20566. * bumpScale: <float>,
  20567. *
  20568. * normalMap: new THREE.Texture( <Image> ),
  20569. * normalMapType: THREE.TangentSpaceNormalMap,
  20570. * normalScale: <Vector2>,
  20571. *
  20572. * displacementMap: new THREE.Texture( <Image> ),
  20573. * displacementScale: <float>,
  20574. * displacementBias: <float>,
  20575. *
  20576. * alphaMap: new THREE.Texture( <Image> ),
  20577. *
  20578. * wireframe: <boolean>,
  20579. * wireframeLinewidth: <float>,
  20580. *
  20581. * skinning: <bool>,
  20582. * morphTargets: <bool>,
  20583. * morphNormals: <bool>
  20584. * }
  20585. */
  20586. function MeshToonMaterial(parameters) {
  20587. Material.call(this);
  20588. this.defines = {
  20589. 'TOON': ''
  20590. };
  20591. this.type = 'MeshToonMaterial';
  20592. this.color = new Color(0xffffff);
  20593. this.map = null;
  20594. this.gradientMap = null;
  20595. this.lightMap = null;
  20596. this.lightMapIntensity = 1.0;
  20597. this.aoMap = null;
  20598. this.aoMapIntensity = 1.0;
  20599. this.emissive = new Color(0x000000);
  20600. this.emissiveIntensity = 1.0;
  20601. this.emissiveMap = null;
  20602. this.bumpMap = null;
  20603. this.bumpScale = 1;
  20604. this.normalMap = null;
  20605. this.normalMapType = TangentSpaceNormalMap;
  20606. this.normalScale = new Vector2(1, 1);
  20607. this.displacementMap = null;
  20608. this.displacementScale = 1;
  20609. this.displacementBias = 0;
  20610. this.alphaMap = null;
  20611. this.wireframe = false;
  20612. this.wireframeLinewidth = 1;
  20613. this.wireframeLinecap = 'round';
  20614. this.wireframeLinejoin = 'round';
  20615. this.skinning = false;
  20616. this.morphTargets = false;
  20617. this.morphNormals = false;
  20618. this.setValues(parameters);
  20619. }
  20620. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20621. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20622. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20623. MeshToonMaterial.prototype.copy = function (source) {
  20624. Material.prototype.copy.call(this, source);
  20625. this.color.copy(source.color);
  20626. this.map = source.map;
  20627. this.gradientMap = source.gradientMap;
  20628. this.lightMap = source.lightMap;
  20629. this.lightMapIntensity = source.lightMapIntensity;
  20630. this.aoMap = source.aoMap;
  20631. this.aoMapIntensity = source.aoMapIntensity;
  20632. this.emissive.copy(source.emissive);
  20633. this.emissiveMap = source.emissiveMap;
  20634. this.emissiveIntensity = source.emissiveIntensity;
  20635. this.bumpMap = source.bumpMap;
  20636. this.bumpScale = source.bumpScale;
  20637. this.normalMap = source.normalMap;
  20638. this.normalMapType = source.normalMapType;
  20639. this.normalScale.copy(source.normalScale);
  20640. this.displacementMap = source.displacementMap;
  20641. this.displacementScale = source.displacementScale;
  20642. this.displacementBias = source.displacementBias;
  20643. this.alphaMap = source.alphaMap;
  20644. this.wireframe = source.wireframe;
  20645. this.wireframeLinewidth = source.wireframeLinewidth;
  20646. this.wireframeLinecap = source.wireframeLinecap;
  20647. this.wireframeLinejoin = source.wireframeLinejoin;
  20648. this.skinning = source.skinning;
  20649. this.morphTargets = source.morphTargets;
  20650. this.morphNormals = source.morphNormals;
  20651. return this;
  20652. };
  20653. /**
  20654. * parameters = {
  20655. * opacity: <float>,
  20656. *
  20657. * bumpMap: new THREE.Texture( <Image> ),
  20658. * bumpScale: <float>,
  20659. *
  20660. * normalMap: new THREE.Texture( <Image> ),
  20661. * normalMapType: THREE.TangentSpaceNormalMap,
  20662. * normalScale: <Vector2>,
  20663. *
  20664. * displacementMap: new THREE.Texture( <Image> ),
  20665. * displacementScale: <float>,
  20666. * displacementBias: <float>,
  20667. *
  20668. * wireframe: <boolean>,
  20669. * wireframeLinewidth: <float>
  20670. *
  20671. * skinning: <bool>,
  20672. * morphTargets: <bool>,
  20673. * morphNormals: <bool>
  20674. * }
  20675. */
  20676. function MeshNormalMaterial(parameters) {
  20677. Material.call(this);
  20678. this.type = 'MeshNormalMaterial';
  20679. this.bumpMap = null;
  20680. this.bumpScale = 1;
  20681. this.normalMap = null;
  20682. this.normalMapType = TangentSpaceNormalMap;
  20683. this.normalScale = new Vector2(1, 1);
  20684. this.displacementMap = null;
  20685. this.displacementScale = 1;
  20686. this.displacementBias = 0;
  20687. this.wireframe = false;
  20688. this.wireframeLinewidth = 1;
  20689. this.fog = false;
  20690. this.skinning = false;
  20691. this.morphTargets = false;
  20692. this.morphNormals = false;
  20693. this.setValues(parameters);
  20694. }
  20695. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20696. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20697. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20698. MeshNormalMaterial.prototype.copy = function (source) {
  20699. Material.prototype.copy.call(this, source);
  20700. this.bumpMap = source.bumpMap;
  20701. this.bumpScale = source.bumpScale;
  20702. this.normalMap = source.normalMap;
  20703. this.normalMapType = source.normalMapType;
  20704. this.normalScale.copy(source.normalScale);
  20705. this.displacementMap = source.displacementMap;
  20706. this.displacementScale = source.displacementScale;
  20707. this.displacementBias = source.displacementBias;
  20708. this.wireframe = source.wireframe;
  20709. this.wireframeLinewidth = source.wireframeLinewidth;
  20710. this.skinning = source.skinning;
  20711. this.morphTargets = source.morphTargets;
  20712. this.morphNormals = source.morphNormals;
  20713. return this;
  20714. };
  20715. /**
  20716. * parameters = {
  20717. * color: <hex>,
  20718. * opacity: <float>,
  20719. *
  20720. * map: new THREE.Texture( <Image> ),
  20721. *
  20722. * lightMap: new THREE.Texture( <Image> ),
  20723. * lightMapIntensity: <float>
  20724. *
  20725. * aoMap: new THREE.Texture( <Image> ),
  20726. * aoMapIntensity: <float>
  20727. *
  20728. * emissive: <hex>,
  20729. * emissiveIntensity: <float>
  20730. * emissiveMap: new THREE.Texture( <Image> ),
  20731. *
  20732. * specularMap: new THREE.Texture( <Image> ),
  20733. *
  20734. * alphaMap: new THREE.Texture( <Image> ),
  20735. *
  20736. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20737. * combine: THREE.Multiply,
  20738. * reflectivity: <float>,
  20739. * refractionRatio: <float>,
  20740. *
  20741. * wireframe: <boolean>,
  20742. * wireframeLinewidth: <float>,
  20743. *
  20744. * skinning: <bool>,
  20745. * morphTargets: <bool>,
  20746. * morphNormals: <bool>
  20747. * }
  20748. */
  20749. function MeshLambertMaterial(parameters) {
  20750. Material.call(this);
  20751. this.type = 'MeshLambertMaterial';
  20752. this.color = new Color(0xffffff); // diffuse
  20753. this.map = null;
  20754. this.lightMap = null;
  20755. this.lightMapIntensity = 1.0;
  20756. this.aoMap = null;
  20757. this.aoMapIntensity = 1.0;
  20758. this.emissive = new Color(0x000000);
  20759. this.emissiveIntensity = 1.0;
  20760. this.emissiveMap = null;
  20761. this.specularMap = null;
  20762. this.alphaMap = null;
  20763. this.envMap = null;
  20764. this.combine = MultiplyOperation;
  20765. this.reflectivity = 1;
  20766. this.refractionRatio = 0.98;
  20767. this.wireframe = false;
  20768. this.wireframeLinewidth = 1;
  20769. this.wireframeLinecap = 'round';
  20770. this.wireframeLinejoin = 'round';
  20771. this.skinning = false;
  20772. this.morphTargets = false;
  20773. this.morphNormals = false;
  20774. this.setValues(parameters);
  20775. }
  20776. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20777. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20778. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20779. MeshLambertMaterial.prototype.copy = function (source) {
  20780. Material.prototype.copy.call(this, source);
  20781. this.color.copy(source.color);
  20782. this.map = source.map;
  20783. this.lightMap = source.lightMap;
  20784. this.lightMapIntensity = source.lightMapIntensity;
  20785. this.aoMap = source.aoMap;
  20786. this.aoMapIntensity = source.aoMapIntensity;
  20787. this.emissive.copy(source.emissive);
  20788. this.emissiveMap = source.emissiveMap;
  20789. this.emissiveIntensity = source.emissiveIntensity;
  20790. this.specularMap = source.specularMap;
  20791. this.alphaMap = source.alphaMap;
  20792. this.envMap = source.envMap;
  20793. this.combine = source.combine;
  20794. this.reflectivity = source.reflectivity;
  20795. this.refractionRatio = source.refractionRatio;
  20796. this.wireframe = source.wireframe;
  20797. this.wireframeLinewidth = source.wireframeLinewidth;
  20798. this.wireframeLinecap = source.wireframeLinecap;
  20799. this.wireframeLinejoin = source.wireframeLinejoin;
  20800. this.skinning = source.skinning;
  20801. this.morphTargets = source.morphTargets;
  20802. this.morphNormals = source.morphNormals;
  20803. return this;
  20804. };
  20805. /**
  20806. * parameters = {
  20807. * color: <hex>,
  20808. * opacity: <float>,
  20809. *
  20810. * matcap: new THREE.Texture( <Image> ),
  20811. *
  20812. * map: new THREE.Texture( <Image> ),
  20813. *
  20814. * bumpMap: new THREE.Texture( <Image> ),
  20815. * bumpScale: <float>,
  20816. *
  20817. * normalMap: new THREE.Texture( <Image> ),
  20818. * normalMapType: THREE.TangentSpaceNormalMap,
  20819. * normalScale: <Vector2>,
  20820. *
  20821. * displacementMap: new THREE.Texture( <Image> ),
  20822. * displacementScale: <float>,
  20823. * displacementBias: <float>,
  20824. *
  20825. * alphaMap: new THREE.Texture( <Image> ),
  20826. *
  20827. * skinning: <bool>,
  20828. * morphTargets: <bool>,
  20829. * morphNormals: <bool>
  20830. * }
  20831. */
  20832. function MeshMatcapMaterial(parameters) {
  20833. Material.call(this);
  20834. this.defines = {
  20835. 'MATCAP': ''
  20836. };
  20837. this.type = 'MeshMatcapMaterial';
  20838. this.color = new Color(0xffffff); // diffuse
  20839. this.matcap = null;
  20840. this.map = null;
  20841. this.bumpMap = null;
  20842. this.bumpScale = 1;
  20843. this.normalMap = null;
  20844. this.normalMapType = TangentSpaceNormalMap;
  20845. this.normalScale = new Vector2(1, 1);
  20846. this.displacementMap = null;
  20847. this.displacementScale = 1;
  20848. this.displacementBias = 0;
  20849. this.alphaMap = null;
  20850. this.skinning = false;
  20851. this.morphTargets = false;
  20852. this.morphNormals = false;
  20853. this.setValues(parameters);
  20854. }
  20855. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20856. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20857. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20858. MeshMatcapMaterial.prototype.copy = function (source) {
  20859. Material.prototype.copy.call(this, source);
  20860. this.defines = {
  20861. 'MATCAP': ''
  20862. };
  20863. this.color.copy(source.color);
  20864. this.matcap = source.matcap;
  20865. this.map = source.map;
  20866. this.bumpMap = source.bumpMap;
  20867. this.bumpScale = source.bumpScale;
  20868. this.normalMap = source.normalMap;
  20869. this.normalMapType = source.normalMapType;
  20870. this.normalScale.copy(source.normalScale);
  20871. this.displacementMap = source.displacementMap;
  20872. this.displacementScale = source.displacementScale;
  20873. this.displacementBias = source.displacementBias;
  20874. this.alphaMap = source.alphaMap;
  20875. this.skinning = source.skinning;
  20876. this.morphTargets = source.morphTargets;
  20877. this.morphNormals = source.morphNormals;
  20878. return this;
  20879. };
  20880. /**
  20881. * parameters = {
  20882. * color: <hex>,
  20883. * opacity: <float>,
  20884. *
  20885. * linewidth: <float>,
  20886. *
  20887. * scale: <float>,
  20888. * dashSize: <float>,
  20889. * gapSize: <float>
  20890. * }
  20891. */
  20892. function LineDashedMaterial(parameters) {
  20893. LineBasicMaterial.call(this);
  20894. this.type = 'LineDashedMaterial';
  20895. this.scale = 1;
  20896. this.dashSize = 3;
  20897. this.gapSize = 1;
  20898. this.setValues(parameters);
  20899. }
  20900. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20901. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20902. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20903. LineDashedMaterial.prototype.copy = function (source) {
  20904. LineBasicMaterial.prototype.copy.call(this, source);
  20905. this.scale = source.scale;
  20906. this.dashSize = source.dashSize;
  20907. this.gapSize = source.gapSize;
  20908. return this;
  20909. };
  20910. var Materials = /*#__PURE__*/Object.freeze({
  20911. __proto__: null,
  20912. ShadowMaterial: ShadowMaterial,
  20913. SpriteMaterial: SpriteMaterial,
  20914. RawShaderMaterial: RawShaderMaterial,
  20915. ShaderMaterial: ShaderMaterial,
  20916. PointsMaterial: PointsMaterial,
  20917. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20918. MeshStandardMaterial: MeshStandardMaterial,
  20919. MeshPhongMaterial: MeshPhongMaterial,
  20920. MeshToonMaterial: MeshToonMaterial,
  20921. MeshNormalMaterial: MeshNormalMaterial,
  20922. MeshLambertMaterial: MeshLambertMaterial,
  20923. MeshDepthMaterial: MeshDepthMaterial,
  20924. MeshDistanceMaterial: MeshDistanceMaterial,
  20925. MeshBasicMaterial: MeshBasicMaterial,
  20926. MeshMatcapMaterial: MeshMatcapMaterial,
  20927. LineDashedMaterial: LineDashedMaterial,
  20928. LineBasicMaterial: LineBasicMaterial,
  20929. Material: Material
  20930. });
  20931. var AnimationUtils = {
  20932. // same as Array.prototype.slice, but also works on typed arrays
  20933. arraySlice: function arraySlice(array, from, to) {
  20934. if (AnimationUtils.isTypedArray(array)) {
  20935. // in ios9 array.subarray(from, undefined) will return empty array
  20936. // but array.subarray(from) or array.subarray(from, len) is correct
  20937. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20938. }
  20939. return array.slice(from, to);
  20940. },
  20941. // converts an array to a specific type
  20942. convertArray: function convertArray(array, type, forceClone) {
  20943. if (!array || // let 'undefined' and 'null' pass
  20944. !forceClone && array.constructor === type) return array;
  20945. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20946. return new type(array); // create typed array
  20947. }
  20948. return Array.prototype.slice.call(array); // create Array
  20949. },
  20950. isTypedArray: function isTypedArray(object) {
  20951. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20952. },
  20953. // returns an array by which times and values can be sorted
  20954. getKeyframeOrder: function getKeyframeOrder(times) {
  20955. function compareTime(i, j) {
  20956. return times[i] - times[j];
  20957. }
  20958. var n = times.length;
  20959. var result = new Array(n);
  20960. for (var i = 0; i !== n; ++i) {
  20961. result[i] = i;
  20962. }
  20963. result.sort(compareTime);
  20964. return result;
  20965. },
  20966. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20967. sortedArray: function sortedArray(values, stride, order) {
  20968. var nValues = values.length;
  20969. var result = new values.constructor(nValues);
  20970. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20971. var srcOffset = order[i] * stride;
  20972. for (var j = 0; j !== stride; ++j) {
  20973. result[dstOffset++] = values[srcOffset + j];
  20974. }
  20975. }
  20976. return result;
  20977. },
  20978. // function for parsing AOS keyframe formats
  20979. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20980. var i = 1,
  20981. key = jsonKeys[0];
  20982. while (key !== undefined && key[valuePropertyName] === undefined) {
  20983. key = jsonKeys[i++];
  20984. }
  20985. if (key === undefined) return; // no data
  20986. var value = key[valuePropertyName];
  20987. if (value === undefined) return; // no data
  20988. if (Array.isArray(value)) {
  20989. do {
  20990. value = key[valuePropertyName];
  20991. if (value !== undefined) {
  20992. times.push(key.time);
  20993. values.push.apply(values, value); // push all elements
  20994. }
  20995. key = jsonKeys[i++];
  20996. } while (key !== undefined);
  20997. } else if (value.toArray !== undefined) {
  20998. // ...assume THREE.Math-ish
  20999. do {
  21000. value = key[valuePropertyName];
  21001. if (value !== undefined) {
  21002. times.push(key.time);
  21003. value.toArray(values, values.length);
  21004. }
  21005. key = jsonKeys[i++];
  21006. } while (key !== undefined);
  21007. } else {
  21008. // otherwise push as-is
  21009. do {
  21010. value = key[valuePropertyName];
  21011. if (value !== undefined) {
  21012. times.push(key.time);
  21013. values.push(value);
  21014. }
  21015. key = jsonKeys[i++];
  21016. } while (key !== undefined);
  21017. }
  21018. },
  21019. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  21020. if (fps === void 0) {
  21021. fps = 30;
  21022. }
  21023. var clip = sourceClip.clone();
  21024. clip.name = name;
  21025. var tracks = [];
  21026. for (var i = 0; i < clip.tracks.length; ++i) {
  21027. var track = clip.tracks[i];
  21028. var valueSize = track.getValueSize();
  21029. var times = [];
  21030. var values = [];
  21031. for (var j = 0; j < track.times.length; ++j) {
  21032. var frame = track.times[j] * fps;
  21033. if (frame < startFrame || frame >= endFrame) continue;
  21034. times.push(track.times[j]);
  21035. for (var k = 0; k < valueSize; ++k) {
  21036. values.push(track.values[j * valueSize + k]);
  21037. }
  21038. }
  21039. if (times.length === 0) continue;
  21040. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  21041. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  21042. tracks.push(track);
  21043. }
  21044. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  21045. var minStartTime = Infinity;
  21046. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  21047. if (minStartTime > clip.tracks[_i].times[0]) {
  21048. minStartTime = clip.tracks[_i].times[0];
  21049. }
  21050. } // shift all tracks such that clip begins at t=0
  21051. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  21052. clip.tracks[_i2].shift(-1 * minStartTime);
  21053. }
  21054. clip.resetDuration();
  21055. return clip;
  21056. },
  21057. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  21058. if (referenceFrame === void 0) {
  21059. referenceFrame = 0;
  21060. }
  21061. if (referenceClip === void 0) {
  21062. referenceClip = targetClip;
  21063. }
  21064. if (fps === void 0) {
  21065. fps = 30;
  21066. }
  21067. if (fps <= 0) fps = 30;
  21068. var numTracks = referenceClip.tracks.length;
  21069. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  21070. var _loop = function _loop(i) {
  21071. var referenceTrack = referenceClip.tracks[i];
  21072. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  21073. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  21074. var targetTrack = targetClip.tracks.find(function (track) {
  21075. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  21076. });
  21077. if (targetTrack === undefined) return "continue";
  21078. var referenceOffset = 0;
  21079. var referenceValueSize = referenceTrack.getValueSize();
  21080. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  21081. referenceOffset = referenceValueSize / 3;
  21082. }
  21083. var targetOffset = 0;
  21084. var targetValueSize = targetTrack.getValueSize();
  21085. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  21086. targetOffset = targetValueSize / 3;
  21087. }
  21088. var lastIndex = referenceTrack.times.length - 1;
  21089. var referenceValue = void 0; // Find the value to subtract out of the track
  21090. if (referenceTime <= referenceTrack.times[0]) {
  21091. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  21092. var startIndex = referenceOffset;
  21093. var endIndex = referenceValueSize - referenceOffset;
  21094. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  21095. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  21096. // Reference frame is after the last keyframe, so just use the last keyframe
  21097. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  21098. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  21099. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  21100. } else {
  21101. // Interpolate to the reference value
  21102. var interpolant = referenceTrack.createInterpolant();
  21103. var _startIndex2 = referenceOffset;
  21104. var _endIndex2 = referenceValueSize - referenceOffset;
  21105. interpolant.evaluate(referenceTime);
  21106. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  21107. } // Conjugate the quaternion
  21108. if (referenceTrackType === 'quaternion') {
  21109. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  21110. referenceQuat.toArray(referenceValue);
  21111. } // Subtract the reference value from all of the track values
  21112. var numTimes = targetTrack.times.length;
  21113. for (var j = 0; j < numTimes; ++j) {
  21114. var valueStart = j * targetValueSize + targetOffset;
  21115. if (referenceTrackType === 'quaternion') {
  21116. // Multiply the conjugate for quaternion track types
  21117. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  21118. } else {
  21119. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  21120. for (var k = 0; k < valueEnd; ++k) {
  21121. targetTrack.values[valueStart + k] -= referenceValue[k];
  21122. }
  21123. }
  21124. }
  21125. };
  21126. for (var i = 0; i < numTracks; ++i) {
  21127. var _ret = _loop(i);
  21128. if (_ret === "continue") continue;
  21129. }
  21130. targetClip.blendMode = AdditiveAnimationBlendMode;
  21131. return targetClip;
  21132. }
  21133. };
  21134. /**
  21135. * Abstract base class of interpolants over parametric samples.
  21136. *
  21137. * The parameter domain is one dimensional, typically the time or a path
  21138. * along a curve defined by the data.
  21139. *
  21140. * The sample values can have any dimensionality and derived classes may
  21141. * apply special interpretations to the data.
  21142. *
  21143. * This class provides the interval seek in a Template Method, deferring
  21144. * the actual interpolation to derived classes.
  21145. *
  21146. * Time complexity is O(1) for linear access crossing at most two points
  21147. * and O(log N) for random access, where N is the number of positions.
  21148. *
  21149. * References:
  21150. *
  21151. * http://www.oodesign.com/template-method-pattern.html
  21152. *
  21153. */
  21154. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21155. this.parameterPositions = parameterPositions;
  21156. this._cachedIndex = 0;
  21157. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  21158. this.sampleValues = sampleValues;
  21159. this.valueSize = sampleSize;
  21160. }
  21161. Object.assign(Interpolant.prototype, {
  21162. evaluate: function evaluate(t) {
  21163. var pp = this.parameterPositions;
  21164. var i1 = this._cachedIndex,
  21165. t1 = pp[i1],
  21166. t0 = pp[i1 - 1];
  21167. validate_interval: {
  21168. seek: {
  21169. var right;
  21170. linear_scan: {
  21171. //- See http://jsperf.com/comparison-to-undefined/3
  21172. //- slower code:
  21173. //-
  21174. //- if ( t >= t1 || t1 === undefined ) {
  21175. forward_scan: if (!(t < t1)) {
  21176. for (var giveUpAt = i1 + 2;;) {
  21177. if (t1 === undefined) {
  21178. if (t < t0) break forward_scan; // after end
  21179. i1 = pp.length;
  21180. this._cachedIndex = i1;
  21181. return this.afterEnd_(i1 - 1, t, t0);
  21182. }
  21183. if (i1 === giveUpAt) break; // this loop
  21184. t0 = t1;
  21185. t1 = pp[++i1];
  21186. if (t < t1) {
  21187. // we have arrived at the sought interval
  21188. break seek;
  21189. }
  21190. } // prepare binary search on the right side of the index
  21191. right = pp.length;
  21192. break linear_scan;
  21193. } //- slower code:
  21194. //- if ( t < t0 || t0 === undefined ) {
  21195. if (!(t >= t0)) {
  21196. // looping?
  21197. var t1global = pp[1];
  21198. if (t < t1global) {
  21199. i1 = 2; // + 1, using the scan for the details
  21200. t0 = t1global;
  21201. } // linear reverse scan
  21202. for (var _giveUpAt = i1 - 2;;) {
  21203. if (t0 === undefined) {
  21204. // before start
  21205. this._cachedIndex = 0;
  21206. return this.beforeStart_(0, t, t1);
  21207. }
  21208. if (i1 === _giveUpAt) break; // this loop
  21209. t1 = t0;
  21210. t0 = pp[--i1 - 1];
  21211. if (t >= t0) {
  21212. // we have arrived at the sought interval
  21213. break seek;
  21214. }
  21215. } // prepare binary search on the left side of the index
  21216. right = i1;
  21217. i1 = 0;
  21218. break linear_scan;
  21219. } // the interval is valid
  21220. break validate_interval;
  21221. } // linear scan
  21222. // binary search
  21223. while (i1 < right) {
  21224. var mid = i1 + right >>> 1;
  21225. if (t < pp[mid]) {
  21226. right = mid;
  21227. } else {
  21228. i1 = mid + 1;
  21229. }
  21230. }
  21231. t1 = pp[i1];
  21232. t0 = pp[i1 - 1]; // check boundary cases, again
  21233. if (t0 === undefined) {
  21234. this._cachedIndex = 0;
  21235. return this.beforeStart_(0, t, t1);
  21236. }
  21237. if (t1 === undefined) {
  21238. i1 = pp.length;
  21239. this._cachedIndex = i1;
  21240. return this.afterEnd_(i1 - 1, t0, t);
  21241. }
  21242. } // seek
  21243. this._cachedIndex = i1;
  21244. this.intervalChanged_(i1, t0, t1);
  21245. } // validate_interval
  21246. return this.interpolate_(i1, t0, t, t1);
  21247. },
  21248. settings: null,
  21249. // optional, subclass-specific settings structure
  21250. // Note: The indirection allows central control of many interpolants.
  21251. // --- Protected interface
  21252. DefaultSettings_: {},
  21253. getSettings_: function getSettings_() {
  21254. return this.settings || this.DefaultSettings_;
  21255. },
  21256. copySampleValue_: function copySampleValue_(index) {
  21257. // copies a sample value to the result buffer
  21258. var result = this.resultBuffer,
  21259. values = this.sampleValues,
  21260. stride = this.valueSize,
  21261. offset = index * stride;
  21262. for (var i = 0; i !== stride; ++i) {
  21263. result[i] = values[offset + i];
  21264. }
  21265. return result;
  21266. },
  21267. // Template methods for derived classes:
  21268. interpolate_: function interpolate_()
  21269. /* i1, t0, t, t1 */
  21270. {
  21271. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  21272. },
  21273. intervalChanged_: function intervalChanged_()
  21274. /* i1, t0, t1 */
  21275. {// empty
  21276. }
  21277. }); // DECLARE ALIAS AFTER assign prototype
  21278. Object.assign(Interpolant.prototype, {
  21279. //( 0, t, t0 ), returns this.resultBuffer
  21280. beforeStart_: Interpolant.prototype.copySampleValue_,
  21281. //( N-1, tN-1, t ), returns this.resultBuffer
  21282. afterEnd_: Interpolant.prototype.copySampleValue_
  21283. });
  21284. /**
  21285. * Fast and simple cubic spline interpolant.
  21286. *
  21287. * It was derived from a Hermitian construction setting the first derivative
  21288. * at each sample position to the linear slope between neighboring positions
  21289. * over their parameter interval.
  21290. */
  21291. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21292. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21293. this._weightPrev = -0;
  21294. this._offsetPrev = -0;
  21295. this._weightNext = -0;
  21296. this._offsetNext = -0;
  21297. }
  21298. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21299. constructor: CubicInterpolant,
  21300. DefaultSettings_: {
  21301. endingStart: ZeroCurvatureEnding,
  21302. endingEnd: ZeroCurvatureEnding
  21303. },
  21304. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  21305. var pp = this.parameterPositions;
  21306. var iPrev = i1 - 2,
  21307. iNext = i1 + 1,
  21308. tPrev = pp[iPrev],
  21309. tNext = pp[iNext];
  21310. if (tPrev === undefined) {
  21311. switch (this.getSettings_().endingStart) {
  21312. case ZeroSlopeEnding:
  21313. // f'(t0) = 0
  21314. iPrev = i1;
  21315. tPrev = 2 * t0 - t1;
  21316. break;
  21317. case WrapAroundEnding:
  21318. // use the other end of the curve
  21319. iPrev = pp.length - 2;
  21320. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  21321. break;
  21322. default:
  21323. // ZeroCurvatureEnding
  21324. // f''(t0) = 0 a.k.a. Natural Spline
  21325. iPrev = i1;
  21326. tPrev = t1;
  21327. }
  21328. }
  21329. if (tNext === undefined) {
  21330. switch (this.getSettings_().endingEnd) {
  21331. case ZeroSlopeEnding:
  21332. // f'(tN) = 0
  21333. iNext = i1;
  21334. tNext = 2 * t1 - t0;
  21335. break;
  21336. case WrapAroundEnding:
  21337. // use the other end of the curve
  21338. iNext = 1;
  21339. tNext = t1 + pp[1] - pp[0];
  21340. break;
  21341. default:
  21342. // ZeroCurvatureEnding
  21343. // f''(tN) = 0, a.k.a. Natural Spline
  21344. iNext = i1 - 1;
  21345. tNext = t0;
  21346. }
  21347. }
  21348. var halfDt = (t1 - t0) * 0.5,
  21349. stride = this.valueSize;
  21350. this._weightPrev = halfDt / (t0 - tPrev);
  21351. this._weightNext = halfDt / (tNext - t1);
  21352. this._offsetPrev = iPrev * stride;
  21353. this._offsetNext = iNext * stride;
  21354. },
  21355. interpolate_: function interpolate_(i1, t0, t, t1) {
  21356. var result = this.resultBuffer,
  21357. values = this.sampleValues,
  21358. stride = this.valueSize,
  21359. o1 = i1 * stride,
  21360. o0 = o1 - stride,
  21361. oP = this._offsetPrev,
  21362. oN = this._offsetNext,
  21363. wP = this._weightPrev,
  21364. wN = this._weightNext,
  21365. p = (t - t0) / (t1 - t0),
  21366. pp = p * p,
  21367. ppp = pp * p; // evaluate polynomials
  21368. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  21369. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  21370. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  21371. var sN = wN * ppp - wN * pp; // combine data linearly
  21372. for (var i = 0; i !== stride; ++i) {
  21373. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  21374. }
  21375. return result;
  21376. }
  21377. });
  21378. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21379. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21380. }
  21381. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21382. constructor: LinearInterpolant,
  21383. interpolate_: function interpolate_(i1, t0, t, t1) {
  21384. var result = this.resultBuffer,
  21385. values = this.sampleValues,
  21386. stride = this.valueSize,
  21387. offset1 = i1 * stride,
  21388. offset0 = offset1 - stride,
  21389. weight1 = (t - t0) / (t1 - t0),
  21390. weight0 = 1 - weight1;
  21391. for (var i = 0; i !== stride; ++i) {
  21392. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  21393. }
  21394. return result;
  21395. }
  21396. });
  21397. /**
  21398. *
  21399. * Interpolant that evaluates to the sample value at the position preceeding
  21400. * the parameter.
  21401. */
  21402. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21403. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21404. }
  21405. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21406. constructor: DiscreteInterpolant,
  21407. interpolate_: function interpolate_(i1
  21408. /*, t0, t, t1 */
  21409. ) {
  21410. return this.copySampleValue_(i1 - 1);
  21411. }
  21412. });
  21413. function KeyframeTrack(name, times, values, interpolation) {
  21414. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  21415. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  21416. this.name = name;
  21417. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  21418. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  21419. this.setInterpolation(interpolation || this.DefaultInterpolation);
  21420. } // Static methods
  21421. Object.assign(KeyframeTrack, {
  21422. // Serialization (in static context, because of constructor invocation
  21423. // and automatic invocation of .toJSON):
  21424. toJSON: function toJSON(track) {
  21425. var trackType = track.constructor;
  21426. var json; // derived classes can define a static toJSON method
  21427. if (trackType.toJSON !== undefined) {
  21428. json = trackType.toJSON(track);
  21429. } else {
  21430. // by default, we assume the data can be serialized as-is
  21431. json = {
  21432. 'name': track.name,
  21433. 'times': AnimationUtils.convertArray(track.times, Array),
  21434. 'values': AnimationUtils.convertArray(track.values, Array)
  21435. };
  21436. var interpolation = track.getInterpolation();
  21437. if (interpolation !== track.DefaultInterpolation) {
  21438. json.interpolation = interpolation;
  21439. }
  21440. }
  21441. json.type = track.ValueTypeName; // mandatory
  21442. return json;
  21443. }
  21444. });
  21445. Object.assign(KeyframeTrack.prototype, {
  21446. constructor: KeyframeTrack,
  21447. TimeBufferType: Float32Array,
  21448. ValueBufferType: Float32Array,
  21449. DefaultInterpolation: InterpolateLinear,
  21450. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  21451. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  21452. },
  21453. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21454. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21455. },
  21456. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  21457. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  21458. },
  21459. setInterpolation: function setInterpolation(interpolation) {
  21460. var factoryMethod;
  21461. switch (interpolation) {
  21462. case InterpolateDiscrete:
  21463. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21464. break;
  21465. case InterpolateLinear:
  21466. factoryMethod = this.InterpolantFactoryMethodLinear;
  21467. break;
  21468. case InterpolateSmooth:
  21469. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21470. break;
  21471. }
  21472. if (factoryMethod === undefined) {
  21473. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  21474. if (this.createInterpolant === undefined) {
  21475. // fall back to default, unless the default itself is messed up
  21476. if (interpolation !== this.DefaultInterpolation) {
  21477. this.setInterpolation(this.DefaultInterpolation);
  21478. } else {
  21479. throw new Error(message); // fatal, in this case
  21480. }
  21481. }
  21482. console.warn('THREE.KeyframeTrack:', message);
  21483. return this;
  21484. }
  21485. this.createInterpolant = factoryMethod;
  21486. return this;
  21487. },
  21488. getInterpolation: function getInterpolation() {
  21489. switch (this.createInterpolant) {
  21490. case this.InterpolantFactoryMethodDiscrete:
  21491. return InterpolateDiscrete;
  21492. case this.InterpolantFactoryMethodLinear:
  21493. return InterpolateLinear;
  21494. case this.InterpolantFactoryMethodSmooth:
  21495. return InterpolateSmooth;
  21496. }
  21497. },
  21498. getValueSize: function getValueSize() {
  21499. return this.values.length / this.times.length;
  21500. },
  21501. // move all keyframes either forwards or backwards in time
  21502. shift: function shift(timeOffset) {
  21503. if (timeOffset !== 0.0) {
  21504. var times = this.times;
  21505. for (var i = 0, n = times.length; i !== n; ++i) {
  21506. times[i] += timeOffset;
  21507. }
  21508. }
  21509. return this;
  21510. },
  21511. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21512. scale: function scale(timeScale) {
  21513. if (timeScale !== 1.0) {
  21514. var times = this.times;
  21515. for (var i = 0, n = times.length; i !== n; ++i) {
  21516. times[i] *= timeScale;
  21517. }
  21518. }
  21519. return this;
  21520. },
  21521. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21522. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21523. trim: function trim(startTime, endTime) {
  21524. var times = this.times,
  21525. nKeys = times.length;
  21526. var from = 0,
  21527. to = nKeys - 1;
  21528. while (from !== nKeys && times[from] < startTime) {
  21529. ++from;
  21530. }
  21531. while (to !== -1 && times[to] > endTime) {
  21532. --to;
  21533. }
  21534. ++to; // inclusive -> exclusive bound
  21535. if (from !== 0 || to !== nKeys) {
  21536. // empty tracks are forbidden, so keep at least one keyframe
  21537. if (from >= to) {
  21538. to = Math.max(to, 1);
  21539. from = to - 1;
  21540. }
  21541. var stride = this.getValueSize();
  21542. this.times = AnimationUtils.arraySlice(times, from, to);
  21543. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21544. }
  21545. return this;
  21546. },
  21547. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21548. validate: function validate() {
  21549. var valid = true;
  21550. var valueSize = this.getValueSize();
  21551. if (valueSize - Math.floor(valueSize) !== 0) {
  21552. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21553. valid = false;
  21554. }
  21555. var times = this.times,
  21556. values = this.values,
  21557. nKeys = times.length;
  21558. if (nKeys === 0) {
  21559. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21560. valid = false;
  21561. }
  21562. var prevTime = null;
  21563. for (var i = 0; i !== nKeys; i++) {
  21564. var currTime = times[i];
  21565. if (typeof currTime === 'number' && isNaN(currTime)) {
  21566. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21567. valid = false;
  21568. break;
  21569. }
  21570. if (prevTime !== null && prevTime > currTime) {
  21571. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21572. valid = false;
  21573. break;
  21574. }
  21575. prevTime = currTime;
  21576. }
  21577. if (values !== undefined) {
  21578. if (AnimationUtils.isTypedArray(values)) {
  21579. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21580. var value = values[_i];
  21581. if (isNaN(value)) {
  21582. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21583. valid = false;
  21584. break;
  21585. }
  21586. }
  21587. }
  21588. }
  21589. return valid;
  21590. },
  21591. // removes equivalent sequential keys as common in morph target sequences
  21592. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21593. optimize: function optimize() {
  21594. // times or values may be shared with other tracks, so overwriting is unsafe
  21595. var times = AnimationUtils.arraySlice(this.times),
  21596. values = AnimationUtils.arraySlice(this.values),
  21597. stride = this.getValueSize(),
  21598. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21599. lastIndex = times.length - 1;
  21600. var writeIndex = 1;
  21601. for (var i = 1; i < lastIndex; ++i) {
  21602. var keep = false;
  21603. var time = times[i];
  21604. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21605. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21606. if (!smoothInterpolation) {
  21607. // remove unnecessary keyframes same as their neighbors
  21608. var offset = i * stride,
  21609. offsetP = offset - stride,
  21610. offsetN = offset + stride;
  21611. for (var j = 0; j !== stride; ++j) {
  21612. var value = values[offset + j];
  21613. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21614. keep = true;
  21615. break;
  21616. }
  21617. }
  21618. } else {
  21619. keep = true;
  21620. }
  21621. } // in-place compaction
  21622. if (keep) {
  21623. if (i !== writeIndex) {
  21624. times[writeIndex] = times[i];
  21625. var readOffset = i * stride,
  21626. writeOffset = writeIndex * stride;
  21627. for (var _j = 0; _j !== stride; ++_j) {
  21628. values[writeOffset + _j] = values[readOffset + _j];
  21629. }
  21630. }
  21631. ++writeIndex;
  21632. }
  21633. } // flush last keyframe (compaction looks ahead)
  21634. if (lastIndex > 0) {
  21635. times[writeIndex] = times[lastIndex];
  21636. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21637. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21638. }
  21639. ++writeIndex;
  21640. }
  21641. if (writeIndex !== times.length) {
  21642. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21643. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21644. } else {
  21645. this.times = times;
  21646. this.values = values;
  21647. }
  21648. return this;
  21649. },
  21650. clone: function clone() {
  21651. var times = AnimationUtils.arraySlice(this.times, 0);
  21652. var values = AnimationUtils.arraySlice(this.values, 0);
  21653. var TypedKeyframeTrack = this.constructor;
  21654. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21655. track.createInterpolant = this.createInterpolant;
  21656. return track;
  21657. }
  21658. });
  21659. /**
  21660. * A Track of Boolean keyframe values.
  21661. */
  21662. function BooleanKeyframeTrack(name, times, values) {
  21663. KeyframeTrack.call(this, name, times, values);
  21664. }
  21665. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21666. constructor: BooleanKeyframeTrack,
  21667. ValueTypeName: 'bool',
  21668. ValueBufferType: Array,
  21669. DefaultInterpolation: InterpolateDiscrete,
  21670. InterpolantFactoryMethodLinear: undefined,
  21671. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21672. // representation of a single value and a custom interpolant that
  21673. // computes "firstValue ^ isOdd( index )".
  21674. });
  21675. /**
  21676. * A Track of keyframe values that represent color.
  21677. */
  21678. function ColorKeyframeTrack(name, times, values, interpolation) {
  21679. KeyframeTrack.call(this, name, times, values, interpolation);
  21680. }
  21681. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21682. constructor: ColorKeyframeTrack,
  21683. ValueTypeName: 'color' // ValueBufferType is inherited
  21684. // DefaultInterpolation is inherited
  21685. // Note: Very basic implementation and nothing special yet.
  21686. // However, this is the place for color space parameterization.
  21687. });
  21688. /**
  21689. * A Track of numeric keyframe values.
  21690. */
  21691. function NumberKeyframeTrack(name, times, values, interpolation) {
  21692. KeyframeTrack.call(this, name, times, values, interpolation);
  21693. }
  21694. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21695. constructor: NumberKeyframeTrack,
  21696. ValueTypeName: 'number' // ValueBufferType is inherited
  21697. // DefaultInterpolation is inherited
  21698. });
  21699. /**
  21700. * Spherical linear unit quaternion interpolant.
  21701. */
  21702. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21703. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21704. }
  21705. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21706. constructor: QuaternionLinearInterpolant,
  21707. interpolate_: function interpolate_(i1, t0, t, t1) {
  21708. var result = this.resultBuffer,
  21709. values = this.sampleValues,
  21710. stride = this.valueSize,
  21711. alpha = (t - t0) / (t1 - t0);
  21712. var offset = i1 * stride;
  21713. for (var end = offset + stride; offset !== end; offset += 4) {
  21714. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21715. }
  21716. return result;
  21717. }
  21718. });
  21719. /**
  21720. * A Track of quaternion keyframe values.
  21721. */
  21722. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21723. KeyframeTrack.call(this, name, times, values, interpolation);
  21724. }
  21725. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21726. constructor: QuaternionKeyframeTrack,
  21727. ValueTypeName: 'quaternion',
  21728. // ValueBufferType is inherited
  21729. DefaultInterpolation: InterpolateLinear,
  21730. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21731. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21732. },
  21733. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21734. });
  21735. /**
  21736. * A Track that interpolates Strings
  21737. */
  21738. function StringKeyframeTrack(name, times, values, interpolation) {
  21739. KeyframeTrack.call(this, name, times, values, interpolation);
  21740. }
  21741. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21742. constructor: StringKeyframeTrack,
  21743. ValueTypeName: 'string',
  21744. ValueBufferType: Array,
  21745. DefaultInterpolation: InterpolateDiscrete,
  21746. InterpolantFactoryMethodLinear: undefined,
  21747. InterpolantFactoryMethodSmooth: undefined
  21748. });
  21749. /**
  21750. * A Track of vectored keyframe values.
  21751. */
  21752. function VectorKeyframeTrack(name, times, values, interpolation) {
  21753. KeyframeTrack.call(this, name, times, values, interpolation);
  21754. }
  21755. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21756. constructor: VectorKeyframeTrack,
  21757. ValueTypeName: 'vector' // ValueBufferType is inherited
  21758. // DefaultInterpolation is inherited
  21759. });
  21760. function AnimationClip(name, duration, tracks, blendMode) {
  21761. if (duration === void 0) {
  21762. duration = -1;
  21763. }
  21764. if (blendMode === void 0) {
  21765. blendMode = NormalAnimationBlendMode;
  21766. }
  21767. this.name = name;
  21768. this.tracks = tracks;
  21769. this.duration = duration;
  21770. this.blendMode = blendMode;
  21771. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21772. if (this.duration < 0) {
  21773. this.resetDuration();
  21774. }
  21775. }
  21776. function getTrackTypeForValueTypeName(typeName) {
  21777. switch (typeName.toLowerCase()) {
  21778. case 'scalar':
  21779. case 'double':
  21780. case 'float':
  21781. case 'number':
  21782. case 'integer':
  21783. return NumberKeyframeTrack;
  21784. case 'vector':
  21785. case 'vector2':
  21786. case 'vector3':
  21787. case 'vector4':
  21788. return VectorKeyframeTrack;
  21789. case 'color':
  21790. return ColorKeyframeTrack;
  21791. case 'quaternion':
  21792. return QuaternionKeyframeTrack;
  21793. case 'bool':
  21794. case 'boolean':
  21795. return BooleanKeyframeTrack;
  21796. case 'string':
  21797. return StringKeyframeTrack;
  21798. }
  21799. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21800. }
  21801. function parseKeyframeTrack(json) {
  21802. if (json.type === undefined) {
  21803. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21804. }
  21805. var trackType = getTrackTypeForValueTypeName(json.type);
  21806. if (json.times === undefined) {
  21807. var times = [],
  21808. values = [];
  21809. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21810. json.times = times;
  21811. json.values = values;
  21812. } // derived classes can define a static parse method
  21813. if (trackType.parse !== undefined) {
  21814. return trackType.parse(json);
  21815. } else {
  21816. // by default, we assume a constructor compatible with the base
  21817. return new trackType(json.name, json.times, json.values, json.interpolation);
  21818. }
  21819. }
  21820. Object.assign(AnimationClip, {
  21821. parse: function parse(json) {
  21822. var tracks = [],
  21823. jsonTracks = json.tracks,
  21824. frameTime = 1.0 / (json.fps || 1.0);
  21825. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21826. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21827. }
  21828. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21829. clip.uuid = json.uuid;
  21830. return clip;
  21831. },
  21832. toJSON: function toJSON(clip) {
  21833. var tracks = [],
  21834. clipTracks = clip.tracks;
  21835. var json = {
  21836. 'name': clip.name,
  21837. 'duration': clip.duration,
  21838. 'tracks': tracks,
  21839. 'uuid': clip.uuid,
  21840. 'blendMode': clip.blendMode
  21841. };
  21842. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21843. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21844. }
  21845. return json;
  21846. },
  21847. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21848. var numMorphTargets = morphTargetSequence.length;
  21849. var tracks = [];
  21850. for (var i = 0; i < numMorphTargets; i++) {
  21851. var times = [];
  21852. var values = [];
  21853. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21854. values.push(0, 1, 0);
  21855. var order = AnimationUtils.getKeyframeOrder(times);
  21856. times = AnimationUtils.sortedArray(times, 1, order);
  21857. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21858. // last frame as well for perfect loop.
  21859. if (!noLoop && times[0] === 0) {
  21860. times.push(numMorphTargets);
  21861. values.push(values[0]);
  21862. }
  21863. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21864. }
  21865. return new AnimationClip(name, -1, tracks);
  21866. },
  21867. findByName: function findByName(objectOrClipArray, name) {
  21868. var clipArray = objectOrClipArray;
  21869. if (!Array.isArray(objectOrClipArray)) {
  21870. var o = objectOrClipArray;
  21871. clipArray = o.geometry && o.geometry.animations || o.animations;
  21872. }
  21873. for (var i = 0; i < clipArray.length; i++) {
  21874. if (clipArray[i].name === name) {
  21875. return clipArray[i];
  21876. }
  21877. }
  21878. return null;
  21879. },
  21880. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21881. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21882. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21883. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21884. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21885. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21886. var morphTarget = morphTargets[i];
  21887. var parts = morphTarget.name.match(pattern);
  21888. if (parts && parts.length > 1) {
  21889. var name = parts[1];
  21890. var animationMorphTargets = animationToMorphTargets[name];
  21891. if (!animationMorphTargets) {
  21892. animationToMorphTargets[name] = animationMorphTargets = [];
  21893. }
  21894. animationMorphTargets.push(morphTarget);
  21895. }
  21896. }
  21897. var clips = [];
  21898. for (var _name in animationToMorphTargets) {
  21899. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21900. }
  21901. return clips;
  21902. },
  21903. // parse the animation.hierarchy format
  21904. parseAnimation: function parseAnimation(animation, bones) {
  21905. if (!animation) {
  21906. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21907. return null;
  21908. }
  21909. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21910. // only return track if there are actually keys.
  21911. if (animationKeys.length !== 0) {
  21912. var times = [];
  21913. var values = [];
  21914. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21915. if (times.length !== 0) {
  21916. destTracks.push(new trackType(trackName, times, values));
  21917. }
  21918. }
  21919. };
  21920. var tracks = [];
  21921. var clipName = animation.name || 'default';
  21922. var fps = animation.fps || 30;
  21923. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21924. var duration = animation.length || -1;
  21925. var hierarchyTracks = animation.hierarchy || [];
  21926. for (var h = 0; h < hierarchyTracks.length; h++) {
  21927. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21928. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21929. if (animationKeys[0].morphTargets) {
  21930. // figure out all morph targets used in this track
  21931. var morphTargetNames = {};
  21932. var k = void 0;
  21933. for (k = 0; k < animationKeys.length; k++) {
  21934. if (animationKeys[k].morphTargets) {
  21935. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21936. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21937. }
  21938. }
  21939. } // create a track for each morph target with all zero
  21940. // morphTargetInfluences except for the keys in which
  21941. // the morphTarget is named.
  21942. for (var morphTargetName in morphTargetNames) {
  21943. var times = [];
  21944. var values = [];
  21945. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21946. var animationKey = animationKeys[k];
  21947. times.push(animationKey.time);
  21948. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21949. }
  21950. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21951. }
  21952. duration = morphTargetNames.length * (fps || 1.0);
  21953. } else {
  21954. // ...assume skeletal animation
  21955. var boneName = '.bones[' + bones[h].name + ']';
  21956. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21957. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21958. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21959. }
  21960. }
  21961. if (tracks.length === 0) {
  21962. return null;
  21963. }
  21964. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21965. return clip;
  21966. }
  21967. });
  21968. Object.assign(AnimationClip.prototype, {
  21969. resetDuration: function resetDuration() {
  21970. var tracks = this.tracks;
  21971. var duration = 0;
  21972. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21973. var track = this.tracks[i];
  21974. duration = Math.max(duration, track.times[track.times.length - 1]);
  21975. }
  21976. this.duration = duration;
  21977. return this;
  21978. },
  21979. trim: function trim() {
  21980. for (var i = 0; i < this.tracks.length; i++) {
  21981. this.tracks[i].trim(0, this.duration);
  21982. }
  21983. return this;
  21984. },
  21985. validate: function validate() {
  21986. var valid = true;
  21987. for (var i = 0; i < this.tracks.length; i++) {
  21988. valid = valid && this.tracks[i].validate();
  21989. }
  21990. return valid;
  21991. },
  21992. optimize: function optimize() {
  21993. for (var i = 0; i < this.tracks.length; i++) {
  21994. this.tracks[i].optimize();
  21995. }
  21996. return this;
  21997. },
  21998. clone: function clone() {
  21999. var tracks = [];
  22000. for (var i = 0; i < this.tracks.length; i++) {
  22001. tracks.push(this.tracks[i].clone());
  22002. }
  22003. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  22004. },
  22005. toJSON: function toJSON() {
  22006. return AnimationClip.toJSON(this);
  22007. }
  22008. });
  22009. var Cache = {
  22010. enabled: false,
  22011. files: {},
  22012. add: function add(key, file) {
  22013. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  22014. this.files[key] = file;
  22015. },
  22016. get: function get(key) {
  22017. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  22018. return this.files[key];
  22019. },
  22020. remove: function remove(key) {
  22021. delete this.files[key];
  22022. },
  22023. clear: function clear() {
  22024. this.files = {};
  22025. }
  22026. };
  22027. function LoadingManager(onLoad, onProgress, onError) {
  22028. var scope = this;
  22029. var isLoading = false;
  22030. var itemsLoaded = 0;
  22031. var itemsTotal = 0;
  22032. var urlModifier = undefined;
  22033. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  22034. // in the constructor
  22035. this.onStart = undefined;
  22036. this.onLoad = onLoad;
  22037. this.onProgress = onProgress;
  22038. this.onError = onError;
  22039. this.itemStart = function (url) {
  22040. itemsTotal++;
  22041. if (isLoading === false) {
  22042. if (scope.onStart !== undefined) {
  22043. scope.onStart(url, itemsLoaded, itemsTotal);
  22044. }
  22045. }
  22046. isLoading = true;
  22047. };
  22048. this.itemEnd = function (url) {
  22049. itemsLoaded++;
  22050. if (scope.onProgress !== undefined) {
  22051. scope.onProgress(url, itemsLoaded, itemsTotal);
  22052. }
  22053. if (itemsLoaded === itemsTotal) {
  22054. isLoading = false;
  22055. if (scope.onLoad !== undefined) {
  22056. scope.onLoad();
  22057. }
  22058. }
  22059. };
  22060. this.itemError = function (url) {
  22061. if (scope.onError !== undefined) {
  22062. scope.onError(url);
  22063. }
  22064. };
  22065. this.resolveURL = function (url) {
  22066. if (urlModifier) {
  22067. return urlModifier(url);
  22068. }
  22069. return url;
  22070. };
  22071. this.setURLModifier = function (transform) {
  22072. urlModifier = transform;
  22073. return this;
  22074. };
  22075. this.addHandler = function (regex, loader) {
  22076. handlers.push(regex, loader);
  22077. return this;
  22078. };
  22079. this.removeHandler = function (regex) {
  22080. var index = handlers.indexOf(regex);
  22081. if (index !== -1) {
  22082. handlers.splice(index, 2);
  22083. }
  22084. return this;
  22085. };
  22086. this.getHandler = function (file) {
  22087. for (var i = 0, l = handlers.length; i < l; i += 2) {
  22088. var regex = handlers[i];
  22089. var loader = handlers[i + 1];
  22090. if (regex.global) regex.lastIndex = 0; // see #17920
  22091. if (regex.test(file)) {
  22092. return loader;
  22093. }
  22094. }
  22095. return null;
  22096. };
  22097. }
  22098. var DefaultLoadingManager = new LoadingManager();
  22099. function Loader(manager) {
  22100. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  22101. this.crossOrigin = 'anonymous';
  22102. this.withCredentials = false;
  22103. this.path = '';
  22104. this.resourcePath = '';
  22105. this.requestHeader = {};
  22106. }
  22107. Object.assign(Loader.prototype, {
  22108. load: function load()
  22109. /* url, onLoad, onProgress, onError */
  22110. {},
  22111. loadAsync: function loadAsync(url, onProgress) {
  22112. var scope = this;
  22113. return new Promise(function (resolve, reject) {
  22114. scope.load(url, resolve, onProgress, reject);
  22115. });
  22116. },
  22117. parse: function parse()
  22118. /* data */
  22119. {},
  22120. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  22121. this.crossOrigin = crossOrigin;
  22122. return this;
  22123. },
  22124. setWithCredentials: function setWithCredentials(value) {
  22125. this.withCredentials = value;
  22126. return this;
  22127. },
  22128. setPath: function setPath(path) {
  22129. this.path = path;
  22130. return this;
  22131. },
  22132. setResourcePath: function setResourcePath(resourcePath) {
  22133. this.resourcePath = resourcePath;
  22134. return this;
  22135. },
  22136. setRequestHeader: function setRequestHeader(requestHeader) {
  22137. this.requestHeader = requestHeader;
  22138. return this;
  22139. }
  22140. });
  22141. var loading = {};
  22142. function FileLoader(manager) {
  22143. Loader.call(this, manager);
  22144. }
  22145. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22146. constructor: FileLoader,
  22147. load: function load(url, onLoad, onProgress, onError) {
  22148. if (url === undefined) url = '';
  22149. if (this.path !== undefined) url = this.path + url;
  22150. url = this.manager.resolveURL(url);
  22151. var scope = this;
  22152. var cached = Cache.get(url);
  22153. if (cached !== undefined) {
  22154. scope.manager.itemStart(url);
  22155. setTimeout(function () {
  22156. if (onLoad) onLoad(cached);
  22157. scope.manager.itemEnd(url);
  22158. }, 0);
  22159. return cached;
  22160. } // Check if request is duplicate
  22161. if (loading[url] !== undefined) {
  22162. loading[url].push({
  22163. onLoad: onLoad,
  22164. onProgress: onProgress,
  22165. onError: onError
  22166. });
  22167. return;
  22168. } // Check for data: URI
  22169. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  22170. var dataUriRegexResult = url.match(dataUriRegex);
  22171. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  22172. if (dataUriRegexResult) {
  22173. var mimeType = dataUriRegexResult[1];
  22174. var isBase64 = !!dataUriRegexResult[2];
  22175. var data = dataUriRegexResult[3];
  22176. data = decodeURIComponent(data);
  22177. if (isBase64) data = atob(data);
  22178. try {
  22179. var response;
  22180. var responseType = (this.responseType || '').toLowerCase();
  22181. switch (responseType) {
  22182. case 'arraybuffer':
  22183. case 'blob':
  22184. var view = new Uint8Array(data.length);
  22185. for (var i = 0; i < data.length; i++) {
  22186. view[i] = data.charCodeAt(i);
  22187. }
  22188. if (responseType === 'blob') {
  22189. response = new Blob([view.buffer], {
  22190. type: mimeType
  22191. });
  22192. } else {
  22193. response = view.buffer;
  22194. }
  22195. break;
  22196. case 'document':
  22197. var parser = new DOMParser();
  22198. response = parser.parseFromString(data, mimeType);
  22199. break;
  22200. case 'json':
  22201. response = JSON.parse(data);
  22202. break;
  22203. default:
  22204. // 'text' or other
  22205. response = data;
  22206. break;
  22207. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22208. setTimeout(function () {
  22209. if (onLoad) onLoad(response);
  22210. scope.manager.itemEnd(url);
  22211. }, 0);
  22212. } catch (error) {
  22213. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22214. setTimeout(function () {
  22215. if (onError) onError(error);
  22216. scope.manager.itemError(url);
  22217. scope.manager.itemEnd(url);
  22218. }, 0);
  22219. }
  22220. } else {
  22221. // Initialise array for duplicate requests
  22222. loading[url] = [];
  22223. loading[url].push({
  22224. onLoad: onLoad,
  22225. onProgress: onProgress,
  22226. onError: onError
  22227. });
  22228. request = new XMLHttpRequest();
  22229. request.open('GET', url, true);
  22230. request.addEventListener('load', function (event) {
  22231. var response = this.response;
  22232. var callbacks = loading[url];
  22233. delete loading[url];
  22234. if (this.status === 200 || this.status === 0) {
  22235. // Some browsers return HTTP Status 0 when using non-http protocol
  22236. // e.g. 'file://' or 'data://'. Handle as success.
  22237. 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
  22238. // error response bodies as proper responses to requests.
  22239. Cache.add(url, response);
  22240. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  22241. var callback = callbacks[_i];
  22242. if (callback.onLoad) callback.onLoad(response);
  22243. }
  22244. scope.manager.itemEnd(url);
  22245. } else {
  22246. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  22247. var _callback = callbacks[_i2];
  22248. if (_callback.onError) _callback.onError(event);
  22249. }
  22250. scope.manager.itemError(url);
  22251. scope.manager.itemEnd(url);
  22252. }
  22253. }, false);
  22254. request.addEventListener('progress', function (event) {
  22255. var callbacks = loading[url];
  22256. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  22257. var callback = callbacks[_i3];
  22258. if (callback.onProgress) callback.onProgress(event);
  22259. }
  22260. }, false);
  22261. request.addEventListener('error', function (event) {
  22262. var callbacks = loading[url];
  22263. delete loading[url];
  22264. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  22265. var callback = callbacks[_i4];
  22266. if (callback.onError) callback.onError(event);
  22267. }
  22268. scope.manager.itemError(url);
  22269. scope.manager.itemEnd(url);
  22270. }, false);
  22271. request.addEventListener('abort', function (event) {
  22272. var callbacks = loading[url];
  22273. delete loading[url];
  22274. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  22275. var callback = callbacks[_i5];
  22276. if (callback.onError) callback.onError(event);
  22277. }
  22278. scope.manager.itemError(url);
  22279. scope.manager.itemEnd(url);
  22280. }, false);
  22281. if (this.responseType !== undefined) request.responseType = this.responseType;
  22282. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  22283. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  22284. for (var header in this.requestHeader) {
  22285. request.setRequestHeader(header, this.requestHeader[header]);
  22286. }
  22287. request.send(null);
  22288. }
  22289. scope.manager.itemStart(url);
  22290. return request;
  22291. },
  22292. setResponseType: function setResponseType(value) {
  22293. this.responseType = value;
  22294. return this;
  22295. },
  22296. setMimeType: function setMimeType(value) {
  22297. this.mimeType = value;
  22298. return this;
  22299. }
  22300. });
  22301. function AnimationLoader(manager) {
  22302. Loader.call(this, manager);
  22303. }
  22304. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22305. constructor: AnimationLoader,
  22306. load: function load(url, onLoad, onProgress, onError) {
  22307. var scope = this;
  22308. var loader = new FileLoader(scope.manager);
  22309. loader.setPath(scope.path);
  22310. loader.setRequestHeader(scope.requestHeader);
  22311. loader.setWithCredentials(scope.withCredentials);
  22312. loader.load(url, function (text) {
  22313. try {
  22314. onLoad(scope.parse(JSON.parse(text)));
  22315. } catch (e) {
  22316. if (onError) {
  22317. onError(e);
  22318. } else {
  22319. console.error(e);
  22320. }
  22321. scope.manager.itemError(url);
  22322. }
  22323. }, onProgress, onError);
  22324. },
  22325. parse: function parse(json) {
  22326. var animations = [];
  22327. for (var i = 0; i < json.length; i++) {
  22328. var clip = AnimationClip.parse(json[i]);
  22329. animations.push(clip);
  22330. }
  22331. return animations;
  22332. }
  22333. });
  22334. /**
  22335. * Abstract Base class to block based textures loader (dds, pvr, ...)
  22336. *
  22337. * Sub classes have to implement the parse() method which will be used in load().
  22338. */
  22339. function CompressedTextureLoader(manager) {
  22340. Loader.call(this, manager);
  22341. }
  22342. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22343. constructor: CompressedTextureLoader,
  22344. load: function load(url, onLoad, onProgress, onError) {
  22345. var scope = this;
  22346. var images = [];
  22347. var texture = new CompressedTexture();
  22348. var loader = new FileLoader(this.manager);
  22349. loader.setPath(this.path);
  22350. loader.setResponseType('arraybuffer');
  22351. loader.setRequestHeader(this.requestHeader);
  22352. loader.setWithCredentials(scope.withCredentials);
  22353. var loaded = 0;
  22354. function loadTexture(i) {
  22355. loader.load(url[i], function (buffer) {
  22356. var texDatas = scope.parse(buffer, true);
  22357. images[i] = {
  22358. width: texDatas.width,
  22359. height: texDatas.height,
  22360. format: texDatas.format,
  22361. mipmaps: texDatas.mipmaps
  22362. };
  22363. loaded += 1;
  22364. if (loaded === 6) {
  22365. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  22366. texture.image = images;
  22367. texture.format = texDatas.format;
  22368. texture.needsUpdate = true;
  22369. if (onLoad) onLoad(texture);
  22370. }
  22371. }, onProgress, onError);
  22372. }
  22373. if (Array.isArray(url)) {
  22374. for (var i = 0, il = url.length; i < il; ++i) {
  22375. loadTexture(i);
  22376. }
  22377. } else {
  22378. // compressed cubemap texture stored in a single DDS file
  22379. loader.load(url, function (buffer) {
  22380. var texDatas = scope.parse(buffer, true);
  22381. if (texDatas.isCubemap) {
  22382. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22383. for (var f = 0; f < faces; f++) {
  22384. images[f] = {
  22385. mipmaps: []
  22386. };
  22387. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  22388. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  22389. images[f].format = texDatas.format;
  22390. images[f].width = texDatas.width;
  22391. images[f].height = texDatas.height;
  22392. }
  22393. }
  22394. texture.image = images;
  22395. } else {
  22396. texture.image.width = texDatas.width;
  22397. texture.image.height = texDatas.height;
  22398. texture.mipmaps = texDatas.mipmaps;
  22399. }
  22400. if (texDatas.mipmapCount === 1) {
  22401. texture.minFilter = LinearFilter;
  22402. }
  22403. texture.format = texDatas.format;
  22404. texture.needsUpdate = true;
  22405. if (onLoad) onLoad(texture);
  22406. }, onProgress, onError);
  22407. }
  22408. return texture;
  22409. }
  22410. });
  22411. function ImageLoader(manager) {
  22412. Loader.call(this, manager);
  22413. }
  22414. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22415. constructor: ImageLoader,
  22416. load: function load(url, onLoad, onProgress, onError) {
  22417. if (this.path !== undefined) url = this.path + url;
  22418. url = this.manager.resolveURL(url);
  22419. var scope = this;
  22420. var cached = Cache.get(url);
  22421. if (cached !== undefined) {
  22422. scope.manager.itemStart(url);
  22423. setTimeout(function () {
  22424. if (onLoad) onLoad(cached);
  22425. scope.manager.itemEnd(url);
  22426. }, 0);
  22427. return cached;
  22428. }
  22429. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  22430. function onImageLoad() {
  22431. image.removeEventListener('load', onImageLoad, false);
  22432. image.removeEventListener('error', onImageError, false);
  22433. Cache.add(url, this);
  22434. if (onLoad) onLoad(this);
  22435. scope.manager.itemEnd(url);
  22436. }
  22437. function onImageError(event) {
  22438. image.removeEventListener('load', onImageLoad, false);
  22439. image.removeEventListener('error', onImageError, false);
  22440. if (onError) onError(event);
  22441. scope.manager.itemError(url);
  22442. scope.manager.itemEnd(url);
  22443. }
  22444. image.addEventListener('load', onImageLoad, false);
  22445. image.addEventListener('error', onImageError, false);
  22446. if (url.substr(0, 5) !== 'data:') {
  22447. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  22448. }
  22449. scope.manager.itemStart(url);
  22450. image.src = url;
  22451. return image;
  22452. }
  22453. });
  22454. function CubeTextureLoader(manager) {
  22455. Loader.call(this, manager);
  22456. }
  22457. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22458. constructor: CubeTextureLoader,
  22459. load: function load(urls, onLoad, onProgress, onError) {
  22460. var texture = new CubeTexture();
  22461. var loader = new ImageLoader(this.manager);
  22462. loader.setCrossOrigin(this.crossOrigin);
  22463. loader.setPath(this.path);
  22464. var loaded = 0;
  22465. function loadTexture(i) {
  22466. loader.load(urls[i], function (image) {
  22467. texture.images[i] = image;
  22468. loaded++;
  22469. if (loaded === 6) {
  22470. texture.needsUpdate = true;
  22471. if (onLoad) onLoad(texture);
  22472. }
  22473. }, undefined, onError);
  22474. }
  22475. for (var i = 0; i < urls.length; ++i) {
  22476. loadTexture(i);
  22477. }
  22478. return texture;
  22479. }
  22480. });
  22481. /**
  22482. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22483. *
  22484. * Sub classes have to implement the parse() method which will be used in load().
  22485. */
  22486. function DataTextureLoader(manager) {
  22487. Loader.call(this, manager);
  22488. }
  22489. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22490. constructor: DataTextureLoader,
  22491. load: function load(url, onLoad, onProgress, onError) {
  22492. var scope = this;
  22493. var texture = new DataTexture();
  22494. var loader = new FileLoader(this.manager);
  22495. loader.setResponseType('arraybuffer');
  22496. loader.setRequestHeader(this.requestHeader);
  22497. loader.setPath(this.path);
  22498. loader.setWithCredentials(scope.withCredentials);
  22499. loader.load(url, function (buffer) {
  22500. var texData = scope.parse(buffer);
  22501. if (!texData) return;
  22502. if (texData.image !== undefined) {
  22503. texture.image = texData.image;
  22504. } else if (texData.data !== undefined) {
  22505. texture.image.width = texData.width;
  22506. texture.image.height = texData.height;
  22507. texture.image.data = texData.data;
  22508. }
  22509. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22510. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22511. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22512. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22513. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22514. if (texData.format !== undefined) {
  22515. texture.format = texData.format;
  22516. }
  22517. if (texData.type !== undefined) {
  22518. texture.type = texData.type;
  22519. }
  22520. if (texData.mipmaps !== undefined) {
  22521. texture.mipmaps = texData.mipmaps;
  22522. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22523. }
  22524. if (texData.mipmapCount === 1) {
  22525. texture.minFilter = LinearFilter;
  22526. }
  22527. texture.needsUpdate = true;
  22528. if (onLoad) onLoad(texture, texData);
  22529. }, onProgress, onError);
  22530. return texture;
  22531. }
  22532. });
  22533. function TextureLoader(manager) {
  22534. Loader.call(this, manager);
  22535. }
  22536. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22537. constructor: TextureLoader,
  22538. load: function load(url, onLoad, onProgress, onError) {
  22539. var texture = new Texture();
  22540. var loader = new ImageLoader(this.manager);
  22541. loader.setCrossOrigin(this.crossOrigin);
  22542. loader.setPath(this.path);
  22543. loader.load(url, function (image) {
  22544. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22545. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22546. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22547. texture.needsUpdate = true;
  22548. if (onLoad !== undefined) {
  22549. onLoad(texture);
  22550. }
  22551. }, onProgress, onError);
  22552. return texture;
  22553. }
  22554. });
  22555. /**
  22556. * Extensible curve object.
  22557. *
  22558. * Some common of curve methods:
  22559. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22560. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22561. * .getPoints(), .getSpacedPoints()
  22562. * .getLength()
  22563. * .updateArcLengths()
  22564. *
  22565. * This following curves inherit from THREE.Curve:
  22566. *
  22567. * -- 2D curves --
  22568. * THREE.ArcCurve
  22569. * THREE.CubicBezierCurve
  22570. * THREE.EllipseCurve
  22571. * THREE.LineCurve
  22572. * THREE.QuadraticBezierCurve
  22573. * THREE.SplineCurve
  22574. *
  22575. * -- 3D curves --
  22576. * THREE.CatmullRomCurve3
  22577. * THREE.CubicBezierCurve3
  22578. * THREE.LineCurve3
  22579. * THREE.QuadraticBezierCurve3
  22580. *
  22581. * A series of curves can be represented as a THREE.CurvePath.
  22582. *
  22583. **/
  22584. function Curve() {
  22585. this.type = 'Curve';
  22586. this.arcLengthDivisions = 200;
  22587. }
  22588. Object.assign(Curve.prototype, {
  22589. // Virtual base class method to overwrite and implement in subclasses
  22590. // - t [0 .. 1]
  22591. getPoint: function getPoint()
  22592. /* t, optionalTarget */
  22593. {
  22594. console.warn('THREE.Curve: .getPoint() not implemented.');
  22595. return null;
  22596. },
  22597. // Get point at relative position in curve according to arc length
  22598. // - u [0 .. 1]
  22599. getPointAt: function getPointAt(u, optionalTarget) {
  22600. var t = this.getUtoTmapping(u);
  22601. return this.getPoint(t, optionalTarget);
  22602. },
  22603. // Get sequence of points using getPoint( t )
  22604. getPoints: function getPoints(divisions) {
  22605. if (divisions === void 0) {
  22606. divisions = 5;
  22607. }
  22608. var points = [];
  22609. for (var d = 0; d <= divisions; d++) {
  22610. points.push(this.getPoint(d / divisions));
  22611. }
  22612. return points;
  22613. },
  22614. // Get sequence of points using getPointAt( u )
  22615. getSpacedPoints: function getSpacedPoints(divisions) {
  22616. if (divisions === void 0) {
  22617. divisions = 5;
  22618. }
  22619. var points = [];
  22620. for (var d = 0; d <= divisions; d++) {
  22621. points.push(this.getPointAt(d / divisions));
  22622. }
  22623. return points;
  22624. },
  22625. // Get total curve arc length
  22626. getLength: function getLength() {
  22627. var lengths = this.getLengths();
  22628. return lengths[lengths.length - 1];
  22629. },
  22630. // Get list of cumulative segment lengths
  22631. getLengths: function getLengths(divisions) {
  22632. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22633. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22634. return this.cacheArcLengths;
  22635. }
  22636. this.needsUpdate = false;
  22637. var cache = [];
  22638. var current,
  22639. last = this.getPoint(0);
  22640. var sum = 0;
  22641. cache.push(0);
  22642. for (var p = 1; p <= divisions; p++) {
  22643. current = this.getPoint(p / divisions);
  22644. sum += current.distanceTo(last);
  22645. cache.push(sum);
  22646. last = current;
  22647. }
  22648. this.cacheArcLengths = cache;
  22649. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22650. },
  22651. updateArcLengths: function updateArcLengths() {
  22652. this.needsUpdate = true;
  22653. this.getLengths();
  22654. },
  22655. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22656. getUtoTmapping: function getUtoTmapping(u, distance) {
  22657. var arcLengths = this.getLengths();
  22658. var i = 0;
  22659. var il = arcLengths.length;
  22660. var targetArcLength; // The targeted u distance value to get
  22661. if (distance) {
  22662. targetArcLength = distance;
  22663. } else {
  22664. targetArcLength = u * arcLengths[il - 1];
  22665. } // binary search for the index with largest value smaller than target u distance
  22666. var low = 0,
  22667. high = il - 1,
  22668. comparison;
  22669. while (low <= high) {
  22670. 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
  22671. comparison = arcLengths[i] - targetArcLength;
  22672. if (comparison < 0) {
  22673. low = i + 1;
  22674. } else if (comparison > 0) {
  22675. high = i - 1;
  22676. } else {
  22677. high = i;
  22678. break; // DONE
  22679. }
  22680. }
  22681. i = high;
  22682. if (arcLengths[i] === targetArcLength) {
  22683. return i / (il - 1);
  22684. } // we could get finer grain at lengths, or use simple interpolation between two points
  22685. var lengthBefore = arcLengths[i];
  22686. var lengthAfter = arcLengths[i + 1];
  22687. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22688. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22689. var t = (i + segmentFraction) / (il - 1);
  22690. return t;
  22691. },
  22692. // Returns a unit vector tangent at t
  22693. // In case any sub curve does not implement its tangent derivation,
  22694. // 2 points a small delta apart will be used to find its gradient
  22695. // which seems to give a reasonable approximation
  22696. getTangent: function getTangent(t, optionalTarget) {
  22697. var delta = 0.0001;
  22698. var t1 = t - delta;
  22699. var t2 = t + delta; // Capping in case of danger
  22700. if (t1 < 0) t1 = 0;
  22701. if (t2 > 1) t2 = 1;
  22702. var pt1 = this.getPoint(t1);
  22703. var pt2 = this.getPoint(t2);
  22704. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22705. tangent.copy(pt2).sub(pt1).normalize();
  22706. return tangent;
  22707. },
  22708. getTangentAt: function getTangentAt(u, optionalTarget) {
  22709. var t = this.getUtoTmapping(u);
  22710. return this.getTangent(t, optionalTarget);
  22711. },
  22712. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22713. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22714. var normal = new Vector3();
  22715. var tangents = [];
  22716. var normals = [];
  22717. var binormals = [];
  22718. var vec = new Vector3();
  22719. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22720. for (var i = 0; i <= segments; i++) {
  22721. var u = i / segments;
  22722. tangents[i] = this.getTangentAt(u, new Vector3());
  22723. tangents[i].normalize();
  22724. } // select an initial normal vector perpendicular to the first tangent vector,
  22725. // and in the direction of the minimum tangent xyz component
  22726. normals[0] = new Vector3();
  22727. binormals[0] = new Vector3();
  22728. var min = Number.MAX_VALUE;
  22729. var tx = Math.abs(tangents[0].x);
  22730. var ty = Math.abs(tangents[0].y);
  22731. var tz = Math.abs(tangents[0].z);
  22732. if (tx <= min) {
  22733. min = tx;
  22734. normal.set(1, 0, 0);
  22735. }
  22736. if (ty <= min) {
  22737. min = ty;
  22738. normal.set(0, 1, 0);
  22739. }
  22740. if (tz <= min) {
  22741. normal.set(0, 0, 1);
  22742. }
  22743. vec.crossVectors(tangents[0], normal).normalize();
  22744. normals[0].crossVectors(tangents[0], vec);
  22745. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22746. for (var _i = 1; _i <= segments; _i++) {
  22747. normals[_i] = normals[_i - 1].clone();
  22748. binormals[_i] = binormals[_i - 1].clone();
  22749. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22750. if (vec.length() > Number.EPSILON) {
  22751. vec.normalize();
  22752. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22753. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22754. }
  22755. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22756. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22757. if (closed === true) {
  22758. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22759. _theta /= segments;
  22760. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22761. _theta = -_theta;
  22762. }
  22763. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22764. // twist a little...
  22765. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22766. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22767. }
  22768. }
  22769. return {
  22770. tangents: tangents,
  22771. normals: normals,
  22772. binormals: binormals
  22773. };
  22774. },
  22775. clone: function clone() {
  22776. return new this.constructor().copy(this);
  22777. },
  22778. copy: function copy(source) {
  22779. this.arcLengthDivisions = source.arcLengthDivisions;
  22780. return this;
  22781. },
  22782. toJSON: function toJSON() {
  22783. var data = {
  22784. metadata: {
  22785. version: 4.5,
  22786. type: 'Curve',
  22787. generator: 'Curve.toJSON'
  22788. }
  22789. };
  22790. data.arcLengthDivisions = this.arcLengthDivisions;
  22791. data.type = this.type;
  22792. return data;
  22793. },
  22794. fromJSON: function fromJSON(json) {
  22795. this.arcLengthDivisions = json.arcLengthDivisions;
  22796. return this;
  22797. }
  22798. });
  22799. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22800. Curve.call(this);
  22801. this.type = 'EllipseCurve';
  22802. this.aX = aX || 0;
  22803. this.aY = aY || 0;
  22804. this.xRadius = xRadius || 1;
  22805. this.yRadius = yRadius || 1;
  22806. this.aStartAngle = aStartAngle || 0;
  22807. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22808. this.aClockwise = aClockwise || false;
  22809. this.aRotation = aRotation || 0;
  22810. }
  22811. EllipseCurve.prototype = Object.create(Curve.prototype);
  22812. EllipseCurve.prototype.constructor = EllipseCurve;
  22813. EllipseCurve.prototype.isEllipseCurve = true;
  22814. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22815. var point = optionalTarget || new Vector2();
  22816. var twoPi = Math.PI * 2;
  22817. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22818. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22819. while (deltaAngle < 0) {
  22820. deltaAngle += twoPi;
  22821. }
  22822. while (deltaAngle > twoPi) {
  22823. deltaAngle -= twoPi;
  22824. }
  22825. if (deltaAngle < Number.EPSILON) {
  22826. if (samePoints) {
  22827. deltaAngle = 0;
  22828. } else {
  22829. deltaAngle = twoPi;
  22830. }
  22831. }
  22832. if (this.aClockwise === true && !samePoints) {
  22833. if (deltaAngle === twoPi) {
  22834. deltaAngle = -twoPi;
  22835. } else {
  22836. deltaAngle = deltaAngle - twoPi;
  22837. }
  22838. }
  22839. var angle = this.aStartAngle + t * deltaAngle;
  22840. var x = this.aX + this.xRadius * Math.cos(angle);
  22841. var y = this.aY + this.yRadius * Math.sin(angle);
  22842. if (this.aRotation !== 0) {
  22843. var cos = Math.cos(this.aRotation);
  22844. var sin = Math.sin(this.aRotation);
  22845. var tx = x - this.aX;
  22846. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22847. x = tx * cos - ty * sin + this.aX;
  22848. y = tx * sin + ty * cos + this.aY;
  22849. }
  22850. return point.set(x, y);
  22851. };
  22852. EllipseCurve.prototype.copy = function (source) {
  22853. Curve.prototype.copy.call(this, source);
  22854. this.aX = source.aX;
  22855. this.aY = source.aY;
  22856. this.xRadius = source.xRadius;
  22857. this.yRadius = source.yRadius;
  22858. this.aStartAngle = source.aStartAngle;
  22859. this.aEndAngle = source.aEndAngle;
  22860. this.aClockwise = source.aClockwise;
  22861. this.aRotation = source.aRotation;
  22862. return this;
  22863. };
  22864. EllipseCurve.prototype.toJSON = function () {
  22865. var data = Curve.prototype.toJSON.call(this);
  22866. data.aX = this.aX;
  22867. data.aY = this.aY;
  22868. data.xRadius = this.xRadius;
  22869. data.yRadius = this.yRadius;
  22870. data.aStartAngle = this.aStartAngle;
  22871. data.aEndAngle = this.aEndAngle;
  22872. data.aClockwise = this.aClockwise;
  22873. data.aRotation = this.aRotation;
  22874. return data;
  22875. };
  22876. EllipseCurve.prototype.fromJSON = function (json) {
  22877. Curve.prototype.fromJSON.call(this, json);
  22878. this.aX = json.aX;
  22879. this.aY = json.aY;
  22880. this.xRadius = json.xRadius;
  22881. this.yRadius = json.yRadius;
  22882. this.aStartAngle = json.aStartAngle;
  22883. this.aEndAngle = json.aEndAngle;
  22884. this.aClockwise = json.aClockwise;
  22885. this.aRotation = json.aRotation;
  22886. return this;
  22887. };
  22888. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22889. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22890. this.type = 'ArcCurve';
  22891. }
  22892. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22893. ArcCurve.prototype.constructor = ArcCurve;
  22894. ArcCurve.prototype.isArcCurve = true;
  22895. /**
  22896. * Centripetal CatmullRom Curve - which is useful for avoiding
  22897. * cusps and self-intersections in non-uniform catmull rom curves.
  22898. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22899. *
  22900. * curve.type accepts centripetal(default), chordal and catmullrom
  22901. * curve.tension is used for catmullrom which defaults to 0.5
  22902. */
  22903. /*
  22904. Based on an optimized c++ solution in
  22905. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22906. - http://ideone.com/NoEbVM
  22907. This CubicPoly class could be used for reusing some variables and calculations,
  22908. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22909. which can be placed in CurveUtils.
  22910. */
  22911. function CubicPoly() {
  22912. var c0 = 0,
  22913. c1 = 0,
  22914. c2 = 0,
  22915. c3 = 0;
  22916. /*
  22917. * Compute coefficients for a cubic polynomial
  22918. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22919. * such that
  22920. * p(0) = x0, p(1) = x1
  22921. * and
  22922. * p'(0) = t0, p'(1) = t1.
  22923. */
  22924. function init(x0, x1, t0, t1) {
  22925. c0 = x0;
  22926. c1 = t0;
  22927. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22928. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22929. }
  22930. return {
  22931. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22932. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22933. },
  22934. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22935. // compute tangents when parameterized in [t1,t2]
  22936. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22937. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22938. t1 *= dt1;
  22939. t2 *= dt1;
  22940. init(x1, x2, t1, t2);
  22941. },
  22942. calc: function calc(t) {
  22943. var t2 = t * t;
  22944. var t3 = t2 * t;
  22945. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22946. }
  22947. };
  22948. } //
  22949. var tmp = new Vector3();
  22950. var px = new CubicPoly(),
  22951. py = new CubicPoly(),
  22952. pz = new CubicPoly();
  22953. function CatmullRomCurve3(points, closed, curveType, tension) {
  22954. if (points === void 0) {
  22955. points = [];
  22956. }
  22957. if (closed === void 0) {
  22958. closed = false;
  22959. }
  22960. if (curveType === void 0) {
  22961. curveType = 'centripetal';
  22962. }
  22963. if (tension === void 0) {
  22964. tension = 0.5;
  22965. }
  22966. Curve.call(this);
  22967. this.type = 'CatmullRomCurve3';
  22968. this.points = points;
  22969. this.closed = closed;
  22970. this.curveType = curveType;
  22971. this.tension = tension;
  22972. }
  22973. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22974. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22975. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22976. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22977. if (optionalTarget === void 0) {
  22978. optionalTarget = new Vector3();
  22979. }
  22980. var point = optionalTarget;
  22981. var points = this.points;
  22982. var l = points.length;
  22983. var p = (l - (this.closed ? 0 : 1)) * t;
  22984. var intPoint = Math.floor(p);
  22985. var weight = p - intPoint;
  22986. if (this.closed) {
  22987. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22988. } else if (weight === 0 && intPoint === l - 1) {
  22989. intPoint = l - 2;
  22990. weight = 1;
  22991. }
  22992. var p0, p3; // 4 points (p1 & p2 defined below)
  22993. if (this.closed || intPoint > 0) {
  22994. p0 = points[(intPoint - 1) % l];
  22995. } else {
  22996. // extrapolate first point
  22997. tmp.subVectors(points[0], points[1]).add(points[0]);
  22998. p0 = tmp;
  22999. }
  23000. var p1 = points[intPoint % l];
  23001. var p2 = points[(intPoint + 1) % l];
  23002. if (this.closed || intPoint + 2 < l) {
  23003. p3 = points[(intPoint + 2) % l];
  23004. } else {
  23005. // extrapolate last point
  23006. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  23007. p3 = tmp;
  23008. }
  23009. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  23010. // init Centripetal / Chordal Catmull-Rom
  23011. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  23012. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  23013. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  23014. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  23015. if (dt1 < 1e-4) dt1 = 1.0;
  23016. if (dt0 < 1e-4) dt0 = dt1;
  23017. if (dt2 < 1e-4) dt2 = dt1;
  23018. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  23019. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  23020. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  23021. } else if (this.curveType === 'catmullrom') {
  23022. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  23023. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  23024. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  23025. }
  23026. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  23027. return point;
  23028. };
  23029. CatmullRomCurve3.prototype.copy = function (source) {
  23030. Curve.prototype.copy.call(this, source);
  23031. this.points = [];
  23032. for (var i = 0, l = source.points.length; i < l; i++) {
  23033. var point = source.points[i];
  23034. this.points.push(point.clone());
  23035. }
  23036. this.closed = source.closed;
  23037. this.curveType = source.curveType;
  23038. this.tension = source.tension;
  23039. return this;
  23040. };
  23041. CatmullRomCurve3.prototype.toJSON = function () {
  23042. var data = Curve.prototype.toJSON.call(this);
  23043. data.points = [];
  23044. for (var i = 0, l = this.points.length; i < l; i++) {
  23045. var point = this.points[i];
  23046. data.points.push(point.toArray());
  23047. }
  23048. data.closed = this.closed;
  23049. data.curveType = this.curveType;
  23050. data.tension = this.tension;
  23051. return data;
  23052. };
  23053. CatmullRomCurve3.prototype.fromJSON = function (json) {
  23054. Curve.prototype.fromJSON.call(this, json);
  23055. this.points = [];
  23056. for (var i = 0, l = json.points.length; i < l; i++) {
  23057. var point = json.points[i];
  23058. this.points.push(new Vector3().fromArray(point));
  23059. }
  23060. this.closed = json.closed;
  23061. this.curveType = json.curveType;
  23062. this.tension = json.tension;
  23063. return this;
  23064. };
  23065. /**
  23066. * Bezier Curves formulas obtained from
  23067. * http://en.wikipedia.org/wiki/Bézier_curve
  23068. */
  23069. function CatmullRom(t, p0, p1, p2, p3) {
  23070. var v0 = (p2 - p0) * 0.5;
  23071. var v1 = (p3 - p1) * 0.5;
  23072. var t2 = t * t;
  23073. var t3 = t * t2;
  23074. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  23075. } //
  23076. function QuadraticBezierP0(t, p) {
  23077. var k = 1 - t;
  23078. return k * k * p;
  23079. }
  23080. function QuadraticBezierP1(t, p) {
  23081. return 2 * (1 - t) * t * p;
  23082. }
  23083. function QuadraticBezierP2(t, p) {
  23084. return t * t * p;
  23085. }
  23086. function QuadraticBezier(t, p0, p1, p2) {
  23087. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  23088. } //
  23089. function CubicBezierP0(t, p) {
  23090. var k = 1 - t;
  23091. return k * k * k * p;
  23092. }
  23093. function CubicBezierP1(t, p) {
  23094. var k = 1 - t;
  23095. return 3 * k * k * t * p;
  23096. }
  23097. function CubicBezierP2(t, p) {
  23098. return 3 * (1 - t) * t * t * p;
  23099. }
  23100. function CubicBezierP3(t, p) {
  23101. return t * t * t * p;
  23102. }
  23103. function CubicBezier(t, p0, p1, p2, p3) {
  23104. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  23105. }
  23106. function CubicBezierCurve(v0, v1, v2, v3) {
  23107. if (v0 === void 0) {
  23108. v0 = new Vector2();
  23109. }
  23110. if (v1 === void 0) {
  23111. v1 = new Vector2();
  23112. }
  23113. if (v2 === void 0) {
  23114. v2 = new Vector2();
  23115. }
  23116. if (v3 === void 0) {
  23117. v3 = new Vector2();
  23118. }
  23119. Curve.call(this);
  23120. this.type = 'CubicBezierCurve';
  23121. this.v0 = v0;
  23122. this.v1 = v1;
  23123. this.v2 = v2;
  23124. this.v3 = v3;
  23125. }
  23126. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  23127. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  23128. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  23129. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  23130. if (optionalTarget === void 0) {
  23131. optionalTarget = new Vector2();
  23132. }
  23133. var point = optionalTarget;
  23134. var v0 = this.v0,
  23135. v1 = this.v1,
  23136. v2 = this.v2,
  23137. v3 = this.v3;
  23138. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  23139. return point;
  23140. };
  23141. CubicBezierCurve.prototype.copy = function (source) {
  23142. Curve.prototype.copy.call(this, source);
  23143. this.v0.copy(source.v0);
  23144. this.v1.copy(source.v1);
  23145. this.v2.copy(source.v2);
  23146. this.v3.copy(source.v3);
  23147. return this;
  23148. };
  23149. CubicBezierCurve.prototype.toJSON = function () {
  23150. var data = Curve.prototype.toJSON.call(this);
  23151. data.v0 = this.v0.toArray();
  23152. data.v1 = this.v1.toArray();
  23153. data.v2 = this.v2.toArray();
  23154. data.v3 = this.v3.toArray();
  23155. return data;
  23156. };
  23157. CubicBezierCurve.prototype.fromJSON = function (json) {
  23158. Curve.prototype.fromJSON.call(this, json);
  23159. this.v0.fromArray(json.v0);
  23160. this.v1.fromArray(json.v1);
  23161. this.v2.fromArray(json.v2);
  23162. this.v3.fromArray(json.v3);
  23163. return this;
  23164. };
  23165. function CubicBezierCurve3(v0, v1, v2, v3) {
  23166. if (v0 === void 0) {
  23167. v0 = new Vector3();
  23168. }
  23169. if (v1 === void 0) {
  23170. v1 = new Vector3();
  23171. }
  23172. if (v2 === void 0) {
  23173. v2 = new Vector3();
  23174. }
  23175. if (v3 === void 0) {
  23176. v3 = new Vector3();
  23177. }
  23178. Curve.call(this);
  23179. this.type = 'CubicBezierCurve3';
  23180. this.v0 = v0;
  23181. this.v1 = v1;
  23182. this.v2 = v2;
  23183. this.v3 = v3;
  23184. }
  23185. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  23186. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  23187. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  23188. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  23189. if (optionalTarget === void 0) {
  23190. optionalTarget = new Vector3();
  23191. }
  23192. var point = optionalTarget;
  23193. var v0 = this.v0,
  23194. v1 = this.v1,
  23195. v2 = this.v2,
  23196. v3 = this.v3;
  23197. 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));
  23198. return point;
  23199. };
  23200. CubicBezierCurve3.prototype.copy = function (source) {
  23201. Curve.prototype.copy.call(this, source);
  23202. this.v0.copy(source.v0);
  23203. this.v1.copy(source.v1);
  23204. this.v2.copy(source.v2);
  23205. this.v3.copy(source.v3);
  23206. return this;
  23207. };
  23208. CubicBezierCurve3.prototype.toJSON = function () {
  23209. var data = Curve.prototype.toJSON.call(this);
  23210. data.v0 = this.v0.toArray();
  23211. data.v1 = this.v1.toArray();
  23212. data.v2 = this.v2.toArray();
  23213. data.v3 = this.v3.toArray();
  23214. return data;
  23215. };
  23216. CubicBezierCurve3.prototype.fromJSON = function (json) {
  23217. Curve.prototype.fromJSON.call(this, json);
  23218. this.v0.fromArray(json.v0);
  23219. this.v1.fromArray(json.v1);
  23220. this.v2.fromArray(json.v2);
  23221. this.v3.fromArray(json.v3);
  23222. return this;
  23223. };
  23224. function LineCurve(v1, v2) {
  23225. if (v1 === void 0) {
  23226. v1 = new Vector2();
  23227. }
  23228. if (v2 === void 0) {
  23229. v2 = new Vector2();
  23230. }
  23231. Curve.call(this);
  23232. this.type = 'LineCurve';
  23233. this.v1 = v1;
  23234. this.v2 = v2;
  23235. }
  23236. LineCurve.prototype = Object.create(Curve.prototype);
  23237. LineCurve.prototype.constructor = LineCurve;
  23238. LineCurve.prototype.isLineCurve = true;
  23239. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  23240. if (optionalTarget === void 0) {
  23241. optionalTarget = new Vector2();
  23242. }
  23243. var point = optionalTarget;
  23244. if (t === 1) {
  23245. point.copy(this.v2);
  23246. } else {
  23247. point.copy(this.v2).sub(this.v1);
  23248. point.multiplyScalar(t).add(this.v1);
  23249. }
  23250. return point;
  23251. }; // Line curve is linear, so we can overwrite default getPointAt
  23252. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  23253. return this.getPoint(u, optionalTarget);
  23254. };
  23255. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  23256. var tangent = optionalTarget || new Vector2();
  23257. tangent.copy(this.v2).sub(this.v1).normalize();
  23258. return tangent;
  23259. };
  23260. LineCurve.prototype.copy = function (source) {
  23261. Curve.prototype.copy.call(this, source);
  23262. this.v1.copy(source.v1);
  23263. this.v2.copy(source.v2);
  23264. return this;
  23265. };
  23266. LineCurve.prototype.toJSON = function () {
  23267. var data = Curve.prototype.toJSON.call(this);
  23268. data.v1 = this.v1.toArray();
  23269. data.v2 = this.v2.toArray();
  23270. return data;
  23271. };
  23272. LineCurve.prototype.fromJSON = function (json) {
  23273. Curve.prototype.fromJSON.call(this, json);
  23274. this.v1.fromArray(json.v1);
  23275. this.v2.fromArray(json.v2);
  23276. return this;
  23277. };
  23278. function LineCurve3(v1, v2) {
  23279. if (v1 === void 0) {
  23280. v1 = new Vector3();
  23281. }
  23282. if (v2 === void 0) {
  23283. v2 = new Vector3();
  23284. }
  23285. Curve.call(this);
  23286. this.type = 'LineCurve3';
  23287. this.v1 = v1;
  23288. this.v2 = v2;
  23289. }
  23290. LineCurve3.prototype = Object.create(Curve.prototype);
  23291. LineCurve3.prototype.constructor = LineCurve3;
  23292. LineCurve3.prototype.isLineCurve3 = true;
  23293. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  23294. if (optionalTarget === void 0) {
  23295. optionalTarget = new Vector3();
  23296. }
  23297. var point = optionalTarget;
  23298. if (t === 1) {
  23299. point.copy(this.v2);
  23300. } else {
  23301. point.copy(this.v2).sub(this.v1);
  23302. point.multiplyScalar(t).add(this.v1);
  23303. }
  23304. return point;
  23305. }; // Line curve is linear, so we can overwrite default getPointAt
  23306. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  23307. return this.getPoint(u, optionalTarget);
  23308. };
  23309. LineCurve3.prototype.copy = function (source) {
  23310. Curve.prototype.copy.call(this, source);
  23311. this.v1.copy(source.v1);
  23312. this.v2.copy(source.v2);
  23313. return this;
  23314. };
  23315. LineCurve3.prototype.toJSON = function () {
  23316. var data = Curve.prototype.toJSON.call(this);
  23317. data.v1 = this.v1.toArray();
  23318. data.v2 = this.v2.toArray();
  23319. return data;
  23320. };
  23321. LineCurve3.prototype.fromJSON = function (json) {
  23322. Curve.prototype.fromJSON.call(this, json);
  23323. this.v1.fromArray(json.v1);
  23324. this.v2.fromArray(json.v2);
  23325. return this;
  23326. };
  23327. function QuadraticBezierCurve(v0, v1, v2) {
  23328. if (v0 === void 0) {
  23329. v0 = new Vector2();
  23330. }
  23331. if (v1 === void 0) {
  23332. v1 = new Vector2();
  23333. }
  23334. if (v2 === void 0) {
  23335. v2 = new Vector2();
  23336. }
  23337. Curve.call(this);
  23338. this.type = 'QuadraticBezierCurve';
  23339. this.v0 = v0;
  23340. this.v1 = v1;
  23341. this.v2 = v2;
  23342. }
  23343. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  23344. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  23345. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  23346. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  23347. if (optionalTarget === void 0) {
  23348. optionalTarget = new Vector2();
  23349. }
  23350. var point = optionalTarget;
  23351. var v0 = this.v0,
  23352. v1 = this.v1,
  23353. v2 = this.v2;
  23354. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  23355. return point;
  23356. };
  23357. QuadraticBezierCurve.prototype.copy = function (source) {
  23358. Curve.prototype.copy.call(this, source);
  23359. this.v0.copy(source.v0);
  23360. this.v1.copy(source.v1);
  23361. this.v2.copy(source.v2);
  23362. return this;
  23363. };
  23364. QuadraticBezierCurve.prototype.toJSON = function () {
  23365. var data = Curve.prototype.toJSON.call(this);
  23366. data.v0 = this.v0.toArray();
  23367. data.v1 = this.v1.toArray();
  23368. data.v2 = this.v2.toArray();
  23369. return data;
  23370. };
  23371. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  23372. Curve.prototype.fromJSON.call(this, json);
  23373. this.v0.fromArray(json.v0);
  23374. this.v1.fromArray(json.v1);
  23375. this.v2.fromArray(json.v2);
  23376. return this;
  23377. };
  23378. function QuadraticBezierCurve3(v0, v1, v2) {
  23379. if (v0 === void 0) {
  23380. v0 = new Vector3();
  23381. }
  23382. if (v1 === void 0) {
  23383. v1 = new Vector3();
  23384. }
  23385. if (v2 === void 0) {
  23386. v2 = new Vector3();
  23387. }
  23388. Curve.call(this);
  23389. this.type = 'QuadraticBezierCurve3';
  23390. this.v0 = v0;
  23391. this.v1 = v1;
  23392. this.v2 = v2;
  23393. }
  23394. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  23395. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  23396. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  23397. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  23398. if (optionalTarget === void 0) {
  23399. optionalTarget = new Vector3();
  23400. }
  23401. var point = optionalTarget;
  23402. var v0 = this.v0,
  23403. v1 = this.v1,
  23404. v2 = this.v2;
  23405. 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));
  23406. return point;
  23407. };
  23408. QuadraticBezierCurve3.prototype.copy = function (source) {
  23409. Curve.prototype.copy.call(this, source);
  23410. this.v0.copy(source.v0);
  23411. this.v1.copy(source.v1);
  23412. this.v2.copy(source.v2);
  23413. return this;
  23414. };
  23415. QuadraticBezierCurve3.prototype.toJSON = function () {
  23416. var data = Curve.prototype.toJSON.call(this);
  23417. data.v0 = this.v0.toArray();
  23418. data.v1 = this.v1.toArray();
  23419. data.v2 = this.v2.toArray();
  23420. return data;
  23421. };
  23422. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  23423. Curve.prototype.fromJSON.call(this, json);
  23424. this.v0.fromArray(json.v0);
  23425. this.v1.fromArray(json.v1);
  23426. this.v2.fromArray(json.v2);
  23427. return this;
  23428. };
  23429. function SplineCurve(points) {
  23430. if (points === void 0) {
  23431. points = [];
  23432. }
  23433. Curve.call(this);
  23434. this.type = 'SplineCurve';
  23435. this.points = points;
  23436. }
  23437. SplineCurve.prototype = Object.create(Curve.prototype);
  23438. SplineCurve.prototype.constructor = SplineCurve;
  23439. SplineCurve.prototype.isSplineCurve = true;
  23440. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  23441. if (optionalTarget === void 0) {
  23442. optionalTarget = new Vector2();
  23443. }
  23444. var point = optionalTarget;
  23445. var points = this.points;
  23446. var p = (points.length - 1) * t;
  23447. var intPoint = Math.floor(p);
  23448. var weight = p - intPoint;
  23449. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  23450. var p1 = points[intPoint];
  23451. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  23452. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  23453. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  23454. return point;
  23455. };
  23456. SplineCurve.prototype.copy = function (source) {
  23457. Curve.prototype.copy.call(this, source);
  23458. this.points = [];
  23459. for (var i = 0, l = source.points.length; i < l; i++) {
  23460. var point = source.points[i];
  23461. this.points.push(point.clone());
  23462. }
  23463. return this;
  23464. };
  23465. SplineCurve.prototype.toJSON = function () {
  23466. var data = Curve.prototype.toJSON.call(this);
  23467. data.points = [];
  23468. for (var i = 0, l = this.points.length; i < l; i++) {
  23469. var point = this.points[i];
  23470. data.points.push(point.toArray());
  23471. }
  23472. return data;
  23473. };
  23474. SplineCurve.prototype.fromJSON = function (json) {
  23475. Curve.prototype.fromJSON.call(this, json);
  23476. this.points = [];
  23477. for (var i = 0, l = json.points.length; i < l; i++) {
  23478. var point = json.points[i];
  23479. this.points.push(new Vector2().fromArray(point));
  23480. }
  23481. return this;
  23482. };
  23483. var Curves = /*#__PURE__*/Object.freeze({
  23484. __proto__: null,
  23485. ArcCurve: ArcCurve,
  23486. CatmullRomCurve3: CatmullRomCurve3,
  23487. CubicBezierCurve: CubicBezierCurve,
  23488. CubicBezierCurve3: CubicBezierCurve3,
  23489. EllipseCurve: EllipseCurve,
  23490. LineCurve: LineCurve,
  23491. LineCurve3: LineCurve3,
  23492. QuadraticBezierCurve: QuadraticBezierCurve,
  23493. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23494. SplineCurve: SplineCurve
  23495. });
  23496. /**************************************************************
  23497. * Curved Path - a curve path is simply a array of connected
  23498. * curves, but retains the api of a curve
  23499. **************************************************************/
  23500. function CurvePath() {
  23501. Curve.call(this);
  23502. this.type = 'CurvePath';
  23503. this.curves = [];
  23504. this.autoClose = false; // Automatically closes the path
  23505. }
  23506. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  23507. constructor: CurvePath,
  23508. add: function add(curve) {
  23509. this.curves.push(curve);
  23510. },
  23511. closePath: function closePath() {
  23512. // Add a line curve if start and end of lines are not connected
  23513. var startPoint = this.curves[0].getPoint(0);
  23514. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  23515. if (!startPoint.equals(endPoint)) {
  23516. this.curves.push(new LineCurve(endPoint, startPoint));
  23517. }
  23518. },
  23519. // To get accurate point with reference to
  23520. // entire path distance at time t,
  23521. // following has to be done:
  23522. // 1. Length of each sub path have to be known
  23523. // 2. Locate and identify type of curve
  23524. // 3. Get t for the curve
  23525. // 4. Return curve.getPointAt(t')
  23526. getPoint: function getPoint(t) {
  23527. var d = t * this.getLength();
  23528. var curveLengths = this.getCurveLengths();
  23529. var i = 0; // To think about boundaries points.
  23530. while (i < curveLengths.length) {
  23531. if (curveLengths[i] >= d) {
  23532. var diff = curveLengths[i] - d;
  23533. var curve = this.curves[i];
  23534. var segmentLength = curve.getLength();
  23535. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23536. return curve.getPointAt(u);
  23537. }
  23538. i++;
  23539. }
  23540. return null; // loop where sum != 0, sum > d , sum+1 <d
  23541. },
  23542. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23543. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23544. // getPoint() depends on getLength
  23545. getLength: function getLength() {
  23546. var lens = this.getCurveLengths();
  23547. return lens[lens.length - 1];
  23548. },
  23549. // cacheLengths must be recalculated.
  23550. updateArcLengths: function updateArcLengths() {
  23551. this.needsUpdate = true;
  23552. this.cacheLengths = null;
  23553. this.getCurveLengths();
  23554. },
  23555. // Compute lengths and cache them
  23556. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23557. getCurveLengths: function getCurveLengths() {
  23558. // We use cache values if curves and cache array are same length
  23559. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23560. return this.cacheLengths;
  23561. } // Get length of sub-curve
  23562. // Push sums into cached array
  23563. var lengths = [];
  23564. var sums = 0;
  23565. for (var i = 0, l = this.curves.length; i < l; i++) {
  23566. sums += this.curves[i].getLength();
  23567. lengths.push(sums);
  23568. }
  23569. this.cacheLengths = lengths;
  23570. return lengths;
  23571. },
  23572. getSpacedPoints: function getSpacedPoints(divisions) {
  23573. if (divisions === void 0) {
  23574. divisions = 40;
  23575. }
  23576. var points = [];
  23577. for (var i = 0; i <= divisions; i++) {
  23578. points.push(this.getPoint(i / divisions));
  23579. }
  23580. if (this.autoClose) {
  23581. points.push(points[0]);
  23582. }
  23583. return points;
  23584. },
  23585. getPoints: function getPoints(divisions) {
  23586. if (divisions === void 0) {
  23587. divisions = 12;
  23588. }
  23589. var points = [];
  23590. var last;
  23591. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23592. var curve = curves[i];
  23593. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23594. var pts = curve.getPoints(resolution);
  23595. for (var j = 0; j < pts.length; j++) {
  23596. var point = pts[j];
  23597. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23598. points.push(point);
  23599. last = point;
  23600. }
  23601. }
  23602. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23603. points.push(points[0]);
  23604. }
  23605. return points;
  23606. },
  23607. copy: function copy(source) {
  23608. Curve.prototype.copy.call(this, source);
  23609. this.curves = [];
  23610. for (var i = 0, l = source.curves.length; i < l; i++) {
  23611. var curve = source.curves[i];
  23612. this.curves.push(curve.clone());
  23613. }
  23614. this.autoClose = source.autoClose;
  23615. return this;
  23616. },
  23617. toJSON: function toJSON() {
  23618. var data = Curve.prototype.toJSON.call(this);
  23619. data.autoClose = this.autoClose;
  23620. data.curves = [];
  23621. for (var i = 0, l = this.curves.length; i < l; i++) {
  23622. var curve = this.curves[i];
  23623. data.curves.push(curve.toJSON());
  23624. }
  23625. return data;
  23626. },
  23627. fromJSON: function fromJSON(json) {
  23628. Curve.prototype.fromJSON.call(this, json);
  23629. this.autoClose = json.autoClose;
  23630. this.curves = [];
  23631. for (var i = 0, l = json.curves.length; i < l; i++) {
  23632. var curve = json.curves[i];
  23633. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23634. }
  23635. return this;
  23636. }
  23637. });
  23638. function Path(points) {
  23639. CurvePath.call(this);
  23640. this.type = 'Path';
  23641. this.currentPoint = new Vector2();
  23642. if (points) {
  23643. this.setFromPoints(points);
  23644. }
  23645. }
  23646. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  23647. constructor: Path,
  23648. setFromPoints: function setFromPoints(points) {
  23649. this.moveTo(points[0].x, points[0].y);
  23650. for (var i = 1, l = points.length; i < l; i++) {
  23651. this.lineTo(points[i].x, points[i].y);
  23652. }
  23653. return this;
  23654. },
  23655. moveTo: function moveTo(x, y) {
  23656. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23657. return this;
  23658. },
  23659. lineTo: function lineTo(x, y) {
  23660. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23661. this.curves.push(curve);
  23662. this.currentPoint.set(x, y);
  23663. return this;
  23664. },
  23665. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23666. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23667. this.curves.push(curve);
  23668. this.currentPoint.set(aX, aY);
  23669. return this;
  23670. },
  23671. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23672. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23673. this.curves.push(curve);
  23674. this.currentPoint.set(aX, aY);
  23675. return this;
  23676. },
  23677. splineThru: function splineThru(pts
  23678. /*Array of Vector*/
  23679. ) {
  23680. var npts = [this.currentPoint.clone()].concat(pts);
  23681. var curve = new SplineCurve(npts);
  23682. this.curves.push(curve);
  23683. this.currentPoint.copy(pts[pts.length - 1]);
  23684. return this;
  23685. },
  23686. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23687. var x0 = this.currentPoint.x;
  23688. var y0 = this.currentPoint.y;
  23689. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23690. return this;
  23691. },
  23692. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23693. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23694. return this;
  23695. },
  23696. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23697. var x0 = this.currentPoint.x;
  23698. var y0 = this.currentPoint.y;
  23699. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23700. return this;
  23701. },
  23702. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23703. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23704. if (this.curves.length > 0) {
  23705. // if a previous curve is present, attempt to join
  23706. var firstPoint = curve.getPoint(0);
  23707. if (!firstPoint.equals(this.currentPoint)) {
  23708. this.lineTo(firstPoint.x, firstPoint.y);
  23709. }
  23710. }
  23711. this.curves.push(curve);
  23712. var lastPoint = curve.getPoint(1);
  23713. this.currentPoint.copy(lastPoint);
  23714. return this;
  23715. },
  23716. copy: function copy(source) {
  23717. CurvePath.prototype.copy.call(this, source);
  23718. this.currentPoint.copy(source.currentPoint);
  23719. return this;
  23720. },
  23721. toJSON: function toJSON() {
  23722. var data = CurvePath.prototype.toJSON.call(this);
  23723. data.currentPoint = this.currentPoint.toArray();
  23724. return data;
  23725. },
  23726. fromJSON: function fromJSON(json) {
  23727. CurvePath.prototype.fromJSON.call(this, json);
  23728. this.currentPoint.fromArray(json.currentPoint);
  23729. return this;
  23730. }
  23731. });
  23732. function Shape(points) {
  23733. Path.call(this, points);
  23734. this.uuid = MathUtils.generateUUID();
  23735. this.type = 'Shape';
  23736. this.holes = [];
  23737. }
  23738. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23739. constructor: Shape,
  23740. getPointsHoles: function getPointsHoles(divisions) {
  23741. var holesPts = [];
  23742. for (var i = 0, l = this.holes.length; i < l; i++) {
  23743. holesPts[i] = this.holes[i].getPoints(divisions);
  23744. }
  23745. return holesPts;
  23746. },
  23747. // get points of shape and holes (keypoints based on segments parameter)
  23748. extractPoints: function extractPoints(divisions) {
  23749. return {
  23750. shape: this.getPoints(divisions),
  23751. holes: this.getPointsHoles(divisions)
  23752. };
  23753. },
  23754. copy: function copy(source) {
  23755. Path.prototype.copy.call(this, source);
  23756. this.holes = [];
  23757. for (var i = 0, l = source.holes.length; i < l; i++) {
  23758. var hole = source.holes[i];
  23759. this.holes.push(hole.clone());
  23760. }
  23761. return this;
  23762. },
  23763. toJSON: function toJSON() {
  23764. var data = Path.prototype.toJSON.call(this);
  23765. data.uuid = this.uuid;
  23766. data.holes = [];
  23767. for (var i = 0, l = this.holes.length; i < l; i++) {
  23768. var hole = this.holes[i];
  23769. data.holes.push(hole.toJSON());
  23770. }
  23771. return data;
  23772. },
  23773. fromJSON: function fromJSON(json) {
  23774. Path.prototype.fromJSON.call(this, json);
  23775. this.uuid = json.uuid;
  23776. this.holes = [];
  23777. for (var i = 0, l = json.holes.length; i < l; i++) {
  23778. var hole = json.holes[i];
  23779. this.holes.push(new Path().fromJSON(hole));
  23780. }
  23781. return this;
  23782. }
  23783. });
  23784. function Light(color, intensity) {
  23785. if (intensity === void 0) {
  23786. intensity = 1;
  23787. }
  23788. Object3D.call(this);
  23789. this.type = 'Light';
  23790. this.color = new Color(color);
  23791. this.intensity = intensity;
  23792. }
  23793. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23794. constructor: Light,
  23795. isLight: true,
  23796. copy: function copy(source) {
  23797. Object3D.prototype.copy.call(this, source);
  23798. this.color.copy(source.color);
  23799. this.intensity = source.intensity;
  23800. return this;
  23801. },
  23802. toJSON: function toJSON(meta) {
  23803. var data = Object3D.prototype.toJSON.call(this, meta);
  23804. data.object.color = this.color.getHex();
  23805. data.object.intensity = this.intensity;
  23806. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23807. if (this.distance !== undefined) data.object.distance = this.distance;
  23808. if (this.angle !== undefined) data.object.angle = this.angle;
  23809. if (this.decay !== undefined) data.object.decay = this.decay;
  23810. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23811. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23812. return data;
  23813. }
  23814. });
  23815. function HemisphereLight(skyColor, groundColor, intensity) {
  23816. Light.call(this, skyColor, intensity);
  23817. this.type = 'HemisphereLight';
  23818. this.position.copy(Object3D.DefaultUp);
  23819. this.updateMatrix();
  23820. this.groundColor = new Color(groundColor);
  23821. }
  23822. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23823. constructor: HemisphereLight,
  23824. isHemisphereLight: true,
  23825. copy: function copy(source) {
  23826. Light.prototype.copy.call(this, source);
  23827. this.groundColor.copy(source.groundColor);
  23828. return this;
  23829. }
  23830. });
  23831. function LightShadow(camera) {
  23832. this.camera = camera;
  23833. this.bias = 0;
  23834. this.normalBias = 0;
  23835. this.radius = 1;
  23836. this.mapSize = new Vector2(512, 512);
  23837. this.map = null;
  23838. this.mapPass = null;
  23839. this.matrix = new Matrix4();
  23840. this.autoUpdate = true;
  23841. this.needsUpdate = false;
  23842. this._frustum = new Frustum();
  23843. this._frameExtents = new Vector2(1, 1);
  23844. this._viewportCount = 1;
  23845. this._viewports = [new Vector4(0, 0, 1, 1)];
  23846. }
  23847. Object.assign(LightShadow.prototype, {
  23848. _projScreenMatrix: new Matrix4(),
  23849. _lightPositionWorld: new Vector3(),
  23850. _lookTarget: new Vector3(),
  23851. getViewportCount: function getViewportCount() {
  23852. return this._viewportCount;
  23853. },
  23854. getFrustum: function getFrustum() {
  23855. return this._frustum;
  23856. },
  23857. updateMatrices: function updateMatrices(light) {
  23858. var shadowCamera = this.camera,
  23859. shadowMatrix = this.matrix,
  23860. projScreenMatrix = this._projScreenMatrix,
  23861. lookTarget = this._lookTarget,
  23862. lightPositionWorld = this._lightPositionWorld;
  23863. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23864. shadowCamera.position.copy(lightPositionWorld);
  23865. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23866. shadowCamera.lookAt(lookTarget);
  23867. shadowCamera.updateMatrixWorld();
  23868. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23869. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23870. 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);
  23871. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23872. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23873. },
  23874. getViewport: function getViewport(viewportIndex) {
  23875. return this._viewports[viewportIndex];
  23876. },
  23877. getFrameExtents: function getFrameExtents() {
  23878. return this._frameExtents;
  23879. },
  23880. copy: function copy(source) {
  23881. this.camera = source.camera.clone();
  23882. this.bias = source.bias;
  23883. this.radius = source.radius;
  23884. this.mapSize.copy(source.mapSize);
  23885. return this;
  23886. },
  23887. clone: function clone() {
  23888. return new this.constructor().copy(this);
  23889. },
  23890. toJSON: function toJSON() {
  23891. var object = {};
  23892. if (this.bias !== 0) object.bias = this.bias;
  23893. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23894. if (this.radius !== 1) object.radius = this.radius;
  23895. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23896. object.camera = this.camera.toJSON(false).object;
  23897. delete object.camera.matrix;
  23898. return object;
  23899. }
  23900. });
  23901. function SpotLightShadow() {
  23902. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23903. this.focus = 1;
  23904. }
  23905. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23906. constructor: SpotLightShadow,
  23907. isSpotLightShadow: true,
  23908. updateMatrices: function updateMatrices(light) {
  23909. var camera = this.camera;
  23910. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23911. var aspect = this.mapSize.width / this.mapSize.height;
  23912. var far = light.distance || camera.far;
  23913. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23914. camera.fov = fov;
  23915. camera.aspect = aspect;
  23916. camera.far = far;
  23917. camera.updateProjectionMatrix();
  23918. }
  23919. LightShadow.prototype.updateMatrices.call(this, light);
  23920. }
  23921. });
  23922. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23923. Light.call(this, color, intensity);
  23924. this.type = 'SpotLight';
  23925. this.position.copy(Object3D.DefaultUp);
  23926. this.updateMatrix();
  23927. this.target = new Object3D();
  23928. Object.defineProperty(this, 'power', {
  23929. get: function get() {
  23930. // intensity = power per solid angle.
  23931. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23932. return this.intensity * Math.PI;
  23933. },
  23934. set: function set(power) {
  23935. // intensity = power per solid angle.
  23936. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23937. this.intensity = power / Math.PI;
  23938. }
  23939. });
  23940. this.distance = distance !== undefined ? distance : 0;
  23941. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23942. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23943. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23944. this.shadow = new SpotLightShadow();
  23945. }
  23946. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23947. constructor: SpotLight,
  23948. isSpotLight: true,
  23949. copy: function copy(source) {
  23950. Light.prototype.copy.call(this, source);
  23951. this.distance = source.distance;
  23952. this.angle = source.angle;
  23953. this.penumbra = source.penumbra;
  23954. this.decay = source.decay;
  23955. this.target = source.target.clone();
  23956. this.shadow = source.shadow.clone();
  23957. return this;
  23958. }
  23959. });
  23960. function PointLightShadow() {
  23961. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23962. this._frameExtents = new Vector2(4, 2);
  23963. this._viewportCount = 6;
  23964. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23965. // following orientation:
  23966. //
  23967. // xzXZ
  23968. // y Y
  23969. //
  23970. // X - Positive x direction
  23971. // x - Negative x direction
  23972. // Y - Positive y direction
  23973. // y - Negative y direction
  23974. // Z - Positive z direction
  23975. // z - Negative z direction
  23976. // positive X
  23977. new Vector4(2, 1, 1, 1), // negative X
  23978. new Vector4(0, 1, 1, 1), // positive Z
  23979. new Vector4(3, 1, 1, 1), // negative Z
  23980. new Vector4(1, 1, 1, 1), // positive Y
  23981. new Vector4(3, 0, 1, 1), // negative Y
  23982. new Vector4(1, 0, 1, 1)];
  23983. 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)];
  23984. 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)];
  23985. }
  23986. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23987. constructor: PointLightShadow,
  23988. isPointLightShadow: true,
  23989. updateMatrices: function updateMatrices(light, viewportIndex) {
  23990. if (viewportIndex === void 0) {
  23991. viewportIndex = 0;
  23992. }
  23993. var camera = this.camera,
  23994. shadowMatrix = this.matrix,
  23995. lightPositionWorld = this._lightPositionWorld,
  23996. lookTarget = this._lookTarget,
  23997. projScreenMatrix = this._projScreenMatrix;
  23998. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23999. camera.position.copy(lightPositionWorld);
  24000. lookTarget.copy(camera.position);
  24001. lookTarget.add(this._cubeDirections[viewportIndex]);
  24002. camera.up.copy(this._cubeUps[viewportIndex]);
  24003. camera.lookAt(lookTarget);
  24004. camera.updateMatrixWorld();
  24005. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  24006. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  24007. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  24008. }
  24009. });
  24010. function PointLight(color, intensity, distance, decay) {
  24011. Light.call(this, color, intensity);
  24012. this.type = 'PointLight';
  24013. Object.defineProperty(this, 'power', {
  24014. get: function get() {
  24015. // intensity = power per solid angle.
  24016. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  24017. return this.intensity * 4 * Math.PI;
  24018. },
  24019. set: function set(power) {
  24020. // intensity = power per solid angle.
  24021. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  24022. this.intensity = power / (4 * Math.PI);
  24023. }
  24024. });
  24025. this.distance = distance !== undefined ? distance : 0;
  24026. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  24027. this.shadow = new PointLightShadow();
  24028. }
  24029. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  24030. constructor: PointLight,
  24031. isPointLight: true,
  24032. copy: function copy(source) {
  24033. Light.prototype.copy.call(this, source);
  24034. this.distance = source.distance;
  24035. this.decay = source.decay;
  24036. this.shadow = source.shadow.clone();
  24037. return this;
  24038. }
  24039. });
  24040. function OrthographicCamera(left, right, top, bottom, near, far) {
  24041. if (left === void 0) {
  24042. left = -1;
  24043. }
  24044. if (right === void 0) {
  24045. right = 1;
  24046. }
  24047. if (top === void 0) {
  24048. top = 1;
  24049. }
  24050. if (bottom === void 0) {
  24051. bottom = -1;
  24052. }
  24053. if (near === void 0) {
  24054. near = 0.1;
  24055. }
  24056. if (far === void 0) {
  24057. far = 2000;
  24058. }
  24059. Camera.call(this);
  24060. this.type = 'OrthographicCamera';
  24061. this.zoom = 1;
  24062. this.view = null;
  24063. this.left = left;
  24064. this.right = right;
  24065. this.top = top;
  24066. this.bottom = bottom;
  24067. this.near = near;
  24068. this.far = far;
  24069. this.updateProjectionMatrix();
  24070. }
  24071. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  24072. constructor: OrthographicCamera,
  24073. isOrthographicCamera: true,
  24074. copy: function copy(source, recursive) {
  24075. Camera.prototype.copy.call(this, source, recursive);
  24076. this.left = source.left;
  24077. this.right = source.right;
  24078. this.top = source.top;
  24079. this.bottom = source.bottom;
  24080. this.near = source.near;
  24081. this.far = source.far;
  24082. this.zoom = source.zoom;
  24083. this.view = source.view === null ? null : Object.assign({}, source.view);
  24084. return this;
  24085. },
  24086. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  24087. if (this.view === null) {
  24088. this.view = {
  24089. enabled: true,
  24090. fullWidth: 1,
  24091. fullHeight: 1,
  24092. offsetX: 0,
  24093. offsetY: 0,
  24094. width: 1,
  24095. height: 1
  24096. };
  24097. }
  24098. this.view.enabled = true;
  24099. this.view.fullWidth = fullWidth;
  24100. this.view.fullHeight = fullHeight;
  24101. this.view.offsetX = x;
  24102. this.view.offsetY = y;
  24103. this.view.width = width;
  24104. this.view.height = height;
  24105. this.updateProjectionMatrix();
  24106. },
  24107. clearViewOffset: function clearViewOffset() {
  24108. if (this.view !== null) {
  24109. this.view.enabled = false;
  24110. }
  24111. this.updateProjectionMatrix();
  24112. },
  24113. updateProjectionMatrix: function updateProjectionMatrix() {
  24114. var dx = (this.right - this.left) / (2 * this.zoom);
  24115. var dy = (this.top - this.bottom) / (2 * this.zoom);
  24116. var cx = (this.right + this.left) / 2;
  24117. var cy = (this.top + this.bottom) / 2;
  24118. var left = cx - dx;
  24119. var right = cx + dx;
  24120. var top = cy + dy;
  24121. var bottom = cy - dy;
  24122. if (this.view !== null && this.view.enabled) {
  24123. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  24124. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  24125. left += scaleW * this.view.offsetX;
  24126. right = left + scaleW * this.view.width;
  24127. top -= scaleH * this.view.offsetY;
  24128. bottom = top - scaleH * this.view.height;
  24129. }
  24130. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  24131. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  24132. },
  24133. toJSON: function toJSON(meta) {
  24134. var data = Object3D.prototype.toJSON.call(this, meta);
  24135. data.object.zoom = this.zoom;
  24136. data.object.left = this.left;
  24137. data.object.right = this.right;
  24138. data.object.top = this.top;
  24139. data.object.bottom = this.bottom;
  24140. data.object.near = this.near;
  24141. data.object.far = this.far;
  24142. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  24143. return data;
  24144. }
  24145. });
  24146. function DirectionalLightShadow() {
  24147. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  24148. }
  24149. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  24150. constructor: DirectionalLightShadow,
  24151. isDirectionalLightShadow: true,
  24152. updateMatrices: function updateMatrices(light) {
  24153. LightShadow.prototype.updateMatrices.call(this, light);
  24154. }
  24155. });
  24156. function DirectionalLight(color, intensity) {
  24157. Light.call(this, color, intensity);
  24158. this.type = 'DirectionalLight';
  24159. this.position.copy(Object3D.DefaultUp);
  24160. this.updateMatrix();
  24161. this.target = new Object3D();
  24162. this.shadow = new DirectionalLightShadow();
  24163. }
  24164. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  24165. constructor: DirectionalLight,
  24166. isDirectionalLight: true,
  24167. copy: function copy(source) {
  24168. Light.prototype.copy.call(this, source);
  24169. this.target = source.target.clone();
  24170. this.shadow = source.shadow.clone();
  24171. return this;
  24172. }
  24173. });
  24174. function AmbientLight(color, intensity) {
  24175. Light.call(this, color, intensity);
  24176. this.type = 'AmbientLight';
  24177. }
  24178. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  24179. constructor: AmbientLight,
  24180. isAmbientLight: true
  24181. });
  24182. function RectAreaLight(color, intensity, width, height) {
  24183. Light.call(this, color, intensity);
  24184. this.type = 'RectAreaLight';
  24185. this.width = width !== undefined ? width : 10;
  24186. this.height = height !== undefined ? height : 10;
  24187. }
  24188. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  24189. constructor: RectAreaLight,
  24190. isRectAreaLight: true,
  24191. copy: function copy(source) {
  24192. Light.prototype.copy.call(this, source);
  24193. this.width = source.width;
  24194. this.height = source.height;
  24195. return this;
  24196. },
  24197. toJSON: function toJSON(meta) {
  24198. var data = Light.prototype.toJSON.call(this, meta);
  24199. data.object.width = this.width;
  24200. data.object.height = this.height;
  24201. return data;
  24202. }
  24203. });
  24204. /**
  24205. * Primary reference:
  24206. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24207. *
  24208. * Secondary reference:
  24209. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24210. */
  24211. // 3-band SH defined by 9 coefficients
  24212. var SphericalHarmonics3 = /*#__PURE__*/function () {
  24213. function SphericalHarmonics3() {
  24214. Object.defineProperty(this, 'isSphericalHarmonics3', {
  24215. value: true
  24216. });
  24217. this.coefficients = [];
  24218. for (var i = 0; i < 9; i++) {
  24219. this.coefficients.push(new Vector3());
  24220. }
  24221. }
  24222. var _proto = SphericalHarmonics3.prototype;
  24223. _proto.set = function set(coefficients) {
  24224. for (var i = 0; i < 9; i++) {
  24225. this.coefficients[i].copy(coefficients[i]);
  24226. }
  24227. return this;
  24228. };
  24229. _proto.zero = function zero() {
  24230. for (var i = 0; i < 9; i++) {
  24231. this.coefficients[i].set(0, 0, 0);
  24232. }
  24233. return this;
  24234. } // get the radiance in the direction of the normal
  24235. // target is a Vector3
  24236. ;
  24237. _proto.getAt = function getAt(normal, target) {
  24238. // normal is assumed to be unit length
  24239. var x = normal.x,
  24240. y = normal.y,
  24241. z = normal.z;
  24242. var coeff = this.coefficients; // band 0
  24243. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  24244. target.addScaledVector(coeff[1], 0.488603 * y);
  24245. target.addScaledVector(coeff[2], 0.488603 * z);
  24246. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  24247. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  24248. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  24249. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  24250. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  24251. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  24252. return target;
  24253. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24254. // target is a Vector3
  24255. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24256. ;
  24257. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  24258. // normal is assumed to be unit length
  24259. var x = normal.x,
  24260. y = normal.y,
  24261. z = normal.z;
  24262. var coeff = this.coefficients; // band 0
  24263. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  24264. // band 1
  24265. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  24266. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  24267. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  24268. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  24269. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  24270. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  24271. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  24272. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  24273. return target;
  24274. };
  24275. _proto.add = function add(sh) {
  24276. for (var i = 0; i < 9; i++) {
  24277. this.coefficients[i].add(sh.coefficients[i]);
  24278. }
  24279. return this;
  24280. };
  24281. _proto.addScaledSH = function addScaledSH(sh, s) {
  24282. for (var i = 0; i < 9; i++) {
  24283. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  24284. }
  24285. return this;
  24286. };
  24287. _proto.scale = function scale(s) {
  24288. for (var i = 0; i < 9; i++) {
  24289. this.coefficients[i].multiplyScalar(s);
  24290. }
  24291. return this;
  24292. };
  24293. _proto.lerp = function lerp(sh, alpha) {
  24294. for (var i = 0; i < 9; i++) {
  24295. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  24296. }
  24297. return this;
  24298. };
  24299. _proto.equals = function equals(sh) {
  24300. for (var i = 0; i < 9; i++) {
  24301. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  24302. return false;
  24303. }
  24304. }
  24305. return true;
  24306. };
  24307. _proto.copy = function copy(sh) {
  24308. return this.set(sh.coefficients);
  24309. };
  24310. _proto.clone = function clone() {
  24311. return new this.constructor().copy(this);
  24312. };
  24313. _proto.fromArray = function fromArray(array, offset) {
  24314. if (offset === void 0) {
  24315. offset = 0;
  24316. }
  24317. var coefficients = this.coefficients;
  24318. for (var i = 0; i < 9; i++) {
  24319. coefficients[i].fromArray(array, offset + i * 3);
  24320. }
  24321. return this;
  24322. };
  24323. _proto.toArray = function toArray(array, offset) {
  24324. if (array === void 0) {
  24325. array = [];
  24326. }
  24327. if (offset === void 0) {
  24328. offset = 0;
  24329. }
  24330. var coefficients = this.coefficients;
  24331. for (var i = 0; i < 9; i++) {
  24332. coefficients[i].toArray(array, offset + i * 3);
  24333. }
  24334. return array;
  24335. } // evaluate the basis functions
  24336. // shBasis is an Array[ 9 ]
  24337. ;
  24338. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  24339. // normal is assumed to be unit length
  24340. var x = normal.x,
  24341. y = normal.y,
  24342. z = normal.z; // band 0
  24343. shBasis[0] = 0.282095; // band 1
  24344. shBasis[1] = 0.488603 * y;
  24345. shBasis[2] = 0.488603 * z;
  24346. shBasis[3] = 0.488603 * x; // band 2
  24347. shBasis[4] = 1.092548 * x * y;
  24348. shBasis[5] = 1.092548 * y * z;
  24349. shBasis[6] = 0.315392 * (3 * z * z - 1);
  24350. shBasis[7] = 1.092548 * x * z;
  24351. shBasis[8] = 0.546274 * (x * x - y * y);
  24352. };
  24353. return SphericalHarmonics3;
  24354. }();
  24355. function LightProbe(sh, intensity) {
  24356. Light.call(this, undefined, intensity);
  24357. this.type = 'LightProbe';
  24358. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  24359. }
  24360. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  24361. constructor: LightProbe,
  24362. isLightProbe: true,
  24363. copy: function copy(source) {
  24364. Light.prototype.copy.call(this, source);
  24365. this.sh.copy(source.sh);
  24366. return this;
  24367. },
  24368. fromJSON: function fromJSON(json) {
  24369. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24370. this.sh.fromArray(json.sh);
  24371. return this;
  24372. },
  24373. toJSON: function toJSON(meta) {
  24374. var data = Light.prototype.toJSON.call(this, meta);
  24375. data.object.sh = this.sh.toArray();
  24376. return data;
  24377. }
  24378. });
  24379. function MaterialLoader(manager) {
  24380. Loader.call(this, manager);
  24381. this.textures = {};
  24382. }
  24383. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24384. constructor: MaterialLoader,
  24385. load: function load(url, onLoad, onProgress, onError) {
  24386. var scope = this;
  24387. var loader = new FileLoader(scope.manager);
  24388. loader.setPath(scope.path);
  24389. loader.setRequestHeader(scope.requestHeader);
  24390. loader.setWithCredentials(scope.withCredentials);
  24391. loader.load(url, function (text) {
  24392. try {
  24393. onLoad(scope.parse(JSON.parse(text)));
  24394. } catch (e) {
  24395. if (onError) {
  24396. onError(e);
  24397. } else {
  24398. console.error(e);
  24399. }
  24400. scope.manager.itemError(url);
  24401. }
  24402. }, onProgress, onError);
  24403. },
  24404. parse: function parse(json) {
  24405. var textures = this.textures;
  24406. function getTexture(name) {
  24407. if (textures[name] === undefined) {
  24408. console.warn('THREE.MaterialLoader: Undefined texture', name);
  24409. }
  24410. return textures[name];
  24411. }
  24412. var material = new Materials[json.type]();
  24413. if (json.uuid !== undefined) material.uuid = json.uuid;
  24414. if (json.name !== undefined) material.name = json.name;
  24415. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  24416. if (json.roughness !== undefined) material.roughness = json.roughness;
  24417. if (json.metalness !== undefined) material.metalness = json.metalness;
  24418. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  24419. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  24420. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  24421. if (json.shininess !== undefined) material.shininess = json.shininess;
  24422. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  24423. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  24424. if (json.fog !== undefined) material.fog = json.fog;
  24425. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  24426. if (json.blending !== undefined) material.blending = json.blending;
  24427. if (json.combine !== undefined) material.combine = json.combine;
  24428. if (json.side !== undefined) material.side = json.side;
  24429. if (json.opacity !== undefined) material.opacity = json.opacity;
  24430. if (json.transparent !== undefined) material.transparent = json.transparent;
  24431. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  24432. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  24433. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  24434. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  24435. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  24436. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  24437. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  24438. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  24439. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  24440. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  24441. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  24442. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  24443. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  24444. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  24445. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  24446. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  24447. if (json.rotation !== undefined) material.rotation = json.rotation;
  24448. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  24449. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  24450. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  24451. if (json.scale !== undefined) material.scale = json.scale;
  24452. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  24453. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24454. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24455. if (json.skinning !== undefined) material.skinning = json.skinning;
  24456. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  24457. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  24458. if (json.dithering !== undefined) material.dithering = json.dithering;
  24459. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  24460. if (json.visible !== undefined) material.visible = json.visible;
  24461. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  24462. if (json.userData !== undefined) material.userData = json.userData;
  24463. if (json.vertexColors !== undefined) {
  24464. if (typeof json.vertexColors === 'number') {
  24465. material.vertexColors = json.vertexColors > 0 ? true : false;
  24466. } else {
  24467. material.vertexColors = json.vertexColors;
  24468. }
  24469. } // Shader Material
  24470. if (json.uniforms !== undefined) {
  24471. for (var name in json.uniforms) {
  24472. var uniform = json.uniforms[name];
  24473. material.uniforms[name] = {};
  24474. switch (uniform.type) {
  24475. case 't':
  24476. material.uniforms[name].value = getTexture(uniform.value);
  24477. break;
  24478. case 'c':
  24479. material.uniforms[name].value = new Color().setHex(uniform.value);
  24480. break;
  24481. case 'v2':
  24482. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  24483. break;
  24484. case 'v3':
  24485. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  24486. break;
  24487. case 'v4':
  24488. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  24489. break;
  24490. case 'm3':
  24491. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  24492. break;
  24493. case 'm4':
  24494. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24495. break;
  24496. default:
  24497. material.uniforms[name].value = uniform.value;
  24498. }
  24499. }
  24500. }
  24501. if (json.defines !== undefined) material.defines = json.defines;
  24502. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24503. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24504. if (json.extensions !== undefined) {
  24505. for (var key in json.extensions) {
  24506. material.extensions[key] = json.extensions[key];
  24507. }
  24508. } // Deprecated
  24509. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24510. // for PointsMaterial
  24511. if (json.size !== undefined) material.size = json.size;
  24512. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24513. if (json.map !== undefined) material.map = getTexture(json.map);
  24514. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24515. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24516. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24517. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24518. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24519. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24520. if (json.normalScale !== undefined) {
  24521. var normalScale = json.normalScale;
  24522. if (Array.isArray(normalScale) === false) {
  24523. // Blender exporter used to export a scalar. See #7459
  24524. normalScale = [normalScale, normalScale];
  24525. }
  24526. material.normalScale = new Vector2().fromArray(normalScale);
  24527. }
  24528. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24529. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24530. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24531. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24532. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24533. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24534. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24535. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24536. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24537. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24538. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24539. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24540. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24541. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24542. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24543. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24544. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24545. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24546. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24547. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24548. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24549. if (json.transmission !== undefined) material.transmission = json.transmission;
  24550. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24551. return material;
  24552. },
  24553. setTextures: function setTextures(value) {
  24554. this.textures = value;
  24555. return this;
  24556. }
  24557. });
  24558. var LoaderUtils = {
  24559. decodeText: function decodeText(array) {
  24560. if (typeof TextDecoder !== 'undefined') {
  24561. return new TextDecoder().decode(array);
  24562. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24563. // throws a "maximum call stack size exceeded" error for large arrays.
  24564. var s = '';
  24565. for (var i = 0, il = array.length; i < il; i++) {
  24566. // Implicitly assumes little-endian.
  24567. s += String.fromCharCode(array[i]);
  24568. }
  24569. try {
  24570. // merges multi-byte utf-8 characters.
  24571. return decodeURIComponent(escape(s));
  24572. } catch (e) {
  24573. // see #16358
  24574. return s;
  24575. }
  24576. },
  24577. extractUrlBase: function extractUrlBase(url) {
  24578. var index = url.lastIndexOf('/');
  24579. if (index === -1) return './';
  24580. return url.substr(0, index + 1);
  24581. }
  24582. };
  24583. function InstancedBufferGeometry() {
  24584. BufferGeometry.call(this);
  24585. this.type = 'InstancedBufferGeometry';
  24586. this.instanceCount = Infinity;
  24587. }
  24588. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24589. constructor: InstancedBufferGeometry,
  24590. isInstancedBufferGeometry: true,
  24591. copy: function copy(source) {
  24592. BufferGeometry.prototype.copy.call(this, source);
  24593. this.instanceCount = source.instanceCount;
  24594. return this;
  24595. },
  24596. clone: function clone() {
  24597. return new this.constructor().copy(this);
  24598. },
  24599. toJSON: function toJSON() {
  24600. var data = BufferGeometry.prototype.toJSON.call(this);
  24601. data.instanceCount = this.instanceCount;
  24602. data.isInstancedBufferGeometry = true;
  24603. return data;
  24604. }
  24605. });
  24606. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24607. if (typeof normalized === 'number') {
  24608. meshPerAttribute = normalized;
  24609. normalized = false;
  24610. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24611. }
  24612. BufferAttribute.call(this, array, itemSize, normalized);
  24613. this.meshPerAttribute = meshPerAttribute || 1;
  24614. }
  24615. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24616. constructor: InstancedBufferAttribute,
  24617. isInstancedBufferAttribute: true,
  24618. copy: function copy(source) {
  24619. BufferAttribute.prototype.copy.call(this, source);
  24620. this.meshPerAttribute = source.meshPerAttribute;
  24621. return this;
  24622. },
  24623. toJSON: function toJSON() {
  24624. var data = BufferAttribute.prototype.toJSON.call(this);
  24625. data.meshPerAttribute = this.meshPerAttribute;
  24626. data.isInstancedBufferAttribute = true;
  24627. return data;
  24628. }
  24629. });
  24630. function BufferGeometryLoader(manager) {
  24631. Loader.call(this, manager);
  24632. }
  24633. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24634. constructor: BufferGeometryLoader,
  24635. load: function load(url, onLoad, onProgress, onError) {
  24636. var scope = this;
  24637. var loader = new FileLoader(scope.manager);
  24638. loader.setPath(scope.path);
  24639. loader.setRequestHeader(scope.requestHeader);
  24640. loader.setWithCredentials(scope.withCredentials);
  24641. loader.load(url, function (text) {
  24642. try {
  24643. onLoad(scope.parse(JSON.parse(text)));
  24644. } catch (e) {
  24645. if (onError) {
  24646. onError(e);
  24647. } else {
  24648. console.error(e);
  24649. }
  24650. scope.manager.itemError(url);
  24651. }
  24652. }, onProgress, onError);
  24653. },
  24654. parse: function parse(json) {
  24655. var interleavedBufferMap = {};
  24656. var arrayBufferMap = {};
  24657. function getInterleavedBuffer(json, uuid) {
  24658. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24659. var interleavedBuffers = json.interleavedBuffers;
  24660. var interleavedBuffer = interleavedBuffers[uuid];
  24661. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24662. var array = getTypedArray(interleavedBuffer.type, buffer);
  24663. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24664. ib.uuid = interleavedBuffer.uuid;
  24665. interleavedBufferMap[uuid] = ib;
  24666. return ib;
  24667. }
  24668. function getArrayBuffer(json, uuid) {
  24669. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24670. var arrayBuffers = json.arrayBuffers;
  24671. var arrayBuffer = arrayBuffers[uuid];
  24672. var ab = new Uint32Array(arrayBuffer).buffer;
  24673. arrayBufferMap[uuid] = ab;
  24674. return ab;
  24675. }
  24676. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24677. var index = json.data.index;
  24678. if (index !== undefined) {
  24679. var typedArray = getTypedArray(index.type, index.array);
  24680. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24681. }
  24682. var attributes = json.data.attributes;
  24683. for (var key in attributes) {
  24684. var attribute = attributes[key];
  24685. var bufferAttribute = void 0;
  24686. if (attribute.isInterleavedBufferAttribute) {
  24687. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24688. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24689. } else {
  24690. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24691. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24692. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24693. }
  24694. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24695. geometry.setAttribute(key, bufferAttribute);
  24696. }
  24697. var morphAttributes = json.data.morphAttributes;
  24698. if (morphAttributes) {
  24699. for (var _key in morphAttributes) {
  24700. var attributeArray = morphAttributes[_key];
  24701. var array = [];
  24702. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24703. var _attribute = attributeArray[i];
  24704. var _bufferAttribute = void 0;
  24705. if (_attribute.isInterleavedBufferAttribute) {
  24706. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24707. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24708. } else {
  24709. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24710. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24711. }
  24712. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24713. array.push(_bufferAttribute);
  24714. }
  24715. geometry.morphAttributes[_key] = array;
  24716. }
  24717. }
  24718. var morphTargetsRelative = json.data.morphTargetsRelative;
  24719. if (morphTargetsRelative) {
  24720. geometry.morphTargetsRelative = true;
  24721. }
  24722. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24723. if (groups !== undefined) {
  24724. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24725. var group = groups[_i];
  24726. geometry.addGroup(group.start, group.count, group.materialIndex);
  24727. }
  24728. }
  24729. var boundingSphere = json.data.boundingSphere;
  24730. if (boundingSphere !== undefined) {
  24731. var center = new Vector3();
  24732. if (boundingSphere.center !== undefined) {
  24733. center.fromArray(boundingSphere.center);
  24734. }
  24735. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24736. }
  24737. if (json.name) geometry.name = json.name;
  24738. if (json.userData) geometry.userData = json.userData;
  24739. return geometry;
  24740. }
  24741. });
  24742. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24743. _inheritsLoose(ObjectLoader, _Loader);
  24744. function ObjectLoader(manager) {
  24745. return _Loader.call(this, manager) || this;
  24746. }
  24747. var _proto = ObjectLoader.prototype;
  24748. _proto.load = function load(url, onLoad, onProgress, onError) {
  24749. var scope = this;
  24750. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24751. this.resourcePath = this.resourcePath || path;
  24752. var loader = new FileLoader(this.manager);
  24753. loader.setPath(this.path);
  24754. loader.setRequestHeader(this.requestHeader);
  24755. loader.setWithCredentials(this.withCredentials);
  24756. loader.load(url, function (text) {
  24757. var json = null;
  24758. try {
  24759. json = JSON.parse(text);
  24760. } catch (error) {
  24761. if (onError !== undefined) onError(error);
  24762. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24763. return;
  24764. }
  24765. var metadata = json.metadata;
  24766. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24767. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24768. return;
  24769. }
  24770. scope.parse(json, onLoad);
  24771. }, onProgress, onError);
  24772. };
  24773. _proto.parse = function parse(json, onLoad) {
  24774. var animations = this.parseAnimations(json.animations);
  24775. var shapes = this.parseShapes(json.shapes);
  24776. var geometries = this.parseGeometries(json.geometries, shapes);
  24777. var images = this.parseImages(json.images, function () {
  24778. if (onLoad !== undefined) onLoad(object);
  24779. });
  24780. var textures = this.parseTextures(json.textures, images);
  24781. var materials = this.parseMaterials(json.materials, textures);
  24782. var object = this.parseObject(json.object, geometries, materials, animations);
  24783. var skeletons = this.parseSkeletons(json.skeletons, object);
  24784. this.bindSkeletons(object, skeletons); //
  24785. if (onLoad !== undefined) {
  24786. var hasImages = false;
  24787. for (var uuid in images) {
  24788. if (images[uuid] instanceof HTMLImageElement) {
  24789. hasImages = true;
  24790. break;
  24791. }
  24792. }
  24793. if (hasImages === false) onLoad(object);
  24794. }
  24795. return object;
  24796. };
  24797. _proto.parseShapes = function parseShapes(json) {
  24798. var shapes = {};
  24799. if (json !== undefined) {
  24800. for (var i = 0, l = json.length; i < l; i++) {
  24801. var shape = new Shape().fromJSON(json[i]);
  24802. shapes[shape.uuid] = shape;
  24803. }
  24804. }
  24805. return shapes;
  24806. };
  24807. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24808. var skeletons = {};
  24809. var bones = {}; // generate bone lookup table
  24810. object.traverse(function (child) {
  24811. if (child.isBone) bones[child.uuid] = child;
  24812. }); // create skeletons
  24813. if (json !== undefined) {
  24814. for (var i = 0, l = json.length; i < l; i++) {
  24815. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24816. skeletons[skeleton.uuid] = skeleton;
  24817. }
  24818. }
  24819. return skeletons;
  24820. };
  24821. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24822. var geometries = {};
  24823. var geometryShapes;
  24824. if (json !== undefined) {
  24825. var bufferGeometryLoader = new BufferGeometryLoader();
  24826. for (var i = 0, l = json.length; i < l; i++) {
  24827. var geometry = void 0;
  24828. var data = json[i];
  24829. switch (data.type) {
  24830. case 'PlaneGeometry':
  24831. case 'PlaneBufferGeometry':
  24832. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24833. break;
  24834. case 'BoxGeometry':
  24835. case 'BoxBufferGeometry':
  24836. case 'CubeGeometry':
  24837. // backwards compatible
  24838. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24839. break;
  24840. case 'CircleGeometry':
  24841. case 'CircleBufferGeometry':
  24842. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24843. break;
  24844. case 'CylinderGeometry':
  24845. case 'CylinderBufferGeometry':
  24846. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24847. break;
  24848. case 'ConeGeometry':
  24849. case 'ConeBufferGeometry':
  24850. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24851. break;
  24852. case 'SphereGeometry':
  24853. case 'SphereBufferGeometry':
  24854. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24855. break;
  24856. case 'DodecahedronGeometry':
  24857. case 'DodecahedronBufferGeometry':
  24858. case 'IcosahedronGeometry':
  24859. case 'IcosahedronBufferGeometry':
  24860. case 'OctahedronGeometry':
  24861. case 'OctahedronBufferGeometry':
  24862. case 'TetrahedronGeometry':
  24863. case 'TetrahedronBufferGeometry':
  24864. geometry = new Geometries[data.type](data.radius, data.detail);
  24865. break;
  24866. case 'RingGeometry':
  24867. case 'RingBufferGeometry':
  24868. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24869. break;
  24870. case 'TorusGeometry':
  24871. case 'TorusBufferGeometry':
  24872. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24873. break;
  24874. case 'TorusKnotGeometry':
  24875. case 'TorusKnotBufferGeometry':
  24876. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24877. break;
  24878. case 'TubeGeometry':
  24879. case 'TubeBufferGeometry':
  24880. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24881. // User defined curves or instances of CurvePath will not be deserialized.
  24882. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24883. break;
  24884. case 'LatheGeometry':
  24885. case 'LatheBufferGeometry':
  24886. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24887. break;
  24888. case 'PolyhedronGeometry':
  24889. case 'PolyhedronBufferGeometry':
  24890. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24891. break;
  24892. case 'ShapeGeometry':
  24893. case 'ShapeBufferGeometry':
  24894. geometryShapes = [];
  24895. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24896. var shape = shapes[data.shapes[j]];
  24897. geometryShapes.push(shape);
  24898. }
  24899. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24900. break;
  24901. case 'ExtrudeGeometry':
  24902. case 'ExtrudeBufferGeometry':
  24903. geometryShapes = [];
  24904. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24905. var _shape = shapes[data.shapes[_j]];
  24906. geometryShapes.push(_shape);
  24907. }
  24908. var extrudePath = data.options.extrudePath;
  24909. if (extrudePath !== undefined) {
  24910. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24911. }
  24912. geometry = new Geometries[data.type](geometryShapes, data.options);
  24913. break;
  24914. case 'BufferGeometry':
  24915. case 'InstancedBufferGeometry':
  24916. geometry = bufferGeometryLoader.parse(data);
  24917. break;
  24918. case 'Geometry':
  24919. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24920. break;
  24921. default:
  24922. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24923. continue;
  24924. }
  24925. geometry.uuid = data.uuid;
  24926. if (data.name !== undefined) geometry.name = data.name;
  24927. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24928. geometries[data.uuid] = geometry;
  24929. }
  24930. }
  24931. return geometries;
  24932. };
  24933. _proto.parseMaterials = function parseMaterials(json, textures) {
  24934. var cache = {}; // MultiMaterial
  24935. var materials = {};
  24936. if (json !== undefined) {
  24937. var loader = new MaterialLoader();
  24938. loader.setTextures(textures);
  24939. for (var i = 0, l = json.length; i < l; i++) {
  24940. var data = json[i];
  24941. if (data.type === 'MultiMaterial') {
  24942. // Deprecated
  24943. var array = [];
  24944. for (var j = 0; j < data.materials.length; j++) {
  24945. var material = data.materials[j];
  24946. if (cache[material.uuid] === undefined) {
  24947. cache[material.uuid] = loader.parse(material);
  24948. }
  24949. array.push(cache[material.uuid]);
  24950. }
  24951. materials[data.uuid] = array;
  24952. } else {
  24953. if (cache[data.uuid] === undefined) {
  24954. cache[data.uuid] = loader.parse(data);
  24955. }
  24956. materials[data.uuid] = cache[data.uuid];
  24957. }
  24958. }
  24959. }
  24960. return materials;
  24961. };
  24962. _proto.parseAnimations = function parseAnimations(json) {
  24963. var animations = {};
  24964. if (json !== undefined) {
  24965. for (var i = 0; i < json.length; i++) {
  24966. var data = json[i];
  24967. var clip = AnimationClip.parse(data);
  24968. animations[clip.uuid] = clip;
  24969. }
  24970. }
  24971. return animations;
  24972. };
  24973. _proto.parseImages = function parseImages(json, onLoad) {
  24974. var scope = this;
  24975. var images = {};
  24976. var loader;
  24977. function loadImage(url) {
  24978. scope.manager.itemStart(url);
  24979. return loader.load(url, function () {
  24980. scope.manager.itemEnd(url);
  24981. }, undefined, function () {
  24982. scope.manager.itemError(url);
  24983. scope.manager.itemEnd(url);
  24984. });
  24985. }
  24986. function deserializeImage(image) {
  24987. if (typeof image === 'string') {
  24988. var url = image;
  24989. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24990. return loadImage(path);
  24991. } else {
  24992. if (image.data) {
  24993. return {
  24994. data: getTypedArray(image.type, image.data),
  24995. width: image.width,
  24996. height: image.height
  24997. };
  24998. } else {
  24999. return null;
  25000. }
  25001. }
  25002. }
  25003. if (json !== undefined && json.length > 0) {
  25004. var manager = new LoadingManager(onLoad);
  25005. loader = new ImageLoader(manager);
  25006. loader.setCrossOrigin(this.crossOrigin);
  25007. for (var i = 0, il = json.length; i < il; i++) {
  25008. var image = json[i];
  25009. var url = image.url;
  25010. if (Array.isArray(url)) {
  25011. // load array of images e.g CubeTexture
  25012. images[image.uuid] = [];
  25013. for (var j = 0, jl = url.length; j < jl; j++) {
  25014. var currentUrl = url[j];
  25015. var deserializedImage = deserializeImage(currentUrl);
  25016. if (deserializedImage !== null) {
  25017. if (deserializedImage instanceof HTMLImageElement) {
  25018. images[image.uuid].push(deserializedImage);
  25019. } else {
  25020. // special case: handle array of data textures for cube textures
  25021. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  25022. }
  25023. }
  25024. }
  25025. } else {
  25026. // load single image
  25027. var _deserializedImage = deserializeImage(image.url);
  25028. if (_deserializedImage !== null) {
  25029. images[image.uuid] = _deserializedImage;
  25030. }
  25031. }
  25032. }
  25033. }
  25034. return images;
  25035. };
  25036. _proto.parseTextures = function parseTextures(json, images) {
  25037. function parseConstant(value, type) {
  25038. if (typeof value === 'number') return value;
  25039. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  25040. return type[value];
  25041. }
  25042. var textures = {};
  25043. if (json !== undefined) {
  25044. for (var i = 0, l = json.length; i < l; i++) {
  25045. var data = json[i];
  25046. if (data.image === undefined) {
  25047. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  25048. }
  25049. if (images[data.image] === undefined) {
  25050. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  25051. }
  25052. var texture = void 0;
  25053. var image = images[data.image];
  25054. if (Array.isArray(image)) {
  25055. texture = new CubeTexture(image);
  25056. if (image.length === 6) texture.needsUpdate = true;
  25057. } else {
  25058. if (image && image.data) {
  25059. texture = new DataTexture(image.data, image.width, image.height);
  25060. } else {
  25061. texture = new Texture(image);
  25062. }
  25063. if (image) texture.needsUpdate = true; // textures can have undefined image data
  25064. }
  25065. texture.uuid = data.uuid;
  25066. if (data.name !== undefined) texture.name = data.name;
  25067. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  25068. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  25069. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  25070. if (data.center !== undefined) texture.center.fromArray(data.center);
  25071. if (data.rotation !== undefined) texture.rotation = data.rotation;
  25072. if (data.wrap !== undefined) {
  25073. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  25074. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  25075. }
  25076. if (data.format !== undefined) texture.format = data.format;
  25077. if (data.type !== undefined) texture.type = data.type;
  25078. if (data.encoding !== undefined) texture.encoding = data.encoding;
  25079. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  25080. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  25081. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  25082. if (data.flipY !== undefined) texture.flipY = data.flipY;
  25083. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  25084. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  25085. textures[data.uuid] = texture;
  25086. }
  25087. }
  25088. return textures;
  25089. };
  25090. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  25091. var object;
  25092. function getGeometry(name) {
  25093. if (geometries[name] === undefined) {
  25094. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  25095. }
  25096. return geometries[name];
  25097. }
  25098. function getMaterial(name) {
  25099. if (name === undefined) return undefined;
  25100. if (Array.isArray(name)) {
  25101. var array = [];
  25102. for (var i = 0, l = name.length; i < l; i++) {
  25103. var uuid = name[i];
  25104. if (materials[uuid] === undefined) {
  25105. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  25106. }
  25107. array.push(materials[uuid]);
  25108. }
  25109. return array;
  25110. }
  25111. if (materials[name] === undefined) {
  25112. console.warn('THREE.ObjectLoader: Undefined material', name);
  25113. }
  25114. return materials[name];
  25115. }
  25116. var geometry, material;
  25117. switch (data.type) {
  25118. case 'Scene':
  25119. object = new Scene();
  25120. if (data.background !== undefined) {
  25121. if (Number.isInteger(data.background)) {
  25122. object.background = new Color(data.background);
  25123. }
  25124. }
  25125. if (data.fog !== undefined) {
  25126. if (data.fog.type === 'Fog') {
  25127. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  25128. } else if (data.fog.type === 'FogExp2') {
  25129. object.fog = new FogExp2(data.fog.color, data.fog.density);
  25130. }
  25131. }
  25132. break;
  25133. case 'PerspectiveCamera':
  25134. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  25135. if (data.focus !== undefined) object.focus = data.focus;
  25136. if (data.zoom !== undefined) object.zoom = data.zoom;
  25137. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  25138. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  25139. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  25140. break;
  25141. case 'OrthographicCamera':
  25142. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  25143. if (data.zoom !== undefined) object.zoom = data.zoom;
  25144. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  25145. break;
  25146. case 'AmbientLight':
  25147. object = new AmbientLight(data.color, data.intensity);
  25148. break;
  25149. case 'DirectionalLight':
  25150. object = new DirectionalLight(data.color, data.intensity);
  25151. break;
  25152. case 'PointLight':
  25153. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  25154. break;
  25155. case 'RectAreaLight':
  25156. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  25157. break;
  25158. case 'SpotLight':
  25159. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  25160. break;
  25161. case 'HemisphereLight':
  25162. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  25163. break;
  25164. case 'LightProbe':
  25165. object = new LightProbe().fromJSON(data);
  25166. break;
  25167. case 'SkinnedMesh':
  25168. geometry = getGeometry(data.geometry);
  25169. material = getMaterial(data.material);
  25170. object = new SkinnedMesh(geometry, material);
  25171. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  25172. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  25173. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  25174. break;
  25175. case 'Mesh':
  25176. geometry = getGeometry(data.geometry);
  25177. material = getMaterial(data.material);
  25178. object = new Mesh(geometry, material);
  25179. break;
  25180. case 'InstancedMesh':
  25181. geometry = getGeometry(data.geometry);
  25182. material = getMaterial(data.material);
  25183. var count = data.count;
  25184. var instanceMatrix = data.instanceMatrix;
  25185. object = new InstancedMesh(geometry, material, count);
  25186. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  25187. break;
  25188. case 'LOD':
  25189. object = new LOD();
  25190. break;
  25191. case 'Line':
  25192. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  25193. break;
  25194. case 'LineLoop':
  25195. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  25196. break;
  25197. case 'LineSegments':
  25198. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  25199. break;
  25200. case 'PointCloud':
  25201. case 'Points':
  25202. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  25203. break;
  25204. case 'Sprite':
  25205. object = new Sprite(getMaterial(data.material));
  25206. break;
  25207. case 'Group':
  25208. object = new Group();
  25209. break;
  25210. case 'Bone':
  25211. object = new Bone();
  25212. break;
  25213. default:
  25214. object = new Object3D();
  25215. }
  25216. object.uuid = data.uuid;
  25217. if (data.name !== undefined) object.name = data.name;
  25218. if (data.matrix !== undefined) {
  25219. object.matrix.fromArray(data.matrix);
  25220. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  25221. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  25222. } else {
  25223. if (data.position !== undefined) object.position.fromArray(data.position);
  25224. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  25225. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  25226. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  25227. }
  25228. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  25229. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  25230. if (data.shadow) {
  25231. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  25232. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  25233. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  25234. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  25235. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  25236. }
  25237. if (data.visible !== undefined) object.visible = data.visible;
  25238. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  25239. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  25240. if (data.userData !== undefined) object.userData = data.userData;
  25241. if (data.layers !== undefined) object.layers.mask = data.layers;
  25242. if (data.children !== undefined) {
  25243. var children = data.children;
  25244. for (var i = 0; i < children.length; i++) {
  25245. object.add(this.parseObject(children[i], geometries, materials, animations));
  25246. }
  25247. }
  25248. if (data.animations !== undefined) {
  25249. var objectAnimations = data.animations;
  25250. for (var _i = 0; _i < objectAnimations.length; _i++) {
  25251. var uuid = objectAnimations[_i];
  25252. object.animations.push(animations[uuid]);
  25253. }
  25254. }
  25255. if (data.type === 'LOD') {
  25256. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  25257. var levels = data.levels;
  25258. for (var l = 0; l < levels.length; l++) {
  25259. var level = levels[l];
  25260. var child = object.getObjectByProperty('uuid', level.object);
  25261. if (child !== undefined) {
  25262. object.addLevel(child, level.distance);
  25263. }
  25264. }
  25265. }
  25266. return object;
  25267. };
  25268. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  25269. if (Object.keys(skeletons).length === 0) return;
  25270. object.traverse(function (child) {
  25271. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  25272. var skeleton = skeletons[child.skeleton];
  25273. if (skeleton === undefined) {
  25274. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  25275. } else {
  25276. child.bind(skeleton, child.bindMatrix);
  25277. }
  25278. }
  25279. });
  25280. }
  25281. /* DEPRECATED */
  25282. ;
  25283. _proto.setTexturePath = function setTexturePath(value) {
  25284. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  25285. return this.setResourcePath(value);
  25286. };
  25287. return ObjectLoader;
  25288. }(Loader);
  25289. var TEXTURE_MAPPING = {
  25290. UVMapping: UVMapping,
  25291. CubeReflectionMapping: CubeReflectionMapping,
  25292. CubeRefractionMapping: CubeRefractionMapping,
  25293. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  25294. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  25295. CubeUVReflectionMapping: CubeUVReflectionMapping,
  25296. CubeUVRefractionMapping: CubeUVRefractionMapping
  25297. };
  25298. var TEXTURE_WRAPPING = {
  25299. RepeatWrapping: RepeatWrapping,
  25300. ClampToEdgeWrapping: ClampToEdgeWrapping,
  25301. MirroredRepeatWrapping: MirroredRepeatWrapping
  25302. };
  25303. var TEXTURE_FILTER = {
  25304. NearestFilter: NearestFilter,
  25305. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  25306. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  25307. LinearFilter: LinearFilter,
  25308. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  25309. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  25310. };
  25311. function ImageBitmapLoader(manager) {
  25312. if (typeof createImageBitmap === 'undefined') {
  25313. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  25314. }
  25315. if (typeof fetch === 'undefined') {
  25316. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  25317. }
  25318. Loader.call(this, manager);
  25319. this.options = {
  25320. premultiplyAlpha: 'none'
  25321. };
  25322. }
  25323. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25324. constructor: ImageBitmapLoader,
  25325. isImageBitmapLoader: true,
  25326. setOptions: function setOptions(options) {
  25327. this.options = options;
  25328. return this;
  25329. },
  25330. load: function load(url, onLoad, onProgress, onError) {
  25331. if (url === undefined) url = '';
  25332. if (this.path !== undefined) url = this.path + url;
  25333. url = this.manager.resolveURL(url);
  25334. var scope = this;
  25335. var cached = Cache.get(url);
  25336. if (cached !== undefined) {
  25337. scope.manager.itemStart(url);
  25338. setTimeout(function () {
  25339. if (onLoad) onLoad(cached);
  25340. scope.manager.itemEnd(url);
  25341. }, 0);
  25342. return cached;
  25343. }
  25344. var fetchOptions = {};
  25345. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  25346. fetch(url, fetchOptions).then(function (res) {
  25347. return res.blob();
  25348. }).then(function (blob) {
  25349. return createImageBitmap(blob, scope.options);
  25350. }).then(function (imageBitmap) {
  25351. Cache.add(url, imageBitmap);
  25352. if (onLoad) onLoad(imageBitmap);
  25353. scope.manager.itemEnd(url);
  25354. }).catch(function (e) {
  25355. if (onError) onError(e);
  25356. scope.manager.itemError(url);
  25357. scope.manager.itemEnd(url);
  25358. });
  25359. scope.manager.itemStart(url);
  25360. }
  25361. });
  25362. function ShapePath() {
  25363. this.type = 'ShapePath';
  25364. this.color = new Color();
  25365. this.subPaths = [];
  25366. this.currentPath = null;
  25367. }
  25368. Object.assign(ShapePath.prototype, {
  25369. moveTo: function moveTo(x, y) {
  25370. this.currentPath = new Path();
  25371. this.subPaths.push(this.currentPath);
  25372. this.currentPath.moveTo(x, y);
  25373. return this;
  25374. },
  25375. lineTo: function lineTo(x, y) {
  25376. this.currentPath.lineTo(x, y);
  25377. return this;
  25378. },
  25379. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  25380. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  25381. return this;
  25382. },
  25383. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  25384. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  25385. return this;
  25386. },
  25387. splineThru: function splineThru(pts) {
  25388. this.currentPath.splineThru(pts);
  25389. return this;
  25390. },
  25391. toShapes: function toShapes(isCCW, noHoles) {
  25392. function toShapesNoHoles(inSubpaths) {
  25393. var shapes = [];
  25394. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  25395. var _tmpPath = inSubpaths[i];
  25396. var _tmpShape = new Shape();
  25397. _tmpShape.curves = _tmpPath.curves;
  25398. shapes.push(_tmpShape);
  25399. }
  25400. return shapes;
  25401. }
  25402. function isPointInsidePolygon(inPt, inPolygon) {
  25403. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  25404. // toggling of inside/outside at every single! intersection point of an edge
  25405. // with the horizontal line through inPt, left of inPt
  25406. // not counting lowerY endpoints of edges and whole edges on that line
  25407. var inside = false;
  25408. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  25409. var edgeLowPt = inPolygon[p];
  25410. var edgeHighPt = inPolygon[q];
  25411. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  25412. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25413. if (Math.abs(edgeDy) > Number.EPSILON) {
  25414. // not parallel
  25415. if (edgeDy < 0) {
  25416. edgeLowPt = inPolygon[q];
  25417. edgeDx = -edgeDx;
  25418. edgeHighPt = inPolygon[p];
  25419. edgeDy = -edgeDy;
  25420. }
  25421. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  25422. if (inPt.y === edgeLowPt.y) {
  25423. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  25424. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25425. } else {
  25426. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  25427. if (perpEdge === 0) return true; // inPt is on contour ?
  25428. if (perpEdge < 0) continue;
  25429. inside = !inside; // true intersection left of inPt
  25430. }
  25431. } else {
  25432. // parallel or collinear
  25433. if (inPt.y !== edgeLowPt.y) continue; // parallel
  25434. // edge lies on the same horizontal line as inPt
  25435. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  25436. // continue;
  25437. }
  25438. }
  25439. return inside;
  25440. }
  25441. var isClockWise = ShapeUtils.isClockWise;
  25442. var subPaths = this.subPaths;
  25443. if (subPaths.length === 0) return [];
  25444. if (noHoles === true) return toShapesNoHoles(subPaths);
  25445. var solid, tmpPath, tmpShape;
  25446. var shapes = [];
  25447. if (subPaths.length === 1) {
  25448. tmpPath = subPaths[0];
  25449. tmpShape = new Shape();
  25450. tmpShape.curves = tmpPath.curves;
  25451. shapes.push(tmpShape);
  25452. return shapes;
  25453. }
  25454. var holesFirst = !isClockWise(subPaths[0].getPoints());
  25455. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  25456. var betterShapeHoles = [];
  25457. var newShapes = [];
  25458. var newShapeHoles = [];
  25459. var mainIdx = 0;
  25460. var tmpPoints;
  25461. newShapes[mainIdx] = undefined;
  25462. newShapeHoles[mainIdx] = [];
  25463. for (var i = 0, l = subPaths.length; i < l; i++) {
  25464. tmpPath = subPaths[i];
  25465. tmpPoints = tmpPath.getPoints();
  25466. solid = isClockWise(tmpPoints);
  25467. solid = isCCW ? !solid : solid;
  25468. if (solid) {
  25469. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  25470. newShapes[mainIdx] = {
  25471. s: new Shape(),
  25472. p: tmpPoints
  25473. };
  25474. newShapes[mainIdx].s.curves = tmpPath.curves;
  25475. if (holesFirst) mainIdx++;
  25476. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  25477. } else {
  25478. newShapeHoles[mainIdx].push({
  25479. h: tmpPath,
  25480. p: tmpPoints[0]
  25481. }); //console.log('ccw', i);
  25482. }
  25483. } // only Holes? -> probably all Shapes with wrong orientation
  25484. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  25485. if (newShapes.length > 1) {
  25486. var ambiguous = false;
  25487. var toChange = [];
  25488. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  25489. betterShapeHoles[sIdx] = [];
  25490. }
  25491. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  25492. var sho = newShapeHoles[_sIdx];
  25493. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  25494. var ho = sho[hIdx];
  25495. var hole_unassigned = true;
  25496. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  25497. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  25498. if (_sIdx !== s2Idx) toChange.push({
  25499. froms: _sIdx,
  25500. tos: s2Idx,
  25501. hole: hIdx
  25502. });
  25503. if (hole_unassigned) {
  25504. hole_unassigned = false;
  25505. betterShapeHoles[s2Idx].push(ho);
  25506. } else {
  25507. ambiguous = true;
  25508. }
  25509. }
  25510. }
  25511. if (hole_unassigned) {
  25512. betterShapeHoles[_sIdx].push(ho);
  25513. }
  25514. }
  25515. } // console.log("ambiguous: ", ambiguous);
  25516. if (toChange.length > 0) {
  25517. // console.log("to change: ", toChange);
  25518. if (!ambiguous) newShapeHoles = betterShapeHoles;
  25519. }
  25520. }
  25521. var tmpHoles;
  25522. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  25523. tmpShape = newShapes[_i].s;
  25524. shapes.push(tmpShape);
  25525. tmpHoles = newShapeHoles[_i];
  25526. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  25527. tmpShape.holes.push(tmpHoles[j].h);
  25528. }
  25529. } //console.log("shape", shapes);
  25530. return shapes;
  25531. }
  25532. });
  25533. function Font(data) {
  25534. this.type = 'Font';
  25535. this.data = data;
  25536. }
  25537. Object.assign(Font.prototype, {
  25538. isFont: true,
  25539. generateShapes: function generateShapes(text, size) {
  25540. if (size === void 0) {
  25541. size = 100;
  25542. }
  25543. var shapes = [];
  25544. var paths = createPaths(text, size, this.data);
  25545. for (var p = 0, pl = paths.length; p < pl; p++) {
  25546. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25547. }
  25548. return shapes;
  25549. }
  25550. });
  25551. function createPaths(text, size, data) {
  25552. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25553. var scale = size / data.resolution;
  25554. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25555. var paths = [];
  25556. var offsetX = 0,
  25557. offsetY = 0;
  25558. for (var i = 0; i < chars.length; i++) {
  25559. var char = chars[i];
  25560. if (char === '\n') {
  25561. offsetX = 0;
  25562. offsetY -= line_height;
  25563. } else {
  25564. var ret = createPath(char, scale, offsetX, offsetY, data);
  25565. offsetX += ret.offsetX;
  25566. paths.push(ret.path);
  25567. }
  25568. }
  25569. return paths;
  25570. }
  25571. function createPath(char, scale, offsetX, offsetY, data) {
  25572. var glyph = data.glyphs[char] || data.glyphs['?'];
  25573. if (!glyph) {
  25574. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25575. return;
  25576. }
  25577. var path = new ShapePath();
  25578. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25579. if (glyph.o) {
  25580. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25581. for (var i = 0, l = outline.length; i < l;) {
  25582. var action = outline[i++];
  25583. switch (action) {
  25584. case 'm':
  25585. // moveTo
  25586. x = outline[i++] * scale + offsetX;
  25587. y = outline[i++] * scale + offsetY;
  25588. path.moveTo(x, y);
  25589. break;
  25590. case 'l':
  25591. // lineTo
  25592. x = outline[i++] * scale + offsetX;
  25593. y = outline[i++] * scale + offsetY;
  25594. path.lineTo(x, y);
  25595. break;
  25596. case 'q':
  25597. // quadraticCurveTo
  25598. cpx = outline[i++] * scale + offsetX;
  25599. cpy = outline[i++] * scale + offsetY;
  25600. cpx1 = outline[i++] * scale + offsetX;
  25601. cpy1 = outline[i++] * scale + offsetY;
  25602. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25603. break;
  25604. case 'b':
  25605. // bezierCurveTo
  25606. cpx = outline[i++] * scale + offsetX;
  25607. cpy = outline[i++] * scale + offsetY;
  25608. cpx1 = outline[i++] * scale + offsetX;
  25609. cpy1 = outline[i++] * scale + offsetY;
  25610. cpx2 = outline[i++] * scale + offsetX;
  25611. cpy2 = outline[i++] * scale + offsetY;
  25612. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25613. break;
  25614. }
  25615. }
  25616. }
  25617. return {
  25618. offsetX: glyph.ha * scale,
  25619. path: path
  25620. };
  25621. }
  25622. function FontLoader(manager) {
  25623. Loader.call(this, manager);
  25624. }
  25625. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25626. constructor: FontLoader,
  25627. load: function load(url, onLoad, onProgress, onError) {
  25628. var scope = this;
  25629. var loader = new FileLoader(this.manager);
  25630. loader.setPath(this.path);
  25631. loader.setRequestHeader(this.requestHeader);
  25632. loader.setWithCredentials(scope.withCredentials);
  25633. loader.load(url, function (text) {
  25634. var json;
  25635. try {
  25636. json = JSON.parse(text);
  25637. } catch (e) {
  25638. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25639. json = JSON.parse(text.substring(65, text.length - 2));
  25640. }
  25641. var font = scope.parse(json);
  25642. if (onLoad) onLoad(font);
  25643. }, onProgress, onError);
  25644. },
  25645. parse: function parse(json) {
  25646. return new Font(json);
  25647. }
  25648. });
  25649. var _context;
  25650. var AudioContext = {
  25651. getContext: function getContext() {
  25652. if (_context === undefined) {
  25653. _context = new (window.AudioContext || window.webkitAudioContext)();
  25654. }
  25655. return _context;
  25656. },
  25657. setContext: function setContext(value) {
  25658. _context = value;
  25659. }
  25660. };
  25661. function AudioLoader(manager) {
  25662. Loader.call(this, manager);
  25663. }
  25664. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25665. constructor: AudioLoader,
  25666. load: function load(url, onLoad, onProgress, onError) {
  25667. var scope = this;
  25668. var loader = new FileLoader(scope.manager);
  25669. loader.setResponseType('arraybuffer');
  25670. loader.setPath(scope.path);
  25671. loader.setRequestHeader(scope.requestHeader);
  25672. loader.setWithCredentials(scope.withCredentials);
  25673. loader.load(url, function (buffer) {
  25674. try {
  25675. // Create a copy of the buffer. The `decodeAudioData` method
  25676. // detaches the buffer when complete, preventing reuse.
  25677. var bufferCopy = buffer.slice(0);
  25678. var context = AudioContext.getContext();
  25679. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25680. onLoad(audioBuffer);
  25681. });
  25682. } catch (e) {
  25683. if (onError) {
  25684. onError(e);
  25685. } else {
  25686. console.error(e);
  25687. }
  25688. scope.manager.itemError(url);
  25689. }
  25690. }, onProgress, onError);
  25691. }
  25692. });
  25693. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25694. LightProbe.call(this, undefined, intensity);
  25695. var color1 = new Color().set(skyColor);
  25696. var color2 = new Color().set(groundColor);
  25697. var sky = new Vector3(color1.r, color1.g, color1.b);
  25698. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25699. var c0 = Math.sqrt(Math.PI);
  25700. var c1 = c0 * Math.sqrt(0.75);
  25701. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25702. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25703. }
  25704. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25705. constructor: HemisphereLightProbe,
  25706. isHemisphereLightProbe: true,
  25707. copy: function copy(source) {
  25708. // modifying colors not currently supported
  25709. LightProbe.prototype.copy.call(this, source);
  25710. return this;
  25711. },
  25712. toJSON: function toJSON(meta) {
  25713. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25714. return data;
  25715. }
  25716. });
  25717. function AmbientLightProbe(color, intensity) {
  25718. LightProbe.call(this, undefined, intensity);
  25719. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25720. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25721. }
  25722. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25723. constructor: AmbientLightProbe,
  25724. isAmbientLightProbe: true,
  25725. copy: function copy(source) {
  25726. // modifying color not currently supported
  25727. LightProbe.prototype.copy.call(this, source);
  25728. return this;
  25729. },
  25730. toJSON: function toJSON(meta) {
  25731. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25732. return data;
  25733. }
  25734. });
  25735. var _eyeRight = new Matrix4();
  25736. var _eyeLeft = new Matrix4();
  25737. function StereoCamera() {
  25738. this.type = 'StereoCamera';
  25739. this.aspect = 1;
  25740. this.eyeSep = 0.064;
  25741. this.cameraL = new PerspectiveCamera();
  25742. this.cameraL.layers.enable(1);
  25743. this.cameraL.matrixAutoUpdate = false;
  25744. this.cameraR = new PerspectiveCamera();
  25745. this.cameraR.layers.enable(2);
  25746. this.cameraR.matrixAutoUpdate = false;
  25747. this._cache = {
  25748. focus: null,
  25749. fov: null,
  25750. aspect: null,
  25751. near: null,
  25752. far: null,
  25753. zoom: null,
  25754. eyeSep: null
  25755. };
  25756. }
  25757. Object.assign(StereoCamera.prototype, {
  25758. update: function update(camera) {
  25759. var cache = this._cache;
  25760. 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;
  25761. if (needsUpdate) {
  25762. cache.focus = camera.focus;
  25763. cache.fov = camera.fov;
  25764. cache.aspect = camera.aspect * this.aspect;
  25765. cache.near = camera.near;
  25766. cache.far = camera.far;
  25767. cache.zoom = camera.zoom;
  25768. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25769. // http://paulbourke.net/stereographics/stereorender/
  25770. var projectionMatrix = camera.projectionMatrix.clone();
  25771. var eyeSepHalf = cache.eyeSep / 2;
  25772. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25773. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25774. var xmin, xmax; // translate xOffset
  25775. _eyeLeft.elements[12] = -eyeSepHalf;
  25776. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25777. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25778. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25779. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25780. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25781. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25782. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25783. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25784. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25785. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25786. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25787. }
  25788. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25789. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25790. }
  25791. });
  25792. var Clock = /*#__PURE__*/function () {
  25793. function Clock(autoStart) {
  25794. this.autoStart = autoStart !== undefined ? autoStart : true;
  25795. this.startTime = 0;
  25796. this.oldTime = 0;
  25797. this.elapsedTime = 0;
  25798. this.running = false;
  25799. }
  25800. var _proto = Clock.prototype;
  25801. _proto.start = function start() {
  25802. this.startTime = now();
  25803. this.oldTime = this.startTime;
  25804. this.elapsedTime = 0;
  25805. this.running = true;
  25806. };
  25807. _proto.stop = function stop() {
  25808. this.getElapsedTime();
  25809. this.running = false;
  25810. this.autoStart = false;
  25811. };
  25812. _proto.getElapsedTime = function getElapsedTime() {
  25813. this.getDelta();
  25814. return this.elapsedTime;
  25815. };
  25816. _proto.getDelta = function getDelta() {
  25817. var diff = 0;
  25818. if (this.autoStart && !this.running) {
  25819. this.start();
  25820. return 0;
  25821. }
  25822. if (this.running) {
  25823. var newTime = now();
  25824. diff = (newTime - this.oldTime) / 1000;
  25825. this.oldTime = newTime;
  25826. this.elapsedTime += diff;
  25827. }
  25828. return diff;
  25829. };
  25830. return Clock;
  25831. }();
  25832. function now() {
  25833. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25834. }
  25835. var _position$2 = /*@__PURE__*/new Vector3();
  25836. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25837. var _scale$1 = /*@__PURE__*/new Vector3();
  25838. var _orientation = /*@__PURE__*/new Vector3();
  25839. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25840. _inheritsLoose(AudioListener, _Object3D);
  25841. function AudioListener() {
  25842. var _this;
  25843. _this = _Object3D.call(this) || this;
  25844. _this.type = 'AudioListener';
  25845. _this.context = AudioContext.getContext();
  25846. _this.gain = _this.context.createGain();
  25847. _this.gain.connect(_this.context.destination);
  25848. _this.filter = null;
  25849. _this.timeDelta = 0; // private
  25850. _this._clock = new Clock();
  25851. return _this;
  25852. }
  25853. var _proto = AudioListener.prototype;
  25854. _proto.getInput = function getInput() {
  25855. return this.gain;
  25856. };
  25857. _proto.removeFilter = function removeFilter() {
  25858. if (this.filter !== null) {
  25859. this.gain.disconnect(this.filter);
  25860. this.filter.disconnect(this.context.destination);
  25861. this.gain.connect(this.context.destination);
  25862. this.filter = null;
  25863. }
  25864. return this;
  25865. };
  25866. _proto.getFilter = function getFilter() {
  25867. return this.filter;
  25868. };
  25869. _proto.setFilter = function setFilter(value) {
  25870. if (this.filter !== null) {
  25871. this.gain.disconnect(this.filter);
  25872. this.filter.disconnect(this.context.destination);
  25873. } else {
  25874. this.gain.disconnect(this.context.destination);
  25875. }
  25876. this.filter = value;
  25877. this.gain.connect(this.filter);
  25878. this.filter.connect(this.context.destination);
  25879. return this;
  25880. };
  25881. _proto.getMasterVolume = function getMasterVolume() {
  25882. return this.gain.gain.value;
  25883. };
  25884. _proto.setMasterVolume = function setMasterVolume(value) {
  25885. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25886. return this;
  25887. };
  25888. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25889. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25890. var listener = this.context.listener;
  25891. var up = this.up;
  25892. this.timeDelta = this._clock.getDelta();
  25893. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25894. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25895. if (listener.positionX) {
  25896. // code path for Chrome (see #14393)
  25897. var endTime = this.context.currentTime + this.timeDelta;
  25898. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25899. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25900. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25901. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25902. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25903. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25904. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25905. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25906. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25907. } else {
  25908. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25909. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25910. }
  25911. };
  25912. return AudioListener;
  25913. }(Object3D);
  25914. var Audio = /*#__PURE__*/function (_Object3D) {
  25915. _inheritsLoose(Audio, _Object3D);
  25916. function Audio(listener) {
  25917. var _this;
  25918. _this = _Object3D.call(this) || this;
  25919. _this.type = 'Audio';
  25920. _this.listener = listener;
  25921. _this.context = listener.context;
  25922. _this.gain = _this.context.createGain();
  25923. _this.gain.connect(listener.getInput());
  25924. _this.autoplay = false;
  25925. _this.buffer = null;
  25926. _this.detune = 0;
  25927. _this.loop = false;
  25928. _this.loopStart = 0;
  25929. _this.loopEnd = 0;
  25930. _this.offset = 0;
  25931. _this.duration = undefined;
  25932. _this.playbackRate = 1;
  25933. _this.isPlaying = false;
  25934. _this.hasPlaybackControl = true;
  25935. _this.source = null;
  25936. _this.sourceType = 'empty';
  25937. _this._startedAt = 0;
  25938. _this._progress = 0;
  25939. _this._connected = false;
  25940. _this.filters = [];
  25941. return _this;
  25942. }
  25943. var _proto = Audio.prototype;
  25944. _proto.getOutput = function getOutput() {
  25945. return this.gain;
  25946. };
  25947. _proto.setNodeSource = function setNodeSource(audioNode) {
  25948. this.hasPlaybackControl = false;
  25949. this.sourceType = 'audioNode';
  25950. this.source = audioNode;
  25951. this.connect();
  25952. return this;
  25953. };
  25954. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25955. this.hasPlaybackControl = false;
  25956. this.sourceType = 'mediaNode';
  25957. this.source = this.context.createMediaElementSource(mediaElement);
  25958. this.connect();
  25959. return this;
  25960. };
  25961. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25962. this.hasPlaybackControl = false;
  25963. this.sourceType = 'mediaStreamNode';
  25964. this.source = this.context.createMediaStreamSource(mediaStream);
  25965. this.connect();
  25966. return this;
  25967. };
  25968. _proto.setBuffer = function setBuffer(audioBuffer) {
  25969. this.buffer = audioBuffer;
  25970. this.sourceType = 'buffer';
  25971. if (this.autoplay) this.play();
  25972. return this;
  25973. };
  25974. _proto.play = function play(delay) {
  25975. if (delay === void 0) {
  25976. delay = 0;
  25977. }
  25978. if (this.isPlaying === true) {
  25979. console.warn('THREE.Audio: Audio is already playing.');
  25980. return;
  25981. }
  25982. if (this.hasPlaybackControl === false) {
  25983. console.warn('THREE.Audio: this Audio has no playback control.');
  25984. return;
  25985. }
  25986. this._startedAt = this.context.currentTime + delay;
  25987. var source = this.context.createBufferSource();
  25988. source.buffer = this.buffer;
  25989. source.loop = this.loop;
  25990. source.loopStart = this.loopStart;
  25991. source.loopEnd = this.loopEnd;
  25992. source.onended = this.onEnded.bind(this);
  25993. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25994. this.isPlaying = true;
  25995. this.source = source;
  25996. this.setDetune(this.detune);
  25997. this.setPlaybackRate(this.playbackRate);
  25998. return this.connect();
  25999. };
  26000. _proto.pause = function pause() {
  26001. if (this.hasPlaybackControl === false) {
  26002. console.warn('THREE.Audio: this Audio has no playback control.');
  26003. return;
  26004. }
  26005. if (this.isPlaying === true) {
  26006. // update current progress
  26007. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  26008. if (this.loop === true) {
  26009. // ensure _progress does not exceed duration with looped audios
  26010. this._progress = this._progress % (this.duration || this.buffer.duration);
  26011. }
  26012. this.source.stop();
  26013. this.source.onended = null;
  26014. this.isPlaying = false;
  26015. }
  26016. return this;
  26017. };
  26018. _proto.stop = function stop() {
  26019. if (this.hasPlaybackControl === false) {
  26020. console.warn('THREE.Audio: this Audio has no playback control.');
  26021. return;
  26022. }
  26023. this._progress = 0;
  26024. this.source.stop();
  26025. this.source.onended = null;
  26026. this.isPlaying = false;
  26027. return this;
  26028. };
  26029. _proto.connect = function connect() {
  26030. if (this.filters.length > 0) {
  26031. this.source.connect(this.filters[0]);
  26032. for (var i = 1, l = this.filters.length; i < l; i++) {
  26033. this.filters[i - 1].connect(this.filters[i]);
  26034. }
  26035. this.filters[this.filters.length - 1].connect(this.getOutput());
  26036. } else {
  26037. this.source.connect(this.getOutput());
  26038. }
  26039. this._connected = true;
  26040. return this;
  26041. };
  26042. _proto.disconnect = function disconnect() {
  26043. if (this.filters.length > 0) {
  26044. this.source.disconnect(this.filters[0]);
  26045. for (var i = 1, l = this.filters.length; i < l; i++) {
  26046. this.filters[i - 1].disconnect(this.filters[i]);
  26047. }
  26048. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  26049. } else {
  26050. this.source.disconnect(this.getOutput());
  26051. }
  26052. this._connected = false;
  26053. return this;
  26054. };
  26055. _proto.getFilters = function getFilters() {
  26056. return this.filters;
  26057. };
  26058. _proto.setFilters = function setFilters(value) {
  26059. if (!value) value = [];
  26060. if (this._connected === true) {
  26061. this.disconnect();
  26062. this.filters = value.slice();
  26063. this.connect();
  26064. } else {
  26065. this.filters = value.slice();
  26066. }
  26067. return this;
  26068. };
  26069. _proto.setDetune = function setDetune(value) {
  26070. this.detune = value;
  26071. if (this.source.detune === undefined) return; // only set detune when available
  26072. if (this.isPlaying === true) {
  26073. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  26074. }
  26075. return this;
  26076. };
  26077. _proto.getDetune = function getDetune() {
  26078. return this.detune;
  26079. };
  26080. _proto.getFilter = function getFilter() {
  26081. return this.getFilters()[0];
  26082. };
  26083. _proto.setFilter = function setFilter(filter) {
  26084. return this.setFilters(filter ? [filter] : []);
  26085. };
  26086. _proto.setPlaybackRate = function setPlaybackRate(value) {
  26087. if (this.hasPlaybackControl === false) {
  26088. console.warn('THREE.Audio: this Audio has no playback control.');
  26089. return;
  26090. }
  26091. this.playbackRate = value;
  26092. if (this.isPlaying === true) {
  26093. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  26094. }
  26095. return this;
  26096. };
  26097. _proto.getPlaybackRate = function getPlaybackRate() {
  26098. return this.playbackRate;
  26099. };
  26100. _proto.onEnded = function onEnded() {
  26101. this.isPlaying = false;
  26102. };
  26103. _proto.getLoop = function getLoop() {
  26104. if (this.hasPlaybackControl === false) {
  26105. console.warn('THREE.Audio: this Audio has no playback control.');
  26106. return false;
  26107. }
  26108. return this.loop;
  26109. };
  26110. _proto.setLoop = function setLoop(value) {
  26111. if (this.hasPlaybackControl === false) {
  26112. console.warn('THREE.Audio: this Audio has no playback control.');
  26113. return;
  26114. }
  26115. this.loop = value;
  26116. if (this.isPlaying === true) {
  26117. this.source.loop = this.loop;
  26118. }
  26119. return this;
  26120. };
  26121. _proto.setLoopStart = function setLoopStart(value) {
  26122. this.loopStart = value;
  26123. return this;
  26124. };
  26125. _proto.setLoopEnd = function setLoopEnd(value) {
  26126. this.loopEnd = value;
  26127. return this;
  26128. };
  26129. _proto.getVolume = function getVolume() {
  26130. return this.gain.gain.value;
  26131. };
  26132. _proto.setVolume = function setVolume(value) {
  26133. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  26134. return this;
  26135. };
  26136. return Audio;
  26137. }(Object3D);
  26138. var _position$3 = /*@__PURE__*/new Vector3();
  26139. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  26140. var _scale$2 = /*@__PURE__*/new Vector3();
  26141. var _orientation$1 = /*@__PURE__*/new Vector3();
  26142. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  26143. _inheritsLoose(PositionalAudio, _Audio);
  26144. function PositionalAudio(listener) {
  26145. var _this;
  26146. _this = _Audio.call(this, listener) || this;
  26147. _this.panner = _this.context.createPanner();
  26148. _this.panner.panningModel = 'HRTF';
  26149. _this.panner.connect(_this.gain);
  26150. return _this;
  26151. }
  26152. var _proto = PositionalAudio.prototype;
  26153. _proto.getOutput = function getOutput() {
  26154. return this.panner;
  26155. };
  26156. _proto.getRefDistance = function getRefDistance() {
  26157. return this.panner.refDistance;
  26158. };
  26159. _proto.setRefDistance = function setRefDistance(value) {
  26160. this.panner.refDistance = value;
  26161. return this;
  26162. };
  26163. _proto.getRolloffFactor = function getRolloffFactor() {
  26164. return this.panner.rolloffFactor;
  26165. };
  26166. _proto.setRolloffFactor = function setRolloffFactor(value) {
  26167. this.panner.rolloffFactor = value;
  26168. return this;
  26169. };
  26170. _proto.getDistanceModel = function getDistanceModel() {
  26171. return this.panner.distanceModel;
  26172. };
  26173. _proto.setDistanceModel = function setDistanceModel(value) {
  26174. this.panner.distanceModel = value;
  26175. return this;
  26176. };
  26177. _proto.getMaxDistance = function getMaxDistance() {
  26178. return this.panner.maxDistance;
  26179. };
  26180. _proto.setMaxDistance = function setMaxDistance(value) {
  26181. this.panner.maxDistance = value;
  26182. return this;
  26183. };
  26184. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  26185. this.panner.coneInnerAngle = coneInnerAngle;
  26186. this.panner.coneOuterAngle = coneOuterAngle;
  26187. this.panner.coneOuterGain = coneOuterGain;
  26188. return this;
  26189. };
  26190. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  26191. _Audio.prototype.updateMatrixWorld.call(this, force);
  26192. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  26193. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  26194. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  26195. var panner = this.panner;
  26196. if (panner.positionX) {
  26197. // code path for Chrome and Firefox (see #14393)
  26198. var endTime = this.context.currentTime + this.listener.timeDelta;
  26199. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  26200. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  26201. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  26202. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  26203. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  26204. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  26205. } else {
  26206. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  26207. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  26208. }
  26209. };
  26210. return PositionalAudio;
  26211. }(Audio);
  26212. var AudioAnalyser = /*#__PURE__*/function () {
  26213. function AudioAnalyser(audio, fftSize) {
  26214. if (fftSize === void 0) {
  26215. fftSize = 2048;
  26216. }
  26217. this.analyser = audio.context.createAnalyser();
  26218. this.analyser.fftSize = fftSize;
  26219. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  26220. audio.getOutput().connect(this.analyser);
  26221. }
  26222. var _proto = AudioAnalyser.prototype;
  26223. _proto.getFrequencyData = function getFrequencyData() {
  26224. this.analyser.getByteFrequencyData(this.data);
  26225. return this.data;
  26226. };
  26227. _proto.getAverageFrequency = function getAverageFrequency() {
  26228. var value = 0;
  26229. var data = this.getFrequencyData();
  26230. for (var i = 0; i < data.length; i++) {
  26231. value += data[i];
  26232. }
  26233. return value / data.length;
  26234. };
  26235. return AudioAnalyser;
  26236. }();
  26237. function PropertyMixer(binding, typeName, valueSize) {
  26238. this.binding = binding;
  26239. this.valueSize = valueSize;
  26240. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  26241. //
  26242. // interpolators can use .buffer as their .result
  26243. // the data then goes to 'incoming'
  26244. //
  26245. // 'accu0' and 'accu1' are used frame-interleaved for
  26246. // the cumulative result and are compared to detect
  26247. // changes
  26248. //
  26249. // 'orig' stores the original state of the property
  26250. //
  26251. // 'add' is used for additive cumulative results
  26252. //
  26253. // 'work' is optional and is only present for quaternion types. It is used
  26254. // to store intermediate quaternion multiplication results
  26255. switch (typeName) {
  26256. case 'quaternion':
  26257. mixFunction = this._slerp;
  26258. mixFunctionAdditive = this._slerpAdditive;
  26259. setIdentity = this._setAdditiveIdentityQuaternion;
  26260. this.buffer = new Float64Array(valueSize * 6);
  26261. this._workIndex = 5;
  26262. break;
  26263. case 'string':
  26264. case 'bool':
  26265. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  26266. // additive is not relevant for non-numeric types
  26267. mixFunctionAdditive = this._select;
  26268. setIdentity = this._setAdditiveIdentityOther;
  26269. this.buffer = new Array(valueSize * 5);
  26270. break;
  26271. default:
  26272. mixFunction = this._lerp;
  26273. mixFunctionAdditive = this._lerpAdditive;
  26274. setIdentity = this._setAdditiveIdentityNumeric;
  26275. this.buffer = new Float64Array(valueSize * 5);
  26276. }
  26277. this._mixBufferRegion = mixFunction;
  26278. this._mixBufferRegionAdditive = mixFunctionAdditive;
  26279. this._setIdentity = setIdentity;
  26280. this._origIndex = 3;
  26281. this._addIndex = 4;
  26282. this.cumulativeWeight = 0;
  26283. this.cumulativeWeightAdditive = 0;
  26284. this.useCount = 0;
  26285. this.referenceCount = 0;
  26286. }
  26287. Object.assign(PropertyMixer.prototype, {
  26288. // accumulate data in the 'incoming' region into 'accu<i>'
  26289. accumulate: function accumulate(accuIndex, weight) {
  26290. // note: happily accumulating nothing when weight = 0, the caller knows
  26291. // the weight and shouldn't have made the call in the first place
  26292. var buffer = this.buffer,
  26293. stride = this.valueSize,
  26294. offset = accuIndex * stride + stride;
  26295. var currentWeight = this.cumulativeWeight;
  26296. if (currentWeight === 0) {
  26297. // accuN := incoming * weight
  26298. for (var i = 0; i !== stride; ++i) {
  26299. buffer[offset + i] = buffer[i];
  26300. }
  26301. currentWeight = weight;
  26302. } else {
  26303. // accuN := accuN + incoming * weight
  26304. currentWeight += weight;
  26305. var mix = weight / currentWeight;
  26306. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  26307. }
  26308. this.cumulativeWeight = currentWeight;
  26309. },
  26310. // accumulate data in the 'incoming' region into 'add'
  26311. accumulateAdditive: function accumulateAdditive(weight) {
  26312. var buffer = this.buffer,
  26313. stride = this.valueSize,
  26314. offset = stride * this._addIndex;
  26315. if (this.cumulativeWeightAdditive === 0) {
  26316. // add = identity
  26317. this._setIdentity();
  26318. } // add := add + incoming * weight
  26319. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  26320. this.cumulativeWeightAdditive += weight;
  26321. },
  26322. // apply the state of 'accu<i>' to the binding when accus differ
  26323. apply: function apply(accuIndex) {
  26324. var stride = this.valueSize,
  26325. buffer = this.buffer,
  26326. offset = accuIndex * stride + stride,
  26327. weight = this.cumulativeWeight,
  26328. weightAdditive = this.cumulativeWeightAdditive,
  26329. binding = this.binding;
  26330. this.cumulativeWeight = 0;
  26331. this.cumulativeWeightAdditive = 0;
  26332. if (weight < 1) {
  26333. // accuN := accuN + original * ( 1 - cumulativeWeight )
  26334. var originalValueOffset = stride * this._origIndex;
  26335. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  26336. }
  26337. if (weightAdditive > 0) {
  26338. // accuN := accuN + additive accuN
  26339. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  26340. }
  26341. for (var i = stride, e = stride + stride; i !== e; ++i) {
  26342. if (buffer[i] !== buffer[i + stride]) {
  26343. // value has changed -> update scene graph
  26344. binding.setValue(buffer, offset);
  26345. break;
  26346. }
  26347. }
  26348. },
  26349. // remember the state of the bound property and copy it to both accus
  26350. saveOriginalState: function saveOriginalState() {
  26351. var binding = this.binding;
  26352. var buffer = this.buffer,
  26353. stride = this.valueSize,
  26354. originalValueOffset = stride * this._origIndex;
  26355. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  26356. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  26357. buffer[i] = buffer[originalValueOffset + i % stride];
  26358. } // Add to identity for additive
  26359. this._setIdentity();
  26360. this.cumulativeWeight = 0;
  26361. this.cumulativeWeightAdditive = 0;
  26362. },
  26363. // apply the state previously taken via 'saveOriginalState' to the binding
  26364. restoreOriginalState: function restoreOriginalState() {
  26365. var originalValueOffset = this.valueSize * 3;
  26366. this.binding.setValue(this.buffer, originalValueOffset);
  26367. },
  26368. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  26369. var startIndex = this._addIndex * this.valueSize;
  26370. var endIndex = startIndex + this.valueSize;
  26371. for (var i = startIndex; i < endIndex; i++) {
  26372. this.buffer[i] = 0;
  26373. }
  26374. },
  26375. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  26376. this._setAdditiveIdentityNumeric();
  26377. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  26378. },
  26379. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  26380. var startIndex = this._origIndex * this.valueSize;
  26381. var targetIndex = this._addIndex * this.valueSize;
  26382. for (var i = 0; i < this.valueSize; i++) {
  26383. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  26384. }
  26385. },
  26386. // mix functions
  26387. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  26388. if (t >= 0.5) {
  26389. for (var i = 0; i !== stride; ++i) {
  26390. buffer[dstOffset + i] = buffer[srcOffset + i];
  26391. }
  26392. }
  26393. },
  26394. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  26395. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  26396. },
  26397. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26398. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  26399. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  26400. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  26401. },
  26402. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  26403. var s = 1 - t;
  26404. for (var i = 0; i !== stride; ++i) {
  26405. var j = dstOffset + i;
  26406. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  26407. }
  26408. },
  26409. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26410. for (var i = 0; i !== stride; ++i) {
  26411. var j = dstOffset + i;
  26412. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  26413. }
  26414. }
  26415. });
  26416. // Characters [].:/ are reserved for track binding syntax.
  26417. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26418. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26419. // only latin characters, and the unicode \p{L} is not yet supported. So
  26420. // instead, we exclude reserved characters and match everything else.
  26421. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26422. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26423. // be matched to parse the rest of the track name.
  26424. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26425. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  26426. // characters. Accessor may contain any character except closing bracket.
  26427. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  26428. // contain any non-bracket characters.
  26429. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  26430. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  26431. var _supportedObjectNames = ['material', 'materials', 'bones'];
  26432. function Composite(targetGroup, path, optionalParsedPath) {
  26433. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  26434. this._targetGroup = targetGroup;
  26435. this._bindings = targetGroup.subscribe_(path, parsedPath);
  26436. }
  26437. Object.assign(Composite.prototype, {
  26438. getValue: function getValue(array, offset) {
  26439. this.bind(); // bind all binding
  26440. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26441. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  26442. if (binding !== undefined) binding.getValue(array, offset);
  26443. },
  26444. setValue: function setValue(array, offset) {
  26445. var bindings = this._bindings;
  26446. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26447. bindings[i].setValue(array, offset);
  26448. }
  26449. },
  26450. bind: function bind() {
  26451. var bindings = this._bindings;
  26452. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26453. bindings[i].bind();
  26454. }
  26455. },
  26456. unbind: function unbind() {
  26457. var bindings = this._bindings;
  26458. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26459. bindings[i].unbind();
  26460. }
  26461. }
  26462. });
  26463. function PropertyBinding(rootNode, path, parsedPath) {
  26464. this.path = path;
  26465. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  26466. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  26467. this.rootNode = rootNode;
  26468. }
  26469. Object.assign(PropertyBinding, {
  26470. Composite: Composite,
  26471. create: function create(root, path, parsedPath) {
  26472. if (!(root && root.isAnimationObjectGroup)) {
  26473. return new PropertyBinding(root, path, parsedPath);
  26474. } else {
  26475. return new PropertyBinding.Composite(root, path, parsedPath);
  26476. }
  26477. },
  26478. /**
  26479. * Replaces spaces with underscores and removes unsupported characters from
  26480. * node names, to ensure compatibility with parseTrackName().
  26481. *
  26482. * @param {string} name Node name to be sanitized.
  26483. * @return {string}
  26484. */
  26485. sanitizeNodeName: function sanitizeNodeName(name) {
  26486. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  26487. },
  26488. parseTrackName: function parseTrackName(trackName) {
  26489. var matches = _trackRe.exec(trackName);
  26490. if (!matches) {
  26491. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  26492. }
  26493. var results = {
  26494. // directoryName: matches[ 1 ], // (tschw) currently unused
  26495. nodeName: matches[2],
  26496. objectName: matches[3],
  26497. objectIndex: matches[4],
  26498. propertyName: matches[5],
  26499. // required
  26500. propertyIndex: matches[6]
  26501. };
  26502. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  26503. if (lastDot !== undefined && lastDot !== -1) {
  26504. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  26505. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26506. // 'bar' could be the objectName, or part of a nodeName (which can
  26507. // include '.' characters).
  26508. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  26509. results.nodeName = results.nodeName.substring(0, lastDot);
  26510. results.objectName = objectName;
  26511. }
  26512. }
  26513. if (results.propertyName === null || results.propertyName.length === 0) {
  26514. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  26515. }
  26516. return results;
  26517. },
  26518. findNode: function findNode(root, nodeName) {
  26519. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  26520. return root;
  26521. } // search into skeleton bones.
  26522. if (root.skeleton) {
  26523. var bone = root.skeleton.getBoneByName(nodeName);
  26524. if (bone !== undefined) {
  26525. return bone;
  26526. }
  26527. } // search into node subtree.
  26528. if (root.children) {
  26529. var searchNodeSubtree = function searchNodeSubtree(children) {
  26530. for (var i = 0; i < children.length; i++) {
  26531. var childNode = children[i];
  26532. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  26533. return childNode;
  26534. }
  26535. var result = searchNodeSubtree(childNode.children);
  26536. if (result) return result;
  26537. }
  26538. return null;
  26539. };
  26540. var subTreeNode = searchNodeSubtree(root.children);
  26541. if (subTreeNode) {
  26542. return subTreeNode;
  26543. }
  26544. }
  26545. return null;
  26546. }
  26547. });
  26548. Object.assign(PropertyBinding.prototype, {
  26549. // prototype, continued
  26550. // these are used to "bind" a nonexistent property
  26551. _getValue_unavailable: function _getValue_unavailable() {},
  26552. _setValue_unavailable: function _setValue_unavailable() {},
  26553. BindingType: {
  26554. Direct: 0,
  26555. EntireArray: 1,
  26556. ArrayElement: 2,
  26557. HasFromToArray: 3
  26558. },
  26559. Versioning: {
  26560. None: 0,
  26561. NeedsUpdate: 1,
  26562. MatrixWorldNeedsUpdate: 2
  26563. },
  26564. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26565. buffer[offset] = this.node[this.propertyName];
  26566. }, function getValue_array(buffer, offset) {
  26567. var source = this.resolvedProperty;
  26568. for (var i = 0, n = source.length; i !== n; ++i) {
  26569. buffer[offset++] = source[i];
  26570. }
  26571. }, function getValue_arrayElement(buffer, offset) {
  26572. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26573. }, function getValue_toArray(buffer, offset) {
  26574. this.resolvedProperty.toArray(buffer, offset);
  26575. }],
  26576. SetterByBindingTypeAndVersioning: [[// Direct
  26577. function setValue_direct(buffer, offset) {
  26578. this.targetObject[this.propertyName] = buffer[offset];
  26579. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26580. this.targetObject[this.propertyName] = buffer[offset];
  26581. this.targetObject.needsUpdate = true;
  26582. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26583. this.targetObject[this.propertyName] = buffer[offset];
  26584. this.targetObject.matrixWorldNeedsUpdate = true;
  26585. }], [// EntireArray
  26586. function setValue_array(buffer, offset) {
  26587. var dest = this.resolvedProperty;
  26588. for (var i = 0, n = dest.length; i !== n; ++i) {
  26589. dest[i] = buffer[offset++];
  26590. }
  26591. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26592. var dest = this.resolvedProperty;
  26593. for (var i = 0, n = dest.length; i !== n; ++i) {
  26594. dest[i] = buffer[offset++];
  26595. }
  26596. this.targetObject.needsUpdate = true;
  26597. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26598. var dest = this.resolvedProperty;
  26599. for (var i = 0, n = dest.length; i !== n; ++i) {
  26600. dest[i] = buffer[offset++];
  26601. }
  26602. this.targetObject.matrixWorldNeedsUpdate = true;
  26603. }], [// ArrayElement
  26604. function setValue_arrayElement(buffer, offset) {
  26605. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26606. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26607. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26608. this.targetObject.needsUpdate = true;
  26609. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26610. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26611. this.targetObject.matrixWorldNeedsUpdate = true;
  26612. }], [// HasToFromArray
  26613. function setValue_fromArray(buffer, offset) {
  26614. this.resolvedProperty.fromArray(buffer, offset);
  26615. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26616. this.resolvedProperty.fromArray(buffer, offset);
  26617. this.targetObject.needsUpdate = true;
  26618. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26619. this.resolvedProperty.fromArray(buffer, offset);
  26620. this.targetObject.matrixWorldNeedsUpdate = true;
  26621. }]],
  26622. getValue: function getValue_unbound(targetArray, offset) {
  26623. this.bind();
  26624. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26625. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26626. // prototype version of these methods with one that represents
  26627. // the bound state. When the property is not found, the methods
  26628. // become no-ops.
  26629. },
  26630. setValue: function getValue_unbound(sourceArray, offset) {
  26631. this.bind();
  26632. this.setValue(sourceArray, offset);
  26633. },
  26634. // create getter / setter pair for a property in the scene graph
  26635. bind: function bind() {
  26636. var targetObject = this.node;
  26637. var parsedPath = this.parsedPath;
  26638. var objectName = parsedPath.objectName;
  26639. var propertyName = parsedPath.propertyName;
  26640. var propertyIndex = parsedPath.propertyIndex;
  26641. if (!targetObject) {
  26642. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26643. this.node = targetObject;
  26644. } // set fail state so we can just 'return' on error
  26645. this.getValue = this._getValue_unavailable;
  26646. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26647. if (!targetObject) {
  26648. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26649. return;
  26650. }
  26651. if (objectName) {
  26652. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26653. switch (objectName) {
  26654. case 'materials':
  26655. if (!targetObject.material) {
  26656. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26657. return;
  26658. }
  26659. if (!targetObject.material.materials) {
  26660. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26661. return;
  26662. }
  26663. targetObject = targetObject.material.materials;
  26664. break;
  26665. case 'bones':
  26666. if (!targetObject.skeleton) {
  26667. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26668. return;
  26669. } // potential future optimization: skip this if propertyIndex is already an integer
  26670. // and convert the integer string to a true integer.
  26671. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26672. for (var i = 0; i < targetObject.length; i++) {
  26673. if (targetObject[i].name === objectIndex) {
  26674. objectIndex = i;
  26675. break;
  26676. }
  26677. }
  26678. break;
  26679. default:
  26680. if (targetObject[objectName] === undefined) {
  26681. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26682. return;
  26683. }
  26684. targetObject = targetObject[objectName];
  26685. }
  26686. if (objectIndex !== undefined) {
  26687. if (targetObject[objectIndex] === undefined) {
  26688. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26689. return;
  26690. }
  26691. targetObject = targetObject[objectIndex];
  26692. }
  26693. } // resolve property
  26694. var nodeProperty = targetObject[propertyName];
  26695. if (nodeProperty === undefined) {
  26696. var nodeName = parsedPath.nodeName;
  26697. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26698. return;
  26699. } // determine versioning scheme
  26700. var versioning = this.Versioning.None;
  26701. this.targetObject = targetObject;
  26702. if (targetObject.needsUpdate !== undefined) {
  26703. // material
  26704. versioning = this.Versioning.NeedsUpdate;
  26705. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26706. // node transform
  26707. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26708. } // determine how the property gets bound
  26709. var bindingType = this.BindingType.Direct;
  26710. if (propertyIndex !== undefined) {
  26711. // access a sub element of the property array (only primitives are supported right now)
  26712. if (propertyName === 'morphTargetInfluences') {
  26713. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26714. // support resolving morphTarget names into indices.
  26715. if (!targetObject.geometry) {
  26716. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26717. return;
  26718. }
  26719. if (targetObject.geometry.isBufferGeometry) {
  26720. if (!targetObject.geometry.morphAttributes) {
  26721. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26722. return;
  26723. }
  26724. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26725. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26726. }
  26727. } else {
  26728. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26729. return;
  26730. }
  26731. }
  26732. bindingType = this.BindingType.ArrayElement;
  26733. this.resolvedProperty = nodeProperty;
  26734. this.propertyIndex = propertyIndex;
  26735. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26736. // must use copy for Object3D.Euler/Quaternion
  26737. bindingType = this.BindingType.HasFromToArray;
  26738. this.resolvedProperty = nodeProperty;
  26739. } else if (Array.isArray(nodeProperty)) {
  26740. bindingType = this.BindingType.EntireArray;
  26741. this.resolvedProperty = nodeProperty;
  26742. } else {
  26743. this.propertyName = propertyName;
  26744. } // select getter / setter
  26745. this.getValue = this.GetterByBindingType[bindingType];
  26746. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26747. },
  26748. unbind: function unbind() {
  26749. this.node = null; // back to the prototype version of getValue / setValue
  26750. // note: avoiding to mutate the shape of 'this' via 'delete'
  26751. this.getValue = this._getValue_unbound;
  26752. this.setValue = this._setValue_unbound;
  26753. }
  26754. }); // DECLARE ALIAS AFTER assign prototype
  26755. Object.assign(PropertyBinding.prototype, {
  26756. // initial state of these methods that calls 'bind'
  26757. _getValue_unbound: PropertyBinding.prototype.getValue,
  26758. _setValue_unbound: PropertyBinding.prototype.setValue
  26759. });
  26760. /**
  26761. *
  26762. * A group of objects that receives a shared animation state.
  26763. *
  26764. * Usage:
  26765. *
  26766. * - Add objects you would otherwise pass as 'root' to the
  26767. * constructor or the .clipAction method of AnimationMixer.
  26768. *
  26769. * - Instead pass this object as 'root'.
  26770. *
  26771. * - You can also add and remove objects later when the mixer
  26772. * is running.
  26773. *
  26774. * Note:
  26775. *
  26776. * Objects of this class appear as one object to the mixer,
  26777. * so cache control of the individual objects must be done
  26778. * on the group.
  26779. *
  26780. * Limitation:
  26781. *
  26782. * - The animated properties must be compatible among the
  26783. * all objects in the group.
  26784. *
  26785. * - A single property can either be controlled through a
  26786. * target group or directly, but not both.
  26787. */
  26788. function AnimationObjectGroup() {
  26789. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26790. this._objects = Array.prototype.slice.call(arguments);
  26791. this.nCachedObjects_ = 0; // threshold
  26792. // note: read by PropertyBinding.Composite
  26793. var indices = {};
  26794. this._indicesByUUID = indices; // for bookkeeping
  26795. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26796. indices[arguments[i].uuid] = i;
  26797. }
  26798. this._paths = []; // inside: string
  26799. this._parsedPaths = []; // inside: { we don't care, here }
  26800. this._bindings = []; // inside: Array< PropertyBinding >
  26801. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26802. var scope = this;
  26803. this.stats = {
  26804. objects: {
  26805. get total() {
  26806. return scope._objects.length;
  26807. },
  26808. get inUse() {
  26809. return this.total - scope.nCachedObjects_;
  26810. }
  26811. },
  26812. get bindingsPerObject() {
  26813. return scope._bindings.length;
  26814. }
  26815. };
  26816. }
  26817. Object.assign(AnimationObjectGroup.prototype, {
  26818. isAnimationObjectGroup: true,
  26819. add: function add() {
  26820. var objects = this._objects,
  26821. indicesByUUID = this._indicesByUUID,
  26822. paths = this._paths,
  26823. parsedPaths = this._parsedPaths,
  26824. bindings = this._bindings,
  26825. nBindings = bindings.length;
  26826. var knownObject = undefined,
  26827. nObjects = objects.length,
  26828. nCachedObjects = this.nCachedObjects_;
  26829. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26830. var object = arguments[i],
  26831. uuid = object.uuid;
  26832. var index = indicesByUUID[uuid];
  26833. if (index === undefined) {
  26834. // unknown object -> add it to the ACTIVE region
  26835. index = nObjects++;
  26836. indicesByUUID[uuid] = index;
  26837. objects.push(object); // accounting is done, now do the same for all bindings
  26838. for (var j = 0, m = nBindings; j !== m; ++j) {
  26839. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26840. }
  26841. } else if (index < nCachedObjects) {
  26842. knownObject = objects[index]; // move existing object to the ACTIVE region
  26843. var firstActiveIndex = --nCachedObjects,
  26844. lastCachedObject = objects[firstActiveIndex];
  26845. indicesByUUID[lastCachedObject.uuid] = index;
  26846. objects[index] = lastCachedObject;
  26847. indicesByUUID[uuid] = firstActiveIndex;
  26848. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26849. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26850. var bindingsForPath = bindings[_j],
  26851. lastCached = bindingsForPath[firstActiveIndex];
  26852. var binding = bindingsForPath[index];
  26853. bindingsForPath[index] = lastCached;
  26854. if (binding === undefined) {
  26855. // since we do not bother to create new bindings
  26856. // for objects that are cached, the binding may
  26857. // or may not exist
  26858. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26859. }
  26860. bindingsForPath[firstActiveIndex] = binding;
  26861. }
  26862. } else if (objects[index] !== knownObject) {
  26863. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26864. } // else the object is already where we want it to be
  26865. } // for arguments
  26866. this.nCachedObjects_ = nCachedObjects;
  26867. },
  26868. remove: function remove() {
  26869. var objects = this._objects,
  26870. indicesByUUID = this._indicesByUUID,
  26871. bindings = this._bindings,
  26872. nBindings = bindings.length;
  26873. var nCachedObjects = this.nCachedObjects_;
  26874. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26875. var object = arguments[i],
  26876. uuid = object.uuid,
  26877. index = indicesByUUID[uuid];
  26878. if (index !== undefined && index >= nCachedObjects) {
  26879. // move existing object into the CACHED region
  26880. var lastCachedIndex = nCachedObjects++,
  26881. firstActiveObject = objects[lastCachedIndex];
  26882. indicesByUUID[firstActiveObject.uuid] = index;
  26883. objects[index] = firstActiveObject;
  26884. indicesByUUID[uuid] = lastCachedIndex;
  26885. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26886. for (var j = 0, m = nBindings; j !== m; ++j) {
  26887. var bindingsForPath = bindings[j],
  26888. firstActive = bindingsForPath[lastCachedIndex],
  26889. binding = bindingsForPath[index];
  26890. bindingsForPath[index] = firstActive;
  26891. bindingsForPath[lastCachedIndex] = binding;
  26892. }
  26893. }
  26894. } // for arguments
  26895. this.nCachedObjects_ = nCachedObjects;
  26896. },
  26897. // remove & forget
  26898. uncache: function uncache() {
  26899. var objects = this._objects,
  26900. indicesByUUID = this._indicesByUUID,
  26901. bindings = this._bindings,
  26902. nBindings = bindings.length;
  26903. var nCachedObjects = this.nCachedObjects_,
  26904. nObjects = objects.length;
  26905. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26906. var object = arguments[i],
  26907. uuid = object.uuid,
  26908. index = indicesByUUID[uuid];
  26909. if (index !== undefined) {
  26910. delete indicesByUUID[uuid];
  26911. if (index < nCachedObjects) {
  26912. // object is cached, shrink the CACHED region
  26913. var firstActiveIndex = --nCachedObjects,
  26914. lastCachedObject = objects[firstActiveIndex],
  26915. lastIndex = --nObjects,
  26916. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26917. indicesByUUID[lastCachedObject.uuid] = index;
  26918. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26919. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26920. objects[firstActiveIndex] = lastObject;
  26921. objects.pop(); // accounting is done, now do the same for all bindings
  26922. for (var j = 0, m = nBindings; j !== m; ++j) {
  26923. var bindingsForPath = bindings[j],
  26924. lastCached = bindingsForPath[firstActiveIndex],
  26925. last = bindingsForPath[lastIndex];
  26926. bindingsForPath[index] = lastCached;
  26927. bindingsForPath[firstActiveIndex] = last;
  26928. bindingsForPath.pop();
  26929. }
  26930. } else {
  26931. // object is active, just swap with the last and pop
  26932. var _lastIndex = --nObjects,
  26933. _lastObject = objects[_lastIndex];
  26934. if (_lastIndex > 0) {
  26935. indicesByUUID[_lastObject.uuid] = index;
  26936. }
  26937. objects[index] = _lastObject;
  26938. objects.pop(); // accounting is done, now do the same for all bindings
  26939. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26940. var _bindingsForPath = bindings[_j2];
  26941. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26942. _bindingsForPath.pop();
  26943. }
  26944. } // cached or active
  26945. } // if object is known
  26946. } // for arguments
  26947. this.nCachedObjects_ = nCachedObjects;
  26948. },
  26949. // Internal interface used by befriended PropertyBinding.Composite:
  26950. subscribe_: function subscribe_(path, parsedPath) {
  26951. // returns an array of bindings for the given path that is changed
  26952. // according to the contained objects in the group
  26953. var indicesByPath = this._bindingsIndicesByPath;
  26954. var index = indicesByPath[path];
  26955. var bindings = this._bindings;
  26956. if (index !== undefined) return bindings[index];
  26957. var paths = this._paths,
  26958. parsedPaths = this._parsedPaths,
  26959. objects = this._objects,
  26960. nObjects = objects.length,
  26961. nCachedObjects = this.nCachedObjects_,
  26962. bindingsForPath = new Array(nObjects);
  26963. index = bindings.length;
  26964. indicesByPath[path] = index;
  26965. paths.push(path);
  26966. parsedPaths.push(parsedPath);
  26967. bindings.push(bindingsForPath);
  26968. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26969. var object = objects[i];
  26970. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26971. }
  26972. return bindingsForPath;
  26973. },
  26974. unsubscribe_: function unsubscribe_(path) {
  26975. // tells the group to forget about a property path and no longer
  26976. // update the array previously obtained with 'subscribe_'
  26977. var indicesByPath = this._bindingsIndicesByPath,
  26978. index = indicesByPath[path];
  26979. if (index !== undefined) {
  26980. var paths = this._paths,
  26981. parsedPaths = this._parsedPaths,
  26982. bindings = this._bindings,
  26983. lastBindingsIndex = bindings.length - 1,
  26984. lastBindings = bindings[lastBindingsIndex],
  26985. lastBindingsPath = path[lastBindingsIndex];
  26986. indicesByPath[lastBindingsPath] = index;
  26987. bindings[index] = lastBindings;
  26988. bindings.pop();
  26989. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26990. parsedPaths.pop();
  26991. paths[index] = paths[lastBindingsIndex];
  26992. paths.pop();
  26993. }
  26994. }
  26995. });
  26996. var AnimationAction = /*#__PURE__*/function () {
  26997. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26998. if (localRoot === void 0) {
  26999. localRoot = null;
  27000. }
  27001. if (blendMode === void 0) {
  27002. blendMode = clip.blendMode;
  27003. }
  27004. this._mixer = mixer;
  27005. this._clip = clip;
  27006. this._localRoot = localRoot;
  27007. this.blendMode = blendMode;
  27008. var tracks = clip.tracks,
  27009. nTracks = tracks.length,
  27010. interpolants = new Array(nTracks);
  27011. var interpolantSettings = {
  27012. endingStart: ZeroCurvatureEnding,
  27013. endingEnd: ZeroCurvatureEnding
  27014. };
  27015. for (var i = 0; i !== nTracks; ++i) {
  27016. var interpolant = tracks[i].createInterpolant(null);
  27017. interpolants[i] = interpolant;
  27018. interpolant.settings = interpolantSettings;
  27019. }
  27020. this._interpolantSettings = interpolantSettings;
  27021. this._interpolants = interpolants; // bound by the mixer
  27022. // inside: PropertyMixer (managed by the mixer)
  27023. this._propertyBindings = new Array(nTracks);
  27024. this._cacheIndex = null; // for the memory manager
  27025. this._byClipCacheIndex = null; // for the memory manager
  27026. this._timeScaleInterpolant = null;
  27027. this._weightInterpolant = null;
  27028. this.loop = LoopRepeat;
  27029. this._loopCount = -1; // global mixer time when the action is to be started
  27030. // it's set back to 'null' upon start of the action
  27031. this._startTime = null; // scaled local time of the action
  27032. // gets clamped or wrapped to 0..clip.duration according to loop
  27033. this.time = 0;
  27034. this.timeScale = 1;
  27035. this._effectiveTimeScale = 1;
  27036. this.weight = 1;
  27037. this._effectiveWeight = 1;
  27038. this.repetitions = Infinity; // no. of repetitions when looping
  27039. this.paused = false; // true -> zero effective time scale
  27040. this.enabled = true; // false -> zero effective weight
  27041. this.clampWhenFinished = false; // keep feeding the last frame?
  27042. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  27043. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  27044. } // State & Scheduling
  27045. var _proto = AnimationAction.prototype;
  27046. _proto.play = function play() {
  27047. this._mixer._activateAction(this);
  27048. return this;
  27049. };
  27050. _proto.stop = function stop() {
  27051. this._mixer._deactivateAction(this);
  27052. return this.reset();
  27053. };
  27054. _proto.reset = function reset() {
  27055. this.paused = false;
  27056. this.enabled = true;
  27057. this.time = 0; // restart clip
  27058. this._loopCount = -1; // forget previous loops
  27059. this._startTime = null; // forget scheduling
  27060. return this.stopFading().stopWarping();
  27061. };
  27062. _proto.isRunning = function isRunning() {
  27063. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  27064. } // return true when play has been called
  27065. ;
  27066. _proto.isScheduled = function isScheduled() {
  27067. return this._mixer._isActiveAction(this);
  27068. };
  27069. _proto.startAt = function startAt(time) {
  27070. this._startTime = time;
  27071. return this;
  27072. };
  27073. _proto.setLoop = function setLoop(mode, repetitions) {
  27074. this.loop = mode;
  27075. this.repetitions = repetitions;
  27076. return this;
  27077. } // Weight
  27078. // set the weight stopping any scheduled fading
  27079. // although .enabled = false yields an effective weight of zero, this
  27080. // method does *not* change .enabled, because it would be confusing
  27081. ;
  27082. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  27083. this.weight = weight; // note: same logic as when updated at runtime
  27084. this._effectiveWeight = this.enabled ? weight : 0;
  27085. return this.stopFading();
  27086. } // return the weight considering fading and .enabled
  27087. ;
  27088. _proto.getEffectiveWeight = function getEffectiveWeight() {
  27089. return this._effectiveWeight;
  27090. };
  27091. _proto.fadeIn = function fadeIn(duration) {
  27092. return this._scheduleFading(duration, 0, 1);
  27093. };
  27094. _proto.fadeOut = function fadeOut(duration) {
  27095. return this._scheduleFading(duration, 1, 0);
  27096. };
  27097. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  27098. fadeOutAction.fadeOut(duration);
  27099. this.fadeIn(duration);
  27100. if (warp) {
  27101. var fadeInDuration = this._clip.duration,
  27102. fadeOutDuration = fadeOutAction._clip.duration,
  27103. startEndRatio = fadeOutDuration / fadeInDuration,
  27104. endStartRatio = fadeInDuration / fadeOutDuration;
  27105. fadeOutAction.warp(1.0, startEndRatio, duration);
  27106. this.warp(endStartRatio, 1.0, duration);
  27107. }
  27108. return this;
  27109. };
  27110. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  27111. return fadeInAction.crossFadeFrom(this, duration, warp);
  27112. };
  27113. _proto.stopFading = function stopFading() {
  27114. var weightInterpolant = this._weightInterpolant;
  27115. if (weightInterpolant !== null) {
  27116. this._weightInterpolant = null;
  27117. this._mixer._takeBackControlInterpolant(weightInterpolant);
  27118. }
  27119. return this;
  27120. } // Time Scale Control
  27121. // set the time scale stopping any scheduled warping
  27122. // although .paused = true yields an effective time scale of zero, this
  27123. // method does *not* change .paused, because it would be confusing
  27124. ;
  27125. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  27126. this.timeScale = timeScale;
  27127. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  27128. return this.stopWarping();
  27129. } // return the time scale considering warping and .paused
  27130. ;
  27131. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  27132. return this._effectiveTimeScale;
  27133. };
  27134. _proto.setDuration = function setDuration(duration) {
  27135. this.timeScale = this._clip.duration / duration;
  27136. return this.stopWarping();
  27137. };
  27138. _proto.syncWith = function syncWith(action) {
  27139. this.time = action.time;
  27140. this.timeScale = action.timeScale;
  27141. return this.stopWarping();
  27142. };
  27143. _proto.halt = function halt(duration) {
  27144. return this.warp(this._effectiveTimeScale, 0, duration);
  27145. };
  27146. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  27147. var mixer = this._mixer,
  27148. now = mixer.time,
  27149. timeScale = this.timeScale;
  27150. var interpolant = this._timeScaleInterpolant;
  27151. if (interpolant === null) {
  27152. interpolant = mixer._lendControlInterpolant();
  27153. this._timeScaleInterpolant = interpolant;
  27154. }
  27155. var times = interpolant.parameterPositions,
  27156. values = interpolant.sampleValues;
  27157. times[0] = now;
  27158. times[1] = now + duration;
  27159. values[0] = startTimeScale / timeScale;
  27160. values[1] = endTimeScale / timeScale;
  27161. return this;
  27162. };
  27163. _proto.stopWarping = function stopWarping() {
  27164. var timeScaleInterpolant = this._timeScaleInterpolant;
  27165. if (timeScaleInterpolant !== null) {
  27166. this._timeScaleInterpolant = null;
  27167. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  27168. }
  27169. return this;
  27170. } // Object Accessors
  27171. ;
  27172. _proto.getMixer = function getMixer() {
  27173. return this._mixer;
  27174. };
  27175. _proto.getClip = function getClip() {
  27176. return this._clip;
  27177. };
  27178. _proto.getRoot = function getRoot() {
  27179. return this._localRoot || this._mixer._root;
  27180. } // Interna
  27181. ;
  27182. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  27183. // called by the mixer
  27184. if (!this.enabled) {
  27185. // call ._updateWeight() to update ._effectiveWeight
  27186. this._updateWeight(time);
  27187. return;
  27188. }
  27189. var startTime = this._startTime;
  27190. if (startTime !== null) {
  27191. // check for scheduled start of action
  27192. var timeRunning = (time - startTime) * timeDirection;
  27193. if (timeRunning < 0 || timeDirection === 0) {
  27194. return; // yet to come / don't decide when delta = 0
  27195. } // start
  27196. this._startTime = null; // unschedule
  27197. deltaTime = timeDirection * timeRunning;
  27198. } // apply time scale and advance time
  27199. deltaTime *= this._updateTimeScale(time);
  27200. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  27201. // an effective weight of 0
  27202. var weight = this._updateWeight(time);
  27203. if (weight > 0) {
  27204. var _interpolants = this._interpolants;
  27205. var propertyMixers = this._propertyBindings;
  27206. switch (this.blendMode) {
  27207. case AdditiveAnimationBlendMode:
  27208. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  27209. _interpolants[j].evaluate(clipTime);
  27210. propertyMixers[j].accumulateAdditive(weight);
  27211. }
  27212. break;
  27213. case NormalAnimationBlendMode:
  27214. default:
  27215. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  27216. _interpolants[_j].evaluate(clipTime);
  27217. propertyMixers[_j].accumulate(accuIndex, weight);
  27218. }
  27219. }
  27220. }
  27221. };
  27222. _proto._updateWeight = function _updateWeight(time) {
  27223. var weight = 0;
  27224. if (this.enabled) {
  27225. weight = this.weight;
  27226. var interpolant = this._weightInterpolant;
  27227. if (interpolant !== null) {
  27228. var interpolantValue = interpolant.evaluate(time)[0];
  27229. weight *= interpolantValue;
  27230. if (time > interpolant.parameterPositions[1]) {
  27231. this.stopFading();
  27232. if (interpolantValue === 0) {
  27233. // faded out, disable
  27234. this.enabled = false;
  27235. }
  27236. }
  27237. }
  27238. }
  27239. this._effectiveWeight = weight;
  27240. return weight;
  27241. };
  27242. _proto._updateTimeScale = function _updateTimeScale(time) {
  27243. var timeScale = 0;
  27244. if (!this.paused) {
  27245. timeScale = this.timeScale;
  27246. var interpolant = this._timeScaleInterpolant;
  27247. if (interpolant !== null) {
  27248. var interpolantValue = interpolant.evaluate(time)[0];
  27249. timeScale *= interpolantValue;
  27250. if (time > interpolant.parameterPositions[1]) {
  27251. this.stopWarping();
  27252. if (timeScale === 0) {
  27253. // motion has halted, pause
  27254. this.paused = true;
  27255. } else {
  27256. // warp done - apply final time scale
  27257. this.timeScale = timeScale;
  27258. }
  27259. }
  27260. }
  27261. }
  27262. this._effectiveTimeScale = timeScale;
  27263. return timeScale;
  27264. };
  27265. _proto._updateTime = function _updateTime(deltaTime) {
  27266. var duration = this._clip.duration;
  27267. var loop = this.loop;
  27268. var time = this.time + deltaTime;
  27269. var loopCount = this._loopCount;
  27270. var pingPong = loop === LoopPingPong;
  27271. if (deltaTime === 0) {
  27272. if (loopCount === -1) return time;
  27273. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  27274. }
  27275. if (loop === LoopOnce) {
  27276. if (loopCount === -1) {
  27277. // just started
  27278. this._loopCount = 0;
  27279. this._setEndings(true, true, false);
  27280. }
  27281. handle_stop: {
  27282. if (time >= duration) {
  27283. time = duration;
  27284. } else if (time < 0) {
  27285. time = 0;
  27286. } else {
  27287. this.time = time;
  27288. break handle_stop;
  27289. }
  27290. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27291. this.time = time;
  27292. this._mixer.dispatchEvent({
  27293. type: 'finished',
  27294. action: this,
  27295. direction: deltaTime < 0 ? -1 : 1
  27296. });
  27297. }
  27298. } else {
  27299. // repetitive Repeat or PingPong
  27300. if (loopCount === -1) {
  27301. // just started
  27302. if (deltaTime >= 0) {
  27303. loopCount = 0;
  27304. this._setEndings(true, this.repetitions === 0, pingPong);
  27305. } else {
  27306. // when looping in reverse direction, the initial
  27307. // transition through zero counts as a repetition,
  27308. // so leave loopCount at -1
  27309. this._setEndings(this.repetitions === 0, true, pingPong);
  27310. }
  27311. }
  27312. if (time >= duration || time < 0) {
  27313. // wrap around
  27314. var loopDelta = Math.floor(time / duration); // signed
  27315. time -= duration * loopDelta;
  27316. loopCount += Math.abs(loopDelta);
  27317. var pending = this.repetitions - loopCount;
  27318. if (pending <= 0) {
  27319. // have to stop (switch state, clamp time, fire event)
  27320. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27321. time = deltaTime > 0 ? duration : 0;
  27322. this.time = time;
  27323. this._mixer.dispatchEvent({
  27324. type: 'finished',
  27325. action: this,
  27326. direction: deltaTime > 0 ? 1 : -1
  27327. });
  27328. } else {
  27329. // keep running
  27330. if (pending === 1) {
  27331. // entering the last round
  27332. var atStart = deltaTime < 0;
  27333. this._setEndings(atStart, !atStart, pingPong);
  27334. } else {
  27335. this._setEndings(false, false, pingPong);
  27336. }
  27337. this._loopCount = loopCount;
  27338. this.time = time;
  27339. this._mixer.dispatchEvent({
  27340. type: 'loop',
  27341. action: this,
  27342. loopDelta: loopDelta
  27343. });
  27344. }
  27345. } else {
  27346. this.time = time;
  27347. }
  27348. if (pingPong && (loopCount & 1) === 1) {
  27349. // invert time for the "pong round"
  27350. return duration - time;
  27351. }
  27352. }
  27353. return time;
  27354. };
  27355. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  27356. var settings = this._interpolantSettings;
  27357. if (pingPong) {
  27358. settings.endingStart = ZeroSlopeEnding;
  27359. settings.endingEnd = ZeroSlopeEnding;
  27360. } else {
  27361. // assuming for LoopOnce atStart == atEnd == true
  27362. if (atStart) {
  27363. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27364. } else {
  27365. settings.endingStart = WrapAroundEnding;
  27366. }
  27367. if (atEnd) {
  27368. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27369. } else {
  27370. settings.endingEnd = WrapAroundEnding;
  27371. }
  27372. }
  27373. };
  27374. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  27375. var mixer = this._mixer,
  27376. now = mixer.time;
  27377. var interpolant = this._weightInterpolant;
  27378. if (interpolant === null) {
  27379. interpolant = mixer._lendControlInterpolant();
  27380. this._weightInterpolant = interpolant;
  27381. }
  27382. var times = interpolant.parameterPositions,
  27383. values = interpolant.sampleValues;
  27384. times[0] = now;
  27385. values[0] = weightNow;
  27386. times[1] = now + duration;
  27387. values[1] = weightThen;
  27388. return this;
  27389. };
  27390. return AnimationAction;
  27391. }();
  27392. function AnimationMixer(root) {
  27393. this._root = root;
  27394. this._initMemoryManager();
  27395. this._accuIndex = 0;
  27396. this.time = 0;
  27397. this.timeScale = 1.0;
  27398. }
  27399. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  27400. constructor: AnimationMixer,
  27401. _bindAction: function _bindAction(action, prototypeAction) {
  27402. var root = action._localRoot || this._root,
  27403. tracks = action._clip.tracks,
  27404. nTracks = tracks.length,
  27405. bindings = action._propertyBindings,
  27406. interpolants = action._interpolants,
  27407. rootUuid = root.uuid,
  27408. bindingsByRoot = this._bindingsByRootAndName;
  27409. var bindingsByName = bindingsByRoot[rootUuid];
  27410. if (bindingsByName === undefined) {
  27411. bindingsByName = {};
  27412. bindingsByRoot[rootUuid] = bindingsByName;
  27413. }
  27414. for (var i = 0; i !== nTracks; ++i) {
  27415. var track = tracks[i],
  27416. trackName = track.name;
  27417. var binding = bindingsByName[trackName];
  27418. if (binding !== undefined) {
  27419. bindings[i] = binding;
  27420. } else {
  27421. binding = bindings[i];
  27422. if (binding !== undefined) {
  27423. // existing binding, make sure the cache knows
  27424. if (binding._cacheIndex === null) {
  27425. ++binding.referenceCount;
  27426. this._addInactiveBinding(binding, rootUuid, trackName);
  27427. }
  27428. continue;
  27429. }
  27430. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  27431. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  27432. ++binding.referenceCount;
  27433. this._addInactiveBinding(binding, rootUuid, trackName);
  27434. bindings[i] = binding;
  27435. }
  27436. interpolants[i].resultBuffer = binding.buffer;
  27437. }
  27438. },
  27439. _activateAction: function _activateAction(action) {
  27440. if (!this._isActiveAction(action)) {
  27441. if (action._cacheIndex === null) {
  27442. // this action has been forgotten by the cache, but the user
  27443. // appears to be still using it -> rebind
  27444. var rootUuid = (action._localRoot || this._root).uuid,
  27445. clipUuid = action._clip.uuid,
  27446. actionsForClip = this._actionsByClip[clipUuid];
  27447. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  27448. this._addInactiveAction(action, clipUuid, rootUuid);
  27449. }
  27450. var bindings = action._propertyBindings; // increment reference counts / sort out state
  27451. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27452. var binding = bindings[i];
  27453. if (binding.useCount++ === 0) {
  27454. this._lendBinding(binding);
  27455. binding.saveOriginalState();
  27456. }
  27457. }
  27458. this._lendAction(action);
  27459. }
  27460. },
  27461. _deactivateAction: function _deactivateAction(action) {
  27462. if (this._isActiveAction(action)) {
  27463. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  27464. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27465. var binding = bindings[i];
  27466. if (--binding.useCount === 0) {
  27467. binding.restoreOriginalState();
  27468. this._takeBackBinding(binding);
  27469. }
  27470. }
  27471. this._takeBackAction(action);
  27472. }
  27473. },
  27474. // Memory manager
  27475. _initMemoryManager: function _initMemoryManager() {
  27476. this._actions = []; // 'nActiveActions' followed by inactive ones
  27477. this._nActiveActions = 0;
  27478. this._actionsByClip = {}; // inside:
  27479. // {
  27480. // knownActions: Array< AnimationAction > - used as prototypes
  27481. // actionByRoot: AnimationAction - lookup
  27482. // }
  27483. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27484. this._nActiveBindings = 0;
  27485. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27486. this._controlInterpolants = []; // same game as above
  27487. this._nActiveControlInterpolants = 0;
  27488. var scope = this;
  27489. this.stats = {
  27490. actions: {
  27491. get total() {
  27492. return scope._actions.length;
  27493. },
  27494. get inUse() {
  27495. return scope._nActiveActions;
  27496. }
  27497. },
  27498. bindings: {
  27499. get total() {
  27500. return scope._bindings.length;
  27501. },
  27502. get inUse() {
  27503. return scope._nActiveBindings;
  27504. }
  27505. },
  27506. controlInterpolants: {
  27507. get total() {
  27508. return scope._controlInterpolants.length;
  27509. },
  27510. get inUse() {
  27511. return scope._nActiveControlInterpolants;
  27512. }
  27513. }
  27514. };
  27515. },
  27516. // Memory management for AnimationAction objects
  27517. _isActiveAction: function _isActiveAction(action) {
  27518. var index = action._cacheIndex;
  27519. return index !== null && index < this._nActiveActions;
  27520. },
  27521. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  27522. var actions = this._actions,
  27523. actionsByClip = this._actionsByClip;
  27524. var actionsForClip = actionsByClip[clipUuid];
  27525. if (actionsForClip === undefined) {
  27526. actionsForClip = {
  27527. knownActions: [action],
  27528. actionByRoot: {}
  27529. };
  27530. action._byClipCacheIndex = 0;
  27531. actionsByClip[clipUuid] = actionsForClip;
  27532. } else {
  27533. var knownActions = actionsForClip.knownActions;
  27534. action._byClipCacheIndex = knownActions.length;
  27535. knownActions.push(action);
  27536. }
  27537. action._cacheIndex = actions.length;
  27538. actions.push(action);
  27539. actionsForClip.actionByRoot[rootUuid] = action;
  27540. },
  27541. _removeInactiveAction: function _removeInactiveAction(action) {
  27542. var actions = this._actions,
  27543. lastInactiveAction = actions[actions.length - 1],
  27544. cacheIndex = action._cacheIndex;
  27545. lastInactiveAction._cacheIndex = cacheIndex;
  27546. actions[cacheIndex] = lastInactiveAction;
  27547. actions.pop();
  27548. action._cacheIndex = null;
  27549. var clipUuid = action._clip.uuid,
  27550. actionsByClip = this._actionsByClip,
  27551. actionsForClip = actionsByClip[clipUuid],
  27552. knownActionsForClip = actionsForClip.knownActions,
  27553. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27554. byClipCacheIndex = action._byClipCacheIndex;
  27555. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27556. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27557. knownActionsForClip.pop();
  27558. action._byClipCacheIndex = null;
  27559. var actionByRoot = actionsForClip.actionByRoot,
  27560. rootUuid = (action._localRoot || this._root).uuid;
  27561. delete actionByRoot[rootUuid];
  27562. if (knownActionsForClip.length === 0) {
  27563. delete actionsByClip[clipUuid];
  27564. }
  27565. this._removeInactiveBindingsForAction(action);
  27566. },
  27567. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27568. var bindings = action._propertyBindings;
  27569. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27570. var binding = bindings[i];
  27571. if (--binding.referenceCount === 0) {
  27572. this._removeInactiveBinding(binding);
  27573. }
  27574. }
  27575. },
  27576. _lendAction: function _lendAction(action) {
  27577. // [ active actions | inactive actions ]
  27578. // [ active actions >| inactive actions ]
  27579. // s a
  27580. // <-swap->
  27581. // a s
  27582. var actions = this._actions,
  27583. prevIndex = action._cacheIndex,
  27584. lastActiveIndex = this._nActiveActions++,
  27585. firstInactiveAction = actions[lastActiveIndex];
  27586. action._cacheIndex = lastActiveIndex;
  27587. actions[lastActiveIndex] = action;
  27588. firstInactiveAction._cacheIndex = prevIndex;
  27589. actions[prevIndex] = firstInactiveAction;
  27590. },
  27591. _takeBackAction: function _takeBackAction(action) {
  27592. // [ active actions | inactive actions ]
  27593. // [ active actions |< inactive actions ]
  27594. // a s
  27595. // <-swap->
  27596. // s a
  27597. var actions = this._actions,
  27598. prevIndex = action._cacheIndex,
  27599. firstInactiveIndex = --this._nActiveActions,
  27600. lastActiveAction = actions[firstInactiveIndex];
  27601. action._cacheIndex = firstInactiveIndex;
  27602. actions[firstInactiveIndex] = action;
  27603. lastActiveAction._cacheIndex = prevIndex;
  27604. actions[prevIndex] = lastActiveAction;
  27605. },
  27606. // Memory management for PropertyMixer objects
  27607. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27608. var bindingsByRoot = this._bindingsByRootAndName,
  27609. bindings = this._bindings;
  27610. var bindingByName = bindingsByRoot[rootUuid];
  27611. if (bindingByName === undefined) {
  27612. bindingByName = {};
  27613. bindingsByRoot[rootUuid] = bindingByName;
  27614. }
  27615. bindingByName[trackName] = binding;
  27616. binding._cacheIndex = bindings.length;
  27617. bindings.push(binding);
  27618. },
  27619. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27620. var bindings = this._bindings,
  27621. propBinding = binding.binding,
  27622. rootUuid = propBinding.rootNode.uuid,
  27623. trackName = propBinding.path,
  27624. bindingsByRoot = this._bindingsByRootAndName,
  27625. bindingByName = bindingsByRoot[rootUuid],
  27626. lastInactiveBinding = bindings[bindings.length - 1],
  27627. cacheIndex = binding._cacheIndex;
  27628. lastInactiveBinding._cacheIndex = cacheIndex;
  27629. bindings[cacheIndex] = lastInactiveBinding;
  27630. bindings.pop();
  27631. delete bindingByName[trackName];
  27632. if (Object.keys(bindingByName).length === 0) {
  27633. delete bindingsByRoot[rootUuid];
  27634. }
  27635. },
  27636. _lendBinding: function _lendBinding(binding) {
  27637. var bindings = this._bindings,
  27638. prevIndex = binding._cacheIndex,
  27639. lastActiveIndex = this._nActiveBindings++,
  27640. firstInactiveBinding = bindings[lastActiveIndex];
  27641. binding._cacheIndex = lastActiveIndex;
  27642. bindings[lastActiveIndex] = binding;
  27643. firstInactiveBinding._cacheIndex = prevIndex;
  27644. bindings[prevIndex] = firstInactiveBinding;
  27645. },
  27646. _takeBackBinding: function _takeBackBinding(binding) {
  27647. var bindings = this._bindings,
  27648. prevIndex = binding._cacheIndex,
  27649. firstInactiveIndex = --this._nActiveBindings,
  27650. lastActiveBinding = bindings[firstInactiveIndex];
  27651. binding._cacheIndex = firstInactiveIndex;
  27652. bindings[firstInactiveIndex] = binding;
  27653. lastActiveBinding._cacheIndex = prevIndex;
  27654. bindings[prevIndex] = lastActiveBinding;
  27655. },
  27656. // Memory management of Interpolants for weight and time scale
  27657. _lendControlInterpolant: function _lendControlInterpolant() {
  27658. var interpolants = this._controlInterpolants,
  27659. lastActiveIndex = this._nActiveControlInterpolants++;
  27660. var interpolant = interpolants[lastActiveIndex];
  27661. if (interpolant === undefined) {
  27662. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27663. interpolant.__cacheIndex = lastActiveIndex;
  27664. interpolants[lastActiveIndex] = interpolant;
  27665. }
  27666. return interpolant;
  27667. },
  27668. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27669. var interpolants = this._controlInterpolants,
  27670. prevIndex = interpolant.__cacheIndex,
  27671. firstInactiveIndex = --this._nActiveControlInterpolants,
  27672. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27673. interpolant.__cacheIndex = firstInactiveIndex;
  27674. interpolants[firstInactiveIndex] = interpolant;
  27675. lastActiveInterpolant.__cacheIndex = prevIndex;
  27676. interpolants[prevIndex] = lastActiveInterpolant;
  27677. },
  27678. _controlInterpolantsResultBuffer: new Float32Array(1),
  27679. // return an action for a clip optionally using a custom root target
  27680. // object (this method allocates a lot of dynamic memory in case a
  27681. // previously unknown clip/root combination is specified)
  27682. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27683. var root = optionalRoot || this._root,
  27684. rootUuid = root.uuid;
  27685. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27686. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27687. var actionsForClip = this._actionsByClip[clipUuid];
  27688. var prototypeAction = null;
  27689. if (blendMode === undefined) {
  27690. if (clipObject !== null) {
  27691. blendMode = clipObject.blendMode;
  27692. } else {
  27693. blendMode = NormalAnimationBlendMode;
  27694. }
  27695. }
  27696. if (actionsForClip !== undefined) {
  27697. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27698. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27699. return existingAction;
  27700. } // we know the clip, so we don't have to parse all
  27701. // the bindings again but can just copy
  27702. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27703. if (clipObject === null) clipObject = prototypeAction._clip;
  27704. } // clip must be known when specified via string
  27705. if (clipObject === null) return null; // allocate all resources required to run it
  27706. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27707. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27708. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27709. return newAction;
  27710. },
  27711. // get an existing action
  27712. existingAction: function existingAction(clip, optionalRoot) {
  27713. var root = optionalRoot || this._root,
  27714. rootUuid = root.uuid,
  27715. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27716. clipUuid = clipObject ? clipObject.uuid : clip,
  27717. actionsForClip = this._actionsByClip[clipUuid];
  27718. if (actionsForClip !== undefined) {
  27719. return actionsForClip.actionByRoot[rootUuid] || null;
  27720. }
  27721. return null;
  27722. },
  27723. // deactivates all previously scheduled actions
  27724. stopAllAction: function stopAllAction() {
  27725. var actions = this._actions,
  27726. nActions = this._nActiveActions;
  27727. for (var i = nActions - 1; i >= 0; --i) {
  27728. actions[i].stop();
  27729. }
  27730. return this;
  27731. },
  27732. // advance the time and update apply the animation
  27733. update: function update(deltaTime) {
  27734. deltaTime *= this.timeScale;
  27735. var actions = this._actions,
  27736. nActions = this._nActiveActions,
  27737. time = this.time += deltaTime,
  27738. timeDirection = Math.sign(deltaTime),
  27739. accuIndex = this._accuIndex ^= 1; // run active actions
  27740. for (var i = 0; i !== nActions; ++i) {
  27741. var action = actions[i];
  27742. action._update(time, deltaTime, timeDirection, accuIndex);
  27743. } // update scene graph
  27744. var bindings = this._bindings,
  27745. nBindings = this._nActiveBindings;
  27746. for (var _i = 0; _i !== nBindings; ++_i) {
  27747. bindings[_i].apply(accuIndex);
  27748. }
  27749. return this;
  27750. },
  27751. // Allows you to seek to a specific time in an animation.
  27752. setTime: function setTime(timeInSeconds) {
  27753. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27754. for (var i = 0; i < this._actions.length; i++) {
  27755. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27756. }
  27757. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27758. },
  27759. // return this mixer's root target object
  27760. getRoot: function getRoot() {
  27761. return this._root;
  27762. },
  27763. // free all resources specific to a particular clip
  27764. uncacheClip: function uncacheClip(clip) {
  27765. var actions = this._actions,
  27766. clipUuid = clip.uuid,
  27767. actionsByClip = this._actionsByClip,
  27768. actionsForClip = actionsByClip[clipUuid];
  27769. if (actionsForClip !== undefined) {
  27770. // note: just calling _removeInactiveAction would mess up the
  27771. // iteration state and also require updating the state we can
  27772. // just throw away
  27773. var actionsToRemove = actionsForClip.knownActions;
  27774. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27775. var action = actionsToRemove[i];
  27776. this._deactivateAction(action);
  27777. var cacheIndex = action._cacheIndex,
  27778. lastInactiveAction = actions[actions.length - 1];
  27779. action._cacheIndex = null;
  27780. action._byClipCacheIndex = null;
  27781. lastInactiveAction._cacheIndex = cacheIndex;
  27782. actions[cacheIndex] = lastInactiveAction;
  27783. actions.pop();
  27784. this._removeInactiveBindingsForAction(action);
  27785. }
  27786. delete actionsByClip[clipUuid];
  27787. }
  27788. },
  27789. // free all resources specific to a particular root target object
  27790. uncacheRoot: function uncacheRoot(root) {
  27791. var rootUuid = root.uuid,
  27792. actionsByClip = this._actionsByClip;
  27793. for (var clipUuid in actionsByClip) {
  27794. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27795. action = actionByRoot[rootUuid];
  27796. if (action !== undefined) {
  27797. this._deactivateAction(action);
  27798. this._removeInactiveAction(action);
  27799. }
  27800. }
  27801. var bindingsByRoot = this._bindingsByRootAndName,
  27802. bindingByName = bindingsByRoot[rootUuid];
  27803. if (bindingByName !== undefined) {
  27804. for (var trackName in bindingByName) {
  27805. var binding = bindingByName[trackName];
  27806. binding.restoreOriginalState();
  27807. this._removeInactiveBinding(binding);
  27808. }
  27809. }
  27810. },
  27811. // remove a targeted clip from the cache
  27812. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27813. var action = this.existingAction(clip, optionalRoot);
  27814. if (action !== null) {
  27815. this._deactivateAction(action);
  27816. this._removeInactiveAction(action);
  27817. }
  27818. }
  27819. });
  27820. var Uniform = /*#__PURE__*/function () {
  27821. function Uniform(value) {
  27822. if (typeof value === 'string') {
  27823. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27824. value = arguments[1];
  27825. }
  27826. this.value = value;
  27827. }
  27828. var _proto = Uniform.prototype;
  27829. _proto.clone = function clone() {
  27830. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27831. };
  27832. return Uniform;
  27833. }();
  27834. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27835. InterleavedBuffer.call(this, array, stride);
  27836. this.meshPerAttribute = meshPerAttribute || 1;
  27837. }
  27838. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27839. constructor: InstancedInterleavedBuffer,
  27840. isInstancedInterleavedBuffer: true,
  27841. copy: function copy(source) {
  27842. InterleavedBuffer.prototype.copy.call(this, source);
  27843. this.meshPerAttribute = source.meshPerAttribute;
  27844. return this;
  27845. },
  27846. clone: function clone(data) {
  27847. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27848. ib.meshPerAttribute = this.meshPerAttribute;
  27849. return ib;
  27850. },
  27851. toJSON: function toJSON(data) {
  27852. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27853. json.isInstancedInterleavedBuffer = true;
  27854. json.meshPerAttribute = this.meshPerAttribute;
  27855. return json;
  27856. }
  27857. });
  27858. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27859. this.buffer = buffer;
  27860. this.type = type;
  27861. this.itemSize = itemSize;
  27862. this.elementSize = elementSize;
  27863. this.count = count;
  27864. this.version = 0;
  27865. }
  27866. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27867. set: function set(value) {
  27868. if (value === true) this.version++;
  27869. }
  27870. });
  27871. Object.assign(GLBufferAttribute.prototype, {
  27872. isGLBufferAttribute: true,
  27873. setBuffer: function setBuffer(buffer) {
  27874. this.buffer = buffer;
  27875. return this;
  27876. },
  27877. setType: function setType(type, elementSize) {
  27878. this.type = type;
  27879. this.elementSize = elementSize;
  27880. return this;
  27881. },
  27882. setItemSize: function setItemSize(itemSize) {
  27883. this.itemSize = itemSize;
  27884. return this;
  27885. },
  27886. setCount: function setCount(count) {
  27887. this.count = count;
  27888. return this;
  27889. }
  27890. });
  27891. function Raycaster(origin, direction, near, far) {
  27892. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27893. this.near = near || 0;
  27894. this.far = far || Infinity;
  27895. this.camera = null;
  27896. this.layers = new Layers();
  27897. this.params = {
  27898. Mesh: {},
  27899. Line: {
  27900. threshold: 1
  27901. },
  27902. LOD: {},
  27903. Points: {
  27904. threshold: 1
  27905. },
  27906. Sprite: {}
  27907. };
  27908. Object.defineProperties(this.params, {
  27909. PointCloud: {
  27910. get: function get() {
  27911. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27912. return this.Points;
  27913. }
  27914. }
  27915. });
  27916. }
  27917. function ascSort(a, b) {
  27918. return a.distance - b.distance;
  27919. }
  27920. function _intersectObject(object, raycaster, intersects, recursive) {
  27921. if (object.layers.test(raycaster.layers)) {
  27922. object.raycast(raycaster, intersects);
  27923. }
  27924. if (recursive === true) {
  27925. var children = object.children;
  27926. for (var i = 0, l = children.length; i < l; i++) {
  27927. _intersectObject(children[i], raycaster, intersects, true);
  27928. }
  27929. }
  27930. }
  27931. Object.assign(Raycaster.prototype, {
  27932. set: function set(origin, direction) {
  27933. // direction is assumed to be normalized (for accurate distance calculations)
  27934. this.ray.set(origin, direction);
  27935. },
  27936. setFromCamera: function setFromCamera(coords, camera) {
  27937. if (camera && camera.isPerspectiveCamera) {
  27938. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27939. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27940. this.camera = camera;
  27941. } else if (camera && camera.isOrthographicCamera) {
  27942. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27943. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27944. this.camera = camera;
  27945. } else {
  27946. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27947. }
  27948. },
  27949. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27950. var intersects = optionalTarget || [];
  27951. _intersectObject(object, this, intersects, recursive);
  27952. intersects.sort(ascSort);
  27953. return intersects;
  27954. },
  27955. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27956. var intersects = optionalTarget || [];
  27957. if (Array.isArray(objects) === false) {
  27958. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27959. return intersects;
  27960. }
  27961. for (var i = 0, l = objects.length; i < l; i++) {
  27962. _intersectObject(objects[i], this, intersects, recursive);
  27963. }
  27964. intersects.sort(ascSort);
  27965. return intersects;
  27966. }
  27967. });
  27968. /**
  27969. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27970. *
  27971. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27972. * The azimuthal angle (theta) is measured from the positive z-axis.
  27973. */
  27974. var Spherical = /*#__PURE__*/function () {
  27975. function Spherical(radius, phi, theta) {
  27976. if (radius === void 0) {
  27977. radius = 1;
  27978. }
  27979. if (phi === void 0) {
  27980. phi = 0;
  27981. }
  27982. if (theta === void 0) {
  27983. theta = 0;
  27984. }
  27985. this.radius = radius;
  27986. this.phi = phi; // polar angle
  27987. this.theta = theta; // azimuthal angle
  27988. return this;
  27989. }
  27990. var _proto = Spherical.prototype;
  27991. _proto.set = function set(radius, phi, theta) {
  27992. this.radius = radius;
  27993. this.phi = phi;
  27994. this.theta = theta;
  27995. return this;
  27996. };
  27997. _proto.clone = function clone() {
  27998. return new this.constructor().copy(this);
  27999. };
  28000. _proto.copy = function copy(other) {
  28001. this.radius = other.radius;
  28002. this.phi = other.phi;
  28003. this.theta = other.theta;
  28004. return this;
  28005. } // restrict phi to be betwee EPS and PI-EPS
  28006. ;
  28007. _proto.makeSafe = function makeSafe() {
  28008. var EPS = 0.000001;
  28009. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  28010. return this;
  28011. };
  28012. _proto.setFromVector3 = function setFromVector3(v) {
  28013. return this.setFromCartesianCoords(v.x, v.y, v.z);
  28014. };
  28015. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  28016. this.radius = Math.sqrt(x * x + y * y + z * z);
  28017. if (this.radius === 0) {
  28018. this.theta = 0;
  28019. this.phi = 0;
  28020. } else {
  28021. this.theta = Math.atan2(x, z);
  28022. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  28023. }
  28024. return this;
  28025. };
  28026. return Spherical;
  28027. }();
  28028. /**
  28029. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  28030. */
  28031. var Cylindrical = /*#__PURE__*/function () {
  28032. function Cylindrical(radius, theta, y) {
  28033. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  28034. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  28035. this.y = y !== undefined ? y : 0; // height above the x-z plane
  28036. return this;
  28037. }
  28038. var _proto = Cylindrical.prototype;
  28039. _proto.set = function set(radius, theta, y) {
  28040. this.radius = radius;
  28041. this.theta = theta;
  28042. this.y = y;
  28043. return this;
  28044. };
  28045. _proto.clone = function clone() {
  28046. return new this.constructor().copy(this);
  28047. };
  28048. _proto.copy = function copy(other) {
  28049. this.radius = other.radius;
  28050. this.theta = other.theta;
  28051. this.y = other.y;
  28052. return this;
  28053. };
  28054. _proto.setFromVector3 = function setFromVector3(v) {
  28055. return this.setFromCartesianCoords(v.x, v.y, v.z);
  28056. };
  28057. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  28058. this.radius = Math.sqrt(x * x + z * z);
  28059. this.theta = Math.atan2(x, z);
  28060. this.y = y;
  28061. return this;
  28062. };
  28063. return Cylindrical;
  28064. }();
  28065. var _vector$8 = /*@__PURE__*/new Vector2();
  28066. var Box2 = /*#__PURE__*/function () {
  28067. function Box2(min, max) {
  28068. Object.defineProperty(this, 'isBox2', {
  28069. value: true
  28070. });
  28071. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  28072. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  28073. }
  28074. var _proto = Box2.prototype;
  28075. _proto.set = function set(min, max) {
  28076. this.min.copy(min);
  28077. this.max.copy(max);
  28078. return this;
  28079. };
  28080. _proto.setFromPoints = function setFromPoints(points) {
  28081. this.makeEmpty();
  28082. for (var i = 0, il = points.length; i < il; i++) {
  28083. this.expandByPoint(points[i]);
  28084. }
  28085. return this;
  28086. };
  28087. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  28088. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  28089. this.min.copy(center).sub(halfSize);
  28090. this.max.copy(center).add(halfSize);
  28091. return this;
  28092. };
  28093. _proto.clone = function clone() {
  28094. return new this.constructor().copy(this);
  28095. };
  28096. _proto.copy = function copy(box) {
  28097. this.min.copy(box.min);
  28098. this.max.copy(box.max);
  28099. return this;
  28100. };
  28101. _proto.makeEmpty = function makeEmpty() {
  28102. this.min.x = this.min.y = +Infinity;
  28103. this.max.x = this.max.y = -Infinity;
  28104. return this;
  28105. };
  28106. _proto.isEmpty = function isEmpty() {
  28107. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  28108. return this.max.x < this.min.x || this.max.y < this.min.y;
  28109. };
  28110. _proto.getCenter = function getCenter(target) {
  28111. if (target === undefined) {
  28112. console.warn('THREE.Box2: .getCenter() target is now required');
  28113. target = new Vector2();
  28114. }
  28115. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  28116. };
  28117. _proto.getSize = function getSize(target) {
  28118. if (target === undefined) {
  28119. console.warn('THREE.Box2: .getSize() target is now required');
  28120. target = new Vector2();
  28121. }
  28122. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  28123. };
  28124. _proto.expandByPoint = function expandByPoint(point) {
  28125. this.min.min(point);
  28126. this.max.max(point);
  28127. return this;
  28128. };
  28129. _proto.expandByVector = function expandByVector(vector) {
  28130. this.min.sub(vector);
  28131. this.max.add(vector);
  28132. return this;
  28133. };
  28134. _proto.expandByScalar = function expandByScalar(scalar) {
  28135. this.min.addScalar(-scalar);
  28136. this.max.addScalar(scalar);
  28137. return this;
  28138. };
  28139. _proto.containsPoint = function containsPoint(point) {
  28140. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  28141. };
  28142. _proto.containsBox = function containsBox(box) {
  28143. 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;
  28144. };
  28145. _proto.getParameter = function getParameter(point, target) {
  28146. // This can potentially have a divide by zero if the box
  28147. // has a size dimension of 0.
  28148. if (target === undefined) {
  28149. console.warn('THREE.Box2: .getParameter() target is now required');
  28150. target = new Vector2();
  28151. }
  28152. 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));
  28153. };
  28154. _proto.intersectsBox = function intersectsBox(box) {
  28155. // using 4 splitting planes to rule out intersections
  28156. 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;
  28157. };
  28158. _proto.clampPoint = function clampPoint(point, target) {
  28159. if (target === undefined) {
  28160. console.warn('THREE.Box2: .clampPoint() target is now required');
  28161. target = new Vector2();
  28162. }
  28163. return target.copy(point).clamp(this.min, this.max);
  28164. };
  28165. _proto.distanceToPoint = function distanceToPoint(point) {
  28166. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  28167. return clampedPoint.sub(point).length();
  28168. };
  28169. _proto.intersect = function intersect(box) {
  28170. this.min.max(box.min);
  28171. this.max.min(box.max);
  28172. return this;
  28173. };
  28174. _proto.union = function union(box) {
  28175. this.min.min(box.min);
  28176. this.max.max(box.max);
  28177. return this;
  28178. };
  28179. _proto.translate = function translate(offset) {
  28180. this.min.add(offset);
  28181. this.max.add(offset);
  28182. return this;
  28183. };
  28184. _proto.equals = function equals(box) {
  28185. return box.min.equals(this.min) && box.max.equals(this.max);
  28186. };
  28187. return Box2;
  28188. }();
  28189. var _startP = /*@__PURE__*/new Vector3();
  28190. var _startEnd = /*@__PURE__*/new Vector3();
  28191. var Line3 = /*#__PURE__*/function () {
  28192. function Line3(start, end) {
  28193. this.start = start !== undefined ? start : new Vector3();
  28194. this.end = end !== undefined ? end : new Vector3();
  28195. }
  28196. var _proto = Line3.prototype;
  28197. _proto.set = function set(start, end) {
  28198. this.start.copy(start);
  28199. this.end.copy(end);
  28200. return this;
  28201. };
  28202. _proto.clone = function clone() {
  28203. return new this.constructor().copy(this);
  28204. };
  28205. _proto.copy = function copy(line) {
  28206. this.start.copy(line.start);
  28207. this.end.copy(line.end);
  28208. return this;
  28209. };
  28210. _proto.getCenter = function getCenter(target) {
  28211. if (target === undefined) {
  28212. console.warn('THREE.Line3: .getCenter() target is now required');
  28213. target = new Vector3();
  28214. }
  28215. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  28216. };
  28217. _proto.delta = function delta(target) {
  28218. if (target === undefined) {
  28219. console.warn('THREE.Line3: .delta() target is now required');
  28220. target = new Vector3();
  28221. }
  28222. return target.subVectors(this.end, this.start);
  28223. };
  28224. _proto.distanceSq = function distanceSq() {
  28225. return this.start.distanceToSquared(this.end);
  28226. };
  28227. _proto.distance = function distance() {
  28228. return this.start.distanceTo(this.end);
  28229. };
  28230. _proto.at = function at(t, target) {
  28231. if (target === undefined) {
  28232. console.warn('THREE.Line3: .at() target is now required');
  28233. target = new Vector3();
  28234. }
  28235. return this.delta(target).multiplyScalar(t).add(this.start);
  28236. };
  28237. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  28238. _startP.subVectors(point, this.start);
  28239. _startEnd.subVectors(this.end, this.start);
  28240. var startEnd2 = _startEnd.dot(_startEnd);
  28241. var startEnd_startP = _startEnd.dot(_startP);
  28242. var t = startEnd_startP / startEnd2;
  28243. if (clampToLine) {
  28244. t = MathUtils.clamp(t, 0, 1);
  28245. }
  28246. return t;
  28247. };
  28248. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  28249. var t = this.closestPointToPointParameter(point, clampToLine);
  28250. if (target === undefined) {
  28251. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  28252. target = new Vector3();
  28253. }
  28254. return this.delta(target).multiplyScalar(t).add(this.start);
  28255. };
  28256. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  28257. this.start.applyMatrix4(matrix);
  28258. this.end.applyMatrix4(matrix);
  28259. return this;
  28260. };
  28261. _proto.equals = function equals(line) {
  28262. return line.start.equals(this.start) && line.end.equals(this.end);
  28263. };
  28264. return Line3;
  28265. }();
  28266. function ImmediateRenderObject(material) {
  28267. Object3D.call(this);
  28268. this.material = material;
  28269. this.render = function ()
  28270. /* renderCallback */
  28271. {};
  28272. this.hasPositions = false;
  28273. this.hasNormals = false;
  28274. this.hasColors = false;
  28275. this.hasUvs = false;
  28276. this.positionArray = null;
  28277. this.normalArray = null;
  28278. this.colorArray = null;
  28279. this.uvArray = null;
  28280. this.count = 0;
  28281. }
  28282. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  28283. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  28284. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  28285. var _vector$9 = /*@__PURE__*/new Vector3();
  28286. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  28287. _inheritsLoose(SpotLightHelper, _Object3D);
  28288. function SpotLightHelper(light, color) {
  28289. var _this;
  28290. _this = _Object3D.call(this) || this;
  28291. _this.light = light;
  28292. _this.light.updateMatrixWorld();
  28293. _this.matrix = light.matrixWorld;
  28294. _this.matrixAutoUpdate = false;
  28295. _this.color = color;
  28296. var geometry = new BufferGeometry();
  28297. 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];
  28298. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  28299. var p1 = i / l * Math.PI * 2;
  28300. var p2 = j / l * Math.PI * 2;
  28301. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  28302. }
  28303. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28304. var material = new LineBasicMaterial({
  28305. fog: false,
  28306. toneMapped: false
  28307. });
  28308. _this.cone = new LineSegments(geometry, material);
  28309. _this.add(_this.cone);
  28310. _this.update();
  28311. return _this;
  28312. }
  28313. var _proto = SpotLightHelper.prototype;
  28314. _proto.dispose = function dispose() {
  28315. this.cone.geometry.dispose();
  28316. this.cone.material.dispose();
  28317. };
  28318. _proto.update = function update() {
  28319. this.light.updateMatrixWorld();
  28320. var coneLength = this.light.distance ? this.light.distance : 1000;
  28321. var coneWidth = coneLength * Math.tan(this.light.angle);
  28322. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  28323. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  28324. this.cone.lookAt(_vector$9);
  28325. if (this.color !== undefined) {
  28326. this.cone.material.color.set(this.color);
  28327. } else {
  28328. this.cone.material.color.copy(this.light.color);
  28329. }
  28330. };
  28331. return SpotLightHelper;
  28332. }(Object3D);
  28333. var _vector$a = /*@__PURE__*/new Vector3();
  28334. var _boneMatrix = /*@__PURE__*/new Matrix4();
  28335. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  28336. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  28337. _inheritsLoose(SkeletonHelper, _LineSegments);
  28338. function SkeletonHelper(object) {
  28339. var _this;
  28340. var bones = getBoneList(object);
  28341. var geometry = new BufferGeometry();
  28342. var vertices = [];
  28343. var colors = [];
  28344. var color1 = new Color(0, 0, 1);
  28345. var color2 = new Color(0, 1, 0);
  28346. for (var i = 0; i < bones.length; i++) {
  28347. var bone = bones[i];
  28348. if (bone.parent && bone.parent.isBone) {
  28349. vertices.push(0, 0, 0);
  28350. vertices.push(0, 0, 0);
  28351. colors.push(color1.r, color1.g, color1.b);
  28352. colors.push(color2.r, color2.g, color2.b);
  28353. }
  28354. }
  28355. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28356. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28357. var material = new LineBasicMaterial({
  28358. vertexColors: true,
  28359. depthTest: false,
  28360. depthWrite: false,
  28361. toneMapped: false,
  28362. transparent: true
  28363. });
  28364. _this = _LineSegments.call(this, geometry, material) || this;
  28365. _this.type = 'SkeletonHelper';
  28366. _this.isSkeletonHelper = true;
  28367. _this.root = object;
  28368. _this.bones = bones;
  28369. _this.matrix = object.matrixWorld;
  28370. _this.matrixAutoUpdate = false;
  28371. return _this;
  28372. }
  28373. var _proto = SkeletonHelper.prototype;
  28374. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28375. var bones = this.bones;
  28376. var geometry = this.geometry;
  28377. var position = geometry.getAttribute('position');
  28378. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  28379. for (var i = 0, j = 0; i < bones.length; i++) {
  28380. var bone = bones[i];
  28381. if (bone.parent && bone.parent.isBone) {
  28382. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  28383. _vector$a.setFromMatrixPosition(_boneMatrix);
  28384. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  28385. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  28386. _vector$a.setFromMatrixPosition(_boneMatrix);
  28387. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  28388. j += 2;
  28389. }
  28390. }
  28391. geometry.getAttribute('position').needsUpdate = true;
  28392. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28393. };
  28394. return SkeletonHelper;
  28395. }(LineSegments);
  28396. function getBoneList(object) {
  28397. var boneList = [];
  28398. if (object && object.isBone) {
  28399. boneList.push(object);
  28400. }
  28401. for (var i = 0; i < object.children.length; i++) {
  28402. boneList.push.apply(boneList, getBoneList(object.children[i]));
  28403. }
  28404. return boneList;
  28405. }
  28406. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  28407. _inheritsLoose(PointLightHelper, _Mesh);
  28408. function PointLightHelper(light, sphereSize, color) {
  28409. var _this;
  28410. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  28411. var material = new MeshBasicMaterial({
  28412. wireframe: true,
  28413. fog: false,
  28414. toneMapped: false
  28415. });
  28416. _this = _Mesh.call(this, geometry, material) || this;
  28417. _this.light = light;
  28418. _this.light.updateMatrixWorld();
  28419. _this.color = color;
  28420. _this.type = 'PointLightHelper';
  28421. _this.matrix = _this.light.matrixWorld;
  28422. _this.matrixAutoUpdate = false;
  28423. _this.update();
  28424. /*
  28425. // TODO: delete this comment?
  28426. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28427. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28428. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28429. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28430. const d = light.distance;
  28431. if ( d === 0.0 ) {
  28432. this.lightDistance.visible = false;
  28433. } else {
  28434. this.lightDistance.scale.set( d, d, d );
  28435. }
  28436. this.add( this.lightDistance );
  28437. */
  28438. return _this;
  28439. }
  28440. var _proto = PointLightHelper.prototype;
  28441. _proto.dispose = function dispose() {
  28442. this.geometry.dispose();
  28443. this.material.dispose();
  28444. };
  28445. _proto.update = function update() {
  28446. if (this.color !== undefined) {
  28447. this.material.color.set(this.color);
  28448. } else {
  28449. this.material.color.copy(this.light.color);
  28450. }
  28451. /*
  28452. const d = this.light.distance;
  28453. if ( d === 0.0 ) {
  28454. this.lightDistance.visible = false;
  28455. } else {
  28456. this.lightDistance.visible = true;
  28457. this.lightDistance.scale.set( d, d, d );
  28458. }
  28459. */
  28460. };
  28461. return PointLightHelper;
  28462. }(Mesh);
  28463. var _vector$b = /*@__PURE__*/new Vector3();
  28464. var _color1 = /*@__PURE__*/new Color();
  28465. var _color2 = /*@__PURE__*/new Color();
  28466. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  28467. _inheritsLoose(HemisphereLightHelper, _Object3D);
  28468. function HemisphereLightHelper(light, size, color) {
  28469. var _this;
  28470. _this = _Object3D.call(this) || this;
  28471. _this.light = light;
  28472. _this.light.updateMatrixWorld();
  28473. _this.matrix = light.matrixWorld;
  28474. _this.matrixAutoUpdate = false;
  28475. _this.color = color;
  28476. var geometry = new OctahedronBufferGeometry(size);
  28477. geometry.rotateY(Math.PI * 0.5);
  28478. _this.material = new MeshBasicMaterial({
  28479. wireframe: true,
  28480. fog: false,
  28481. toneMapped: false
  28482. });
  28483. if (_this.color === undefined) _this.material.vertexColors = true;
  28484. var position = geometry.getAttribute('position');
  28485. var colors = new Float32Array(position.count * 3);
  28486. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28487. _this.add(new Mesh(geometry, _this.material));
  28488. _this.update();
  28489. return _this;
  28490. }
  28491. var _proto = HemisphereLightHelper.prototype;
  28492. _proto.dispose = function dispose() {
  28493. this.children[0].geometry.dispose();
  28494. this.children[0].material.dispose();
  28495. };
  28496. _proto.update = function update() {
  28497. var mesh = this.children[0];
  28498. if (this.color !== undefined) {
  28499. this.material.color.set(this.color);
  28500. } else {
  28501. var colors = mesh.geometry.getAttribute('color');
  28502. _color1.copy(this.light.color);
  28503. _color2.copy(this.light.groundColor);
  28504. for (var i = 0, l = colors.count; i < l; i++) {
  28505. var color = i < l / 2 ? _color1 : _color2;
  28506. colors.setXYZ(i, color.r, color.g, color.b);
  28507. }
  28508. colors.needsUpdate = true;
  28509. }
  28510. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  28511. };
  28512. return HemisphereLightHelper;
  28513. }(Object3D);
  28514. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28515. _inheritsLoose(GridHelper, _LineSegments);
  28516. function GridHelper(size, divisions, color1, color2) {
  28517. var _this;
  28518. if (size === void 0) {
  28519. size = 10;
  28520. }
  28521. if (divisions === void 0) {
  28522. divisions = 10;
  28523. }
  28524. if (color1 === void 0) {
  28525. color1 = 0x444444;
  28526. }
  28527. if (color2 === void 0) {
  28528. color2 = 0x888888;
  28529. }
  28530. color1 = new Color(color1);
  28531. color2 = new Color(color2);
  28532. var center = divisions / 2;
  28533. var step = size / divisions;
  28534. var halfSize = size / 2;
  28535. var vertices = [],
  28536. colors = [];
  28537. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28538. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28539. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28540. var color = i === center ? color1 : color2;
  28541. color.toArray(colors, j);
  28542. j += 3;
  28543. color.toArray(colors, j);
  28544. j += 3;
  28545. color.toArray(colors, j);
  28546. j += 3;
  28547. color.toArray(colors, j);
  28548. j += 3;
  28549. }
  28550. var geometry = new BufferGeometry();
  28551. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28552. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28553. var material = new LineBasicMaterial({
  28554. vertexColors: true,
  28555. toneMapped: false
  28556. });
  28557. _this = _LineSegments.call(this, geometry, material) || this;
  28558. _this.type = 'GridHelper';
  28559. return _this;
  28560. }
  28561. return GridHelper;
  28562. }(LineSegments);
  28563. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28564. _inheritsLoose(PolarGridHelper, _LineSegments);
  28565. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28566. var _this;
  28567. if (radius === void 0) {
  28568. radius = 10;
  28569. }
  28570. if (radials === void 0) {
  28571. radials = 16;
  28572. }
  28573. if (circles === void 0) {
  28574. circles = 8;
  28575. }
  28576. if (divisions === void 0) {
  28577. divisions = 64;
  28578. }
  28579. if (color1 === void 0) {
  28580. color1 = 0x444444;
  28581. }
  28582. if (color2 === void 0) {
  28583. color2 = 0x888888;
  28584. }
  28585. color1 = new Color(color1);
  28586. color2 = new Color(color2);
  28587. var vertices = [];
  28588. var colors = []; // create the radials
  28589. for (var i = 0; i <= radials; i++) {
  28590. var v = i / radials * (Math.PI * 2);
  28591. var x = Math.sin(v) * radius;
  28592. var z = Math.cos(v) * radius;
  28593. vertices.push(0, 0, 0);
  28594. vertices.push(x, 0, z);
  28595. var color = i & 1 ? color1 : color2;
  28596. colors.push(color.r, color.g, color.b);
  28597. colors.push(color.r, color.g, color.b);
  28598. } // create the circles
  28599. for (var _i = 0; _i <= circles; _i++) {
  28600. var _color = _i & 1 ? color1 : color2;
  28601. var r = radius - radius / circles * _i;
  28602. for (var j = 0; j < divisions; j++) {
  28603. // first vertex
  28604. var _v = j / divisions * (Math.PI * 2);
  28605. var _x = Math.sin(_v) * r;
  28606. var _z = Math.cos(_v) * r;
  28607. vertices.push(_x, 0, _z);
  28608. colors.push(_color.r, _color.g, _color.b); // second vertex
  28609. _v = (j + 1) / divisions * (Math.PI * 2);
  28610. _x = Math.sin(_v) * r;
  28611. _z = Math.cos(_v) * r;
  28612. vertices.push(_x, 0, _z);
  28613. colors.push(_color.r, _color.g, _color.b);
  28614. }
  28615. }
  28616. var geometry = new BufferGeometry();
  28617. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28618. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28619. var material = new LineBasicMaterial({
  28620. vertexColors: true,
  28621. toneMapped: false
  28622. });
  28623. _this = _LineSegments.call(this, geometry, material) || this;
  28624. _this.type = 'PolarGridHelper';
  28625. return _this;
  28626. }
  28627. return PolarGridHelper;
  28628. }(LineSegments);
  28629. var _v1$6 = /*@__PURE__*/new Vector3();
  28630. var _v2$3 = /*@__PURE__*/new Vector3();
  28631. var _v3$1 = /*@__PURE__*/new Vector3();
  28632. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28633. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28634. function DirectionalLightHelper(light, size, color) {
  28635. var _this;
  28636. _this = _Object3D.call(this) || this;
  28637. _this.light = light;
  28638. _this.light.updateMatrixWorld();
  28639. _this.matrix = light.matrixWorld;
  28640. _this.matrixAutoUpdate = false;
  28641. _this.color = color;
  28642. if (size === undefined) size = 1;
  28643. var geometry = new BufferGeometry();
  28644. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28645. var material = new LineBasicMaterial({
  28646. fog: false,
  28647. toneMapped: false
  28648. });
  28649. _this.lightPlane = new Line(geometry, material);
  28650. _this.add(_this.lightPlane);
  28651. geometry = new BufferGeometry();
  28652. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28653. _this.targetLine = new Line(geometry, material);
  28654. _this.add(_this.targetLine);
  28655. _this.update();
  28656. return _this;
  28657. }
  28658. var _proto = DirectionalLightHelper.prototype;
  28659. _proto.dispose = function dispose() {
  28660. this.lightPlane.geometry.dispose();
  28661. this.lightPlane.material.dispose();
  28662. this.targetLine.geometry.dispose();
  28663. this.targetLine.material.dispose();
  28664. };
  28665. _proto.update = function update() {
  28666. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28667. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28668. _v3$1.subVectors(_v2$3, _v1$6);
  28669. this.lightPlane.lookAt(_v2$3);
  28670. if (this.color !== undefined) {
  28671. this.lightPlane.material.color.set(this.color);
  28672. this.targetLine.material.color.set(this.color);
  28673. } else {
  28674. this.lightPlane.material.color.copy(this.light.color);
  28675. this.targetLine.material.color.copy(this.light.color);
  28676. }
  28677. this.targetLine.lookAt(_v2$3);
  28678. this.targetLine.scale.z = _v3$1.length();
  28679. };
  28680. return DirectionalLightHelper;
  28681. }(Object3D);
  28682. var _vector$c = /*@__PURE__*/new Vector3();
  28683. var _camera = /*@__PURE__*/new Camera();
  28684. /**
  28685. * - shows frustum, line of sight and up of the camera
  28686. * - suitable for fast updates
  28687. * - based on frustum visualization in lightgl.js shadowmap example
  28688. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28689. */
  28690. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28691. _inheritsLoose(CameraHelper, _LineSegments);
  28692. function CameraHelper(camera) {
  28693. var _this;
  28694. var geometry = new BufferGeometry();
  28695. var material = new LineBasicMaterial({
  28696. color: 0xffffff,
  28697. vertexColors: true,
  28698. toneMapped: false
  28699. });
  28700. var vertices = [];
  28701. var colors = [];
  28702. var pointMap = {}; // colors
  28703. var colorFrustum = new Color(0xffaa00);
  28704. var colorCone = new Color(0xff0000);
  28705. var colorUp = new Color(0x00aaff);
  28706. var colorTarget = new Color(0xffffff);
  28707. var colorCross = new Color(0x333333); // near
  28708. addLine('n1', 'n2', colorFrustum);
  28709. addLine('n2', 'n4', colorFrustum);
  28710. addLine('n4', 'n3', colorFrustum);
  28711. addLine('n3', 'n1', colorFrustum); // far
  28712. addLine('f1', 'f2', colorFrustum);
  28713. addLine('f2', 'f4', colorFrustum);
  28714. addLine('f4', 'f3', colorFrustum);
  28715. addLine('f3', 'f1', colorFrustum); // sides
  28716. addLine('n1', 'f1', colorFrustum);
  28717. addLine('n2', 'f2', colorFrustum);
  28718. addLine('n3', 'f3', colorFrustum);
  28719. addLine('n4', 'f4', colorFrustum); // cone
  28720. addLine('p', 'n1', colorCone);
  28721. addLine('p', 'n2', colorCone);
  28722. addLine('p', 'n3', colorCone);
  28723. addLine('p', 'n4', colorCone); // up
  28724. addLine('u1', 'u2', colorUp);
  28725. addLine('u2', 'u3', colorUp);
  28726. addLine('u3', 'u1', colorUp); // target
  28727. addLine('c', 't', colorTarget);
  28728. addLine('p', 'c', colorCross); // cross
  28729. addLine('cn1', 'cn2', colorCross);
  28730. addLine('cn3', 'cn4', colorCross);
  28731. addLine('cf1', 'cf2', colorCross);
  28732. addLine('cf3', 'cf4', colorCross);
  28733. function addLine(a, b, color) {
  28734. addPoint(a, color);
  28735. addPoint(b, color);
  28736. }
  28737. function addPoint(id, color) {
  28738. vertices.push(0, 0, 0);
  28739. colors.push(color.r, color.g, color.b);
  28740. if (pointMap[id] === undefined) {
  28741. pointMap[id] = [];
  28742. }
  28743. pointMap[id].push(vertices.length / 3 - 1);
  28744. }
  28745. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28746. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28747. _this = _LineSegments.call(this, geometry, material) || this;
  28748. _this.type = 'CameraHelper';
  28749. _this.camera = camera;
  28750. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28751. _this.matrix = camera.matrixWorld;
  28752. _this.matrixAutoUpdate = false;
  28753. _this.pointMap = pointMap;
  28754. _this.update();
  28755. return _this;
  28756. }
  28757. var _proto = CameraHelper.prototype;
  28758. _proto.update = function update() {
  28759. var geometry = this.geometry;
  28760. var pointMap = this.pointMap;
  28761. var w = 1,
  28762. h = 1; // we need just camera projection matrix inverse
  28763. // world matrix must be identity
  28764. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28765. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28766. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28767. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28768. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28769. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28770. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28771. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28772. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28773. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28774. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28775. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28776. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28777. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28778. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28779. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28780. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28781. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28782. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28783. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28784. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28785. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28786. geometry.getAttribute('position').needsUpdate = true;
  28787. };
  28788. return CameraHelper;
  28789. }(LineSegments);
  28790. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28791. _vector$c.set(x, y, z).unproject(camera);
  28792. var points = pointMap[point];
  28793. if (points !== undefined) {
  28794. var position = geometry.getAttribute('position');
  28795. for (var i = 0, l = points.length; i < l; i++) {
  28796. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28797. }
  28798. }
  28799. }
  28800. var _box$3 = /*@__PURE__*/new Box3();
  28801. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28802. _inheritsLoose(BoxHelper, _LineSegments);
  28803. function BoxHelper(object, color) {
  28804. var _this;
  28805. if (color === void 0) {
  28806. color = 0xffff00;
  28807. }
  28808. 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]);
  28809. var positions = new Float32Array(8 * 3);
  28810. var geometry = new BufferGeometry();
  28811. geometry.setIndex(new BufferAttribute(indices, 1));
  28812. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28813. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28814. color: color,
  28815. toneMapped: false
  28816. })) || this;
  28817. _this.object = object;
  28818. _this.type = 'BoxHelper';
  28819. _this.matrixAutoUpdate = false;
  28820. _this.update();
  28821. return _this;
  28822. }
  28823. var _proto = BoxHelper.prototype;
  28824. _proto.update = function update(object) {
  28825. if (object !== undefined) {
  28826. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28827. }
  28828. if (this.object !== undefined) {
  28829. _box$3.setFromObject(this.object);
  28830. }
  28831. if (_box$3.isEmpty()) return;
  28832. var min = _box$3.min;
  28833. var max = _box$3.max;
  28834. /*
  28835. 5____4
  28836. 1/___0/|
  28837. | 6__|_7
  28838. 2/___3/
  28839. 0: max.x, max.y, max.z
  28840. 1: min.x, max.y, max.z
  28841. 2: min.x, min.y, max.z
  28842. 3: max.x, min.y, max.z
  28843. 4: max.x, max.y, min.z
  28844. 5: min.x, max.y, min.z
  28845. 6: min.x, min.y, min.z
  28846. 7: max.x, min.y, min.z
  28847. */
  28848. var position = this.geometry.attributes.position;
  28849. var array = position.array;
  28850. array[0] = max.x;
  28851. array[1] = max.y;
  28852. array[2] = max.z;
  28853. array[3] = min.x;
  28854. array[4] = max.y;
  28855. array[5] = max.z;
  28856. array[6] = min.x;
  28857. array[7] = min.y;
  28858. array[8] = max.z;
  28859. array[9] = max.x;
  28860. array[10] = min.y;
  28861. array[11] = max.z;
  28862. array[12] = max.x;
  28863. array[13] = max.y;
  28864. array[14] = min.z;
  28865. array[15] = min.x;
  28866. array[16] = max.y;
  28867. array[17] = min.z;
  28868. array[18] = min.x;
  28869. array[19] = min.y;
  28870. array[20] = min.z;
  28871. array[21] = max.x;
  28872. array[22] = min.y;
  28873. array[23] = min.z;
  28874. position.needsUpdate = true;
  28875. this.geometry.computeBoundingSphere();
  28876. };
  28877. _proto.setFromObject = function setFromObject(object) {
  28878. this.object = object;
  28879. this.update();
  28880. return this;
  28881. };
  28882. _proto.copy = function copy(source) {
  28883. LineSegments.prototype.copy.call(this, source);
  28884. this.object = source.object;
  28885. return this;
  28886. };
  28887. return BoxHelper;
  28888. }(LineSegments);
  28889. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28890. _inheritsLoose(Box3Helper, _LineSegments);
  28891. function Box3Helper(box, color) {
  28892. var _this;
  28893. if (color === void 0) {
  28894. color = 0xffff00;
  28895. }
  28896. 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]);
  28897. 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];
  28898. var geometry = new BufferGeometry();
  28899. geometry.setIndex(new BufferAttribute(indices, 1));
  28900. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28901. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28902. color: color,
  28903. toneMapped: false
  28904. })) || this;
  28905. _this.box = box;
  28906. _this.type = 'Box3Helper';
  28907. _this.geometry.computeBoundingSphere();
  28908. return _this;
  28909. }
  28910. var _proto = Box3Helper.prototype;
  28911. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28912. var box = this.box;
  28913. if (box.isEmpty()) return;
  28914. box.getCenter(this.position);
  28915. box.getSize(this.scale);
  28916. this.scale.multiplyScalar(0.5);
  28917. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28918. };
  28919. return Box3Helper;
  28920. }(LineSegments);
  28921. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28922. _inheritsLoose(PlaneHelper, _Line);
  28923. function PlaneHelper(plane, size, hex) {
  28924. var _this;
  28925. if (size === void 0) {
  28926. size = 1;
  28927. }
  28928. if (hex === void 0) {
  28929. hex = 0xffff00;
  28930. }
  28931. var color = hex;
  28932. 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];
  28933. var geometry = new BufferGeometry();
  28934. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28935. geometry.computeBoundingSphere();
  28936. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28937. color: color,
  28938. toneMapped: false
  28939. })) || this;
  28940. _this.type = 'PlaneHelper';
  28941. _this.plane = plane;
  28942. _this.size = size;
  28943. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28944. var geometry2 = new BufferGeometry();
  28945. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28946. geometry2.computeBoundingSphere();
  28947. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28948. color: color,
  28949. opacity: 0.2,
  28950. transparent: true,
  28951. depthWrite: false,
  28952. toneMapped: false
  28953. })));
  28954. return _this;
  28955. }
  28956. var _proto = PlaneHelper.prototype;
  28957. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28958. var scale = -this.plane.constant;
  28959. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28960. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28961. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28962. this.lookAt(this.plane.normal);
  28963. _Line.prototype.updateMatrixWorld.call(this, force);
  28964. };
  28965. return PlaneHelper;
  28966. }(Line);
  28967. var _axis = /*@__PURE__*/new Vector3();
  28968. var _lineGeometry, _coneGeometry;
  28969. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28970. _inheritsLoose(ArrowHelper, _Object3D);
  28971. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28972. var _this;
  28973. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28974. _this.type = 'ArrowHelper';
  28975. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28976. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28977. if (length === undefined) length = 1;
  28978. if (color === undefined) color = 0xffff00;
  28979. if (headLength === undefined) headLength = 0.2 * length;
  28980. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28981. if (_lineGeometry === undefined) {
  28982. _lineGeometry = new BufferGeometry();
  28983. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28984. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28985. _coneGeometry.translate(0, -0.5, 0);
  28986. }
  28987. _this.position.copy(origin);
  28988. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28989. color: color,
  28990. toneMapped: false
  28991. }));
  28992. _this.line.matrixAutoUpdate = false;
  28993. _this.add(_this.line);
  28994. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28995. color: color,
  28996. toneMapped: false
  28997. }));
  28998. _this.cone.matrixAutoUpdate = false;
  28999. _this.add(_this.cone);
  29000. _this.setDirection(dir);
  29001. _this.setLength(length, headLength, headWidth);
  29002. return _this;
  29003. }
  29004. var _proto = ArrowHelper.prototype;
  29005. _proto.setDirection = function setDirection(dir) {
  29006. // dir is assumed to be normalized
  29007. if (dir.y > 0.99999) {
  29008. this.quaternion.set(0, 0, 0, 1);
  29009. } else if (dir.y < -0.99999) {
  29010. this.quaternion.set(1, 0, 0, 0);
  29011. } else {
  29012. _axis.set(dir.z, 0, -dir.x).normalize();
  29013. var radians = Math.acos(dir.y);
  29014. this.quaternion.setFromAxisAngle(_axis, radians);
  29015. }
  29016. };
  29017. _proto.setLength = function setLength(length, headLength, headWidth) {
  29018. if (headLength === undefined) headLength = 0.2 * length;
  29019. if (headWidth === undefined) headWidth = 0.2 * headLength;
  29020. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  29021. this.line.updateMatrix();
  29022. this.cone.scale.set(headWidth, headLength, headWidth);
  29023. this.cone.position.y = length;
  29024. this.cone.updateMatrix();
  29025. };
  29026. _proto.setColor = function setColor(color) {
  29027. this.line.material.color.set(color);
  29028. this.cone.material.color.set(color);
  29029. };
  29030. _proto.copy = function copy(source) {
  29031. _Object3D.prototype.copy.call(this, source, false);
  29032. this.line.copy(source.line);
  29033. this.cone.copy(source.cone);
  29034. return this;
  29035. };
  29036. return ArrowHelper;
  29037. }(Object3D);
  29038. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  29039. _inheritsLoose(AxesHelper, _LineSegments);
  29040. function AxesHelper(size) {
  29041. var _this;
  29042. if (size === void 0) {
  29043. size = 1;
  29044. }
  29045. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  29046. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  29047. var geometry = new BufferGeometry();
  29048. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  29049. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  29050. var material = new LineBasicMaterial({
  29051. vertexColors: true,
  29052. toneMapped: false
  29053. });
  29054. _this = _LineSegments.call(this, geometry, material) || this;
  29055. _this.type = 'AxesHelper';
  29056. return _this;
  29057. }
  29058. return AxesHelper;
  29059. }(LineSegments);
  29060. var _floatView = new Float32Array(1);
  29061. var _int32View = new Int32Array(_floatView.buffer);
  29062. var DataUtils = {
  29063. // Converts float32 to float16 (stored as uint16 value).
  29064. toHalfFloat: function toHalfFloat(val) {
  29065. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  29066. /* This method is faster than the OpenEXR implementation (very often
  29067. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  29068. * by James Tursa?s half-precision code. */
  29069. _floatView[0] = val;
  29070. var x = _int32View[0];
  29071. var bits = x >> 16 & 0x8000;
  29072. /* Get the sign */
  29073. var m = x >> 12 & 0x07ff;
  29074. /* Keep one extra bit for rounding */
  29075. var e = x >> 23 & 0xff;
  29076. /* Using int is faster here */
  29077. /* If zero, or denormal, or exponent underflows too much for a denormal
  29078. * half, return signed zero. */
  29079. if (e < 103) return bits;
  29080. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  29081. if (e > 142) {
  29082. bits |= 0x7c00;
  29083. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  29084. * not Inf, so make sure we set one mantissa bit too. */
  29085. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  29086. return bits;
  29087. }
  29088. /* If exponent underflows but not too much, return a denormal */
  29089. if (e < 113) {
  29090. m |= 0x0800;
  29091. /* Extra rounding may overflow and set mantissa to 0 and exponent
  29092. * to 1, which is OK. */
  29093. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  29094. return bits;
  29095. }
  29096. bits |= e - 112 << 10 | m >> 1;
  29097. /* Extra rounding. An overflow will set mantissa to 0 and increment
  29098. * the exponent, which is OK. */
  29099. bits += m & 1;
  29100. return bits;
  29101. }
  29102. };
  29103. var _ENCODINGS;
  29104. var LOD_MIN = 4;
  29105. var LOD_MAX = 8;
  29106. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  29107. // chosen to approximate a Trowbridge-Reitz distribution function times the
  29108. // geometric shadowing function. These sigma values squared must match the
  29109. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  29110. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  29111. 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
  29112. // samples and exit early, but not recompile the shader.
  29113. var MAX_SAMPLES = 20;
  29114. 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);
  29115. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  29116. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  29117. _lodPlanes = _createPlanes2._lodPlanes,
  29118. _sizeLods = _createPlanes2._sizeLods,
  29119. _sigmas = _createPlanes2._sigmas;
  29120. var _clearColor = /*@__PURE__*/new Color();
  29121. var _oldTarget = null; // Golden Ratio
  29122. var PHI = (1 + Math.sqrt(5)) / 2;
  29123. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  29124. // same axis), used as axis directions evenly spread on a sphere.
  29125. 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)];
  29126. /**
  29127. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  29128. * (PMREM) from a cubeMap environment texture. This allows different levels of
  29129. * blur to be quickly accessed based on material roughness. It is packed into a
  29130. * special CubeUV format that allows us to perform custom interpolation so that
  29131. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  29132. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  29133. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  29134. * higher roughness levels. In this way we maintain resolution to smoothly
  29135. * interpolate diffuse lighting while limiting sampling computation.
  29136. */
  29137. var PMREMGenerator = /*#__PURE__*/function () {
  29138. function PMREMGenerator(renderer) {
  29139. this._renderer = renderer;
  29140. this._pingPongRenderTarget = null;
  29141. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  29142. this._equirectShader = null;
  29143. this._cubemapShader = null;
  29144. this._compileMaterial(this._blurMaterial);
  29145. }
  29146. /**
  29147. * Generates a PMREM from a supplied Scene, which can be faster than using an
  29148. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  29149. * in radians to be applied to the scene before PMREM generation. Optional near
  29150. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  29151. * is placed at the origin).
  29152. */
  29153. var _proto = PMREMGenerator.prototype;
  29154. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  29155. if (sigma === void 0) {
  29156. sigma = 0;
  29157. }
  29158. if (near === void 0) {
  29159. near = 0.1;
  29160. }
  29161. if (far === void 0) {
  29162. far = 100;
  29163. }
  29164. _oldTarget = this._renderer.getRenderTarget();
  29165. var cubeUVRenderTarget = this._allocateTargets();
  29166. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  29167. if (sigma > 0) {
  29168. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  29169. }
  29170. this._applyPMREM(cubeUVRenderTarget);
  29171. this._cleanup(cubeUVRenderTarget);
  29172. return cubeUVRenderTarget;
  29173. }
  29174. /**
  29175. * Generates a PMREM from an equirectangular texture, which can be either LDR
  29176. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  29177. * as this matches best with the 256 x 256 cubemap output.
  29178. */
  29179. ;
  29180. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  29181. return this._fromTexture(equirectangular);
  29182. }
  29183. /**
  29184. * Generates a PMREM from an cubemap texture, which can be either LDR
  29185. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  29186. * as this matches best with the 256 x 256 cubemap output.
  29187. */
  29188. ;
  29189. _proto.fromCubemap = function fromCubemap(cubemap) {
  29190. return this._fromTexture(cubemap);
  29191. }
  29192. /**
  29193. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  29194. * your texture's network fetch for increased concurrency.
  29195. */
  29196. ;
  29197. _proto.compileCubemapShader = function compileCubemapShader() {
  29198. if (this._cubemapShader === null) {
  29199. this._cubemapShader = _getCubemapShader();
  29200. this._compileMaterial(this._cubemapShader);
  29201. }
  29202. }
  29203. /**
  29204. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  29205. * your texture's network fetch for increased concurrency.
  29206. */
  29207. ;
  29208. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  29209. if (this._equirectShader === null) {
  29210. this._equirectShader = _getEquirectShader();
  29211. this._compileMaterial(this._equirectShader);
  29212. }
  29213. }
  29214. /**
  29215. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  29216. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  29217. * one of them will cause any others to also become unusable.
  29218. */
  29219. ;
  29220. _proto.dispose = function dispose() {
  29221. this._blurMaterial.dispose();
  29222. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  29223. if (this._equirectShader !== null) this._equirectShader.dispose();
  29224. for (var i = 0; i < _lodPlanes.length; i++) {
  29225. _lodPlanes[i].dispose();
  29226. }
  29227. } // private interface
  29228. ;
  29229. _proto._cleanup = function _cleanup(outputTarget) {
  29230. this._pingPongRenderTarget.dispose();
  29231. this._renderer.setRenderTarget(_oldTarget);
  29232. outputTarget.scissorTest = false;
  29233. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  29234. };
  29235. _proto._fromTexture = function _fromTexture(texture) {
  29236. _oldTarget = this._renderer.getRenderTarget();
  29237. var cubeUVRenderTarget = this._allocateTargets(texture);
  29238. this._textureToCubeUV(texture, cubeUVRenderTarget);
  29239. this._applyPMREM(cubeUVRenderTarget);
  29240. this._cleanup(cubeUVRenderTarget);
  29241. return cubeUVRenderTarget;
  29242. };
  29243. _proto._allocateTargets = function _allocateTargets(texture) {
  29244. // warning: null texture is valid
  29245. var params = {
  29246. magFilter: NearestFilter,
  29247. minFilter: NearestFilter,
  29248. generateMipmaps: false,
  29249. type: UnsignedByteType,
  29250. format: RGBEFormat,
  29251. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  29252. depthBuffer: false
  29253. };
  29254. var cubeUVRenderTarget = _createRenderTarget(params);
  29255. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  29256. this._pingPongRenderTarget = _createRenderTarget(params);
  29257. return cubeUVRenderTarget;
  29258. };
  29259. _proto._compileMaterial = function _compileMaterial(material) {
  29260. var tmpMesh = new Mesh(_lodPlanes[0], material);
  29261. this._renderer.compile(tmpMesh, _flatCamera);
  29262. };
  29263. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  29264. var fov = 90;
  29265. var aspect = 1;
  29266. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  29267. var upSign = [1, -1, 1, 1, 1, 1];
  29268. var forwardSign = [1, 1, 1, -1, -1, -1];
  29269. var renderer = this._renderer;
  29270. var outputEncoding = renderer.outputEncoding;
  29271. var toneMapping = renderer.toneMapping;
  29272. renderer.getClearColor(_clearColor);
  29273. var clearAlpha = renderer.getClearAlpha();
  29274. renderer.toneMapping = NoToneMapping;
  29275. renderer.outputEncoding = LinearEncoding;
  29276. var background = scene.background;
  29277. if (background && background.isColor) {
  29278. background.convertSRGBToLinear(); // Convert linear to RGBE
  29279. var maxComponent = Math.max(background.r, background.g, background.b);
  29280. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  29281. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  29282. var alpha = (fExp + 128.0) / 255.0;
  29283. renderer.setClearColor(background, alpha);
  29284. scene.background = null;
  29285. }
  29286. for (var i = 0; i < 6; i++) {
  29287. var col = i % 3;
  29288. if (col == 0) {
  29289. cubeCamera.up.set(0, upSign[i], 0);
  29290. cubeCamera.lookAt(forwardSign[i], 0, 0);
  29291. } else if (col == 1) {
  29292. cubeCamera.up.set(0, 0, upSign[i]);
  29293. cubeCamera.lookAt(0, forwardSign[i], 0);
  29294. } else {
  29295. cubeCamera.up.set(0, upSign[i], 0);
  29296. cubeCamera.lookAt(0, 0, forwardSign[i]);
  29297. }
  29298. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  29299. renderer.setRenderTarget(cubeUVRenderTarget);
  29300. renderer.render(scene, cubeCamera);
  29301. }
  29302. renderer.toneMapping = toneMapping;
  29303. renderer.outputEncoding = outputEncoding;
  29304. renderer.setClearColor(_clearColor, clearAlpha);
  29305. };
  29306. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  29307. var renderer = this._renderer;
  29308. if (texture.isCubeTexture) {
  29309. if (this._cubemapShader == null) {
  29310. this._cubemapShader = _getCubemapShader();
  29311. }
  29312. } else {
  29313. if (this._equirectShader == null) {
  29314. this._equirectShader = _getEquirectShader();
  29315. }
  29316. }
  29317. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  29318. var mesh = new Mesh(_lodPlanes[0], material);
  29319. var uniforms = material.uniforms;
  29320. uniforms['envMap'].value = texture;
  29321. if (!texture.isCubeTexture) {
  29322. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  29323. }
  29324. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  29325. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  29326. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  29327. renderer.setRenderTarget(cubeUVRenderTarget);
  29328. renderer.render(mesh, _flatCamera);
  29329. };
  29330. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  29331. var renderer = this._renderer;
  29332. var autoClear = renderer.autoClear;
  29333. renderer.autoClear = false;
  29334. for (var i = 1; i < TOTAL_LODS; i++) {
  29335. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  29336. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  29337. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  29338. }
  29339. renderer.autoClear = autoClear;
  29340. }
  29341. /**
  29342. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  29343. * vertically and horizontally, but this breaks down on a cube. Here we apply
  29344. * the blur latitudinally (around the poles), and then longitudinally (towards
  29345. * the poles) to approximate the orthogonally-separable blur. It is least
  29346. * accurate at the poles, but still does a decent job.
  29347. */
  29348. ;
  29349. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  29350. var pingPongRenderTarget = this._pingPongRenderTarget;
  29351. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  29352. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  29353. };
  29354. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  29355. var renderer = this._renderer;
  29356. var blurMaterial = this._blurMaterial;
  29357. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  29358. console.error('blur direction must be either latitudinal or longitudinal!');
  29359. } // Number of standard deviations at which to cut off the discrete approximation.
  29360. var STANDARD_DEVIATIONS = 3;
  29361. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  29362. var blurUniforms = blurMaterial.uniforms;
  29363. var pixels = _sizeLods[lodIn] - 1;
  29364. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  29365. var sigmaPixels = sigmaRadians / radiansPerPixel;
  29366. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  29367. if (samples > MAX_SAMPLES) {
  29368. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  29369. }
  29370. var weights = [];
  29371. var sum = 0;
  29372. for (var i = 0; i < MAX_SAMPLES; ++i) {
  29373. var _x = i / sigmaPixels;
  29374. var weight = Math.exp(-_x * _x / 2);
  29375. weights.push(weight);
  29376. if (i == 0) {
  29377. sum += weight;
  29378. } else if (i < samples) {
  29379. sum += 2 * weight;
  29380. }
  29381. }
  29382. for (var _i = 0; _i < weights.length; _i++) {
  29383. weights[_i] = weights[_i] / sum;
  29384. }
  29385. blurUniforms['envMap'].value = targetIn.texture;
  29386. blurUniforms['samples'].value = samples;
  29387. blurUniforms['weights'].value = weights;
  29388. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  29389. if (poleAxis) {
  29390. blurUniforms['poleAxis'].value = poleAxis;
  29391. }
  29392. blurUniforms['dTheta'].value = radiansPerPixel;
  29393. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  29394. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29395. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29396. var outputSize = _sizeLods[lodOut];
  29397. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  29398. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  29399. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  29400. renderer.setRenderTarget(targetOut);
  29401. renderer.render(blurMesh, _flatCamera);
  29402. };
  29403. return PMREMGenerator;
  29404. }();
  29405. function _isLDR(texture) {
  29406. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  29407. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29408. }
  29409. function _createPlanes() {
  29410. var _lodPlanes = [];
  29411. var _sizeLods = [];
  29412. var _sigmas = [];
  29413. var lod = LOD_MAX;
  29414. for (var i = 0; i < TOTAL_LODS; i++) {
  29415. var sizeLod = Math.pow(2, lod);
  29416. _sizeLods.push(sizeLod);
  29417. var sigma = 1.0 / sizeLod;
  29418. if (i > LOD_MAX - LOD_MIN) {
  29419. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  29420. } else if (i == 0) {
  29421. sigma = 0;
  29422. }
  29423. _sigmas.push(sigma);
  29424. var texelSize = 1.0 / (sizeLod - 1);
  29425. var min = -texelSize / 2;
  29426. var max = 1 + texelSize / 2;
  29427. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  29428. var cubeFaces = 6;
  29429. var vertices = 6;
  29430. var positionSize = 3;
  29431. var uvSize = 2;
  29432. var faceIndexSize = 1;
  29433. var position = new Float32Array(positionSize * vertices * cubeFaces);
  29434. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  29435. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  29436. for (var face = 0; face < cubeFaces; face++) {
  29437. var x = face % 3 * 2 / 3 - 1;
  29438. var y = face > 2 ? 0 : -1;
  29439. 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];
  29440. position.set(coordinates, positionSize * vertices * face);
  29441. uv.set(uv1, uvSize * vertices * face);
  29442. var fill = [face, face, face, face, face, face];
  29443. faceIndex.set(fill, faceIndexSize * vertices * face);
  29444. }
  29445. var planes = new BufferGeometry();
  29446. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  29447. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  29448. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  29449. _lodPlanes.push(planes);
  29450. if (lod > LOD_MIN) {
  29451. lod--;
  29452. }
  29453. }
  29454. return {
  29455. _lodPlanes: _lodPlanes,
  29456. _sizeLods: _sizeLods,
  29457. _sigmas: _sigmas
  29458. };
  29459. }
  29460. function _createRenderTarget(params) {
  29461. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  29462. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29463. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29464. cubeUVRenderTarget.scissorTest = true;
  29465. return cubeUVRenderTarget;
  29466. }
  29467. function _setViewport(target, x, y, width, height) {
  29468. target.viewport.set(x, y, width, height);
  29469. target.scissor.set(x, y, width, height);
  29470. }
  29471. function _getBlurShader(maxSamples) {
  29472. var weights = new Float32Array(maxSamples);
  29473. var poleAxis = new Vector3(0, 1, 0);
  29474. var shaderMaterial = new RawShaderMaterial({
  29475. name: 'SphericalGaussianBlur',
  29476. defines: {
  29477. 'n': maxSamples
  29478. },
  29479. uniforms: {
  29480. 'envMap': {
  29481. value: null
  29482. },
  29483. 'samples': {
  29484. value: 1
  29485. },
  29486. 'weights': {
  29487. value: weights
  29488. },
  29489. 'latitudinal': {
  29490. value: false
  29491. },
  29492. 'dTheta': {
  29493. value: 0
  29494. },
  29495. 'mipInt': {
  29496. value: 0
  29497. },
  29498. 'poleAxis': {
  29499. value: poleAxis
  29500. },
  29501. 'inputEncoding': {
  29502. value: ENCODINGS[LinearEncoding]
  29503. },
  29504. 'outputEncoding': {
  29505. value: ENCODINGS[LinearEncoding]
  29506. }
  29507. },
  29508. vertexShader: _getCommonVertexShader(),
  29509. fragmentShader:
  29510. /* glsl */
  29511. "\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",
  29512. blending: NoBlending,
  29513. depthTest: false,
  29514. depthWrite: false
  29515. });
  29516. return shaderMaterial;
  29517. }
  29518. function _getEquirectShader() {
  29519. var texelSize = new Vector2(1, 1);
  29520. var shaderMaterial = new RawShaderMaterial({
  29521. name: 'EquirectangularToCubeUV',
  29522. uniforms: {
  29523. 'envMap': {
  29524. value: null
  29525. },
  29526. 'texelSize': {
  29527. value: texelSize
  29528. },
  29529. 'inputEncoding': {
  29530. value: ENCODINGS[LinearEncoding]
  29531. },
  29532. 'outputEncoding': {
  29533. value: ENCODINGS[LinearEncoding]
  29534. }
  29535. },
  29536. vertexShader: _getCommonVertexShader(),
  29537. fragmentShader:
  29538. /* glsl */
  29539. "\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",
  29540. blending: NoBlending,
  29541. depthTest: false,
  29542. depthWrite: false
  29543. });
  29544. return shaderMaterial;
  29545. }
  29546. function _getCubemapShader() {
  29547. var shaderMaterial = new RawShaderMaterial({
  29548. name: 'CubemapToCubeUV',
  29549. uniforms: {
  29550. 'envMap': {
  29551. value: null
  29552. },
  29553. 'inputEncoding': {
  29554. value: ENCODINGS[LinearEncoding]
  29555. },
  29556. 'outputEncoding': {
  29557. value: ENCODINGS[LinearEncoding]
  29558. }
  29559. },
  29560. vertexShader: _getCommonVertexShader(),
  29561. fragmentShader:
  29562. /* glsl */
  29563. "\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",
  29564. blending: NoBlending,
  29565. depthTest: false,
  29566. depthWrite: false
  29567. });
  29568. return shaderMaterial;
  29569. }
  29570. function _getCommonVertexShader() {
  29571. return (
  29572. /* glsl */
  29573. "\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"
  29574. );
  29575. }
  29576. function _getEncodings() {
  29577. return (
  29578. /* glsl */
  29579. "\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"
  29580. );
  29581. }
  29582. function Face4(a, b, c, d, normal, color, materialIndex) {
  29583. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  29584. return new Face3(a, b, c, normal, color, materialIndex);
  29585. }
  29586. var LineStrip = 0;
  29587. var LinePieces = 1;
  29588. var NoColors = 0;
  29589. var FaceColors = 1;
  29590. var VertexColors = 2;
  29591. function MeshFaceMaterial(materials) {
  29592. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29593. return materials;
  29594. }
  29595. function MultiMaterial(materials) {
  29596. if (materials === void 0) {
  29597. materials = [];
  29598. }
  29599. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29600. materials.isMultiMaterial = true;
  29601. materials.materials = materials;
  29602. materials.clone = function () {
  29603. return materials.slice();
  29604. };
  29605. return materials;
  29606. }
  29607. function PointCloud(geometry, material) {
  29608. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29609. return new Points(geometry, material);
  29610. }
  29611. function Particle(material) {
  29612. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29613. return new Sprite(material);
  29614. }
  29615. function ParticleSystem(geometry, material) {
  29616. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29617. return new Points(geometry, material);
  29618. }
  29619. function PointCloudMaterial(parameters) {
  29620. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29621. return new PointsMaterial(parameters);
  29622. }
  29623. function ParticleBasicMaterial(parameters) {
  29624. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29625. return new PointsMaterial(parameters);
  29626. }
  29627. function ParticleSystemMaterial(parameters) {
  29628. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29629. return new PointsMaterial(parameters);
  29630. }
  29631. function Vertex(x, y, z) {
  29632. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29633. return new Vector3(x, y, z);
  29634. } //
  29635. function DynamicBufferAttribute(array, itemSize) {
  29636. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29637. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29638. }
  29639. function Int8Attribute(array, itemSize) {
  29640. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29641. return new Int8BufferAttribute(array, itemSize);
  29642. }
  29643. function Uint8Attribute(array, itemSize) {
  29644. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29645. return new Uint8BufferAttribute(array, itemSize);
  29646. }
  29647. function Uint8ClampedAttribute(array, itemSize) {
  29648. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29649. return new Uint8ClampedBufferAttribute(array, itemSize);
  29650. }
  29651. function Int16Attribute(array, itemSize) {
  29652. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29653. return new Int16BufferAttribute(array, itemSize);
  29654. }
  29655. function Uint16Attribute(array, itemSize) {
  29656. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29657. return new Uint16BufferAttribute(array, itemSize);
  29658. }
  29659. function Int32Attribute(array, itemSize) {
  29660. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29661. return new Int32BufferAttribute(array, itemSize);
  29662. }
  29663. function Uint32Attribute(array, itemSize) {
  29664. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29665. return new Uint32BufferAttribute(array, itemSize);
  29666. }
  29667. function Float32Attribute(array, itemSize) {
  29668. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29669. return new Float32BufferAttribute(array, itemSize);
  29670. }
  29671. function Float64Attribute(array, itemSize) {
  29672. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29673. return new Float64BufferAttribute(array, itemSize);
  29674. } //
  29675. Curve.create = function (construct, getPoint) {
  29676. console.log('THREE.Curve.create() has been deprecated');
  29677. construct.prototype = Object.create(Curve.prototype);
  29678. construct.prototype.constructor = construct;
  29679. construct.prototype.getPoint = getPoint;
  29680. return construct;
  29681. }; //
  29682. Object.assign(CurvePath.prototype, {
  29683. createPointsGeometry: function createPointsGeometry(divisions) {
  29684. console.warn('THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from path points (for Line or Points objects)
  29685. var pts = this.getPoints(divisions);
  29686. return this.createGeometry(pts);
  29687. },
  29688. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  29689. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  29690. var pts = this.getSpacedPoints(divisions);
  29691. return this.createGeometry(pts);
  29692. },
  29693. createGeometry: function createGeometry(points) {
  29694. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  29695. var geometry = new Geometry();
  29696. for (var i = 0, l = points.length; i < l; i++) {
  29697. var point = points[i];
  29698. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  29699. }
  29700. return geometry;
  29701. }
  29702. }); //
  29703. Object.assign(Path.prototype, {
  29704. fromPoints: function fromPoints(points) {
  29705. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29706. return this.setFromPoints(points);
  29707. }
  29708. }); //
  29709. function ClosedSplineCurve3(points) {
  29710. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29711. CatmullRomCurve3.call(this, points);
  29712. this.type = 'catmullrom';
  29713. this.closed = true;
  29714. }
  29715. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29716. function SplineCurve3(points) {
  29717. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29718. CatmullRomCurve3.call(this, points);
  29719. this.type = 'catmullrom';
  29720. }
  29721. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29722. function Spline(points) {
  29723. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29724. CatmullRomCurve3.call(this, points);
  29725. this.type = 'catmullrom';
  29726. }
  29727. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29728. Object.assign(Spline.prototype, {
  29729. initFromArray: function initFromArray()
  29730. /* a */
  29731. {
  29732. console.error('THREE.Spline: .initFromArray() has been removed.');
  29733. },
  29734. getControlPointsArray: function getControlPointsArray()
  29735. /* optionalTarget */
  29736. {
  29737. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29738. },
  29739. reparametrizeByArcLength: function reparametrizeByArcLength()
  29740. /* samplingCoef */
  29741. {
  29742. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29743. }
  29744. }); //
  29745. function AxisHelper(size) {
  29746. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29747. return new AxesHelper(size);
  29748. }
  29749. function BoundingBoxHelper(object, color) {
  29750. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29751. return new BoxHelper(object, color);
  29752. }
  29753. function EdgesHelper(object, hex) {
  29754. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29755. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29756. color: hex !== undefined ? hex : 0xffffff
  29757. }));
  29758. }
  29759. GridHelper.prototype.setColors = function () {
  29760. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29761. };
  29762. SkeletonHelper.prototype.update = function () {
  29763. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29764. };
  29765. function WireframeHelper(object, hex) {
  29766. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29767. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29768. color: hex !== undefined ? hex : 0xffffff
  29769. }));
  29770. } //
  29771. Object.assign(Loader.prototype, {
  29772. extractUrlBase: function extractUrlBase(url) {
  29773. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29774. return LoaderUtils.extractUrlBase(url);
  29775. }
  29776. });
  29777. Loader.Handlers = {
  29778. add: function add()
  29779. /* regex, loader */
  29780. {
  29781. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29782. },
  29783. get: function get()
  29784. /* file */
  29785. {
  29786. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29787. }
  29788. };
  29789. function XHRLoader(manager) {
  29790. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29791. return new FileLoader(manager);
  29792. }
  29793. function BinaryTextureLoader(manager) {
  29794. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29795. return new DataTextureLoader(manager);
  29796. } //
  29797. Object.assign(Box2.prototype, {
  29798. center: function center(optionalTarget) {
  29799. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29800. return this.getCenter(optionalTarget);
  29801. },
  29802. empty: function empty() {
  29803. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29804. return this.isEmpty();
  29805. },
  29806. isIntersectionBox: function isIntersectionBox(box) {
  29807. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29808. return this.intersectsBox(box);
  29809. },
  29810. size: function size(optionalTarget) {
  29811. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29812. return this.getSize(optionalTarget);
  29813. }
  29814. });
  29815. Object.assign(Box3.prototype, {
  29816. center: function center(optionalTarget) {
  29817. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29818. return this.getCenter(optionalTarget);
  29819. },
  29820. empty: function empty() {
  29821. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29822. return this.isEmpty();
  29823. },
  29824. isIntersectionBox: function isIntersectionBox(box) {
  29825. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29826. return this.intersectsBox(box);
  29827. },
  29828. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29829. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29830. return this.intersectsSphere(sphere);
  29831. },
  29832. size: function size(optionalTarget) {
  29833. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29834. return this.getSize(optionalTarget);
  29835. }
  29836. });
  29837. Object.assign(Sphere.prototype, {
  29838. empty: function empty() {
  29839. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29840. return this.isEmpty();
  29841. }
  29842. });
  29843. Frustum.prototype.setFromMatrix = function (m) {
  29844. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29845. return this.setFromProjectionMatrix(m);
  29846. };
  29847. Line3.prototype.center = function (optionalTarget) {
  29848. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29849. return this.getCenter(optionalTarget);
  29850. };
  29851. Object.assign(MathUtils, {
  29852. random16: function random16() {
  29853. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29854. return Math.random();
  29855. },
  29856. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29857. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29858. return MathUtils.floorPowerOfTwo(value);
  29859. },
  29860. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29861. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29862. return MathUtils.ceilPowerOfTwo(value);
  29863. }
  29864. });
  29865. Object.assign(Matrix3.prototype, {
  29866. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29867. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29868. return this.toArray(array, offset);
  29869. },
  29870. multiplyVector3: function multiplyVector3(vector) {
  29871. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29872. return vector.applyMatrix3(this);
  29873. },
  29874. multiplyVector3Array: function multiplyVector3Array()
  29875. /* a */
  29876. {
  29877. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29878. },
  29879. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29880. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29881. return attribute.applyMatrix3(this);
  29882. },
  29883. applyToVector3Array: function applyToVector3Array()
  29884. /* array, offset, length */
  29885. {
  29886. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29887. },
  29888. getInverse: function getInverse(matrix) {
  29889. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29890. return this.copy(matrix).invert();
  29891. }
  29892. });
  29893. Object.assign(Matrix4.prototype, {
  29894. extractPosition: function extractPosition(m) {
  29895. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29896. return this.copyPosition(m);
  29897. },
  29898. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29899. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29900. return this.toArray(array, offset);
  29901. },
  29902. getPosition: function getPosition() {
  29903. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29904. return new Vector3().setFromMatrixColumn(this, 3);
  29905. },
  29906. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29907. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29908. return this.makeRotationFromQuaternion(q);
  29909. },
  29910. multiplyToArray: function multiplyToArray() {
  29911. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29912. },
  29913. multiplyVector3: function multiplyVector3(vector) {
  29914. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29915. return vector.applyMatrix4(this);
  29916. },
  29917. multiplyVector4: function multiplyVector4(vector) {
  29918. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29919. return vector.applyMatrix4(this);
  29920. },
  29921. multiplyVector3Array: function multiplyVector3Array()
  29922. /* a */
  29923. {
  29924. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29925. },
  29926. rotateAxis: function rotateAxis(v) {
  29927. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29928. v.transformDirection(this);
  29929. },
  29930. crossVector: function crossVector(vector) {
  29931. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29932. return vector.applyMatrix4(this);
  29933. },
  29934. translate: function translate() {
  29935. console.error('THREE.Matrix4: .translate() has been removed.');
  29936. },
  29937. rotateX: function rotateX() {
  29938. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29939. },
  29940. rotateY: function rotateY() {
  29941. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29942. },
  29943. rotateZ: function rotateZ() {
  29944. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29945. },
  29946. rotateByAxis: function rotateByAxis() {
  29947. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29948. },
  29949. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29950. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29951. return attribute.applyMatrix4(this);
  29952. },
  29953. applyToVector3Array: function applyToVector3Array()
  29954. /* array, offset, length */
  29955. {
  29956. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29957. },
  29958. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29959. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29960. return this.makePerspective(left, right, top, bottom, near, far);
  29961. },
  29962. getInverse: function getInverse(matrix) {
  29963. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29964. return this.copy(matrix).invert();
  29965. }
  29966. });
  29967. Plane.prototype.isIntersectionLine = function (line) {
  29968. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29969. return this.intersectsLine(line);
  29970. };
  29971. Object.assign(Quaternion.prototype, {
  29972. multiplyVector3: function multiplyVector3(vector) {
  29973. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29974. return vector.applyQuaternion(this);
  29975. },
  29976. inverse: function inverse() {
  29977. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29978. return this.invert();
  29979. }
  29980. });
  29981. Object.assign(Ray.prototype, {
  29982. isIntersectionBox: function isIntersectionBox(box) {
  29983. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29984. return this.intersectsBox(box);
  29985. },
  29986. isIntersectionPlane: function isIntersectionPlane(plane) {
  29987. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29988. return this.intersectsPlane(plane);
  29989. },
  29990. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29991. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29992. return this.intersectsSphere(sphere);
  29993. }
  29994. });
  29995. Object.assign(Triangle.prototype, {
  29996. area: function area() {
  29997. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29998. return this.getArea();
  29999. },
  30000. barycoordFromPoint: function barycoordFromPoint(point, target) {
  30001. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  30002. return this.getBarycoord(point, target);
  30003. },
  30004. midpoint: function midpoint(target) {
  30005. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  30006. return this.getMidpoint(target);
  30007. },
  30008. normal: function normal(target) {
  30009. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  30010. return this.getNormal(target);
  30011. },
  30012. plane: function plane(target) {
  30013. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  30014. return this.getPlane(target);
  30015. }
  30016. });
  30017. Object.assign(Triangle, {
  30018. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  30019. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  30020. return Triangle.getBarycoord(point, a, b, c, target);
  30021. },
  30022. normal: function normal(a, b, c, target) {
  30023. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  30024. return Triangle.getNormal(a, b, c, target);
  30025. }
  30026. });
  30027. Object.assign(Shape.prototype, {
  30028. extractAllPoints: function extractAllPoints(divisions) {
  30029. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  30030. return this.extractPoints(divisions);
  30031. },
  30032. extrude: function extrude(options) {
  30033. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  30034. return new ExtrudeGeometry(this, options);
  30035. },
  30036. makeGeometry: function makeGeometry(options) {
  30037. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  30038. return new ShapeGeometry(this, options);
  30039. }
  30040. });
  30041. Object.assign(Vector2.prototype, {
  30042. fromAttribute: function fromAttribute(attribute, index, offset) {
  30043. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30044. return this.fromBufferAttribute(attribute, index, offset);
  30045. },
  30046. distanceToManhattan: function distanceToManhattan(v) {
  30047. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  30048. return this.manhattanDistanceTo(v);
  30049. },
  30050. lengthManhattan: function lengthManhattan() {
  30051. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  30052. return this.manhattanLength();
  30053. }
  30054. });
  30055. Object.assign(Vector3.prototype, {
  30056. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  30057. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  30058. },
  30059. setEulerFromQuaternion: function setEulerFromQuaternion() {
  30060. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  30061. },
  30062. getPositionFromMatrix: function getPositionFromMatrix(m) {
  30063. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  30064. return this.setFromMatrixPosition(m);
  30065. },
  30066. getScaleFromMatrix: function getScaleFromMatrix(m) {
  30067. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  30068. return this.setFromMatrixScale(m);
  30069. },
  30070. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  30071. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  30072. return this.setFromMatrixColumn(matrix, index);
  30073. },
  30074. applyProjection: function applyProjection(m) {
  30075. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  30076. return this.applyMatrix4(m);
  30077. },
  30078. fromAttribute: function fromAttribute(attribute, index, offset) {
  30079. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30080. return this.fromBufferAttribute(attribute, index, offset);
  30081. },
  30082. distanceToManhattan: function distanceToManhattan(v) {
  30083. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  30084. return this.manhattanDistanceTo(v);
  30085. },
  30086. lengthManhattan: function lengthManhattan() {
  30087. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  30088. return this.manhattanLength();
  30089. }
  30090. });
  30091. Object.assign(Vector4.prototype, {
  30092. fromAttribute: function fromAttribute(attribute, index, offset) {
  30093. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30094. return this.fromBufferAttribute(attribute, index, offset);
  30095. },
  30096. lengthManhattan: function lengthManhattan() {
  30097. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  30098. return this.manhattanLength();
  30099. }
  30100. }); //
  30101. Object.assign(Geometry.prototype, {
  30102. computeTangents: function computeTangents() {
  30103. console.error('THREE.Geometry: .computeTangents() has been removed.');
  30104. },
  30105. computeLineDistances: function computeLineDistances() {
  30106. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  30107. },
  30108. applyMatrix: function applyMatrix(matrix) {
  30109. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30110. return this.applyMatrix4(matrix);
  30111. }
  30112. });
  30113. Object.assign(Object3D.prototype, {
  30114. getChildByName: function getChildByName(name) {
  30115. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  30116. return this.getObjectByName(name);
  30117. },
  30118. renderDepth: function renderDepth() {
  30119. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  30120. },
  30121. translate: function translate(distance, axis) {
  30122. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  30123. return this.translateOnAxis(axis, distance);
  30124. },
  30125. getWorldRotation: function getWorldRotation() {
  30126. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  30127. },
  30128. applyMatrix: function applyMatrix(matrix) {
  30129. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  30130. return this.applyMatrix4(matrix);
  30131. }
  30132. });
  30133. Object.defineProperties(Object3D.prototype, {
  30134. eulerOrder: {
  30135. get: function get() {
  30136. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  30137. return this.rotation.order;
  30138. },
  30139. set: function set(value) {
  30140. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  30141. this.rotation.order = value;
  30142. }
  30143. },
  30144. useQuaternion: {
  30145. get: function get() {
  30146. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  30147. },
  30148. set: function set() {
  30149. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  30150. }
  30151. }
  30152. });
  30153. Object.assign(Mesh.prototype, {
  30154. setDrawMode: function setDrawMode() {
  30155. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  30156. }
  30157. });
  30158. Object.defineProperties(Mesh.prototype, {
  30159. drawMode: {
  30160. get: function get() {
  30161. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  30162. return TrianglesDrawMode;
  30163. },
  30164. set: function set() {
  30165. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  30166. }
  30167. }
  30168. });
  30169. Object.defineProperties(LOD.prototype, {
  30170. objects: {
  30171. get: function get() {
  30172. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  30173. return this.levels;
  30174. }
  30175. }
  30176. });
  30177. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  30178. get: function get() {
  30179. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  30180. },
  30181. set: function set() {
  30182. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  30183. }
  30184. });
  30185. SkinnedMesh.prototype.initBones = function () {
  30186. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  30187. };
  30188. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  30189. get: function get() {
  30190. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  30191. return this.arcLengthDivisions;
  30192. },
  30193. set: function set(value) {
  30194. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  30195. this.arcLengthDivisions = value;
  30196. }
  30197. }); //
  30198. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  30199. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  30200. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  30201. this.setFocalLength(focalLength);
  30202. }; //
  30203. Object.defineProperties(Light.prototype, {
  30204. onlyShadow: {
  30205. set: function set() {
  30206. console.warn('THREE.Light: .onlyShadow has been removed.');
  30207. }
  30208. },
  30209. shadowCameraFov: {
  30210. set: function set(value) {
  30211. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  30212. this.shadow.camera.fov = value;
  30213. }
  30214. },
  30215. shadowCameraLeft: {
  30216. set: function set(value) {
  30217. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  30218. this.shadow.camera.left = value;
  30219. }
  30220. },
  30221. shadowCameraRight: {
  30222. set: function set(value) {
  30223. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  30224. this.shadow.camera.right = value;
  30225. }
  30226. },
  30227. shadowCameraTop: {
  30228. set: function set(value) {
  30229. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  30230. this.shadow.camera.top = value;
  30231. }
  30232. },
  30233. shadowCameraBottom: {
  30234. set: function set(value) {
  30235. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  30236. this.shadow.camera.bottom = value;
  30237. }
  30238. },
  30239. shadowCameraNear: {
  30240. set: function set(value) {
  30241. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  30242. this.shadow.camera.near = value;
  30243. }
  30244. },
  30245. shadowCameraFar: {
  30246. set: function set(value) {
  30247. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  30248. this.shadow.camera.far = value;
  30249. }
  30250. },
  30251. shadowCameraVisible: {
  30252. set: function set() {
  30253. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  30254. }
  30255. },
  30256. shadowBias: {
  30257. set: function set(value) {
  30258. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  30259. this.shadow.bias = value;
  30260. }
  30261. },
  30262. shadowDarkness: {
  30263. set: function set() {
  30264. console.warn('THREE.Light: .shadowDarkness has been removed.');
  30265. }
  30266. },
  30267. shadowMapWidth: {
  30268. set: function set(value) {
  30269. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  30270. this.shadow.mapSize.width = value;
  30271. }
  30272. },
  30273. shadowMapHeight: {
  30274. set: function set(value) {
  30275. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  30276. this.shadow.mapSize.height = value;
  30277. }
  30278. }
  30279. }); //
  30280. Object.defineProperties(BufferAttribute.prototype, {
  30281. length: {
  30282. get: function get() {
  30283. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  30284. return this.array.length;
  30285. }
  30286. },
  30287. dynamic: {
  30288. get: function get() {
  30289. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30290. return this.usage === DynamicDrawUsage;
  30291. },
  30292. set: function set()
  30293. /* value */
  30294. {
  30295. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30296. this.setUsage(DynamicDrawUsage);
  30297. }
  30298. }
  30299. });
  30300. Object.assign(BufferAttribute.prototype, {
  30301. setDynamic: function setDynamic(value) {
  30302. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30303. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30304. return this;
  30305. },
  30306. copyIndicesArray: function copyIndicesArray()
  30307. /* indices */
  30308. {
  30309. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  30310. },
  30311. setArray: function setArray()
  30312. /* array */
  30313. {
  30314. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30315. }
  30316. });
  30317. Object.assign(BufferGeometry.prototype, {
  30318. addIndex: function addIndex(index) {
  30319. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  30320. this.setIndex(index);
  30321. },
  30322. addAttribute: function addAttribute(name, attribute) {
  30323. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  30324. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  30325. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  30326. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  30327. }
  30328. if (name === 'index') {
  30329. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  30330. this.setIndex(attribute);
  30331. return this;
  30332. }
  30333. return this.setAttribute(name, attribute);
  30334. },
  30335. addDrawCall: function addDrawCall(start, count, indexOffset) {
  30336. if (indexOffset !== undefined) {
  30337. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  30338. }
  30339. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  30340. this.addGroup(start, count);
  30341. },
  30342. clearDrawCalls: function clearDrawCalls() {
  30343. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  30344. this.clearGroups();
  30345. },
  30346. computeTangents: function computeTangents() {
  30347. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  30348. },
  30349. computeOffsets: function computeOffsets() {
  30350. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  30351. },
  30352. removeAttribute: function removeAttribute(name) {
  30353. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  30354. return this.deleteAttribute(name);
  30355. },
  30356. applyMatrix: function applyMatrix(matrix) {
  30357. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30358. return this.applyMatrix4(matrix);
  30359. }
  30360. });
  30361. Object.defineProperties(BufferGeometry.prototype, {
  30362. drawcalls: {
  30363. get: function get() {
  30364. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  30365. return this.groups;
  30366. }
  30367. },
  30368. offsets: {
  30369. get: function get() {
  30370. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  30371. return this.groups;
  30372. }
  30373. }
  30374. });
  30375. Object.defineProperties(InstancedBufferGeometry.prototype, {
  30376. maxInstancedCount: {
  30377. get: function get() {
  30378. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30379. return this.instanceCount;
  30380. },
  30381. set: function set(value) {
  30382. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30383. this.instanceCount = value;
  30384. }
  30385. }
  30386. });
  30387. Object.defineProperties(Raycaster.prototype, {
  30388. linePrecision: {
  30389. get: function get() {
  30390. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30391. return this.params.Line.threshold;
  30392. },
  30393. set: function set(value) {
  30394. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30395. this.params.Line.threshold = value;
  30396. }
  30397. }
  30398. });
  30399. Object.defineProperties(InterleavedBuffer.prototype, {
  30400. dynamic: {
  30401. get: function get() {
  30402. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30403. return this.usage === DynamicDrawUsage;
  30404. },
  30405. set: function set(value) {
  30406. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30407. this.setUsage(value);
  30408. }
  30409. }
  30410. });
  30411. Object.assign(InterleavedBuffer.prototype, {
  30412. setDynamic: function setDynamic(value) {
  30413. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30414. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30415. return this;
  30416. },
  30417. setArray: function setArray()
  30418. /* array */
  30419. {
  30420. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30421. }
  30422. }); //
  30423. Object.assign(ExtrudeBufferGeometry.prototype, {
  30424. getArrays: function getArrays() {
  30425. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  30426. },
  30427. addShapeList: function addShapeList() {
  30428. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  30429. },
  30430. addShape: function addShape() {
  30431. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  30432. }
  30433. }); //
  30434. Object.assign(Scene.prototype, {
  30435. dispose: function dispose() {
  30436. console.error('THREE.Scene: .dispose() has been removed.');
  30437. }
  30438. }); //
  30439. Object.defineProperties(Uniform.prototype, {
  30440. dynamic: {
  30441. set: function set() {
  30442. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  30443. }
  30444. },
  30445. onUpdate: {
  30446. value: function value() {
  30447. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  30448. return this;
  30449. }
  30450. }
  30451. }); //
  30452. Object.defineProperties(Material.prototype, {
  30453. wrapAround: {
  30454. get: function get() {
  30455. console.warn('THREE.Material: .wrapAround has been removed.');
  30456. },
  30457. set: function set() {
  30458. console.warn('THREE.Material: .wrapAround has been removed.');
  30459. }
  30460. },
  30461. overdraw: {
  30462. get: function get() {
  30463. console.warn('THREE.Material: .overdraw has been removed.');
  30464. },
  30465. set: function set() {
  30466. console.warn('THREE.Material: .overdraw has been removed.');
  30467. }
  30468. },
  30469. wrapRGB: {
  30470. get: function get() {
  30471. console.warn('THREE.Material: .wrapRGB has been removed.');
  30472. return new Color();
  30473. }
  30474. },
  30475. shading: {
  30476. get: function get() {
  30477. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30478. },
  30479. set: function set(value) {
  30480. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30481. this.flatShading = value === FlatShading;
  30482. }
  30483. },
  30484. stencilMask: {
  30485. get: function get() {
  30486. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30487. return this.stencilFuncMask;
  30488. },
  30489. set: function set(value) {
  30490. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30491. this.stencilFuncMask = value;
  30492. }
  30493. }
  30494. });
  30495. Object.defineProperties(MeshPhongMaterial.prototype, {
  30496. metal: {
  30497. get: function get() {
  30498. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30499. return false;
  30500. },
  30501. set: function set() {
  30502. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30503. }
  30504. }
  30505. });
  30506. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30507. transparency: {
  30508. get: function get() {
  30509. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30510. return this.transmission;
  30511. },
  30512. set: function set(value) {
  30513. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30514. this.transmission = value;
  30515. }
  30516. }
  30517. });
  30518. Object.defineProperties(ShaderMaterial.prototype, {
  30519. derivatives: {
  30520. get: function get() {
  30521. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30522. return this.extensions.derivatives;
  30523. },
  30524. set: function set(value) {
  30525. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30526. this.extensions.derivatives = value;
  30527. }
  30528. }
  30529. }); //
  30530. Object.assign(WebGLRenderer.prototype, {
  30531. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  30532. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30533. this.setRenderTarget(renderTarget);
  30534. this.clear(color, depth, stencil);
  30535. },
  30536. animate: function animate(callback) {
  30537. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30538. this.setAnimationLoop(callback);
  30539. },
  30540. getCurrentRenderTarget: function getCurrentRenderTarget() {
  30541. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30542. return this.getRenderTarget();
  30543. },
  30544. getMaxAnisotropy: function getMaxAnisotropy() {
  30545. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30546. return this.capabilities.getMaxAnisotropy();
  30547. },
  30548. getPrecision: function getPrecision() {
  30549. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30550. return this.capabilities.precision;
  30551. },
  30552. resetGLState: function resetGLState() {
  30553. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30554. return this.state.reset();
  30555. },
  30556. supportsFloatTextures: function supportsFloatTextures() {
  30557. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30558. return this.extensions.get('OES_texture_float');
  30559. },
  30560. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30561. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30562. return this.extensions.get('OES_texture_half_float');
  30563. },
  30564. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30565. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30566. return this.extensions.get('OES_standard_derivatives');
  30567. },
  30568. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30569. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30570. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30571. },
  30572. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30573. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30574. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30575. },
  30576. supportsBlendMinMax: function supportsBlendMinMax() {
  30577. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30578. return this.extensions.get('EXT_blend_minmax');
  30579. },
  30580. supportsVertexTextures: function supportsVertexTextures() {
  30581. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30582. return this.capabilities.vertexTextures;
  30583. },
  30584. supportsInstancedArrays: function supportsInstancedArrays() {
  30585. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30586. return this.extensions.get('ANGLE_instanced_arrays');
  30587. },
  30588. enableScissorTest: function enableScissorTest(boolean) {
  30589. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30590. this.setScissorTest(boolean);
  30591. },
  30592. initMaterial: function initMaterial() {
  30593. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30594. },
  30595. addPrePlugin: function addPrePlugin() {
  30596. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30597. },
  30598. addPostPlugin: function addPostPlugin() {
  30599. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30600. },
  30601. updateShadowMap: function updateShadowMap() {
  30602. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30603. },
  30604. setFaceCulling: function setFaceCulling() {
  30605. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30606. },
  30607. allocTextureUnit: function allocTextureUnit() {
  30608. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30609. },
  30610. setTexture: function setTexture() {
  30611. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30612. },
  30613. setTexture2D: function setTexture2D() {
  30614. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30615. },
  30616. setTextureCube: function setTextureCube() {
  30617. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30618. },
  30619. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30620. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30621. return this.getActiveMipmapLevel();
  30622. }
  30623. });
  30624. Object.defineProperties(WebGLRenderer.prototype, {
  30625. shadowMapEnabled: {
  30626. get: function get() {
  30627. return this.shadowMap.enabled;
  30628. },
  30629. set: function set(value) {
  30630. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30631. this.shadowMap.enabled = value;
  30632. }
  30633. },
  30634. shadowMapType: {
  30635. get: function get() {
  30636. return this.shadowMap.type;
  30637. },
  30638. set: function set(value) {
  30639. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30640. this.shadowMap.type = value;
  30641. }
  30642. },
  30643. shadowMapCullFace: {
  30644. get: function get() {
  30645. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30646. return undefined;
  30647. },
  30648. set: function set()
  30649. /* value */
  30650. {
  30651. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30652. }
  30653. },
  30654. context: {
  30655. get: function get() {
  30656. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30657. return this.getContext();
  30658. }
  30659. },
  30660. vr: {
  30661. get: function get() {
  30662. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30663. return this.xr;
  30664. }
  30665. },
  30666. gammaInput: {
  30667. get: function get() {
  30668. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30669. return false;
  30670. },
  30671. set: function set() {
  30672. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30673. }
  30674. },
  30675. gammaOutput: {
  30676. get: function get() {
  30677. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30678. return false;
  30679. },
  30680. set: function set(value) {
  30681. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30682. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30683. }
  30684. },
  30685. toneMappingWhitePoint: {
  30686. get: function get() {
  30687. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30688. return 1.0;
  30689. },
  30690. set: function set() {
  30691. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30692. }
  30693. }
  30694. });
  30695. Object.defineProperties(WebGLShadowMap.prototype, {
  30696. cullFace: {
  30697. get: function get() {
  30698. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30699. return undefined;
  30700. },
  30701. set: function set()
  30702. /* cullFace */
  30703. {
  30704. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30705. }
  30706. },
  30707. renderReverseSided: {
  30708. get: function get() {
  30709. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30710. return undefined;
  30711. },
  30712. set: function set() {
  30713. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30714. }
  30715. },
  30716. renderSingleSided: {
  30717. get: function get() {
  30718. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30719. return undefined;
  30720. },
  30721. set: function set() {
  30722. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30723. }
  30724. }
  30725. });
  30726. function WebGLRenderTargetCube(width, height, options) {
  30727. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30728. return new WebGLCubeRenderTarget(width, options);
  30729. } //
  30730. Object.defineProperties(WebGLRenderTarget.prototype, {
  30731. wrapS: {
  30732. get: function get() {
  30733. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30734. return this.texture.wrapS;
  30735. },
  30736. set: function set(value) {
  30737. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30738. this.texture.wrapS = value;
  30739. }
  30740. },
  30741. wrapT: {
  30742. get: function get() {
  30743. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30744. return this.texture.wrapT;
  30745. },
  30746. set: function set(value) {
  30747. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30748. this.texture.wrapT = value;
  30749. }
  30750. },
  30751. magFilter: {
  30752. get: function get() {
  30753. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30754. return this.texture.magFilter;
  30755. },
  30756. set: function set(value) {
  30757. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30758. this.texture.magFilter = value;
  30759. }
  30760. },
  30761. minFilter: {
  30762. get: function get() {
  30763. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30764. return this.texture.minFilter;
  30765. },
  30766. set: function set(value) {
  30767. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30768. this.texture.minFilter = value;
  30769. }
  30770. },
  30771. anisotropy: {
  30772. get: function get() {
  30773. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30774. return this.texture.anisotropy;
  30775. },
  30776. set: function set(value) {
  30777. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30778. this.texture.anisotropy = value;
  30779. }
  30780. },
  30781. offset: {
  30782. get: function get() {
  30783. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30784. return this.texture.offset;
  30785. },
  30786. set: function set(value) {
  30787. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30788. this.texture.offset = value;
  30789. }
  30790. },
  30791. repeat: {
  30792. get: function get() {
  30793. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30794. return this.texture.repeat;
  30795. },
  30796. set: function set(value) {
  30797. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30798. this.texture.repeat = value;
  30799. }
  30800. },
  30801. format: {
  30802. get: function get() {
  30803. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30804. return this.texture.format;
  30805. },
  30806. set: function set(value) {
  30807. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30808. this.texture.format = value;
  30809. }
  30810. },
  30811. type: {
  30812. get: function get() {
  30813. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30814. return this.texture.type;
  30815. },
  30816. set: function set(value) {
  30817. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30818. this.texture.type = value;
  30819. }
  30820. },
  30821. generateMipmaps: {
  30822. get: function get() {
  30823. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30824. return this.texture.generateMipmaps;
  30825. },
  30826. set: function set(value) {
  30827. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30828. this.texture.generateMipmaps = value;
  30829. }
  30830. }
  30831. }); //
  30832. Object.defineProperties(Audio.prototype, {
  30833. load: {
  30834. value: function value(file) {
  30835. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30836. var scope = this;
  30837. var audioLoader = new AudioLoader();
  30838. audioLoader.load(file, function (buffer) {
  30839. scope.setBuffer(buffer);
  30840. });
  30841. return this;
  30842. }
  30843. },
  30844. startTime: {
  30845. set: function set() {
  30846. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30847. }
  30848. }
  30849. });
  30850. AudioAnalyser.prototype.getData = function () {
  30851. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30852. return this.getFrequencyData();
  30853. }; //
  30854. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30855. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30856. return this.update(renderer, scene);
  30857. };
  30858. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30859. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30860. return this.renderTarget.clear(renderer, color, depth, stencil);
  30861. }; //
  30862. var GeometryUtils = {
  30863. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30864. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30865. var matrix;
  30866. if (geometry2.isMesh) {
  30867. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30868. matrix = geometry2.matrix;
  30869. geometry2 = geometry2.geometry;
  30870. }
  30871. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30872. },
  30873. center: function center(geometry) {
  30874. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30875. return geometry.center();
  30876. }
  30877. };
  30878. ImageUtils.crossOrigin = undefined;
  30879. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30880. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30881. var loader = new TextureLoader();
  30882. loader.setCrossOrigin(this.crossOrigin);
  30883. var texture = loader.load(url, onLoad, undefined, onError);
  30884. if (mapping) texture.mapping = mapping;
  30885. return texture;
  30886. };
  30887. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30888. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30889. var loader = new CubeTextureLoader();
  30890. loader.setCrossOrigin(this.crossOrigin);
  30891. var texture = loader.load(urls, onLoad, undefined, onError);
  30892. if (mapping) texture.mapping = mapping;
  30893. return texture;
  30894. };
  30895. ImageUtils.loadCompressedTexture = function () {
  30896. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30897. };
  30898. ImageUtils.loadCompressedTextureCube = function () {
  30899. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30900. }; //
  30901. function CanvasRenderer() {
  30902. console.error('THREE.CanvasRenderer has been removed');
  30903. } //
  30904. function JSONLoader() {
  30905. console.error('THREE.JSONLoader has been removed.');
  30906. } //
  30907. var SceneUtils = {
  30908. createMultiMaterialObject: function createMultiMaterialObject()
  30909. /* geometry, materials */
  30910. {
  30911. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30912. },
  30913. detach: function detach()
  30914. /* child, parent, scene */
  30915. {
  30916. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30917. },
  30918. attach: function attach()
  30919. /* child, scene, parent */
  30920. {
  30921. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30922. }
  30923. }; //
  30924. function LensFlare() {
  30925. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30926. }
  30927. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30928. /* eslint-disable no-undef */
  30929. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30930. detail: {
  30931. revision: REVISION
  30932. }
  30933. }));
  30934. /* eslint-enable no-undef */
  30935. }
  30936. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30937. exports.AddEquation = AddEquation;
  30938. exports.AddOperation = AddOperation;
  30939. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30940. exports.AdditiveBlending = AdditiveBlending;
  30941. exports.AlphaFormat = AlphaFormat;
  30942. exports.AlwaysDepth = AlwaysDepth;
  30943. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30944. exports.AmbientLight = AmbientLight;
  30945. exports.AmbientLightProbe = AmbientLightProbe;
  30946. exports.AnimationClip = AnimationClip;
  30947. exports.AnimationLoader = AnimationLoader;
  30948. exports.AnimationMixer = AnimationMixer;
  30949. exports.AnimationObjectGroup = AnimationObjectGroup;
  30950. exports.AnimationUtils = AnimationUtils;
  30951. exports.ArcCurve = ArcCurve;
  30952. exports.ArrayCamera = ArrayCamera;
  30953. exports.ArrowHelper = ArrowHelper;
  30954. exports.Audio = Audio;
  30955. exports.AudioAnalyser = AudioAnalyser;
  30956. exports.AudioContext = AudioContext;
  30957. exports.AudioListener = AudioListener;
  30958. exports.AudioLoader = AudioLoader;
  30959. exports.AxesHelper = AxesHelper;
  30960. exports.AxisHelper = AxisHelper;
  30961. exports.BackSide = BackSide;
  30962. exports.BasicDepthPacking = BasicDepthPacking;
  30963. exports.BasicShadowMap = BasicShadowMap;
  30964. exports.BinaryTextureLoader = BinaryTextureLoader;
  30965. exports.Bone = Bone;
  30966. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30967. exports.BoundingBoxHelper = BoundingBoxHelper;
  30968. exports.Box2 = Box2;
  30969. exports.Box3 = Box3;
  30970. exports.Box3Helper = Box3Helper;
  30971. exports.BoxBufferGeometry = BoxBufferGeometry;
  30972. exports.BoxGeometry = BoxGeometry;
  30973. exports.BoxHelper = BoxHelper;
  30974. exports.BufferAttribute = BufferAttribute;
  30975. exports.BufferGeometry = BufferGeometry;
  30976. exports.BufferGeometryLoader = BufferGeometryLoader;
  30977. exports.ByteType = ByteType;
  30978. exports.Cache = Cache;
  30979. exports.Camera = Camera;
  30980. exports.CameraHelper = CameraHelper;
  30981. exports.CanvasRenderer = CanvasRenderer;
  30982. exports.CanvasTexture = CanvasTexture;
  30983. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30984. exports.CineonToneMapping = CineonToneMapping;
  30985. exports.CircleBufferGeometry = CircleBufferGeometry;
  30986. exports.CircleGeometry = CircleGeometry;
  30987. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30988. exports.Clock = Clock;
  30989. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30990. exports.Color = Color;
  30991. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30992. exports.CompressedTexture = CompressedTexture;
  30993. exports.CompressedTextureLoader = CompressedTextureLoader;
  30994. exports.ConeBufferGeometry = ConeBufferGeometry;
  30995. exports.ConeGeometry = ConeGeometry;
  30996. exports.CubeCamera = CubeCamera;
  30997. exports.CubeGeometry = BoxGeometry;
  30998. exports.CubeReflectionMapping = CubeReflectionMapping;
  30999. exports.CubeRefractionMapping = CubeRefractionMapping;
  31000. exports.CubeTexture = CubeTexture;
  31001. exports.CubeTextureLoader = CubeTextureLoader;
  31002. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  31003. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  31004. exports.CubicBezierCurve = CubicBezierCurve;
  31005. exports.CubicBezierCurve3 = CubicBezierCurve3;
  31006. exports.CubicInterpolant = CubicInterpolant;
  31007. exports.CullFaceBack = CullFaceBack;
  31008. exports.CullFaceFront = CullFaceFront;
  31009. exports.CullFaceFrontBack = CullFaceFrontBack;
  31010. exports.CullFaceNone = CullFaceNone;
  31011. exports.Curve = Curve;
  31012. exports.CurvePath = CurvePath;
  31013. exports.CustomBlending = CustomBlending;
  31014. exports.CustomToneMapping = CustomToneMapping;
  31015. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  31016. exports.CylinderGeometry = CylinderGeometry;
  31017. exports.Cylindrical = Cylindrical;
  31018. exports.DataTexture = DataTexture;
  31019. exports.DataTexture2DArray = DataTexture2DArray;
  31020. exports.DataTexture3D = DataTexture3D;
  31021. exports.DataTextureLoader = DataTextureLoader;
  31022. exports.DataUtils = DataUtils;
  31023. exports.DecrementStencilOp = DecrementStencilOp;
  31024. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  31025. exports.DefaultLoadingManager = DefaultLoadingManager;
  31026. exports.DepthFormat = DepthFormat;
  31027. exports.DepthStencilFormat = DepthStencilFormat;
  31028. exports.DepthTexture = DepthTexture;
  31029. exports.DirectionalLight = DirectionalLight;
  31030. exports.DirectionalLightHelper = DirectionalLightHelper;
  31031. exports.DiscreteInterpolant = DiscreteInterpolant;
  31032. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  31033. exports.DodecahedronGeometry = DodecahedronGeometry;
  31034. exports.DoubleSide = DoubleSide;
  31035. exports.DstAlphaFactor = DstAlphaFactor;
  31036. exports.DstColorFactor = DstColorFactor;
  31037. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  31038. exports.DynamicCopyUsage = DynamicCopyUsage;
  31039. exports.DynamicDrawUsage = DynamicDrawUsage;
  31040. exports.DynamicReadUsage = DynamicReadUsage;
  31041. exports.EdgesGeometry = EdgesGeometry;
  31042. exports.EdgesHelper = EdgesHelper;
  31043. exports.EllipseCurve = EllipseCurve;
  31044. exports.EqualDepth = EqualDepth;
  31045. exports.EqualStencilFunc = EqualStencilFunc;
  31046. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  31047. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  31048. exports.Euler = Euler;
  31049. exports.EventDispatcher = EventDispatcher;
  31050. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  31051. exports.ExtrudeGeometry = ExtrudeGeometry;
  31052. exports.Face3 = Face3;
  31053. exports.Face4 = Face4;
  31054. exports.FaceColors = FaceColors;
  31055. exports.FileLoader = FileLoader;
  31056. exports.FlatShading = FlatShading;
  31057. exports.Float16BufferAttribute = Float16BufferAttribute;
  31058. exports.Float32Attribute = Float32Attribute;
  31059. exports.Float32BufferAttribute = Float32BufferAttribute;
  31060. exports.Float64Attribute = Float64Attribute;
  31061. exports.Float64BufferAttribute = Float64BufferAttribute;
  31062. exports.FloatType = FloatType;
  31063. exports.Fog = Fog;
  31064. exports.FogExp2 = FogExp2;
  31065. exports.Font = Font;
  31066. exports.FontLoader = FontLoader;
  31067. exports.FrontSide = FrontSide;
  31068. exports.Frustum = Frustum;
  31069. exports.GLBufferAttribute = GLBufferAttribute;
  31070. exports.GLSL1 = GLSL1;
  31071. exports.GLSL3 = GLSL3;
  31072. exports.GammaEncoding = GammaEncoding;
  31073. exports.Geometry = Geometry;
  31074. exports.GeometryUtils = GeometryUtils;
  31075. exports.GreaterDepth = GreaterDepth;
  31076. exports.GreaterEqualDepth = GreaterEqualDepth;
  31077. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  31078. exports.GreaterStencilFunc = GreaterStencilFunc;
  31079. exports.GridHelper = GridHelper;
  31080. exports.Group = Group;
  31081. exports.HalfFloatType = HalfFloatType;
  31082. exports.HemisphereLight = HemisphereLight;
  31083. exports.HemisphereLightHelper = HemisphereLightHelper;
  31084. exports.HemisphereLightProbe = HemisphereLightProbe;
  31085. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  31086. exports.IcosahedronGeometry = IcosahedronGeometry;
  31087. exports.ImageBitmapLoader = ImageBitmapLoader;
  31088. exports.ImageLoader = ImageLoader;
  31089. exports.ImageUtils = ImageUtils;
  31090. exports.ImmediateRenderObject = ImmediateRenderObject;
  31091. exports.IncrementStencilOp = IncrementStencilOp;
  31092. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  31093. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  31094. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  31095. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  31096. exports.InstancedMesh = InstancedMesh;
  31097. exports.Int16Attribute = Int16Attribute;
  31098. exports.Int16BufferAttribute = Int16BufferAttribute;
  31099. exports.Int32Attribute = Int32Attribute;
  31100. exports.Int32BufferAttribute = Int32BufferAttribute;
  31101. exports.Int8Attribute = Int8Attribute;
  31102. exports.Int8BufferAttribute = Int8BufferAttribute;
  31103. exports.IntType = IntType;
  31104. exports.InterleavedBuffer = InterleavedBuffer;
  31105. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  31106. exports.Interpolant = Interpolant;
  31107. exports.InterpolateDiscrete = InterpolateDiscrete;
  31108. exports.InterpolateLinear = InterpolateLinear;
  31109. exports.InterpolateSmooth = InterpolateSmooth;
  31110. exports.InvertStencilOp = InvertStencilOp;
  31111. exports.JSONLoader = JSONLoader;
  31112. exports.KeepStencilOp = KeepStencilOp;
  31113. exports.KeyframeTrack = KeyframeTrack;
  31114. exports.LOD = LOD;
  31115. exports.LatheBufferGeometry = LatheBufferGeometry;
  31116. exports.LatheGeometry = LatheGeometry;
  31117. exports.Layers = Layers;
  31118. exports.LensFlare = LensFlare;
  31119. exports.LessDepth = LessDepth;
  31120. exports.LessEqualDepth = LessEqualDepth;
  31121. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  31122. exports.LessStencilFunc = LessStencilFunc;
  31123. exports.Light = Light;
  31124. exports.LightProbe = LightProbe;
  31125. exports.Line = Line;
  31126. exports.Line3 = Line3;
  31127. exports.LineBasicMaterial = LineBasicMaterial;
  31128. exports.LineCurve = LineCurve;
  31129. exports.LineCurve3 = LineCurve3;
  31130. exports.LineDashedMaterial = LineDashedMaterial;
  31131. exports.LineLoop = LineLoop;
  31132. exports.LinePieces = LinePieces;
  31133. exports.LineSegments = LineSegments;
  31134. exports.LineStrip = LineStrip;
  31135. exports.LinearEncoding = LinearEncoding;
  31136. exports.LinearFilter = LinearFilter;
  31137. exports.LinearInterpolant = LinearInterpolant;
  31138. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  31139. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  31140. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  31141. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  31142. exports.LinearToneMapping = LinearToneMapping;
  31143. exports.Loader = Loader;
  31144. exports.LoaderUtils = LoaderUtils;
  31145. exports.LoadingManager = LoadingManager;
  31146. exports.LogLuvEncoding = LogLuvEncoding;
  31147. exports.LoopOnce = LoopOnce;
  31148. exports.LoopPingPong = LoopPingPong;
  31149. exports.LoopRepeat = LoopRepeat;
  31150. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  31151. exports.LuminanceFormat = LuminanceFormat;
  31152. exports.MOUSE = MOUSE;
  31153. exports.Material = Material;
  31154. exports.MaterialLoader = MaterialLoader;
  31155. exports.Math = MathUtils;
  31156. exports.MathUtils = MathUtils;
  31157. exports.Matrix3 = Matrix3;
  31158. exports.Matrix4 = Matrix4;
  31159. exports.MaxEquation = MaxEquation;
  31160. exports.Mesh = Mesh;
  31161. exports.MeshBasicMaterial = MeshBasicMaterial;
  31162. exports.MeshDepthMaterial = MeshDepthMaterial;
  31163. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  31164. exports.MeshFaceMaterial = MeshFaceMaterial;
  31165. exports.MeshLambertMaterial = MeshLambertMaterial;
  31166. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  31167. exports.MeshNormalMaterial = MeshNormalMaterial;
  31168. exports.MeshPhongMaterial = MeshPhongMaterial;
  31169. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  31170. exports.MeshStandardMaterial = MeshStandardMaterial;
  31171. exports.MeshToonMaterial = MeshToonMaterial;
  31172. exports.MinEquation = MinEquation;
  31173. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  31174. exports.MixOperation = MixOperation;
  31175. exports.MultiMaterial = MultiMaterial;
  31176. exports.MultiplyBlending = MultiplyBlending;
  31177. exports.MultiplyOperation = MultiplyOperation;
  31178. exports.NearestFilter = NearestFilter;
  31179. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  31180. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  31181. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  31182. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  31183. exports.NeverDepth = NeverDepth;
  31184. exports.NeverStencilFunc = NeverStencilFunc;
  31185. exports.NoBlending = NoBlending;
  31186. exports.NoColors = NoColors;
  31187. exports.NoToneMapping = NoToneMapping;
  31188. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  31189. exports.NormalBlending = NormalBlending;
  31190. exports.NotEqualDepth = NotEqualDepth;
  31191. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  31192. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  31193. exports.Object3D = Object3D;
  31194. exports.ObjectLoader = ObjectLoader;
  31195. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  31196. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  31197. exports.OctahedronGeometry = OctahedronGeometry;
  31198. exports.OneFactor = OneFactor;
  31199. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  31200. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  31201. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  31202. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  31203. exports.OrthographicCamera = OrthographicCamera;
  31204. exports.PCFShadowMap = PCFShadowMap;
  31205. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  31206. exports.PMREMGenerator = PMREMGenerator;
  31207. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  31208. exports.ParametricGeometry = ParametricGeometry;
  31209. exports.Particle = Particle;
  31210. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  31211. exports.ParticleSystem = ParticleSystem;
  31212. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  31213. exports.Path = Path;
  31214. exports.PerspectiveCamera = PerspectiveCamera;
  31215. exports.Plane = Plane;
  31216. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  31217. exports.PlaneGeometry = PlaneGeometry;
  31218. exports.PlaneHelper = PlaneHelper;
  31219. exports.PointCloud = PointCloud;
  31220. exports.PointCloudMaterial = PointCloudMaterial;
  31221. exports.PointLight = PointLight;
  31222. exports.PointLightHelper = PointLightHelper;
  31223. exports.Points = Points;
  31224. exports.PointsMaterial = PointsMaterial;
  31225. exports.PolarGridHelper = PolarGridHelper;
  31226. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  31227. exports.PolyhedronGeometry = PolyhedronGeometry;
  31228. exports.PositionalAudio = PositionalAudio;
  31229. exports.PropertyBinding = PropertyBinding;
  31230. exports.PropertyMixer = PropertyMixer;
  31231. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  31232. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  31233. exports.Quaternion = Quaternion;
  31234. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  31235. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  31236. exports.REVISION = REVISION;
  31237. exports.RGBADepthPacking = RGBADepthPacking;
  31238. exports.RGBAFormat = RGBAFormat;
  31239. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  31240. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  31241. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  31242. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  31243. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  31244. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  31245. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  31246. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  31247. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  31248. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  31249. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  31250. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  31251. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  31252. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  31253. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  31254. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  31255. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  31256. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  31257. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  31258. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  31259. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  31260. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  31261. exports.RGBDEncoding = RGBDEncoding;
  31262. exports.RGBEEncoding = RGBEEncoding;
  31263. exports.RGBEFormat = RGBEFormat;
  31264. exports.RGBFormat = RGBFormat;
  31265. exports.RGBIntegerFormat = RGBIntegerFormat;
  31266. exports.RGBM16Encoding = RGBM16Encoding;
  31267. exports.RGBM7Encoding = RGBM7Encoding;
  31268. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  31269. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  31270. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  31271. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  31272. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  31273. exports.RGFormat = RGFormat;
  31274. exports.RGIntegerFormat = RGIntegerFormat;
  31275. exports.RawShaderMaterial = RawShaderMaterial;
  31276. exports.Ray = Ray;
  31277. exports.Raycaster = Raycaster;
  31278. exports.RectAreaLight = RectAreaLight;
  31279. exports.RedFormat = RedFormat;
  31280. exports.RedIntegerFormat = RedIntegerFormat;
  31281. exports.ReinhardToneMapping = ReinhardToneMapping;
  31282. exports.RepeatWrapping = RepeatWrapping;
  31283. exports.ReplaceStencilOp = ReplaceStencilOp;
  31284. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  31285. exports.RingBufferGeometry = RingBufferGeometry;
  31286. exports.RingGeometry = RingGeometry;
  31287. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  31288. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  31289. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  31290. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  31291. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  31292. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  31293. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  31294. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  31295. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  31296. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  31297. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  31298. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  31299. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  31300. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  31301. exports.Scene = Scene;
  31302. exports.SceneUtils = SceneUtils;
  31303. exports.ShaderChunk = ShaderChunk;
  31304. exports.ShaderLib = ShaderLib;
  31305. exports.ShaderMaterial = ShaderMaterial;
  31306. exports.ShadowMaterial = ShadowMaterial;
  31307. exports.Shape = Shape;
  31308. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  31309. exports.ShapeGeometry = ShapeGeometry;
  31310. exports.ShapePath = ShapePath;
  31311. exports.ShapeUtils = ShapeUtils;
  31312. exports.ShortType = ShortType;
  31313. exports.Skeleton = Skeleton;
  31314. exports.SkeletonHelper = SkeletonHelper;
  31315. exports.SkinnedMesh = SkinnedMesh;
  31316. exports.SmoothShading = SmoothShading;
  31317. exports.Sphere = Sphere;
  31318. exports.SphereBufferGeometry = SphereBufferGeometry;
  31319. exports.SphereGeometry = SphereGeometry;
  31320. exports.Spherical = Spherical;
  31321. exports.SphericalHarmonics3 = SphericalHarmonics3;
  31322. exports.Spline = Spline;
  31323. exports.SplineCurve = SplineCurve;
  31324. exports.SplineCurve3 = SplineCurve3;
  31325. exports.SpotLight = SpotLight;
  31326. exports.SpotLightHelper = SpotLightHelper;
  31327. exports.Sprite = Sprite;
  31328. exports.SpriteMaterial = SpriteMaterial;
  31329. exports.SrcAlphaFactor = SrcAlphaFactor;
  31330. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  31331. exports.SrcColorFactor = SrcColorFactor;
  31332. exports.StaticCopyUsage = StaticCopyUsage;
  31333. exports.StaticDrawUsage = StaticDrawUsage;
  31334. exports.StaticReadUsage = StaticReadUsage;
  31335. exports.StereoCamera = StereoCamera;
  31336. exports.StreamCopyUsage = StreamCopyUsage;
  31337. exports.StreamDrawUsage = StreamDrawUsage;
  31338. exports.StreamReadUsage = StreamReadUsage;
  31339. exports.StringKeyframeTrack = StringKeyframeTrack;
  31340. exports.SubtractEquation = SubtractEquation;
  31341. exports.SubtractiveBlending = SubtractiveBlending;
  31342. exports.TOUCH = TOUCH;
  31343. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  31344. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  31345. exports.TetrahedronGeometry = TetrahedronGeometry;
  31346. exports.TextBufferGeometry = TextBufferGeometry;
  31347. exports.TextGeometry = TextGeometry;
  31348. exports.Texture = Texture;
  31349. exports.TextureLoader = TextureLoader;
  31350. exports.TorusBufferGeometry = TorusBufferGeometry;
  31351. exports.TorusGeometry = TorusGeometry;
  31352. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  31353. exports.TorusKnotGeometry = TorusKnotGeometry;
  31354. exports.Triangle = Triangle;
  31355. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  31356. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  31357. exports.TrianglesDrawMode = TrianglesDrawMode;
  31358. exports.TubeBufferGeometry = TubeBufferGeometry;
  31359. exports.TubeGeometry = TubeGeometry;
  31360. exports.UVMapping = UVMapping;
  31361. exports.Uint16Attribute = Uint16Attribute;
  31362. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  31363. exports.Uint32Attribute = Uint32Attribute;
  31364. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  31365. exports.Uint8Attribute = Uint8Attribute;
  31366. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  31367. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  31368. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  31369. exports.Uniform = Uniform;
  31370. exports.UniformsLib = UniformsLib;
  31371. exports.UniformsUtils = UniformsUtils;
  31372. exports.UnsignedByteType = UnsignedByteType;
  31373. exports.UnsignedInt248Type = UnsignedInt248Type;
  31374. exports.UnsignedIntType = UnsignedIntType;
  31375. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  31376. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  31377. exports.UnsignedShort565Type = UnsignedShort565Type;
  31378. exports.UnsignedShortType = UnsignedShortType;
  31379. exports.VSMShadowMap = VSMShadowMap;
  31380. exports.Vector2 = Vector2;
  31381. exports.Vector3 = Vector3;
  31382. exports.Vector4 = Vector4;
  31383. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  31384. exports.Vertex = Vertex;
  31385. exports.VertexColors = VertexColors;
  31386. exports.VideoTexture = VideoTexture;
  31387. exports.WebGL1Renderer = WebGL1Renderer;
  31388. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  31389. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  31390. exports.WebGLRenderTarget = WebGLRenderTarget;
  31391. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  31392. exports.WebGLRenderer = WebGLRenderer;
  31393. exports.WebGLUtils = WebGLUtils;
  31394. exports.WireframeGeometry = WireframeGeometry;
  31395. exports.WireframeHelper = WireframeHelper;
  31396. exports.WrapAroundEnding = WrapAroundEnding;
  31397. exports.XHRLoader = XHRLoader;
  31398. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  31399. exports.ZeroFactor = ZeroFactor;
  31400. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  31401. exports.ZeroStencilOp = ZeroStencilOp;
  31402. exports.sRGBEncoding = sRGBEncoding;
  31403. Object.defineProperty(exports, '__esModule', { value: true });
  31404. })));